我目前正在Paypal Payment Gateway实施我的商店。 我在paypal沙盒帐户中添加了一个返回URL。
到目前为止的付款步骤:
WC_Gateway_Paypal
课程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
中,我返回Paypal网址,我将客户重定向到。
成功付款后,客户会从paypal重定向到:http://mypage.com/56/?key=wc_order_59d24a26d4ccb&utm_nooverride=1
现在我想更新我的订单。我知道我可以从重定向网址中读取订单的ID和密钥,但这不是一个安全问题吗?如果有人知道ID或密钥,他只能触发GET
到我的网站并更新订单而无需实际付款。
有没有更好的方法来实现这一目标?或者我只需要使用key=wc_order_59d24a26d4ccb
而不是ID,并注意不要将密钥发送到前端?
此外,我没有收到任何transaction_id
,$order->get_transaction_id();
在成功付款后为空。这是因为我在我的本地机器上开发/使用沙箱帐户吗?
答案 0 :(得分:0)
这是最相似的,因为您正在本地计算机上进行开发。
paypal集成在后台完成了很多工作(交换令牌,更新订单等等)。当您创建付款时,paypal会获取您的本地开发网址(即http://localhost/something
),但由于您位于路由器后面,因此无法访问该网址。尝试将安装移至服务器或网站空间,然后重试,它应该可以正常工作。