flutter_stripe_payment
flutter_stripe_payment copied to clipboard
How to create payment intent method Gpay and Apple Pay
The native payment method in the package example returns a token. How can I post this token value to the stripe panel ?
Native paymet method function
onPressed: () {
if (Platform.isIOS) {
_controller.jumpTo(450);
}
StripePayment.paymentRequestWithNativePay(
androidPayOptions: AndroidPayPaymentRequest(
totalPrice: "1.20",
currencyCode: "EUR",
),
applePayOptions: ApplePayPaymentOptions(
countryCode: 'DE',
currencyCode: 'EUR',
items: [
ApplePayItem(
label: 'Test',
amount: '13',
)
],
),
).then((token) {
setState(() {
_scaffoldKey.currentState.showSnackBar(SnackBar(content: Text('Received ${token.tokenId}')));
_paymentToken = token;
});
}).catchError(setError);
},
),
An helpful approach would be attaching the source to a customer object.
final response0 = await Dio().post(
'https://api.stripe.com/v1/customers/${context.read<UserModel>().stripeAccount}/sources',
data: {'source': token.tokenId},
options: authHeaderSecret());
final response = await Dio().post('https://api.stripe.com/v1/charges',
data: {
//'source': token.tokenId,
'currency': 'EUR',
'amount': 100,
'customer': context.read<UserModel>().stripeAccount
},
options: authHeaderSecret());