Skip to content

Commit 41540fc

Browse files
remonh87jonasbark
andauthored
Sync (#1491)
* Sync Android with v0.35 * Sync iOS to v0.35 * chore: upgrade to latest flutter version * fix: sync with stripe 0.35 sdk * fix: add revolut pay screen * revert stripe checkout fix * fix: several bugfixes --------- Co-authored-by: Jonas Bark <[email protected]> Co-authored-by: Remon <[email protected]>
1 parent 5153d87 commit 41540fc

File tree

290 files changed

+5140
-7225
lines changed

Some content is hidden

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

290 files changed

+5140
-7225
lines changed

example/assets/revolut.png

5.74 KB
Loading
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import 'dart:convert';
2+
3+
import 'package:flutter/material.dart';
4+
import 'package:flutter_stripe/flutter_stripe.dart';
5+
import 'package:http/http.dart' as http;
6+
import 'package:stripe_example/widgets/example_scaffold.dart';
7+
import 'package:stripe_example/widgets/loading_button.dart';
8+
9+
import '../../config.dart';
10+
11+
class RevolutPayScreen extends StatelessWidget {
12+
const RevolutPayScreen({Key? key}) : super(key: key);
13+
14+
Future<Map<String, dynamic>> _createPaymentIntent() async {
15+
final url = Uri.parse('$kApiUrl/create-payment-intent');
16+
final response = await http.post(
17+
url,
18+
headers: {
19+
'Content-Type': 'application/json',
20+
},
21+
body: json.encode({
22+
'currency': 'eur',
23+
'payment_method_types': ['revolut_pay'],
24+
'amount': 1099
25+
}),
26+
);
27+
28+
return json.decode(response.body);
29+
}
30+
31+
Future<void> _pay(BuildContext context) async {
32+
// Precondition:
33+
//Make sure to have set a custom URI scheme in your app and add it to Stripe SDK
34+
// see file main.dart in this example app.
35+
// 1. on the backend create a payment intent for payment method and save the
36+
// client secret.
37+
final result = await _createPaymentIntent();
38+
print('blaat $result');
39+
final clientSecret = await result['clientSecret'];
40+
41+
// 2. use the client secret to confirm the payment and handle the result.
42+
try {
43+
await Stripe.instance.confirmPayment(
44+
paymentIntentClientSecret: clientSecret,
45+
data: PaymentMethodParams.revolutPay(
46+
paymentMethodData: PaymentMethodData(),
47+
),
48+
);
49+
50+
ScaffoldMessenger.of(context).showSnackBar(
51+
SnackBar(
52+
content: Text('Payment succesfully completed'),
53+
),
54+
);
55+
} on Exception catch (e, s) {
56+
throw e;
57+
if (e is StripeException) {
58+
ScaffoldMessenger.of(context).showSnackBar(
59+
SnackBar(
60+
content: Text(
61+
'Error from Stripe: ${e.error.localizedMessage ?? e.error.code}'),
62+
),
63+
);
64+
} else {
65+
ScaffoldMessenger.of(context).showSnackBar(
66+
SnackBar(
67+
content: Text('Unforeseen error: ${e}'),
68+
),
69+
);
70+
}
71+
}
72+
}
73+
74+
@override
75+
Widget build(BuildContext context) {
76+
return ExampleScaffold(
77+
title: 'RevolutPay',
78+
tags: ['Payment method'],
79+
padding: EdgeInsets.all(16),
80+
children: [
81+
LoadingButton(
82+
onPressed: () async {
83+
await _pay(context);
84+
},
85+
text: 'Pay',
86+
),
87+
],
88+
);
89+
}
90+
}

example/lib/screens/screens.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'package:stripe_example/screens/regional_payment_methods/fpx_screen.dart'
1212
import 'package:stripe_example/screens/regional_payment_methods/ideal_screen.dart';
1313
import 'package:stripe_example/screens/regional_payment_methods/klarna_screen.dart';
1414
import 'package:stripe_example/screens/regional_payment_methods/paypal_screen.dart';
15+
import 'package:stripe_example/screens/regional_payment_methods/revolutpay_screen.dart';
1516
import 'package:stripe_example/screens/regional_payment_methods/sofort_screen.dart';
1617
import 'package:stripe_example/screens/regional_payment_methods/us_bank_account.dart';
1718
import 'package:stripe_example/screens/wallets/apple_pay_screen.dart';
@@ -296,6 +297,15 @@ class Example extends StatelessWidget {
296297
builder: (contex) => PayPalScreen(),
297298
platformsSupported: [DevicePlatform.android, DevicePlatform.ios],
298299
),
300+
Example(
301+
title: 'RevolutPay',
302+
leading: Image.asset(
303+
'assets/revolut.png',
304+
width: 48,
305+
),
306+
builder: (context) => RevolutPayScreen(),
307+
platformsSupported: [DevicePlatform.android, DevicePlatform.ios],
308+
),
299309
Example(
300310
title: 'Us bank accounts (ACH)',
301311
builder: (contex) => UsBankAccountScreen(),

packages/stripe/lib/src/widgets/apple_pay_button.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ApplePayButton extends StatelessWidget {
1717
Key? key,
1818
this.style = PlatformButtonStyle.automatic,
1919
this.type = PlatformButtonType.plain,
20-
this.cornerRadius = 4.0,
20+
this.cornerRadius=4,
2121
this.onPressed,
2222
double? width,
2323
double? height = _kApplePayButtonDefaultHeight,
@@ -50,7 +50,7 @@ class ApplePayButton extends StatelessWidget {
5050
/// Modifies the **corner radius** of the payment button.
5151
/// To remove the rounded courners, set this value to 0.0.
5252
/// The default value is set to 4.0
53-
final double cornerRadius;
53+
final int cornerRadius;
5454

5555
/// Callback that is executed when the button is pressed.
5656
final VoidCallback? onPressed;
@@ -116,7 +116,7 @@ class _UiKitApplePayButton extends StatefulWidget {
116116
Key? key,
117117
required this.style,
118118
required this.type,
119-
this.cornerRadius = 4.0,
119+
this.cornerRadius = 4,
120120
this.onPressed,
121121
this.onShippingContactSelected,
122122
this.onCouponCodeEntered,
@@ -126,7 +126,7 @@ class _UiKitApplePayButton extends StatefulWidget {
126126

127127
final PlatformButtonStyle style;
128128
final PlatformButtonType type;
129-
final double cornerRadius;
129+
final int cornerRadius;
130130
final VoidCallback? onPressed;
131131
final OnDidSetShippingContact? onShippingContactSelected;
132132
final OnDidSetShippingMethod? onShippingMethodSelected;

packages/stripe/lib/src/widgets/google_pay_button.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class GooglePayButton extends StatefulWidget {
1010
required this.onTap,
1111
this.type = GooglePayButtonType.pay,
1212
this.buttonType = PlatformButtonType.pay,
13+
this.borderRadius,
14+
this.appearance = PlatformButtonStyle.automatic,
1315
Key? key,
1416
}) : super(key: key);
1517

@@ -22,6 +24,8 @@ class GooglePayButton extends StatefulWidget {
2224
@Deprecated('Use [buttonType] instead')
2325
final GooglePayButtonType type;
2426

27+
final int? borderRadius;
28+
final PlatformButtonStyle appearance;
2529
final PlatformButtonType buttonType;
2630
final VoidCallback onTap;
2731
}
@@ -35,7 +39,8 @@ class _GooglePayButtonState extends State<GooglePayButton> {
3539
// ignore: deprecated_member_use_from_same_package
3640
_creationParams['buttonType'] = widget.type.name;
3741
_creationParams['type'] = widget.buttonType.id;
38-
42+
_creationParams['appearance'] = widget.appearance.id;
43+
_creationParams['borderRadius'] = widget.borderRadius;
3944
super.initState();
4045
}
4146

packages/stripe/lib/src/widgets/platform_pay_button.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class PlatformPayButton extends StatelessWidget {
1616
super.key,
1717
this.type = PlatformButtonType.plain,
1818
this.appearance = PlatformButtonStyle.automatic,
19-
this.borderRadius = 4.0,
19+
this.borderRadius = 4,
2020
this.constraints,
2121
this.onShippingContactSelected,
2222
this.onCouponCodeEntered,
@@ -27,11 +27,11 @@ class PlatformPayButton extends StatelessWidget {
2727
/// Defines the displayed text on the button.
2828
final PlatformButtonType type;
2929

30-
/// iOS only, defines the color and border radius of the button
30+
/// Defines the coloring of the button
3131
final PlatformButtonStyle appearance;
3232

33-
/// iOS only, sets the border radius of the corners.
34-
final double borderRadius;
33+
/// Sets the border radius of the corners.
34+
final int borderRadius;
3535

3636
/// ios only, execute a callback when shipping
3737
@@ -72,6 +72,7 @@ class PlatformPayButton extends StatelessWidget {
7272
return GooglePayButton(
7373
onTap: onPressed,
7474
buttonType: type,
75+
borderRadius: borderRadius,
7576
);
7677
} else if (Platform.isIOS) {
7778
return ApplePayButton(

packages/stripe_android/android/build.gradle

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version '1.0-SNAPSHOT'
33

44
buildscript {
55
ext.kotlin_version = '1.8.0'
6-
ext.stripe_version = '20.31.+'
6+
ext.stripe_version = '20.34.+'
77

88
repositories {
99
google()
@@ -48,15 +48,19 @@ dependencies {
4848
implementation 'com.github.bumptech.glide:glide:4.12.0'
4949

5050
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.4.1"
51-
implementation "com.stripe:stripe-android:$stripe_version"
52-
implementation "com.stripe:financial-connections:$stripe_version"
51+
implementation("com.stripe:stripe-android:$stripe_version") {
52+
exclude group: 'androidx.emoji2', module: 'emoji2'
53+
}
54+
implementation ("com.stripe:financial-connections:$stripe_version") {
55+
exclude group: 'androidx.emoji2', module: 'emoji2'
56+
}
5357
implementation 'com.google.android.material:material:1.6.0'
5458
implementation 'androidx.appcompat:appcompat:1.4.1'
5559
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
5660
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4'
5761

5862
// play-services-wallet is already included in stripe-android
59-
compileOnly "com.google.android.gms:play-services-wallet:19.1.0"
63+
compileOnly "com.google.android.gms:play-services-wallet:19.2.0"
6064

6165
// Users need to declare this dependency on their own, otherwise all methods are a no-op
6266
compileOnly 'com.stripe:stripe-android-issuing-push-provisioning:1.1.0'

packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeSdkGooglePayButtonPlatformView.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ class StripeSdkGooglePayButtonPlatformView(
3131
if (creationParams?.containsKey("type") == true) {
3232
googlePayButtonManager.type(payButton, creationParams["type"] as Int)
3333
}
34+
if (creationParams?.containsKey("appearance") == true) {
35+
googlePayButtonManager.appearance(payButton, creationParams["appearance"] as Int)
36+
}
37+
if (creationParams?.containsKey("borderRadius") == true) {
38+
googlePayButtonManager.borderRadius(payButton, creationParams["borderRadius"] as Int)
39+
}
3440
payButton.initialize()
3541
payButton.getChildAt(0).setOnClickListener {
3642
channel.invokeMethod("onPressed", null)

packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/GooglePayButtonManager.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ class GooglePayButtonManager : SimpleViewManager<GooglePayButtonView?>() {
2020
view.setType(buttonType)
2121
}
2222

23+
@ReactProp(name = "appearance")
24+
fun appearance(view: GooglePayButtonView, appearance: Int) {
25+
view.setAppearance(appearance)
26+
}
27+
28+
@ReactProp(name = "borderRadius")
29+
fun borderRadius(view: GooglePayButtonView, borderRadius: Int) {
30+
view.setBorderRadius(borderRadius)
31+
}
32+
2333
override fun createViewInstance(reactContext: ThemedReactContext): GooglePayButtonView {
2434
return GooglePayButtonView(reactContext)
2535
}

0 commit comments

Comments
 (0)