2017-08-06 67 views
1

我想爲我的應用程序設置Apple Pay,但由於某種原因,PKPaymentViewController總是返回爲零(如果代碼中的語句是測試此)?任何想法爲什麼?PKPaymentAuthorizationViewController總是返回nil?

@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) 
} 
+0

使用此功能'canMakePayments(usingNetworks:)'來檢查是否可以進行支付。並告訴我們結果 –

+0

使用該功能返回爲真 –

+0

您是否在iPhone設備上正確配置Apple Pay? –

回答

1

您配置countryCode與錯ISO

COUNTRYCODE

兩個字母的ISO 3166國家代碼。

爲英國國家代碼爲GB

Documentation

+0

哈哈哈不能相信我錯過了。謝謝!! –

+0

@MatthewFrankland它現在在工作嗎? –