BCOfflinePay { public void reqOfflinePayAsync(final BCReqParams.BCChannelTypes channelType, final String billTitle, final Integer billTotalFee, final String billNum, final Map<String, String> optional, final String authCode, final String terminalId, final String storeId, final BCCallback callback) { reqOfflinePayAsync(channelType, billTitle, billTotalFee, billNum, null, null, null, optional, null, authCode, terminalId, storeId, callback); } private  BCOfflinePay(); synchronized static BCOfflinePay getInstance(); static Bitmap generateBitmap(String contentsToEncode,
                                        int imageWidth, int imageHeight,
                                        int marginSize, int color, int colorBack); void reqQRCodeAsync(final BCReqParams.BCChannelTypes channelType,
                               final String billTitle, final Integer billTotalFee,
                               final String billNum, final Map<String, String> optional,
                               final Boolean genQRCode, final Integer qrCodeWidth,
                               final BCCallback callback); void reqQRCodeAsync(final PayParams payParam,
                               final BCCallback callback); void reqOfflinePayAsync(final BCReqParams.BCChannelTypes channelType,
                                   final String billTitle, final Integer billTotalFee,
                                   final String billNum, final Map<String, String> optional,
                                   final String authCode, final String terminalId,
                                   final String storeId, final BCCallback callback); void reqOfflinePayAsync(final PayParams payParam, final BCCallback callback); void reqWXNativeQRCodeAsync(final String billTitle, final Integer billTotalFee,
                                       final String billNum, final Map<String, String> optional,
                                       final Boolean genQRCode, final Integer qrCodeWidth,
                                       final BCCallback callback); void reqAliOfflineQRCodeAsync(final String billTitle, final Integer billTotalFee,
                                         final String billNum, final Map<String, String> optional,
                                         final Boolean genQRCode, final Integer qrCodeWidth,
                                         final BCCallback callback); void reqRevertBillAsync(final BCReqParams.BCChannelTypes channelType,
                                   final String billNum,
                                   final BCCallback callback);  }
@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}"; 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); }
@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}"; 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); }
@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}"; 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); }
@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); }
@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()); localLatch.countDown(); } }); localLatch.await(2000, TimeUnit.MILLISECONDS); } }
@Test public void testReqOfflinePayAsyncNetworkError() throws Exception { final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response(); response.code = 400; response.content = "wrong"; 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()); latch.countDown(); } }); latch.await(2000, TimeUnit.MILLISECONDS); }