Saleor: Stripe - A token may not be passed in as a PaymentMethod. Instead, use payment_method_data with type=card and card[token]

Created on 18 Jun 2020  路  4Comments  路  Source: mirumee/saleor

What I'm trying to achieve

Complete a checkout with Stripe as the payment method.

Steps to reproduce the problem

  1. Add keys to Stripe plugin
  2. Retrieve token via StripeJS/Elements
  3. Mutation createCheckoutPayment(...)
  4. Mutation completeCheckout(...)

What I expected to happen

Checkout to be completed, instead it throws an error

Screenshots

image

System information
Operating system:
MacOS Cataline 10.15.5
Running Saleor with Docker

bug

Most helpful comment

I'll be happy to submit a PR to resolve this if it is indeed a bug, what I did as a workaround was to modify the PaymentIntent creation arguments in saleor/payment/gateways/stripe/__init__.py to:

intent = client.PaymentIntent.create(
    payment_method_data=dict(
        type="card",
        card=dict(
            token=payment_information.token
        )
    ),
    ...
)

This change allowed it to be accepted by Stripe.

All 4 comments

I'll be happy to submit a PR to resolve this if it is indeed a bug, what I did as a workaround was to modify the PaymentIntent creation arguments in saleor/payment/gateways/stripe/__init__.py to:

intent = client.PaymentIntent.create(
    payment_method_data=dict(
        type="card",
        card=dict(
            token=payment_information.token
        )
    ),
    ...
)

This change allowed it to be accepted by Stripe.

Hi @thomasjiangcy,

Which version of Saleor are you using? I've just tested it with our storefront and everything works correctly. Please send exact mutation with input variables that cause the problem.

Hi I used the latest version of Saleor, and I'm experieincing the same issue version 2.10, I get the same error....

We're also experiencing this checkoutError on 2.10. It's happening after we call the checkoutComplete mutation with a valid checkoutId, which is being called after we await a call to checkoutPaymentCreate which contains a token that we've previously obtained from Stripe.

The specific error we're receiving is A token may not be passed in as a PaymentMethod. Instead, use payment_method_data with type=card and card[token]=<% our_valid_stripe_token_here %>.

Here's our checkoutPaymentCreate mutation:

export const CHECKOUT_PAYMENT_CREATE_MUTATION = gql`
  mutation CHECKOUT_PAYMENT_CREATE_MUTATION(
    $checkoutId: ID!
    $gateway: String!
    $token: String!
    $amount: Decimal!
  ) {
    checkoutPaymentCreate(
      checkoutId: $checkoutId
      input: { gateway: $gateway, token: $token, amount: $amount }
    ) {
      payment {
        id
        chargeStatus
      }
      paymentErrors {
        field
        message
      }
    }
  }
`;

@IKarbowiak I had a look through the release notes and didn't find mention of a fix for this. When you tested, on which version did you run your tests?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ranjanprj picture ranjanprj  路  3Comments

NumanIjaz picture NumanIjaz  路  3Comments

Pacu2 picture Pacu2  路  4Comments

timuric picture timuric  路  3Comments

Pacu2 picture Pacu2  路  3Comments