【发布时间】:2021-08-01 15:23:15
【问题描述】:
我尝试按照:https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_create实现支付宝订阅服务
这是我的第一次尝试。
在沙盒业务帐户中,我创建了两个测试订阅:每月和每年,并使用其 ID 配置应用程序。
这是方法:
public function createSubscription($planSlug, $name, $email) {
return $this->makeRequest(
'POST',
'v1/billing/subscriptions',
[],
[
'plan_id' => $this->plans[$planSlug],
'subscriber' => [
'name' => [
'given_name' => $name,
],
'email_address' => $email
],
'application_context'=> [
'brand_name' => config('app.name'),
'shipping_preference' => 'NO_SHIPPING',
'user_action' => 'SUBSCRIBE_NOW',
'return_url' => route('subscribe.approval', ['plan' => $planSlug]),
'cancel_url'=> route('subscribe.cancelled')
],
],
[],
$isJsonRequest = true
);
}
但是,当我调用 API 以创建测试订阅时,我收到奇怪的响应,即“名称”参数的格式不正确:
php artisan tinker
>>> $paypal = resolve(App\Services\PaypalService::class);
=> App\Services\PaypalService {#3413}
>>> $paypal->createSubscription('monthly', 'Test', 'test@test.com');
GuzzleHttp\Exception\ClientException with message 'Client error: `POST https://api-
m.sandbox.paypal.com/v1/billing/subscriptions` resulted in a `400 Bad Request` response:
{"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect, or
violates schema.","debug_id (truncated...)
这很奇怪,因为在 Paypal API 文档(见上文)中,'name' 参数的描述完全一样!
我错过了什么,或者是 Paypal API 表现得很时髦?
【问题讨论】:
-
最近我正在测试他们的按钮,但他们出现了故障。他们首先未经客户同意就向客户收费。他们的订阅也是我处理过的另一个问题,他们的 webhook 是另外一回事。你应该再试一次。