medusajs / medusa

Building blocks for digital commerce
https://medusajs.com
MIT License
24.45k stars 2.4k forks source link

Payment Complete response sporadic when using payment #4979

Open brendansimcox opened 12 months ago

brendansimcox commented 12 months ago

Bug report

Describe the bug

We have noticed through production testing that the the response from payment complete for paypal payments can be erratic, so far roughly 6/20 attempts have returned a cart object instead of an order object resulting in the order not being created and the user being redirected to a 404 page.

System information

Medusa version (including plugins):

"dependencies": {
    "@medusajs/admin": "^6.0.1",
    "@medusajs/cache-redis": "1.8.8",
    "@medusajs/event-bus-redis": "1.8.8",
    "@medusajs/inventory": "^1.9.1",
    "@medusajs/medusa": "1.12.1",
    "@medusajs/medusa-cli": "^1.3.16",
    "add": "^2.0.6",
    "medusa-extender": "^1.8.8",
    "medusa-file-s3": "^1.2.1",
    "medusa-fulfillment-manual": "^1.1.38",
    "medusa-interfaces": "^1.3.7",
    "medusa-payment-manual": "^1.0.24",
    "medusa-payment-paypal": "^6.0.2",
    "medusa-payment-stripe": "^6.0.2",
    "medusa-plugin-meilisearch": "^2.0.8",
    "medusa-plugin-sendgrid": "^1.3.11",
    "medusa-plugin-ses": "^2.0.17",
    "medusa-plugin-wishlist": "^1.1.43",
    "typeorm": "^0.3.17",
    "yarn": "^1.22.19"
  },

Node.js version: 14.21.3 Database: Postgres Operating system: linux

Steps to reproduce the behavior

  1. Normal process leading up to checkout
  2. Choose paypal
  3. Complete authorisation via paypa
  4. Return to site as normal
  5. Intermittently see cart object being returned in response.

Expected behavior

Always return a complete order object

Screenshots

grasslands-cart grasslands-order

olivermrbl commented 12 months ago

Will try to look into this soon. PayPal's API has had me pulling my teeth out many times. Have you considered using PayPal through Stripe? We've used it for some time and so far has been solid.

brendansimcox commented 12 months ago

Thanks for the response @olivermrbl we didn't realise it was possible - do you have an example of how to implement (we are also struggling to get apple pay functional at the moment) i might be missing something in my plugin configuration

options: { api_key: STRIPE_API_KEY, webhook_secret: STRIPE_WEBHOOK_SECRET, automatic_payment_methods: true, },

brendansimcox commented 12 months ago

image

@olivermrbl can confirm the customer has the methods turned on via their striped dashboard

brendansimcox commented 12 months ago

image

Looking at the stripe intents and the automatic_payment_method is being set to true :s

chemicalkosek commented 12 months ago

What capture_method is on that payment intent?

brendansimcox commented 12 months ago

authorisation

chemicalkosek commented 12 months ago

I thought it could be manual or automatic.

brendansimcox commented 12 months ago

Sorry, the payment intent is authorise and the capture_method is manual

chemicalkosek commented 12 months ago

It needs to be automatic for some payment methods in Stripe, otherwise they won't show in PaymentElement. Set capture: true in plugin settings.

olivermrbl commented 12 months ago

@brendansimcox, I realise we currently don't support PayPal through Stripe. We need a dedicated service in the plugin, similar to the existing ones.

However, adding the following service to your Medusa project should allow you to work with it:

import { PaymentIntentOptions } from "medusa-payment-stripe"
import Stripe from "stripe"
import StripeBase from "medusa-payment-stripe/dist/core/stripe-base"

const STRIPE_API_KEY = process.env.STRIPE_API_KEY || "some_test_key"

class StripePayPalCheckoutService extends StripeBase {
  static identifier = "stripe-paypal"

  constructor(_, options) {
    super(_, options)

    this.stripe_ = new Stripe(STRIPE_API_KEY, {
      apiVersion: "2022-11-15",
    })
  }

  get paymentIntentOptions(): PaymentIntentOptions {
    return {
      payment_method_types: ["card", "paypal"],
      capture_method: "manual",
    }
  }
}

export default StripePayPalCheckoutService

After restarting your server, you should see "stripe-paypal" as a payment provider option in your region settings.

Let me know if it works :)

daysgobye commented 11 months ago

I am having this same problem. for us its more like 6/20 fail. But the payment is left uncaptured and the customer see the money as on hold. the order is not in the medusa dashboard and can not be captured. We can not use paypal through stripe due to it not being offered in the US I would love to see a fix for this or even if someone know what the problem is. I would happily do the work my self I just have no clue where even to start. when its something intermittent like this I dont know the code base enough to even know where to look.