|
@@ -19,7 +19,10 @@
|
|
|
|
|
|
#import "ASAddGiftGoodsView.h"
|
|
#import "ASAddGiftGoodsView.h"
|
|
|
|
|
|
-@interface Cart_CheckoutC ()<RY_baseVMprotocol>
|
|
|
|
|
|
+#import <PayPal-iOS-SDK/PayPalMobile.h>
|
|
|
|
+#import <PayPal-iOS-SDK/PayPalConfiguration.h>
|
|
|
|
+
|
|
|
|
+@interface Cart_CheckoutC ()<RY_baseVMprotocol, PayPalPaymentDelegate>
|
|
|
|
|
|
@property (nonatomic, strong) CartVM *VM;
|
|
@property (nonatomic, strong) CartVM *VM;
|
|
|
|
|
|
@@ -50,15 +53,72 @@
|
|
@property (nonatomic, assign) int index;
|
|
@property (nonatomic, assign) int index;
|
|
@property (nonatomic, assign) int giftShowCount;
|
|
@property (nonatomic, assign) int giftShowCount;
|
|
|
|
|
|
|
|
+//paypal支付
|
|
|
|
+@property (nonatomic, strong) PayPalConfiguration *payPalConfiguration;
|
|
|
|
+
|
|
|
|
|
|
@end
|
|
@end
|
|
|
|
|
|
@implementation Cart_CheckoutC
|
|
@implementation Cart_CheckoutC
|
|
|
|
|
|
|
|
+- (void)initPayPalConfiguration{
|
|
|
|
+ _payPalConfiguration = [[PayPalConfiguration alloc] init];
|
|
|
|
+ _payPalConfiguration.merchantName = @"龙熠科技有限公司";//公司名称
|
|
|
|
+ _payPalConfiguration.acceptCreditCards = NO;
|
|
|
|
+ _payPalConfiguration.payPalShippingAddressOption = PayPalShippingAddressOptionPayPal;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//amount:金额
|
|
|
|
+//currencyCode:获取单位 比如:USD
|
|
|
|
+//shortDescription:商品标题 简短描述
|
|
|
|
+- (void)PayPalWithAmount:(NSString *)amount currencyCode:(NSString *)currencyCode shortDescription:(NSString *)shortDescription{
|
|
|
|
+
|
|
|
|
+ PayPalPayment *payment = [[PayPalPayment alloc] init];
|
|
|
|
+ payment.amount = [[NSDecimalNumber alloc] initWithString:amount];
|
|
|
|
+ payment.currencyCode = currencyCode;
|
|
|
|
+ payment.shortDescription = @"购买商品购买商品购买商品";
|
|
|
|
+ payment.items = nil; // if not including multiple items, then leave payment.items as nil
|
|
|
|
+ payment.paymentDetails = nil; // if not including payment details, then leave payment.paymentDetails as nil
|
|
|
|
+ payment.intent = PayPalPaymentIntentSale;
|
|
|
|
+ if (!payment.processable) {
|
|
|
|
+ NSLog(@"-------------");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ PayPalPaymentViewController *paymentViewController = [[PayPalPaymentViewController alloc] initWithPayment:payment configuration:self.payPalConfiguration delegate:self];
|
|
|
|
+ [self presentViewController:paymentViewController animated:YES completion:nil];
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+#pragma mark - PayPalPaymentDelegate methods
|
|
|
|
+
|
|
|
|
+- (void)payPalPaymentViewController:(nonnull PayPalPaymentViewController *)paymentViewController
|
|
|
|
+ didCompletePayment:(nonnull PayPalPayment *)completedPayment {
|
|
|
|
+ // 支付成功,可以处理你的支付逻辑
|
|
|
|
+ NSLog(@"支付成功: %@", completedPayment.confirmation);
|
|
|
|
+ [self dismissViewControllerAnimated:YES completion:nil];
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+- (void)payPalPaymentDidCancel:(nonnull PayPalPaymentViewController *)paymentViewController {
|
|
|
|
+ NSLog(@"支付取消");
|
|
|
|
+ [self dismissViewControllerAnimated:YES completion:nil];
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+- (void)viewWillAppear:(BOOL)animated {
|
|
|
|
+ [super viewWillAppear:animated];
|
|
|
|
+
|
|
|
|
+ [PayPalMobile preconnectWithEnvironment:PayPalEnvironmentSandbox];
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
- (void)viewDidLoad {
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[super viewDidLoad];
|
|
self.title = @"Checkout";
|
|
self.title = @"Checkout";
|
|
|
|
|
|
|
|
+// [PayPalMobile preconnectWithEnvironment:PayPalEnvironmentSandbox];
|
|
|
|
+// [ PayPalMobile clearAllUserData];
|
|
|
|
+
|
|
|
|
+ [self initPayPalConfiguration];
|
|
|
|
+
|
|
//获取支付方式
|
|
//获取支付方式
|
|
[self requestPaymentMode];
|
|
[self requestPaymentMode];
|
|
//获取运输方式
|
|
//获取运输方式
|
|
@@ -466,8 +526,34 @@
|
|
}
|
|
}
|
|
//下单
|
|
//下单
|
|
-(void)requestSureOrder{
|
|
-(void)requestSureOrder{
|
|
|
|
+
|
|
|
|
+ NSString *paymentCode = self.paymentModel.code;
|
|
|
|
+
|
|
|
|
+ if ([paymentCode isEqualToString:@"paypal_express"]) {//paypal
|
|
|
|
+
|
|
|
|
+ for (int i=0; i<self.totalCellM.total_segments.count; i++) {
|
|
|
|
+ NSDictionary *dic = self.totalCellM.total_segments[i];
|
|
|
|
+ NSString *code = MM_str(dic[@"code"]);
|
|
|
|
+ if ([code isEqualToString:@"grand_total"]){ //subBottomV
|
|
|
|
+ NSString *priceStr = [NSString stringWithFormat:@"%@",dic[@"value"]];
|
|
|
|
+ [self PayPalWithAmount:priceStr currencyCode:ASCurrencyManager.shared.currentCur shortDescription:@"购买商品"];
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return;
|
|
|
|
+ } else if ([paymentCode isEqualToString:@"stripe_payments"]) {//visa
|
|
|
|
+
|
|
|
|
+ } else if ([paymentCode isEqualToString:@"afterpay_payment"]) {//afterpay
|
|
|
|
+
|
|
|
|
+ } else if ([paymentCode isEqualToString:@"klarna_kco"]) {//klarna
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
|
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
|
- NSDictionary *param = @{@"method":self.paymentModel.code};
|
|
|
|
|
|
+ NSDictionary *param = @{@"method":paymentCode};
|
|
|
|
|
|
[ASNetTools.shared putWithPath:Chectout_PUT_sureOrder param:@{@"paymentMethod":param} success:^(id _Nonnull json) {
|
|
[ASNetTools.shared putWithPath:Chectout_PUT_sureOrder param:@{@"paymentMethod":param} success:^(id _Nonnull json) {
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|