0
votes

I have set up the Google Pay button on my page by following Google Pay documentation, but i got stuck in the last step where i need to send the token response from Google Pay to Stripe as the Google Pay document describe.

To execute the payment, the backend processes the purchase and sends the payment token to the payment service provider.

I have search the Stripe documentation but can't seem to find how to use that token but instead they show me how to use Stripe Payment Request Button to integrate Google Pay. So, does stripe support token from Google Pay api or do i need to use Stripe Payment Request Button to integrate with Google Pay?

1

1 Answers

1
votes

You can do either and you don't / shouldn't mix the two approach

Based on the Stripe doc here You can either use

  1. Stripe's PaymentRequestButton
  2. OR you can integrate with Google Pay directly using Stripe as a gateway. See how to do it here; in Step 2 of the tutorial, search stripe to find the gateway configurations
const tokenizationSpecification = {
  type: 'PAYMENT_GATEWAY',
  parameters: {
    "gateway": "stripe"
    "stripe:version": "2018-10-31" // your stripe API version
    "stripe:publishableKey": "pk_test_xxxx" // your stripe publishable key
  }
};

For option 2, you will basically get a Stripe token like this tok_xxxx represent the GooglePay wallet from paymentData.paymentMethodData.tokenizationData.token, and you can use the token directly with Stripe API using your Stripe's secret key sk_test_xxxx e.g. create a charge following this

const stripe = require('stripe')('sk_test_xxxxx');

const charge = await stripe.charges.create({
  amount: 2000,
  currency: 'usd',
  source: 'tok_obtained_from_google_pay_api', 
  description: 'My First Test Charge (created for API docs)',
});

FYI token/charge API is no longer recommended, you can create a payment_method from the token like this

const paymentMethod = await stripe.paymentMethods.create({
  type: 'card',
  card: {
    token: 'tok_xxxxx',
  },
});

and use it with Stripe PaymentIntent API