Skip to content

Commit

Permalink
Merge branch 'main' into sync
Browse files Browse the repository at this point in the history
# Conflicts:
#	example/server/yarn.lock
#	packages/stripe_android/android/build.gradle
#	packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonView.kt
#	packages/stripe_ios/ios/stripe_ios.podspec
  • Loading branch information
jonasbark committed Jul 25, 2023
2 parents a4115dd + 63ab342 commit a85b2d0
Show file tree
Hide file tree
Showing 13 changed files with 5,980 additions and 12 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,16 @@ Future<void> onGooglePayResult(paymentResult) async {
- [Get your test Stripe API keys](https://stripe.com/docs/keys)
- `cp lib/.env.example.dart lib/.env.dart` and set your Stripe publishable key.
- `cp server/.env.example server/.env` and set the variable values in your newly created `.env` file.
- Install the server dependencies: `npm install` or `yarn --cwd "server"`
- Install the server dependencies in the `server` directory:
* `cd server`
* `npm install` or `yarn --cwd "server"`
- Start the example
- Terminal 1: `npm start` or `yarn --cwd "server" start`
- Terminal 2: `flutter run`
- Terminal 1:
* Move to the `server` directory: `cd server`
* Run npm or yarn: `npm start` or `yarn --cwd "server" start`
- Terminal 2:
* Move to the `lib` directory: `cd lib`
* Run flutter: `flutter run`

##### Additional steps for webhook forwarding

Expand Down
89 changes: 89 additions & 0 deletions example/lib/screens/regional_payment_methods/cash_app_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import 'dart:convert';

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 CashAppScreen extends StatelessWidget {
const CashAppScreen({Key? key}) : super(key: key);

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': 'usd',
'payment_method_types': ['cashapp'],
'amount': 6000
}),
);

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();
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.cashAppPay(
paymentMethodData: PaymentMethodData(),
),
);

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

Check warning on line 51 in example/lib/screens/regional_payment_methods/cash_app_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) {
if (e is StripeException) {
print('blaat $e');

Check warning on line 56 in example/lib/screens/regional_payment_methods/cash_app_screen.dart

View workflow job for this annotation

GitHub Actions / Typo CI

blaat

"blaat" is a typo. Did you mean "blast"?
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: 'Cashapp',
tags: ['Payment method'],
padding: EdgeInsets.all(16),
children: [
LoadingButton(
onPressed: () async {
await _pay(context);
},
text: 'Pay',
),
],
);
}
}
6 changes: 6 additions & 0 deletions example/lib/screens/screens.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:stripe_example/screens/payment_sheet/payment_sheet_screen.dart';
import 'package:stripe_example/screens/payment_sheet/payment_sheet_screen_custom_flow.dart';
import 'package:stripe_example/screens/regional_payment_methods/ali_pay_screen.dart';
import 'package:stripe_example/screens/regional_payment_methods/aubecs_debit.dart';
import 'package:stripe_example/screens/regional_payment_methods/cash_app_screen.dart';
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';
Expand Down Expand Up @@ -221,6 +222,11 @@ class Example extends StatelessWidget {
builder: (context) => AliPayScreen(),
platformsSupported: [DevicePlatform.android, DevicePlatform.ios],
),
Example(
title: 'Cash app Pay',
builder: (context) => CashAppScreen(),
platformsSupported: [DevicePlatform.android, DevicePlatform.ios],
),
Example(
title: 'Ideal',
leading: Image.asset(
Expand Down
Loading

0 comments on commit a85b2d0

Please sign in to comment.