Reputation: 67
updated - I am trying to use the API documentation to change the billing date using the PUT method in Http and Guzzle in Laravel, however, the JSON file would return but it will not change the billing date at all.
Reference2: their sample code in detail (sorry about the bad formatting):
<?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;
}
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");
echo $res->getBody();
}
Upvotes: 1
Views: 1167
Reputation: 361
Changes this:
echo $response->getBody();
to
dd($response->getBody());
and repost the response data is returned.
Upvotes: 0