Woocommerce + Payment (PayPal) - 安全更新订单状态 + 获取交易 ID
Woocommerce + Payment (PayPal) - Securely update order status + get transaction ID
我目前正在将 Paypal Payment Gateway 实施到我的商店中。
我在我的贝宝沙盒帐户中添加了一个 return URL。
到目前为止的付款步骤:
- 创建订单
- 通过
WC_Gateway_Paypal
创建付款 class
- 重定向到贝宝网站登录并处理付款
- 成功后重定向到
return_url
示例代码:
function create_order()
{
$order = wc_create_order();
$product = wc_get_product(55);
$order->add_product($product, 1);
$address = array(
'first_name' => 'John',
'last_name' => 'Doe',
'company' => '',
'email' => 'john@doe.com',
'phone' => '111111',
'address_1' => '',
'address_2' => '',
'city' => '',
'state' => '',
'postcode' => '',
'country' => ''
);
$order->set_address($address, 'billing');
$order->set_address($address, 'shipping');
$order->calculate_totals();
$order->set_payment_method('paypal');
$paypal = new WC_Gateway_Paypal();
$paymentdetails = $paypal->process_payment($order->get_id());
return $paymentdetails;
}
在 $paymentdetails
我 return 贝宝 URL 我将客户重定向到的地方。
付款成功后,客户会从 paypal 重定向到:http://mypage.com/56/?key=wc_order_59d24a26d4ccb&utm_nooverride=1
现在我想更新我的订单。我知道我可以从重定向 URL 中读取订单的 ID 和密钥,但这不会是一个安全问题吗?如果有人知道 ID 或密钥,他可以触发 GET
到我的网站并更新他的订单,而无需实际付款。
有没有更好的方法来完成这个?还是我只需要使用 key=wc_order_59d24a26d4ccb
而不是 ID 并注意不要将密钥发送到前端?
此外,我没有收到任何transaction_id
,付款成功后$order->get_transaction_id();
为空。这是因为我在我的本地机器上开发/使用沙箱帐户吗?
这很可能是因为您正在本地计算机上进行开发。
paypal 集成在后台做了很多事情(交换令牌、更新订单等...)。当您创建付款时,paypal 会获取您的本地开发人员 URL(即 http://localhost/something
)但无法访问它,因为您在路由器后面。尝试将安装移动到服务器或网站空间,然后重试,应该可以。
我目前正在将 Paypal Payment Gateway 实施到我的商店中。 我在我的贝宝沙盒帐户中添加了一个 return URL。
到目前为止的付款步骤:
- 创建订单
- 通过
WC_Gateway_Paypal
创建付款 class - 重定向到贝宝网站登录并处理付款
- 成功后重定向到
return_url
示例代码:
function create_order()
{
$order = wc_create_order();
$product = wc_get_product(55);
$order->add_product($product, 1);
$address = array(
'first_name' => 'John',
'last_name' => 'Doe',
'company' => '',
'email' => 'john@doe.com',
'phone' => '111111',
'address_1' => '',
'address_2' => '',
'city' => '',
'state' => '',
'postcode' => '',
'country' => ''
);
$order->set_address($address, 'billing');
$order->set_address($address, 'shipping');
$order->calculate_totals();
$order->set_payment_method('paypal');
$paypal = new WC_Gateway_Paypal();
$paymentdetails = $paypal->process_payment($order->get_id());
return $paymentdetails;
}
在 $paymentdetails
我 return 贝宝 URL 我将客户重定向到的地方。
付款成功后,客户会从 paypal 重定向到:http://mypage.com/56/?key=wc_order_59d24a26d4ccb&utm_nooverride=1
现在我想更新我的订单。我知道我可以从重定向 URL 中读取订单的 ID 和密钥,但这不会是一个安全问题吗?如果有人知道 ID 或密钥,他可以触发 GET
到我的网站并更新他的订单,而无需实际付款。
有没有更好的方法来完成这个?还是我只需要使用 key=wc_order_59d24a26d4ccb
而不是 ID 并注意不要将密钥发送到前端?
此外,我没有收到任何transaction_id
,付款成功后$order->get_transaction_id();
为空。这是因为我在我的本地机器上开发/使用沙箱帐户吗?
这很可能是因为您正在本地计算机上进行开发。
paypal 集成在后台做了很多事情(交换令牌、更新订单等...)。当您创建付款时,paypal 会获取您的本地开发人员 URL(即 http://localhost/something
)但无法访问它,因为您在路由器后面。尝试将安装移动到服务器或网站空间,然后重试,应该可以。