Neteller REST Api 示例 PHP
Neteller REST Api example with PHP
请与 Neteller Rest 分享用于接收付款的代码 API。
我可以设法从 Oauth2 获取 accessToken,但我的其余调用 return 出现错误 400,请求错误。
以下是我使用 Guzzle 获取 accessToken 的方法:
$request = $client->post('https://test.api.neteller.com/v1/oauth2/token', [
'headers' => ['Authorization' => 'Basic ' . base64_encode($client_id . ':' . $client_secret)],
'body' => ['grant_type' => 'client_credentials'],
'allow_redirects' => false
]);
$response = $request->json();
$accessToken = $response['accessToken'];
但是下面的代码给我错误:
$request = $client->post('https://test.api.neteller.com/v1/transferIn', [
'headers' => [
'Authorization' => 'Bearer ' . $accessToken,
'Content-Type' => 'application/json'
],
'body' => [
'paymentMethod' => [
'type' => 'neteller',
'value' => 'netellertest_eur@neteller.com'
],
'transaction' => [
'merchantRefId' => 'P54bd91375d4fe',
'amount' => '5000',
'currency' => 'USD'
],
'verificationCode' => '234124'
]
]);
我做错了什么?如果您有用于接收付款的代码,请分享一个代码。
干杯,
阿尔
您似乎在尝试发送 body 中的 post 字段,而不是 API 期望的 JSON。作为一个相当原始的例子,更接近于此的东西应该可以工作:
$request = $client->post('https://test.api.neteller.com/v1/transferIn', [
'headers' => [
'Authorization' => 'Bearer ' . $accessToken,
'Content-Type' => 'application/json'
],
'body' => '{
"paymentMethod": {
"type": "neteller",
"value": "netellertest_eur@neteller.com"
},
"transaction": {
"merchantRefId": "P54bd91375d4fe",
"amount": 5000,
"currency": "USD"
},
"verificationCode": "234124"
}'
]);
一旦您准备好将代码集成到您的应用程序中,您自然会希望使用 json_encode
之类的东西来构建您的 body。
请与 Neteller Rest 分享用于接收付款的代码 API。
我可以设法从 Oauth2 获取 accessToken,但我的其余调用 return 出现错误 400,请求错误。
以下是我使用 Guzzle 获取 accessToken 的方法:
$request = $client->post('https://test.api.neteller.com/v1/oauth2/token', [
'headers' => ['Authorization' => 'Basic ' . base64_encode($client_id . ':' . $client_secret)],
'body' => ['grant_type' => 'client_credentials'],
'allow_redirects' => false
]);
$response = $request->json();
$accessToken = $response['accessToken'];
但是下面的代码给我错误:
$request = $client->post('https://test.api.neteller.com/v1/transferIn', [
'headers' => [
'Authorization' => 'Bearer ' . $accessToken,
'Content-Type' => 'application/json'
],
'body' => [
'paymentMethod' => [
'type' => 'neteller',
'value' => 'netellertest_eur@neteller.com'
],
'transaction' => [
'merchantRefId' => 'P54bd91375d4fe',
'amount' => '5000',
'currency' => 'USD'
],
'verificationCode' => '234124'
]
]);
我做错了什么?如果您有用于接收付款的代码,请分享一个代码。
干杯, 阿尔
您似乎在尝试发送 body 中的 post 字段,而不是 API 期望的 JSON。作为一个相当原始的例子,更接近于此的东西应该可以工作:
$request = $client->post('https://test.api.neteller.com/v1/transferIn', [
'headers' => [
'Authorization' => 'Bearer ' . $accessToken,
'Content-Type' => 'application/json'
],
'body' => '{
"paymentMethod": {
"type": "neteller",
"value": "netellertest_eur@neteller.com"
},
"transaction": {
"merchantRefId": "P54bd91375d4fe",
"amount": 5000,
"currency": "USD"
},
"verificationCode": "234124"
}'
]);
一旦您准备好将代码集成到您的应用程序中,您自然会希望使用 json_encode
之类的东西来构建您的 body。