How to use applicationData in PKPaymentRequest (ApplePay)?

I want to set a pass-through variable on Apple Pay, I set NSDictionary as JSON :

 PKPaymentRequest *request = [[PKPaymentRequest alloc] init]; [request setApplicationData:[NSJSONSerialization dataWithJSONObject:@{@"name":@"USER_NAME"} options:NSJSONWritingPrettyPrinted error:nil]]; 

Now inside:

 - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didAuthorizePayment:(PKPayment *)payment completion:(void (^)(PKPaymentAuthorizationStatus status))completion; 

I can access applicationData as

 NSError* jsonError; NSDictionary* dataDict = [NSJSONSerialization JSONObjectWithData:payment.token.paymentData options:kNilOptions error:&jsonError]; 

dataDict [@ "header"] [@ "applicationData"] contains application data

but the data is encoded, I want to get @{@"name":@"USER_NAME"} from applicationData.

+5
source share

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


All Articles