Search in sources :

Example 6 with BCPayResult

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

the class BCMockPayActivity method initButtonBehaviors.

void initButtonBehaviors() {
    cancelView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            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));
            } else {
                Log.e(TAG, "Callback should not be null");
            }
            finish();
        }
    });
    payButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            loadingDialog.show();
            // 发送模拟的异步通知
            BCCache.executorService.execute(new Runnable() {

                @Override
                public void run() {
                    String notifyUrl = BCHttpClientUtil.getNotifyPayResultSandboxUrl() + "/" + BCCache.getInstance().billID;
                    BCHttpClientUtil.Response response = BCHttpClientUtil.httpGet(notifyUrl);
                    loadingDialog.dismiss();
                    if (response.code == 200 || (response.code >= 400 && response.code < 500)) {
                        String ret = response.content;
                        // 反序列化json
                        Gson gson = new Gson();
                        Type type = new TypeToken<Map<String, Object>>() {
                        }.getType();
                        Map<String, Object> responseMap;
                        try {
                            responseMap = gson.fromJson(ret, type);
                        } catch (JsonSyntaxException ex) {
                            if (BCPay.payCallback != null) {
                                BCPay.payCallback.done(new BCPayResult(BCPayResult.RESULT_FAIL, BCPayResult.APP_INTERNAL_EXCEPTION_ERR_CODE, BCPayResult.FAIL_EXCEPTION, "JsonSyntaxException or Network Error:" + response.code + " # " + response.content));
                            } else {
                                Log.e(TAG, "Callback should not be null");
                            }
                            return;
                        }
                        // 判断后台返回结果
                        Integer resultCode = ((Double) responseMap.get("result_code")).intValue();
                        if (resultCode == 0) {
                            if (BCPay.payCallback != null) {
                                BCPay.payCallback.done(new BCPayResult(BCPayResult.RESULT_SUCCESS, BCPayResult.APP_PAY_SUCC_CODE, BCPayResult.RESULT_SUCCESS, BCPayResult.RESULT_SUCCESS, BCCache.getInstance().billID));
                            } else {
                                Log.e(TAG, "Callback should not be null");
                            }
                        } else {
                            if (BCPay.payCallback != null) {
                                BCPay.payCallback.done(new BCPayResult(BCPayResult.RESULT_FAIL, resultCode, String.valueOf(responseMap.get("result_msg")), String.valueOf(responseMap.get("err_detail"))));
                            } else {
                                Log.e(TAG, "Callback should not be null");
                            }
                        }
                    } else {
                        if (BCPay.payCallback != null) {
                            BCPay.payCallback.done(new BCPayResult(BCPayResult.RESULT_FAIL, BCPayResult.APP_INTERNAL_NETWORK_ERR_CODE, BCPayResult.FAIL_NETWORK_ISSUE, "Network Error:" + response.code + " # " + response.content));
                        } else {
                            Log.e(TAG, "Callback should not be null");
                        }
                    }
                    finish();
                }
            });
        }
    });
}
Also used : Gson(com.google.gson.Gson) BCPayResult(cn.beecloud.entity.BCPayResult) TextView(android.widget.TextView) View(android.view.View) Type(java.lang.reflect.Type) JsonSyntaxException(com.google.gson.JsonSyntaxException) Map(java.util.Map)

Example 7 with BCPayResult

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

the class BCPayTest method testReqPaymentAsyncParamsInvalid.

/**
 * #1
 * 测试参数错误
 * @throws Exception
 */
