Edmond Tamas
Edmond Tamas

Reputation: 3295

Braintree transaction status android, how to check if declined?

I try to figure out how to check for transaction status in my android app using the Braintree payment gateway.

I have read their documentations, there are decline codes like 2001 if there are insufficient funds. But this refers to the server side only, I have implemented this as:

...
$nonce = $_POST["payment_method_nonce"];
$amount = $_POST["amount"];

$result = Braintree_Transaction::sale(array(
  'amount' => $amount,
  'paymentMethodNonce' => $nonce
));


if ($result->success) {
    echo("Success! Transaction ID: " . $result->transaction->id);
} else if ($result->transaction->status) {
    echo("Error: " . $result->message);
    echo("<br/>");
    echo("Code: " . $result->transaction->processorResponseCode);
} 

...

But as I check for the payment nonce, there is no way to get the response back, I have tried via reading headers, but there I get nothing from what I echo out:

android implementation:

void postNonceToServer(String nonce) {

        //set a boolean to veryfy transaction status, then send files in onResume (error if trying in onActivityResult)
        transactionDone = true;

        AsyncHttpClient client = new AsyncHttpClient();
        RequestParams params = new RequestParams();
        params.put("payment_method_nonce", nonce);
        params.put("amount", total);
        client.post("http://edmondvarga.com/laborator/brt_server/payment-methods.php", params,
                new AsyncHttpResponseHandler() {
                    @Override
                    public void onSuccess(int i, Header[] headers, byte[] bytes) {

                        HashMap<String, String> result = new HashMap<String, String>(headers.length);
                        for (Header header : headers) {
                            result.put(header.getName(), header.getValue());
                            Log.i("header", "name/value: " + header.getName() + " " + header.getValue() + " or " + header.getName().toString() + " " + header.getValue().toString());
                        }


                    }

                    @Override
                    public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
                        Log.i("Nonce", "sending nonce failed!");
                    }

                }
        );
    }

So how could I verify the status of the transaction before I am serving my client?

Upvotes: 1

Views: 649

Answers (2)

cdeist
cdeist

Reputation: 229

I'm a developer at Braintree. In general, the nonce will not contain processor verification information, because these verifications are not run until you attempt to create a transaction using the nonce (with your server-side call).

If you are using our drop-in integration, you can choose to run these verifications before creating the nonce by enabling verifications in the control panel. In this case, the nonce creation will only succeed if the verifications pass.

Upvotes: 1

Seenu S
Seenu S

Reputation: 3481

PaymentMetodNonce is an random integer number while you processing the transaction from the client side. You need a Braintree token for the transaction. You need to create the customer_id. Using the customer_id and paymentmethodnonce you can generate the braintree token. Follow this link: Correct way to link PayPal Accounts to vault with Braintree DropUI

Upvotes: 0

Related Questions