Search code examples
stripe-paymentstokenrecurringcard

Stripe recurring payment integrate with masterpass


Is there any way to take recurring payment with Masterpass using Stripe?

Google pay and Apple pay can take the recurring payment with Stripe by returning the card token for stripe process. Is there any way to get card token like this with Masterpass?


Solution

  • Yes you can, you'd create a PaymentMethod with the data you get back from Secure Remote Commerce (which is what Masterpass is calling itself now) and use that to start a subscription.

    Follow Stripe's SRC guide, then when you get to the "complete the payment" part you'd do something this instead:

      // create the payment method
      const pm = await stripe.paymentMethods.create({
        type: 'card',
        card: {
          masterpass: {
            cart_id: cartId, // your unique cart ID
            transaction_id: req.query.oauth_verifier, // get this from the SRC callback URL
          },
        }
      });
    
      // create the Stripe customer
      const cust = await stripe.customers.create({
        payment_method: pm.id,
      });
    
      // create the subscription
      const sub = await stripe.subscriptions.create({
        customer: cust.id,
        items: [{
          price: {{PRICE_ID}},
        }],
        default_payment_method: pm.id,
      });