0

我正在研究如何在 iOS 应用程序中集成 PayPal/Apple Pay 支付模块。

例如,在我的应用程序中,我想集成 PayPal/Apple pay for payment,那我该怎么办?流程是什么。

如果任何人都可以指导如何做到这一点。请建议我的步骤。然后也欢迎任何参考链接。

4

3 回答 3

2

在 AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [PayPalMobile initializeWithClientIdsForEnvironments:@{PayPalEnvironmentProduction : @"YOUR_CLIENT_ID_FOR_PRODUCTION",
                                                           PayPalEnvironmentSandbox : @"AeB0tbkw-z4Ys3NvxekUZxnVNk26WXRodQBETFG4x-HtQAuqBf5k4edWOn2zia_l8RWBFJGEUNSVWJWg"}];

    return YES;
}

与您的控制器

在您的 .h 文件集委托中

@interface MyCart : UITableViewController

@property(nonatomic, strong, readwrite) PayPalConfiguration *payPalConfig;

在你的 .m 文件中

- (void)viewDidLoad {
 NSString *environment=@"sandbox";
    self.environment = environment;
    [PayPalMobile preconnectWithEnvironment:environment];


 _payPalConfig = [[PayPalConfiguration alloc] init];
    _payPalConfig.acceptCreditCards = YES;
    _payPalConfig.merchantName = @"ScanPay";
    _payPalConfig.merchantPrivacyPolicyURL = [NSURL URLWithString:@"https://www.paypal.com/webapps/mpp/ua/privacy-full"];
    _payPalConfig.merchantUserAgreementURL = [NSURL URLWithString:@"https://www.paypal.com/webapps/mpp/ua/useragreement-full"];

    _payPalConfig.languageOrLocale = [NSLocale preferredLanguages][0];

    _payPalConfig.payPalShippingAddressOption = PayPalShippingAddressOptionPayPal;


}

带有购买按钮事件的代码

-(IBAction)btnCheckoutTapped
{
//    UIAlertView *alt=[[UIAlertView alloc]initWithTitle:@"ScanPay" message:@"Under Development" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
//    [alt show];

    NSDecimalNumber *subtotal = [[NSDecimalNumber alloc]initWithDouble:Price];

    // Optional: include payment details
    NSDecimalNumber *shipping = [[NSDecimalNumber alloc] initWithString:@"0.00"];
    NSDecimalNumber *tax = [[NSDecimalNumber alloc] initWithString:@"0.00"];
    PayPalPaymentDetails *paymentDetails = [PayPalPaymentDetails paymentDetailsWithSubtotal:subtotal
                                                                               withShipping:shipping
                                                                                    withTax:tax];
    NSDecimalNumber *total = [[subtotal decimalNumberByAdding:shipping] decimalNumberByAdding:tax];

    PayPalPayment *payment = [[PayPalPayment alloc] init];
    payment.amount = total;
    payment.currencyCode = @"USD";
    payment.shortDescription = @"You Pay";
    payment.paymentDetails = paymentDetails; // if not including payment details, then leave payment.paymentDetails as nil
    if (!payment.processable) {
        // This particular payment will always be processable. If, for
        // example, the amount was negative or the shortDescription was
        // empty, this payment wouldn't be processable, and you'd want
        // to handle that here.
    }
    // Update payPalConfig re accepting credit cards.
    self.payPalConfig.acceptCreditCards = YES;

    PayPalPaymentViewController *paymentViewController = [[PayPalPaymentViewController alloc] initWithPayment:payment
                                                                                                configuration:self.payPalConfig
                                                                                                     delegate:self];
    [self presentViewController:paymentViewController animated:YES completion:nil];


}

PayPalPaymentDelegate 方法

- (void)payPalPaymentViewController:(PayPalPaymentViewController *)paymentViewController didCompletePayment:(PayPalPayment *)completedPayment {
    NSLog(@"PayPal Payment Success!");
    [self ErrorWithString:@"PayPal Payment Success!"];



    self.resultText = [completedPayment description];
    //[self showSuccess];

    [self sendCompletedPaymentToServer:completedPayment]; // Payment was processed successfully; send to server for verification and fulfillment
    [self dismissViewControllerAnimated:YES completion:nil];

    ReceiptScreen *obj=[self.storyboard instantiateViewControllerWithIdentifier:@"ReceiptScreen"];
    [self.navigationController pushViewController:obj animated:YES];

}

- (void)payPalPaymentDidCancel:(PayPalPaymentViewController *)paymentViewController {
    NSLog(@"PayPal Payment Canceled");
    self.resultText = nil;
  //  self.successView.hidden = YES;
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark Proof of payment validation

- (void)sendCompletedPaymentToServer:(PayPalPayment *)completedPayment {
    // TODO: Send completedPayment.confirmation to server
    NSLog(@"Here is your proof of payment:\n\n%@\n\nSend this to your server for confirmation and fulfillment.", completedPayment.confirmation);
}
于 2015-10-09T06:54:28.543 回答
2

这取决于您集成的支付解决方案。PayPal 将支持账户余额或与账户关联的信用卡/借记卡/银行的资金来源。虽然与 PayPal 钱包不同,Apple Pay/Apple Wallet 中没有“余额”功能,它仅适用于卡标记化(您在 Wallet App 中设置的卡)。

在这个用例中,您的应用程序不必检查钱包中是否有 20 美元(PayPal 或 Apple Pay),而是会发起支付请求,并从支付网关获取响应以处理您的订单

于 2015-10-09T02:54:20.110 回答
1
  1. PayPal - 这是由PayPal Developer GuideSample codehttps://developer.paypal.com建议的完整 PayPal 示例代码

  2. Apple Pay - 您可以查看它的 Apple演示代码

我希望你正在寻找它。:)

于 2015-10-09T14:00:36.913 回答