frames-ios
frames-ios copied to clipboard
CheckoutAPIService.createToken result block never called
Describe the bug After migrating to v4.3.6, the CheckoutAPIService.createToken result block doesn't get called when using Apple Pay.
To Reproduce
- Get a
PKPaymentfromPKPaymentAuthorizationControllerDelegate didAuthorizePayment - Initialize
CheckoutAPIServiceinstance - Call CheckoutAPIService.createToken
- Result block never gets called thus resulting in 'Payment not Completed' in Apple Pay
Expected behavior CheckoutAPIService.createToken result block should be called (failure or success)
Smartphone (please complete the following information):
- Device: iPhone XS
- OS: iOS 17.5.1
Additional context
- Can reproduce issue in both sandbox and production environments
- Can reproduce issue in other devices
- Same code works well with Frames v4.3.2
PKPaymentAuthorizationControllerDelegate
func paymentAuthorizationController(_: PKPaymentAuthorizationController, didAuthorizePayment payment: PKPayment, handler completion: @escaping (PKPaymentAuthorizationResult) -> Void) {
handleApplePayPayment(payment) { token, message in
if let token = token {
self.token = token
self.paymentStatus = .success
completion(PKPaymentAuthorizationResult(status: .success, errors: nil))
} else {
self.errorMessage = message
self.paymentStatus = .failure
completion(PKPaymentAuthorizationResult(status: .failure, errors: nil))
}
}
}
private func handleApplePayPayment(_ payment: PKPayment, completion: @escaping ApplePayCompletion) {
let paymentData = payment.token.paymentData
debugPrint(payment)
let apiKey = UserDefaults.isAUUser ? AppConfig.checkoutApiKeyAU : AppConfig.checkoutApiKeyNZ
let checkoutService = CheckoutAPIService(publicKey: apiKey,
environment: AppConfig.isDebugMode ? .sandbox : .production)
checkoutService.createToken(.applePay(.init(tokenData: paymentData))) { result in
/* THIS BLOCK NEVER GETS CALLED */
debugPrint("checkout create token result \(result)")
switch result {
case let .failure(error):
debugPrint("Checkout create token failed \(error)")
var message = ApplePayError.invalidApplePayToken.message
switch error {
case .cardValidationError: message = ApplePayError.invalidCard.message
case .userCancelled: message = ApplePayError.userCancelled.message
default: ()
}
completion(nil, message)
case let .success(tokenDetails):
completion(tokenDetails.token, nil)
}
}
}
- See Checkout logs produced in the console:
Event(typeIdentifier: "card_validator", time: 2024-06-19 07:04:06 +0000, monitoringLevel: CheckoutEventLoggerKit.MonitoringLevel.info, properties: ["CorrelationId": AnyCodable("873f0b53-1582-4621-85bf-9b4bf5d3d087")])
Event(typeIdentifier: "token_requested", time: 2024-06-19 07:04:06 +0000, monitoringLevel: CheckoutEventLoggerKit.MonitoringLevel.info, properties: ["CorrelationId": AnyCodable("873f0b53-1582-4621-85bf-9b4bf5d3d087"), "tokenType": AnyCodable("applepay"), "publicKey": AnyCodable("_KEY REDACTED_")])
Event(typeIdentifier: "token_response", time: 2024-06-19 07:04:07 +0000, monitoringLevel: CheckoutEventLoggerKit.MonitoringLevel.info, properties: ["tokenID": AnyCodable("_TOKEN REDACTED_"), "scheme": AnyCodable("VISA"), "tokenType": AnyCodable("applepay"), "httpStatusCode": AnyCodable(201), "publicKey": AnyCodable("_KEY REDACTED_"), "CorrelationId": AnyCodable("873f0b53-1582-4621-85bf-9b4bf5d3d087")])