|
@@ -54,47 +54,30 @@ static ASCheckoutPayManager *_instance = nil;
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
[self tool_gotoWebPay:urlStr withVC:topVC];
|
|
[self tool_gotoWebPay:urlStr withVC:topVC];
|
|
});
|
|
});
|
|
-
|
|
|
|
- NSLog(@"=====%@", json);
|
|
|
|
} faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
|
|
} faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
|
|
- K_STRONG_SELF;
|
|
|
|
|
|
+// K_STRONG_SELF;
|
|
[MBProgressHUD hideHUDForView:topVC.view animated:YES];
|
|
[MBProgressHUD hideHUDForView:topVC.view animated:YES];
|
|
}];
|
|
}];
|
|
|
|
|
|
} else if ([payType isEqualToString:@"stripe_payments"]) {//visa
|
|
} else if ([payType isEqualToString:@"stripe_payments"]) {//visa
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
double totalPay = [[payParam objectForKey:@"price"] doubleValue];
|
|
double totalPay = [[payParam objectForKey:@"price"] doubleValue];
|
|
-
|
|
|
|
ToolStripePayment *payment = [[ToolStripePayment alloc]init];
|
|
ToolStripePayment *payment = [[ToolStripePayment alloc]init];
|
|
NSString *price_unit_code = ASCurrencyManager.shared.currentCur;
|
|
NSString *price_unit_code = ASCurrencyManager.shared.currentCur;
|
|
if (price_unit_code.isEmpty) {
|
|
if (price_unit_code.isEmpty) {
|
|
price_unit_code = @"USD";
|
|
price_unit_code = @"USD";
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-// double totalPay = 212.00;
|
|
|
|
-// NSString *price_unit_code = @"USD";
|
|
|
|
- [payment stripedidTapCheckoutButtonWithCurrentvc:[Current_normalTool topViewController] publishableKey:@"pk_test_51MFDGRAxgV55iyHtmJFrPuz4i5cl1y3nhTLVT3EmsHlYLIwsj7TnPRPeulAUXSbOW7gccaVLJmFjVz4eu3E17g6z00TLI1YvoG" reqbaseUrl:BaseRequestrUrl(@"carts/mine/order") amount:totalPay*100 currency:price_unit_code addressModel:self.addressModel completion:^(NSInteger isState, id _Nonnull data) {
|
|
|
|
-
|
|
|
|
- NSLog(@"======%ld==========%@", isState, (NSString *)data);
|
|
|
|
-
|
|
|
|
- if(isState == 0){
|
|
|
|
- NSString *orderId = (NSString *)data;
|
|
|
|
-// [self tool_payMentSucessOrderId:orderId];
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- }];
|
|
|
|
|
|
+ [payment stripedidTapCheckoutButtonWithCurrentvc:[Current_normalTool topViewController] publishableKey:PayStripepublishableKey reqbaseUrl:BaseRequestrUrl(@"carts/mine/order") amount:totalPay*100 currency:price_unit_code addressModel:self.addressModel completion:nil];
|
|
|
|
|
|
payment.payFinishBlock = ^(NSString *status, NSString *orderid) {
|
|
payment.payFinishBlock = ^(NSString *status, NSString *orderid) {
|
|
- NSLog(@"======%@==========%@", status, orderid);
|
|
|
|
int statusInt = [status intValue];
|
|
int statusInt = [status intValue];
|
|
if (statusInt == 0) {
|
|
if (statusInt == 0) {
|
|
if (self.payFinishBlock) {
|
|
if (self.payFinishBlock) {
|
|
self.payFinishBlock(self.payType, 1, @{@"orderid":orderid});
|
|
self.payFinishBlock(self.payType, 1, @{@"orderid":orderid});
|
|
}
|
|
}
|
|
} else if (statusInt == 1) {
|
|
} else if (statusInt == 1) {
|
|
|
|
+ //二次验证
|
|
[self stripePayCreateOrderid:orderid];
|
|
[self stripePayCreateOrderid:orderid];
|
|
} else {
|
|
} else {
|
|
if (self.payFinishBlock) {
|
|
if (self.payFinishBlock) {
|
|
@@ -102,9 +85,7 @@ static ASCheckoutPayManager *_instance = nil;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
};
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
} else if ([payType isEqualToString:@"afterpay_payment"]) {//afterpay
|
|
} else if ([payType isEqualToString:@"afterpay_payment"]) {//afterpay
|
|
|
|
|
|
} else if ([payType isEqualToString:@"klarna_kco"]) {//klarna
|
|
} else if ([payType isEqualToString:@"klarna_kco"]) {//klarna
|
|
@@ -127,22 +108,30 @@ static ASCheckoutPayManager *_instance = nil;
|
|
|
|
|
|
}];
|
|
}];
|
|
} else {
|
|
} else {
|
|
-
|
|
|
|
|
|
+ //货到付款
|
|
|
|
+ [self stripePayCreateOrderid:@""];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#pragma mark ----- stripe支付 、 货到付款方式-----
|
|
//stripe支付(二次校验后生成订单)
|
|
//stripe支付(二次校验后生成订单)
|
|
- (void)stripePayCreateOrderid:(NSString *)payid {
|
|
- (void)stripePayCreateOrderid:(NSString *)payid {
|
|
UIViewController *topVC = topViewController();
|
|
UIViewController *topVC = topViewController();
|
|
|
|
|
|
- [MBProgressHUD showHUDAddedTo:topVC.view animated:YES];
|
|
|
|
- NSDictionary *methodDic = @{@"payment_method":payid,
|
|
|
|
- @"manual_authentication":@"card",
|
|
|
|
- @"payment_element":@(YES)};
|
|
|
|
|
|
+ NSDictionary *requestParams = nil;
|
|
|
|
+ if ([payid isEqualToString:@""]) {//货到付款方式
|
|
|
|
+ requestParams = @{@"paymentMethod":self.payType};
|
|
|
|
+ } else {//stripe支付
|
|
|
|
+ NSDictionary *methodDic = @{@"payment_method":payid,
|
|
|
|
+ @"manual_authentication":@"card",
|
|
|
|
+ @"payment_element":@(YES)};
|
|
|
|
+ NSDictionary *param = @{@"method":self.payType, @"additional_data":methodDic};
|
|
|
|
+ requestParams = @{@"paymentMethod":param};
|
|
|
|
+ }
|
|
|
|
|
|
- NSDictionary *param = @{@"method":self.payType, @"additional_data":methodDic};
|
|
|
|
|
|
+ [MBProgressHUD showHUDAddedTo:topVC.view animated:YES];
|
|
K_WEAK_SELF;
|
|
K_WEAK_SELF;
|
|
- [ASNetTools.shared putWithPath:Chectout_PUT_sureOrder param:@{@"paymentMethod":param} success:^(id _Nonnull json) {
|
|
|
|
|
|
+ [ASNetTools.shared putWithPath:Chectout_PUT_sureOrder param:requestParams success:^(id _Nonnull json) {
|
|
K_STRONG_SELF;
|
|
K_STRONG_SELF;
|
|
[MBProgressHUD hideHUDForView:topVC.view animated:YES];
|
|
[MBProgressHUD hideHUDForView:topVC.view animated:YES];
|
|
|
|
|
|
@@ -155,26 +144,53 @@ static ASCheckoutPayManager *_instance = nil;
|
|
K_STRONG_SELF;
|
|
K_STRONG_SELF;
|
|
[MBProgressHUD hideHUDForView:topVC.view animated:YES];
|
|
[MBProgressHUD hideHUDForView:topVC.view animated:YES];
|
|
if (self.payFinishBlock) {
|
|
if (self.payFinishBlock) {
|
|
- self.payFinishBlock(self.payType, 0, @{@"msg":@"取消支付/支付失败"});
|
|
|
|
|
|
+ self.payFinishBlock(self.payType, 0, @{@"msg":@"支付失败"});
|
|
}
|
|
}
|
|
}];
|
|
}];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#pragma mark ----- PayPal支付 -----
|
|
//paypal支付
|
|
//paypal支付
|
|
- (void)tool_gotoWebPay:(NSString *)urlStr withVC:(UIViewController *)tmpvc {
|
|
- (void)tool_gotoWebPay:(NSString *)urlStr withVC:(UIViewController *)tmpvc {
|
|
XXX_BaseWebC *vc = [[XXX_BaseWebC alloc] init];
|
|
XXX_BaseWebC *vc = [[XXX_BaseWebC alloc] init];
|
|
vc.isPayType = YES;
|
|
vc.isPayType = YES;
|
|
|
|
+ K_WEAK_SELF;
|
|
vc.WebViewBlock = ^(NSUInteger status, id _Nonnull webData) {
|
|
vc.WebViewBlock = ^(NSUInteger status, id _Nonnull webData) {
|
|
-
|
|
|
|
- if (self.payFinishBlock) {
|
|
|
|
- self.payFinishBlock(self.payType, status, webData);
|
|
|
|
- }
|
|
|
|
|
|
+ K_STRONG_SELF;
|
|
|
|
+ [self requestVerifyPaypalToken:webData];
|
|
};
|
|
};
|
|
[vc xxx_dsWebLoadUrl:urlStr];
|
|
[vc xxx_dsWebLoadUrl:urlStr];
|
|
vc.modalPresentationStyle = UIModalPresentationFullScreen;
|
|
vc.modalPresentationStyle = UIModalPresentationFullScreen;
|
|
[tmpvc presentViewController:vc animated:YES completion:nil];
|
|
[tmpvc presentViewController:vc animated:YES completion:nil];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+//paypal支付 Token验证
|
|
|
|
+- (void)requestVerifyPaypalToken:(NSDictionary *)dic {
|
|
|
|
+ UIViewController *topVC = topViewController();
|
|
|
|
+
|
|
|
|
+ NSDictionary *params = @{@"token":[dic objectForKey:@"token"]};
|
|
|
|
+ [MBProgressHUD showHUDAddedTo:topVC.view animated:YES];
|
|
|
|
+ K_WEAK_SELF;
|
|
|
|
+ [ASNetTools.shared postWithPath:Chectout_Verify_PayToken param:params success:^(id _Nonnull json) {
|
|
|
|
+ K_STRONG_SELF;
|
|
|
|
+ [MBProgressHUD hideHUDForView:topVC.view animated:YES];
|
|
|
|
+
|
|
|
|
+ NSDictionary *payReturnDic = (NSDictionary *)json;
|
|
|
|
+ NSString *orderid = [payReturnDic objectForKey:@"id"];
|
|
|
|
+ if (self.payFinishBlock) {
|
|
|
|
+ self.payFinishBlock(self.payType, 1, @{@"orderid":orderid});
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
|
|
|
|
+ K_STRONG_SELF;
|
|
|
|
+ [MBProgressHUD hideHUDForView:topVC.view animated:YES];
|
|
|
|
+ if (self.payFinishBlock) {
|
|
|
|
+ self.payFinishBlock(self.payType, 0, @{@"msg":@"支付失败"});
|
|
|
|
+ }
|
|
|
|
+ }];
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+#pragma mark ----- klarna支付验证 -----
|
|
//klarna支付验证
|
|
//klarna支付验证
|
|
-(void)tool_verifyOrderAutoken:(NSString *)authToken{
|
|
-(void)tool_verifyOrderAutoken:(NSString *)authToken{
|
|
|
|
|
|
@@ -184,10 +200,8 @@ static ASCheckoutPayManager *_instance = nil;
|
|
|
|
|
|
[MBProgressHUD showHUDAddedTo:topVC.view animated:YES];
|
|
[MBProgressHUD showHUDAddedTo:topVC.view animated:YES];
|
|
K_WEAK_SELF;
|
|
K_WEAK_SELF;
|
|
- [ASNetTools.shared postWithPath:@"rest/V1/rewrite/klarna/checkoutQuoteStatus" param:params success:^(id _Nonnull json) {
|
|
|
|
|
|
+ [ASNetTools.shared postWithPath:Chectout_Verify_KlarnaCart param:params success:^(id _Nonnull json) {
|
|
K_STRONG_SELF;
|
|
K_STRONG_SELF;
|
|
-// [MBProgressHUD hideHUDForView:topVC.view animated:YES];
|
|
|
|
-
|
|
|
|
|
|
|
|
NSString *is_active = [(NSDictionary *)json objectForKey:@"is_active"];
|
|
NSString *is_active = [(NSDictionary *)json objectForKey:@"is_active"];
|
|
NSLog(@"=======%@", is_active);
|
|
NSLog(@"=======%@", is_active);
|
|
@@ -197,14 +211,12 @@ static ASCheckoutPayManager *_instance = nil;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
} faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
|
|
} faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
|
|
K_STRONG_SELF;
|
|
K_STRONG_SELF;
|
|
[MBProgressHUD hideHUDForView:topVC.view animated:YES];
|
|
[MBProgressHUD hideHUDForView:topVC.view animated:YES];
|
|
|
|
|
|
if (self.payFinishBlock) {
|
|
if (self.payFinishBlock) {
|
|
- self.payFinishBlock(self.payType, 0, @{@"msg":@"取消支付/支付失败"});
|
|
|
|
|
|
+ self.payFinishBlock(self.payType, 0, @{@"msg":@"支付失败"});
|
|
}
|
|
}
|
|
}];
|
|
}];
|
|
}
|
|
}
|
|
@@ -240,19 +252,13 @@ static ASCheckoutPayManager *_instance = nil;
|
|
[MBProgressHUD hideHUDForView:topVC.view animated:YES];
|
|
[MBProgressHUD hideHUDForView:topVC.view animated:YES];
|
|
|
|
|
|
if (self.payFinishBlock) {
|
|
if (self.payFinishBlock) {
|
|
- self.payFinishBlock(self.payType, 0, @{@"msg":@"取消支付/支付失败"});
|
|
|
|
|
|
+ self.payFinishBlock(self.payType, 0, @{@"msg":@"支付失败"});
|
|
}
|
|
}
|
|
}];
|
|
}];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-#pragma mark - **************** KlarnaEventHandler ****************
|
|
|
|
-- (void)klarnaComponent:(id <KlarnaComponent> _Nonnull)klarnaComponent dispatchedEvent:(KlarnaProductEvent * _Nonnull)event{
|
|
|
|
- NSLog(@"klarna---111---%@",event.qmui_allBindingKeys);
|
|
|
|
-}
|
|
|
|
-- (void)klarnaComponent:(id <KlarnaComponent> _Nonnull)klarnaComponent encounteredError:(KlarnaError * _Nonnull)error{
|
|
|
|
- NSLog(@"klarna---222---error:%@",error);
|
|
|
|
-}
|
|
|
|
|
|
+
|
|
#pragma mark - **************** KlarnaPaymentEventListener ****************
|
|
#pragma mark - **************** KlarnaPaymentEventListener ****************
|
|
- (void)klarnaInitializedWithPaymentView:(KlarnaPaymentView * _Nonnull)paymentView { //init 成功
|
|
- (void)klarnaInitializedWithPaymentView:(KlarnaPaymentView * _Nonnull)paymentView { //init 成功
|
|
NSLog(@"klarna---888---%@",self.client_token);
|
|
NSLog(@"klarna---888---%@",self.client_token);
|
|
@@ -261,34 +267,19 @@ static ASCheckoutPayManager *_instance = nil;
|
|
//klarna_3 授权支付操作 klarna_getClientTokenAurhorizePay
|
|
//klarna_3 授权支付操作 klarna_getClientTokenAurhorizePay
|
|
[self.klarna_payV authorizeWithAutoFinalize:YES jsonData:self.client_token];
|
|
[self.klarna_payV authorizeWithAutoFinalize:YES jsonData:self.client_token];
|
|
}
|
|
}
|
|
-- (void)klarnaLoadedWithPaymentView:(KlarnaPaymentView * _Nonnull)paymentView {
|
|
|
|
- NSLog(@"klarna---333---%@",paymentView);
|
|
|
|
-// self.bottomPaybtn.backgroundColor = [UIColor colorWithHexString:@"#B2000F"];
|
|
|
|
-// self.bottomPaybtn.userInteractionEnabled = YES;
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-- (void)klarnaLoadedPaymentReviewWithPaymentView:(KlarnaPaymentView * _Nonnull)paymentView {
|
|
|
|
- NSLog(@"klarna---444---%@",paymentView);
|
|
|
|
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
- (void)klarnaAuthorizedWithPaymentView:(KlarnaPaymentView * _Nonnull)paymentView approved:(BOOL)approved authToken:(NSString * _Nullable)authToken finalizeRequired:(BOOL)finalizeRequired {
|
|
- (void)klarnaAuthorizedWithPaymentView:(KlarnaPaymentView * _Nonnull)paymentView approved:(BOOL)approved authToken:(NSString * _Nullable)authToken finalizeRequired:(BOOL)finalizeRequired {
|
|
|
|
|
|
NSLog(@"klarna---555---%@--approved---%d",authToken, approved);
|
|
NSLog(@"klarna---555---%@--approved---%d",authToken, approved);
|
|
|
|
|
|
if (approved == true ){
|
|
if (approved == true ){
|
|
NSLog(@"klarna 授权支付成功");
|
|
NSLog(@"klarna 授权支付成功");
|
|
-// if (self.payFinishBlock) {
|
|
|
|
-// self.payFinishBlock(self.payType, 1, @{@"token":authToken});
|
|
|
|
-// }
|
|
|
|
-// self.author_token = authToken;
|
|
|
|
-// [self tool_creatOrderAutoken:authToken];
|
|
|
|
[self tool_verifyOrderAutoken:authToken];
|
|
[self tool_verifyOrderAutoken:authToken];
|
|
|
|
|
|
} else {
|
|
} else {
|
|
-// if (self.payFinishBlock) {
|
|
|
|
-// self.payFinishBlock(self.payType, 0, @{@"token":authToken});
|
|
|
|
-// }
|
|
|
|
|
|
+ if (self.payFinishBlock) {
|
|
|
|
+ self.payFinishBlock(self.payType, 0, @{@"msg":@"支付失败"});
|
|
|
|
+ }
|
|
NSLog(@"klarna 授权支付失败");
|
|
NSLog(@"klarna 授权支付失败");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -298,6 +289,13 @@ static ASCheckoutPayManager *_instance = nil;
|
|
[self tool_creatOrderAutoken:authToken];
|
|
[self tool_creatOrderAutoken:authToken];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+#pragma mark - **************** KlarnaEventHandler ****************
|
|
|
|
+- (void)klarnaComponent:(id <KlarnaComponent> _Nonnull)klarnaComponent dispatchedEvent:(KlarnaProductEvent * _Nonnull)event{
|
|
|
|
+ NSLog(@"klarna---111---%@",event.qmui_allBindingKeys);
|
|
|
|
+}
|
|
|
|
+- (void)klarnaComponent:(id <KlarnaComponent> _Nonnull)klarnaComponent encounteredError:(KlarnaError * _Nonnull)error{
|
|
|
|
+ NSLog(@"klarna---222---error:%@",error);
|
|
|
|
+}
|
|
- (void)klarnaResizedWithPaymentView:(KlarnaPaymentView * _Nonnull)paymentView to:(CGFloat)newHeight {
|
|
- (void)klarnaResizedWithPaymentView:(KlarnaPaymentView * _Nonnull)paymentView to:(CGFloat)newHeight {
|
|
// [self.klarna_payV mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
// [self.klarna_payV mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
// make.height.mas_equalTo(newHeight);
|
|
// make.height.mas_equalTo(newHeight);
|
|
@@ -310,8 +308,18 @@ static ASCheckoutPayManager *_instance = nil;
|
|
- (void)klarnaFinalizedWithPaymentView:(KlarnaPaymentView * _Nonnull)paymentView approved:(BOOL)approved authToken:(NSString * _Nullable)authToken {
|
|
- (void)klarnaFinalizedWithPaymentView:(KlarnaPaymentView * _Nonnull)paymentView approved:(BOOL)approved authToken:(NSString * _Nullable)authToken {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+- (void)klarnaLoadedWithPaymentView:(KlarnaPaymentView * _Nonnull)paymentView {
|
|
|
|
+ NSLog(@"klarna---333---%@",paymentView);
|
|
|
|
+// self.bottomPaybtn.backgroundColor = [UIColor colorWithHexString:@"#B2000F"];
|
|
|
|
+// self.bottomPaybtn.userInteractionEnabled = YES;
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+- (void)klarnaLoadedPaymentReviewWithPaymentView:(KlarnaPaymentView * _Nonnull)paymentView {
|
|
|
|
+ NSLog(@"klarna---444---%@",paymentView);
|
|
|
|
|
|
|
|
|
|
|
|
+}
|
|
|
|
+
|
|
#pragma mark - **************** lazy ****************
|
|
#pragma mark - **************** lazy ****************
|
|
-(KlarnaPaymentView *)klarna_payV{
|
|
-(KlarnaPaymentView *)klarna_payV{
|
|
if(!_klarna_payV){
|
|
if(!_klarna_payV){
|