サブスクリプションコントローラーに、サブスクリプションの保留中のステータスをchargifyから削除するパブリック関数があります。
ドキュメントによると、pecl/http1 メソッドを使用するコードは次のようになります。
$request = new HttpRequest();
$request->setUrl('https://subdomain.chargify.com/subscriptions/$subscriptionId/delayed_cancel.json');
$request->setMethod(HTTP_METH_DELETE);
$request->setHeaders(array(
'authorization' => 'Basic YXBpLWtleTp4'
));
$request->setBody('{}');
try {
$response = $request->send();
echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}
したがって、このコードを関数内に配置します
public function changeYearlySubscriptionBillingDate(Request $request)
{
$chargify = new \Crucial\Service\Chargify([
'hostname' => env('CHARGIFY_HOSTNAME'),
'api_key' => env('CHARGIFY_KEY'),
'shared_key' => env('CHARGIFY_SHARED_KEY')
]);
$subscription = $chargify->subscription();
$user = $request->user();
$subscriptionId = $user->subscription->subscription_id;
$nextBilling = Carbon::now()->addYear();
$hostname = env('CHARGIFY_HOSTNAME');
$config = [
'headers' => [
'authorization' => 'Basic YXBpLWtleTp4',
'content-type' => 'application/json'
]
];
$client = new Client($config);
$res = $client->put("https://$hostname/subscriptions/$subscriptionId/.json",
["json" => [
[ "subscription" =>
[ "next_billing_at" => $nextBilling ]
]
]]);
echo $res->getBody();
}
私は Laravel を初めて使用し、このドキュメントは一般的に PHP 向けであるため、Laravel フレームワーク内でこのコードをどのように変換すればよいかわかりません。
参照:
エラーメッセージ:
Client error: `PUT https://(the hostname)/subscriptions/(the id)/.json` `resulted in a `404 Not Found` response:`
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>404 File Not Found</title>
<style>
b (truncated...)
参考2:公式ドキュメント
https://reference.chargify.com/v1/subscriptions/update-subscription-calendar-billing-day-change