Skip to content

Commit

Permalink
fix: add revolut pay screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Remon committed Nov 20, 2023
1 parent 277b786 commit d074ca2
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 1 deletion.
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
2 changes: 1 addition & 1 deletion packages/stripe/lib/src/widgets/google_pay_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class _GooglePayButtonState extends State<GooglePayButton> {
@override
void initState() {
// ignore: deprecated_member_use_from_same_package
_creationParams['buttonType'] = describeEnum(widget.type);
_creationParams['buttonType'] = widget.type.name;
_creationParams['type'] = widget.buttonType.id;
_creationParams['appearance'] = widget.appearance.id;
_creationParams['borderRadius'] = widget.borderRadius;
Expand Down

0 comments on commit d074ca2

Please sign in to comment.