首页 > 解决方案 > API函数OctoberCMS / Laravel

问题描述

各位下午。我正在尝试使用 VATLayer 来验证增值税号。

我有一个Organisation有字段 的模型company_vat

我可以检查增值税号是否有效,如果有效,则返回成功消息。这看起来对吗?

我正在使用十月CMS。

public function onVatValidation()
{
    $organisation = Organisation::find($this->param('id'));

    // set API Endpoint and Access Key
    $endpoint = 'validate';
    $access_key = 'xxxxxxxxxxxxxxx';

    // set VAT number
    $vat_number = $organisation->company_vat;

    // Initialize CURL:
    $ch = curl_init('http://apilayer.net/api/'.$endpoint.'?access_key='.$access_key.'&vat_number='.$vat_number.'');  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // Store the data:
    $json = curl_exec($ch);
    curl_close($ch);

    // Decode JSON response:
    $validationResult = json_decode($json, true);

    // Access and use your preferred validation result objects
    $validationResult['valid'];
    $validationResult['query'];
    $validationResult['company_name'];
    $validationResult['company_address'];

    Flash::success($organisation->name." has a valid VAT number.");

    return Redirect::refresh();
}

标签: phplaravelapioctobercms

解决方案


推荐阅读