Paypal - Capture Order - TypeError: strtolower(): Argument #1 ($string) must be of type string, int given
Paypal - Capture Order - TypeError: strtolower(): Argument #1 ($string) must be of type string, int given
我想在我的网站上使用 PayPal 作为付款方式。我正在使用 Laravel 框架和 GuzzleHttp 包。创建订单运行顺利。尝试使用 id 捕获订单时出现问题。
php artisan tinker
>>> $paypal = new App\Services\PayPalService;
=> App\Services\PayPalService {#3447}
>>> $paypal->createOrder(500.00, 'EUR');
=> {#3478
+"id": "3NK71944KB9544808",
+"status": "CREATED",
+"links": [
{#3476
+"href": "https://api.sandbox.paypal.com/v2/checkout/orders/3NK71944KB9544808",
+"rel": "self",
+"method": "GET",
},
{#3461
+"href": "https://www.sandbox.paypal.com/checkoutnow?token=3NK71944KB9544808",
+"rel": "approve",
+"method": "GET",
},
{#3472
+"href": "https://api.sandbox.paypal.com/v2/checkout/orders/3NK71944KB9544808",
+"rel": "update",
+"method": "PATCH",
},
{#3465
+"href": "https://api.sandbox.paypal.com/v2/checkout/orders/3NK71944KB9544808/capture",
+"rel": "capture",
+"method": "POST",
},
],
}
>>> $paypal->capture("3NK71944KB9544808");
TypeError: strtolower(): Argument #1 ($string) must be of type string, int given
消费API码:
public function makeRequest($method, $requestURL, $queryParams = [], $formParams = [], $headers = [], $isJSONRequest = false)
{
$client = new Client([
'base_uri' => $this->baseUri,
]);
if (method_exists($this, 'resolveAuthorization')) {
$this->resolveAuthorization($queryParams, $formParams, $headers);
}
$response = $client->request($method, $requestURL, [
$isJSONRequest ? 'json' : 'form_params' => $formParams,
'headers' => $headers,
'query' => $queryParams,
]);
if (method_exists($this, 'decodeResponse')) {
return $this->decodeResponse($response->getBody()->getContents());
}
return $response->getBody()->getContents();
}
正在获取订单代码:
public function captureOrder($id)
{
return $this->makeRequest('POST', "/v2/checkout/orders/$id/capture", [], [], [
"Content-Type: application/json",
]);
}
嗯,我切换到 PayPal HTTP 客户端,它工作得很好。
我想在我的网站上使用 PayPal 作为付款方式。我正在使用 Laravel 框架和 GuzzleHttp 包。创建订单运行顺利。尝试使用 id 捕获订单时出现问题。
php artisan tinker
>>> $paypal = new App\Services\PayPalService;
=> App\Services\PayPalService {#3447}
>>> $paypal->createOrder(500.00, 'EUR');
=> {#3478
+"id": "3NK71944KB9544808",
+"status": "CREATED",
+"links": [
{#3476
+"href": "https://api.sandbox.paypal.com/v2/checkout/orders/3NK71944KB9544808",
+"rel": "self",
+"method": "GET",
},
{#3461
+"href": "https://www.sandbox.paypal.com/checkoutnow?token=3NK71944KB9544808",
+"rel": "approve",
+"method": "GET",
},
{#3472
+"href": "https://api.sandbox.paypal.com/v2/checkout/orders/3NK71944KB9544808",
+"rel": "update",
+"method": "PATCH",
},
{#3465
+"href": "https://api.sandbox.paypal.com/v2/checkout/orders/3NK71944KB9544808/capture",
+"rel": "capture",
+"method": "POST",
},
],
}
>>> $paypal->capture("3NK71944KB9544808");
TypeError: strtolower(): Argument #1 ($string) must be of type string, int given
消费API码:
public function makeRequest($method, $requestURL, $queryParams = [], $formParams = [], $headers = [], $isJSONRequest = false)
{
$client = new Client([
'base_uri' => $this->baseUri,
]);
if (method_exists($this, 'resolveAuthorization')) {
$this->resolveAuthorization($queryParams, $formParams, $headers);
}
$response = $client->request($method, $requestURL, [
$isJSONRequest ? 'json' : 'form_params' => $formParams,
'headers' => $headers,
'query' => $queryParams,
]);
if (method_exists($this, 'decodeResponse')) {
return $this->decodeResponse($response->getBody()->getContents());
}
return $response->getBody()->getContents();
}
正在获取订单代码:
public function captureOrder($id)
{
return $this->makeRequest('POST', "/v2/checkout/orders/$id/capture", [], [], [
"Content-Type: application/json",
]);
}
嗯,我切换到 PayPal HTTP 客户端,它工作得很好。