use of cn.beecloud.entity.BCPayResult in project ttdj by soonphe.
the class BCOfflinePayTest method testReqOfflinePayAsyncSucc.
/**
* #4
* 测试全部正常的情况
* @throws Exception
*/
@Test
public void testReqOfflinePayAsyncSucc() throws Exception {
final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
response.code = 200;
response.content = "{\"result_msg\":\"OK\",\"err_detail\":\"\",\"result_code\":0,\"pay_result\":true}";
// mock network
PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpPost", String.class, Map.class)).toReturn(response);
pay.reqOfflinePayAsync(BCReqParams.BCChannelTypes.WX_SCAN, "订单标题", 1, "123456789ABCDE", null, "fakecode", null, "storeid", new BCCallback() {
@Override
public void done(BCResult result) {
Assert.assertTrue(result instanceof BCPayResult);
BCPayResult payResult = (BCPayResult) result;
Assert.assertEquals(BCPayResult.RESULT_SUCCESS, payResult.getResult());
latch.countDown();
}
});
latch.await(2000, TimeUnit.MILLISECONDS);
}
use of cn.beecloud.entity.BCPayResult in project ttdj by soonphe.
the class BCOfflinePayTest method testReqOfflinePayAsyncNetworkError.
/**
* #2
* 测试网络400异常情况
* @throws Exception
*/
@Test
public void testReqOfflinePayAsyncNetworkError() throws Exception {
final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
response.code = 400;
response.content = "wrong";
// mock network
PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpPost", String.class, Map.class)).toReturn(response);
pay.reqOfflinePayAsync(BCReqParams.BCChannelTypes.WX_SCAN, "订单标题", 1, "123456789ABCDE", null, "fakecode", null, 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_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 BCOfflinePayTest method testReqOfflinePayAsyncByBean.
/**
* #5
* 测试通过PayParams支付
* @throws Exception
*/
@Test
public void testReqOfflinePayAsyncByBean() throws Exception {
final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
response.code = 200;
response.content = "{\"result_msg\":\"OK\",\"err_detail\":\"\",\"result_code\":0,\"pay_result\":true}";
// mock network
PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpPost", String.class, Map.class)).toReturn(response);
BCOfflinePay.PayParams params = new BCOfflinePay.PayParams();
params.channelType = BCReqParams.BCChannelTypes.WX_SCAN;
params.billTitle = "订单标题";
params.billTotalFee = 1;
params.billNum = "123456789ABCDE";
params.authCode = "fakecode";
pay.reqOfflinePayAsync(params, new BCCallback() {
@Override
public void done(BCResult result) {
Assert.assertTrue(result instanceof BCPayResult);
BCPayResult payResult = (BCPayResult) result;
Assert.assertEquals(BCPayResult.RESULT_SUCCESS, payResult.getResult());
latch.countDown();
}
});
latch.await(2000, TimeUnit.MILLISECONDS);
}
use of cn.beecloud.entity.BCPayResult in project ttdj by soonphe.
the class BCOfflinePayTest method testReqOfflinePayAsyncTestMode.
/**
* #6
* 模拟test mode,应该提示暂不支持
* @throws Exception
*/
@Test
public void testReqOfflinePayAsyncTestMode() throws Exception {
BeeCloud.setSandbox(true);
pay.reqOfflinePayAsync(BCReqParams.BCChannelTypes.ALI_SCAN, "正常title", 1, "123456789abcde", null, "authcode", "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());
Assert.assertEquals("该功能暂不支持测试模式", payResult.getDetailInfo());
BeeCloud.setSandbox(false);
latch.countDown();
}
});
latch.await(2000, TimeUnit.MILLISECONDS);
}
use of cn.beecloud.entity.BCPayResult in project ttdj by soonphe.
the class BCOfflinePayTest method testReqOfflinePayAsyncErrorFromServer.
/**
* #3
* 测试网络200 但是 支付不成功
* @throws Exception
*/
@Test
public void testReqOfflinePayAsyncErrorFromServer() throws Exception {
final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
response.code = 200;
response.content = "{\"result_msg\":\"CHANNEL_ERROR\",\"err_detail\":\"AUTHCODEEXPIRE\",\"result_code\":7,\"pay_result\":false}";
// mock network
PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpPost", String.class, Map.class)).toReturn(response);
pay.reqOfflinePayAsync(BCReqParams.BCChannelTypes.WX_SCAN, "订单标题", 1, "123456789ABCDE", null, "fakecode", null, "storeid", 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) 7, payResult.getErrCode());
Assert.assertEquals("CHANNEL_ERROR", payResult.getErrMsg());
latch.countDown();
}
});
latch.await(2000, TimeUnit.MILLISECONDS);
}
Aggregations