Search in sources :

Example 1 with BCQueryBillResult

use of cn.beecloud.entity.BCQueryBillResult in project ttdj by soonphe.

the class BCQueryTest method testQueryBillByIDAsyncTestMode.

/**
 * #4
 * test mode
 * @throws Exception
 */
@Test
public void testQueryBillByIDAsyncTestMode() throws Exception {
    BeeCloud.setSandbox(true);
    final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
    response.code = 200;
    response.content = "{\"result_msg\":\"OK\",\"err_detail\":\"\",\"pay\":{\"spay_result\":false,\"create_time\":1447643289722,\"total_fee\":1,\"channel\":\"WX\",\"trade_no\":\"\",\"bill_no\":\"20151116110810464\",\"optional\":\"{\\\"testkey1\\\":\\\"测试value值1\\\"}\",\"revert_result\":false,\"title\":\"安卓微信支付测试\",\"sub_channel\":\"WX_APP\",\"message_detail\":\"\",\"refund_result\":false},\"result_code\":0}";
    // mock
    PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpGet", String.class)).toReturn(response);
    query.queryBillByIDAsync("billid", new BCCallback() {

        @Override
        public void done(BCResult result) {
            Assert.assertTrue(result instanceof BCQueryBillResult);
            BCQueryBillResult billResult = (BCQueryBillResult) result;
            Assert.assertEquals((Integer) 0, billResult.getResultCode());
            BCBillOrder billOrder = billResult.getBill();
            Assert.assertEquals("20151116110810464", billOrder.getBillNum());
            Assert.assertEquals("安卓微信支付测试", billOrder.getTitle());
            Assert.assertTrue(billOrder.getTradeNum() == null || billOrder.getTradeNum().length() == 0);
            Assert.assertEquals((Integer) 1, billOrder.getTotalFee());
            Assert.assertEquals("WX", billOrder.getChannel());
            Assert.assertEquals("WX_APP", billOrder.getSubChannel());
            Assert.assertFalse(billOrder.getPayResult());
            Assert.assertFalse(billOrder.getRevertResult());
            Assert.assertEquals((Long) 1447643289722L, billOrder.getCreatedTime());
            Assert.assertEquals("{\"testkey1\":\"测试value值1\"}", billOrder.getOptional());
            BeeCloud.setSandbox(false);
            latch.countDown();
        }
    });
    // 等待
    latch.await(2000, TimeUnit.MILLISECONDS);
}
Also used : BCQueryBillResult(cn.beecloud.entity.BCQueryBillResult) BCCallback(cn.beecloud.async.BCCallback) BCResult(cn.beecloud.async.BCResult) BCBillOrder(cn.beecloud.entity.BCBillOrder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with BCQueryBillResult

use of cn.beecloud.entity.BCQueryBillResult in project ttdj by soonphe.

the class BCQueryTest method testQueryBillByIDAsyncParamInvalid.

/**
 * #1
 * 测试传入id为null的情况
 * @throws Exception
 */
@Test
public void testQueryBillByIDAsyncParamInvalid() throws Exception {
    query.queryBillByIDAsync(null, new BCCallback() {

        @Override
        public void done(BCResult result) {
            // 传出的应是BCQueryBillResult类型
            Assert.assertTrue(result instanceof BCQueryBillResult);
            BCQueryBillResult billResult = (BCQueryBillResult) result;
            // 返回的结果应该是-1
            Assert.assertEquals(BCRestfulCommonResult.APP_INNER_FAIL_NUM, billResult.getResultCode());
            latch.countDown();
        }
    });
    latch.await(2000, TimeUnit.MILLISECONDS);
}
Also used : BCQueryBillResult(cn.beecloud.entity.BCQueryBillResult) BCCallback(cn.beecloud.async.BCCallback) BCResult(cn.beecloud.async.BCResult) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with BCQueryBillResult

use of cn.beecloud.entity.BCQueryBillResult in project ttdj by soonphe.

the class BCQueryTest method testQueryBillByIDAsyncSucc.

/**
 * #3
 * 模拟response为200
 * @throws Exception
 */
@Test
public void testQueryBillByIDAsyncSucc() throws Exception {
    final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
    response.code = 200;
    response.content = "{\"result_msg\":\"OK\",\"err_detail\":\"\",\"pay\":{\"spay_result\":false,\"create_time\":1447643289722,\"total_fee\":1,\"channel\":\"WX\",\"trade_no\":\"\",\"bill_no\":\"20151116110810464\",\"optional\":\"{\\\"testkey1\\\":\\\"测试value值1\\\"}\",\"revert_result\":false,\"title\":\"安卓微信支付测试\",\"sub_channel\":\"WX_APP\",\"message_detail\":\"\",\"refund_result\":false},\"result_code\":0}";
    // mock
    PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpGet", String.class)).toReturn(response);
    query.queryBillByIDAsync("billid", new BCCallback() {

        @Override
        public void done(BCResult result) {
            Assert.assertTrue(result instanceof BCQueryBillResult);
            BCQueryBillResult billResult = (BCQueryBillResult) result;
            Assert.assertEquals((Integer) 0, billResult.getResultCode());
            BCBillOrder billOrder = billResult.getBill();
            Assert.assertEquals("20151116110810464", billOrder.getBillNum());
            Assert.assertEquals("安卓微信支付测试", billOrder.getTitle());
            Assert.assertTrue(billOrder.getTradeNum() == null || billOrder.getTradeNum().length() == 0);
            Assert.assertEquals((Integer) 1, billOrder.getTotalFee());
            Assert.assertEquals("WX", billOrder.getChannel());
            Assert.assertEquals("WX_APP", billOrder.getSubChannel());
            Assert.assertFalse(billOrder.getPayResult());
            Assert.assertFalse(billOrder.getRevertResult());
            Assert.assertEquals((Long) 1447643289722L, billOrder.getCreatedTime());
            Assert.assertEquals("{\"testkey1\":\"测试value值1\"}", billOrder.getOptional());
            // 释放
            latch.countDown();
        }
    });
    // 等待
    latch.await(2000, TimeUnit.MILLISECONDS);
}
Also used : BCQueryBillResult(cn.beecloud.entity.BCQueryBillResult) BCCallback(cn.beecloud.async.BCCallback) BCResult(cn.beecloud.async.BCResult) BCBillOrder(cn.beecloud.entity.BCBillOrder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with BCQueryBillResult

use of cn.beecloud.entity.BCQueryBillResult in project ttdj by soonphe.

the class BCQueryTest method testQueryBillByIDAsyncNetworkError.

/**
 * #2
 * 模拟网络异常response为400等
 * @throws Exception
 */
@Test
public void testQueryBillByIDAsyncNetworkError() throws Exception {
    final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
    response.code = 400;
    response.content = "wrong";
    // mock
    PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpGet", String.class)).toReturn(response);
    query.queryBillByIDAsync("billid", new BCCallback() {

        @Override
        public void done(BCResult result) {
            Assert.assertTrue(result instanceof BCQueryBillResult);
            BCQueryBillResult billResult = (BCQueryBillResult) result;
            Assert.assertEquals(BCRestfulCommonResult.APP_INNER_FAIL_NUM, billResult.getResultCode());
            // 释放
            latch.countDown();
        }
    });
    // 等待
    latch.await(2000, TimeUnit.MILLISECONDS);
}
Also used : BCQueryBillResult(cn.beecloud.entity.BCQueryBillResult) BCCallback(cn.beecloud.async.BCCallback) BCResult(cn.beecloud.async.BCResult) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with BCQueryBillResult

use of cn.beecloud.entity.BCQueryBillResult in project ttdj by soonphe.

the class BCWXWapPaymentActivity method onResume.

public void onResume() {
    super.onResume();
    synchronized (this) {
        if (firstIn) {
            firstIn = false;
            return;
        }
    }
    final ProgressDialog loadingDialog = new ProgressDialog(this);
    loadingDialog.setMessage("处理中,请稍候...");
    loadingDialog.setIndeterminate(true);
    loadingDialog.setCancelable(false);
    loadingDialog.show();
    BCCache.executorService.execute(new Runnable() {

        @Override
        public void run() {
            boolean found = false;
            // 总共查3次
            for (int i = 0; i < 3; i++) {
                BCQueryReqParams bcQueryReqParams;
                try {
                    bcQueryReqParams = new BCQueryReqParams(BCReqParams.BCChannelTypes.ALL);
                } catch (BCException e) {
                    Log.w(TAG, e.getMessage() + "");
                    return;
                }
                String queryURL = BCHttpClientUtil.getBillQueryURL() + "/" + BCCache.getInstance().billID + "?para=";
                BCHttpClientUtil.Response response = BCHttpClientUtil.httpGet(queryURL + bcQueryReqParams.transToEncodedJsonString());
                if (response.code == 200 || (response.code >= 400 && response.code < 500)) {
                    try {
                        BCQueryBillResult billResult = BCQueryBillResult.transJsonToResultObject(response.content);
                        // 如果查询到成功退出
                        if (billResult.getResultCode() == 0 && billResult.getBill().getPayResult() != null && billResult.getBill().getPayResult()) {
                            if (BCPay.payCallback != null) {
                                BCPay.payCallback.done(new BCPayResult(BCPayResult.RESULT_SUCCESS, BCPayResult.APP_PAY_SUCC_CODE, BCPayResult.RESULT_SUCCESS, "用户支付成功", BCCache.getInstance().billID));
                            }
                            found = true;
                            break;
                        }
                    } catch (JsonSyntaxException ex) {
                        Log.w(TAG, ex.getMessage() + "");
                    }
                }
                try {
                    // 0.5s后继续查
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    Log.w(TAG, e.getMessage() + "");
                }
            }
            if (!found) {
                // 如果一直没有查询到支付结果
                if (BCPay.payCallback != null) {
                    BCPay.payCallback.done(new BCPayResult(BCPayResult.RESULT_CANCEL, BCPayResult.APP_PAY_CANCEL_CODE, BCPayResult.RESULT_CANCEL, "用户未支付,或服务器通信延迟,如果用户确认已支付,请注意webhook推送", BCCache.getInstance().billID));
                }
            }
            loadingDialog.dismiss();
            finish();
        }
    });
}
Also used : BCQueryReqParams(cn.beecloud.entity.BCQueryReqParams) BCQueryBillResult(cn.beecloud.entity.BCQueryBillResult) JsonSyntaxException(com.google.gson.JsonSyntaxException) ProgressDialog(android.app.ProgressDialog) BCPayResult(cn.beecloud.entity.BCPayResult)

Aggregations

BCQueryBillResult (cn.beecloud.entity.BCQueryBillResult)5 BCCallback (cn.beecloud.async.BCCallback)4 BCResult (cn.beecloud.async.BCResult)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 BCBillOrder (cn.beecloud.entity.BCBillOrder)2 ProgressDialog (android.app.ProgressDialog)1 BCPayResult (cn.beecloud.entity.BCPayResult)1 BCQueryReqParams (cn.beecloud.entity.BCQueryReqParams)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1