Skip to content

Commit a8958f6

Browse files
Add payment intent confirmation method
1 parent d6884ca commit a8958f6

4 files changed

Lines changed: 135 additions & 0 deletions

File tree

lib/messages.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ part 'src/messages/price.dart';
2626
part 'src/messages/product.dart';
2727
part 'src/messages/promotion_code.dart';
2828
part 'src/messages/refund.dart';
29+
part 'src/messages/requests/confirm_payment_intent.dart';
2930
part 'src/messages/requests/create_checkout_session.dart';
3031
part 'src/messages/requests/create_customer.dart';
3132
part 'src/messages/requests/create_discount.dart';

lib/messages.g.dart

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
part of '../../../messages.dart';
2+
3+
@JsonSerializable()
4+
class ConfirmPaymentIntentRequest {
5+
/// ID of the payment method (a PaymentMethod, Card, or compatible Source
6+
/// object) to attach to this PaymentIntent.
7+
final String? paymentMethod;
8+
9+
/// Email address that the receipt for the resulting payment will be sent to.
10+
/// If receipt_email is specified for a payment in live mode, a receipt will
11+
/// be sent regardless of your email settings.
12+
final String? receiptEmail;
13+
14+
/// Indicates that you intend to make future payments with this
15+
/// PaymentIntent’s payment method.
16+
///
17+
/// If you provide a Customer with the PaymentIntent, you can use this
18+
/// parameter to attach the payment method to the Customer after the
19+
/// PaymentIntent is confirmed and the customer completes any required
20+
/// actions. If you don’t provide a Customer, you can still attach the
21+
/// payment method to a Customer after the transaction completes.
22+
///
23+
/// If the payment method is card_present and isn’t a digital wallet, Stripe
24+
/// creates and attaches a generated_card payment method representing the
25+
/// card to the Customer instead.
26+
///
27+
/// When processing card payments, Stripe uses setup_future_usage to help you
28+
/// comply with regional legislation and network rules, such as SCA.
29+
///
30+
/// If you’ve already set setup_future_usage and you’re performing a request
31+
/// using a publishable key, you can only update the value from on_session to
32+
/// off_session.
33+
final SetupFutureUsage? setupFutureUsage;
34+
35+
/// ID of the ConfirmationToken used to confirm this PaymentIntent.
36+
///
37+
/// If the provided ConfirmationToken contains properties that are also being
38+
/// provided in this request, such as payment_method, then the values in
39+
/// this request will take precedence.
40+
final String? confirmationToken;
41+
42+
/// Set to true to fail the payment attempt if the PaymentIntent transitions
43+
/// into requires_action. This parameter is intended for simpler integrations
44+
/// that do not handle customer actions, like saving cards without
45+
/// authentication.
46+
final bool? errorOnRequiresAction;
47+
48+
/// ID of the mandate that’s used for this payment.
49+
final String? mandate;
50+
51+
/// Set to true to indicate that the customer isn’t in your checkout flow
52+
/// during this payment attempt and can’t authenticate. Use this parameter in
53+
/// scenarios where you collect card details and charge them later.
54+
final bool? offSession;
55+
56+
/// The URL to redirect your customer back to after they authenticate or
57+
/// cancel their payment on the payment method’s app or site. If you’d prefer
58+
/// to redirect to a mobile application, you can alternatively supply an
59+
/// application URI scheme. This parameter is only used for cards and other
60+
/// redirect-based payment methods.
61+
final String? returnUrl;
62+
63+
/// Set to true when confirming server-side and using Stripe.js, iOS, or
64+
/// Android client-side SDKs to handle the next actions.
65+
final bool? useStripeSdk;
66+
67+
ConfirmPaymentIntentRequest({
68+
this.paymentMethod,
69+
this.receiptEmail,
70+
this.setupFutureUsage,
71+
this.confirmationToken,
72+
this.errorOnRequiresAction,
73+
this.mandate,
74+
this.offSession,
75+
this.returnUrl,
76+
this.useStripeSdk,
77+
});
78+
79+
factory ConfirmPaymentIntentRequest.fromJson(Map<String, dynamic> json) =>
80+
_$ConfirmPaymentIntentRequestFromJson(json);
81+
82+
Map<String, dynamic> toJson() => _$ConfirmPaymentIntentRequestToJson(this);
83+
}

lib/src/resources/payment_intent.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,17 @@ class PaymentIntentResource extends Resource<PaymentIntent> {
6464

6565
return PaymentIntent.fromJson(response);
6666
}
67+
68+
/// https://docs.stripe.com/api/payment_intents/confirm
69+
Future<PaymentIntent> confirm(
70+
String id, {
71+
required ConfirmPaymentIntentRequest request,
72+
}) async {
73+
final response = await post(
74+
'$_resourceName/$id/confirm',
75+
data: request.toJson(),
76+
);
77+
78+
return PaymentIntent.fromJson(response);
79+
}
6780
}

0 commit comments

Comments
 (0)