Skip to content

Commit

Permalink
[MBL-1391] Payment Intent StripeIntentContextType and CheckoutID (#2057)
Browse files Browse the repository at this point in the history
* pass StripeIntentContextType to createPaymentIntent calls

* hard code the context because it'll we have no plans to change it

* update GraphAPI to expose checkoutID property on CreatePaymentIntent

* pass checkoutId to all .createPaymentIntent call sites

* update tests
  • Loading branch information
scottkicks authored May 14, 2024
1 parent 740b6e9 commit 881f728
Show file tree
Hide file tree
Showing 14 changed files with 3,580 additions and 842 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ final class PledgePaymentMethodsViewControllerTests: TestCase {
let data = PledgePaymentMethodsValue(
user: .template,
project: project,
checkoutId: "checkoutId",
reward: reward,
context: .pledge,
refTag: nil,
Expand Down Expand Up @@ -89,6 +90,7 @@ final class PledgePaymentMethodsViewControllerTests: TestCase {
let data = PledgePaymentMethodsValue(
user: .template,
project: project,
checkoutId: "checkoutId",
reward: reward,
context: .pledge,
refTag: nil,
Expand Down
38 changes: 30 additions & 8 deletions KsApi/GraphAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,17 @@ public enum GraphAPI {
public var graphQLMap: GraphQLMap

/// - Parameters:
/// - checkoutId: The graphql relay id of the checkout
/// - paymentIntentClientSecret: The stripe payment intent client secret
/// - paymentSourceId: The rosie payment source id when using a saved source (optional)
/// - checkoutId: The graphql relay id of the checkout (base64 encoded)
/// - paymentIntentClientSecret: the client_secret returned by createPaymentIntent, starts with `pi_` (the same secret passed to stripe)
/// - paymentSourceId: Kickstarter internal payment source id. Expects a number (not the stripe id starting with `pm_`). Pass in when using a saved card (optional)
/// - paymentSourceReusable: If the payment source can be reused for future payments (optional)
/// - applePay: Apple pay attributes for creating a payment source (optional)
/// - clientMutationId: A unique identifier for the client performing the mutation.
public init(checkoutId: GraphQLID, paymentIntentClientSecret: String, paymentSourceId: Swift.Optional<String?> = nil, paymentSourceReusable: Swift.Optional<Bool?> = nil, applePay: Swift.Optional<ApplePayInput?> = nil, clientMutationId: Swift.Optional<String?> = nil) {
graphQLMap = ["checkoutId": checkoutId, "paymentIntentClientSecret": paymentIntentClientSecret, "paymentSourceId": paymentSourceId, "paymentSourceReusable": paymentSourceReusable, "applePay": applePay, "clientMutationId": clientMutationId]
}

/// The graphql relay id of the checkout
/// The graphql relay id of the checkout (base64 encoded)
public var checkoutId: GraphQLID {
get {
return graphQLMap["checkoutId"] as! GraphQLID
Expand All @@ -126,7 +126,7 @@ public enum GraphAPI {
}
}

/// The stripe payment intent client secret
/// the client_secret returned by createPaymentIntent, starts with `pi_` (the same secret passed to stripe)
public var paymentIntentClientSecret: String {
get {
return graphQLMap["paymentIntentClientSecret"] as! String
Expand All @@ -136,7 +136,7 @@ public enum GraphAPI {
}
}

/// The rosie payment source id when using a saved source (optional)
/// Kickstarter internal payment source id. Expects a number (not the stripe id starting with `pm_`). Pass in when using a saved card (optional)
public var paymentSourceId: Swift.Optional<String?> {
get {
return graphQLMap["paymentSourceId"] as? Swift.Optional<String?> ?? Swift.Optional<String?>.none
Expand Down Expand Up @@ -871,9 +871,11 @@ public enum GraphAPI {
/// - amount: total amount to be paid (eg. 10.55)
/// - paymentIntentContext: Context in which this stripe intent is created
/// - digitalMarketingAttributed: if the payment is attributed to digital marketing (default: false)
/// - backingId: Current backing id for tracking purposes
/// - checkoutId: Current checkout id for tracking purposes
/// - clientMutationId: A unique identifier for the client performing the mutation.
public init(projectId: GraphQLID, amount: String, paymentIntentContext: Swift.Optional<StripeIntentContextTypes?> = nil, digitalMarketingAttributed: Swift.Optional<Bool?> = nil, clientMutationId: Swift.Optional<String?> = nil) {
graphQLMap = ["projectId": projectId, "amount": amount, "paymentIntentContext": paymentIntentContext, "digitalMarketingAttributed": digitalMarketingAttributed, "clientMutationId": clientMutationId]
public init(projectId: GraphQLID, amount: String, paymentIntentContext: Swift.Optional<StripeIntentContextTypes?> = nil, digitalMarketingAttributed: Swift.Optional<Bool?> = nil, backingId: Swift.Optional<GraphQLID?> = nil, checkoutId: Swift.Optional<GraphQLID?> = nil, clientMutationId: Swift.Optional<String?> = nil) {
graphQLMap = ["projectId": projectId, "amount": amount, "paymentIntentContext": paymentIntentContext, "digitalMarketingAttributed": digitalMarketingAttributed, "backingId": backingId, "checkoutId": checkoutId, "clientMutationId": clientMutationId]
}

/// kickstarter project id
Expand Down Expand Up @@ -916,6 +918,26 @@ public enum GraphAPI {
}
}

/// Current backing id for tracking purposes
public var backingId: Swift.Optional<GraphQLID?> {
get {
return graphQLMap["backingId"] as? Swift.Optional<GraphQLID?> ?? Swift.Optional<GraphQLID?>.none
}
set {
graphQLMap.updateValue(newValue, forKey: "backingId")
}
}

/// Current checkout id for tracking purposes
public var checkoutId: Swift.Optional<GraphQLID?> {
get {
return graphQLMap["checkoutId"] as? Swift.Optional<GraphQLID?> ?? Swift.Optional<GraphQLID?>.none
}
set {
graphQLMap.updateValue(newValue, forKey: "checkoutId")
}
}

/// A unique identifier for the client performing the mutation.
public var clientMutationId: Swift.Optional<String?> {
get {
Expand Down
4 changes: 3 additions & 1 deletion KsApi/Service.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ public struct Service: ServiceType {
.CreatePaymentIntentMutation(input: GraphAPI.CreatePaymentIntentInput(
projectId: input.projectId,
amount: input.amountDollars,
digitalMarketingAttributed: input.digitalMarketingAttributed
paymentIntentContext: input.paymentIntentContext,
digitalMarketingAttributed: input.digitalMarketingAttributed,
checkoutId: input.checkoutId
))
)
.flatMap(PaymentIntentEnvelope.envelopeProducer(from:))
Expand Down
Loading

0 comments on commit 881f728

Please sign in to comment.