1

更新 - 我正在尝试使用 API 文档在 Laravel 的 Http 和 Guzzle 中使用 PUT 方法更改计费日期,但是,JSON 文件会返回,但它根本不会更改计费日期。

  • 参考1:关于更改计费日期的官方文档。
  • 参考2:他们的示例代码详细(抱歉格式错误):

    <?php
    
    $request = new HttpRequest();
    $request->setUrl('https://subdomain.chargify.com/subscriptions/subscriptionId.json');
    $request->setMethod(HTTP_METH_PUT);
    
    $request->setHeaders(array('content-type' => 'application/json'));
    
    $request->setBody('{"subscription":{"next_billing_at":"2018-12-15"}}');
    
    try {
          $response = $request->send();
    
          echo $response->getBody();
     } catch (HttpException $ex) {
          echo $ex;
     }
    

我的代码详细:

public function changeYearlySubscriptionBillingDate(Request $request)
{
    $user = $request->user();
    $subscriptionId = $user->subscription->subscription_id;
    $nextBilling = Carbon::now()->addYear();
    $hostname = env('CHARGIFY_HOSTNAME');

    $headers = [
        'authorization' => 'Basic ANIDIANDIAJIJCQ',
        'content-type' => 'application/json'
    ];

    $body = ["subscription" => ["next_billing_at" =>[ $nextBilling ]]];

    $config = [
        'headers' => $headers,
        'form_param' => $body
    ];

    $client = new Client($config);

    $res = $client->put("https://$hostname/subscriptions/$subscriptionId.json");

    echo $res->getBody();
}
4

1 回答 1

0

改变这个:

echo $response->getBody();

dd($response->getBody());

并重新发布返回响应数据。

于 2017-06-20T15:56:44.640 回答