Matthew Frankland
Matthew Frankland

Reputation: 80

PKPaymentAuthorizationViewController always returns nil?

I am trying to set up Apple Pay for my application but for some reason the PKPaymentViewController is always returned as nil (if statement in code was to test this)?? Any ideas why?

@IBAction func payAction(_ sender: Any) {

    price = donationAmount.text
    print(price)

    let request = PKPaymentRequest()
    request.merchantIdentifier = applePayMerchantID
    request.supportedNetworks = SupportedPaymentNetworks
    request.merchantCapabilities = PKMerchantCapability.capability3DS
    request.countryCode = "GBR"
    request.currencyCode = "GBP"
    request.requiredBillingAddressFields = PKAddressField.all

    //request.applicationData = "This is a test".dataUsingEncoding(NSUTF8StringEncoding)

    let paymentSummary = [PKPaymentSummaryItem(label:"Sponsorship", amount: 10.00)]

    request.paymentSummaryItems = paymentSummary

    let applePayController: PKPaymentAuthorizationViewController = PKPaymentAuthorizationViewController(paymentRequest: request)

    applePayController.delegate = self;


    if(applePayController == nil){
        print("___")
    } else{
        self.present(applePayController, animated: true, completion: nil)
    }
}


func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, completion: @escaping (PKPaymentAuthorizationStatus) -> Void) {
    completion(PKPaymentAuthorizationStatus.success)
}

func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) {
    controller.dismiss(animated: true, completion: nil)
}

Upvotes: 2

Views: 1418

Answers (1)

Adrian Bobrowski
Adrian Bobrowski

Reputation: 2794

You configure countryCode with wrong ISO

countryCode

The two-letter ISO 3166 country code.

for the United Kingdom country code is GB

Documentation

Upvotes: 2

Related Questions