2017-06-20 9 views
1

が更新されました - APIドキュメントを使用してLaravelのHttpとGuzzleのPUTメソッドを使用して請求日を変更しようとしていますが、JSONファイルは返されますが、すべて。Laravel PUTメソッドが動作しない

  • 参考資料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(); 
} 
+0

'' next_billing_at "=> [$ nextBilling]'の '[$ nextBilling]'は、あなたのコードの配列であるはずですか?例のようには見えません: '' next_billing_at ":" 2018-12-15 "' – Hollings

+0

元は配列ではありません。 '' {"subscription":{"next_billing_at": "2018年12月15日"}} ''、私はあまりにもその方法を試みたが、まだこれまで働いていない。 – zhiyu

+0

私が気付いたもう一つの事は、Carbonの日付を '$ nextBilling-> toDateString()'でフォーマットしなければならないかもしれないということです。それはカーボン日付オブジェクトからYYYY-MM-DD文字列形式に変換されます – Hollings

答えて

0

変更この:

echo $response->getBody(); 

dd($response->getBody()); 

応答データが返されます。

+0

'ストリーム{#726▼ -stream: "PHP" のstream_type: "TEMP" モード: "W + B" unread_bytes:0 シーク:真 URI:「PHP:11▼ wrapper_type @ストリームリソース// TEMP」 オプション:[]} -size:ヌル -seekable:真 可読:真 -writable:真 -uri: "PHP:// TEMP" -customMetadata:[] } ' – zhiyu

+0

' dd($ res-> getBody());を試してください。 – Hollings

+0

私は 'dd($ res-> getBody());'を使いました。これは上記と同じです。 :) – zhiyu

関連する問題