布伦特里支付 - 检查交易状态
Braintree Payments - Checking transaction status
我正在创建我的第一个电子商务网站,并使用 Braintree Payments 作为网关。
我已按照此处所示进行设置 https://www.youtube.com/watch?v=dUAk5kwKfjs 以便它现在接受付款,然后在数据库中更新我的订单 table,如下所示:
$result = Braintree_Transaction::sale([
'amount' => $total,
'orderId' => $order_id,
'merchantAccountId' => $active_country_braintree,
'paymentMethodNonce' => $nonce,
'customer' => [
'firstName' => $first_name,
'lastName' => $last_name,
'email' => $email
],
'options' => [
'submitForSettlement' => true
]
]);
if ($result->success === true) {
$transaction_id = $result->transaction->id;
$params = [$transaction_id,$order_id];
$sql = "UPDATE orders SET transaction_id=?, status='processing payment', date_last_status_change=now() WHERE id=?";
$stmt = DB::run($sql,$params);
}else{
$error = serialize($result->errors);
$params = [$error,$order_id];
$sql = "UPDATE orders SET errors=? WHERE id=?";
$stmt = DB::run($sql,$params);
}
一切正常,我所有的付款都发送到 Braintree 进行结算。但是,然后我希望能够向 Braintree 发送另一个请求(可能每天一次通过 cron 作业)以查看此交易是否已结算或拒绝并适当地更新我的数据库。
我一直试图通过查看 Braintrees 文档 (https://developers.braintreepayments.com/reference/response/transaction/php#result-object) 来解决这个问题,但我并没有真正理解它。
我想要的是能够将我存储的交易 ID 传回 Braintree 并获取它的状态。
$params = ['processing payment'];
$sql = "SELECT * FROM orders WHERE status=?";
$stmt = DB::run($sql,$params);
$orderCount = $stmt->rowCount();
if ($orderCount > 0) {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
$id = $row["id"];
$transaction_id = $row["transaction_id"];
$order_id = $row["order_id"];
// Pass transaction ID back to Braintree and get status
// $result = Braintree_Transaction::sale($transaction_id);
// var_dump($result);
}
}
如果有人能给我任何帮助或协助,将不胜感激。
如果您的交易失败,您可以使用以下方法获取错误报告
$result->errors->shallowAll();
它将 return 错误详细信息和 BraintreeErrorValidationcode。
完全披露:我在 Braintree 工作。如果您有任何其他问题,请联系 support
如果您有交易 ID,则可以使用以下方法将 ID 传递到 Transaction Find API Call, which returns the transaction object, and querying the status 来访问交易状态:
$transaction = Braintree_Transaction::find("the_transaction_id");
$transaction->status;
// "settled"
话虽如此,但在交易销售电话中,提交结算后通常不需要查询交易的最终状态。
Settlement declined 状态仅适用于 PayPal 销售、Paypal 退款和信用卡退款。如果信用卡交易销售被授权并提交结算,则也将达到已结算状态。即使是 PayPal 交易,交易也会立即进入 Settlement Declined 状态,因此您也可以在交易销售调用后立即使用 $transaction->status
查询状态。
Settlement pending 交易也只能用于 PayPal 交易,并且会在销售电话后立即达到该状态。它们可以用于信用卡交易,但前提是您要求我们启用它。
我正在创建我的第一个电子商务网站,并使用 Braintree Payments 作为网关。
我已按照此处所示进行设置 https://www.youtube.com/watch?v=dUAk5kwKfjs 以便它现在接受付款,然后在数据库中更新我的订单 table,如下所示:
$result = Braintree_Transaction::sale([
'amount' => $total,
'orderId' => $order_id,
'merchantAccountId' => $active_country_braintree,
'paymentMethodNonce' => $nonce,
'customer' => [
'firstName' => $first_name,
'lastName' => $last_name,
'email' => $email
],
'options' => [
'submitForSettlement' => true
]
]);
if ($result->success === true) {
$transaction_id = $result->transaction->id;
$params = [$transaction_id,$order_id];
$sql = "UPDATE orders SET transaction_id=?, status='processing payment', date_last_status_change=now() WHERE id=?";
$stmt = DB::run($sql,$params);
}else{
$error = serialize($result->errors);
$params = [$error,$order_id];
$sql = "UPDATE orders SET errors=? WHERE id=?";
$stmt = DB::run($sql,$params);
}
一切正常,我所有的付款都发送到 Braintree 进行结算。但是,然后我希望能够向 Braintree 发送另一个请求(可能每天一次通过 cron 作业)以查看此交易是否已结算或拒绝并适当地更新我的数据库。
我一直试图通过查看 Braintrees 文档 (https://developers.braintreepayments.com/reference/response/transaction/php#result-object) 来解决这个问题,但我并没有真正理解它。
我想要的是能够将我存储的交易 ID 传回 Braintree 并获取它的状态。
$params = ['processing payment'];
$sql = "SELECT * FROM orders WHERE status=?";
$stmt = DB::run($sql,$params);
$orderCount = $stmt->rowCount();
if ($orderCount > 0) {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
$id = $row["id"];
$transaction_id = $row["transaction_id"];
$order_id = $row["order_id"];
// Pass transaction ID back to Braintree and get status
// $result = Braintree_Transaction::sale($transaction_id);
// var_dump($result);
}
}
如果有人能给我任何帮助或协助,将不胜感激。
如果您的交易失败,您可以使用以下方法获取错误报告
$result->errors->shallowAll();
它将 return 错误详细信息和 BraintreeErrorValidationcode。
完全披露:我在 Braintree 工作。如果您有任何其他问题,请联系 support
如果您有交易 ID,则可以使用以下方法将 ID 传递到 Transaction Find API Call, which returns the transaction object, and querying the status 来访问交易状态:
$transaction = Braintree_Transaction::find("the_transaction_id");
$transaction->status;
// "settled"
话虽如此,但在交易销售电话中,提交结算后通常不需要查询交易的最终状态。
Settlement declined 状态仅适用于 PayPal 销售、Paypal 退款和信用卡退款。如果信用卡交易销售被授权并提交结算,则也将达到已结算状态。即使是 PayPal 交易,交易也会立即进入 Settlement Declined 状态,因此您也可以在交易销售调用后立即使用 $transaction->status
查询状态。
Settlement pending 交易也只能用于 PayPal 交易,并且会在销售电话后立即达到该状态。它们可以用于信用卡交易,但前提是您要求我们启用它。