【发布时间】:2015-09-12 23:16:03
【问题描述】:
我试图弄清楚如何使用 Braintree 支付网关在我的 Android 应用中检查交易状态。
我已经阅读了他们的文档,如果资金不足,会有类似 2001 的拒绝代码。但这仅指服务器端,我已将其实现为:
...
$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);
}
...
但是当我检查付款随机数时,没有办法取回响应,我已经尝试通过读取标题,但我从回显的内容中一无所获:
安卓实现:
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!");
}
}
);
}
那么在为客户提供服务之前,我如何验证交易状态?
【问题讨论】:
标签: android http response payment-gateway braintree