So after a couple of days, I was finally able to get the token created as well the payment method, and a payment intent setup this morning. Now I'm confused on how to actually confirm the payment with Apple Pay, in the non-Apple Pay checkout flow, I had this function:
func paymentContext(_ paymentContext: STPPaymentContext, didCreatePaymentResult paymentResult: STPPaymentResult, completion: @escaping STPPaymentStatusBlock) {
guard let paymentIntentClientSecret = paymentIntentClientSecret else {
return;
}
// Collect card details
let paymentIntentParams = STPPaymentIntentParams(clientSecret: paymentIntentClientSecret)
paymentIntentParams.configure(with: paymentResult)
// Submit the payment
let paymentHandler = STPPaymentHandler.shared()
paymentHandler.confirmPayment(paymentIntentParams, with: self) { (status, paymentIntent, error) in
switch (status) {
case .failed:
self.displayFailureAlert(title: "Payment Failed", message: "There was an error trying to complete the payment, please try again later.")
self.paymentInProgress = false
break
case .canceled:
self.displayCancelledAlert(title: "Payment Canceled", message: "The payment has been cancelled.")
self.paymentInProgress = false
break
case .succeeded:
self.displaySuccessAlert(title: "Payment Succeeded", message: "The payment was successful!")
self.paymentInProgress = false
break
@unknown default:
fatalError()
break
}
}
}
This works great. The parameters in the STPApplePayContext
are a bit different from the STPPaymentContext
and I can't use the exact same functionality for it. This is the function I have for the apple Pay checkout:
func applePayContext(_ context: STPApplePayContext, didCreatePaymentMethod paymentMethod: STPPaymentMethod, paymentInformation: PKPayment, completion: @escaping STPIntentClientSecretCompletionBlock) {
guard let paymentIntentClientSecret = paymentIntentClientSecret else {
return;
}
let paymentIntentParams = STPPaymentIntentParams(clientSecret: paymentIntentClientSecret)
let error = NSError()
completion(paymentIntentClientSecret, error)
}
This is all I have so far, I tried doing STPAPIClient.shared.confirmPaymentIntent(with:)
but nothing changed, any suggestions?