Commit cde96918 authored by zhang_z's avatar zhang_z

整合新的支付模块;

parent 332b953f
...@@ -190,8 +190,8 @@ public class SettleActivity extends BaseActivity<SettlePresenter, ActivitySettle ...@@ -190,8 +190,8 @@ public class SettleActivity extends BaseActivity<SettlePresenter, ActivitySettle
} }
@Override @Override
public void showPayingDialog(int payType, com.xingdata.zzdpos.api.Pay.Response response) { public void showPayingDialog(int payType) {
mPayingDialog.setType(payType).setResponse(response).show(this); mPayingDialog.setType(payType).show(this);
} }
@Override @Override
......
...@@ -130,7 +130,7 @@ interface SettleContract { ...@@ -130,7 +130,7 @@ interface SettleContract {
/** /**
* 显示支付中页面 * 显示支付中页面
*/ */
void showPayingDialog(int payType, com.xingdata.zzdpos.api.Pay.Response response); void showPayingDialog(int payType);
/** /**
* 获取备注 * 获取备注
......
package com.xingdata.zzdpos.ui.settle; package com.xingdata.zzdpos.ui.settle;
import com.alibaba.fastjson.JSON;
import com.blankj.utilcode.util.StringUtils; import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.ToastUtils; import com.blankj.utilcode.util.ToastUtils;
import com.xingdata.api.print.ZX_PrintPOS; import com.xingdata.api.print.ZX_PrintPOS;
import com.xingdata.zxpay.PayCenter;
import com.xingdata.zzdpos.C; import com.xingdata.zzdpos.C;
import com.xingdata.zzdpos.api.ApiFactory; import com.xingdata.zzdpos.api.ApiFactory;
import com.xingdata.zzdpos.api.JniFactory;
import com.xingdata.zzdpos.db.DBFactory; import com.xingdata.zzdpos.db.DBFactory;
import com.xingdata.zzdpos.model.HandoverInfo; import com.xingdata.zzdpos.model.HandoverInfo;
import com.xingdata.zzdpos.model.Ms; import com.xingdata.zzdpos.model.Ms;
...@@ -218,79 +217,117 @@ public class SettlePresenter extends SettleContract.Presenter { ...@@ -218,79 +217,117 @@ public class SettlePresenter extends SettleContract.Presenter {
@Override @Override
public void payInCash(Long inputAmt, Long changeAmt) { public void payInCash(Long inputAmt, Long changeAmt) {
mView.showLoadingDialog(); mView.showLoadingDialog();
subscribePay(commitOrder().flatMap(orderNo -> ApiFactory.Saleorder.addOrderPayMis(mSaleorder.pay(orderNo, C.PAY_CHANNEL.CASH)).doFinally(() -> mView.dismissLoadingDialog()))); subscribePay(commitOrder().flatMap(orderNo -> ApiFactory.Saleorder.addOrderPayMis(mSaleorder.pay(orderNo, C.PAY_CHANNEL.CASH))));
} }
@Override @Override
public void payInAli(String payCode) { public void payInAli(String payCode) {
mView.showLoadingDialog(); mView.showLoadingDialog();
commitOrder() // commitOrder()
.flatMap(orderNo -> JniFactory.Settle.pay(C.PAY_CHANNEL.ALI, payCode, mSaleorder.getOrderPayAmt(), orderNo)) // .flatMap(orderNo -> JniFactory.Settle.pay(C.PAY_CHANNEL.ALI, payCode, mSaleorder.getOrderPayAmt(), orderNo))
.doFinally(() -> mView.dismissLoadingDialog()) // .doFinally(() -> mView.dismissLoadingDialog())
.subscribe( // .subscribe(
// response -> {
// com.xingdata.zzdpos.api.Pay.Response r1 = JSON.parseObject(response.replace("\\", ""), com.xingdata.zzdpos.api.Pay.Response.class);
// switch (r1.getResponseCode()) {
// case "0000":
// subscribePay(commitOrder().flatMap(orderNo -> ApiFactory.Saleorder.addOrderPayMis(mSaleorder.pay(orderNo, C.PAY_CHANNEL.ALI)).doFinally(() -> mView.dismissLoadingDialog())));
// break;
// case "0098":
// mView.showPayingDialog(C.PAY_CHANNEL.ALI, r1);
// break;
// default:
// mView.showPayFailFragment(null, mSaleorder);
// break;
// }
// },
// throwable -> mView.showPayFailFragment(throwable, mSaleorder));
commitOrder(
).flatMap(orderNo -> {
//获取支付中心参数
return ApiFactory.Pay.getPayKey();
}).flatMap(json -> {
//初始化支付中心,并发送支付指令
return PayCenter.getInstance().init(json).pay(C.PAY_CHANNEL.ALI, payCode, mSaleorder.getOrderPayAmt());
}).doFinally(() -> {
mView.dismissLoadingDialog();
}).subscribe(
response -> { response -> {
com.xingdata.zzdpos.api.Pay.Response r1 = JSON.parseObject(response.replace("\\", ""), com.xingdata.zzdpos.api.Pay.Response.class); switch (response.getCode()) {
switch (r1.getResponseCode()) { case com.xingdata.zxpay.C.PAY_STATE.ING:
case "0000": //支付中, 显示支付对话框
subscribePay(commitOrder().flatMap(orderNo -> ApiFactory.Saleorder.addOrderPayMis(mSaleorder.pay(orderNo, C.PAY_CHANNEL.ALI)).doFinally(() -> mView.dismissLoadingDialog()))); mView.showPayingDialog(C.PAY_CHANNEL.ALI);
break; break;
case "0098": case com.xingdata.zxpay.C.PAY_STATE.SUCCESS:
mView.showPayingDialog(C.PAY_CHANNEL.ALI, r1); //支付成功, 发送完成订单指令
subscribePay(ApiFactory.Saleorder.addOrderPayMis(mSaleorder.pay(mSaleorder.getOrderNo(), C.PAY_CHANNEL.ALI)));
break; break;
default: default:
//支付失败
mView.showPayFailFragment(null, mSaleorder); mView.showPayFailFragment(null, mSaleorder);
break; break;
} }
}, },
throwable -> mView.showPayFailFragment(throwable, mSaleorder)); throwable -> {
// commitOrder() mView.showPayFailFragment(throwable, mSaleorder);
// .flatMap(orderNo -> PayCenter.getInstance().pay(C.PAY_CHANNEL.ALI, payCode, mSaleorder.getOrderPayAmt())) }
// .doFinally(() -> mView.dismissLoadingDialog()) );
// .subscribe(
// response -> {
// LogUtils.e(response.getMsg());
// },
// throwable -> {
// mView.showPayFailFragment(throwable, mSaleorder);
// });
} }
@Override @Override
public void payInWechat(String payCode) { public void payInWechat(String payCode) {
mView.showLoadingDialog(); mView.showLoadingDialog();
commitOrder() // commitOrder()
.flatMap(orderNo -> JniFactory.Settle.pay(C.PAY_CHANNEL.WECHAT, payCode, mSaleorder.getOrderPayAmt(), orderNo)) // .flatMap(orderNo -> JniFactory.Settle.pay(C.PAY_CHANNEL.WECHAT, payCode, mSaleorder.getOrderPayAmt(), orderNo))
.doFinally(() -> mView.dismissLoadingDialog()) // .doFinally(() -> mView.dismissLoadingDialog())
.subscribe( // .subscribe(
// response -> {
// com.xingdata.zzdpos.api.Pay.Response r1 = JSON.parseObject(response.replace("\\", ""), com.xingdata.zzdpos.api.Pay.Response.class);
// switch (r1.getResponseCode()) {
// case C.PAY_STATE.SUCC:
// subscribePay(commitOrder().flatMap(orderNo -> ApiFactory.Saleorder.addOrderPayMis(mSaleorder.pay(orderNo, C.PAY_CHANNEL.WECHAT)).doFinally(() -> mView.dismissLoadingDialog())));
// break;
// case C.PAY_STATE.PAYING:
// mView.showPayingDialog(C.PAY_CHANNEL.WECHAT, r1);
// break;
// default:
// mView.showPayFailFragment(null, mSaleorder);
// break;
// }
// },
// throwable -> mView.showPayFailFragment(throwable, mSaleorder));
//提交订单
commitOrder(
).flatMap(orderNo -> {
//获取支付中心参数
return ApiFactory.Pay.getPayKey();
}).flatMap(json -> {
//初始化支付中心,并发送支付指令
return PayCenter.getInstance().init(json).pay(C.PAY_CHANNEL.WECHAT, payCode, mSaleorder.getOrderPayAmt());
}).doFinally(() -> {
mView.dismissLoadingDialog();
}).subscribe(
response -> { response -> {
com.xingdata.zzdpos.api.Pay.Response r1 = JSON.parseObject(response.replace("\\", ""), com.xingdata.zzdpos.api.Pay.Response.class); switch (response.getCode()) {
switch (r1.getResponseCode()) { case com.xingdata.zxpay.C.PAY_STATE.ING:
case C.PAY_STATE.SUCC: //支付中, 显示支付对话框
subscribePay(commitOrder().flatMap(orderNo -> ApiFactory.Saleorder.addOrderPayMis(mSaleorder.pay(orderNo, C.PAY_CHANNEL.WECHAT)).doFinally(() -> mView.dismissLoadingDialog()))); mView.showPayingDialog(C.PAY_CHANNEL.WECHAT);
break; break;
case C.PAY_STATE.PAYING: case com.xingdata.zxpay.C.PAY_STATE.SUCCESS:
mView.showPayingDialog(C.PAY_CHANNEL.WECHAT, r1); //支付成功, 发送完成订单指令
subscribePay(ApiFactory.Saleorder.addOrderPayMis(mSaleorder.pay(mSaleorder.getOrderNo(), C.PAY_CHANNEL.WECHAT)));
break; break;
default: default:
//支付失败
mView.showPayFailFragment(null, mSaleorder); mView.showPayFailFragment(null, mSaleorder);
break; break;
} }
}, },
throwable -> mView.showPayFailFragment(throwable, mSaleorder)); throwable -> {
// ApiFactory.Pay.getPayKey().flatMap(s -> { mView.showPayFailFragment(throwable, mSaleorder);
// return Observable.just(commitOrder() }
// .flatMap(orderNo -> PayCenter.getInstance().init(s).pay(C.PAY_CHANNEL.WECHAT, payCode, mSaleorder.getOrderPayAmt())) );
// .doFinally(() -> mView.dismissLoadingDialog())
// .subscribe(
// response -> {
// LogUtils.e(response.getMsg());
// },
// throwable -> {
// mView.showPayFailFragment(throwable, mSaleorder);
// })
// );
// }).subscribe();
} }
@Override @Override
...@@ -303,7 +340,7 @@ public class SettlePresenter extends SettleContract.Presenter { ...@@ -303,7 +340,7 @@ public class SettlePresenter extends SettleContract.Presenter {
b -> { b -> {
mView.dismissPasswordDialog(); mView.dismissPasswordDialog();
mView.showLoadingDialog(); mView.showLoadingDialog();
subscribePay(commitOrder().flatMap(orderNo -> ApiFactory.Saleorder.addOrderPayMis(mSaleorder.pay(orderNo, C.PAY_CHANNEL.CARD, String.valueOf(cardNo))).doFinally(() -> mView.dismissLoadingDialog()))); subscribePay(commitOrder().flatMap(orderNo -> ApiFactory.Saleorder.addOrderPayMis(mSaleorder.pay(orderNo, C.PAY_CHANNEL.CARD, String.valueOf(cardNo)))));
}, },
throwable -> mView.showMsg(throwable.getMessage()) throwable -> mView.showMsg(throwable.getMessage())
); );
...@@ -315,7 +352,7 @@ public class SettlePresenter extends SettleContract.Presenter { ...@@ -315,7 +352,7 @@ public class SettlePresenter extends SettleContract.Presenter {
b -> { b -> {
mView.dismissPasswordDialog(); mView.dismissPasswordDialog();
mView.showLoadingDialog(); mView.showLoadingDialog();
subscribePay(commitOrder().flatMap(orderNo -> ApiFactory.Saleorder.addOrderPayMis(mSaleorder.pay(orderNo, C.PAY_CHANNEL.TALLY)).doFinally(() -> mView.dismissLoadingDialog()))); subscribePay(commitOrder().flatMap(orderNo -> ApiFactory.Saleorder.addOrderPayMis(mSaleorder.pay(orderNo, C.PAY_CHANNEL.TALLY))));
}, },
throwable -> mView.showMsg(throwable.getMessage()) throwable -> mView.showMsg(throwable.getMessage())
); );
...@@ -324,23 +361,41 @@ public class SettlePresenter extends SettleContract.Presenter { ...@@ -324,23 +361,41 @@ public class SettlePresenter extends SettleContract.Presenter {
@Override @Override
public void checkPayState(int payType) { public void checkPayState(int payType) {
mView.showLoadingDialog(); mView.showLoadingDialog();
JniFactory.Settle.query() // JniFactory.Settle.query()
// .doFinally(() -> mView.dismissLoadingDialog())
// .subscribe(s -> {
// com.xingdata.zzdpos.api.Pay.Response r1 = JSON.parseObject(s.replace("\\", ""), com.xingdata.zzdpos.api.Pay.Response.class);
// switch (r1.getResponseCode()) {
// case C.PAY_STATE.SUCC:
// subscribePay(commitOrder().flatMap(orderNo -> ApiFactory.Saleorder.addOrderPayMis(mSaleorder.pay(orderNo, payType))));
// break;
// case C.PAY_STATE.PAYING:
// mView.showMsg("交易处理中");
// break;
// default:
// mView.showPayFailFragment(null, mSaleorder);
// break;
// }
// },
// throwable -> mView.showPayFailFragment(throwable, mSaleorder));
PayCenter.getInstance().query()
.doFinally(() -> mView.dismissLoadingDialog()) .doFinally(() -> mView.dismissLoadingDialog())
.subscribe(s -> { .subscribe(response -> {
com.xingdata.zzdpos.api.Pay.Response r1 = JSON.parseObject(s.replace("\\", ""), com.xingdata.zzdpos.api.Pay.Response.class); switch (response.getCode()) {
switch (r1.getResponseCode()) { case com.xingdata.zxpay.C.PAY_STATE.ING:
case C.PAY_STATE.SUCC: //支付中, Toast提示
subscribePay(commitOrder().flatMap(orderNo -> ApiFactory.Saleorder.addOrderPayMis(mSaleorder.pay(orderNo, payType)).doFinally(() -> mView.dismissLoadingDialog())));
break;
case C.PAY_STATE.PAYING:
mView.showMsg("交易处理中"); mView.showMsg("交易处理中");
break; break;
case com.xingdata.zxpay.C.PAY_STATE.SUCCESS:
//支付成功, 发送完成订单指令
subscribePay(ApiFactory.Saleorder.addOrderPayMis(mSaleorder.pay(mSaleorder.getOrderNo(), payType)));
break;
default: default:
//支付失败
mView.showPayFailFragment(null, mSaleorder); mView.showPayFailFragment(null, mSaleorder);
break; break;
} }
}, });
throwable -> mView.showPayFailFragment(throwable, mSaleorder));
} }
@Override @Override
...@@ -386,11 +441,15 @@ public class SettlePresenter extends SettleContract.Presenter { ...@@ -386,11 +441,15 @@ public class SettlePresenter extends SettleContract.Presenter {
* 提交订单 * 提交订单
*/ */
private Observable<String> commitOrder() { private Observable<String> commitOrder() {
if (StringUtils.isEmpty(mSaleorder.getOrderNo())) {
return ApiFactory.Saleorder.addOrderMis(createSaleorderParam()) return ApiFactory.Saleorder.addOrderMis(createSaleorderParam())
.doAfterNext(s -> { .doAfterNext(s -> {
mSaleorder.setOrderNo(s); mSaleorder.setOrderNo(s);
mView.changeLockState(true); mView.changeLockState(true);
}); });
} else {
return Observable.just(mSaleorder.getOrderNo());
}
} }
/** /**
......
...@@ -4,7 +4,6 @@ import android.content.DialogInterface; ...@@ -4,7 +4,6 @@ import android.content.DialogInterface;
import com.xingdata.zzdpos.C; import com.xingdata.zzdpos.C;
import com.xingdata.zzdpos.R; import com.xingdata.zzdpos.R;
import com.xingdata.zzdpos.api.Pay;
import com.xingdata.zzdpos.base.BaseDialog; import com.xingdata.zzdpos.base.BaseDialog;
import com.xingdata.zzdpos.databinding.DialogSettlePayingBinding; import com.xingdata.zzdpos.databinding.DialogSettlePayingBinding;
import com.xingdata.zzdpos.ui.settle.SettlePresenter; import com.xingdata.zzdpos.ui.settle.SettlePresenter;
...@@ -12,7 +11,6 @@ import com.xingdata.zzdpos.ui.settle.SettlePresenter; ...@@ -12,7 +11,6 @@ import com.xingdata.zzdpos.ui.settle.SettlePresenter;
public class PayingDialog extends BaseDialog<SettlePresenter, DialogSettlePayingBinding> { public class PayingDialog extends BaseDialog<SettlePresenter, DialogSettlePayingBinding> {
private int mType; private int mType;
private Pay.Response mResponse;
@Override @Override
protected boolean isEasy() { protected boolean isEasy() {
...@@ -47,8 +45,4 @@ public class PayingDialog extends BaseDialog<SettlePresenter, DialogSettlePaying ...@@ -47,8 +45,4 @@ public class PayingDialog extends BaseDialog<SettlePresenter, DialogSettlePaying
return this; return this;
} }
public PayingDialog setResponse(Pay.Response response) {
this.mResponse = response;
return this;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment