更新 - 我正在尝试使用API文档在Http和Guzzle in Laravel中使用PUT方法更改开票日期,但是,JSON文件将返回,但它根本不会更改开票日期。
参考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();
}
答案 0 :(得分:0)
更改此内容:
echo $response->getBody();
到
dd($response->getBody());
并重新发布响应数据。