@Test
public void testReqPaymentAsyncParamsInvalid() throws Exception {
    Object[][] test = new Object[][] { // 依次对应必填参数 渠道类型 订单标题 订单金额 订单流水号
    new Object[] { BCReqParams.BCChannelTypes.JD_WAP, null, null, null }, new Object[] { BCReqParams.BCChannelTypes.WX_APP, null, null, null }, new Object[] { BCReqParams.BCChannelTypes.ALI_APP, "试一个很长的title--参数公共返回参数取值及含义参见支付公共返回参数部分", null, null }, new Object[] { BCReqParams.BCChannelTypes.UN_APP, "正常title", null, null }, new Object[] { BCReqParams.BCChannelTypes.BD_APP, "正常title", -1, null } };
    for (Object[] objects : test) {
        BCPay.PayParams payParams = new BCPay.PayParams();
        payParams.channelType = (BCReqParams.BCChannelTypes) objects[0];
        payParams.billTitle = (String) objects[1];
        payParams.billTotalFee = (Integer) objects[2];
        payParams.billNum = (String) objects[3];
        final CountDownLatch localLatch = new CountDownLatch(1);
        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());
                // 渠道错误由BCException抛出,其他正常参数异常错误
                Assert.assertTrue(payResult.getErrCode() == BCPayResult.APP_INTERNAL_EXCEPTION_ERR_CODE || payResult.getErrCode() == BCPayResult.APP_INTERNAL_PARAMS_ERR_CODE);
                Assert.assertTrue(payResult.getErrMsg().equals(BCPayResult.FAIL_EXCEPTION) || payResult.getErrMsg().equals(BCPayResult.FAIL_INVALID_PARAMS));
                // System.out.println(payResult.getDetailInfo());
                localLatch.countDown();
            }
        });
        localLatch.await(2000, TimeUnit.MILLISECONDS);
    }
}
Also used : BCReqParams(cn.beecloud.entity.BCReqParams) BCCallback(cn.beecloud.async.BCCallback) CountDownLatch(java.util.concurrent.CountDownLatch) BCPayResult(cn.beecloud.entity.BCPayResult) BCResult(cn.beecloud.async.BCResult) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 with BCPayResult

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

the class BCPayTest method testReqWXPaymentAsync.

/**
 * 模拟微信发起支付
 * @throws Exception
 */
@Test
public void testReqWXPaymentAsync() throws Exception {
    final BCHttpClientUtil.Response response = new BCHttpClientUtil.Response();
    response.code = 200;
    response.content = "{\"nonce_str\":\"20151119114011235\",\"package\":\"Sign=WXPay\",\"resultCode\":0,\"errMsg\":\"OK:\",\"prepay_id\":\"wx20151119114008765ce0ad440384384408\",\"result_msg\":\"OK\",\"partner_id\":\"1240421502\",\"err_detail\":\"\",\"result_code\":0,\"id\":\"ff5fef0c-93bd-46d2-8500-5ed53502d344\",\"app_id\":\"wxf1aa465362b4c8f1\",\"pay_sign\":\"D0F8E79A14731B59CE04B634FD588C35\",\"timestamp\":\"1447904408\"}";
    // mock network
    PowerMockito.stub(PowerMockito.method(BCHttpClientUtil.class, "httpPost", String.class, Map.class)).toReturn(response);
    Map<String, String> optional = new HashMap<String, String>();
    optional.put("aya", "啊呀");
    pay.reqWXPaymentAsync("正常title", 22, "123456789ABCDE", optional, 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());
            Assert.assertTrue(payResult.getDetailInfo().startsWith("Error: 微信API为空"));
            System.out.println(payResult.getDetailInfo());
            Assert.assertEquals("ff5fef0c-93bd-46d2-8500-5ed53502d344", BCCache.getInstance().billID);
            latch.countDown();
        }
    });
    latch.await(2000, TimeUnit.MILLISECONDS);
}
Also used : HashMap(java.util.HashMap) BCCallback(cn.beecloud.async.BCCallback) BCPayResult(cn.beecloud.entity.BCPayResult) BCResult(cn.beecloud.async.BCResult) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 9 with BCPayResult

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

the class BCUnionPaymentActivity method onActivityResult.

