I am trying to process Apple Pay using Stripe on the backend however I am getting stuck with the completion block. The documentation has the following steps:
- Request payment intent which will return a client-secret key
- Pass client-secret to completion block
didCompleteis called
However I am taking a different approach:
- Pass payment method id to backend
- Backend runs logic and creates payment intent and captures charge
- Client receives 200
- Completion block to activate
didComplete
Step 4 is where the error occurs. Calling the completion block without a client-secret key crashes the app.
STPIntentClientSecretCompletionBlock - requires optional string for first parameter which is the client-secret
func applePayContext(_ context: STPApplePayContext, didCreatePaymentMethod paymentMethod: STPPaymentMethod, paymentInformation: PKPayment, completion: @escaping STPIntentClientSecretCompletionBlock) {
sudo code:
API.makePayment(paymentInformation.stripeId)
completion(nil, nil)
}
func applePayContext(_ context: STPApplePayContext, didCompleteWith status: STPPaymentStatus, error: Error?) {
switch status {
case .success:
break
case .error:
break
case .userCancellation:
break
@unknown default:
fatalError()
}
}