が更新されました - 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();
}
'' next_billing_at "=> [$ nextBilling]'の '[$ nextBilling]'は、あなたのコードの配列であるはずですか?例のようには見えません: '' next_billing_at ":" 2018-12-15 "' – Hollings
元は配列ではありません。 '' {"subscription":{"next_billing_at": "2018年12月15日"}} ''、私はあまりにもその方法を試みたが、まだこれまで働いていない。 – zhiyu
私が気付いたもう一つの事は、Carbonの日付を '$ nextBilling-> toDateString()'でフォーマットしなければならないかもしれないということです。それはカーボン日付オブジェクトからYYYY-MM-DD文字列形式に変換されます – Hollings