Created
August 8, 2017 01:25
-
-
Save andrekutianski/da957f6b9009bcd47438945acf13f098 to your computer and use it in GitHub Desktop.
Função para o WHMCS Cadastrar o cliente na Iugu com os dados disponíveis no WHMCS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Cadastra o cliente na Iugu com os dados disponíveis no WHMCS | |
function iugu_boleto_add_client( $params ){ | |
// busco o campo personalizado referente ao documento do cliente configurado no modulo | |
$campoDoc = $params['cpf_cnpj_field']; | |
try{ | |
Iugu::setApiKey($params['api_token']); | |
$iuguCustomer = Iugu_Customer::create(Array( | |
"email" => $params['clientdetails']['email'], | |
"name" => $params['clientdetails']['fullname'], | |
"notes" => "Cliente cadastrado através do WHMCS", | |
"cpf_cnpj" => $params['clientdetails'][$campoDoc], | |
"zip_code" => $params['clientdetails']['postcode'], | |
"number" => "000", | |
"custom_variables" => Array( | |
Array( | |
"name" => "whmcs_user_id", | |
"value" => $params['clientdetails']['userid'] | |
)) | |
)); | |
// print_r($params); | |
if(!is_null($iuguCustomer->id)){ | |
// Insere na tabela mod_iugu_customers o Código do cliente Iugu | |
Capsule::table('mod_iugu_customers')->insert( | |
[ | |
'user_id' => $params['clientdetails']['userid'], | |
'iugu_id' => $iuguCustomer->id | |
] | |
); | |
} | |
logModuleCall("Iugu Boleto", "Criar Cliente", $params, json_decode($iuguCustomer, true)); | |
// retorna o ID do cliente na Iugu para gerar o boleto associado ao cliente em questão | |
return $iuguCustomer->id; | |
}catch (\Exception $e){ | |
//logModuleCall("Iugu Cartao","Buscar Cliente",$userid,$iuguUserId); | |
echo "Problemas em cadastrar o cliente na Iugu. {$e->getMessage()}"; | |
} | |
} | |
// Busca na tabela mod_iugu_customers se já existe o cliente cadastrado | |
function iugu_boleto_search_client( $user ) { | |
try{ | |
// procura no banco | |
$iuguUserId = Capsule::table('mod_iugu_customers')->where('user_id', $user)->value('iugu_id'); | |
// loga a ação para debug | |
logModuleCall("Iugu Boleto","Buscar Cliente",$user,$iuguUserId); | |
// retorna o ID do cliente | |
return $iuguUserId; | |
}catch (\Exception $e){ | |
//logModuleCall("Iugu Cartao","Buscar Cliente",$userid,$iuguUserId); | |
echo "Problemas em localizar o cliente no banco de dados local. {$e->getMessage()}"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment