Skip to content

Commit

Permalink
Sync (#1491)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Nov 28, 2023
1 parent 5153d87 commit 41540fc
Show file tree
Hide file tree
Showing 290 changed files with 5,140 additions and 7,225 deletions.
Binary file added example/assets/revolut.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import 'dart:convert';

Check warning on line 1 in example/lib/screens/regional_payment_methods/revolutpay_screen.dart

View workflow job for this annotation

GitHub Actions / Typo CI

Filename: example/lib/screens/regional_payment_methods/revolutpay_screen.dart

"revolutpay" in the filename is a typo. Did you mean "revolutionary"?

import 'package:flutter/material.dart';
import 'package:flutter_stripe/flutter_stripe.dart';
import 'package:http/http.dart' as http;
import 'package:stripe_example/widgets/example_scaffold.dart';
import 'package:stripe_example/widgets/loading_button.dart';

import '../../config.dart';

class RevolutPayScreen extends StatelessWidget {

Check warning on line 11 in example/lib/screens/regional_payment_methods/revolutpay_screen.dart

View workflow job for this annotation

GitHub Actions / Typo CI

RevolutPayScreen

"RevolutPayScreen" is a typo. Did you mean "RevoltPayScreen"?
const RevolutPayScreen({Key? key}) : super(key: key);

Check warning on line 12 in example/lib/screens/regional_payment_methods/revolutpay_screen.dart

View workflow job for this annotation

GitHub Actions / Typo CI

RevolutPayScreen

"RevolutPayScreen" is a typo. Did you mean "RevoltPayScreen"?

Future<Map<String, dynamic>> _createPaymentIntent() async {
final url = Uri.parse('$kApiUrl/create-payment-intent');
final response = await http.post(
url,
headers: {
'Content-Type': 'application/json',
},
body: json.encode({
'currency': 'eur',
'payment_method_types': ['revolut_pay'],
'amount': 1099
}),
);

return json.decode(response.body);
}

Future<void> _pay(BuildContext context) async {
// Precondition:
//Make sure to have set a custom URI scheme in your app and add it to Stripe SDK
// see file main.dart in this example app.
// 1. on the backend create a payment intent for payment method and save the
// client secret.
final result = await _createPaymentIntent();
print('blaat $result');

Check warning on line 38 in example/lib/screens/regional_payment_methods/revolutpay_screen.dart

View workflow job for this annotation

GitHub Actions / Typo CI

blaat

"blaat" is a typo. Did you mean "blast"?
final clientSecret = await result['clientSecret'];

// 2. use the client secret to confirm the payment and handle the result.
try {
await Stripe.instance.confirmPayment(
paymentIntentClientSecret: clientSecret,
data: PaymentMethodParams.revolutPay(

Check warning on line 45 in example/lib/screens/regional_payment_methods/revolutpay_screen.dart

View workflow job for this annotation

GitHub Actions / Typo CI

revolutPay

"revolutPay" is a typo. Did you mean "revoltPay"?
paymentMethodData: PaymentMethodData(),
),
);

ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Payment succesfully completed'),

Check warning on line 52 in example/lib/screens/regional_payment_methods/revolutpay_screen.dart

View workflow job for this annotation

GitHub Actions / Typo CI

succesfully

"succesfully" is a typo. Did you mean "successfully"?
),
);
} on Exception catch (e, s) {
throw e;
if (e is StripeException) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'Error from Stripe: ${e.error.localizedMessage ?? e.error.code}'),
),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Unforeseen error: ${e}'),
),
);
}
}
}

@override
Widget build(BuildContext context) {
return ExampleScaffold(
title: 'RevolutPay',

Check warning on line 77 in example/lib/screens/regional_payment_methods/revolutpay_screen.dart

View workflow job for this annotation

GitHub Actions / Typo CI

RevolutPay

"RevolutPay" is a typo. Did you mean "RevoltPay"?
tags: ['Payment method'],
padding: EdgeInsets.all(16),
children: [
LoadingButton(
onPressed: () async {
await _pay(context);
},
text: 'Pay',
),
],
);
}
}
10 changes: 10 additions & 0 deletions example/lib/screens/screens.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:stripe_example/screens/regional_payment_methods/fpx_screen.dart'
import 'package:stripe_example/screens/regional_payment_methods/ideal_screen.dart';
import 'package:stripe_example/screens/regional_payment_methods/klarna_screen.dart';
import 'package:stripe_example/screens/regional_payment_methods/paypal_screen.dart';
import 'package:stripe_example/screens/regional_payment_methods/revolutpay_screen.dart';
import 'package:stripe_example/screens/regional_payment_methods/sofort_screen.dart';
import 'package:stripe_example/screens/regional_payment_methods/us_bank_account.dart';
import 'package:stripe_example/screens/wallets/apple_pay_screen.dart';
Expand Down Expand Up @@ -296,6 +297,15 @@ class Example extends StatelessWidget {
builder: (contex) => PayPalScreen(),
platformsSupported: [DevicePlatform.android, DevicePlatform.ios],
),
Example(
title: 'RevolutPay',

Check warning on line 301 in example/lib/screens/screens.dart

View workflow job for this annotation

GitHub Actions / Typo CI

RevolutPay

"RevolutPay" is a typo. Did you mean "RevoltPay"?
leading: Image.asset(
'assets/revolut.png',

Check warning on line 303 in example/lib/screens/screens.dart

View workflow job for this annotation

GitHub Actions / Typo CI

revolut

"revolut" is a typo. Did you mean "revolt"?
width: 48,
),
builder: (context) => RevolutPayScreen(),

Check warning on line 306 in example/lib/screens/screens.dart

View workflow job for this annotation

GitHub Actions / Typo CI

RevolutPayScreen

"RevolutPayScreen" is a typo. Did you mean "RevoltPayScreen"?
platformsSupported: [DevicePlatform.android, DevicePlatform.ios],
),
Example(
title: 'Us bank accounts (ACH)',
builder: (contex) => UsBankAccountScreen(),
Expand Down
8 changes: 4 additions & 4 deletions packages/stripe/lib/src/widgets/apple_pay_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ApplePayButton extends StatelessWidget {
Key? key,
this.style = PlatformButtonStyle.automatic,
this.type = PlatformButtonType.plain,
this.cornerRadius = 4.0,
this.cornerRadius=4,
this.onPressed,
double? width,
double? height = _kApplePayButtonDefaultHeight,
Expand Down Expand Up @@ -50,7 +50,7 @@ class ApplePayButton extends StatelessWidget {
/// Modifies the **corner radius** of the payment button.
/// To remove the rounded courners, set this value to 0.0.
/// The default value is set to 4.0
final double cornerRadius;
final int cornerRadius;

/// Callback that is executed when the button is pressed.
final VoidCallback? onPressed;
Expand Down Expand Up @@ -116,7 +116,7 @@ class _UiKitApplePayButton extends StatefulWidget {
Key? key,
required this.style,
required this.type,
this.cornerRadius = 4.0,
this.cornerRadius = 4,
this.onPressed,
this.onShippingContactSelected,
this.onCouponCodeEntered,
Expand All @@ -126,7 +126,7 @@ class _UiKitApplePayButton extends StatefulWidget {

final PlatformButtonStyle style;
final PlatformButtonType type;
final double cornerRadius;
final int cornerRadius;
final VoidCallback? onPressed;
final OnDidSetShippingContact? onShippingContactSelected;
final OnDidSetShippingMethod? onShippingMethodSelected;
Expand Down
7 changes: 6 additions & 1 deletion packages/stripe/lib/src/widgets/google_pay_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class GooglePayButton extends StatefulWidget {
required this.onTap,
this.type = GooglePayButtonType.pay,
this.buttonType = PlatformButtonType.pay,
this.borderRadius,
this.appearance = PlatformButtonStyle.automatic,
Key? key,
}) : super(key: key);

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

final int? borderRadius;
final PlatformButtonStyle appearance;
final PlatformButtonType buttonType;
final VoidCallback onTap;
}
Expand All @@ -35,7 +39,8 @@ class _GooglePayButtonState extends State<GooglePayButton> {
// ignore: deprecated_member_use_from_same_package
_creationParams['buttonType'] = widget.type.name;
_creationParams['type'] = widget.buttonType.id;

_creationParams['appearance'] = widget.appearance.id;
_creationParams['borderRadius'] = widget.borderRadius;
super.initState();
}

Expand Down
9 changes: 5 additions & 4 deletions packages/stripe/lib/src/widgets/platform_pay_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PlatformPayButton extends StatelessWidget {
super.key,
this.type = PlatformButtonType.plain,
this.appearance = PlatformButtonStyle.automatic,
this.borderRadius = 4.0,
this.borderRadius = 4,
this.constraints,
this.onShippingContactSelected,
this.onCouponCodeEntered,
Expand All @@ -27,11 +27,11 @@ class PlatformPayButton extends StatelessWidget {
/// Defines the displayed text on the button.
final PlatformButtonType type;

/// iOS only, defines the color and border radius of the button
/// Defines the coloring of the button
final PlatformButtonStyle appearance;

/// iOS only, sets the border radius of the corners.
final double borderRadius;
/// Sets the border radius of the corners.
final int borderRadius;

/// ios only, execute a callback when shipping
Expand Down Expand Up @@ -72,6 +72,7 @@ class PlatformPayButton extends StatelessWidget {
return GooglePayButton(
onTap: onPressed,
buttonType: type,
borderRadius: borderRadius,
);
} else if (Platform.isIOS) {
return ApplePayButton(
Expand Down
12 changes: 8 additions & 4 deletions packages/stripe_android/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.8.0'
ext.stripe_version = '20.31.+'
ext.stripe_version = '20.34.+'

repositories {
google()
Expand Down Expand Up @@ -48,15 +48,19 @@ dependencies {
implementation 'com.github.bumptech.glide:glide:4.12.0'

implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.4.1"
implementation "com.stripe:stripe-android:$stripe_version"
implementation "com.stripe:financial-connections:$stripe_version"
implementation("com.stripe:stripe-android:$stripe_version") {
exclude group: 'androidx.emoji2', module: 'emoji2'

Check warning on line 52 in packages/stripe_android/android/build.gradle

View workflow job for this annotation

GitHub Actions / Typo CI

androidx

"androidx" is a typo. Did you mean "android"?
}
implementation ("com.stripe:financial-connections:$stripe_version") {
exclude group: 'androidx.emoji2', module: 'emoji2'

Check warning on line 55 in packages/stripe_android/android/build.gradle

View workflow job for this annotation

GitHub Actions / Typo CI

androidx

"androidx" is a typo. Did you mean "android"?
}
implementation 'com.google.android.material:material:1.6.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4'

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

// Users need to declare this dependency on their own, otherwise all methods are a no-op
compileOnly 'com.stripe:stripe-android-issuing-push-provisioning:1.1.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ class StripeSdkGooglePayButtonPlatformView(
if (creationParams?.containsKey("type") == true) {
googlePayButtonManager.type(payButton, creationParams["type"] as Int)
}
if (creationParams?.containsKey("appearance") == true) {
googlePayButtonManager.appearance(payButton, creationParams["appearance"] as Int)
}
if (creationParams?.containsKey("borderRadius") == true) {
googlePayButtonManager.borderRadius(payButton, creationParams["borderRadius"] as Int)
}
payButton.initialize()
payButton.getChildAt(0).setOnClickListener {
channel.invokeMethod("onPressed", null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ class GooglePayButtonManager : SimpleViewManager<GooglePayButtonView?>() {
view.setType(buttonType)
}

@ReactProp(name = "appearance")
fun appearance(view: GooglePayButtonView, appearance: Int) {
view.setAppearance(appearance)
}

@ReactProp(name = "borderRadius")
fun borderRadius(view: GooglePayButtonView, borderRadius: Int) {
view.setBorderRadius(borderRadius)
}

override fun createViewInstance(reactContext: ThemedReactContext): GooglePayButtonView {
return GooglePayButtonView(reactContext)
}
Expand Down
Loading

0 comments on commit 41540fc

Please sign in to comment.