medusajs / medusa

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

Checkout flow stripe: An error occurred in InitiatePayment during the creation of the stripe payment intent #7111

Open davidparys opened 2 months ago

davidparys commented 2 months ago

Bug report

Describe the bug

Hello, I am having a little bit of an issue, currently building a storefront with the js-client, and I am creating a checkout session with the stripe provider, I am running into the following issue when:

/// StoreCartsRes || cart.payment_sessions
[
    {
        "id": "ps_01HW0J61ZM1C5Q5C020KKZC50M",
        "created_at": "2024-04-21T14:50:24.077Z",
        "updated_at": "2024-04-21T15:04:58.516Z",
        "cart_id": "cart_01HW0HZ35BQW6JPM264Y417ATD",
        "provider_id": "manual",
        "is_selected": null,
        "is_initiated": false,
        "status": "pending",
        "data": {},
        "idempotency_key": null,
        "amount": 97818,
        "payment_authorized_at": null
    },
    {
        "id": "ps_01HW0J61ZN8J8R52710SQKSRV2",
        "created_at": "2024-04-21T14:50:24.077Z",
        "updated_at": "2024-04-21T15:04:58.516Z",
        "cart_id": "cart_01HW0HZ35BQW6JPM264Y417ATD",
        "provider_id": "stripe-bancontact",
        "is_selected": null,
        "is_initiated": false,
        "status": "pending",
        "data": {},
        "idempotency_key": null,
        "amount": 97818,
        "payment_authorized_at": null
    },
    {
        "id": "ps_01HW0J61ZNYRMZJR2XEPVFPXMV",
        "created_at": "2024-04-21T14:50:24.077Z",
        "updated_at": "2024-04-21T15:04:58.516Z",
        "cart_id": "cart_01HW0HZ35BQW6JPM264Y417ATD",
        "provider_id": "stripe-giropay",
        "is_selected": null,
        "is_initiated": false,
        "status": "pending",
        "data": {},
        "idempotency_key": null,
        "amount": 97818,
        "payment_authorized_at": null
    },
    {
        "id": "ps_01HW0J61ZNNNYWWZWTRAMBSM0C",
        "created_at": "2024-04-21T14:50:24.077Z",
        "updated_at": "2024-04-21T15:04:58.516Z",
        "cart_id": "cart_01HW0HZ35BQW6JPM264Y417ATD",
        "provider_id": "stripe-ideal",
        "is_selected": null,
        "is_initiated": false,
        "status": "pending",
        "data": {},
        "idempotency_key": null,
        "amount": 97818,
        "payment_authorized_at": null
    },
    {
        "id": "ps_01HW0J61ZNK0771STTYGRY98VN",
        "created_at": "2024-04-21T14:50:24.077Z",
        "updated_at": "2024-04-21T15:04:58.516Z",
        "cart_id": "cart_01HW0HZ35BQW6JPM264Y417ATD",
        "provider_id": "stripe-blik",
        "is_selected": null,
        "is_initiated": false,
        "status": "pending",
        "data": {
            "id": "pi_3P81tqLncb1cbHug112IioWx",
            "amount": 97818,
            "object": "payment_intent",
            "review": null,
            "source": null,
            "status": "requires_payment_method",
            "created": 1713711710,
            "invoice": null,
            "currency": "pln",
            "customer": "xxxxx",
            "livemode": false,
            "metadata": {
                "resource_id": "cart_01HW0HZ35BQW6JPM264Y417ATD"
            },
            "shipping": null,
            "processing": null,
            "application": null,
            "canceled_at": null,
            "description": null,
            "next_action": null,
            "on_behalf_of": null,
            "client_secret": "xxx",
            "latest_charge": null,
            "receipt_email": "xxxxx",
            "transfer_data": null,
            "amount_details": {
                "tip": {}
            },
            "capture_method": "automatic",
            "payment_method": null,
            "transfer_group": null,
            "amount_received": 0,
            "amount_capturable": 0,
            "last_payment_error": null,
            "setup_future_usage": null,
            "cancellation_reason": null,
            "confirmation_method": "automatic",
            "payment_method_types": [
                "blik"
            ],
            "statement_descriptor": null,
            "application_fee_amount": null,
            "payment_method_options": {
                "blik": {}
            },
            "automatic_payment_methods": null,
            "statement_descriptor_suffix": null,
            "payment_method_configuration_details": null
        },
        "idempotency_key": null,
        "amount": 97818,
        "payment_authorized_at": null
    },
    {
        "id": "ps_01HW0J61ZN59FZ070R0Q9RG84A",
        "created_at": "2024-04-21T14:50:24.077Z",
        "updated_at": "2024-04-21T15:04:58.516Z",
        "cart_id": "cart_01HW0HZ35BQW6JPM264Y417ATD",
        "provider_id": "stripe-przelewy24",
        "is_selected": null,
        "is_initiated": false,
        "status": "pending",
        "data": {
            "id": "xxx",
            "amount": 97818,
            "object": "payment_intent",
            "review": null,
            "source": null,
            "status": "requires_payment_method",
            "created": 1713711721,
            "invoice": null,
            "currency": "pln",
            "customer": "xxxxx",
            "livemode": false,
            "metadata": {
                "resource_id": "cart_01HW0HZ35BQW6JPM264Y417ATD"
            },
            "shipping": null,
            "processing": null,
            "application": null,
            "canceled_at": null,
            "description": null,
            "next_action": null,
            "on_behalf_of": null,
            "client_secret": "xxx",
            "latest_charge": null,
            "receipt_email": "xxxxx",
            "transfer_data": null,
            "amount_details": {
                "tip": {}
            },
            "capture_method": "automatic",
            "payment_method": null,
            "transfer_group": null,
            "amount_received": 0,
            "amount_capturable": 0,
            "last_payment_error": null,
            "setup_future_usage": null,
            "cancellation_reason": null,
            "confirmation_method": "automatic",
            "payment_method_types": [
                "p24"
            ],
            "statement_descriptor": null,
            "application_fee_amount": null,
            "payment_method_options": {
                "p24": {}
            },
            "automatic_payment_methods": null,
            "statement_descriptor_suffix": null,
            "payment_method_configuration_details": null
        },
        "idempotency_key": null,
        "amount": 97818,
        "payment_authorized_at": null
    },
    {
        "id": "ps_01HW0J61ZNN9M47MB9J2QH44F9",
        "created_at": "2024-04-21T14:50:24.077Z",
        "updated_at": "2024-04-21T15:04:58.516Z",
        "cart_id": "cart_01HW0HZ35BQW6JPM264Y417ATD",
        "provider_id": "stripe",
        "is_selected": true,
        "is_initiated": true,
        "status": "pending",
        "data": {
            "id": "",
            "amount": 97818,
            "object": "payment_intent",
            "review": null,
            "source": null,
            "status": "requires_payment_method",
            "created": 1713711900,
            "invoice": null,
            "currency": "pln",
            "customer": "xxxxx",
            "livemode": false,
            "metadata": {
                "resource_id": "cart_01HW0HZ35BQW6JPM264Y417ATD"
            },
            "shipping": null,
            "processing": null,
            "application": null,
            "canceled_at": null,
            "description": null,
            "next_action": null,
            "on_behalf_of": null,
            "client_secret": "xxx",
            "latest_charge": null,
            "receipt_email": "xxxxx",
            "transfer_data": null,
            "amount_details": {
                "tip": {}
            },
            "capture_method": "manual",
            "payment_method": null,
            "transfer_group": null,
            "amount_received": 0,
            "amount_capturable": 0,
            "last_payment_error": null,
            "setup_future_usage": null,
            "cancellation_reason": null,
            "confirmation_method": "automatic",
            "payment_method_types": [
                "card"
            ],
            "statement_descriptor": null,
            "application_fee_amount": null,
            "payment_method_options": {
                "card": {
                    "network": null,
                    "installments": null,
                    "mandate_options": null,
                    "request_three_d_secure": "automatic"
                }
            },
            "automatic_payment_methods": null,
            "statement_descriptor_suffix": null,
            "payment_method_configuration_details": null
        },
        "idempotency_key": null,
        "amount": 97818,
        "payment_authorized_at": null
    }
]

