zoukankan      html  css  js  c++  java
  • 集成paypal支付

    https://developer.paypal.com

    cocoapods 管理 引入 

    pod 'PayPal-iOS-SDK'

    1.在appdelegate 

    #import <PayPalMobile.h>

    //#define PAYPAL_SANDBOX  @"AcQxuBDdBh3jNaYTnB79coxVr3wihIQVkJzI1stUX4V2yJByccNTgKNu1zeO"

    #define PAYPAL_PRODUCTION @"AZF********"

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

        [PayPalMobile initializeWithClientIdsForEnvironments:@{PayPalEnvironmentSandbox:PAYPAL_SANDBOX}];
        
    //    [PayPalMobile initializeWithClientIdsForEnvironments:@{PayPalEnvironmentProduction : PAYPAL_PRODUCTION}];

    }

    2.支付页面

    #import <PayPalMobile.h>

    遵循 <PayPalPaymentDelegate>//Paypal支付

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

     

    - (void)viewWillAppear:(BOOL)animated {
        
        [super viewWillAppear:animated];
        [PayPalMobile preconnectWithEnvironment:PayPalEnvironmentProduction];
    }
    #pragma mark - PaypalSDK支付
    - (void)onClickPayPalButtonAction:(UIButton *)sender
    {
        _payPalConfig = [[PayPalConfiguration alloc] init];
        _payPalConfig.acceptCreditCards = NO;
        _payPalConfig.languageOrLocale = [NSLocale preferredLanguages][0];
        
        NSString *priceString = [NSString stringWithFormat:@"%f",_totalPrice];
        NSDecimalNumber *total = [NSDecimalNumber decimalNumberWithString:priceString];
        
        PayPalPayment *payment = [[PayPalPayment alloc] init];
        payment.amount = total;
        payment.currencyCode = @"HKD";
        payment.shortDescription = @"#####订单描述";
        payment.custom = @"123456789";//self.order.order_no;
        
        PayPalPaymentViewController *paymentViewController = [[PayPalPaymentViewController alloc]initWithPayment:payment configuration:self.payPalConfig delegate:self];
        [self presentViewController:paymentViewController animated:YES completion:nil];
    }
    
    
    #pragma mark PayPalPaymentDelegate methods
    
    - (void)payPalPaymentViewController:(PayPalPaymentViewController *)paymentViewController didCompletePayment:(PayPalPayment *)completedPayment {
        NSLog(@"PayPal Payment Success!");
        
    //    [[NSNotificationCenter defaultCenter]postNotificationName:kNoticePaidSuccess object:@"paypal"userInfo:nil];
        
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    
    - (void)payPalPaymentDidCancel:(PayPalPaymentViewController *)paymentViewController {
        NSLog(@"PayPal Payment Canceled");
        
        [self dismissViewControllerAnimated:YES completion:nil];
        
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:NSLocalizedString(@"支付结果", nil) message:NSLocalizedString(@"支付失败!请重新支付", nil) delegate:nil cancelButtonTitle:NSLocalizedString(@"确定", nil) otherButtonTitles:nil];
        [alert show];
        
        
    }

    附录 网站步奏 https://developer.paypal.com/docs/api/quickstart/credentials/?mark=client%20id

    Create an app to get credentials

    Create an app to get credentials and use these credentials to authenticate when you make REST API requests.

    1. Go to My Apps & Credentials. Click Log In.

    2. In the REST API apps section, click Create App.

    3. On the Create New App page, enter an app name, select your sandbox developer account, and click Create App.

    4. The Sandbox tab shows your client ID. Click Show to show your secret. Note your client ID and secret. You'll need these values later.

    Stay logged in for the next step.

    Next

    Create a test account

     

  • 相关阅读:
    Java 基础(接口的应用:代理模式 Proxy)
    Appium 环境配置
    破解CCleaner
    数据驱动
    (C语言内存二十)C语言内存泄露(内存丢失)
    (C语言内存十九)C语言野指针以及非法内存操作
    (C语言内存十八)malloc函数背后的实现原理——内存池
    (C语言内存十七)栈溢出攻击的原理是什么?
    (C语言内存十六)C语言动态内存分配
    (C语言内存十五)用一个实例来深入剖析函数进栈出栈的过程
  • 原文地址:https://www.cnblogs.com/zhujin/p/4349530.html
Copyright © 2011-2022 走看看