Commit 8d3b7dfd authored by zhang_z's avatar zhang_z

添加二维码支付;

parent 36966005
......@@ -43,6 +43,7 @@
<w>strs</w>
<w>sunquan</w>
<w>transclose</w>
<w>unionpay</w>
<w>unipay</w>
<w>unkonw</w>
<w>unkonwcode</w>
......
......@@ -29,22 +29,40 @@ public class PayCenter {
}
/**
* 支付
* 条码支付
*
* @param payChannel 支付渠道
* @param payCode 支付码
* @param orderAmt 金额
* @return 直接结果的Observable
* @return 支付结果的Observable
*/
public Observable<Response> pay(int payChannel, String payCode, Long orderAmt) {
switch (mShopppp.getHost().getHostMapId()) {
case C.HOST.PAX:
return Factory.pay(payChannel, payCode, Util.fenToYuan(orderAmt));
return Factory.microPay(payChannel, payCode, Util.fenToYuan(orderAmt));
default:
return Observable.just(new Response(C.PAY_STATE.FAIL_CUSTOM, "未知渠道"));
}
}
/**
* QR支付
*
* @param payChannel 支付渠道
* @param orderAmt 金额
* @return 支付结果的Observable
*/
public Observable<Response> pay(int payChannel, Long orderAmt) {
switch (mShopppp.getHost().getHostMapId()) {
case C.HOST.PAX:
return Factory.qrPay(payChannel, Util.fenToYuan(orderAmt));
default:
return Observable.just(new Response(C.PAY_STATE.FAIL_CUSTOM, "未知渠道"));
}
}
/**
* 查询
*
......
......@@ -5,6 +5,9 @@ package com.xingdata.zxpay.api;
*/
public class Response {
public Response() {
}
public Response(int code, String msg) {
this.code = code;
this.msg = msg;
......@@ -14,6 +17,8 @@ public class Response {
private String msg;
private String body;
public int getCode() {
return code;
}
......@@ -29,4 +34,12 @@ public class Response {
public void setMsg(String msg) {
this.msg = msg;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
}
......@@ -150,4 +150,21 @@ class C {
*/
static final String MD5 = "MD5";
}
class TRADE_TYPE {
/**
* 微信
*/
static final String WECHAT = "pay.weixin.native";
/**
* 支付宝
*/
static final String ALI = "pay.alipay.native";
/**
* 银联
*/
static final String UNION = "pay.unionpay.native";
}
}
......@@ -24,7 +24,7 @@ public class Factory extends com.xingdata.zxpay.api.Factory {
* @param totalAmount 总金额(单位元)
* @return 交易结果
*/
public static Observable<com.xingdata.zxpay.api.Response> pay(int payChannel, String authCode, String totalAmount) {
public static Observable<com.xingdata.zxpay.api.Response> microPay(int payChannel, String authCode, String totalAmount) {
Request request = Request.create(C.METHOD.MICROPAY);
request.setOutTransactionNo(PayCenter.getInstance().mShopppp.getPosppp().getHposTrace());
request.setTimeStart(TimeUtils.getNowString(format));
......@@ -47,6 +47,35 @@ public class Factory extends com.xingdata.zxpay.api.Factory {
.doFinally(() -> orderMap.put(request.getOutTransactionNo(), request.getTimeStart()));
}
/**
* 二维码支付
*
* @param payChannel 支付渠道
* @param totalAmount 支付金额
* @return 交易结果
*/
public static Observable<com.xingdata.zxpay.api.Response> qrPay(int payChannel, String totalAmount) {
Request request = Request.create(C.METHOD.QRPAY);
request.setOutTransactionNo(PayCenter.getInstance().mShopppp.getPosppp().getHposTrace());
request.setTimeStart(TimeUtils.getNowString(format));
request.setTotalAmount(totalAmount);
switch (payChannel) {
case com.xingdata.zxpay.C.PAY_CHANNEL.ALI:
request.setTradeType(C.TRADE_TYPE.ALI);
break;
case com.xingdata.zxpay.C.PAY_CHANNEL.WECHAT:
request.setTradeType(C.TRADE_TYPE.WECHAT);
break;
case com.xingdata.zxpay.C.PAY_CHANNEL.BANK:
request.setTradeType(C.TRADE_TYPE.UNION);
break;
}
request.sign();
return run(Api.getInstance().service.action(request))
.map(new ResultFilter())
.doFinally(() -> orderMap.put(request.getOutTransactionNo(), request.getTimeStart()));
}
/**
* 查询
......
......@@ -94,6 +94,12 @@ class Request {
@JSONField(name = "body")
private String body;
/**
* 支付类型
*/
@JSONField(name = "trade_type")
private String tradeType;
/**
* 支付授权码
*/
......@@ -216,6 +222,14 @@ class Request {
this.body = body;
}
String getTradeType() {
return tradeType;
}
void setTradeType(String tradeType) {
this.tradeType = tradeType;
}
String getAuthCode() {
return authCode;
}
......
......@@ -33,6 +33,12 @@ class Response {
@JSONField(name = "msg")
private String msg;
/**
* 二维码地址
*/
@JSONField(name = "code_url")
private String codeUrl;
String getMethod() {
return method;
}
......@@ -72,4 +78,12 @@ class Response {
void setMsg(String msg) {
this.msg = msg;
}
String getCodeUrl() {
return codeUrl;
}
void setCodeUrl(String codeUrl) {
this.codeUrl = codeUrl;
}
}
......@@ -7,14 +7,26 @@ class ResultFilter implements Function<Response, com.xingdata.zxpay.api.Response
@Override
public com.xingdata.zxpay.api.Response apply(Response response) throws Exception {
com.xingdata.zxpay.api.Response r = new com.xingdata.zxpay.api.Response();
r.setMsg(response.getMsg());
switch (response.getCode()) {
case C.CODE.SUCCESS:
return new com.xingdata.zxpay.api.Response(com.xingdata.zxpay.C.PAY_STATE.SUCCESS, response.getMsg());
r.setCode(com.xingdata.zxpay.C.PAY_STATE.SUCCESS);
break;
case C.CODE.USINGPAY:
case C.CODE.UNKONW:
return new com.xingdata.zxpay.api.Response(com.xingdata.zxpay.C.PAY_STATE.ING, response.getMsg());
r.setCode(com.xingdata.zxpay.C.PAY_STATE.ING);
break;
default:
return new com.xingdata.zxpay.api.Response(com.xingdata.zxpay.C.PAY_STATE.FAIL, response.getMsg());
r.setCode(com.xingdata.zxpay.C.PAY_STATE.FAIL);
break;
}
switch (response.getMethod()) {
case C.METHOD.QRPAY:
r.setBody(response.getCodeUrl());
break;
}
return r;
}
}
\ No newline at end of file
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