Ali
Ali

Reputation: 327

Setting shipping address in PKPaymentRequest for apple pay

Based on apple document : PKPaymentRequest_Ref

Each PKPaymentRequest has a requiredShippingAddressFields and shippingContact. I have a prepopulated shipping address. this is the address that user inserted before selecting apple pay to checkout but i want to let the user to select any other address if he wants.

this is how i make my request :

- (PKPaymentRequest *)paymentRequest {
    PKPaymentRequest *paymentRequest = [[PKPaymentRequest alloc] init];
    paymentRequest.merchantIdentifier = @"merchant.com.myCompany.sandbox";
    paymentRequest.requiredShippingAddressFields = (PKAddressFieldPostalAddress|PKAddressFieldPhone|PKAddressFieldName);
    paymentRequest.requiredBillingAddressFields = (PKAddressFieldPostalAddress|PKAddressFieldPhone|PKAddressFieldName);
    paymentRequest.supportedNetworks = @[PKPaymentNetworkAmex, PKPaymentNetworkVisa, PKPaymentNetworkMasterCard];
    paymentRequest.billingContact = [self contactForAddress:self.info.billingAddress];
    paymentRequest.shippingContact = [self contactForAddress:self.info.shippingAddress];
    paymentRequest.merchantCapabilities = PKMerchantCapability3DS;
    paymentRequest.countryCode = [self.info.country uppercaseString];
    paymentRequest.currencyCode = [self.info.currency uppercaseString];
    paymentRequest.paymentSummaryItems = [self summaryItems];
    paymentRequest.shippingMethods = [self shippingMethod];
    return paymentRequest;
}

but when apple pay window comes up, it does not show pre-set shipping contact ( what i set to paymentRequest.shippingContact ). but in document it says

This shipping address appears in the payment sheet. When the PKPaymentAuthorizationViewController class is presented, the user can either keep the address you specified or enter a different address.

is there anything wrong in my code ?

Upvotes: 1

Views: 2014

Answers (1)

Ali
Ali

Reputation: 327

I Tried to use shippingAddress instead of shippingContact and it works. sample code :

https://github.com/PersianDevelopers/ApplePay-Manager

Upvotes: 1

Related Questions