The Windwaker
The Windwaker

Reputation: 1054

PKPaymentAuthorizationViewController not nil but not showing

I'm trying to display a PKPaymentAuthorizationViewController which is not nil but isn't showing. I worked before but it doesn't anymore. The entitlement and merchant id seems good. Here is my init code (without useless code)

PKPaymentRequest *request = [PKPaymentRequest new];

request.merchantIdentifier = kApplePayMerchantId;
request.merchantCapabilities = PKMerchantCapability3DS;
request.supportedNetworks = self.class.supportedNetworks;
request.countryCode = _countryCode;
request.currencyCode = _currencyCode;
request.requiredShippingAddressFields = PKAddressFieldAll;
request.requiredBillingAddressFields = PKAddressFieldName | PKAddressFieldPostalAddress;
request.paymentSummaryItems = summaryItems;

PKPaymentAuthorizationViewController *paymentVC = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:request];
paymentVC.delegate = self;
return paymentVC;

Then I display it using

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^ __nullable)(void))completion;

But nothing happens. No log ...

I tried to set a breakpoint before return paymentVC;, printed this object (seemed ok) and then pressed Play and I had the following log

Payment request is invalid: check your entitlements

the apple pay view controller showed up and crashed in a BAD ACCESS error.

I really don't understand what happens. Can you help me with this bug ?

Upvotes: 3

Views: 1642

Answers (2)

Moskwinow
Moskwinow

Reputation: 1

Other issue can be in case if u use SandBox card then you have setup currency and country as USA

if PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: paymentNetworks) {
        let request = PKPaymentRequest()
        request.currencyCode = "USD"
        request.countryCode = "US"
        request.merchantIdentifier = "merchant.com.axiomc.beanbar"
        request.merchantCapabilities = PKMerchantCapability.capability3DS
        request.supportedNetworks = paymentNetworks
        request.paymentSummaryItems = [paymentItems]
        }
    }

Upvotes: 0

The Windwaker
The Windwaker

Reputation: 1054

Wow I found it, after a day of research. If you have a default Apple Pay shipping address (in Wallet entry, settings) with a non valid field (I don't know the rules for it), Apple Pay sheet won't pop up ... So be aware of that !

Upvotes: 3

Related Questions