Hello I've wrote, taking example from internet, a simple apple pay integration to my app.
I've successful complete the Xcode configuration adding apple pay capability, then I've configured all apple store profile with certs and identifier reporting this to xcode.
This is my class code:
class applePay: NSObject {
func payWithApplePay( total: Double) {
// Create a payment request and add all data to it
let paymentRequest = PKPaymentRequest()
paymentRequest.merchantIdentifier = "merchant.myshop.domain.com"
paymentRequest.merchantCapabilities = .capability3DS // A security protocol used to authenticate users
paymentRequest.countryCode = "US"
paymentRequest.currencyCode = "USD"
paymentRequest.supportedNetworks = [.visa, .masterCard, .amex]
paymentRequest.shippingType = .delivery
paymentRequest.requiredShippingContactFields = [.name, .postalAddress]
paymentRequest!.paymentSummaryItems =
[
PKPaymentSummaryItem(label: "Total Amount", amount: NSDecimalNumber(string: String(format: "%.2f", total)))
]
// Display the payment request in a sheet presentation
let paymentController = PKPaymentAuthorizationController(paymentRequest: paymentRequest!)
paymentController.delegate = self
paymentController.present(completion: nil)
}
}
extension applePay: PKPaymentAuthorizationControllerDelegate{
func paymentAuthorizationController(_ controller: PKPaymentAuthorizationController,
didAuthorizePayment payment: PKPayment,
handler completion: @escaping (PKPaymentAuthorizationResult) -> Void) {
print("test apple pay successful")
}
func paymentAuthorizationControllerDidFinish(_ controller: PKPaymentAuthorizationController) {
// Apple Payment finished
print("test apple close")
controller.dismiss(completion: nil)
}
}
This is how I show the view
applePay().payWithApplePay(total: currentCart.total)
It's seem that everything works well, I can set shipping detail, changing cart an so on, but I can't complete payment or closing the view. It is like no delagate is called from the PKPaymentAuthorizationController. I think that my code is right I've tested it on a minimal xcode project and delegate works well, so I conclude that there is something wrong in my app.
Where I should check to resolve my issue?
Is there a way to avoid delegates with apple pay?
Regards