|
@@ -15,7 +15,14 @@
|
|
|
#import "CartVM.h"
|
|
|
#import "ASUserModel.h"
|
|
|
|
|
|
-@interface Cart_CheckoutC ()<RY_baseVMprotocol>
|
|
|
+#import "ASGoodsDetailsVM.h"
|
|
|
+
|
|
|
+#import "ASAddGiftGoodsView.h"
|
|
|
+
|
|
|
+#import <PayPal-iOS-SDK/PayPalMobile.h>
|
|
|
+#import <PayPal-iOS-SDK/PayPalConfiguration.h>
|
|
|
+
|
|
|
+@interface Cart_CheckoutC ()<RY_baseVMprotocol, PayPalPaymentDelegate>
|
|
|
|
|
|
@property (nonatomic, strong) CartVM *VM;
|
|
|
|
|
@@ -38,14 +45,80 @@
|
|
|
@property (nonatomic, strong) ASCheckoutPaymentModel *paymentModel;
|
|
|
|
|
|
|
|
|
+//手动添加赠品至购物车
|
|
|
+@property (nonatomic, strong) ASGoodsDetailsVM *goodsDetailsVM;
|
|
|
+
|
|
|
+@property (nonatomic, strong) ASAddGiftGoodsView *addGiftView;
|
|
|
+@property (nonatomic, strong) NSMutableArray *addGiftParamArr;
|
|
|
+@property (nonatomic, assign) int index;
|
|
|
+@property (nonatomic, assign) int giftShowCount;
|
|
|
+
|
|
|
+//paypal支付
|
|
|
+@property (nonatomic, strong) PayPalConfiguration *payPalConfiguration;
|
|
|
+
|
|
|
+
|
|
|
@end
|
|
|
|
|
|
@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 {
|
|
|
[super viewDidLoad];
|
|
|
self.title = @"Checkout";
|
|
|
|
|
|
+// [PayPalMobile preconnectWithEnvironment:PayPalEnvironmentSandbox];
|
|
|
+// [ PayPalMobile clearAllUserData];
|
|
|
+
|
|
|
+ [self initPayPalConfiguration];
|
|
|
+
|
|
|
//获取支付方式
|
|
|
[self requestPaymentMode];
|
|
|
//获取运输方式
|
|
@@ -57,6 +130,10 @@
|
|
|
- (void)initSubviews {
|
|
|
[super initSubviews];
|
|
|
|
|
|
+ self.addGiftParamArr = [[NSMutableArray alloc] initWithCapacity:1];
|
|
|
+ self.index = 0;
|
|
|
+ self.giftShowCount = 0;
|
|
|
+
|
|
|
IPhoneXHeigh
|
|
|
[self setupTableV:[CartCheckTableV class] Frame:CGRectMake(0, securitytop_Y , KScreenWidth, KScreenHeight - securitytop_Y)];
|
|
|
self.TableV.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
|
|
@@ -211,16 +288,43 @@
|
|
|
[self updateData];
|
|
|
|
|
|
} else if ([mark isEqualToString:Cart_cartsMineItems_Post]
|
|
|
- || [mark isEqualToString:DEL_cartsMineItems]
|
|
|
- || [mark isEqualToString:PUT_cartsMineCoupons]
|
|
|
- || [mark isEqualToString:Chectout_PUT_usePoints]
|
|
|
- || [mark isEqualToString:Chectout_DEL_cancelusePoints]
|
|
|
- || [mark isEqualToString:Chectout_setShipMethod]){
|
|
|
+ || [mark isEqualToString:DEL_cartsMineItems]
|
|
|
+ || [mark isEqualToString:PUT_cartsMineCoupons]
|
|
|
+ || [mark isEqualToString:Chectout_PUT_usePoints]
|
|
|
+ || [mark isEqualToString:Chectout_DEL_cancelusePoints]
|
|
|
+ || [mark isEqualToString:Chectout_setShipMethod]
|
|
|
+ || [mark isEqualToString:Chectout_giftAddCart]){
|
|
|
if(sucessOrFail){
|
|
|
- [self reqNet_Cart_cartsMineTotals];
|
|
|
+ if ([mark isEqualToString:Chectout_giftAddCart]) {
|
|
|
+ self.index --;
|
|
|
+ if (self.index == 0) {
|
|
|
+ [self reqNet_Cart_cartsMineTotals];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ [self reqNet_Cart_cartsMineTotals];
|
|
|
+ }
|
|
|
}else{
|
|
|
[self.view makeToast:(NSString *)data duration:2 position:CSToastPositionCenter];
|
|
|
}
|
|
|
+ } else if ([mark isEqualToString:Goods_productGetProductsById]) {
|
|
|
+ //请求赠品详情
|
|
|
+ GoodsInformationM *model = (GoodsInformationM *)[arry firstObject];
|
|
|
+
|
|
|
+ NSMutableDictionary *param = [NSMutableDictionary dictionaryWithDictionary:@{@"product_id":model.Id, @"isPromoItems":@"yes"}];
|
|
|
+ if (model.options.count > 0) {
|
|
|
+ NSMutableDictionary *optionDic = [NSMutableDictionary dictionary];
|
|
|
+ for (OptionsModel *optionM in model.options) {
|
|
|
+ OptionsValuesM *valuesM = optionM.values[0];
|
|
|
+ NSString *tempStr =[NSString stringWithFormat:@"options[%@]",optionM.option_id];
|
|
|
+ optionDic[tempStr] =valuesM.option_type_id;
|
|
|
+ }
|
|
|
+ [param addEntriesFromDictionary:optionDic];
|
|
|
+ }
|
|
|
+ [self.addGiftParamArr addObject:param];
|
|
|
+ if (self.giftShowCount < 2 && self.addGiftParamArr.count == 1 && self.addGiftView.hidden) {
|
|
|
+ self.addGiftView.hidden = NO;
|
|
|
+ [self.addGiftView setGiftData:model.add_gooodsImgUrl];
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -269,8 +373,21 @@
|
|
|
//支付方式数据
|
|
|
[self.TableV.infodata addObjectsFromArray:self.paymentArray];
|
|
|
|
|
|
+ //手动添加赠品功能
|
|
|
+ [self.addGiftParamArr removeAllObjects];
|
|
|
|
|
|
-
|
|
|
+ NSDictionary *freeData = (NSDictionary *)[[self.totalsM.extension_attributes objectForKey:@"free_data"] mj_JSONObject];
|
|
|
+ BOOL is_show = [[freeData objectForKey:@"is_show"] boolValue];
|
|
|
+ if (is_show && self.giftShowCount< 2) {//显示存在赠品
|
|
|
+ NSArray *productArr = [freeData objectForKey:@"products"];
|
|
|
+ if (productArr.count > 0) { //存在赠品
|
|
|
+ for (int i = 0; i < productArr.count; i++) {
|
|
|
+ NSDictionary *productDic = productArr[i];
|
|
|
+ NSString *entity_id = productDic[@"entity_id"];
|
|
|
+ [self reqNet_GoodsDetails_productGetProduct:entity_id];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
[self.TableV reloadData];
|
|
|
}
|
|
@@ -348,6 +465,11 @@
|
|
|
|
|
|
[param removeObjectForKey:@"extension_attributes"];//移除格式不正确的无用参数
|
|
|
|
|
|
+ if (NIL(self.shipmethodCellM.shipMethodModel.method_code) || NIL(self.shipmethodCellM.shipMethodModel.carrier_code)) {
|
|
|
+ [self.view makeToast:@"运输方式获取失败"];
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
NSDictionary *params = @{@"shipping_address":param,
|
|
|
@"shipping_method_code":self.shipmethodCellM.shipMethodModel.method_code,
|
|
|
@"shipping_carrier_code":self.shipmethodCellM.shipMethodModel.carrier_code};
|
|
@@ -385,7 +507,7 @@
|
|
|
}
|
|
|
-(void)reqNet_PUT_cartsMineCoupons:(NSString *)coupon{
|
|
|
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
|
|
-
|
|
|
+ self.giftShowCount = 0;
|
|
|
[self.VM ry_requestPutApi:PUT_cartsMineCoupons param:coupon];
|
|
|
}
|
|
|
-(void)reqNet_DEL_cartsMineCoupons{
|
|
@@ -404,8 +526,34 @@
|
|
|
}
|
|
|
//下单
|
|
|
-(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];
|
|
|
- NSDictionary *param = @{@"method":self.paymentModel.code};
|
|
|
+ NSDictionary *param = @{@"method":paymentCode};
|
|
|
|
|
|
[ASNetTools.shared putWithPath:Chectout_PUT_sureOrder param:@{@"paymentMethod":param} success:^(id _Nonnull json) {
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
|
@@ -418,9 +566,34 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
+//请求赠品商品详情
|
|
|
+-(void)reqNet_GoodsDetails_productGetProduct:(NSString *)enterId{
|
|
|
+ NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
|
|
|
+// [params setObject:@"55475" forKey:@"productId"];
|
|
|
+ [params setObject:enterId forKey:@"productId"];
|
|
|
+ [params setObject:ASCurrencyManager.shared.currentCur forKey:@"currencyCode"];
|
|
|
+// [MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
|
|
+ [self.goodsDetailsVM ry_requestGetApi:Goods_productGetProductsById param:params];
|
|
|
+}
|
|
|
+
|
|
|
+//赠品加车
|
|
|
+- (void)requestGiftAddCart {
|
|
|
+ [MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
|
|
+
|
|
|
+ for (int i = 0; i < self.addGiftParamArr.count; i++) {
|
|
|
+ NSDictionary *param = self.addGiftParamArr[i];
|
|
|
+ self.index ++;
|
|
|
+ self.giftShowCount = 2;
|
|
|
+ [self.VM ry_formDataRequestPostApi:Chectout_giftAddCart param:param];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
#pragma mark --- 懒加载 ---
|
|
|
- (void)ucm_bindvmmodel{
|
|
|
self.VM = [[CartVM alloc] initDelegate:self];
|
|
|
+ self.goodsDetailsVM = [[ASGoodsDetailsVM alloc] initDelegate:self];
|
|
|
}
|
|
|
|
|
|
- (MyCartCouponCellData *)couponCellM {
|
|
@@ -491,6 +664,25 @@
|
|
|
return _bottomView;
|
|
|
}
|
|
|
|
|
|
+- (ASAddGiftGoodsView *)addGiftView {
|
|
|
+ if (!_addGiftView) {
|
|
|
+ _addGiftView = [[ASAddGiftGoodsView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
|
|
|
+ @weakify(self)
|
|
|
+ _addGiftView.addBlock = ^(int type) {
|
|
|
+ @strongify(self)
|
|
|
+ self.addGiftView.hidden = YES;
|
|
|
+ if (type == 1) {
|
|
|
+ [self requestGiftAddCart];
|
|
|
+ } else {
|
|
|
+ self.giftShowCount ++;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ _addGiftView.hidden = YES;
|
|
|
+ [[UIApplication sharedApplication].keyWindow addSubview:_addGiftView];
|
|
|
+ }
|
|
|
+ return _addGiftView;
|
|
|
+}
|
|
|
+
|
|
|
#pragma mark - **************** reqNet ****************
|
|
|
|
|
|
|