Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup confirm stripe web #1989

Merged
merged 18 commits into from
Nov 17, 2024
239 changes: 0 additions & 239 deletions example/lib/screens/others/setup_future_payment_screen.dart

This file was deleted.

15 changes: 10 additions & 5 deletions example/lib/screens/screens.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'package:stripe_example/screens/regional_payment_methods/paypal_screen.da
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/setup_future_payments/setup_future_payments_screen.dart';
import 'package:stripe_example/screens/wallets/apple_pay_screen.dart';
import 'package:stripe_example/screens/wallets/apple_pay_screen_plugin.dart';
import 'package:stripe_example/screens/wallets/google_pay_screen.dart';
Expand All @@ -33,7 +34,6 @@ import 'financial_connections.dart/financial_connections_session_screen.dart';
import 'others/cvc_re_collection_screen.dart';
import 'others/legacy_token_bank_screen.dart';
import 'others/legacy_token_card_screen.dart';
import 'others/setup_future_payment_screen.dart';
import 'regional_payment_methods/grab_pay_screen.dart';
import 'themes.dart';
import 'wallets/apple_pay_create_payment_method.dart';
Expand Down Expand Up @@ -131,6 +131,15 @@ class Example extends StatelessWidget {
DevicePlatform.web,
],
),
Example(
title: 'Setup future payments',
builder: (_) => SetupFuturePaymentsScreen(),
platformsSupported: [
DevicePlatform.android,
DevicePlatform.ios,
DevicePlatform.web,
],
)
],
expanded: true,
),
Expand Down Expand Up @@ -356,10 +365,6 @@ class Example extends StatelessWidget {
],
),
ExampleSection(title: 'Others', children: [
Example(
title: 'Setup Future Payment',
builder: (c) => SetupFuturePaymentScreen(),
),
Example(
title: 'Re-collect CVC',
builder: (c) => CVCReCollectionScreen(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'dart:convert';

import 'package:http/http.dart' as http;
import 'package:stripe_example/config.dart';

typedef SetupKeys = ({
String clientSecret,
String customerId,
});

Future<SetupKeys> createSetupIntent() async {
final url = Uri.parse('$kApiUrl/create-setup-intent');
final response = await http.post(
url,
headers: {
'Content-Type': 'application/json',
},
body: json.encode({
'payment_method_types': ['card', 'sepa_debit'],
}),
);
final body = json.decode(response.body);
if (body['error'] != null) {
throw Exception(body['error']);
}
return (
clientSecret: body['clientSecret'] as String,
customerId: body['customerId'] as String
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:flutter/material.dart';

import 'add_payment_method_screen_loader.dart'
if (dart.library.js) 'add_payment_method_screen_loader_web.dart'
if (dart.library.io) 'add_payment_method_screen_loader_mobile.dart';

class AddPaymentMethodButton extends StatefulWidget {
const AddPaymentMethodButton({
super.key,
});

@override
State<AddPaymentMethodButton> createState() => _AddPaymentMethodButtonState();
}

class _AddPaymentMethodButtonState extends State<AddPaymentMethodButton> {
bool isLoading = false;

void _onAddPaymentMethodPressed() async {
setState(() => isLoading = true);
try {
AddPaymentMethodScreenLoader().display(
context: context,
);
} finally {
setState(() => isLoading = false);
}
}

@override
Widget build(BuildContext context) {
return ListTile(
leading: isLoading
? SizedBox(
height: 16, width: 16, child: const CircularProgressIndicator())
: const Icon(Icons.credit_card),
title: Text('Add payment method'),
trailing: const Icon(Icons.chevron_right),
onTap: isLoading ? null : _onAddPaymentMethodPressed,
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:flutter/material.dart';

class AddPaymentMethodScreenLoader {
const AddPaymentMethodScreenLoader();

Future<void> display({
required BuildContext context,
}) {
throw UnimplementedError();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'package:flutter/material.dart';

/// abstract class so both mobile and web use the same constructor
abstract class AddPaymentMethodScreenLoaderAbstract {
const AddPaymentMethodScreenLoaderAbstract();

Future<void> display({required BuildContext context});
}
Loading
Loading