123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754 |
- //
- // Cart_CheckoutC.m
- // Asteria
- //
- // Created by 王猛 on 2024/2/16.
- //
- #import "Cart_CheckoutC.h"
- #import "ASAddressListViewController.h"
- #import "ASPayFailedViewController.h"
- #import "ASOrderDetailsViewController.h"
- #import "ASCheckoutTopView.h"
- #import "ASCheckoutBottomView.h"
- #import "CartCheckTableV.h"
- #import "CartVM.h"
- #import "ASUserModel.h"
- #import "ASGoodsDetailsVM.h"
- #import "ASAddGiftGoodsView.h"
- #import "ASCheckoutPayManager.h"
- @interface Cart_CheckoutC ()<RY_baseVMprotocol>
- @property (nonatomic, strong) CartVM *VM;
- @property (nonatomic, strong) ASCheckoutTopView *topView;
- @property (nonatomic, strong) ASCheckoutBottomView *bottomView;
- @property (nonatomic, strong) CartCheckTableV *TableV;
- @property (nonatomic, strong) MyCartCouponCellData *couponCellM;
- @property (nonatomic, strong) MyCartGrandTotalCellData *totalCellM;
- @property (nonatomic, strong) ASCheckoutPointData *pointCellM;
- @property (nonatomic, strong) ASCheckoutAddressData *addressCellM;
- @property (nonatomic, strong) ASCheckoutShipMethodData *shipmethodCellM;
- @property (nonatomic, strong) ASCheckoutCommentData *commentCellM;
- //存放支付方式
- @property (nonatomic, strong) NSArray *paymentArray;
- //选中支付方式
- @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;
- @end
- @implementation Cart_CheckoutC
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.title = @"Checkout";
-
- //获取支付方式
- [self requestPaymentMode];
- //获取运输方式
- // [self requestGetShipMethodByAddress];
- //获取购物车信息(地址信息)
- // [self requestCartInfo];
- [self getDefaultAddress];
- if (!self.totalsM) {
- [self reqNet_Cart_cartsMineTotals];
- }
- }
- - (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"];
- self.TableV.tableHeaderView = self.topView;
- self.TableV.tableFooterView = self.bottomView;
-
- @weakify(self)
- self.TableV.tapClose = ^(NSInteger num, id data) {
- //num = 0 删除商品 ,1 修改数量 countV
- @strongify(self)
- if([data isKindOfClass:[CartTotalsItemsM class]]){
- switch (num) {
- case 0:
- [self reqNet_DEL_cartsMineItems:(CartTotalsItemsM *)data];
- break;
- case 1:
- [self reqnet_Cart_cartsMineItems_Post:(CartTotalsItemsM *)data];
- break;
- default:
- break;
- }
- }else if ([data isKindOfClass:[MyCartCouponCellData class]]){
- MyCartCouponCellData *couponM = (MyCartCouponCellData *)data;
- if(num ==0){ //使用优惠券
- [self reqNet_PUT_cartsMineCoupons:couponM.coupon_code];
- }else if(num == 1){//删除优惠券
- [self reqNet_DEL_cartsMineCoupons];
- }
- } else if ([data isKindOfClass:[ASCheckoutPointData class]]) {
- ASCheckoutPointData *pointData = (ASCheckoutPointData *)data;
- if(num ==0){ //使用积分
- [self requestUseLimitPoint:pointData.usePoint];
- }else if(num == 1){//取消使用积分
- [self requestCancelUsePoint];
- }
- } else if ([data isKindOfClass:[ASCheckoutCommentData class]]) {
- ASCheckoutCommentData *commentData = (ASCheckoutCommentData *)data;
- if(num ==0){ //使用积分
- self.commentCellM.commentStr = commentData.commentStr;
- }
- } else if ([data isKindOfClass:[ASCheckoutShipMethodData class]]) {
- //选择运输方式、、、、并设置
- ASCheckoutShipMethodData *shipMethodData = (ASCheckoutShipMethodData *)data;
- self.shipmethodCellM = shipMethodData;
- for (int i = 0; i < self.shipmethodCellM.shipMethodArray.count; i++) {
- ASCheckoutShipMethodModel *shipModel = [self.shipmethodCellM.shipMethodArray objectAtIndex:i];
- if (i == num) {
- shipModel.isSelect = YES;
- self.shipmethodCellM.shipMethodModel = shipModel;
- } else {
- shipModel.isSelect = NO;
- }
- }
- [self requestSetShipMethodByAddress];
- } else if ([data isKindOfClass:[MyCartGrandTotalCellData class]]){
- // MyCartGrandTotalCellData *totalData = (MyCartGrandTotalCellData *)data;
- //丢件险
- [self requestLostExtraFee:num];
- }
- };
-
- }
- - (void)ry_respnsData:(id)data
- parseAry:(NSMutableArray *)arry
- sucess:(BOOL)sucessOrFail
- mark:(NSString *)mark
- reqNetType:(ReqNetType)reqNetType{
- [MBProgressHUD hideHUDForView:self.view animated:YES];
- if([mark isEqualToString:Cart_cartsMineTotals]){
- if(sucessOrFail){
- CartTotalsM *model = [arry firstObject];
- self.totalsM = model;
-
- [self updateData];
- }
- } else if ([mark isEqualToString:Chectout_getPaymentMode]) {
- if(sucessOrFail){
- // 更新支付方式
- self.paymentArray = arry;
- if (self.paymentArray.count > 0) {
- self.paymentModel = self.paymentArray[0];
- [self.bottomView setBottomPayStyle:self.paymentModel.code];
- }
- //首次进入展示购物车数据UI
- [self updateData];
- }
- } else if ([mark isEqualToString:Chectout_addBillingAddress]) {
- if(sucessOrFail){
-
- }
- }else if ([mark isEqualToString:Cart_cartInfo]) {
- if(sucessOrFail){
- // 获取上次下单地址
- NSDictionary *dic = (NSDictionary *)data;
- NSArray *array = [[dic objectForKey:@"extension_attributes"] objectForKey:@"shipping_assignments"];
-
- if (array.count > 0) {
- NSDictionary *shipping_assignments = array[0];
- NSDictionary *shippingDic = [shipping_assignments objectForKey:@"shipping"];
- NSDictionary *addressDic = [shippingDic objectForKey:@"address"];
- // ASAddressModel *addressModel = [ASAddressModel defualtData];
- ASAddressReginModel *reginModel = [ASAddressReginModel mj_objectWithKeyValues:addressDic];
- ASAddressModel *addressModel = [ASAddressModel mj_objectWithKeyValues:addressDic];
-
-
- addressModel.region = reginModel;
- if (AS_String_valid(addressModel.postcode) && AS_String_valid(addressModel.telephone) && AS_String_valid(addressModel.firstname) && AS_String_valid(addressModel.lastname)) {
- self.addressCellM.addressModel = addressModel;
-
- [self requestAddShipAddress];
- [self requestAddBillingAddress];
- }
- }
- //首次进入展示购物车数据UI
- [self updateData];
- }
-
- } else if ([mark isEqualToString:Chectout_addShipAddress_id]) {
-
- if(sucessOrFail){
- NSArray *shipMethodArr = (NSArray *)data;
- if (shipMethodArr.count > 0) {
-
- self.shipmethodCellM.shipMethodArray = [ASCheckoutShipMethodModel mj_objectArrayWithKeyValuesArray:shipMethodArr];
- ASCheckoutShipMethodModel *firstModel = self.shipmethodCellM.shipMethodArray[0];
- firstModel.isSelect = YES;
-
- self.shipmethodCellM.shipMethodModel = firstModel;
- self.shipmethodCellM.shipmethodSymbol = self.totalsM.currency_symbol;
-
- //默认设置第一个运输方式
- [self requestSetShipMethodByAddress];
-
-
- }
- }
- /// || [mark isEqualToString:Chectout_addBillingAddress]
- } else if ([mark isEqualToString:Chectout_getShipMethod]) {
-
- if(sucessOrFail){
- NSArray *shipMethodArr = (NSArray *)data;
-
-
- if (shipMethodArr.count > 0) {
- self.shipmethodCellM.shipMethodArray = [ASCheckoutShipMethodModel mj_objectArrayWithKeyValuesArray:shipMethodArr];
- ASCheckoutShipMethodModel *firstModel = self.shipmethodCellM.shipMethodArray[0];
- firstModel.isSelect = YES;
- self.shipmethodCellM.shipMethodModel = firstModel;
-
- if (self.addressCellM.addressModel) {
- //默认设置第一个运输方式
- [self requestSetShipMethodByAddress];
- }
- }
- }else{
- [self.view makeToast:(NSString *)data duration:2 position:CSToastPositionCenter];
- }
- [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:Chectout_giftAddCart]
- || [mark isEqualToString:Chectout_lost_extrafee]){
- if(sucessOrFail){
- 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]) {
- //请求赠品详情
- if(sucessOrFail) {
- if (!AS_Array_valid(arry)) {
- return;
- }
- 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 <= 1 && self.addGiftParamArr.count == 1 && self.addGiftView.hidden) {
-
- dispatch_async(dispatch_get_main_queue(), ^{
- self.addGiftView.hidden = NO;
- [self.addGiftView setGiftData:model.add_gooodsImgUrl];
- });
-
- }
- }
- }
- }
- - (void)updateData{
-
- [self.topView setTopViewData:AS_String_NotNull(self.totalsM.items_qty) price:[NSString stringWithFormat:@"%@%@",AS_String_NotNull(self.totalsM.currency_symbol),AS_String_NotNull(self.totalsM.subtotal)]];
-
- [self.TableV.infodata removeAllObjects];
- self.TableV.infodata = [NSMutableArray arrayWithArray:self.totalsM.items];
-
- //邮寄地址--邮寄方式
- [self.TableV.infodata addObject:self.addressCellM];
-
- //运输方式
- self.shipmethodCellM.shipmethodSymbol = self.totalsM.currency_symbol;
- [self.TableV.infodata addObject:self.shipmethodCellM];
-
- //优惠券
- self.couponCellM.couponAry =[NSMutableArray arrayWithArray: [ASNetTools shared].xxx_couponAry];
- self.couponCellM.coupon_code = self.totalsM.coupon_code;
- self.couponCellM.discount_amount = self.totalsM.discount_amount;
- self.couponCellM.currency_symbol = self.totalsM.currency_symbol;
- [self.TableV.infodata addObject:self.couponCellM];
-
- //积分
- NSDictionary *pointScaleDic = [Current_normalTool dicFromjsonStr:[self.totalsM.extension_attributes objectForKey:@"mw_earn_points_data"]];
- if (pointScaleDic.count > 0) {
- self.pointCellM.pointScale = [[pointScaleDic allValues] objectAtIndex:0];
- self.pointCellM.priceScale = [[pointScaleDic allKeys] objectAtIndex:0];
- }
- self.pointCellM.usePoint = [NSString stringWithFormat:@"%@", [self.totalsM.extension_attributes objectForKey:@"mw_rwrdpoints_amnt"]];
- self.pointCellM.usePrice = [NSString stringWithFormat:@"%@", [self.totalsM.extension_attributes objectForKey:@"mw_rwrdpoints_cur_amnt"]];
- self.pointCellM.pointBalance = [ASUserInfoManager shared].userPoints;
- self.pointCellM.priceSymbol = self.totalsM.currency_symbol;
- [self.TableV.infodata addObject:self.pointCellM];
-
- //备注
- [self.TableV.infodata addObject:self.commentCellM];
-
- //价格明细
- self.totalCellM.total_segments = [NSMutableArray arrayWithArray:self.totalsM.total_segments];
- self.totalCellM.currency_symbol = self.totalsM.currency_symbol;
- [self.TableV.infodata addObject:self.totalCellM];
-
- //支付方式数据
- [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< 1) {//显示存在赠品
- 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.giftShowCount++;
- }
- }
-
- [self.TableV reloadData];
- }
- - (void)tapcellTriggereventIndex:(NSIndexPath *)index model:(id)model{
- if([model isKindOfClass:[CartTotalsItemsM class]]){
- CartTotalsItemsM *itemM = (CartTotalsItemsM *)model;
- if(itemM.isGift){
- return;
- }
- UIViewController *viewController = [[CTMediator sharedInstance] Goods_GoodsDetailsC:@{@"entity_id":itemM.product_id}];
- [self.navigationController pushViewController:viewController animated:YES];
- } else if ([model isKindOfClass:[ASCheckoutPaymentModel class]]) {
- ASCheckoutPaymentModel *paymentModel = (ASCheckoutPaymentModel *)model;
- if (paymentModel.isSelect) {
- return;
- }
-
- for (int i = 0; i < self.TableV.infodata.count; i++) {
- id itemModel = self.TableV.infodata[i];
-
- if ([itemModel isKindOfClass:[ASCheckoutPaymentModel class]]) {
- ASCheckoutPaymentModel *tempModel = (ASCheckoutPaymentModel *)itemModel;
- if (index.row == i) {
- tempModel.isSelect = YES;
- self.paymentModel = tempModel;
- [self.bottomView setBottomPayStyle:tempModel.code];
- } else {
- tempModel.isSelect = NO;
- }
- }
- }
-
- [self.TableV reloadData];
- } else if ([model isKindOfClass:[ASCheckoutAddressData class]]) {
-
- ASAddressListViewController *vc = [ASAddressListViewController new];
- vc.isSelMode = true;
- vc.sel_Id = self.addressCellM.addressModel.Id;
- @weakify(self)
- vc.selectAddressBlock = ^(ASAddressModel * _Nonnull addressM) {
- @strongify(self)
-
- self.addressCellM.addressModel = addressM;
-
- [self requestAddShipAddress];
- [self requestAddBillingAddress];
- };
- [self.navigationController pushViewController:vc animated:true];
- }
- }
- #pragma mark - **************** reqNet ****************
- //每次进来获取用户默认地址
- - (void)getDefaultAddress {
- NSArray *addressArr = ASUserInfoManager.shared.userInfo.addresses;
-
- if (AS_Array_valid(addressArr)) {
- self.addressCellM.addressModel = addressArr.firstObject;
- for (ASAddressModel *addressModel in addressArr) {
- if ([addressModel.default_shipping isEqualToString:@"1"]) {
- self.addressCellM.addressModel = addressModel;
- }
- }
-
- [self requestAddShipAddress];
- [self requestAddBillingAddress];
- }
- }
- //获取支付方式
- - (void)requestPaymentMode {
- [self.VM ry_requestGetApi:Chectout_getPaymentMode param:@{}];
- }
- //添加邮寄地址
- - (void)requestAddShipAddress {
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- [self.VM ry_requestPostApi:Chectout_addShipAddress_id param:@{@"addressId":self.addressCellM.addressModel.Id}];
- }
- - (NSDictionary *)getAddressParam:(ASAddressModel *)addressModel {
-
- NSArray *street = addressModel.street;
- NSDictionary *shipping_address = @{@"region_code":AS_String_NotNull(addressModel.region_id),
- @"country_id":AS_String_NotNull(addressModel.country_id),
- @"postcode":AS_String_NotNull(addressModel.postcode),
- @"lastname":AS_String_NotNull(addressModel.lastname),
- @"firstname":AS_String_NotNull(addressModel.firstname),
- @"city":AS_String_NotNull(addressModel.city),
- @"region":AS_String_NotNull(addressModel.region.region),
- @"region_id":AS_String_NotNull(addressModel.region.region_id),
- @"telephone":AS_String_NotNull(addressModel.telephone),
- @"street":street,
- @"email":ASUserInfoManager.shared.userInfo.email};
-
- return shipping_address;
- }
- //添加账单地址
- - (void)requestAddBillingAddress {
-
- NSDictionary *addressInformation = [self getAddressParam:self.addressCellM.addressModel];
- NSDictionary *params = @{@"address":addressInformation, @"useForShipping":@"true"};
- [self.VM ry_requestPostApi:Chectout_addBillingAddress param:params];
- }
- //根据邮寄地址获取邮寄方式
- - (void)requestGetShipMethodByAddress {
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- [self.VM ry_requestGetApi:Chectout_getShipMethod param:@{}];
- }
- //设置邮寄方式
- - (void)requestSetShipMethodByAddress {
-
- if (NIL(self.shipmethodCellM.shipMethodModel.method_code) || NIL(self.shipmethodCellM.shipMethodModel.carrier_code)) {
- [self.view makeToast:self.shipmethodCellM.shipMethodModel.error_message];
- return;
- }
-
- NSDictionary *shipping_address = [self getAddressParam:self.addressCellM.addressModel];
-
- NSDictionary *params = @{@"shipping_address":shipping_address,
- @"shipping_method_code":self.shipmethodCellM.shipMethodModel.method_code,
- @"shipping_carrier_code":self.shipmethodCellM.shipMethodModel.carrier_code};
- NSDictionary *finalDic = @{@"addressInformation":params};
- NSLog(@"finalDic=====%@", [finalDic mj_JSONString]);
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- [self.VM ry_requestPostApi:Chectout_setShipMethod param:finalDic];
- }
- //获取购物车信息(地址信息)
- - (void)requestCartInfo {
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- [self.VM ry_requestGetApi:Cart_cartInfo param:@{}];
- }
- ///获取购物车信息(报价整合)
- -(void)reqNet_Cart_cartsMineTotals{
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- [self.VM ry_requestGetApi:Cart_cartsMineTotals param:@{}];
- }
- ///修改商品的数量
- -(void)reqnet_Cart_cartsMineItems_Post:(CartTotalsItemsM *)itemM{
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- NSDictionary *cartItemDic = @{
- @"item_id":itemM.item_id,
- @"qty":itemM.qty,
- @"quote_id":self.totalsM.cart_id
- };
- NSMutableDictionary *param = [NSMutableDictionary dictionaryWithDictionary:@{
- @"cartItem":cartItemDic
- }];
- [self.VM ry_requestPostApi:Cart_cartsMineItems_Post param:param];
- }
- ///删除商品
- -(void)reqNet_DEL_cartsMineItems:(CartTotalsItemsM *)itemM{
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- [self.VM ry_requestDeleteApi:DEL_cartsMineItems paramStr:itemM.item_id];
- }
- -(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{
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- [self.VM ry_requestDeleteApi:DEL_cartsMineCoupons paramStr:@""];
- }
- //使用指定积分
- - (void)requestUseLimitPoint:(NSString *)point {
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- [self.VM ry_requestPutApi:Chectout_PUT_usePoints param:point];
- }
- //取消使用积分
- - (void)requestCancelUsePoint {
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- [self.VM ry_requestDeleteApi:Chectout_DEL_cancelusePoints paramStr:@""];
- }
- //下单
- -(void)requestSureOrder{
-
- NSString *paymentCode = self.paymentModel.code;
-
- [ASCheckoutPayManager sharedInstance].cartId = self.totalsM.cart_id;
- [ASCheckoutPayManager sharedInstance].addressModel = self.addressCellM.addressModel;
- [[ASCheckoutPayManager sharedInstance] checkoutPayWithMethodType:paymentCode param:@{@"price":self.totalsM.grand_total, @"currency":self.totalsM.currency_symbol}];
- K_WEAK_SELF;
- [ASCheckoutPayManager sharedInstance].payFinishBlock = ^(NSString * _Nonnull payMethod, NSUInteger isSucess, id _Nonnull payData) {
- K_STRONG_SELF;
- NSLog(@"payData======%@", payData);
- NSDictionary *payDic = (NSDictionary *)payData;
- if (isSucess == 1) {
-
- [self.view makeToast:@"Payment success" duration:0.5 position:CSToastPositionCenter];
- K_WEAK_SELF;
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- K_STRONG_SELF;
-
-
-
- NSString *orderidStr = [NSString stringWithFormat:@"%@", [payDic objectForKey:@"orderid"]];
-
- [self paymentResultStatus:orderidStr];
-
- // if ([payMethod isEqualToString:@"paypal_express"]) {
- // [self paymentResultStatus:orderidStr];
- // } else if ([payMethod isEqualToString:@"stripe_payments"]) {//visa
- // [self paymentResultStatus:orderidStr];
- // } else if ([payMethod isEqualToString:@"afterpay_payment"]) {//afterpay
- //
- // } else if ([payMethod isEqualToString:@"klarna_kco"]) {//klarna
- //// NSString *orderidStr = [NSString stringWithFormat:@"%@", [payDic objectForKey:@"orderid"]];
- //
- // }
-
- });
-
- } else {
-
- NSString *msg = [NSString stringWithFormat:@"%@", [payDic objectForKey:@"msg"]];
-
- if ([msg isEqualToString:@"Payment anomaly"] && [payMethod isEqualToString:@"klarna_kco"]) {
- [self.view makeToast:msg duration:0.5 position:CSToastPositionCenter];
-
- K_WEAK_SELF;
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- K_STRONG_SELF;
- [self reqNet_Cart_cartsMineTotals];
- });
- return;
- }
-
- [self.view makeToast:@"Payment Failed" duration:0.5 position:CSToastPositionCenter];
- K_WEAK_SELF;
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- K_STRONG_SELF;
- //支付失败
- [self paymentResultStatus:@""];
- });
-
- }
- };
- }
- - (void)paymentResultStatus:(NSString *)orderid {
- if (AS_String_valid(orderid)) {
- ASOrderDetailsViewController *paySuccessVC = [[ASOrderDetailsViewController alloc] init];
- paySuccessVC.orderId = orderid;
- paySuccessVC.isPay = YES;
- [self.navigationController pushViewController:paySuccessVC animated:YES];
- } else {
- ASPayFailedViewController *payFailedVC = [[ASPayFailedViewController alloc] init];
- [self.navigationController pushViewController:payFailedVC animated:YES];
- }
- }
- //请求赠品商品详情
- -(void)reqNet_GoodsDetails_productGetProduct:(NSString *)enterId{
- NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
- [params setObject:enterId forKey:@"productId"];
- [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 = 1;
- [self.VM ry_formDataRequestPostApi:Chectout_giftAddCart param:param];
- }
- }
- //丢件险
- - (void)requestLostExtraFee:(BOOL)isOpen {
- NSDictionary *address = @{@"countryId":AS_String_valid(self.addressCellM.addressModel.country_id) ? AS_String_NotNull(self.addressCellM.addressModel.country_id) : @"US",
- @"region":AS_String_NotNull(self.addressCellM.addressModel.region.region),
- @"postcode":AS_String_NotNull(self.addressCellM.addressModel.postcode),
- @"city":AS_String_NotNull(self.addressCellM.addressModel.city)};
- NSDictionary *addressInformation = @{@"address":address,
- @"shipping_method_code":AS_String_valid(self.shipmethodCellM.shipMethodModel.method_code) ? self.shipmethodCellM.shipMethodModel.method_code : @"bestway",
- @"shipping_carrier_code":AS_String_valid(self.shipmethodCellM.shipMethodModel.carrier_code) ? self.shipmethodCellM.shipMethodModel.carrier_code : @"tablerate"};
-
- NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithCapacity:1];
- if(isOpen ==0){ //取消丢件险
- NSDictionary *information = @{@"fee_id":@(1), @"options_ids":@[]};
- [params addEntriesFromDictionary:@{@"information":information}];
- }else if(isOpen == 1){//打开丢件险
- NSDictionary *information = @{@"fee_id":@(1), @"options_ids":@[@"1"]};
- [params addEntriesFromDictionary:@{@"information":information}];
- }
- [params setValue:addressInformation forKey:@"addressInformation"];
-
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- [self.VM ry_requestPostApi:Chectout_lost_extrafee param:params];
- }
- #pragma mark --- 懒加载 ---
- - (void)ucm_bindvmmodel{
- self.VM = [[CartVM alloc] initDelegate:self];
- self.goodsDetailsVM = [[ASGoodsDetailsVM alloc] initDelegate:self];
- }
- - (MyCartCouponCellData *)couponCellM {
- if (!_couponCellM) {
- _couponCellM = [[MyCartCouponCellData alloc] init];
- }
- return _couponCellM;
- }
- - (MyCartGrandTotalCellData *)totalCellM {
- if (!_totalCellM) {
- _totalCellM = [[MyCartGrandTotalCellData alloc] init];
- }
- return _totalCellM;
- }
- - (ASCheckoutPointData *)pointCellM {
- if (!_pointCellM) {
- _pointCellM = [[ASCheckoutPointData alloc] init];
- }
- return _pointCellM;
- }
- - (ASCheckoutAddressData *)addressCellM {
- if (!_addressCellM) {
- _addressCellM = [[ASCheckoutAddressData alloc] init];
- }
- return _addressCellM;
- }
- - (ASCheckoutShipMethodData *)shipmethodCellM {
- if (!_shipmethodCellM) {
- _shipmethodCellM = [[ASCheckoutShipMethodData alloc] init];
- }
- return _shipmethodCellM;
- }
- - (ASCheckoutCommentData *)commentCellM {
- if (!_commentCellM) {
- _commentCellM = [[ASCheckoutCommentData alloc] init];
- _commentCellM.commentStr = @"";
- }
- return _commentCellM;
- }
- - (ASCheckoutTopView *)topView {
- if (!_topView) {
- // IPhoneXHeigh
- _topView = [[ASCheckoutTopView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 60)];
- @weakify(self)
- _topView.isFlodBlock = ^(BOOL isFlod) {
- @strongify(self)
- self.TableV.isFlod = isFlod;
- [self.TableV reloadData];
- };
- }
- return _topView;
- }
- - (ASCheckoutBottomView *)bottomView {
- if (!_bottomView) {
- _bottomView = [[ASCheckoutBottomView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 100)];
- @weakify(self)
- _bottomView.bottomBlock = ^{
- @strongify(self)
- // [self.view makeToast:@"调起支付"];
- [self requestSureOrder];
- };
- }
- 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].windows.firstObject addSubview:_addGiftView];
- }
- return _addGiftView;
- }
- #pragma mark - **************** reqNet ****************
- @end
|