123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- //
- // FKVipBuyPayController.m
- // FirstLink
- //
- // Created by jack on 15/9/14.
- // Copyright (c) 2015年 FirstLink. All rights reserved.
- //
- #import "FKVipPayController.h"
- #import "OrderPayWayCell.h"
- #import "FLThirdPayHelper.h"
- #import "OrderPayBottomView.h"
- #import "ShakeRedPacketController.h"
- #import "FKVipPayReform.h"
- #import "FKPaySuccessAnimView.h"
- @interface FKVipPayController () <UITableViewDataSource, UITableViewDelegate, FLNetworkDelegate, UIAlertViewDelegate>
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) UIView *headerView;
- @property (nonatomic, strong) OrderPayBottomView *bottomView;
- @end
- @implementation FKVipPayController
- - (void)viewDidLoad{
- [super viewDidLoad];
- [self addAllSubViews];
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- self.navigationItem.title = @"付款方式";
- }
- - (void)viewDidAppear:(BOOL)animated
- {
- [super viewDidAppear:animated];
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(alipaySuccess:) name:AlipaySuccessNotificaitonName object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(alipayFailed:) name:AlipayFailedNotificaitonName object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(weixinPaySuccess:) name:WeixinPaySuccessNotificaitonName object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(weixinPayFailed:) name:WeixinPayFailedNotificaitonName object:nil];
- }
- - (void)addAllSubViews{
- [self.view addSubview:self.tableView];
- [self.view addSubview:self.bottomView];
-
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.left.right.equalTo(self.view);
- make.bottom.equalTo(self.bottomView.mas_top);
- }];
-
- [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.equalTo(self.view);
- make.bottom.equalTo(self.view).offset(IS_IPHONE_X ? -34 : 0);
- make.height.equalTo(@45);
- }];
- }
- #pragma mark - tableView dataSource
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return [FLThirdPayHelper isWXAppInstalled] ? 2 : 1;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- OrderPayWayCell *wayCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([OrderPayWayCell class])];
- if (indexPath.row == 0 && [FLThirdPayHelper isWXAppInstalled]) {
- wayCell.iconImgView.image = [UIImage imageNamed:@"confirm_body_weixin_n"];
- wayCell.titleLabel.text = @"微信支付";
- wayCell.bottomLine.hidden = NO;
- wayCell.catchImgView.hidden = NO;
- return wayCell;
- }else{
- wayCell.iconImgView.image = [UIImage imageNamed:@"confirm_body_zhifubao_n"];
- wayCell.titleLabel.text = @"支付宝支付";
- wayCell.bottomLine.hidden = YES;
- wayCell.catchImgView.hidden = [FLThirdPayHelper isWXAppInstalled] ? YES : NO;
- return wayCell;
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 60;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- if (section == 0) return 45;
- return 0;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
- if (section == 0) {
- return self.headerView;
- }
- return nil;
- }
- #pragma mark - tableView delegate
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
-
- for (OrderPayWayCell *cell in self.tableView.visibleCells) {
- if ([cell isKindOfClass:[OrderPayWayCell class]]) cell.catchImgView.hidden = YES;
- }
- OrderPayWayCell *wayCell = (OrderPayWayCell *)[tableView cellForRowAtIndexPath:indexPath];
- if ([wayCell isKindOfClass:[OrderPayWayCell class]]) {
- wayCell.catchImgView.hidden = NO;
- }
- }
- #pragma mark - response
- - (void)networkDidReceiveError:(NSError*)error identify:(int)identify header:(MSGHeader*)header{
-
- if (header.code.intValue == RESPONSE_MSG_BUSINESS_EXCEPTION) {
- [FLProgressHUDHelper showText:header.msg inView:self.view];
- }else if (header.code.intValue == RESPONSE_MSG_ACCESS_EXCEPTION){
- [FLProgressHUDHelper showText:@"请求失败" inView:self.view];
- }
- }
- - (void)networkDidSuccessResponse:(NSDictionary*)response identify:(int)identify header:(MSGHeader*)header{
-
- // [self.hudView hide:NO];
- if (identify == WX_PREPARE_ID_REQ) {
- NSString *prepayId = [FKVipPayReform parserWxPrepayId:response];
- if (prepayId.length > 0) [FLThirdPayHelper wxPayWithPrepayID:prepayId];
- }
- }
- #pragma mark - action
- - (void)payButtonClick{
- NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
- // if (indexPath && indexPath.section == 0) return;
-
- if (![FLThirdPayHelper isWXAppInstalled] || indexPath.row == 1){
- [FLThirdPayHelper alipayLaunchWithPaymentModel:self.payItem];
- }else if (!indexPath || indexPath.row == 0){
- [FLThirdPayHelper getWxPayPrepayIdWithOrderID:self.payItem.paymentNo delegate:self];
- }
- }
- #pragma mark - alipay response
- - (void)setUserAsVIP {
- User *user = [FKUserManager sharedManager].user;
- user.level = @"2";
- [[FKUserManager sharedManager] saveUser:user];
- }
- - (void)alipaySuccess:(NSNotification *)notification{
- [self setUserAsVIP];
-
- WeakSelf(weakSelf);
- [FKPaySuccessAnimView showInView:self.view finish:^(BOOL done) {
- [weakSelf paySuccessDelegateAction];
- }];
-
- }
- - (void)alipayFailed:(NSNotificationCenter *)notification{
- if (self.delegate && [self.delegate respondsToSelector:@selector(vipPayFail)]) {
- [self.delegate vipPayFail];
- }
- }
- - (void)weixinPaySuccess:(NSNotification *)notification{
- [self setUserAsVIP];
-
- WeakSelf(weakSelf);
- [FKPaySuccessAnimView showInView:self.view finish:^(BOOL done) {
- [weakSelf paySuccessDelegateAction];
- }];
- }
- - (void)weixinPayFailed:(NSNotification *)notification{
- if (self.delegate && [self.delegate respondsToSelector:@selector(vipPayFail)]) {
- [self.delegate vipPayFail];
- }
- }
- #pragma mark - method
- - (void)paySuccessDelegateAction{
- if (self.delegate && [self.delegate respondsToSelector:@selector(vipPaySuccess)]) {
- [self.delegate vipPaySuccess];
- }
- }
- #pragma mark - property
- - (UITableView *)tableView{
- if (_tableView == nil) {
- _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
- _tableView.dataSource = self;
- _tableView.delegate = self;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.sectionFooterHeight = 0;
- _tableView.backgroundColor = COMMON_TABLEVIEW_BACKGROUND_COLOR;
- [_tableView registerClass:[OrderPayWayCell class] forCellReuseIdentifier:NSStringFromClass([OrderPayWayCell class])];
-
- if (@available(iOS 11.0, *)) {
- _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- }
- }
- return _tableView;
- }
- - (UIView *)headerView{
- if (_headerView == nil) {
- _headerView = [[UIView alloc]init];
-
- _headerView.backgroundColor = [UIColor clearColor];
- UILabel *titleLabel = ({
- UILabel *label = [[UILabel alloc]init];
- label.font = [UIFont systemFontOfSize:14];
- label.textColor = UIColorFromRGB(0x333333);
- label.text = @"选择支付方式";
- label;
- });
-
- [_headerView addSubview:titleLabel];
- [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(_headerView).offset(15);
- make.bottom.equalTo(_headerView).offset(- 15);
- }];
- }
- return _headerView;
- }
- - (OrderPayBottomView *)bottomView
- {
- if (_bottomView == nil) {
- _bottomView = [[OrderPayBottomView alloc]init];
- [_bottomView.payButton addTarget:self action:@selector(payButtonClick) forControlEvents:UIControlEventTouchUpInside];
- _bottomView.amountLabel.text = [NSString stringWithFormat:@"¥%@", [FLStringHelper convertFenToYuan:self.payItem.totalFee]];
- }
- return _bottomView;
- }
- @end
|