码迷,mamicode.com
首页 > 其他好文 > 详细

集成paypal支付

时间:2015-03-19 10:08:50      阅读:278      评论:0      收藏:0      [点我收藏+]

标签:

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 {

//p //paypal支付 PayPalEnvironmentSandbox:PAYPAL_SANDBOX

    [PayPalMobileinitializeWithClientIdsForEnvironments:@{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 = [[PayPalConfigurationalloc] init];

    _payPalConfig.acceptCreditCards = NO;

    _payPalConfig.languageOrLocale = [NSLocalepreferredLanguages][0];

    

    NSString *priceString = [NSString stringWithFormat:@"%f",self.order.price];

    NSDecimalNumber *total = [NSDecimalNumber decimalNumberWithString:priceString];

 

    PayPalPayment *payment = [[PayPalPaymentalloc] init];

    payment.amount = total;

    payment.currencyCode = @"HKD";

    payment.shortDescription = @"#####订单描述";

    payment.custom = self.order.order_no;

 

    PayPalPaymentViewController *paymentViewController = [[PayPalPaymentViewControlleralloc] initWithPayment:payment

                                                                                                configuration:self.payPalConfig

                                                                                                     delegate:self];

    [selfpresentViewController:paymentViewController animated:YEScompletion:nil];

}

 

 

#pragma mark PayPalPaymentDelegate methods

 

- (void)payPalPaymentViewController:(PayPalPaymentViewController *)paymentViewController didCompletePayment:(PayPalPayment *)completedPayment {

    NSLog(@"PayPal Payment Success!");

    

    [[NSNotificationCenterdefaultCenter]postNotificationName:kNoticePaidSuccessobject:@"paypal"userInfo:nil];

        

    [selfdismissViewControllerAnimated:YEScompletion:nil];

}

 

- (void)payPalPaymentDidCancel:(PayPalPaymentViewController *)paymentViewController {

    NSLog(@"PayPal Payment Canceled");

    

    [selfdismissViewControllerAnimated:YEScompletion:nil];

    

    UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:NSLocalizedString(@"支付结果", nil) message:NSLocalizedString(@"支付失败!请重新支付", nil) delegate:nilcancelButtonTitle:NSLocalizedString(@"确定", nil) otherButtonTitles:nil];

    [alert show];

 

}

 

 

集成paypal支付

标签:

原文地址:http://www.cnblogs.com/zhujin/p/4349530.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!