stripe / stripe-node

Node.js library for the Stripe API.
https://stripe.com
MIT License
3.88k stars 751 forks source link

"Stripe.PaymentIntentCreateParams.PaymentMethodData.Type" does not contain "card" #1161

Closed yilmazbingo closed 3 years ago

yilmazbingo commented 3 years ago
"stripe": "^8.149.0"

node version: v14.15.1

This is the type definiton of "Stripe.PaymentIntentCreateParams.PaymentMethodData.Type"

 type Type =
          | 'acss_debit'
          | 'afterpay_clearpay'
          | 'alipay'
          | 'au_becs_debit'
          | 'bacs_debit'
          | 'bancontact'
          | 'eps'
          | 'fpx'
          | 'giropay'
          | 'grabpay'
          | 'ideal'
          | 'oxxo'
          | 'p24'
          | 'sepa_debit'
          | 'sofort';
      }

I checked the docs to see if something changed, but it shows "card" on enum:

stripe-docs-enum-type

Here is my code:

stripeClient.paymentIntents
    .create({
      amount,
      currency: "USD",
      payment_method_types: ["card"],
      // Type '"card"' is not assignable to type 'Type'
      payment_method_data: { type: "card", card: { token } },
      confirm: true,
    })
    .then((paymentIntent) => {
      response.json(paymentIntent);
    })
    .catch((error) => {
      console.log(error.message);
      response.status(400);
      response.send("Something went wrong with your payment");
    });
};
remi-stripe commented 3 years ago

@yilmazbingo This is by design on our end. Sending raw card details server-side changes your PCI compliance requirements and are harmful to the vast majority of developers and businesses out there. We strongly discourage doing this and instead recommend that you collect card details securely client-side via Elements instead.

Ultimately though, this works if you are already meeting the higher PCI compliance requirements and you can pass card details, it will just be untyped to avoid mistaken adoption by developers.