Vend entire PM (#2575)

* Vend entire PM

* Fix test

* Update StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/PaymentSheetIntentConfiguration.swift

Co-authored-by: Yuki <yuki@stripe.com>

---------

Co-authored-by: Yuki <yuki@stripe.com>
This commit is contained in:
Nick Porter 2023-05-17 09:30:23 -07:00 committed by GitHub
parent fdc1a6fa93
commit 749d0b1b9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 15 additions and 13 deletions

View File

@ -707,7 +707,7 @@ extension PaymentSheetTestPlayground: EndpointSelectorViewControllerDelegate {
extension PaymentSheetTestPlayground {
// Client-side confirmation handler
func confirmHandler(_ paymentMethodID: String,
func confirmHandler(_ paymentMethod: STPPaymentMethod,
_ intentCreationCallback: @escaping (Result<String, Error>) -> Void) {
DispatchQueue.global(qos: .background).async {
intentCreationCallback(.success(self.clientSecret!))

View File

@ -1130,7 +1130,7 @@ class PaymentSheetSnapshotTests: FBSnapshotTestCase {
stubCustomers()
}
func confirmHandler(_ paymentMethodID: String,
func confirmHandler(_ paymentMethod: STPPaymentMethod,
_ intentCreationCallback: (Result<String, Error>) -> Void) {
// no-op
}

View File

@ -604,8 +604,8 @@ class PaymentSheetAPITest: XCTestCase {
let expectation = expectation(description: "")
var sut_paymentMethodID: String = "" // The PM that the sut gave us
var merchant_clientSecret: String?
let client_confirmHandler: PaymentSheet.IntentConfiguration.ConfirmHandler = { paymentMethodID, intentCreationCallback in
sut_paymentMethodID = paymentMethodID
let client_confirmHandler: PaymentSheet.IntentConfiguration.ConfirmHandler = { paymentMethod, intentCreationCallback in
sut_paymentMethodID = paymentMethod.stripeId
let createIntentCompletion: (String?, Error?) -> Void = { clientSecret, error in
if let clientSecret {
merchant_clientSecret = clientSecret

View File

@ -9,3 +9,4 @@
import Foundation
@_exported import StripeCore
@_exported import StripePayments

View File

@ -38,7 +38,7 @@ extension PaymentSheet {
// 2. Get Intent client secret from merchant
let clientSecret = try await fetchIntentClientSecretFromMerchant(intentConfig: intentConfig,
paymentMethodID: paymentMethod.stripeId,
paymentMethod: paymentMethod,
shouldSavePaymentMethod: confirmType.shouldSave)
guard clientSecret != IntentConfiguration.FORCE_SUCCESS else {
// Force close PaymentSheet and early exit
@ -125,19 +125,19 @@ extension PaymentSheet {
}
static func fetchIntentClientSecretFromMerchant(intentConfig: IntentConfiguration,
paymentMethodID: String,
paymentMethod: STPPaymentMethod,
shouldSavePaymentMethod: Bool) async throws -> String {
try await withCheckedThrowingContinuation { continuation in
if let confirmHandlerForServerSideConfirmation = intentConfig.confirmHandlerForServerSideConfirmation {
DispatchQueue.main.async {
confirmHandlerForServerSideConfirmation(paymentMethodID, shouldSavePaymentMethod, { result in
confirmHandlerForServerSideConfirmation(paymentMethod.stripeId, shouldSavePaymentMethod, { result in
continuation.resume(with: result)
})
}
} else if let confirmHandler = intentConfig.confirmHandler {
DispatchQueue.main.async {
confirmHandler(paymentMethodID, { result in
confirmHandler(paymentMethod, { result in
continuation.resume(with: result)
})
}

View File

@ -22,11 +22,11 @@ import Foundation
/// Your implementation should create a PaymentIntent or SetupIntent on your server and call the `intentCreationCallback` with its client secret or an error if one occurred.
/// - Note: You must create the PaymentIntent or SetupIntent with the same values used as the `IntentConfiguration` e.g. the same amount, currency, etc.
/// - Parameters:
/// - paymentMethodId: The id of the PaymentMethod representing the customer's payment details.
/// If you need to inspect payment method details, you can fetch the PaymentMethod object using this id on your server. Otherwise, you can ignore this.
/// - paymentMethod: The `STPPaymentMethod` representing the customer's payment details.
/// If your server needs the payment method, send `paymentMethod.stripeId` to your server and have it fetch the PaymentMethod object. Otherwise, you can ignore this. Don't send other properties besides the ID to your server.
/// - intentCreationCallback: Call this with the `client_secret` of the PaymentIntent or SetupIntent created by your server or the error that occurred. If you're using PaymentSheet, the error's localizedDescription will be displayed to the customer in the sheet. If you're using PaymentSheet.FlowController, the `confirm` method fails with the error.
public typealias ConfirmHandler = (
_ paymentMethodID: String,
_ paymentMethod: STPPaymentMethod,
_ intentCreationCallback: @escaping ((Result<String, Error>) -> Void)
) -> Void

View File

@ -52,8 +52,9 @@ extension STPApplePayContext {
case .setupIntent(let setupIntent):
completion(setupIntent.clientSecret, nil)
case .deferredIntent(_, let intentConfig):
if let confirmHandler = intentConfig.confirmHandler {
confirmHandler(paymentMethod.id, { result in
if let confirmHandler = intentConfig.confirmHandler,
let stpPaymentMethod = STPPaymentMethod.decodedObject(fromAPIResponse: paymentMethod.allResponseFields) {
confirmHandler(stpPaymentMethod, { result in
switch result {
case .success(let clientSecret):
completion(clientSecret, nil)