How do I test Braintree + Apple Pay on a real device?

微笑、不失礼 提交于 2019-12-01 05:06:16

It's likely that your app's Apple Pay entitlement is not set up correctly.

I've noticed canMakePayments returns YES and canMakePaymentsUsingNetworks: returns NO when the entitlement is not set.

(I've also noticed that they can both return YES when the merchant ID you set on your PKPaymentRequest does not match the merchant ID of your Apple Pay entitlement. In this case, your PKPaymentAuthorizationViewController will be non-nil, but presenting it logs a cryptic error in the console).

So to verify that Apple Pay is configured for your app, ensure that "Apple Pay" is "On" in the Capabilities section of your target settings, and that it has a merchant identifier (which you'll need to set up if you haven't already).

Then either:

  • If using your BTPaymentProvider integration method, ensure that the certificate and merchant identifier are correctly set up in the Braintree control panel.
  • If using your direct PassKit integration method, ensure that you are setting merchantIdentifier property to the matching merchant identifier in the entitlement.

Most likely this is happening because no payment cards are configured for any of those networks. From the documentation:

On devices that support making payments but don’t have any payment cards configured, the canMakePayments method returns YES because the hardware and parental controls allow making payments, but the canMakePaymentsUsingNetworks: method returns NO regardless of network.

The documentation also mentions other reasons:

User may not be able to make payments for a variety of reasons. For example, this functionality may not be supported by their hardware, or it may be restricted by parental controls.


On a separate note, if(self.braintree!=nil && self.braintree != Nil is redundant - those are the same. I would simply collapse this into if (self.braintree) { …

In version 3.9.3 of the BraintreeSDK, I found a bug in BTClientTokenApplePayPaymentNetworksValueTransformer in which there is no case for Discover Card when deserializing BTConfiguration.applePaySupportedNetworks. This results in a PKPaymentRequest with an array containing an instance of NSNull in its supportedNetworks. Passing that array to PKPaymentAuthorizationViewController.canMakePaymentsUsingNetworks results in a NO. This method contains the bug:

- (id)transformedValue:(id)value {
    if ([PKPaymentRequest class]) {
        if ([value isEqualToString:@"amex"]) {
            return PKPaymentNetworkAmex;
        } else if ([value isEqualToString:@"visa"]) {
            return PKPaymentNetworkVisa;
        } else if ([value isEqualToString:@"mastercard"]) {
            return PKPaymentNetworkMasterCard;
        }
    }

    return [NSNull null];
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!