【发布时间】:2021-12-29 10:07:26
【问题描述】:
我在下面有这段代码,它运行良好,但我可以使用代理来更改所有数据(我也可以更改接收者电子邮件):/
如何使它成为 POST 结帐方法?现在它是一个 GET 方法
<?php
public function checkout()
{
$query = [];
$query['cmd'] = '_cart';
$query['upload'] = 1;
$query['business'] = $this->getCredential();
foreach ($this->getItems() as $id => $item)
{
$id = $id + 1;
$query['item_name_' . $id] = $item['name'];
$query['amount_' . $id] = $item['amount'];
$query['quantity_' . $id] = $item['quantity'];
}
$query['custom'] = $this->getReference();
$query['<first_name>'] = $this->first_name;
$query['<last_name>'] = $this->last_name;
$query['<email>'] = $this->customer_email;
$query['notify_url'] = $this->getNotificationURL();
$query['return'] = $this->getReturnURL();
$query['cancel_return'] = $this->getCancelURL();
$query['rm'] = '2';
$query['cbt'] = 'Retornar para o site';
$query['lc'] = $this->getLocation();
$query['currency_code'] = $this->getCurrency();
$query_string = http_build_query($query);
return "https://". ($this->isSandbox() ? 'sandbox' : 'www' ) .".paypal.com/cgi-bin/webscr?".$query_string;
}
我也试过下面的代码,但是当我点击完成付款时,它会返回带有令牌和payer_id的返回URL,但不要付款:C
public function checkout()
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://api-m.paypal.com/v2/checkout/orders');
curl_setopt($curl, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: ' . $this->getAccessToken(),
'Prefer: return=representation'
]);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode([
'brand_name' => 'yStore Plugins',
'intent' => 'CAPTURE',
'purchase_units' => $this->getItems(),
'application_context' => [
'notify_url' => $this->getNotificationURL(),
'cancel_url' => $this->getCancelURL(),
'return_url' => $this->getReturnURL()
]
]));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = json_decode(curl_exec($curl));
curl_close($curl);
return $response->links[1]->href;
}
【问题讨论】: