2017-06-18 9 views
0
  • updated - JSONファイルは返されますが、請求日はまったく変更されません。(更新済み)Laravel PUTメソッドが動作しません

  • 参考文献1changing the billing dateに関する公式ドキュメント。

  • 参考2:詳細にそのサンプルコード:

    <?php 
    
    $request = new HttpRequest(); 
    $request->setUrl('https://domain.chargify.com/subscriptions/$subscriptionId.json'); 
    $request->setMethod(HTTP_METH_PUT); 
    
    $request->setHeaders(array(
        'authorization' => 'Basic YXBpa2V5Og==', 
        'content-type' => 'application/json' 
    )); 
    
    $request->setBody('{"subscription":{"next_billing_at":"2028-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", 
    ["json" => [ 
    [ "subscription" => 
     [ "next_billing_at" => $nextBilling ] 
    ] 
] 
]); 

    echo $res->getBody(); 
} 
+1

は... – perror

答えて

0

皆さんありがとうございました。

私は2日間、この問題に取り組んできた、それは私に右になるはずでした。最終的に、私を惑わしたAPIです。

私たちがしなければならない唯一のことは、単に

'body' => "{\"subscription\":{\"next_billing_at\":\"$nextBilling\"}}" 

を変更され、いくつかの '\' sの内部を追加しました。私を助けるため

みんなありがとう、良い一日を過ごします!私の最善をしようとし

1

あなたが構築しているURLが正しくありません。

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

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

にEDITはこのように呼んでがつがつ食う作るためにロジックを変更してみてください/

$subscription間と.jsonの変更があってはなりません。

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

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

$client = new Client(); 

$res = $client->put("https://$hostname/subscriptions/$subscriptionId.json", 
    [ 
     'headers' => $headers, 
     'body' => json_encode($body) 
    ] 
); 

echo $res->getBody()->getContents(); 
+0

は、Uに感謝し、私は今、単に(これはJSONファイルを返しますが、すべてのサブスクリプションの日付を変更しなかった)働いていない、質問を更新しました。あなたは私を探すことができますか?私は戻ってJSONファイルを得たものの、 – zhiyu

+0

残念ながら私の更新の答え – ayip

+0

を試し、請求日はまだ同じです。 JSONが私たちに送り返されて以来、それは "身体"の問題かもしれません、私はちょうど方法を言うことができません。 – zhiyu

関連する問題