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

     

  • 相关阅读:
    Selenium webdriver 操作日历控件
    selenuim-webdriver注解之@FindBy、@FindBys、@FindAll的区别
    配置 mybatis的 log4j.properties
    查询在一个数据库中某个字段存在于哪些表
    Linux下修改Mysql的用户(root)的密码
    MySQL——修改root密码的4种方法(以windows为例)
    报错:1130-host ... is not allowed to connect to this MySql server 开放mysql远程连接 不使用localhost
    C++中的static 成员变量的一些注意点
    #pragma once与#ifndef的区别
    C++类中的成员函数和构造函数为模板函数时的调用方法
  • 原文地址:https://www.cnblogs.com/zhujin/p/4349530.html
Copyright © 2011-2022 走看看