Skip to content

Commit

Permalink
Merge pull request #155 from shial4/feature/154-add-checkout-session-…
Browse files Browse the repository at this point in the history
…invoice-parameter

Add Invoice creation parameter to checkout session
  • Loading branch information
Andrewangeta authored Jan 18, 2023
2 parents 9454cd5 + 615d86a commit 81e9e52
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Sources/StripeKit/Checkout/SessionRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public protocol SessionRoutes {
/// - locale: The IETF language tag of the locale Checkout is displayed in. If blank or auto, the browser’s locale is used. Supported values are auto, da, de, en, es, fi, fr, it, ja, nb, nl, pl, pt, sv, or zh.
/// - metadata: Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`.
/// - mode: The mode of the Checkout Session, one of `payment`, `setup`, or `subscription`.
/// - invoiceCreation: The Invoice creation of the Checkout Session for successful one-time payments.
/// - paymentIntentData: A subset of parameters to be passed to PaymentIntent creation.
/// - paymentMethodOptions: Payment-method-specific configuration.
/// - phoneNumberCollection: Controls phone number collection settings for the session. We recommend that you review your privacy policy and check with your legal contacts before using this feature. Learn more about collecting phone numbers with Checkout.
Expand All @@ -51,6 +52,7 @@ public protocol SessionRoutes {
locale: StripeSessionLocale?,
metadata: [String: String]?,
mode: StripeSessionMode?,
invoiceCreation: StripeInvoiceCreation?,
paymentIntentData: [String: Any]?,
paymentMethodOptions: [String: Any]?,
phoneNumberCollection: Bool?,
Expand Down Expand Up @@ -106,6 +108,7 @@ extension SessionRoutes {
locale: StripeSessionLocale? = nil,
metadata: [String: String]? = nil,
mode: StripeSessionMode? = nil,
invoiceCreation: StripeInvoiceCreation? = nil,
paymentIntentData: [String: Any]? = nil,
paymentMethodOptions: [String: Any]? = nil,
phoneNumberCollection: Bool? = nil,
Expand All @@ -130,6 +133,7 @@ extension SessionRoutes {
locale: locale,
metadata: metadata,
mode: mode,
invoiceCreation: invoiceCreation,
paymentIntentData: paymentIntentData,
paymentMethodOptions: paymentMethodOptions,
phoneNumberCollection: phoneNumberCollection,
Expand Down Expand Up @@ -183,6 +187,7 @@ public struct StripeSessionRoutes: SessionRoutes {
locale: StripeSessionLocale?,
metadata: [String: String]?,
mode: StripeSessionMode?,
invoiceCreation: StripeInvoiceCreation?,
paymentIntentData: [String: Any]?,
paymentMethodOptions: [String: Any]?,
phoneNumberCollection: Bool?,
Expand Down Expand Up @@ -241,6 +246,10 @@ public struct StripeSessionRoutes: SessionRoutes {
body["mode"] = mode
}

if let invoiceCreation = invoiceCreation {
body["invoice_creation"] = invoiceCreation
}

if let paymentIntentData = paymentIntentData {
paymentIntentData.forEach { body["payment_intent_data[\($0)]"] = $1 }
}
Expand Down
7 changes: 7 additions & 0 deletions Sources/StripeKit/Checkout/Sessions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public struct StripeSession: StripeModel {
public var mode: StripeSessionMode?
/// The ID of the PaymentIntent created if SKUs or line items were provided.
@Expandable<StripePaymentIntent> public var paymentIntent: String?
/// Enable invoice creation of this CheckoutSession.
public var invoiceCreation: StripeInvoiceCreation?
/// Payment-method-specific configuration for the PaymentIntent or SetupIntent of this CheckoutSession.
public var paymentMethodOptions: StripeSessionPaymentMethodOptions?
/// Details on the state of phone number collection for the session.
Expand Down Expand Up @@ -196,6 +198,11 @@ public enum StripeSessionMode: String, StripeModel {
case subscription
}

public struct StripeInvoiceCreation: StripeModel {
/// Indicates whether invoice creation is enabled for the session
public var enabled: Bool
}

public struct StripeSessionPaymentMethodOptions: StripeModel {
/// If the Checkout Session’s `payment_method_types` includes `acss_debit`, this hash contains the configurations that will be applied to each payment attempt of that type.
public var acssDebit: StripeSessionPaymentMethodOptionsAcssDebit?
Expand Down

0 comments on commit 81e9e52

Please sign in to comment.