1氮块、使用cocoapods
?? pod'PayPal-iOS-SDK'
2奏窑、AppDelegate 中key 的設(shè)置
?? [PayPalMobile initializeWithClientIdsForEnvironments:@{PayPalEnvironmentProduction:PAYPAL_PRODUCTION,PayPalEnvironmentSandbox:PAYPAL_SANDBOX}];
3、設(shè)置支付環(huán)境
? [PayPalMobile preconnectWithEnvironment:PayPalEnvironmentProduction];
PayPalEnvironmentProduction ?正式環(huán)境
?PayPalEnvironmentSandbox
?PayPalEnvironmentNoNetwork
4、付款頁面
一特占、@property(nonatomic, strong, readwrite) PayPalConfiguration *payPalConfig;
二、實(shí)現(xiàn)代理 PayPalPaymentDelegate
三云茸、點(diǎn)擊付款
- (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];
?? ? ? ? ? ? ? ? });
}