Laravel PUT方法不起作用

时间:2017-06-20 14:33:05

标签: php json api chargify

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

  • 参考文献1:关于changing the billing date的官方文档。
  • 参考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();
}

1 个答案:

答案 0 :(得分:0)

更改此内容:

echo $response->getBody();

dd($response->getBody());

并重新发布响应数据。