Skip to content

Commit

Permalink
Feat: add BillingDetailsCollectionConfiguration to paymentsheet. This…
Browse files Browse the repository at this point in the history
… can be used to collect email,phone,name or address in Paymentsheet
  • Loading branch information
Remon committed Apr 29, 2023
1 parent fe1375c commit 8c0abf6
Show file tree
Hide file tree
Showing 3 changed files with 481 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ class SetupPaymentSheetParameters with _$SetupPaymentSheetParameters {

/// Return URL is required for IDEAL and few other payment methods
String? returnURL,

/// Configuration for how billing details are collected during checkout.
BillingDetailsCollectionConfiguration?
billingDetailsCollectionConfiguration,
}) = _SetupParameters;

factory SetupPaymentSheetParameters.fromJson(Map<String, dynamic> json) =>
Expand Down Expand Up @@ -374,6 +378,7 @@ class PresentPaymentSheetParameters with _$PresentPaymentSheetParameters {

@freezed
class PaymentSheetPresentOptions with _$PaymentSheetPresentOptions {
@JsonSerializable(explicitToJson: true)
const factory PaymentSheetPresentOptions({
/// The number of milliseconds (after presenting) before the Payment Sheet
/// closes automatically.
Expand All @@ -385,3 +390,67 @@ class PaymentSheetPresentOptions with _$PaymentSheetPresentOptions {
factory PaymentSheetPresentOptions.fromJson(Map<String, dynamic> json) =>
_$PaymentSheetPresentOptionsFromJson(json);
}

@freezed
class BillingDetailsCollectionConfiguration
with _$BillingDetailsCollectionConfiguration {
@JsonSerializable(explicitToJson: true)
const factory BillingDetailsCollectionConfiguration({
/// How to collect the name field.
///
/// Defaults to `CollectionMode.automatic`.
CollectionMode? name,

/// How to collect the phone field.
///
/// Defaults to `CollectionMode.automatic`.
CollectionMode? phone,

/// How to collect the email field.
///
/// Defaults to `CollectionMode.automatic`.
CollectionMode? email,

/// How to collect the billing address.
///
/// Defaults to `CollectionMode.automatic`.
AddressCollectionMode? address,

/// Whether the values included in `Configuration.defaultBillingDetails` should be attached to the payment method, this includes fields that aren't displayed in the form.
///
/// If `false` (the default), those values will only be used to prefill the corresponding fields in the form.
bool? attachDefaultsToPaymentMethod,
}) = _BillingDetailsCollectionConfiguration;

factory BillingDetailsCollectionConfiguration.fromJson(
Map<String, dynamic> json) =>
_$BillingDetailsCollectionConfigurationFromJson(json);
}

/// Types of how to collect non address fields
enum CollectionMode {
/// The field may or may not be collected depending on the Payment Method's requirements.
automatic,

/// The field will never be collected.
///
/// If this field is required by the Payment Method, you must provide it as part of `defaultBillingDetails`.
never,

/// The field will always be collected, even if it isn't required for the Payment Method.
always,
}

/// Types of how to collect the address.
enum AddressCollectionMode {
/// Only the fields required by the Payment Method will be collected, which may be none.
automatic,

/// Billing address will never be collected.
///
/// If the Payment Method requires a billing address, you must provide it as part of `defaultBillingDetails`.
never,

/// Collect the full billing address, regardless of the Payment Method's requirements. */
full,
}
Loading

0 comments on commit 8c0abf6

Please sign in to comment.