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?