use of cn.beecloud.entity.BCPayResult in project ttdj by soonphe.
the class BCWechatPaymentActivity method onResp.
/**
* 第三方应用发送到微信的请求处理后的响应结果,会回调到该方法
*/
@Override
public void onResp(BaseResp baseResp) {
Log.i(TAG, "onPayFinish, result code = " + baseResp.errCode);
String result = BCPayResult.RESULT_FAIL;
int errCode = BCPayResult.APP_INTERNAL_THIRD_CHANNEL_ERR_CODE;
String errMsg = BCPayResult.FAIL_ERR_FROM_CHANNEL;
String detailInfo = "WECHAT_PAY: ";
switch(baseResp.errCode) {
case BaseResp.ErrCode.ERR_OK:
result = BCPayResult.RESULT_SUCCESS;
errCode = BCPayResult.APP_PAY_SUCC_CODE;
errMsg = BCPayResult.RESULT_SUCCESS;
detailInfo += "用户支付已成功";
break;
case BaseResp.ErrCode.ERR_USER_CANCEL:
result = BCPayResult.RESULT_CANCEL;
errCode = BCPayResult.APP_PAY_CANCEL_CODE;
errMsg = BCPayResult.RESULT_CANCEL;
detailInfo += "用户取消";
break;
case BaseResp.ErrCode.ERR_AUTH_DENIED:
detailInfo += "发送被拒绝";
break;
case BaseResp.ErrCode.ERR_COMM:
detailInfo += "一般错误,微信Debug版本常见错误,请查看工单http://help.beecloud.cn/hc/kb/article/157111";
break;
case BaseResp.ErrCode.ERR_UNSUPPORT:
detailInfo += "不支持错误";
break;
case BaseResp.ErrCode.ERR_SENT_FAILED:
detailInfo += "发送失败";
break;
default:
detailInfo += "支付失败";
}
if (BCPay.payCallback != null) {
BCPay.payCallback.done(new BCPayResult(result, errCode, errMsg, detailInfo, BCCache.getInstance().billID));
}
this.finish();
}
use of cn.beecloud.entity.BCPayResult in project ttdj by soonphe.
the class BCOfflinePayTest method testReqOfflinePayAsyncParamInvalid.
/**
* #1
* 模拟参数问题
* @throws Exception
*/
@Test
public void testReqOfflinePayAsyncParamInvalid() throws Exception {
Object[][] test = new Object[][] { // 依次对应必填参数 渠道类型 订单标题 订单金额 订单流水号 收款码
new Object[] { null, null, null, null, null }, new Object[] { BCReqParams.BCChannelTypes.ALI_APP, null, null, null, null }, new Object[] { BCReqParams.BCChannelTypes.ALI_SCAN, null, null, null, null }, new Object[] { BCReqParams.BCChannelTypes.ALI_SCAN, "试一个很长的title--参数公共返回参数取值及含义参见支付公共返回参数部分", null, null, null }, new Object[] { BCReqParams.BCChannelTypes.ALI_SCAN, "正常title", null, null, null }, new Object[] { BCReqParams.BCChannelTypes.ALI_SCAN, "正常title", -1, null, null }, new Object[] { BCReqParams.BCChannelTypes.ALI_SCAN, "正常title", 3, null, null }, new Object[] { BCReqParams.BCChannelTypes.WX_SCAN, "正常title", 3, "123", null }, new Object[] { BCReqParams.BCChannelTypes.WX_SCAN, "正常title", 3, "123456789ABCDE", null } };
for (Object[] objects : test) {
final CountDownLatch localLatch = new CountDownLatch(1);
pay.reqOfflinePayAsync((BCReqParams.BCChannelTypes) objects[0], (String) objects[1], (Integer) objects[2], (String) objects[3], null, (String) objects[4], "terminalid", null, new BCCallback() {
@Override
public void done(BCResult result) {
Assert.assertTrue(result instanceof BCPayResult);
BCPayResult payResult = (BCPayResult) result;
Assert.assertEquals(BCPayResult.RESULT_FAIL, payResult.getResult());
Assert.assertEquals((Integer) BCPayResult.APP_INTERNAL_PARAMS_ERR_CODE, payResult.getErrCode());
Assert.assertEquals(BCPayResult.FAIL_INVALID_PARAMS, payResult.getErrMsg());
// System.out.println(payResult.getDetailInfo());
localLatch.countDown();
}
});
localLatch.await(2000, TimeUnit.MILLISECONDS);
}
}
use of cn.beecloud.entity.BCPayResult in project ttdj by soonphe.
the class BCPayTest method testReqPaymentAsyncNetworkError.
/**
* #2
* 模拟网络400等异常
* @throws Exception
*/
@Test
public void testReqPaymentAsyncNetworkError() throws Exception {
final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
response.code = 400;
response.content = "mocked";
// mock network
PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpPost", String.class, Map.class)).toReturn(response);
// prepare params
final BCPay.PayParams payParams = new BCPay.PayParams();
payParams.channelType = BCReqParams.BCChannelTypes.WX_APP;
payParams.billTitle = "正常title";
payParams.billTotalFee = 3;
payParams.billNum = "123456789ABCDE";
pay.reqPaymentAsync(payParams, new BCCallback() {
@Override
public void done(BCResult result) {
Assert.assertTrue(result instanceof BCPayResult);
BCPayResult payResult = (BCPayResult) result;
Assert.assertEquals(BCPayResult.RESULT_FAIL, payResult.getResult());
Assert.assertEquals((Integer) BCPayResult.APP_INTERNAL_EXCEPTION_ERR_CODE, payResult.getErrCode());
Assert.assertEquals(BCPayResult.FAIL_EXCEPTION, payResult.getErrMsg());
// System.out.println(payResult.getDetailInfo());
latch.countDown();
}
});
latch.await(2000, TimeUnit.MILLISECONDS);
}
use of cn.beecloud.entity.BCPayResult in project ttdj by soonphe.
the class BCPayTest method testReqPaymentAsyncErrorFromServer.
/**
* #3
* 模拟网络200 但是存在后台参数配置问题导致的错误
* @throws Exception
*/
@Test
public void testReqPaymentAsyncErrorFromServer() throws Exception {
final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
response.code = 200;
response.content = "{\"result_msg\":\"PAY_FACTOR_NOT_SET\",\"err_detail\":\"支付宝参数: partner, seller_id, RSA密钥未配置\",\"result_code\":2}";
// mock network
PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpPost", String.class, Map.class)).toReturn(response);
// prepare params
final BCPay.PayParams payParams = new BCPay.PayParams();
payParams.channelType = BCReqParams.BCChannelTypes.WX_APP;
payParams.billTitle = "正常title";
payParams.billTotalFee = 3;
payParams.billNum = "123456789ABCDE";
Map<String, String> analysis = new HashMap<String, String>();
analysis.put("category", "en");
payParams.analysis = analysis;
pay.reqPaymentAsync(payParams, new BCCallback() {
@Override
public void done(BCResult result) {
Assert.assertTrue(result instanceof BCPayResult);
BCPayResult payResult = (BCPayResult) result;
Assert.assertEquals(BCPayResult.RESULT_FAIL, payResult.getResult());
// 回调的错误信息与服务端保持一致
Assert.assertEquals((Integer) 2, payResult.getErrCode());
Assert.assertEquals("PAY_FACTOR_NOT_SET", payResult.getErrMsg());
Assert.assertEquals("支付宝参数: partner, seller_id, RSA密钥未配置", payResult.getDetailInfo());
latch.countDown();
}
});
latch.await(2000, TimeUnit.MILLISECONDS);
}
use of cn.beecloud.entity.BCPayResult in project ttdj by soonphe.
the class BCMockPayActivity method onBackPressed.
@Override
public void onBackPressed() {
if (BCPay.payCallback != null) {
BCPay.payCallback.done(new BCPayResult(BCPayResult.RESULT_CANCEL, BCPayResult.APP_PAY_CANCEL_CODE, BCPayResult.RESULT_CANCEL, BCPayResult.RESULT_CANCEL, BCCache.getInstance().billID));
super.onBackPressed();
} else {
Log.e(TAG, "Callback should not be null");
}
}
Aggregations