Apple pays PKPaymentauthorizationViewController always returns nil on boot using a payment request

I get a PK Payment authentication controller instance returned as nil. What is wrong with this code?

if([PKPaymentAuthorizationViewController canMakePayments]) { if ([PKPaymentAuthorizationViewController canMakePaymentsUsingNetworks:@[PKPaymentNetworkAmex, PKPaymentNetworkMasterCard, PKPaymentNetworkVisa]]) { PKPaymentRequest *request = [[PKPaymentRequest alloc] init]; request.currencyCode = @"USD"; request.countryCode = @"US"; request.merchantCapabilities = 0; request.requiredBillingAddressFields=PKAddressFieldAll; request.merchantIdentifier = @"merchant.com.domain.mine"; PKPaymentSummaryItem *item = [[PKPaymentSummaryItem alloc] init]; item.label=@ "Merchant"; item.amount=[NSDecimalNumber decimalNumberWithString:@"10"]; request.paymentSummaryItems=@ [item]; PKPaymentAuthorizationViewController *viewController = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:request]; viewController.delegate = self; [self presentViewController:viewController animated:YES completion:nil]; } } 
+3
source share
1 answer

Before moving on to PKPaymentAuthorizationViewController , you must properly configure Apple Payp on your iPhone. If you have not configured Apple Pay on your device, you will receive a nil value for PKPaymentAuthorizationViewController . You can even find an exception on the console by specifying " This device cannot make payment. "

To set up Apple Pay on your device, follow these steps:

  • Go to Settings .
  • Select the Passbook and Apple Pay option (if this parameter does not appear in the settings, go to General → Language and region , change your region to the USA or Great Britain, after that you can see the Passbook and Apple Pay option in Settings )
  • Open the Passbook app on your home screen and set up a valid credit / debit card (only on cards in the US and UK).
  • After checking the added card, run the application, you will receive a valid instance of PKPaymentAuthorizationViewController .

Hope this helps.

+5
source

Source: https://habr.com/ru/post/1236473/


All Articles