Skip to content

Commit 0b83ba0

Browse files
remonh87jonasbark
andauthored
* Sync Android with React Native 0.22.1 * Sync iOS with Stripe React Native 0.22.1 * add small data changes for for sync with react native 0.22 * platform pay implementation confirm payment and setup implementation * migrate example app to new platform pay payment methods * add platform pay create payment method * add create paymentmethod from apple pay example * add new platformpaybutton widget * wip add apple pay callbacks * Android: fix casting issues * iOS: update ApplePayButtonView * add stripe sdk instance to apple paybutton * add callbacks to apple pay button * sync iOS with 0.23.0 * sync Android with v0.23.0 * sync with latest react native * create migration doc for platform pay * fix comment for setupinten * Fix pr comments --------- Co-authored-by: Jonas Bark <[email protected]> Co-authored-by: Remon <>
1 parent 1ed0ae8 commit 0b83ba0

File tree

364 files changed

+15440
-6843
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

364 files changed

+15440
-6843
lines changed

docs.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
],
1818
["Financial connections", "/financial_connections" ],
1919
["Troubleshooting", "/troubleshooting"],
20+
["Migration guide platformpay", "/platform_pay_migration"],
2021
["Api Reference", "https://pub.dev/documentation/flutter_stripe/latest/flutter_stripe/flutter_stripe-library.html"]
2122
]
2223
}

docs/platform_pay_migration.mdx

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: Platform pay migration guide
3+
description: Migration guide to platform pay when upgrading to release >v.8.0
4+
---
5+
6+
# `isApplePaySupported` and `isGooglePaySupported`
7+
8+
`isApplePaySupported` and `isGooglePaySupported` have both been replaced by `isPlatformPaySupported`.
9+
10+
`isPlatformPaySupported` requires no parameters, but you _can_ optionally pass in the same parameters in the old method.
11+
12+
```diff
13+
- isGooglePaySupported(myParams);
14+
+ isPlatformPaySupported({googlePay: myParams});
15+
```
16+
17+
# `presentApplePay`, `confirmApplePayPayment`, `initGooglePay`, `presentGooglePay`, and `createGooglePayPaymentMethod`
18+
19+
`presentApplePay`, `confirmApplePayPayment`, `isGooglePaySupported`, `presentGooglePay`, and `createGooglePayPaymentMethod` have been replaced with:
20+
21+
- `confirmPlatformPaySetupIntent` if you use platform pay to confirm setupintent.
22+
- `confirmPlatformPayPayment` if you use platform pay to confirm payment intent
23+
- `createPlatformPayPaymentMethod` if you were use platformpay to create a payment method (this was not possible previously with Apple Pay).
24+
25+
# `updateApplePaySummaryItems`
26+
27+
`updateApplePaySummaryItems` has been replaced with `updatePlatformPaySheet`.
28+
29+
`updatePlatformPaySheet` accepts an parameter `applePay`. When using this, you can pass an object containing your `summaryItems`, `shippingMethods`, and `errors` to be displayed in the Apple Pay sheet to your customer.
30+
31+
# `<GooglePayButton />` and `<ApplePayButton />`
32+
33+
The `GooglePayButton` and `ApplePayButton` components have been replaced with `PlatformPayButton`.

example/lib/screens/card_payments/no_webhook_payment_screen.dart

+1-7
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,7 @@ class _NoWebhookPaymentScreenState extends State<NoWebhookPaymentScreen> {
140140
returnURL: 'flutterstripe://redirect',
141141
);
142142

143-
// todo handle error
144-
/*if (cardActionError) {
145-
Alert.alert(
146-
`Error code: ${cardActionError.code}`,
147-
cardActionError.message
148-
);
149-
} else*/
143+
150144