As you can see some of these have the data object, and some don't, and this is problematic for $medusa.carts.setPaymentSession as this needs a client_secret for my Stripe Elements to load up, so the ones that have data work perfectly fine and the ones that don't obviously throw an error message.

{
    "type": "invalid_data",
    "message": "An error occurred in InitiatePayment during the creation of the stripe payment intent"
}

Unfortunately not much more in the medusa logs.

It is not mentioned in the stripe module docs how to deal with stripe-xxx payment providers,

Any clues?

System information

Medusa version (including plugins): 1.20.4 / stripe: 6.0.9 Node.js version: v21.6.1 Database: Postgre

R-Art-project commented 2 months ago

I think you should validate that your stripe account accepts all the payment methods you are asking for. Or, in effect, that you have them authorized to receive payments in that way.

davidparys commented 2 months ago

I think you should validate that your stripe account accepts all the payment methods you are asking for. Or, in effect, that you have them authorized to receive payments in that way.

Screenshot 2024-04-28 at 13 00 43

I currently have the same stripe account running on a different shop platform and these payment methods are working perfectly fine. I'm starting to think it has something to do with region, but after changing it on medusa it did not affect anything, so I am wondering what could it be.

R-Art-project commented 2 months ago

I have a very similar or the same error. In my case I am implementing stripe but manually not through the plugin. The stripe component is mounted correctly on the front and the payment is made successfully (in stripe). But in Medusa the payment is never authorized and as a consequence the order is never created. I suspect that the fact that the payment is not authorized is related to the error described here. If I find a solution I will post it here

Error in frontend Screenshot 2024-04-30 at 11 42 40 PM

Error in backend:

Screenshot 2024-04-30 at 11 43 56 PM

But payment succeeded 🤯 Screenshot 2024-04-30 at 11 44 38 PM

R-Art-project commented 2 months ago

@davidparys Some update about this issue?

davidparys commented 2 months ago

@davidparys Some update about this issue?

I have at the moment resigned from the providers that did not work I am not sure how to approach this issue.

Your issue seems a little bit more different as medusa needs to know that the payment session has been completed, I suppose there are some stripe.api involved to see if the payment_session has been finished when you call the complete cart function

R-Art-project commented 2 months ago

@davidparys Some update about this issue?

I have at the moment resigned from the providers that did not work I am not sure how to approach this issue.

Your issue seems a little bit more different as medusa needs to know that the payment session has been completed, I suppose there are some stripe.api involved to see if the payment_session has been finished when you call the complete cart function

No, look i have the same problem... I keep investigating Screenshot 2024-05-01 at 10 55 28 PM

R-Art-project commented 2 months ago

@davidparys Can you verify that all paymet providers are installed? is_installed -> true

Screenshot 2024-05-02 at 9 06 13 PM