/**
 * 处理银联手机支付控件返回的支付结果
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    String result = null;
    int errCode = -99;
    String errMsg = null;
    String detailInfo = "银联支付:";
    // 银联插件内部升级会出现data为null的情况
    if (data == null) {
        result = BCPayResult.RESULT_FAIL;
        errCode = BCPayResult.APP_INTERNAL_THIRD_CHANNEL_ERR_CODE;
        errMsg = BCPayResult.FAIL_ERR_FROM_CHANNEL;
        detailInfo += "invalid pay result";
    } else {
        /*
             * 支付控件返回字符串:success、fail、cancel 分别代表支付成功,支付失败,支付取消
             */
        String str = data.getExtras().getString("pay_result");
        if (str == null) {
            result = BCPayResult.RESULT_FAIL;
            errCode = BCPayResult.APP_INTERNAL_THIRD_CHANNEL_ERR_CODE;
            errMsg = BCPayResult.FAIL_ERR_FROM_CHANNEL;
            detailInfo += "invalid pay result";
        } else if (str.equalsIgnoreCase("success")) {
            result = BCPayResult.RESULT_SUCCESS;
            errCode = BCPayResult.APP_PAY_SUCC_CODE;
            errMsg = BCPayResult.RESULT_SUCCESS;
            detailInfo += "支付成功!";
        } else if (str.equalsIgnoreCase("fail")) {
            result = BCPayResult.RESULT_FAIL;
            errCode = BCPayResult.APP_INTERNAL_THIRD_CHANNEL_ERR_CODE;
            errMsg = BCPayResult.RESULT_FAIL;
            detailInfo += "支付失败!";
        } else if (str.equalsIgnoreCase("cancel")) {
            result = BCPayResult.RESULT_CANCEL;
            errCode = BCPayResult.APP_PAY_CANCEL_CODE;
            errMsg = BCPayResult.RESULT_CANCEL;
            detailInfo += "用户取消了支付";
        }
    }
    if (BCPay.payCallback != null) {
        BCPay.payCallback.done(new BCPayResult(result, errCode, errMsg, detailInfo, BCCache.getInstance().billID));
    } else {
        Log.e("BCUnionPaymentActivity", "BCPay payCallback NPE");
    }
    this.finish();
}
Also used : BCPayResult(cn.beecloud.entity.BCPayResult)

Example 10 with BCPayResult

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

the class BCWechatPaymentActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i(TAG, "into weixin return activity");
    try {
        String wxAppId = BCCache.getInstance().wxAppId;
        if (wxAppId != null && wxAppId.length() > 0) {
            wxAPI = WXAPIFactory.createWXAPI(this, wxAppId);
            wxAPI.handleIntent(getIntent(), this);
        } else {
            Log.e(TAG, "Error: wxAppId 不合法 BCWechatPaymentActivity: " + wxAppId);
            if (BCPay.payCallback != null) {
                BCPay.payCallback.done(new BCPayResult(BCPayResult.RESULT_FAIL, BCPayResult.APP_INTERNAL_PARAMS_ERR_CODE, BCPayResult.FAIL_INVALID_PARAMS, "wxAppId 不合法"));
            }
            this.finish();
        }
    } catch (Exception ex) {
        Log.e(TAG, ex.getMessage() == null ? "未知错误,初始化回调入口失败" : ex.getMessage());
        if (BCPay.payCallback != null) {
            BCPay.payCallback.done(new BCPayResult(BCPayResult.RESULT_FAIL, BCPayResult.APP_INTERNAL_EXCEPTION_ERR_CODE, BCPayResult.FAIL_EXCEPTION, "微信回调入口初始化失败"));
        }
        this.finish();
    }
}
Also used : BCPayResult(cn.beecloud.entity.BCPayResult)

Aggregations

BCPayResult (cn.beecloud.entity.BCPayResult)20 BCCallback (cn.beecloud.async.BCCallback)10 BCResult (cn.beecloud.async.BCResult)10 Test (org.junit.Test)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 HashMap (java.util.HashMap)4 JsonSyntaxException (com.google.gson.JsonSyntaxException)3 BCReqParams (cn.beecloud.entity.BCReqParams)2 Gson (com.google.gson.Gson)2 Type (java.lang.reflect.Type)2 Map (java.util.Map)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ProgressDialog (android.app.ProgressDialog)1 View (android.view.View)1 TextView (android.widget.TextView)1 BCPayReqParams (cn.beecloud.entity.BCPayReqParams)1 BCQueryBillResult (cn.beecloud.entity.BCQueryBillResult)1 BCQueryReqParams (cn.beecloud.entity.BCQueryReqParams)1 PayTask (com.alipay.sdk.app.PayTask)1 PayCallBack (com.baidu.android.pay.PayCallBack)1