GooglePayButton when clicked does not show the sheet to fill or choose payment details.
In the Console getting this when button clicked:
Console
I am using pay: ^2.0.0 to make use of gpay. The code for gpay button is:
<code>FutureBuilder<PaymentConfiguration>(
future: _googlePayConfigFuture,
builder: (context, snapshot) => snapshot.hasData
? GooglePayButton(
paymentConfiguration: snapshot.data!,
paymentItems: paymentItems,
type: GooglePayButtonType.pay,
theme: GooglePayButtonTheme.light,
width: double.maxFinite,
margin: const EdgeInsets.only(top: 15.0),
onPaymentResult: (data){
print(data);
},
loadingIndicator: const Center(
child: CircularProgressIndicator(),
),
)
: const SizedBox.shrink()),
</code>
<code>FutureBuilder<PaymentConfiguration>(
future: _googlePayConfigFuture,
builder: (context, snapshot) => snapshot.hasData
? GooglePayButton(
paymentConfiguration: snapshot.data!,
paymentItems: paymentItems,
type: GooglePayButtonType.pay,
theme: GooglePayButtonTheme.light,
width: double.maxFinite,
margin: const EdgeInsets.only(top: 15.0),
onPaymentResult: (data){
print(data);
},
loadingIndicator: const Center(
child: CircularProgressIndicator(),
),
)
: const SizedBox.shrink()),
</code>
FutureBuilder<PaymentConfiguration>(
future: _googlePayConfigFuture,
builder: (context, snapshot) => snapshot.hasData
? GooglePayButton(
paymentConfiguration: snapshot.data!,
paymentItems: paymentItems,
type: GooglePayButtonType.pay,
theme: GooglePayButtonTheme.light,
width: double.maxFinite,
margin: const EdgeInsets.only(top: 15.0),
onPaymentResult: (data){
print(data);
},
loadingIndicator: const Center(
child: CircularProgressIndicator(),
),
)
: const SizedBox.shrink()),
_googlePayConfigFuture used in paymentConfiguration:
<code>late final Future<PaymentConfiguration> _googlePayConfigFuture;
@override
void initState() {
paymentItems.add(PaymentItem(amount: '${retrievePaymentAmount}', label: "Bin", status: PaymentItemStatus.final_price));
super.initState();
_googlePayConfigFuture =
PaymentConfiguration.fromAsset('gpay.json');
}
</code>
<code>late final Future<PaymentConfiguration> _googlePayConfigFuture;
@override
void initState() {
paymentItems.add(PaymentItem(amount: '${retrievePaymentAmount}', label: "Bin", status: PaymentItemStatus.final_price));
super.initState();
_googlePayConfigFuture =
PaymentConfiguration.fromAsset('gpay.json');
}
</code>
late final Future<PaymentConfiguration> _googlePayConfigFuture;
@override
void initState() {
paymentItems.add(PaymentItem(amount: '${retrievePaymentAmount}', label: "Bin", status: PaymentItemStatus.final_price));
super.initState();
_googlePayConfigFuture =
PaymentConfiguration.fromAsset('gpay.json');
}
Here is gpay.json file which is in assets.
<code>{
"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"
}
}
}
</code>
<code>{
"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"
}
}
}
</code>
{
"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"
}
}
}
New contributor
Sushant Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.