Braintree沙盒账户不显示交易

Posted

技术标签:

【中文标题】Braintree沙盒账户不显示交易【英文标题】:Braintree sandbox account does not show transaction 【发布时间】:2016-12-28 15:49:26 【问题描述】:

我是 android 端客户端令牌生成并获取 nonce 对象以通过我的服务器现在 php 端 checkouut 文件

  <?php

require_once(__DIR__ . DIRECTORY_SEPARATOR . 'config.php');

$nonceFromTheClient = $_POST['payment_method_nonce']
$amount = $_POST['amount']
$merchantAccountId = someFunctionToLookupCorrectMerchantIdBasedOnCurrency();

 $result = Braintree_Transaction::sale([
'amount' => "10.00",
'paymentMethodNonce' => $nonceFromTheClient,
'merchantAccountId' => $merchantAccountId,
'options' => [
    'submitForSettlement' => True
   ]
]);
 $transaction = $result->transaction;
 $transaction->paymentInstrumentType ==    
Braintree_PaymentInstrumentType::PAYPAL_ACCOUNT;
# false
  $transaction->paymentInstrumentType ==    
 Braintree_PaymentInstrumentType::CREDIT_CARD;

这些我在检查沙盒账户交易后的代码没有显示交易摘要我在做什么请帮助我提前谢谢

客户端代码

    AsyncHttpClient client = new AsyncHttpClient();
    client.get("http://192.168.0.102:8080/btsample/client_token.php", new TextHttpResponseHandler() 
        @Override
        public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) 

        
        @Override
        public void onSuccess(int statusCode, Header[] headers, String clientToken) 
            Toast.makeText(MainActivity.this, clientToken.toString(), Toast.LENGTH_SHORT).show();
            Log.d("clientToken",clientToken.toString());
          //  onBraintreeSubmit("eyJ2ZXJzaW9uIjoyLCJhdXRob3JpemF0aW9uRmluZ2VycHJpbnQiOiI4ZjJhOTVlN2E0NjE2NzRjYzE3MmIxN2I4MmYxOGZiNjhhODkzOWVmZmViNTkxNTExM2EzMjlkMjY4MWIwYjE1fGNyZWF0ZWRfYXQ9MjAxNi0wOC0yMlQwNTozNzo0OC45MjU5NDk2OTArMDAwMFx1MDAyNm1lcmNoYW50X2lkPTM0OHBrOWNnZjNiZ3l3MmJcdTAwMjZwdWJsaWNfa2V5PTJuMjQ3Z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ubmit(String Token) 

    PaymentRequest paymentRequest = new PaymentRequest().clientToken(Token);
    startActivityForResult(paymentRequest.getIntent(this), REQUEST_CODE);


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) 
    if (requestCode == REQUEST_CODE) 
        if (resultCode == Activity.RESULT_OK) 
            PaymentMethodNonce paymentMethodNonce = data.getParcelableExtra(
                    BraintreePaymentActivity.EXTRA_PAYMENT_METHOD_NONCE
            );
            String nonce = paymentMethodNonce.getNonce();
            Log.d("nonce",nonce);
            postNonceToServer(nonce);
        
    


    void postNonceToServer(String nonce) 
    AsyncHttpClient client = new AsyncHttpClient();
    RequestParams params = new RequestParams();
    params.put("payment_method_nonce", nonce);
    params.put("amount", 20);
    client.post("http://192.168.0.102:8080/btsample/checkout.php", params, new AsyncHttpResponseHandler() 
        @Override
        public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) 
            Log.d("responsebody",responseBody.toString());
            Toast.makeText(MainActivity.this, responseBody.toString(), Toast.LENGTH_SHORT).show();
            startActivity(new Intent(getApplicationContext(),Main2Activity.class));
        

        @Override
        public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) 
        
     
  );

【问题讨论】:

【参考方案1】:

我的代码完美运行 php 服务器端静态金额传递使用'fake-valid-nonce',客户端金额传递使用'paymentMethodNonce' => nonceFromTheClient,代码完美运行

【讨论】:

【参考方案2】:

全面披露:我在 Braintree 工作。如果您还有任何问题,请随时联系support。

您的交易未在网关中注册可能有多种原因。你应该确保

    您的 API credentials 已全部设置好并可供您的服务器端集成使用

    您是服务器中的generating a unique client token,并将其发送给您的客户端

    您是客户端中的generating a paymentMethodNonce,并将其发送回您的服务器

    使用 nonce 创建新事务。 检查从Braintree_Transaction::Sale 返回的transaction result object 以检查错误。

根据您发布的具体实施,我建议您仔细检查 someFunctionToLookupCorrectMerchantIdBasedOnCurrency() 是否返回有效的商家 ID,$nonceFromTheClient 已定义且唯一,并且您的客户正在接收客户令牌。

有关您的集成的更多帮助,请联系Braintree support。

【讨论】:

不显示沙盒账户交易摘要 通过服务器付款不显示在交易中我有手动交易支付成功显示交易 这段代码有什么问题我需要沙箱凭据;交易不显示 "paymentMethodNonce" => 'fake-valid-nonce' 我已经修改了这些工作的代码但是 nonceobject pass 为什么不起作用???

以上是关于Braintree沙盒账户不显示交易的主要内容,如果未能解决你的问题,请参考以下文章

Braintree - 为啥通过 API 或沙盒创建的 Braintree 交易需要这么长时间才能完成?

如何在没有商户账户的情况下使用 Braintree 进行买卖双方的付款?

Braintree 付款 - 沙盒交易的处理器拒绝(2409)错误

用braintree生产账户接受paypal

贝宝沙盒账户交易失败

Braintree Paypal 交易处理器被拒绝(货币代码无效)