Braintree 沙箱帐户不显示交易

Braintree sandbox account does not show transaction

我正在 android 侧客户端令牌生成并获取 nonce 对象现在通过我的服务器 php 侧检查文件

  <?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("eyJ2ZXJzaW9uIjoyLCJhdXRob3JpemF0aW9uRmluZ2VycHJpbnQiOiI4ZjJhOTVlN2E0NjE2NzRjYzE3MmIxN2I4MmYxOGZiNjhhODkzOWVmZmViNTkxNTExM2EzMjlkMjY4MWIwYjE1fGNyZWF0ZWRfYXQ9MjAxNi0wOC0yMlQwNTozNzo0OC45MjU5NDk2OTArMDAwMFx1MDAyNm1lcmNoYW50X2lkPTM0OHBrOWNnZjNiZ3l3MmJcdTAwMjZwdWJsaWNfa2V5PTJuMjQ3ZHY4OWJxOXZtcHIiLCJjb25maWdVcmwiOiJodHRwczovL2FwaS5zYW5kYm94LmJyYWludHJlZWdh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0aC52ZW5tby5zYW5kYm94LmJyYWludHJlZWdhdGV3YXkuY29tIiwiYW5hbHl0aWNzIjp7InVybCI6Imh0dHBzOi8vY2xpZW50LWFuYWx5dGljcy5zYW5kYm94LmJyYWludHJlZWdhdGV3YXkuY29tLzM0OHBrOWNnZjNiZ3l3MmIifSwidGhyZWVEU2VjdXJlRW5hYmxlZCI6dHJ1ZSwicGF5cGFsRW5hYmxlZCI6dHJ1ZSwicGF5cGFsIjp7ImRpc3BsYXlOYW1lIjoiQWNtZSBXaWRnZXRzLCBMdGQuIChTYW5kYm94KSIsImNsaWVudElkIjpudWxsLCJwcml2YWN5VXJsIjoiaHR0cDovL2V4YW1wbGUuY29tL3BwIiwidXNlckFncmVlbWVudFVybCI6Imh0dHA6Ly9leGFtcGxlLmNvbS90b3MiLCJiYXNlVXJsIjoiaHR0cHM6Ly9hc3NldHMuYnJhaW50cmVlZ2F0ZXdheS5jb20iLCJhc3NldHNVcmwiOiJodHRwczovL2NoZWNrb3V0LnBheXBhbC5jb20iLCJkaXJlY3RCYXNlVXJsIjpudWxsLCJhbGxvd0h0dHAiOnRydWUsImVudmlyb25tZW50Tm9OZXR3b3JrIjp0cnVlLCJlbnZpcm9ubWVudCI6Im9mZmxpbmUiLCJ1bnZldHRlZE1lcmNoYW50IjpmYWxzZSwiYnJhaW50cmVlQ2xpZW50SWQiOiJtYXN0ZXJjbGllbnQzIiwiYmlsbGluZ0FncmVlbWVudHNFbmFibGVkIjp0cnVlLCJtZXJjaGFudEFjY291bnRJZCI6ImFjbWV3aWRnZXRzbHRkc2FuZGJveCIsImN1cnJlbmN5SXNvQ29kZSI6IlVTRCJ9LCJjb2luYmFzZUVuYWJsZWQiOmZhbHNlLCJtZXJjaGFudElkIjoiMzQ4cGs5Y2dmM2JneXcyYiIsInZlbm1vIjoib2ZmIn0=");
        }
    });
}

public void onBraintreeSubmit(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) {
        }
     }
  );

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

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

  1. 您的 API credentials 已全部设置并可用于服务器端集成
  2. 您正在 generating a unique client token 在您的服务器中并将其发送给您的客户端

  3. 您在您的客户端中 generating a paymentMethodNonce 并将其发送回您的服务器

  4. 使用随机数创建您的新交易。
  5. 检查从 Braintree_Transaction::Sale 返回的 transaction result object 以检查错误。

根据您发布的具体实施,我建议您仔细检查 someFunctionToLookupCorrectMerchantIdBasedOnCurrency() returns 有效的 merchantID,$nonceFromTheClient 是否定义且唯一,并且您的客户是收到客户端令牌。

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

我的代码工作正常php 服务器端静态金额传递使用 'fake-valid-nonce' 客户端金额传递使用 'paymentMethodNonce' => nonceFromTheClient,代码工作正常