Braintree 支付网关 - 处理订单
Braintree Payment Gateway - processing orders
我正在尝试使用 braintree 支付网关创建一个电子商务网站。
我已经使用此处所示的 dropin 容器创建了表单 https://www.youtube.com/watch?v=dUAk5kwKfjs
然后我尝试添加处理这些数据并将其发送到 braintree 以及将所有内容存储在我的数据库中。这是我要处理的PHP
:
<?php include_once("connection.php"); ?>
<?php
var_dump($_POST);
session_start();
require "boot.php";
$active_country_code = $_SESSION["active_country_code"];
$active_country_braintree = $_SESSION["active_country_braintree"];
$subtotal = $_POST['subtotal'];
$vat = $_POST['vat'];
$vat_percent = $_POST['vat_percent'];
$total = $_POST['total'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$nonce = $_POST['payment_method_nonce'];
$serialized_cart_array = $_POST['cart_array'];
$cart_array = unserialize($serialized_cart_array);
$currency = $active_country_currency;
$customer_id = $_POST['customer_id'];
$address = $_POST['address'];
$params = [$customer_id,$address,$active_country_braintree,$serialized_cart_array,$subtotal,$vat,$vat_percent,$total,$currency,$active_country_code];
$sql = "INSERT INTO orders (customer_id,address_id,braintree_account,cart_array,subtotal,vat,vat_percent,total,currency,country_id,date_created,status,date_last_status_change) VALUES (?,?,?,?,?,?,?,?,?,?,now(),'created',now())";
$stmt = DB::run($sql,$params);
$order_id = DB::lastInsertId();
if (!isset($_POST['payment_method_nonce']) || $_POST['payment_method_nonce']!="") {
echo 'fail';
}
$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);
}
?>
这导致以下输出:
array (size=12)
'first_name' => string 'Paddy' (length=5)
'last_name' => string 'Hallihan' (length=8)
'email' => string 'it@sublift.ie' (length=13)
'address' => string '2' (length=1)
'customer_id' => string '2' (length=1)
'subtotal' => string '196' (length=3)
'vat' => string '45.08' (length=5)
'vat_percent' => string '23' (length=2)
'total' => string '241.08' (length=6)
'guest_checkout' => string 'true' (length=4)
'cart_array' => string 'a:1:{i:0;a:4:{s:7:"item_id";s:1:"1";s:8:"quantity";d:1;s:9:"attribute";s:10:"attribute1";s:15:"attribute_price";s:3:"196";}}' (length=124)
'payment_method_nonce' => string '59698de8-8d4e-0a05-5d02-e8d512057712' (length=36)
fail
如您所见,它正在回显 'fail',因为 $_POST['payment_method_nonce']
不存在,但我也可以看到它存在,但 var_dump($_POST);
这真的很奇怪。
实际上,它正在向我的 table 添加 2 个订单。第一个从 braintree 得到一个错误,指出 'Cannot determine payment method'
,第二个得到正确处理并从 Braintree 取回事务 ID。
好像页面没有获取随机数 运行 然后刷新并正确读取发布的变量。
注释除 var_dump($_POST);
之外的所有内容会导致:
array (size=12)
'first_name' => string 'Paddy' (length=5)
'last_name' => string 'Hallihan' (length=8)
'email' => string 'it@sublift.ie' (length=13)
'address' => string '5' (length=1)
'customer_id' => string '5' (length=1)
'subtotal' => string '196' (length=3)
'vat' => string '45.08' (length=5)
'vat_percent' => string '23' (length=2)
'total' => string '241.08' (length=6)
'guest_checkout' => string 'true' (length=4)
'cart_array' => string 'a:1:{i:0;a:4:{s:7:"item_id";s:1:"1";s:8:"quantity";d:1;s:9:"attribute";s:10:"attribute1";s:15:"attribute_price";s:3:"196";}}' (length=124)
'payment_method_nonce' => string '' (length=0)
如有任何帮助,我们将不胜感激。
问题是我提交到此页面的方式
我正在使用:
<button onclick=this.form.submit();>Pay Now</button>
我现在正在使用:
<input type="submit" value="Pay Now">
但是,我不确定这首先导致问题的原因。我认为这些应该都一样。
我正在尝试使用 braintree 支付网关创建一个电子商务网站。
我已经使用此处所示的 dropin 容器创建了表单 https://www.youtube.com/watch?v=dUAk5kwKfjs
然后我尝试添加处理这些数据并将其发送到 braintree 以及将所有内容存储在我的数据库中。这是我要处理的PHP
:
<?php include_once("connection.php"); ?>
<?php
var_dump($_POST);
session_start();
require "boot.php";
$active_country_code = $_SESSION["active_country_code"];
$active_country_braintree = $_SESSION["active_country_braintree"];
$subtotal = $_POST['subtotal'];
$vat = $_POST['vat'];
$vat_percent = $_POST['vat_percent'];
$total = $_POST['total'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$nonce = $_POST['payment_method_nonce'];
$serialized_cart_array = $_POST['cart_array'];
$cart_array = unserialize($serialized_cart_array);
$currency = $active_country_currency;
$customer_id = $_POST['customer_id'];
$address = $_POST['address'];
$params = [$customer_id,$address,$active_country_braintree,$serialized_cart_array,$subtotal,$vat,$vat_percent,$total,$currency,$active_country_code];
$sql = "INSERT INTO orders (customer_id,address_id,braintree_account,cart_array,subtotal,vat,vat_percent,total,currency,country_id,date_created,status,date_last_status_change) VALUES (?,?,?,?,?,?,?,?,?,?,now(),'created',now())";
$stmt = DB::run($sql,$params);
$order_id = DB::lastInsertId();
if (!isset($_POST['payment_method_nonce']) || $_POST['payment_method_nonce']!="") {
echo 'fail';
}
$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);
}
?>
这导致以下输出:
array (size=12)
'first_name' => string 'Paddy' (length=5)
'last_name' => string 'Hallihan' (length=8)
'email' => string 'it@sublift.ie' (length=13)
'address' => string '2' (length=1)
'customer_id' => string '2' (length=1)
'subtotal' => string '196' (length=3)
'vat' => string '45.08' (length=5)
'vat_percent' => string '23' (length=2)
'total' => string '241.08' (length=6)
'guest_checkout' => string 'true' (length=4)
'cart_array' => string 'a:1:{i:0;a:4:{s:7:"item_id";s:1:"1";s:8:"quantity";d:1;s:9:"attribute";s:10:"attribute1";s:15:"attribute_price";s:3:"196";}}' (length=124)
'payment_method_nonce' => string '59698de8-8d4e-0a05-5d02-e8d512057712' (length=36)
fail
如您所见,它正在回显 'fail',因为 $_POST['payment_method_nonce']
不存在,但我也可以看到它存在,但 var_dump($_POST);
这真的很奇怪。
实际上,它正在向我的 table 添加 2 个订单。第一个从 braintree 得到一个错误,指出 'Cannot determine payment method'
,第二个得到正确处理并从 Braintree 取回事务 ID。
好像页面没有获取随机数 运行 然后刷新并正确读取发布的变量。
注释除 var_dump($_POST);
之外的所有内容会导致:
array (size=12)
'first_name' => string 'Paddy' (length=5)
'last_name' => string 'Hallihan' (length=8)
'email' => string 'it@sublift.ie' (length=13)
'address' => string '5' (length=1)
'customer_id' => string '5' (length=1)
'subtotal' => string '196' (length=3)
'vat' => string '45.08' (length=5)
'vat_percent' => string '23' (length=2)
'total' => string '241.08' (length=6)
'guest_checkout' => string 'true' (length=4)
'cart_array' => string 'a:1:{i:0;a:4:{s:7:"item_id";s:1:"1";s:8:"quantity";d:1;s:9:"attribute";s:10:"attribute1";s:15:"attribute_price";s:3:"196";}}' (length=124)
'payment_method_nonce' => string '' (length=0)
如有任何帮助,我们将不胜感激。
问题是我提交到此页面的方式
我正在使用:
<button onclick=this.form.submit();>Pay Now</button>
我现在正在使用:
<input type="submit" value="Pay Now">
但是,我不确定这首先导致问题的原因。我认为这些应该都一样。