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

     

  • 相关阅读:
    全局变量与全局静态变量的区别:
    Python模块学习 ---- datetime
    python sys.path用法
    过来人谈《去360还是留在百度?》
    [编码问题] Python错误: SyntaxError: Non-ASCII character
    E513: write error, conversion failed (make 'fenc' empty to override)"解决办法
    巴真的点评
    set之hashset与TreeSet、LinkedHashSet实现原理
    list之linedlist与arraylist实现原理
    统一会话与单点登录
  • 原文地址:https://www.cnblogs.com/zhujin/p/4349530.html
Copyright © 2011-2022 走看看