151145
if (paymentIntent.status == PaymentIntentsStatus.RequiresConfirmation) {
152146
// 5. Call API to confirm intent

example/lib/screens/screens.dart

+10
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import 'others/legacy_token_card_screen.dart';
2929
import 'others/setup_future_payment_screen.dart';
3030
import 'regional_payment_methods/grab_pay_screen.dart';
3131
import 'themes.dart';
32+
import 'wallets/apple_pay_create_payment_method.dart';
3233

3334
class ExampleSection extends StatelessWidget {
3435
final String title;
@@ -162,6 +163,15 @@ class Example extends StatelessWidget {
162163
builder: (c) => ApplePayExternalPluginScreen(),
163164
platformsSupported: [DevicePlatform.ios],
164165
),
166+
Example(
167+
title: 'Apple Pay - Create payment method',
168+
leading: Image.asset(
169+
'assets/apple_pay.png',
170+
width: 48,
171+
),
172+
builder: (c) => ApplePayCreatePaymentMethodScreen(),
173+
platformsSupported: [DevicePlatform.ios],
174+
),
165175
Example(
166176
title: 'Open Apple Pay setup',
167177
leading: Image.asset(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_stripe/flutter_stripe.dart';
3+
import 'package:stripe_example/widgets/example_scaffold.dart';
4+
5+
6+
class ApplePayCreatePaymentMethodScreen extends StatefulWidget {
7+
@override
8+
_ApplePayScreenState createState() => _ApplePayScreenState();
9+
}
10+
11+
class _ApplePayScreenState extends State<ApplePayCreatePaymentMethodScreen> {
12+
@override
13+
void initState() {
14+
Stripe.instance.isPlatformPaySupportedListenable.addListener(update);
15+
super.initState();
16+
}
17+
18+
@override
19+
void dispose() {
20+
Stripe.instance.isPlatformPaySupportedListenable.removeListener(update);
21+
super.dispose();
22+
}
23+
24+
void update() {
25+
setState(() {});
26+
}
27+
28+
@override
29+
Widget build(BuildContext context) {
30+
return ExampleScaffold(
31+
title: 'Apple Pay',
32+
tags: ['iOS'],
33+
padding: EdgeInsets.all(16),
34+
children: [
35+
if (Stripe.instance.isPlatformPaySupportedListenable.value)
36+
PlatformPayButton(
37+
onPressed: _handlePayPress,
38+
)
39+
else
40+
Text('Apple Pay is not available in this device'),
41+
],
42+
);
43+
}
44+
45+
Future<void> _handlePayPress() async {
46+
// 1. create payment method
47+
48+
final paymentMethod = await Stripe.instance.createPlatformPayPaymentMethod(
49+
params: PlatformPayPaymentMethodParams.applePay(
50+
applePayParams: ApplePayParams(
51+
cartItems: [
52+
ApplePayCartSummaryItem.immediate(
53+
label: 'Product Test',
54+
amount: '20.01',
55+
),
56+
],
57+
requiredShippingAddressFields: [
58+
ApplePayContactFieldsType.postalAddress,
59+
],
60+
shippingMethods: [
61+
ApplePayShippingMethod(
62+
identifier: 'free',
63+
detail: 'Arrives by July 2',
64+
label: 'Free Shipping',
65+
amount: '0.0',
66+
),
67+
ApplePayShippingMethod(
68+
identifier: 'standard',
69+
detail: 'Arrives by June 29',
70+
label: 'Standard Shipping',
71+
amount: '3.21',
72+
),
73+
],
74+
merchantCountryCode: 'Es',
75+
currencyCode: 'EUR',
76+
),
77+
applePayPaymentMethodParams: ApplePayPaymentMethodParams(),
78+
),
79+
);
80+
81+
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
82+
content: Text(
83+
'Success!: The payment method with id: ${paymentMethod.id} was created successfully,')));
84+
}
85+
}

example/lib/screens/wallets/apple_pay_screen.dart

+78-50
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'dart:convert';
22

3-
import 'package:flutter/foundation.dart';
43
import 'package:flutter/material.dart';
54
import 'package:flutter_stripe/flutter_stripe.dart';
65
import 'package:http/http.dart' as http;
@@ -14,15 +13,37 @@ class ApplePayScreen extends StatefulWidget {
1413
}
1514

1615
class _ApplePayScreenState extends State<ApplePayScreen> {
16+
final items = [
17+
ApplePayCartSummaryItem.immediate(
18+
label: 'Product Test',
19+
amount: '0.01',
20+
)
21+
];
22+
23+
final shippingMethods = [
24+
ApplePayShippingMethod(
25+
identifier: 'free',
26+
detail: 'Arrives by July 2',
27+
label: 'Free Shipping',
28+
amount: '0.0',
29+
),
30+
ApplePayShippingMethod(
31+
identifier: 'standard',
32+
detail: 'Arrives by June 29',
33+
label: 'Standard Shipping',
34+
amount: '3.21',
35+
)
36+
];
37+
1738
@override
1839
void initState() {
19-
Stripe.instance.isApplePaySupported.addListener(update);
40+
Stripe.instance.isPlatformPaySupportedListenable.addListener(update);
2041
super.initState();
2142
}
2243

2344
@override
2445
void dispose() {
25-
Stripe.instance.isApplePaySupported.removeListener(update);
46+
Stripe.instance.isPlatformPaySupportedListenable.removeListener(update);
2647
super.dispose();
2748
}
2849

@@ -37,65 +58,71 @@ class _ApplePayScreenState extends State<ApplePayScreen> {
3758
tags: ['iOS'],
3859
padding: EdgeInsets.all(16),
3960
children: [
40-
if (Stripe.instance.isApplePaySupported.value)
41-
ApplePayButton(
42-
onPressed: _handlePayPress,
61+
if (Stripe.instance.isPlatformPaySupportedListenable.value)
62+
PlatformPayButton(
63+
onDidSetShippingContact: (contact) {
64+
debugPrint('Shipping contact updated $contact');
65+
66+
// Mandatory after entering a shipping contact
67+
Stripe.instance.updatePlatformSheet(
68+
params: PlatformPaySheetUpdateParams.applePay(
69+
summaryItems: items,
70+
shippingMethods: shippingMethods,
71+
errors: [],
72+
),
73+
);
74+
},
75+
onShippingMethodSelected: (method) {
76+
debugPrint('Shipping contact updated $method');
77+
78+
Stripe.instance.updatePlatformSheet(
79+
params: PlatformPaySheetUpdateParams.applePay(
80+
summaryItems: items,
81+
shippingMethods: shippingMethods,
82+
errors: [],
83+
),
84+
);
85+
},
86+
type: PlatformButtonType.buy,
87+
appearance: PlatformButtonStyle.whiteOutline,
88+
onPressed: () => _handlePayPress(
89+
summaryItems: items,
90+
shippingMethods: shippingMethods,
91+
),
4392
)
4493
else
4594
Text('Apple Pay is not available in this device'),
4695
],
4796
);
4897
}
4998

50-
Future<void> _handlePayPress() async {
99+
Future<void> _handlePayPress({
100+
required List<ApplePayCartSummaryItem> summaryItems,
101+
required List<ApplePayShippingMethod> shippingMethods,
102+
}) async {
51103
try {
52-
// 1. Present Apple Pay sheet
53-
await Stripe.instance.presentApplePay(
54-
params: ApplePayPresentParams(
55-
cartItems: [
56-
ApplePayCartSummaryItem.immediate(
57-
label: 'Product Test',
58-
amount: '0.01',
59-
),
60-
],
61-
requiredShippingAddressFields: [
62-
ApplePayContactFieldsType.postalAddress,
63-
],
64-
shippingMethods: [
65-
ApplePayShippingMethod(
66-
identifier: 'free',
67-
detail: 'Arrives by July 2',
68-
label: 'Free Shipping',
69-
amount: '0.0',
70-
),
71-
ApplePayShippingMethod(
72-
identifier: 'standard',
73-
detail: 'Arrives by June 29',
74-
label: 'Standard Shipping',
75-
amount: '3.21',
76-
),
77-
],
78-
country: 'Es',
79-
currency: 'EUR',
80-
),
81-
onDidSetShippingContact: (contact) {
82-
if (kDebugMode) {
83-
print('shipping contact provided $contact ');
84-
}
85-
},
86-
onDidSetShippingMethod: (method) {
87-
if (kDebugMode) {
88-
print('shipping method provided $method ');
89-
}
90-
},
91-
);
92-
93-
// 2. fetch Intent Client Secret from backend
104+
// 1. fetch Intent Client Secret from backend
94105
final response = await fetchPaymentIntentClientSecret();
95106
final clientSecret = response['clientSecret'];
96107

97108
// 2. Confirm apple pay payment
98-
await Stripe.instance.confirmApplePayPayment(clientSecret);
109+
await Stripe.instance.confirmPlatformPayPaymentIntent(
110+
clientSecret: clientSecret,
111+
confirmParams: PlatformPayConfirmParams.applePay(
112+
applePay: ApplePayParams(
113+
cartItems: items,
114+
requiredShippingAddressFields: [
115+
ApplePayContactFieldsType.name,
116+
ApplePayContactFieldsType.postalAddress,
117+
ApplePayContactFieldsType.emailAddress,
118+
ApplePayContactFieldsType.phoneNumber,
119+
],
120+
shippingMethods: shippingMethods,
121+
merchantCountryCode: 'Es',
122+
currencyCode: 'EUR',
123+
),
124+
),
125+
);
99126
ScaffoldMessenger.of(context).showSnackBar(
100127
const SnackBar(
101128
content: Text('Apple Pay payment succesfully completed')),
@@ -104,6 +131,7 @@ class _ApplePayScreenState extends State<ApplePayScreen> {
104131
ScaffoldMessenger.of(context).showSnackBar(
105132
SnackBar(content: Text('Error: $e')),
106133
);
134+
rethrow;
107135
}
108136
}
109137

example/lib/screens/wallets/google_pay_screen.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class _GooglePayScreenState extends State<GooglePayScreen> {
8181
final token =
8282
paymentResult['paymentMethodData']['tokenizationData']['token'];
8383
final tokenJson = Map.castFrom(json.decode(token));
84-
print(tokenJson);
84+
debugPrint(tokenJson.toString());
8585

8686
final params = PaymentMethodParams.cardFromToken(
8787
paymentMethodData: PaymentMethodDataCardFromToken(

0 commit comments

Comments
 (0)