updated - the JSON file would return but it will not change the billing date at all.
Reference 1: The official documentation about changing the billing date.
-
Reference2: their sample code in detail:
<?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; }
My code in detail:
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();
}