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];
}