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之软件管理
    优雅的使用python之环境管理
    SpriteSheet精灵动画引擎
    【译】AS3利用CPU缓存
    走在网页游戏开发的路上(十一)
    自定义路径创建Cocos2d-x项目
    C++静态库与动态库
    C++对象模型
    超时空英雄传说2复仇魔神完全攻略&秘技
    从头写个http client(java)
  • 原文地址:https://www.cnblogs.com/zhujin/p/4349530.html
Copyright © 2011-2022 走看看