Search code examples
ioscordovastripe-paymentspayment-processing

How to integrate PhoneGap mobile app with ApplePay and Stripe


Can you add ApplePay to an iOS PhoneGap application, using Stripe?


Solution

  • Here is the code snippet for it. Calling this method will invoke apple pay's controllersheet

    -(void)handlesApplePay
    {
    
        @try {
    
            PKPaymentSummaryItem *paymentSummary = [PKPaymentSummaryItem summaryItemWithLabel:@"Credit Card" amount:[NSDecimalNumber decimalNumberWithString:@"20.00"]];
    
            NSArray *summaryItem = [[NSArray alloc] initWithObjects:paymentSummary, nil];
    
            //Creates the type of credit card it wil support
            NSArray *supportPaymentType = [[NSArray alloc] initWithObjects:PKPaymentNetworkAmex, PKPaymentNetworkMasterCard, PKPaymentNetworkVisa, nil];
    
            PKPaymentRequest *paymentRequest = [[PKPaymentRequest alloc]init];
    
            //This is the merchant id you create from the provisioing profile page
            //developer.apple.com
            paymentRequest.merchantIdentifier = @"merchant.com.ApplePay";
            paymentRequest.paymentSummaryItems = summaryItem;
            paymentRequest.countryCode = @"EN";
            paymentRequest.currencyCode = @"USD";
            paymentRequest.supportedNetworks = supportPaymentType;
            paymentRequest.merchantCapabilities = PKMerchantCapabilityEMV;
    
            PKPaymentAuthorizationViewController *paymentAuthController = [[PKPaymentAuthorizationViewController alloc]initWithPaymentRequest:paymentRequest];
            paymentAuthController.delegate = self;
    
            [self presentViewController:paymentAuthController animated:YES completion:nil];
        }
        @catch (NSException *exception) {
    
        }
    
    
    }