I am testing handling payments using Google Pay, and I use the pay package for this.
I made a simple app and set it for the test environment, I have now a working Google Pay button, which shows the sheet to fill with the card information.
I am using this button code:
GooglePayButton(
paymentConfigurationAsset:
'default_payment_profile_google_pay.json',
paymentItems: _paymentItems,
type: GooglePayButtonType.buy,
margin: const EdgeInsets.only(top: 15.0),
onPaymentResult: (Map<String, dynamic> paymentResult) {
print(paymentResult); // The question starts here
},
loadingIndicator: const Center(
child: CircularProgressIndicator(),
),
),
and the default_payment_profile_google_pay.json
contains this:
{
"provider": "google_pay",
"data": {
"environment": "TEST",
"apiVersion": 2,
"apiVersionMinor": 0,
"allowedPaymentMethods": [
{
"type": "CARD",
"tokenizationSpecification": {
"type": "PAYMENT_GATEWAY",
"parameters": {
"gateway": "example",
"gatewayMerchantId": "gatewayMerchantId"
}
},
"parameters": {
"allowedCardNetworks": ["VISA", "MASTERCARD"],
"allowedAuthMethods": ["PAN_ONLY", "CRYPTOGRAM_3DS"],
"billingAddressRequired": true,
"billingAddressParameters": {
"format": "FULL",
"phoneNumberRequired": true
}
}
}
],
"merchantInfo": {
"merchantId": "01234567890123456789",
"merchantName": "Example Merchant Name"
},
"transactionInfo": {
"countryCode": "US",
"currencyCode": "USD"
}
}
}
the onPaymentResult
method will print the response triggered after the payment is done, it’s Map<String, dynamic>
.
I am using the test suite provided by Google Pay, after a successful payment, the response is this:
{
"apiVersionMinor": "0",
"apiVersion": "2",
"paymentMethodData": {
"description": "Mastercard •••• 4444",
"tokenizationData": {
"type": "PAYMENT_GATEWAY",
"token": "examplePaymentMethodToken"
},
"type": "CARD",
"info": {
"cardNetwork": "MASTERCARD",
"cardDetails": "4444",
"billingAddress": {
"phoneNumber": "+1 650-555-5555",
"address3": "",
"sortingCode": "",
"address2": "",
"countryCode": "US",
"address1": "1600 Amphitheatre Parkway",
"postalCode": "94043",
"name": "Card Holder Name",
"locality": "Mountain View",
"administrativeArea": "CA"
}
}
}
}
My question is:
What should I do now to complete the payment process, where should I see the payments or manage them?
I have no experience dealing with payments, so any pieces of information or ways of what I should do from this point is really really welcome.
2
Answers
From there, you have to use a payment processor to process your payment. A good example is Stripe. You can do it by using this plugin flutter_stripe then using something like this (From the plugin description)
}
Of course you have to get a Stripe account and so and so
Inside the onGooglePayResult method, you can use this:
I was having trouble with the accepted answer because the [‘paymentMethodData’][‘tokenizationData’][‘token’] was returning "examplePaymentMethodToken" which was breaking decoding