1、使用cocoapods
pod'PayPal-iOS-SDK'
2、AppDelegate 中key 的设置
[PayPalMobile initializeWithClientIdsForEnvironments:@{PayPalEnvironmentProduction:PAYPAL_PRODUCTION,PayPalEnvironmentSandbox:PAYPAL_SANDBOX}];
3、设置支付环境
[PayPalMobile preconnectWithEnvironment:PayPalEnvironmentProduction];
PayPalEnvironmentProduction 正式环境
PayPalEnvironmentSandbox
PayPalEnvironmentNoNetwork
4、付款页面
一、@property(nonatomic, strong, readwrite) PayPalConfiguration *payPalConfig;
二、实现代理 PayPalPaymentDelegate
三、点击付款
- (void)onClickPayPalButtonAction:(NSString *)orderId{
_payPalConfig = [[PayPalConfiguration alloc] init];
_payPalConfig.acceptCreditCards = NO;
_payPalConfig.languageOrLocale = [NSLocale preferredLanguages][0];
NSString*priceString =grand_total;
NSDecimalNumber*total = [NSDecimalNumberdecimalNumberWithString:priceString];
PayPalPayment *payment = [[PayPalPayment alloc] init];
payment.amount= total;
payment.currencyCode = currency_info.code;
payment.shortDescription=@"order summary";
payment.custom=orderId;//self.order.order_no;
// payment.shippingAddress= [PayPalShippingAddress shippingAddressWithRecipientName:@"1" withLine1:@"2" withLine2:@"3" withCity:@"3" withState:@"3" withPostalCode:@"4" withCountryCode:@"5"];
PayPalPaymentViewController *paymentViewController = [[PayPalPaymentViewController alloc]initWithPayment:payment configuration:self.payPalConfig delegate:self];
paymentViewController.modalPresentationStyle = UIModalPresentationOverFullScreen;
[self presentViewController:paymentViewController animated:YES completion:nil];
}
五、付款后代理方法 PayPalPaymentDelegate methods
- (void)payPalPaymentViewController:(PayPalPaymentViewController*)paymentViewControllerdidCompletePayment:(PayPalPayment*)completedPayment {
NSLog(@"PayPal Payment Success!");
[self dismissViewControllerAnimated:YES completion:nil];
[MBProgressHUD showSuccess:@"PayPal Payment Success!" toView:self.view];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
PaySuccess*pay=[[PaySuccessalloc]init];
pay.order_id=completedPayment.custom;
[self.navigationController pushViewController:pay animated:YES];
});
}
- (void)payPalPaymentDidCancel:(PayPalPaymentViewController*)paymentViewController {
NSLog(@"PayPal Payment Canceled");
[self dismissViewControllerAnimated:YES completion:nil];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[MBProgressHUD showSuccess:@"PayPal Payment failed!" toView:self.view];
});
}
网友评论