Mohsin Khubaib Ahmed
Mohsin Khubaib Ahmed

Reputation: 1018

For ApplePay paymentAuthorizationViewController delegate creates nil PKSummaryItem

In reference to this question, thank you for narrowing it down. But sadly I have to configure this delegate

- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller
               didSelectShippingMethod:(PKShippingMethod *)shippingMethod                   
completion:(void (^)(PKPaymentAuthorizationStatus, NSArray *summaryItems))completion
{
    completion(PKPaymentAuthorizationStatusSuccess, [self summaryItemsForShippingMethod:shippingMethod]);
}

- (NSArray *)summaryItemsForShippingMethod:(PKShippingMethod *)shippingMethod
{
    totalPrice = 5;
    NSString *prices = [NSString stringWithFormat:@"%d",totalPrice];
    NSDecimalNumber *num = [[NSDecimalNumber alloc] initWithString:prices];
    PKPaymentSummaryItem *foodItem = [PKPaymentSummaryItem summaryItemWithLabel:@"Total Products Cost" amount:num];
    NSDecimalNumber *total = [foodItem.amount decimalNumberByAdding:shippingMethod.amount];
    PKPaymentSummaryItem *totalItem = [PKPaymentSummaryItem summaryItemWithLabel:@"Video Mantis Productions, INC." amount:total];
    return @[foodItem, shippingMethod, totalItem];
}

in order to show the user what products summary really is. Sadly I am getting PKPaymentSummaryItem *foodItem as nil and consequently the processing doesn't ever gets fixed. Please HELP! Thank you in advance.

Upvotes: 0

Views: 749

Answers (2)

Mohsin Khubaib Ahmed
Mohsin Khubaib Ahmed

Reputation: 1018

So the answer, eh? I was using Stripe as an intermediate medium for transactions with ApplePay and hence used their SDK and tutorials to setUp ApplePay as well. Anyhow, the Passkit's PKPaymentAuthorizationViewController uses two separate protocols that can be configured in order to help ease up the implementation. I was using both, namely;

- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller
                   didSelectShippingMethod:(PKShippingMethod *)shippingMethod
                                completion:(void (^)(PKPaymentAuthorizationStatus status, NSArray *summaryItems))completion;

And...

- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller
                  didSelectShippingAddress:(ABRecordRef)address
                                completion:(void (^)(PKPaymentAuthorizationStatus status, NSArray *shippingMethods, NSArray *summaryItems))completion;

However, what I noticed was when the later one was called, that is, didSelectShippingAddress, the Passkit kind of stalled, so I removed it and only used the first one that is didSelectShippingMethod to help implement the entire thing, and the infinite processing never occurred again! Hope it works out for you too (:

Upvotes: 1

Thibaud David
Thibaud David

Reputation: 504

PKPaymentSummaryItem is available from iOS 8, so if you are trying to use it with a less recent iOS version, you'll get nil instead of expected value.

I just got stuck with this too

Upvotes: 0

Related Questions