inital commit
This commit is contained in:
101
app/Services/ClientService.php
Normal file
101
app/Services/ClientService.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Permission;
|
||||
use App\Models\User;
|
||||
|
||||
class ClientService
|
||||
{
|
||||
public function getUsers($inputData)
|
||||
{
|
||||
return (new User())->getClients($inputData);
|
||||
}
|
||||
public function getUserInfoById($id)
|
||||
{
|
||||
$result = ['status'=>false,'data'=>[]];
|
||||
if ($user = User::where(['id'=>$id])->first()) {
|
||||
$result = ['status'=>true,'data'=>$user];
|
||||
}
|
||||
return $result;
|
||||
|
||||
}
|
||||
public function updateUserInfoById($inputData)
|
||||
{
|
||||
$result = null;
|
||||
if ($user = User::where('id',$inputData['id'])->first()) {
|
||||
$currentWave = $user['wave'];
|
||||
$maxWave=config('constant.MAX_WAVE');
|
||||
$currentWave = ($currentWave<$maxWave)? ($currentWave+1) : $maxWave;
|
||||
$packedData = $this->userDataPacking($inputData);
|
||||
if(!empty($inputData['reset_account'])){
|
||||
$packedData['subscription_status'] = 1;
|
||||
$packedData['wave'] = $currentWave;
|
||||
$packedData['last_payment_date'] = addDays($inputData['reset_account'],$user->last_payment_date);
|
||||
}
|
||||
|
||||
$user->update($packedData);
|
||||
$result = $user;
|
||||
}
|
||||
return $result;
|
||||
|
||||
}
|
||||
private function userDataPacking($inputData)
|
||||
{
|
||||
$outputData=[];
|
||||
|
||||
$outputData['first_name'] = $inputData['first_name'];
|
||||
$outputData['last_name'] = $inputData['last_name'];
|
||||
|
||||
$outputData['state'] = $inputData['state'];
|
||||
$outputData['phone'] = $inputData['phone'];
|
||||
$outputData['password'] = customEncrypt($inputData['password']);
|
||||
$outputData['street_no'] = $inputData['street_no'];
|
||||
$outputData['street_name'] = $inputData['street_name'];
|
||||
$outputData['city'] = $inputData['city'];
|
||||
$outputData['zip_code'] = $inputData['zip_code'];
|
||||
$outputData['credit_report_company_type'] = $inputData['credit_report_company_type'];
|
||||
|
||||
$status = $inputData['status'];
|
||||
if(!empty($inputData['email']))
|
||||
{
|
||||
$outputData['email'] = $inputData['email'];
|
||||
}
|
||||
if($inputData['status'] == 3)
|
||||
{
|
||||
$status = 1;
|
||||
$outputData['subscription_status'] = 2;
|
||||
$outputData['account_cancel_datetime'] = getCurrentDate();
|
||||
}
|
||||
if(!empty($inputData['user_access_date']))
|
||||
{
|
||||
$outputData['user_access_end_date'] = $inputData['user_access_date'];
|
||||
}
|
||||
if(!empty($inputData['birth_date']))
|
||||
{
|
||||
$outputData['birth_date'] = $inputData['birth_date'];
|
||||
}
|
||||
if(!empty($inputData['ssn']))
|
||||
{
|
||||
$outputData['ssn'] = $inputData['ssn'];
|
||||
}
|
||||
if(!empty($inputData['last_payment_date']))
|
||||
{
|
||||
$outputData['last_payment_date'] = $inputData['last_payment_date'];
|
||||
}
|
||||
if(!empty($inputData['subscription_status']))
|
||||
{
|
||||
$outputData['subscription_status'] = $inputData['subscription_status'];
|
||||
}
|
||||
if(!empty($inputData['wave'])){
|
||||
$outputData['wave'] = $inputData['wave'];
|
||||
}
|
||||
if(!empty($inputData['last_import_date'])){
|
||||
$outputData['last_import_date'] = $inputData['last_import_date'];
|
||||
}
|
||||
|
||||
$outputData['status'] = $status;
|
||||
return $outputData;
|
||||
}
|
||||
|
||||
}
|
||||
314
app/Services/CreditReportService.php
Normal file
314
app/Services/CreditReportService.php
Normal file
@@ -0,0 +1,314 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Creditreport;
|
||||
use App\Utility\CurlRequest;
|
||||
use App\Models\IqCallHistory;
|
||||
use App\Utility\Email;
|
||||
use function PHPUnit\Framework\isEmpty;
|
||||
|
||||
class CreditReportService
|
||||
{
|
||||
|
||||
const HTML_SCRAPPER_API_DOMAIN = "https://readytogoletters.com:8080";
|
||||
// const HTML_SCRAPPER_API_DOMAIN = "https://test.readytogoletters.com:8080";
|
||||
// const HTML_SCRAPPER_API_DOMAIN = "http://localhost:5000";
|
||||
|
||||
public $identity_iq_html_url = self::HTML_SCRAPPER_API_DOMAIN."/identity-iq-credit-report-html";
|
||||
public $identity_iq_refresh_date_url = self::HTML_SCRAPPER_API_DOMAIN."/identity-iq-report-refresh-date"; // For Import button hit request for getting popup
|
||||
public $identity_iq_refresh_button_url = self::HTML_SCRAPPER_API_DOMAIN."/identity-iq-click-refresh-btn";
|
||||
public $smart_credit_refresh_button_url = self::HTML_SCRAPPER_API_DOMAIN."/smart-credit-credit-click-refresh-btn";
|
||||
public $SMART_CREDIT_HTML_URL = self::HTML_SCRAPPER_API_DOMAIN."/smart-credit-credit-report-3b";
|
||||
public $smart_credit_refresh_date_url = self::HTML_SCRAPPER_API_DOMAIN."/smart-credit-credit-refresh-status";
|
||||
public $SMART_CREDIT_JSON_URL = self::HTML_SCRAPPER_API_DOMAIN."/smart-credit-credit-report-3b-json";
|
||||
public $ip = "45.55.43.211:8080";
|
||||
|
||||
|
||||
public function getIdentityRefreshButtonContent($username, $password,$ssn) {
|
||||
$result['status'] = false;
|
||||
$result['message'] = 'api problem.';
|
||||
$credentials['email'] = $username;
|
||||
$credentials['password'] = $password;
|
||||
$credentials['ssn'] = $ssn;
|
||||
$status = 0;
|
||||
$params = json_encode($credentials);
|
||||
$URL = $this->identity_iq_refresh_button_url;
|
||||
$curlRequest = new CurlRequest();
|
||||
|
||||
$response = $curlRequest->makeCurlRequest($params,'POST',$URL);
|
||||
$response = json_decode($response,true);
|
||||
|
||||
if (!empty($response) && $response['status_code'] == 200) {
|
||||
$status = 1;
|
||||
$result['status'] = true;
|
||||
$result['message'] = $response['data'];
|
||||
}
|
||||
if(isset($response['ip']) && !empty($response["ip"])){
|
||||
$this->ip = $response['ip'];
|
||||
}
|
||||
$ip_explode = explode(":", $this->ip );
|
||||
(new IqCallHistory())->insertHistory($ip_explode[0],$ip_explode[1],$response['page'],$response['page_code'],$status);
|
||||
return $result;
|
||||
}
|
||||
public function getIdentityIQHTML($username, $password,$ssn) {
|
||||
$logData['action'] = "GET_IDENTITY_IQ_HTML";
|
||||
|
||||
$result['status'] = false;
|
||||
$result['html'] = "";
|
||||
$result['message'] = '';
|
||||
|
||||
$credentials['email'] = $username;
|
||||
$credentials['password'] = $password;
|
||||
$credentials['ssn'] = $ssn;
|
||||
$status = 0;
|
||||
try {
|
||||
$params = json_encode($credentials);
|
||||
$URL = $this->identity_iq_html_url;
|
||||
|
||||
$curlRequest = new CurlRequest();
|
||||
|
||||
$response = $curlRequest->makeCurlRequest($params,'POST', $URL);
|
||||
$response = json_decode($response,true);
|
||||
|
||||
// if ($response['data'] == "ERROR" || $response['data'] == "TIME_OUT" || $response['data'] == "INVALID_LOGIN" || $response['data'] == 'ACCOUNT_LOCKED' ) {
|
||||
if (!empty($response) && $response['status_code'] == 200){
|
||||
$status = 1;
|
||||
$result['status'] = true;
|
||||
$result['html'] = $response['data'];
|
||||
$result['message'] = 'User is valid.';
|
||||
}else{
|
||||
$result['status_code'] = $response['status_code'];
|
||||
$result['message'] = config('constant.SCRAPPER_RESPONSE'.'.'.$response['data']);
|
||||
$response['page_code'] = $response['page_code']??"403";
|
||||
throw new \Exception(config('constant.SCRAPPER_RESPONSE'.$response['data']));
|
||||
}
|
||||
|
||||
/*
|
||||
if ($response == "ERROR" || $response == "TIME_OUT" || $response == "INVALID_LOGIN" || $response == "ACCOUNT_LOCKED") {
|
||||
|
||||
$result['message'] = config('constant.SCRAPPER_RESPONSE'.'.'.$response);
|
||||
throw new \Exception(config('constant.SCRAPPER_RESPONSE'.$response));
|
||||
}
|
||||
|
||||
if (!empty($response) ) {
|
||||
$result['status'] = true;
|
||||
$result['html'] = $response['data'];
|
||||
$result['message'] = 'User is valid.';
|
||||
}
|
||||
*/
|
||||
|
||||
$logData['user_info'] = $credentials['email'];
|
||||
$logData['status'] = $result['status'];
|
||||
|
||||
}catch (\Exception $ex){
|
||||
$logData['data']['response'] = $response;
|
||||
$logData['data']['credentials'] = $credentials['email'];
|
||||
|
||||
}
|
||||
|
||||
if(isset($response['ip']) && !empty($response["ip"])){
|
||||
$this->ip = $response['ip'];
|
||||
}
|
||||
$ip_explode = explode(":", $this->ip );
|
||||
(new IqCallHistory())->insertHistory($ip_explode[0],$ip_explode[1],$response['page'],$response['page_code'],$status);
|
||||
appLog($logData);
|
||||
|
||||
return $result;
|
||||
}
|
||||
public function getIdentityIQRefreshDate($username, $password,$ssn) {
|
||||
|
||||
$credentials['email'] = $username;
|
||||
$credentials['password'] = $password;
|
||||
$credentials['ssn'] = $ssn;
|
||||
$status = 0;
|
||||
|
||||
$params = json_encode($credentials);
|
||||
$URL = $this->identity_iq_refresh_date_url;
|
||||
$curlRequest = new CurlRequest();
|
||||
$response = $curlRequest->makeCurlRequest($params,'POST',$URL);
|
||||
$response = json_decode($response,true);
|
||||
|
||||
// if ($response['data'] == "ERROR" || $response['data'] == "TIME_OUT" || $response['data'] == "INVALID_LOGIN" || $response['data'] == 'ACCOUNT_LOCKED' ) {
|
||||
|
||||
if(!empty($response) && $response['status_code'] == 200) {
|
||||
$status = 1;
|
||||
}
|
||||
if(isset($response['ip']) && !empty($response["ip"])){
|
||||
$this->ip = $response['ip'];
|
||||
}
|
||||
$ip_explode = explode(":", $this->ip );
|
||||
(new IqCallHistory())->insertHistory($ip_explode[0],$ip_explode[1],$response['page'],$response['page_code'],$status);
|
||||
|
||||
if ($response['status_code'] != 200){
|
||||
$status = 0;
|
||||
$result['refresh_date'] = 'ERROR';
|
||||
$result['message'] = config('constant.SCRAPPER_RESPONSE'.'.'.$response['data']) ;
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
public function getSmartCreditRefreshButtonContent($username, $password) {
|
||||
|
||||
$result['status'] = false;
|
||||
$result['message'] = 'api problem.';
|
||||
$credentials['email'] = $username;
|
||||
$credentials['password'] = $password;
|
||||
//$credentials['ssn'] = $ssn;
|
||||
|
||||
$params = json_encode($credentials);
|
||||
$URL = $this->smart_credit_refresh_button_url;
|
||||
$curlRequest = new CurlRequest();
|
||||
$response =$curlRequest->makeCurlRequest($params,'POST',$URL);
|
||||
|
||||
if (!empty($response)) {
|
||||
$result['status'] = true;
|
||||
$result['message'] = $response;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
public function getSmartCreditRefreshDate($username, $password,$ssn) {
|
||||
|
||||
$credentials['email'] = $username;
|
||||
$credentials['password'] = $password;
|
||||
//$credentials['ssn'] = $ssn;
|
||||
|
||||
$params = json_encode($credentials);
|
||||
$URL = $this->smart_credit_refresh_date_url;
|
||||
$curlRequest = new CurlRequest();
|
||||
$response = $curlRequest->makeCurlRequest($params,'POST',$URL);
|
||||
if ($response == "ERROR" || $response == "TIME_OUT" || $response == "INVALID_LOGIN" || $response == 'ACCOUNT_LOCKED' ) {
|
||||
$result['refresh_date'] = 'ERROR';
|
||||
$result['message'] = config('constant.SCRAPPER_RESPONSE'.'.'.$response) ;
|
||||
return $result;
|
||||
}
|
||||
return json_decode($response,true);
|
||||
}
|
||||
public function getSmartCreditHTML($username, $password) {
|
||||
|
||||
$result['status'] = false;
|
||||
$result['html'] = "";
|
||||
$result['message'] = '';
|
||||
$logData['action'] = "GET_SMART_CREDIT_HTML";
|
||||
try {
|
||||
$credentials['email'] = $username;
|
||||
$credentials['password'] = $password;
|
||||
|
||||
// $credentials['email'] = "stevetest@consumerdirect.com";
|
||||
// $credentials['password'] = "123456789";
|
||||
$params = json_encode($credentials);
|
||||
|
||||
$URL = $this->SMART_CREDIT_HTML_URL;
|
||||
|
||||
if(config('app.SMART_CREDIT_REPORT_BY_JSON') == '1') {
|
||||
|
||||
$URL = $this->SMART_CREDIT_JSON_URL;
|
||||
}
|
||||
|
||||
$curlRequest = new CurlRequest();
|
||||
|
||||
$response = $curlRequest->makeCurlRequest($params,'POST', $URL);
|
||||
|
||||
if ($response == "ERROR" || $response == "TIME_OUT" || $response == "INVALID_LOGIN" ) {
|
||||
$result['message'] = config('constant.SCRAPPER_RESPONSE'.'.'.$response);
|
||||
throw new \Exception('Report not found');
|
||||
}
|
||||
|
||||
if (!empty($response)) {
|
||||
$result['status'] = true;
|
||||
$result['html'] = $response;
|
||||
$result['message'] = 'User is valid.';
|
||||
}
|
||||
$logData['user_info'] = $credentials['email'];
|
||||
$logData['status'] = $result['status'];
|
||||
|
||||
}catch (\Exception $ex){
|
||||
$logData['data']['response'] = $response;
|
||||
$logData['data']['credentials'] = $credentials['email'];
|
||||
|
||||
}
|
||||
|
||||
appLog($logData);
|
||||
|
||||
return $result;
|
||||
}
|
||||
public static function getCreditReportContent($user_id,$file_name){
|
||||
if(empty($user_id) || empty($file_name)){
|
||||
return "";
|
||||
}
|
||||
$file_path = config('constant.CREDIT_REPORT_CONTENT_PATH').DIRECTORY_SEPARATOR.$user_id.DIRECTORY_SEPARATOR.$file_name ?? "";
|
||||
return getFile($file_path);
|
||||
}
|
||||
public function getUpdatedReport($user_id,$report_type,$ssn){
|
||||
$reportContent = [];
|
||||
|
||||
try {
|
||||
$creditReportDataObj = (new Creditreport())->getCreditReportInfoByUserIdAndType($user_id, $report_type);
|
||||
/*$creditReportDataObj->email = "stevetest@consumerdirect.com";*/
|
||||
|
||||
/*$reportContent = $this->getSmartCreditHTML("stevetest@consumerdirect.com", "123456789");
|
||||
$reportContent = $this->getIdentityIQHTML("faust_89@ukr.net", "Faust_4639672",'5150');
|
||||
$reportContent['status'] = true;*/
|
||||
if (!empty($creditReportDataObj)) {
|
||||
$creditReportDataObj->password = customDecrypt($creditReportDataObj->password);
|
||||
if($report_type == config('constant.reportType.SMART_CREDIT')) {
|
||||
$reportContent = $this->getSmartCreditHTML($creditReportDataObj->email, $creditReportDataObj->password);
|
||||
// $reportContent = $this->getSmartCreditHTML("stevetest@consumerdirect.com", "123456789");
|
||||
}else if($report_type == config('constant.reportType.IDENTITY_IQ')){
|
||||
$reportContent = $this->getIdentityIQHTML($creditReportDataObj->email, $creditReportDataObj->password,$ssn);
|
||||
// $reportContent = $this->getIdentityIQHTML("faust_89@ukr.net", "Faust_4639672",'5150');
|
||||
}
|
||||
$reportContent['credit_report_file_name'] = $creditReportDataObj->file_name ?? "";
|
||||
$reportContent['credit_report_user_obj']=$creditReportDataObj;
|
||||
}else{
|
||||
$reportContent['status'] = false;
|
||||
}
|
||||
}
|
||||
catch (\Exception $ex){
|
||||
|
||||
$reportContent['status'] = false;
|
||||
$reportContent['message'] = $ex->getMessage();
|
||||
|
||||
}
|
||||
|
||||
return $reportContent;
|
||||
}
|
||||
public function uploadCreditReport($inputData)
|
||||
{
|
||||
return (new Creditreport())->updateCreditReport($inputData);
|
||||
}
|
||||
public function validateUserInCreditReportProvider($inputData){
|
||||
$reportContent = [];
|
||||
try {
|
||||
if($inputData['source_type'] == config('constant.reportType.SMART_CREDIT')) {
|
||||
$reportContent = $this->getSmartCreditHTML($inputData['email'], $inputData['password']);
|
||||
// $reportContent = $this->getSmartCreditHTML("stevetest@consumerdirect.com", "123456789");
|
||||
}else if($inputData['source_type'] == config('constant.reportType.IDENTITY_IQ')){
|
||||
$reportContent = $this->getIdentityIQHTML($inputData['email'], $inputData['password'], $inputData['ssn']);
|
||||
// $reportContent = $this->getIdentityIQHTML("faust_89@ukr.net", "Faust_4639672",'5150');
|
||||
}
|
||||
|
||||
}
|
||||
catch (\Exception $ex){
|
||||
|
||||
$reportContent['status'] = false;
|
||||
$reportContent['message'] = $ex->getMessage();
|
||||
|
||||
}
|
||||
|
||||
return $reportContent;
|
||||
}
|
||||
|
||||
public function sampledata(){
|
||||
$data = [
|
||||
"button_type" => 1,
|
||||
"ip" => "206.206.124.81:6662",
|
||||
"page" => "Dashboard.aspx",
|
||||
"page_code" => 403,
|
||||
"data" => "ERROR",
|
||||
"status_code" => 408
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
16
app/Services/CustomContainer.php
Normal file
16
app/Services/CustomContainer.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
class CustomContainer
|
||||
{
|
||||
private static $resource;
|
||||
|
||||
public static function setContainer($key,$value){
|
||||
static::$resource[$key] = $value;
|
||||
}
|
||||
|
||||
public static function getContainer($key){
|
||||
return static::$resource[$key] ?? "";
|
||||
}
|
||||
}
|
||||
144
app/Services/Encryption.php
Normal file
144
app/Services/Encryption.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
class Encryption
|
||||
{
|
||||
private $pubkey = '';
|
||||
private $privkey = '';
|
||||
|
||||
//Block size for encryption block cipher
|
||||
private $ENCRYPT_BLOCK_SIZE = 200;// this for 2048 bit key for example, leaving some room
|
||||
|
||||
//Block size for decryption block cipher
|
||||
private $DECRYPT_BLOCK_SIZE = 256;// this again for 2048 bit key
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// $this->pubkey = file_get_contents(config('keys.public_key'));
|
||||
// $this->privkey = file_get_contents(config('keys.private_key'));
|
||||
}
|
||||
|
||||
public function encryptByPublicKey($plaintext)
|
||||
{
|
||||
$plaintext = gzcompress($plaintext);
|
||||
|
||||
// Get the public Key of the recipient
|
||||
$publicKey = openssl_pkey_get_public('file://' . config('keys.public_key'));
|
||||
$a_key = openssl_pkey_get_details($publicKey);
|
||||
|
||||
// Encrypt the data in small chunks and then combine and send it.
|
||||
$chunkSize = ceil($a_key['bits'] / 8) - 11;
|
||||
$output = '';
|
||||
|
||||
while ($plaintext) {
|
||||
$chunk = substr($plaintext, 0, $chunkSize);
|
||||
$plaintext = substr($plaintext, $chunkSize);
|
||||
$encrypted = '';
|
||||
if (!openssl_public_encrypt($chunk, $encrypted, $publicKey)) {
|
||||
die('Failed to encrypt data');
|
||||
}
|
||||
$output .= $encrypted;
|
||||
}
|
||||
openssl_free_key($publicKey);
|
||||
|
||||
// This is the final encrypted data to be sent to the recipient
|
||||
return bin2hex($output);
|
||||
}
|
||||
|
||||
public function decryptByPrivateKey($encrypted)
|
||||
{
|
||||
if (!$privateKey = openssl_pkey_get_private('file://' . config('keys.private_key'))) {
|
||||
die('Private Key failed');
|
||||
}
|
||||
$encrypted = hex2bin($encrypted);
|
||||
$a_key = openssl_pkey_get_details($privateKey);
|
||||
|
||||
// Decrypt the data in the small chunks
|
||||
$chunkSize = ceil($a_key['bits'] / 8);
|
||||
$output = '';
|
||||
|
||||
while ($encrypted) {
|
||||
$chunk = substr($encrypted, 0, $chunkSize);
|
||||
$encrypted = substr($encrypted, $chunkSize);
|
||||
$decrypted = '';
|
||||
if (!openssl_private_decrypt($chunk, $decrypted, $privateKey)) {
|
||||
die('Failed to decrypt data');
|
||||
}
|
||||
$output .= $decrypted;
|
||||
}
|
||||
openssl_free_key($privateKey);
|
||||
|
||||
// Uncompress the unencrypted data.
|
||||
return gzuncompress($output);
|
||||
}
|
||||
|
||||
|
||||
public function decryptByPublicKey($data)
|
||||
{
|
||||
$decrypted = '';
|
||||
|
||||
//decode must be done before spliting for getting the binary String
|
||||
$data = str_split(base64_decode($data), $this->DECRYPT_BLOCK_SIZE);
|
||||
|
||||
foreach ($data as $chunk) {
|
||||
$partial = '';
|
||||
|
||||
//be sure to match padding
|
||||
$decryptionOK = openssl_public_decrypt($chunk, $partial, $this->pubkey, OPENSSL_PKCS1_PADDING);
|
||||
|
||||
if ($decryptionOK === false) {
|
||||
return false;
|
||||
}//here also processed errors in decryption. If too big this will be false
|
||||
$decrypted .= $partial;
|
||||
}
|
||||
return $decrypted;
|
||||
}
|
||||
|
||||
public function encryptByPrivateKey($plainData)
|
||||
{
|
||||
$encrypted = '';
|
||||
$plainData = str_split($plainData, $this->ENCRYPT_BLOCK_SIZE);
|
||||
foreach ($plainData as $chunk) {
|
||||
$partialEncrypted = '';
|
||||
|
||||
//using for example OPENSSL_PKCS1_PADDING as padding
|
||||
$encryptionOk = openssl_private_encrypt($chunk, $partialEncrypted, $this->privkey, OPENSSL_PKCS1_PADDING);
|
||||
|
||||
if ($encryptionOk === false) {
|
||||
return false;
|
||||
}//also you can return and error. If too big this will be false
|
||||
$encrypted .= $partialEncrypted;
|
||||
}
|
||||
return base64_encode($encrypted);//encoding the whole binary String as MIME base 64
|
||||
}
|
||||
|
||||
|
||||
public function generateKeys()
|
||||
{
|
||||
if(!is_dir(storage_path("app/public/keys"))){
|
||||
mkdir(storage_path("app/public/keys"));
|
||||
}
|
||||
|
||||
$config = array(
|
||||
"config"=>storage_path("app/openssl.cnf"),
|
||||
"private_key_bits" => 2048,
|
||||
"private_key_type" => OPENSSL_KEYTYPE_RSA,
|
||||
);
|
||||
$privateKey = openssl_pkey_new($config);
|
||||
|
||||
// Save the private key to private.key file. Never share this file with anyone.
|
||||
//openssl_pkey_export_to_file($privateKey, storage_path("app/public/keys/oauth-private1.key"));
|
||||
// Get private key
|
||||
openssl_pkey_export($privateKey, $privKey,NULL,$config);
|
||||
file_put_contents(storage_path("app/public/keys/oauth-private.key"), $privKey);
|
||||
|
||||
// Generate the public key for the private key
|
||||
$a_key = openssl_pkey_get_details($privateKey);
|
||||
// Save the public key in public.key file. Send this file to anyone who want to send you the encrypted data.
|
||||
file_put_contents(storage_path("app/public/keys/oauth-public.key"), $a_key['key']);
|
||||
//uploadFile(config('keys.public_key'),'oauth-public.key', $a_key['key']);
|
||||
// Free the private Key.
|
||||
//dd(openssl_free_key($privateKey),$privateKey);
|
||||
}
|
||||
}
|
||||
32
app/Services/ManageFile.php
Normal file
32
app/Services/ManageFile.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ManageFile
|
||||
{
|
||||
const DISK = 'public';
|
||||
const RESOURCE_DIR = 'resources';
|
||||
|
||||
public function uploadFile($file_path,$file_name,$content){
|
||||
Storage::disk(self::DISK)->put(self::RESOURCE_DIR.DIRECTORY_SEPARATOR.$file_path.DIRECTORY_SEPARATOR.$file_name,$content);
|
||||
|
||||
}
|
||||
|
||||
public function uploadHTML($file_path,$file_name,$content){
|
||||
Storage::disk(self::DISK)->put(self::RESOURCE_DIR.DIRECTORY_SEPARATOR.$file_path.DIRECTORY_SEPARATOR.$file_name,$content);
|
||||
}
|
||||
|
||||
public function getFile($file_path): string
|
||||
{
|
||||
if (!Storage::disk(self::DISK)->exists(self::RESOURCE_DIR.DIRECTORY_SEPARATOR.$file_path)) {
|
||||
return "";
|
||||
}
|
||||
return Storage::disk(self::DISK)->get(self::RESOURCE_DIR.DIRECTORY_SEPARATOR.$file_path);
|
||||
}
|
||||
|
||||
public function deleteFile($file_path){
|
||||
return Storage::disk(self::DISK)->delete(self::RESOURCE_DIR.DIRECTORY_SEPARATOR.$file_path);
|
||||
}
|
||||
}
|
||||
148
app/Services/ManageLogging.php
Normal file
148
app/Services/ManageLogging.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ManageLogging {
|
||||
|
||||
public static function safe_json_encode($value, $options = 0, $depth = 512, $utfErrorFlag = false) {
|
||||
$encoded = json_encode($value, $options, $depth);
|
||||
switch (json_last_error()) {
|
||||
case JSON_ERROR_NONE:
|
||||
return $encoded;
|
||||
case JSON_ERROR_DEPTH:
|
||||
return 'Maximum stack depth exceeded'; // or trigger_error() or throw new Exception()
|
||||
case JSON_ERROR_STATE_MISMATCH:
|
||||
return 'Underflow or the modes mismatch'; // or trigger_error() or throw new Exception()
|
||||
case JSON_ERROR_CTRL_CHAR:
|
||||
return 'Unexpected control character found';
|
||||
case JSON_ERROR_SYNTAX:
|
||||
return 'Syntax error, malformed JSON'; // or trigger_error() or throw new Exception()
|
||||
case JSON_ERROR_UTF8:
|
||||
$clean = self::utf8ize($value);
|
||||
if ($utfErrorFlag) {
|
||||
return 'UTF8 encoding error'; // or trigger_error() or throw new Exception()
|
||||
}
|
||||
return self::safe_json_encode($clean, $options, $depth, true);
|
||||
default:
|
||||
return 'Unknown error'; // or trigger_error() or throw new Exception()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function createLog($data)
|
||||
{
|
||||
$status = true;
|
||||
|
||||
if(isset($data['card_number'])){
|
||||
$data['card_number'] = "XXXXXXX";
|
||||
}
|
||||
if(isset($data['expiry'])) {
|
||||
$data['expiry'] = "XXXXXXX";
|
||||
}
|
||||
|
||||
try {
|
||||
self::getCommonLogData($data);
|
||||
$json_data = self::safe_json_encode($data,JSON_UNESCAPED_UNICODE);
|
||||
Log::info($json_data);
|
||||
} catch (\Exception $e) {
|
||||
$status = false;
|
||||
}
|
||||
return $status;
|
||||
|
||||
}
|
||||
|
||||
public function getCommonLogData(&$logData)
|
||||
{
|
||||
$logData['date_time'] = getCurrentDateTime();
|
||||
$logData['auth_user_ip'] = self::getClientIpAddress();
|
||||
$logData['auth_user_agent'] = self::getUserAgentInfo();
|
||||
if (auth()->user()) {
|
||||
$logData['auth_email'] = auth()->user()->email;
|
||||
$logData['auth_id'] = auth()->user()->id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function getClientIpAddress(){
|
||||
$ipaddress = '';
|
||||
if (isset($_SERVER['HTTP_CLIENT_IP']))
|
||||
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
|
||||
else if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
|
||||
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||
else if (isset($_SERVER['HTTP_X_FORWARDED']))
|
||||
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
|
||||
else if (isset($_SERVER['HTTP_FORWARDED_FOR']))
|
||||
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
|
||||
else if (isset($_SERVER['HTTP_FORWARDED']))
|
||||
$ipaddress = $_SERVER['HTTP_FORWARDED'];
|
||||
else if (isset($_SERVER['REMOTE_ADDR']))
|
||||
$ipaddress = $_SERVER['REMOTE_ADDR'];
|
||||
else
|
||||
$ipaddress = 'UNKNOWN';
|
||||
|
||||
if (strlen($ipaddress) > 45){
|
||||
$ipaddress = substr($ipaddress, 0,45);
|
||||
}
|
||||
return $ipaddress;
|
||||
}
|
||||
|
||||
public static function getServerIpAddress()
|
||||
{
|
||||
$ip = '';
|
||||
|
||||
if (isset($_SERVER['HTTP_REFERER'])) {
|
||||
$addr = $_SERVER['HTTP_REFERER'];
|
||||
}elseif (isset($_SERVER['REMOTE_ADDR'])){
|
||||
$addr = $_SERVER['REMOTE_ADDR'];
|
||||
} else {
|
||||
$addr = url()->previous();
|
||||
|
||||
}
|
||||
|
||||
if (strlen($addr) > 2) {
|
||||
$subAddr = substr($addr, 0, 3);
|
||||
if ($subAddr == 'htt' || $subAddr == 'www') {
|
||||
$host = parse_url($addr, PHP_URL_HOST);
|
||||
$currentServerHost = parse_url(config('app.url'), PHP_URL_HOST);
|
||||
if ($host != $currentServerHost){
|
||||
$ip = gethostbyname($host);
|
||||
}
|
||||
|
||||
} else {
|
||||
$ip = $addr;
|
||||
}
|
||||
}
|
||||
// $this->fileWrite("otp.txt", $ip.$addr, config('app.IS_OTP_FILE_WRITE_ENABLE'));
|
||||
return $ip;
|
||||
}
|
||||
|
||||
|
||||
public static function getUserAgentInfo(){
|
||||
$maxlength = 80;
|
||||
$userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? strtolower($_SERVER['HTTP_USER_AGENT']) : '';
|
||||
if (strlen($userAgent) < 80) {
|
||||
$maxlength = strlen($userAgent);
|
||||
}
|
||||
|
||||
return substr($userAgent, 0, $maxlength);
|
||||
}
|
||||
|
||||
|
||||
public function nullRemovalMethod ($maybe_array, $replace_from, $replace_to)
|
||||
{
|
||||
if (!empty($maybe_array)) {
|
||||
if (is_array($maybe_array)) {
|
||||
foreach ($maybe_array as $key => $value) {
|
||||
$maybe_array[$key] = $this->nullRemovalMethod($value, $replace_from, $replace_to);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return is_null($maybe_array) ? '' : $maybe_array;
|
||||
}
|
||||
}
|
||||
32
app/Services/OpenSSLCryptoClass.php
Normal file
32
app/Services/OpenSSLCryptoClass.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
class OpenSSLCryptoClass
|
||||
{
|
||||
private string $secret_key = "6818f23eef19d38dad1d2729991f6368";
|
||||
private string $secret_iv = "0ac35e3823616c810f86e526d1ed59e7";
|
||||
|
||||
public function encrypt_decrypt($action, $string) {
|
||||
$output = false;
|
||||
|
||||
$encrypt_method = "AES-256-CBC";
|
||||
$secret_key = $this->secret_key;
|
||||
$secret_iv = $this->secret_iv;
|
||||
|
||||
// hash
|
||||
$key = hash('sha256', $secret_key);
|
||||
|
||||
// iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
|
||||
$iv = substr(hash('sha256', $secret_iv), 0, 16);
|
||||
|
||||
if ( $action == 'encrypt' ) {
|
||||
$output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
|
||||
$output = base64_encode($output);
|
||||
} else if( $action == 'decrypt' ) {
|
||||
$output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
634
app/Services/Package.php
Normal file
634
app/Services/Package.php
Normal file
@@ -0,0 +1,634 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Creditreport;
|
||||
use App\Models\Sale;
|
||||
use App\Models\TmpSale;
|
||||
use App\Models\Recurring;
|
||||
use App\Models\User;
|
||||
use App\Models\UserSecurityQuestion;
|
||||
use App\Models\UserSecurityQuestionAnswer;
|
||||
use App\Services\Payment\GateWay;
|
||||
use App\Services\Payment\Payment;
|
||||
use App\Services\SmartCredit\SmartCredit;
|
||||
use App\Utility\Email;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class Package
|
||||
{
|
||||
public array $data = [];
|
||||
public string $message = "";
|
||||
public string $status_code = "";
|
||||
public string $customer_token="";
|
||||
public string $tracking_token="";
|
||||
public string $payment_status_code = "";
|
||||
public string $transaction_id = "";
|
||||
|
||||
public function makePayment($inputData){
|
||||
$result = false;
|
||||
$this->status_code = config('constant.API_FAILED_CODE');
|
||||
$inputData['order_id'] = generateOrderId();
|
||||
$inputData['order_description'] = "Creditzombies Package";
|
||||
$inputData['ip'] = getClientIpAddress();
|
||||
// create pending sale
|
||||
$tmpSaleData=[
|
||||
'order_id' => $inputData['order_id']
|
||||
];
|
||||
$tmpSaleInsetedData = (new TmpSale())->createTmpSale($tmpSaleData);
|
||||
|
||||
// send payment request
|
||||
$response = (new Payment(GateWay::getGateWayInstance(config('constant.PAYMENT_GATEWAY.NMI')), $inputData))->pay();
|
||||
|
||||
|
||||
// log from payment gate way
|
||||
appLog([
|
||||
'action'=>'PAYMENT_GATEWAY_RESPONSE',
|
||||
'response'=>$response
|
||||
]);
|
||||
|
||||
$this->message = $response['message'];
|
||||
|
||||
$sale_status = config('constant.SALE_STATUS.FAILED');
|
||||
$inputData['status_code'] = $response['status_code'];
|
||||
|
||||
if($response['status_code'] == config('constant.API_SUCCESS_CODE')){
|
||||
|
||||
$this->purchasePackage($inputData);
|
||||
$this->status_code = $response['status_code'];
|
||||
$sale_status = config('constant.SALE_STATUS.COMPLETED');
|
||||
$this->message = __("Successfully paid");
|
||||
|
||||
}
|
||||
|
||||
// from payment response insert sale table with auth_code, trans_id, invoice_id, order_id
|
||||
$inputData['sale_status']=$sale_status;
|
||||
$inputData['auth_code'] = $response['auth_code'] ?? "";
|
||||
$inputData['transaction_id'] = $response['transaction_id'] ?? "";
|
||||
$this->sales($inputData);
|
||||
// delete pending sale
|
||||
(new TmpSale())->deleteTmpSaleById($tmpSaleInsetedData->id);
|
||||
|
||||
if($inputData['status_code'] == config('constant.API_FAILED_CODE')) {
|
||||
$this->paymentFailedMail($inputData);
|
||||
}
|
||||
|
||||
if($sale_status == config('constant.SALE_STATUS.COMPLETED')){
|
||||
$result = true;
|
||||
}
|
||||
|
||||
return [
|
||||
'status'=>$result,
|
||||
'order_id'=> $inputData['order_id'] ?? 0
|
||||
];
|
||||
}
|
||||
|
||||
public function makePayments($inputData){
|
||||
$result = false;
|
||||
$this->status_code = config('constant.API_FAILED_CODE');
|
||||
$inputData['order_id'] = generateOrderId();
|
||||
$inputData['order_description'] = "Creditzombies Package";
|
||||
$inputData['ip'] = getClientIpAddress();
|
||||
// create pending sale
|
||||
$tmpSaleData=[
|
||||
'order_id' => $inputData['order_id']
|
||||
];
|
||||
$tmpSaleInsetedData = (new TmpSale())->createTmpSale($tmpSaleData);
|
||||
|
||||
// send payment request
|
||||
$response = (new Payment(GateWay::getGateWayInstance(config('constant.PAYMENT_GATEWAY.NMI')), $inputData))->pay();
|
||||
|
||||
|
||||
// log from payment gate way
|
||||
appLog([
|
||||
'action'=>'PAYMENT_GATEWAY_RESPONSE',
|
||||
'response'=>$response
|
||||
]);
|
||||
|
||||
$this->message = $response['message'];
|
||||
|
||||
$sale_status = config('constant.SALE_STATUS.FAILED');
|
||||
$inputData['status_code'] = $response['status_code'];
|
||||
|
||||
if($response['status_code'] == config('constant.API_SUCCESS_CODE')){
|
||||
|
||||
$this->purchasePackages($inputData);
|
||||
$this->status_code = $response['status_code'];
|
||||
$sale_status = config('constant.SALE_STATUS.COMPLETED');
|
||||
$this->message = __("Successfully paid");
|
||||
|
||||
}
|
||||
|
||||
// from payment response insert sale table with auth_code, trans_id, invoice_id, order_id
|
||||
$inputData['sale_status']=$sale_status;
|
||||
$inputData['auth_code'] = $response['auth_code'] ?? "";
|
||||
$inputData['transaction_id'] = $response['transaction_id'] ?? "";
|
||||
$this->sales($inputData);
|
||||
// delete pending sale
|
||||
(new TmpSale())->deleteTmpSaleById($tmpSaleInsetedData->id);
|
||||
|
||||
if($inputData['status_code'] == config('constant.API_FAILED_CODE')) {
|
||||
$this->paymentFailedMail($inputData);
|
||||
}
|
||||
|
||||
if($sale_status == config('constant.SALE_STATUS.COMPLETED')){
|
||||
$result = true;
|
||||
}
|
||||
|
||||
return [
|
||||
'status'=>$result,
|
||||
'order_id'=> $inputData['order_id'] ?? 0
|
||||
];
|
||||
}
|
||||
|
||||
public function recurringPackage($paymentData)
|
||||
{
|
||||
|
||||
$inputData=[];
|
||||
$result = [];
|
||||
$logData['action'] = "RECURRING_PACKAGE";
|
||||
|
||||
try {
|
||||
$response = (new Payment(GateWay::getGateWayInstance(config('constant.PAYMENT_GATEWAY.NMI')), $paymentData))->makeRecurringPayment();
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$inputData['transaction_status'] = $response['transaction_status'];
|
||||
$inputData['email'] = $paymentData['email'];
|
||||
$inputData['name'] = $paymentData['first_name'] . ' ' . $paymentData['last_name'];
|
||||
$inputData['user_id'] = $paymentData['user_id'] ?? 0;
|
||||
$inputData['day_frequency'] = 0;
|
||||
$inputData['transaction_id'] = $response['transaction_id'] ;
|
||||
$inputData['subscription_id'] = $response['subscription_id'] ;
|
||||
$inputData['last_process_date'] = getCurrentDateTime();
|
||||
$inputData['plan_amount'] = config('constant.PLAN_AMOUNT');
|
||||
$inputData['day_of_month'] = config('constant.DAY_OF_MONTH');
|
||||
|
||||
(new Recurring())->insert($inputData);
|
||||
|
||||
DB::commit();
|
||||
$result['message'] = $response['message'];
|
||||
$result['status_code'] = $response['status_code'];
|
||||
$result['transaction_id'] = $inputData['transaction_id'];
|
||||
$result['status'] = $response['status'];
|
||||
// $result['order_id'] = $inputData['orderid'] ?? "";
|
||||
|
||||
} catch (\Exception $ex) {
|
||||
DB::rollback();
|
||||
$result['message'] = $ex->getMessage();
|
||||
$result['status_code'] = config('constant.API_FAILED_CODE');
|
||||
}
|
||||
|
||||
$logData['data']['message'] = $result['message'];
|
||||
$logData['data']['status_code'] = $result['status_code'];
|
||||
|
||||
appLog($logData);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function deleteRecurringPackage($inputData)
|
||||
{
|
||||
$result = [];
|
||||
|
||||
$logData['action'] = "DELETE_RECURRING_PACKAGE";
|
||||
|
||||
try {
|
||||
$response = (new Payment(GateWay::getGateWayInstance(config('constant.PAYMENT_GATEWAY.NMI')), $inputData))->deleteSubscription();
|
||||
|
||||
$result['message'] = $response['message'];
|
||||
$result['status_code'] = $response['status_code'];
|
||||
$result['subscription_id'] = $inputData['subscription_id'];
|
||||
$result['status'] = $response['status'];
|
||||
|
||||
}catch (\Exception $ex) {
|
||||
$result['message'] = $ex->getMessage();
|
||||
$result['status_code'] = config('constant.API_FAILED_CODE');
|
||||
}
|
||||
|
||||
$logData['data']['message'] = $result['message'];
|
||||
$logData['data']['status_code'] = $result['status_code'];
|
||||
$logData['email'] = $inputData['email'];
|
||||
|
||||
appLog($logData);
|
||||
|
||||
return $result;
|
||||
}
|
||||
/*
|
||||
public function payment($inputData)
|
||||
{
|
||||
$logData['action'] = "PURCHASE_PACKAGE";
|
||||
$sale_status = config('constant.SALE_STATUS.PENDING');
|
||||
|
||||
$inputData['order_id'] = generateOrderId();
|
||||
$inputData['order_description'] = "Creditzombies Package";
|
||||
$inputData['ip'] = getClientIpAddress();
|
||||
|
||||
if(isset($inputData['user_id']) && $inputData['user_id'] > 0){
|
||||
$user_id = $inputData['user_id'];
|
||||
}else {
|
||||
$user_id = getUserId();
|
||||
}
|
||||
|
||||
// create pending sale
|
||||
$tmpSaleData['order_id'] = $inputData['order_id'];
|
||||
$tmpSaleObj = new TmpSale();
|
||||
$tmpSaleInsetedData = $tmpSaleObj->createTmpSale($tmpSaleData);
|
||||
|
||||
// send payment request
|
||||
$response = (new Payment(GateWay::getGateWayInstance(config('constant.PAYMENT_GATEWAY.NMI')), $inputData))->pay();
|
||||
|
||||
// log from payment gate way
|
||||
appLog([
|
||||
'action'=>'PAYMENT_GATEWAY_RESPONSE',
|
||||
'response'=>$response
|
||||
]);
|
||||
|
||||
$this->message = __($response['message']);
|
||||
|
||||
$sale_status = config('constant.SALE_STATUS.FAILED');
|
||||
|
||||
if($response['status_code'] == config('constant.API_SUCCESS_CODE')){
|
||||
$this->status_code = $response['status_code'];
|
||||
$sale_status = config('constant.SALE_STATUS.COMPLETED');
|
||||
$this->message = __("Successfully paid");
|
||||
}
|
||||
|
||||
// from payment response insert sale table with auth_code, trans_id, invoice_id, order_id
|
||||
$saleData['order_id'] = $inputData['order_id'];
|
||||
$saleData['ip'] = $inputData['ip'];
|
||||
$saleData['status'] = $sale_status;
|
||||
$saleData['auth_code'] = $response['auth_code'] ?? "";
|
||||
$saleData['transaction_id'] = $response['transaction_id'] ?? "";
|
||||
$saleData['user_id'] = $user_id;
|
||||
(new Sale())->createSale($saleData);
|
||||
|
||||
// delete pending sale
|
||||
$tmpSaleObj->deleteTmpSaleById($tmpSaleInsetedData->id);
|
||||
|
||||
if($sale_status != config('constant.SALE_STATUS.COMPLETED')){
|
||||
throw new \Exception($this->message);
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
public function deleteRecurring($inputData)
|
||||
{
|
||||
$returnData= (new Recurring())->deleteRecurring($inputData);
|
||||
if($returnData) {
|
||||
$userData = [
|
||||
'is_import' => config('constant.IMPORT_REPORT_STATUS.NOT_ELIGIBLE'),
|
||||
'subscription_status' => config('constant.SUBSCRIPTION_STATUS.UNSUBSCRIBED')
|
||||
];
|
||||
(new User())->userupdate($userData, $inputData['user_id']);
|
||||
}
|
||||
return $returnData;
|
||||
}
|
||||
|
||||
public function createCustomer($inputData){
|
||||
|
||||
$this->payment_status_code = config('constant.API_FAILED_CODE');
|
||||
$status_code = config('constant.API_FAILED_CODE');
|
||||
$payment_data = $inputData;
|
||||
// for one time payment
|
||||
$onetimePayment = $this->makePayment($payment_data);
|
||||
|
||||
if($onetimePayment['status']) {
|
||||
|
||||
// for recurring
|
||||
$this->recurringPackage($inputData);
|
||||
|
||||
$this->payment_status_code = config('constant.API_SUCCESS_CODE');
|
||||
$order_id = $onetimePayment['order_id'] ?? "";
|
||||
|
||||
if(config('app.REPORT_PROVIDER') == '3') {
|
||||
|
||||
$smart_creditData = $this->prepareData($inputData);
|
||||
$smart_credit = (new SmartCredit(config('app.CLIENT_KEY')))
|
||||
->setData($smart_creditData)
|
||||
// ->register() // for stage server
|
||||
->register();
|
||||
|
||||
$status_code = $smart_credit->status_code ;
|
||||
$this->tracking_token = $smart_credit->tracking_token ;
|
||||
$this->customer_token = $smart_credit->customer_token ;
|
||||
$this->data = $smart_credit->data;
|
||||
$this->message = $smart_credit->message;
|
||||
|
||||
}
|
||||
$this->data['order_id'] = $order_id;
|
||||
|
||||
}
|
||||
|
||||
$this->status_code = $status_code;
|
||||
|
||||
/*// log from payment gate way
|
||||
appLog([
|
||||
'action' => 'SMART_CREDIT_API_RESPONSE',
|
||||
'response' => $smart_credit
|
||||
]);*/
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function securityQuestions()
|
||||
{
|
||||
return (new SmartCredit(config('app.CLIENT_KEY')))->security_questions();
|
||||
}
|
||||
|
||||
public function checkIsEmailExistOnSmartCredit($inputData)
|
||||
{
|
||||
return (new SmartCredit(config('app.CLIENT_KEY')))->setData($inputData)->checkIsEmailExistOnSmartCredit();
|
||||
}
|
||||
|
||||
public function identityQuestionAnswer()
|
||||
{
|
||||
$data='{
|
||||
"idVerificationCriteria": {
|
||||
"referenceNumber": "07271524018421870957",
|
||||
"question1": {
|
||||
"name": "YEAR_FOUNDED",
|
||||
"displayName": "What year was ConsumerDirect (aka PathwayData, aka MyPerfectCredit) founded?",
|
||||
"type": "MC",
|
||||
"choiceList": {
|
||||
"choice": [
|
||||
{
|
||||
"key": "1980",
|
||||
"display": "1980"
|
||||
},
|
||||
{
|
||||
"key": "1969",
|
||||
"display": "1969"
|
||||
},
|
||||
{
|
||||
"key": "2012",
|
||||
"display": "2012"
|
||||
},
|
||||
{
|
||||
"key": "2003",
|
||||
"display": "2003"
|
||||
},
|
||||
{
|
||||
"key": "!(1980^1969^2012^2003)",
|
||||
"display": "None of the above"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"question2": {
|
||||
"name": "NOT_CREDIT_BUREAU",
|
||||
"displayName": "Which company is NOT a credit bureau?",
|
||||
"type": "MC",
|
||||
"choiceList": {
|
||||
"choice": [
|
||||
{
|
||||
"key": "Experian",
|
||||
"display": "Experian"
|
||||
},
|
||||
{
|
||||
"key": "ConsumerDirect",
|
||||
"display": "ConsumerDirect"
|
||||
},
|
||||
{
|
||||
"key": "Equifax",
|
||||
"display": "Equifax"
|
||||
},
|
||||
{
|
||||
"key": "TransUnion",
|
||||
"display": "TransUnion"
|
||||
},
|
||||
{
|
||||
"key": "!(Experian^ConsumerDirect^Equifax^TransUnion^)",
|
||||
"display": "None of the above"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"question3": {
|
||||
"name": "INVENTED_INTERNET",
|
||||
"displayName": "Who invented the internet?",
|
||||
"type": "MC",
|
||||
"choiceList": {
|
||||
"choice": [
|
||||
{
|
||||
"key": "J. C. R. Licklider",
|
||||
"display": "J. C. R. Licklider"
|
||||
},
|
||||
{
|
||||
"key": "George Clooney",
|
||||
"display": "George Clooney"
|
||||
},
|
||||
{
|
||||
"key": "Al Gore",
|
||||
"display": "Al Gore"
|
||||
},
|
||||
{
|
||||
"key": "Howard Stark",
|
||||
"display": "Howard Stark"
|
||||
},
|
||||
{
|
||||
"key": "!(J. C. R. Licklider^George Clooney^Al Gore^Howard Stark^)",
|
||||
"display": "None of the above"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}';
|
||||
$returnData['data']=json_decode($data,true);
|
||||
$returnData['message']='success';
|
||||
$returnData['status_code']='100';
|
||||
// $questionAnswerList=(new SmartCredit(config('app.CLIENT_KEY')))->security_questions();
|
||||
return $returnData;
|
||||
}
|
||||
|
||||
public function submitIdentityQuestionAnswer($inputData)
|
||||
{
|
||||
$questionAnswerList=(new SmartCredit(config('app.CLIENT_KEY')))->security_question($inputData);
|
||||
return $questionAnswerList;
|
||||
}
|
||||
|
||||
private function prepareData($inputData)
|
||||
{
|
||||
$smart_creditData=[];
|
||||
$smart_creditData['email'] = $inputData['email'];
|
||||
$smart_creditData['planType'] = config('constant.package')[$inputData['package_id']];
|
||||
$smart_creditData['password'] = $inputData['password'];
|
||||
$smart_creditData['first_name'] = $inputData['first_name'];
|
||||
$smart_creditData['last_name'] = $inputData['last_name'];
|
||||
$smart_creditData['client_ip'] = getClientIpAddress();
|
||||
$smart_creditData['zip'] = $inputData['zip_code'];
|
||||
$smart_creditData['street'] = $inputData['street_no'] . " " . $inputData['street_name'];
|
||||
$smart_creditData['phone'] = $inputData['phone'];
|
||||
$smart_creditData['dob'] = $inputData['birth_date'];
|
||||
$smart_creditData['ssn'] = $inputData['full_ssn'];
|
||||
$smart_creditData['partial_ssn'] = $inputData['ssn'];
|
||||
$smart_creditData['sqa_answer'] = "Creditzombies";
|
||||
$smart_creditData['sqa_question'] = 1;
|
||||
return $smart_creditData;
|
||||
}
|
||||
|
||||
public function purchasePackage($inputData){
|
||||
$logData['action'] = "PURCHASE_PACKAGE";
|
||||
$inputData['order_description'] = "Creditzombies Package";
|
||||
$inputData['ip'] = getClientIpAddress();
|
||||
|
||||
if(!isset($inputData['user_id'])){
|
||||
$inputData['user_id'] = 0;
|
||||
}
|
||||
|
||||
$trace_string = "";
|
||||
try {
|
||||
// start begin transaction
|
||||
DB::beginTransaction();
|
||||
$is_import = 0;
|
||||
$wave = $inputData['wave'] ?? 0;
|
||||
$is_subscribed = 0;
|
||||
$last_payment_date = $inputData['last_payment_date'] ?? null;
|
||||
if(($inputData['status_code'] == config('constant.API_SUCCESS_CODE') && $inputData['user_id']>0) || $inputData['is_free'] == 1)
|
||||
{
|
||||
$is_import = 1;
|
||||
$wave += 1;
|
||||
$is_subscribed = 1;
|
||||
$last_payment_date = getCurrentDateTime();
|
||||
$creditReportData['user_id'] = $inputData['user_id'];
|
||||
$creditReportData['email'] = $inputData['email'];
|
||||
$creditReportData['password'] = $inputData['password'];
|
||||
$creditReportData['report_type'] = config('app.REPORT_PROVIDER') ?? 3;
|
||||
|
||||
(new Creditreport())->insertCreditReport($creditReportData);
|
||||
|
||||
$updateUserData['zip_code'] = $inputData['zip_code'];
|
||||
$updateUserData['phone'] = $inputData['phone'];
|
||||
$updateUserData['is_import'] = $is_import;
|
||||
$updateUserData['subscription_status'] = $is_subscribed;
|
||||
$updateUserData['wave'] = $wave;
|
||||
$updateUserData['last_payment_date'] = $last_payment_date;
|
||||
$updateUserData['user_access_end_date'] = getDateAfterSpicificDay($last_payment_date,config('constant.PAYMENT_INTERVAL_DAY'));
|
||||
(new User())->userupdate($updateUserData,$inputData['user_id']);
|
||||
}
|
||||
|
||||
|
||||
DB::commit();
|
||||
|
||||
$this->message = __("Account creation completed");
|
||||
$this->status_code = config('constant.API_SUCCESS_CODE');
|
||||
|
||||
} catch (\Exception $ex){
|
||||
DB::rollback();
|
||||
$this->message = $ex->getMessage();
|
||||
$this->status_code = config('constant.API_FAILED_CODE');
|
||||
$trace_string = $ex->getTraceAsString();
|
||||
}
|
||||
|
||||
$logData['data']['message'] = $this->message;
|
||||
$logData['data']['status_code'] = $this->status_code;
|
||||
|
||||
if(!empty($trace_string)) {
|
||||
$logData['data']['trace'] = $trace_string;
|
||||
}
|
||||
|
||||
appLog($logData);
|
||||
|
||||
}
|
||||
|
||||
public function purchasePackages($inputData){
|
||||
$logData['action'] = "PURCHASE_PACKAGE";
|
||||
$inputData['order_description'] = "Creditzombies Package";
|
||||
$inputData['ip'] = getClientIpAddress();
|
||||
|
||||
if(!isset($inputData['user_id'])){
|
||||
$inputData['user_id'] = 0;
|
||||
}
|
||||
|
||||
$trace_string = "";
|
||||
try {
|
||||
// start begin transaction
|
||||
DB::beginTransaction();
|
||||
|
||||
$is_subscribed = 0;
|
||||
$last_payment_date = $inputData['last_payment_date'] ?? null;
|
||||
if($inputData['status_code'] == config('constant.API_SUCCESS_CODE') && $inputData['user_id']>0)
|
||||
{
|
||||
|
||||
$is_subscribed = 1;
|
||||
$last_payment_date = getCurrentDateTime();
|
||||
$creditReportData['user_id'] = $inputData['user_id'];
|
||||
$creditReportData['email'] = $inputData['email'];
|
||||
$creditReportData['password'] = $inputData['password'];
|
||||
$creditReportData['report_type'] = config('app.REPORT_PROVIDER') ?? 3;
|
||||
|
||||
(new Creditreport())->insertCreditReport($creditReportData);
|
||||
|
||||
$updateUserData['zip_code'] = $inputData['zip_code'];
|
||||
$updateUserData['phone'] = $inputData['phone'];
|
||||
$updateUserData['subscription_status'] = $is_subscribed;
|
||||
$updateUserData['last_payment_date'] = $last_payment_date;
|
||||
(new User())->userupdate($updateUserData,$inputData['user_id']);
|
||||
}
|
||||
|
||||
|
||||
DB::commit();
|
||||
|
||||
$this->message = __("Account creation completed");
|
||||
$this->status_code = config('constant.API_SUCCESS_CODE');
|
||||
|
||||
} catch (\Exception $ex){
|
||||
DB::rollback();
|
||||
$this->message = $ex->getMessage();
|
||||
$this->status_code = config('constant.API_FAILED_CODE');
|
||||
$trace_string = $ex->getTraceAsString();
|
||||
}
|
||||
|
||||
$logData['data']['message'] = $this->message;
|
||||
$logData['data']['status_code'] = $this->status_code;
|
||||
|
||||
if(!empty($trace_string)) {
|
||||
$logData['data']['trace'] = $trace_string;
|
||||
}
|
||||
|
||||
appLog($logData);
|
||||
|
||||
}
|
||||
|
||||
public function customerCreditReportStatus($inputData)
|
||||
{
|
||||
$creditReportDataObj = (new Creditreport())->getCreditReportInfoByUserIdAndType($inputData['user_id'], $inputData['report_type']);
|
||||
if (!empty($creditReportDataObj)) {
|
||||
$password = customDecrypt($creditReportDataObj->password);
|
||||
$inputData['email'] = $creditReportDataObj->email;
|
||||
$inputData['password'] = $password;
|
||||
$apiResponse = (new SmartCredit(config('app.CLIENT_KEY')))->customerSubscription($inputData);
|
||||
if($apiResponse->status_code == config('constant.API_SUCCESS_CODE')) {
|
||||
$this->data = $apiResponse->data;
|
||||
$this->status_code = $apiResponse->status_code;
|
||||
$this->message = $apiResponse->message;
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function sales($inputData){
|
||||
$saleData = [];
|
||||
$saleData['order_id'] = $inputData['order_id'];
|
||||
$saleData['ip'] = getClientIpAddress();
|
||||
$saleData['status'] = $inputData['sale_status'];
|
||||
$saleData['auth_code'] = $inputData['auth_code'];
|
||||
$saleData['transaction_id'] = $inputData['transaction_id'];
|
||||
$saleData['user_id'] = $inputData['user_id'] ?? 0;
|
||||
$saleData['cc_number'] =creditCardNumberMasking($inputData['card_number']);
|
||||
return (new Sale())->createSale($saleData);
|
||||
}
|
||||
|
||||
public function paymentFailedMail($inputData)
|
||||
{
|
||||
|
||||
$data['email'] = $inputData['email'];
|
||||
$data['email_body'] = $inputData['first_name'] . ' ' . $inputData['last_name'];
|
||||
$data['email_subject'] = "Payment Failed";
|
||||
$from = null;
|
||||
$attachment = null;
|
||||
(new Email())->send($data, $data['email_subject'], $from, $attachment, 'email.payment_failed_letter', $data['email']);
|
||||
|
||||
}
|
||||
}
|
||||
14
app/Services/Payment/GateWay.php
Normal file
14
app/Services/Payment/GateWay.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Payment;
|
||||
|
||||
use App\Services\Payment\Gateway\NmiPayment;
|
||||
|
||||
class GateWay
|
||||
{
|
||||
public static function getGateWayInstance($gateway_code){
|
||||
if($gateway_code == config('constant.PAYMENT_GATEWAY.NMI')){
|
||||
return new NmiPayment();
|
||||
}
|
||||
}
|
||||
}
|
||||
877
app/Services/Payment/Gateway/NmiPayment.php
Normal file
877
app/Services/Payment/Gateway/NmiPayment.php
Normal file
@@ -0,0 +1,877 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Payment\Gateway;
|
||||
|
||||
use App\Services\Payment\PaymentInterface;
|
||||
|
||||
class NmiPayment implements PaymentInterface
|
||||
{
|
||||
// Initial Setting Functions
|
||||
|
||||
private string $base_url = "https://secure.nmi.com/api/transact.php";
|
||||
|
||||
private array $login = [];
|
||||
private array $responses = [];
|
||||
private array $recurringData = [];
|
||||
|
||||
private array $preparePaymentData = [];
|
||||
|
||||
private array $shipping = [];
|
||||
|
||||
private array $billing = [];
|
||||
|
||||
private array $order = [];
|
||||
private bool $isRecurring = false;
|
||||
private string $pay_log_id="";
|
||||
private array $logData = [];
|
||||
private array $data=[];
|
||||
|
||||
function setLogin($security_key) {
|
||||
$this->login['security_key'] = $security_key;
|
||||
$this->pay_log_id = "LOG_".getSecurityKey();
|
||||
}
|
||||
|
||||
function setOrder($orderid,
|
||||
$orderdescription,
|
||||
$tax,
|
||||
$shipping,
|
||||
$ponumber,
|
||||
$ipaddress) {
|
||||
$this->order['orderid'] = $orderid;
|
||||
$this->order['orderdescription'] = $orderdescription;
|
||||
$this->order['tax'] = $tax;
|
||||
$this->order['shipping'] = $shipping;
|
||||
$this->order['ponumber'] = $ponumber;
|
||||
$this->order['ipaddress'] = $ipaddress;
|
||||
}
|
||||
|
||||
function setBilling($firstname,
|
||||
$lastname,
|
||||
$company,
|
||||
$address1,
|
||||
$address2,
|
||||
$city,
|
||||
$state,
|
||||
$zip,
|
||||
$country,
|
||||
$phone,
|
||||
$fax,
|
||||
$email,
|
||||
$website) {
|
||||
$this->billing['firstname'] = $firstname;
|
||||
$this->billing['lastname'] = $lastname;
|
||||
$this->billing['company'] = $company;
|
||||
$this->billing['address1'] = $address1;
|
||||
$this->billing['address2'] = $address2;
|
||||
$this->billing['city'] = $city;
|
||||
$this->billing['state'] = $state;
|
||||
$this->billing['zip'] = $zip;
|
||||
$this->billing['country'] = $country;
|
||||
$this->billing['phone'] = $phone;
|
||||
$this->billing['fax'] = $fax;
|
||||
$this->billing['email'] = $email;
|
||||
$this->billing['website'] = $website;
|
||||
}
|
||||
|
||||
function setShipping($firstname,
|
||||
$lastname,
|
||||
$company,
|
||||
$address1,
|
||||
$address2,
|
||||
$city,
|
||||
$state,
|
||||
$zip,
|
||||
$country,
|
||||
$email) {
|
||||
$this->shipping['firstname'] = $firstname;
|
||||
$this->shipping['lastname'] = $lastname;
|
||||
$this->shipping['company'] = $company;
|
||||
$this->shipping['address1'] = $address1;
|
||||
$this->shipping['address2'] = $address2;
|
||||
$this->shipping['city'] = $city;
|
||||
$this->shipping['state'] = $state;
|
||||
$this->shipping['zip'] = $zip;
|
||||
$this->shipping['country'] = $country;
|
||||
$this->shipping['email'] = $email;
|
||||
}
|
||||
|
||||
public static function nmiAmountValueFormat($value){
|
||||
return number_format($value,2,".","");
|
||||
}
|
||||
|
||||
private function preparePaymentData($inputData)
|
||||
{
|
||||
|
||||
$this->preparePaymentData['type'] = "sale";
|
||||
$this->preparePaymentData['ccnumber'] = $inputData['card_number'];
|
||||
$this->preparePaymentData['ccexp'] = $inputData['expiry'];
|
||||
$this->preparePaymentData['amount'] = self::nmiAmountValueFormat($inputData['amount']);
|
||||
$this->preparePaymentData['cvv'] = $inputData['cvv'] ?? "";
|
||||
|
||||
$this->preparePaymentData['orderid'] = $inputData['order_id'];
|
||||
$this->preparePaymentData['orderdescription'] = $inputData['order_description'];
|
||||
$this->preparePaymentData['tax'] = number_format($inputData['tax'],2,".","") ;
|
||||
$this->preparePaymentData['shipping'] = number_format($inputData['shipping'],2,".","");
|
||||
$this->preparePaymentData['ponumber'] = $inputData['ponumber'];
|
||||
$this->preparePaymentData['ipaddress'] = $inputData['ip'];
|
||||
|
||||
$this->preparePaymentData['firstname'] = $inputData['first_name'];
|
||||
$this->preparePaymentData['lastname'] = $inputData['last_name'];
|
||||
$this->preparePaymentData['company'] = $inputData['company'];
|
||||
$this->preparePaymentData['address1'] = $inputData['address1'];
|
||||
$this->preparePaymentData['address2'] = $inputData['address2'];
|
||||
$this->preparePaymentData['city'] = $inputData['city'];
|
||||
$this->preparePaymentData['state'] = $inputData['state'];
|
||||
$this->preparePaymentData['zip'] = $inputData['zip'];
|
||||
$this->preparePaymentData['country'] = $inputData['country'];
|
||||
$this->preparePaymentData['email'] = $inputData['email'];
|
||||
$this->preparePaymentData['phone'] = $inputData['phone'];
|
||||
$this->preparePaymentData['fax'] = $inputData['fax'];
|
||||
$this->preparePaymentData['website'] = $inputData['website'];
|
||||
|
||||
$this->preparePaymentData['shipping_firstname'] = $inputData['first_name'];
|
||||
$this->preparePaymentData['shipping_lastname'] = $inputData['last_name'];
|
||||
$this->preparePaymentData['shipping_company'] = $inputData['company'];
|
||||
$this->preparePaymentData['shipping_address1'] = $inputData['address1'];
|
||||
$this->preparePaymentData['shipping_address2'] = $inputData['address2'];
|
||||
$this->preparePaymentData['shipping_city'] = $inputData['city'];
|
||||
$this->preparePaymentData['shipping_state'] = $inputData['state'];
|
||||
$this->preparePaymentData['shipping_zip'] = $inputData['zip'];
|
||||
$this->preparePaymentData['shipping_country'] = $inputData['country'];
|
||||
$this->preparePaymentData['shipping_email'] = $inputData['email'];
|
||||
}
|
||||
|
||||
// Transaction Functions
|
||||
|
||||
private function doSale() {
|
||||
|
||||
if(empty($this->preparePaymentData)){
|
||||
throw new \Exception('You must have to set payment data by calling preparePaymentData method.');
|
||||
}
|
||||
|
||||
/*
|
||||
$query = "";
|
||||
// Login Information
|
||||
$query .= "security_key=" . urlencode($this->login['security_key']) . "&";
|
||||
// Sales Information
|
||||
$query .= "ccnumber=" . urlencode($ccnumber) . "&";
|
||||
$query .= "ccexp=" . urlencode($ccexp) . "&";
|
||||
$query .= "amount=" . urlencode(number_format($amount,2,".","")) . "&";
|
||||
$query .= "cvv=" . urlencode($cvv) . "&";
|
||||
// Order Information
|
||||
$query .= "ipaddress=" . urlencode($this->order['ipaddress']) . "&";
|
||||
$query .= "orderid=" . urlencode($this->order['orderid']) . "&";
|
||||
$query .= "orderdescription=" . urlencode($this->order['orderdescription']) . "&";
|
||||
$query .= "tax=" . urlencode(number_format($this->order['tax'],2,".","")) . "&";
|
||||
$query .= "shipping=" . urlencode(number_format($this->order['shipping'],2,".","")) . "&";
|
||||
$query .= "ponumber=" . urlencode($this->order['ponumber']) . "&";
|
||||
// Billing Information
|
||||
$query .= "firstname=" . urlencode($this->billing['firstname']) . "&";
|
||||
$query .= "lastname=" . urlencode($this->billing['lastname']) . "&";
|
||||
$query .= "company=" . urlencode($this->billing['company']) . "&";
|
||||
$query .= "address1=" . urlencode($this->billing['address1']) . "&";
|
||||
$query .= "address2=" . urlencode($this->billing['address2']) . "&";
|
||||
$query .= "city=" . urlencode($this->billing['city']) . "&";
|
||||
$query .= "state=" . urlencode($this->billing['state']) . "&";
|
||||
$query .= "zip=" . urlencode($this->billing['zip']) . "&";
|
||||
$query .= "country=" . urlencode($this->billing['country']) . "&";
|
||||
$query .= "phone=" . urlencode($this->billing['phone']) . "&";
|
||||
$query .= "fax=" . urlencode($this->billing['fax']) . "&";
|
||||
$query .= "email=" . urlencode($this->billing['email']) . "&";
|
||||
$query .= "website=" . urlencode($this->billing['website']) . "&";
|
||||
// Shipping Information
|
||||
$query .= "shipping_firstname=" . urlencode($this->shipping['firstname']) . "&";
|
||||
$query .= "shipping_lastname=" . urlencode($this->shipping['lastname']) . "&";
|
||||
$query .= "shipping_company=" . urlencode($this->shipping['company']) . "&";
|
||||
$query .= "shipping_address1=" . urlencode($this->shipping['address1']) . "&";
|
||||
$query .= "shipping_address2=" . urlencode($this->shipping['address2']) . "&";
|
||||
$query .= "shipping_city=" . urlencode($this->shipping['city']) . "&";
|
||||
$query .= "shipping_state=" . urlencode($this->shipping['state']) . "&";
|
||||
$query .= "shipping_zip=" . urlencode($this->shipping['zip']) . "&";
|
||||
$query .= "shipping_country=" . urlencode($this->shipping['country']) . "&";
|
||||
$query .= "shipping_email=" . urlencode($this->shipping['email']) . "&";
|
||||
|
||||
$query .= "type=sale";
|
||||
|
||||
return $this->_doPost($query);
|
||||
*/
|
||||
$query = "";
|
||||
// Login Information
|
||||
|
||||
if(!empty($this->preparePaymentData)) {
|
||||
$query .= "security_key=" . urlencode($this->login['security_key']) . "&";
|
||||
|
||||
foreach ($this->preparePaymentData as $key => $value) {
|
||||
$query .= "&{$key}=" . urlencode($value);
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($query)){
|
||||
return $this->_doPost($query);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function doAuth($amount, $ccnumber, $ccexp, $cvv="") {
|
||||
|
||||
$query = "";
|
||||
// Login Information
|
||||
$query .= "security_key=" . urlencode($this->login['security_key']) . "&";
|
||||
// Sales Information
|
||||
$query .= "ccnumber=" . urlencode($ccnumber) . "&";
|
||||
$query .= "ccexp=" . urlencode($ccexp) . "&";
|
||||
$query .= "amount=" . urlencode(number_format($amount,2,".","")) . "&";
|
||||
$query .= "cvv=" . urlencode($cvv) . "&";
|
||||
// Order Information
|
||||
$query .= "ipaddress=" . urlencode($this->order['ipaddress']) . "&";
|
||||
$query .= "orderid=" . urlencode($this->order['orderid']) . "&";
|
||||
$query .= "orderdescription=" . urlencode($this->order['orderdescription']) . "&";
|
||||
$query .= "tax=" . urlencode(number_format($this->order['tax'],2,".","")) . "&";
|
||||
$query .= "shipping=" . urlencode(number_format($this->order['shipping'],2,".","")) . "&";
|
||||
$query .= "ponumber=" . urlencode($this->order['ponumber']) . "&";
|
||||
// Billing Information
|
||||
$query .= "firstname=" . urlencode($this->billing['firstname']) . "&";
|
||||
$query .= "lastname=" . urlencode($this->billing['lastname']) . "&";
|
||||
$query .= "company=" . urlencode($this->billing['company']) . "&";
|
||||
$query .= "address1=" . urlencode($this->billing['address1']) . "&";
|
||||
$query .= "address2=" . urlencode($this->billing['address2']) . "&";
|
||||
$query .= "city=" . urlencode($this->billing['city']) . "&";
|
||||
$query .= "state=" . urlencode($this->billing['state']) . "&";
|
||||
$query .= "zip=" . urlencode($this->billing['zip']) . "&";
|
||||
$query .= "country=" . urlencode($this->billing['country']) . "&";
|
||||
$query .= "phone=" . urlencode($this->billing['phone']) . "&";
|
||||
$query .= "fax=" . urlencode($this->billing['fax']) . "&";
|
||||
$query .= "email=" . urlencode($this->billing['email']) . "&";
|
||||
$query .= "website=" . urlencode($this->billing['website']) . "&";
|
||||
// Shipping Information
|
||||
$query .= "shipping_firstname=" . urlencode($this->shipping['firstname']) . "&";
|
||||
$query .= "shipping_lastname=" . urlencode($this->shipping['lastname']) . "&";
|
||||
$query .= "shipping_company=" . urlencode($this->shipping['company']) . "&";
|
||||
$query .= "shipping_address1=" . urlencode($this->shipping['address1']) . "&";
|
||||
$query .= "shipping_address2=" . urlencode($this->shipping['address2']) . "&";
|
||||
$query .= "shipping_city=" . urlencode($this->shipping['city']) . "&";
|
||||
$query .= "shipping_state=" . urlencode($this->shipping['state']) . "&";
|
||||
$query .= "shipping_zip=" . urlencode($this->shipping['zip']) . "&";
|
||||
$query .= "shipping_country=" . urlencode($this->shipping['country']) . "&";
|
||||
$query .= "shipping_email=" . urlencode($this->shipping['email']) . "&";
|
||||
$query .= "type=auth";
|
||||
return $this->_doPost($query);
|
||||
}
|
||||
|
||||
function doCredit($amount, $ccnumber, $ccexp) {
|
||||
|
||||
$query = "";
|
||||
// Login Information
|
||||
$query .= "security_key=" . urlencode($this->login['security_key']) . "&";
|
||||
// Sales Information
|
||||
$query .= "ccnumber=" . urlencode($ccnumber) . "&";
|
||||
$query .= "ccexp=" . urlencode($ccexp) . "&";
|
||||
$query .= "amount=" . urlencode(number_format($amount,2,".","")) . "&";
|
||||
// Order Information
|
||||
$query .= "ipaddress=" . urlencode($this->order['ipaddress']) . "&";
|
||||
$query .= "orderid=" . urlencode($this->order['orderid']) . "&";
|
||||
$query .= "orderdescription=" . urlencode($this->order['orderdescription']) . "&";
|
||||
$query .= "tax=" . urlencode(number_format($this->order['tax'],2,".","")) . "&";
|
||||
$query .= "shipping=" . urlencode(number_format($this->order['shipping'],2,".","")) . "&";
|
||||
$query .= "ponumber=" . urlencode($this->order['ponumber']) . "&";
|
||||
// Billing Information
|
||||
$query .= "firstname=" . urlencode($this->billing['firstname']) . "&";
|
||||
$query .= "lastname=" . urlencode($this->billing['lastname']) . "&";
|
||||
$query .= "company=" . urlencode($this->billing['company']) . "&";
|
||||
$query .= "address1=" . urlencode($this->billing['address1']) . "&";
|
||||
$query .= "address2=" . urlencode($this->billing['address2']) . "&";
|
||||
$query .= "city=" . urlencode($this->billing['city']) . "&";
|
||||
$query .= "state=" . urlencode($this->billing['state']) . "&";
|
||||
$query .= "zip=" . urlencode($this->billing['zip']) . "&";
|
||||
$query .= "country=" . urlencode($this->billing['country']) . "&";
|
||||
$query .= "phone=" . urlencode($this->billing['phone']) . "&";
|
||||
$query .= "fax=" . urlencode($this->billing['fax']) . "&";
|
||||
$query .= "email=" . urlencode($this->billing['email']) . "&";
|
||||
$query .= "website=" . urlencode($this->billing['website']) . "&";
|
||||
$query .= "type=credit";
|
||||
return $this->_doPost($query);
|
||||
}
|
||||
|
||||
function doOffline($authorizationcode, $amount, $ccnumber, $ccexp) {
|
||||
|
||||
$query = "";
|
||||
// Login Information
|
||||
$query .= "security_key=" . urlencode($this->login['security_key']) . "&";
|
||||
// Sales Information
|
||||
$query .= "ccnumber=" . urlencode($ccnumber) . "&";
|
||||
$query .= "ccexp=" . urlencode($ccexp) . "&";
|
||||
$query .= "amount=" . urlencode(number_format($amount,2,".","")) . "&";
|
||||
$query .= "authorizationcode=" . urlencode($authorizationcode) . "&";
|
||||
// Order Information
|
||||
$query .= "ipaddress=" . urlencode($this->order['ipaddress']) . "&";
|
||||
$query .= "orderid=" . urlencode($this->order['orderid']) . "&";
|
||||
$query .= "orderdescription=" . urlencode($this->order['orderdescription']) . "&";
|
||||
$query .= "tax=" . urlencode(number_format($this->order['tax'],2,".","")) . "&";
|
||||
$query .= "shipping=" . urlencode(number_format($this->order['shipping'],2,".","")) . "&";
|
||||
$query .= "ponumber=" . urlencode($this->order['ponumber']) . "&";
|
||||
// Billing Information
|
||||
$query .= "firstname=" . urlencode($this->billing['firstname']) . "&";
|
||||
$query .= "lastname=" . urlencode($this->billing['lastname']) . "&";
|
||||
$query .= "company=" . urlencode($this->billing['company']) . "&";
|
||||
$query .= "address1=" . urlencode($this->billing['address1']) . "&";
|
||||
$query .= "address2=" . urlencode($this->billing['address2']) . "&";
|
||||
$query .= "city=" . urlencode($this->billing['city']) . "&";
|
||||
$query .= "state=" . urlencode($this->billing['state']) . "&";
|
||||
$query .= "zip=" . urlencode($this->billing['zip']) . "&";
|
||||
$query .= "country=" . urlencode($this->billing['country']) . "&";
|
||||
$query .= "phone=" . urlencode($this->billing['phone']) . "&";
|
||||
$query .= "fax=" . urlencode($this->billing['fax']) . "&";
|
||||
$query .= "email=" . urlencode($this->billing['email']) . "&";
|
||||
$query .= "website=" . urlencode($this->billing['website']) . "&";
|
||||
// Shipping Information
|
||||
$query .= "shipping_firstname=" . urlencode($this->shipping['firstname']) . "&";
|
||||
$query .= "shipping_lastname=" . urlencode($this->shipping['lastname']) . "&";
|
||||
$query .= "shipping_company=" . urlencode($this->shipping['company']) . "&";
|
||||
$query .= "shipping_address1=" . urlencode($this->shipping['address1']) . "&";
|
||||
$query .= "shipping_address2=" . urlencode($this->shipping['address2']) . "&";
|
||||
$query .= "shipping_city=" . urlencode($this->shipping['city']) . "&";
|
||||
$query .= "shipping_state=" . urlencode($this->shipping['state']) . "&";
|
||||
$query .= "shipping_zip=" . urlencode($this->shipping['zip']) . "&";
|
||||
$query .= "shipping_country=" . urlencode($this->shipping['country']) . "&";
|
||||
$query .= "shipping_email=" . urlencode($this->shipping['email']) . "&";
|
||||
$query .= "type=offline";
|
||||
return $this->_doPost($query);
|
||||
}
|
||||
|
||||
function doCapture($transactionid, $amount =0) {
|
||||
|
||||
$query = "";
|
||||
// Login Information
|
||||
$query .= "security_key=" . urlencode($this->login['security_key']) . "&";
|
||||
// Transaction Information
|
||||
$query .= "transactionid=" . urlencode($transactionid) . "&";
|
||||
if ($amount>0) {
|
||||
$query .= "amount=" . urlencode(number_format($amount,2,".","")) . "&";
|
||||
}
|
||||
$query .= "type=capture";
|
||||
return $this->_doPost($query);
|
||||
}
|
||||
|
||||
function doVoid($transactionid) {
|
||||
|
||||
$query = "";
|
||||
// Login Information
|
||||
$query .= "security_key=" . urlencode($this->login['security_key']) . "&";
|
||||
// Transaction Information
|
||||
$query .= "transactionid=" . urlencode($transactionid) . "&";
|
||||
$query .= "type=void";
|
||||
return $this->_doPost($query);
|
||||
}
|
||||
|
||||
function doRefund($transactionid, $amount = 0) {
|
||||
|
||||
$query = "";
|
||||
// Login Information
|
||||
$query .= "security_key=" . urlencode($this->login['security_key']) . "&";
|
||||
// Transaction Information
|
||||
$query .= "transactionid=" . urlencode($transactionid) . "&";
|
||||
if ($amount>0) {
|
||||
$query .= "amount=" . urlencode(number_format($amount,2,".","")) . "&";
|
||||
}
|
||||
$query .= "type=refund";
|
||||
return $this->_doPost($query);
|
||||
}
|
||||
|
||||
|
||||
function doRecurringUpdate()
|
||||
{
|
||||
$query = "";
|
||||
// // Login Information
|
||||
$query .= "security_key=" . urlencode($this->login['security_key']) . "&";
|
||||
// update subscription
|
||||
$query .= "recurring=" . urlencode($this->recurringData['recurring']) . "&";
|
||||
$query .= "subscription_id=" . urlencode($this->recurringData['subscription_id']);
|
||||
|
||||
return $this->_doPost($query);
|
||||
|
||||
}
|
||||
function doTransactionInfo()
|
||||
{
|
||||
$query = "";
|
||||
// // Login Information
|
||||
$query .= "security_key=" . urlencode($this->login['security_key']) . "&";
|
||||
// update subscription
|
||||
$query .= "transaction_id=" . urlencode($this->recurringData['transaction_id']) . "&";
|
||||
$query .= "subscription_id=" . urlencode($this->recurringData['subscription_id']);
|
||||
|
||||
return $this->_doPost($query);
|
||||
|
||||
}
|
||||
|
||||
function _doPost($query) {
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $this->base_url);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
|
||||
if (!($data = curl_exec($ch))) {
|
||||
return 3;
|
||||
}
|
||||
curl_close($ch);
|
||||
unset($ch);
|
||||
// print "\n$data\n";
|
||||
|
||||
$data = explode("&",$data);
|
||||
for($i=0;$i<count($data);$i++) {
|
||||
$rdata = explode("=",$data[$i]);
|
||||
$this->responses[$rdata[0]] = $rdata[1];
|
||||
}
|
||||
return $this->responses['response'];
|
||||
}
|
||||
function doRecurring()
|
||||
{
|
||||
// Login Information
|
||||
$query_string = "";
|
||||
|
||||
if(!empty($this->recurringData)){
|
||||
$query_string .= "security_key=" . urlencode($this->login['security_key']);
|
||||
foreach ($this->recurringData as $key => $value){
|
||||
$query_string .= "&{$key}=".urlencode($value);
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($query_string)){
|
||||
return $this->_doPost($query_string);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function prepareData($inputData): array
|
||||
{
|
||||
if(empty($inputData['order_id'])){
|
||||
throw new \Exception('Order id missing');
|
||||
}
|
||||
|
||||
if(empty($inputData['order_description'])){
|
||||
throw new \Exception('order description missing');
|
||||
}
|
||||
|
||||
if(empty($inputData['ip'])){
|
||||
throw new \Exception('ip missing');
|
||||
}
|
||||
$prepareData['first_name'] = $inputData['first_name'];
|
||||
$prepareData['last_name'] = $inputData['last_name'];
|
||||
$prepareData['company'] = $inputData['company'] ?? config('app.name');
|
||||
$prepareData['address1'] = $inputData['street_no'];
|
||||
$prepareData['address2'] = $inputData['street_name'];
|
||||
$prepareData['city']= $inputData['city'];
|
||||
$prepareData['state']= $inputData['state'];
|
||||
$prepareData['zip']= $inputData['zip_code'];
|
||||
$prepareData['country']= $inputData['country'] ?? 'US';
|
||||
$prepareData['phone']= $inputData['phone'];
|
||||
$prepareData['fax']= $inputData['fax'] ?? "";
|
||||
$prepareData['email']= $inputData['email'];
|
||||
$prepareData['website'] = $inputData['website'] ?? "";
|
||||
|
||||
$prepareData['order_id']= $inputData['order_id'];
|
||||
$prepareData['order_description']= $inputData['order_description'];
|
||||
$prepareData['tax']= 1;
|
||||
$prepareData['shipping']= 1;
|
||||
$prepareData['ponumber']= "PO1234";
|
||||
$prepareData['ip'] = $inputData['ip'];
|
||||
|
||||
$prepareData['amount']= $inputData['amount'];
|
||||
$prepareData['card_number']= $inputData['card_number'];
|
||||
$prepareData['expiry'] = str_replace("/","",$inputData['expiry']);
|
||||
|
||||
return $prepareData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function makePayment($prepareData)
|
||||
{
|
||||
$result = [];
|
||||
// $logData['action'] = "NMI_PAYMENT";
|
||||
$this->setLogin(config('app.NMI_SECURITY_KEY'));
|
||||
/*
|
||||
$this->setBilling(
|
||||
$prepareData['first_name'],
|
||||
$prepareData['last_name'],
|
||||
$prepareData['company'],
|
||||
$prepareData['address1'],
|
||||
$prepareData['address2'],
|
||||
$prepareData['city'],
|
||||
$prepareData['state'],
|
||||
$prepareData['zip'],
|
||||
$prepareData['country'],
|
||||
$prepareData['phone'],
|
||||
$prepareData['fax'],
|
||||
$prepareData['email'],
|
||||
$prepareData['website']
|
||||
);
|
||||
|
||||
$this->setShipping(
|
||||
$prepareData['first_name'],
|
||||
$prepareData['last_name'],
|
||||
$prepareData['company'],
|
||||
$prepareData['address1'],
|
||||
$prepareData['address2'],
|
||||
$prepareData['city'],
|
||||
$prepareData['state'],
|
||||
$prepareData['zip'],
|
||||
$prepareData['country'],
|
||||
$prepareData['email']
|
||||
);
|
||||
|
||||
$this->setOrder(
|
||||
$prepareData['order_id'],
|
||||
$prepareData['order_description'],
|
||||
$prepareData['tax'],
|
||||
$prepareData['shipping'],
|
||||
$prepareData['ponumber'], //"PO1234",
|
||||
$prepareData['ip']
|
||||
);
|
||||
*/
|
||||
|
||||
$this->preparePaymentData($prepareData);
|
||||
$this->doSale();
|
||||
// $this->responseDataSample();
|
||||
$result['status_code'] = config('constant.API_FAILED_CODE');
|
||||
|
||||
$result['auth_code'] = $this->responses['authcode'] ?? "";
|
||||
$result['transaction_id'] = $this->responses['transactionid'] ?? "";
|
||||
$result['order_id'] = $this->responses['orderid'] ?? "";
|
||||
$result['message'] = $this->responses['responsetext'] ?? "";
|
||||
|
||||
if(isset($this->responses['response_code']) && $this->responses['response_code'] == config('constant.API_SUCCESS_CODE')){
|
||||
$result['status_code'] = config('constant.API_SUCCESS_CODE');
|
||||
}
|
||||
|
||||
// $logData['data'] = $this->responses;
|
||||
$this->logData['NMI_PAYMENT_API_LOG'][$this->pay_log_id]["MAKE_PAYMENT"]= $this->prepareLogData($this->base_url,'POST',$prepareData);
|
||||
|
||||
appLog($this->logData);
|
||||
|
||||
return $result;
|
||||
}
|
||||
public function makeRecurringPayment($inputData)
|
||||
{
|
||||
$result=[];
|
||||
$result['status'] = false;
|
||||
$this->setLogin(config('app.NMI_SECURITY_KEY'));
|
||||
$this->prepareRecurringData($inputData);
|
||||
$this->doRecurring();
|
||||
|
||||
$result['status_code'] = config('constant.API_FAILED_CODE');
|
||||
|
||||
$result['transaction_status'] = $this->responses['response'] ?? 0;
|
||||
$result['transaction_id'] = $this->responses['transactionid'] ?? "";
|
||||
$result['subscription_id'] = $this->responses['subscription_id'] ?? "";
|
||||
$result['message'] = $this->responses['responsetext'] ?? "";
|
||||
|
||||
if(isset($this->responses['response_code']) && $this->responses['response_code'] == config('constant.API_SUCCESS_CODE'))
|
||||
{
|
||||
$result['status_code'] = config('constant.API_SUCCESS_CODE');
|
||||
$result['status'] = true;
|
||||
}
|
||||
|
||||
$this->logData['NMI_RECURRING_API_LOG'][$this->pay_log_id]["MAKE_RECURRING"]= $this->prepareLogData($this->base_url,'POST',$inputData);
|
||||
|
||||
appLog( $this->logData);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
// prepare data for add subscription in existing plan
|
||||
public function prepareRecurringData($prepareData)
|
||||
{
|
||||
|
||||
/*
|
||||
first_name Cardholder's first name. Legacy variable includes: firstname
|
||||
last_name Cardholder's last name. Legacy variable includes: lastname
|
||||
address1 Card billing address.
|
||||
city Card billing city
|
||||
state Card billing state.
|
||||
zip Card billing postal code.
|
||||
country Card billing country code.
|
||||
phone Billing phone number.
|
||||
email Billing email address.
|
||||
company Cardholder's company.
|
||||
address2 Card billing address, line 2.
|
||||
fax Billing fax number.
|
||||
*/
|
||||
|
||||
// these are mandatory field for CZ
|
||||
|
||||
$this->recurringData['recurring'] = 'add_subscription';
|
||||
$this->recurringData['plan_id'] = "creditzombiesplan";
|
||||
$this->recurringData['payment'] = "creditcard";
|
||||
$this->recurringData['company'] = "Creditzombies";
|
||||
$this->recurringData['country'] = "US";
|
||||
|
||||
// these are mandatory field for CZ
|
||||
|
||||
$this->recurringData['ccnumber'] = $prepareData['card_number'];
|
||||
$this->recurringData['ccexp'] = $prepareData['expiry'];
|
||||
$this->recurringData['first_name'] = $prepareData['first_name'];
|
||||
$this->recurringData['last_name'] = $prepareData['last_name'];
|
||||
$this->recurringData['address1'] = $prepareData['street_no'];
|
||||
$this->recurringData['address2'] = $prepareData['street_name'];
|
||||
$this->recurringData['city'] = $prepareData['city'];
|
||||
$this->recurringData['state'] = $prepareData['state'];
|
||||
$this->recurringData['zip'] = $prepareData['zip_code'];
|
||||
$this->recurringData['phone'] = $prepareData['phone'];
|
||||
$this->recurringData['email'] = $prepareData['email'];
|
||||
|
||||
}
|
||||
|
||||
private function prepareLogData($url,$method,$request_data){
|
||||
if(isset($request_data['ccnumber'])){
|
||||
$request_data['ccnumber'] = "*********";
|
||||
}
|
||||
if(isset($request_data['card_number'])){
|
||||
$request_data['card_number'] = "*********";
|
||||
}
|
||||
if(!empty($request_data['password'])){
|
||||
$request_data['password'] = "*********";
|
||||
}
|
||||
|
||||
return [
|
||||
'request' => [
|
||||
'url' => $url,
|
||||
'method' => $method,
|
||||
'body'=> $request_data,
|
||||
'Header'=>[
|
||||
'ContentType' => 'application/x-www-form-urlencoded'
|
||||
]
|
||||
],
|
||||
'response' => $this->responses
|
||||
];
|
||||
}
|
||||
|
||||
private function getRecurringBySubscriptionId($security_key,$constraints){
|
||||
// transactionFields has all of the fields we want to validate
|
||||
// in the transaction tag in the XML output
|
||||
$transactionFields = array(
|
||||
'transaction_id',
|
||||
'partial_payment_id',
|
||||
'partial_payment_balance',
|
||||
'platform_id',
|
||||
'transaction_type',
|
||||
'condition',
|
||||
'order_id',
|
||||
'authorization_code',
|
||||
'ponumber',
|
||||
'order_description',
|
||||
|
||||
'first_name',
|
||||
'last_name',
|
||||
'address_1',
|
||||
'address_2',
|
||||
'company',
|
||||
'city',
|
||||
'state',
|
||||
'postal_code',
|
||||
'country',
|
||||
'email',
|
||||
'phone',
|
||||
'fax',
|
||||
'cell_phone',
|
||||
'customertaxid',
|
||||
'customerid',
|
||||
'website',
|
||||
|
||||
'shipping_first_name',
|
||||
'shipping_last_name',
|
||||
'shipping_address_1',
|
||||
'shipping_address_2',
|
||||
'shipping_company',
|
||||
'shipping_city',
|
||||
'shipping_state',
|
||||
'shipping_postal_code',
|
||||
'shipping_country',
|
||||
'shipping_email',
|
||||
'shipping_carrier',
|
||||
'tracking_number',
|
||||
'shipping_date',
|
||||
'shipping',
|
||||
'shipping_phone',
|
||||
|
||||
'cc_number',
|
||||
'cc_hash',
|
||||
'cc_exp',
|
||||
'cavv',
|
||||
'cavv_result',
|
||||
'xid',
|
||||
'eci',
|
||||
'avs_response',
|
||||
'csc_response',
|
||||
'cardholder_auth',
|
||||
'cc_start_date',
|
||||
'cc_issue_number',
|
||||
'check_account',
|
||||
'check_hash',
|
||||
'check_aba',
|
||||
'check_name',
|
||||
'account_holder_type',
|
||||
'account_type',
|
||||
'sec_code',
|
||||
'drivers_license_number',
|
||||
'drivers_license_state',
|
||||
'drivers_license_dob',
|
||||
'social_security_number',
|
||||
|
||||
'processor_id',
|
||||
'tax',
|
||||
'currency',
|
||||
'surcharge',
|
||||
'tip',
|
||||
|
||||
'card_balance',
|
||||
'card_available_balance',
|
||||
'entry_mode',
|
||||
'cc_bin',
|
||||
'cc_type'
|
||||
);
|
||||
|
||||
// actionFields is used to validate the XML tags in the
|
||||
// action element
|
||||
$actionFields = array(
|
||||
'amount',
|
||||
'action_type',
|
||||
'date',
|
||||
'success',
|
||||
'ip_address',
|
||||
'source',
|
||||
'api_method',
|
||||
'username',
|
||||
'response_text',
|
||||
'batch_id',
|
||||
'processor_batch_id',
|
||||
'response_code',
|
||||
'processor_response_text',
|
||||
'processor_response_code',
|
||||
'device_license_number',
|
||||
'device_nickname'
|
||||
);
|
||||
|
||||
$mycurl=curl_init();
|
||||
$postStr='security_key='.$security_key.$constraints;
|
||||
$url="https://secure.nmi.com/api/query.php?". $postStr;
|
||||
curl_setopt($mycurl, CURLOPT_URL, $url);
|
||||
curl_setopt($mycurl, CURLOPT_RETURNTRANSFER, 1);
|
||||
$responseXML=curl_exec($mycurl);
|
||||
curl_close($mycurl);
|
||||
|
||||
$testXmlSimple= new \SimpleXMLElement($responseXML);
|
||||
|
||||
if (!isset($testXmlSimple->transaction)) {
|
||||
throw new \Exception('No transactions returned');
|
||||
}
|
||||
|
||||
$transNum = 1;
|
||||
foreach($testXmlSimple->transaction as $transaction) {
|
||||
foreach ($transactionFields as $xmlField) {
|
||||
if (!isset($transaction->{$xmlField}[0])){
|
||||
throw new \Exception('Error in transaction_id:'. $transaction->transaction_id[0] .' id Transaction tag is missing field ' . $xmlField);
|
||||
}
|
||||
}
|
||||
if (!isset ($transaction->action)) {
|
||||
throw new \Exception('Error, Action tag is missing from transaction_id '. $transaction->transaction_id[0]);
|
||||
}
|
||||
|
||||
$actionNum = 1;
|
||||
foreach ($transaction->action as $action){
|
||||
foreach ($actionFields as $xmlField){
|
||||
if (!isset($action->{$xmlField}[0])){
|
||||
throw new \Exception('Error with transaction_id'.$transaction->transaction_id[0].'
|
||||
Action number '. $actionNum . ' Action tag is missing field ' . $xmlField);
|
||||
}
|
||||
}
|
||||
$actionNum++;
|
||||
}
|
||||
$transNum++;
|
||||
}
|
||||
|
||||
return $testXmlSimple;
|
||||
}
|
||||
|
||||
public function getRecurringInfoBySubscriptionId($inputData){
|
||||
$this->responses['data'] = [];
|
||||
try {
|
||||
$this->setLogin(config('app.NMI_SECURITY_KEY'));
|
||||
// $this->login['security_key'] = config('app.NMI_SECURITY_KEY');
|
||||
$this->pay_log_id = "LOG_".generateUniqueId();
|
||||
$constraints = "&subscription_id={$inputData['subscription_id']}&condition=complete&start_date={$inputData['start_date']}&end_date={$inputData['end_date']}";
|
||||
$result = $this->getRecurringBySubscriptionId($this->login['security_key'],$constraints);
|
||||
$result_json = json_encode($result);
|
||||
$result_json_array = json_decode($result_json,TRUE);
|
||||
$this->responses['data'] = $result_json_array['transaction'];
|
||||
$this->responses['status_code'] = config('constant.API_SUCCESS_CODE');
|
||||
$this->responses['message'] = "Successfully get data.";
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
||||
$this->responses['message'] = $e->getMessage();
|
||||
$this->responses['status_code'] = config('constant.API_FAILED_CODE');
|
||||
|
||||
}
|
||||
$this->logData['NMI_PAYMENT_API_LOG'][$this->pay_log_id]["SUBSCRIPTION_UPDATE_FOR_RECURRING"]= $this->prepareLogData($this->base_url,'POST',$inputData);
|
||||
|
||||
appLog( $this->logData);
|
||||
|
||||
return $this->responses;
|
||||
}
|
||||
|
||||
private function responseDataSample()
|
||||
{
|
||||
$data = '{"response": "2","responsetext": "Issuer Declined MCC","authcode": " ","transactionid": "8105207298",
|
||||
"avsresponse": "Y","cvvresponse": "","orderid": "167760085077649","type": "sale","response_code": "204"
|
||||
}';
|
||||
$this->responses = json_decode($data,true);
|
||||
}
|
||||
|
||||
public function deleteRecurringPayment($inputData)
|
||||
{
|
||||
$result = [];
|
||||
$result['status'] = false;
|
||||
$this->setLogin(config('app.NMI_SECURITY_KEY'));
|
||||
$this->prepareDeleteRecurringData($inputData);
|
||||
$this->doRecurring();
|
||||
|
||||
$result['status_code'] = config('constant.API_FAILED_CODE');
|
||||
|
||||
$result['transaction_status'] = $this->responses['response'] ?? 0;
|
||||
$result['transaction_id'] = $this->responses['transactionid'] ?? "";
|
||||
$result['subscription_id'] = $this->responses['subscription_id'] ?? "";
|
||||
$result['message'] = $this->responses['responsetext'] ?? "";
|
||||
|
||||
if(isset($this->responses['response_code']) && $this->responses['response_code'] == config('constant.API_SUCCESS_CODE'))
|
||||
{
|
||||
$result['status_code'] = config('constant.API_SUCCESS_CODE');
|
||||
$result['status'] = true;
|
||||
}
|
||||
|
||||
$this->logData['NMI_RECURRING_API_LOG'][$this->pay_log_id]["DELETE_MAKE_RECURRING"]= $this->prepareLogData($this->base_url,'POST',$inputData);
|
||||
|
||||
appLog( $this->logData);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function prepareDeleteRecurringData($prepareData)
|
||||
{
|
||||
$this->recurringData['recurring'] = 'delete_subscription';
|
||||
$this->recurringData['subscription_id'] = $prepareData['subscription_id'];
|
||||
}
|
||||
|
||||
}
|
||||
36
app/Services/Payment/Payment.php
Normal file
36
app/Services/Payment/Payment.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Payment;
|
||||
|
||||
class Payment
|
||||
{
|
||||
|
||||
private array $paymentData = [];
|
||||
private PaymentInterface $payment;
|
||||
|
||||
public function __construct(PaymentInterface $payment, $inputData)
|
||||
{
|
||||
$this->paymentData = $inputData;
|
||||
$this->payment = $payment;
|
||||
}
|
||||
|
||||
public function pay()
|
||||
{
|
||||
return $this->payment->makePayment($this->payment->prepareData($this->paymentData));
|
||||
}
|
||||
|
||||
public function makeRecurringPayment()
|
||||
{
|
||||
return $this->payment->makeRecurringPayment($this->paymentData);
|
||||
}
|
||||
|
||||
public function deleteSubscription()
|
||||
{
|
||||
return $this->payment->deleteRecurringPayment($this->paymentData);
|
||||
}
|
||||
public function getSubscriptionInfoBySubscriptionId()
|
||||
{
|
||||
return $this->payment->getRecurringInfoBySubscriptionId($this->paymentData);
|
||||
}
|
||||
|
||||
}
|
||||
12
app/Services/Payment/PaymentInterface.php
Normal file
12
app/Services/Payment/PaymentInterface.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Payment;
|
||||
|
||||
interface PaymentInterface
|
||||
{
|
||||
|
||||
public function makePayment($data);
|
||||
|
||||
public function prepareData($data);
|
||||
|
||||
}
|
||||
122
app/Services/PaymentService.php
Normal file
122
app/Services/PaymentService.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\CardToken;
|
||||
use App\Models\Sale;
|
||||
use App\Models\TmpSale;
|
||||
use App\Models\UserPackage;
|
||||
use App\Services\Payment\GateWay;
|
||||
use App\Services\Payment\Payment;
|
||||
use App\Services\Package;
|
||||
use App\Utility\Email;
|
||||
|
||||
class PaymentService
|
||||
{
|
||||
public array $data = [];
|
||||
public string $message = "";
|
||||
public string $status_code = "";
|
||||
public string $customer_token="";
|
||||
public string $tracking_token="";
|
||||
public string $payment_status_code = "";
|
||||
public string $transaction_id = "";
|
||||
public function payment($inputData)
|
||||
{
|
||||
$modelData=[];
|
||||
$result = false;
|
||||
$modelData['token']=$inputData['cc-number'];
|
||||
$modelData['user_id']=$inputData['User']->id;
|
||||
if ($saved = (new CardToken())->createPayment($modelData)) {
|
||||
$result = true;
|
||||
}
|
||||
return $result;
|
||||
|
||||
}
|
||||
public function getUserPackage($user_id)
|
||||
{
|
||||
$userPackage = UserPackage::join('packages', 'user_packages.package_id', '=', 'packages.id')
|
||||
->where('user_packages.user_id',$user_id)
|
||||
->first(['user_packages.*', 'packages.amount']);
|
||||
return $userPackage;
|
||||
}
|
||||
public function makePayment($inputData){
|
||||
$result = false;
|
||||
$this->status_code = config('constant.API_FAILED_CODE');
|
||||
$inputData['order_id'] = generateOrderId();
|
||||
$inputData['order_description'] = "Creditzombies Package";
|
||||
$inputData['ip'] = getClientIpAddress();
|
||||
// create pending sale
|
||||
$tmpSaleData=[
|
||||
'order_id' => $inputData['order_id']
|
||||
];
|
||||
|
||||
$tmpSaleInsertedData = (new TmpSale())->createTmpSale($tmpSaleData);
|
||||
|
||||
// send payment request
|
||||
$response = (new Payment(GateWay::getGateWayInstance(config('constant.PAYMENT_GATEWAY.NMI')), $inputData))->pay();
|
||||
|
||||
// log from payment gate way
|
||||
appLog([
|
||||
'action'=>'PAYMENT_GATEWAY_RESPONSE',
|
||||
'response'=>$response
|
||||
]);
|
||||
|
||||
$this->message = $response['message'];
|
||||
|
||||
$sale_status = config('constant.SALE_STATUS.FAILED');
|
||||
$inputData['status_code'] = $response['status_code'];
|
||||
|
||||
if($response['status_code'] == config('constant.API_SUCCESS_CODE')){
|
||||
|
||||
$this->status_code = $response['status_code'];
|
||||
$sale_status = config('constant.SALE_STATUS.COMPLETED');
|
||||
$this->message = __("Successfully paid");
|
||||
|
||||
}
|
||||
|
||||
// from payment response insert sale table with auth_code, trans_id, invoice_id, order_id
|
||||
$inputData['sale_status'] = $sale_status;
|
||||
$inputData['auth_code'] = $response['auth_code'] ?? "";
|
||||
$inputData['transaction_id'] = $response['transaction_id'] ?? "";
|
||||
$this->sales($inputData);
|
||||
// delete pending sale
|
||||
(new TmpSale())->deleteTmpSaleById($tmpSaleInsertedData->id);
|
||||
|
||||
if($inputData['status_code'] == config('constant.API_FAILED_CODE')) {
|
||||
$this->paymentFailedMail($inputData);
|
||||
}
|
||||
|
||||
if($sale_status == config('constant.SALE_STATUS.COMPLETED')){
|
||||
$result = true;
|
||||
}
|
||||
|
||||
return [
|
||||
'status'=>$result,
|
||||
'order_id'=> $inputData['order_id'] ?? 0
|
||||
];
|
||||
}
|
||||
private function sales($inputData){
|
||||
$saleData = [];
|
||||
$saleData['order_id'] = $inputData['order_id'];
|
||||
$saleData['ip'] = getClientIpAddress();
|
||||
$saleData['status'] = $inputData['sale_status'];
|
||||
$saleData['auth_code'] = $inputData['auth_code'];
|
||||
$saleData['transaction_id'] = $inputData['transaction_id'];
|
||||
$saleData['user_id'] = $inputData['user_id'] ?? 0;
|
||||
$saleData['cc_number'] =creditCardNumberMasking($inputData['card_number']);
|
||||
return (new Sale())->createSale($saleData);
|
||||
}
|
||||
|
||||
public function paymentFailedMail($inputData)
|
||||
{
|
||||
|
||||
$data['email'] = $inputData['email'];
|
||||
$data['email_body'] = $inputData['first_name'] . ' ' . $inputData['last_name'];
|
||||
$data['email_subject'] = "Payment Failed";
|
||||
$from = null;
|
||||
$attachment = null;
|
||||
(new Email())->send($data, $data['email_subject'], $from, $attachment, 'email.payment_failed_letter', $data['email']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
84
app/Services/Register.php
Normal file
84
app/Services/Register.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Submodule;
|
||||
use App\Models\UserPackage;
|
||||
use Exception;
|
||||
|
||||
class Register
|
||||
{
|
||||
public function createAccount($inputData){
|
||||
$result = [];
|
||||
$user = app(\App\Models\User::class);
|
||||
if ($saved = $user->addUser($inputData)) {
|
||||
$result = $saved;
|
||||
$result['security_key'] = customEncrypt(json_encode(['user_id'=>$saved->id]));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function addProfile($inputData,$user_id):bool{
|
||||
$result = false;
|
||||
$user = app(\App\Models\User::class);
|
||||
if ($saved = $user->userupdate($inputData,$user_id)) {
|
||||
$result = true;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function addPackage($package_id, $user_id){
|
||||
|
||||
$comapanyTypeArray = [
|
||||
'1'=>3,
|
||||
'2'=>3,
|
||||
'3'=>1
|
||||
];
|
||||
|
||||
$userPackage = new UserPackage();
|
||||
|
||||
if($userPackage->isExistPackage($package_id,$user_id)){
|
||||
throw new \Exception("Package already taken.");
|
||||
}
|
||||
$inputData['package_id'] = $package_id;
|
||||
$inputData['user_id'] = $user_id;
|
||||
if(!$userPackage->setUserPackage($inputData)) {
|
||||
throw new \Exception("Package doesn't added.Please try again!");
|
||||
}
|
||||
|
||||
$user = app(\App\Models\User::class);
|
||||
|
||||
$updateData['credit_report_company_type'] = $comapanyTypeArray[$inputData['package_id']];
|
||||
|
||||
if(!$user->userupdate($updateData,$inputData['user_id'])){
|
||||
throw new \Exception("Package doesn't added.Please try again!");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function emailVarification($inputData){
|
||||
$result = [];
|
||||
$user = app(\App\Models\User::class);
|
||||
if ($saved = $user->getUserByEmail($inputData)) {
|
||||
$result = $saved;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function roleList($inputData)
|
||||
{
|
||||
$result = [];
|
||||
$submoduleResult=Submodule::join('modules', 'submodules.module_id', '=', 'modules.id')
|
||||
->select('submodules.*','modules.name as moduleName');
|
||||
|
||||
$result= $submoduleResult->get();
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
}
|
||||
15
app/Services/ReportService.php
Normal file
15
app/Services/ReportService.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Sale;
|
||||
|
||||
class ReportService
|
||||
{
|
||||
public function getSalesReport($inputData)
|
||||
{
|
||||
return (new Sale())->getSalesList($inputData);
|
||||
}
|
||||
|
||||
}
|
||||
956
app/Services/SmartCredit/SmartCredit.php
Normal file
956
app/Services/SmartCredit/SmartCredit.php
Normal file
@@ -0,0 +1,956 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\SmartCredit;
|
||||
|
||||
use App\Utility\HttpRequest\HttpAsForm;
|
||||
use Exception;
|
||||
use Illuminate\Validation\Rules\Enum;
|
||||
|
||||
class SmartCredit
|
||||
{
|
||||
/*
|
||||
* Create smart credit account life cycle
|
||||
* call /start api (GET)
|
||||
* call /customer/create api (POST)
|
||||
* call /customer/update/identity api (POST)
|
||||
* call /id-verification api (GET)
|
||||
* call /id-verification api (POST)
|
||||
* call /validate/credit-card-number (GET)
|
||||
* call /customer/update/credit-card (POST)
|
||||
* call /complete api (POST)
|
||||
* */
|
||||
|
||||
const CLIENT_KEY = "ddeada92-6310-4850-82c4-0b99159b9339";
|
||||
|
||||
private string $api_base_url = '';
|
||||
private string $pws_base_url = '';
|
||||
|
||||
private string $client_key;
|
||||
public string $customer_token='';
|
||||
public string $pws_customer_token='';
|
||||
public string $tracking_token='';
|
||||
|
||||
private string $email;
|
||||
private string $first_name;
|
||||
private string $last_name;
|
||||
private string $client_ip;
|
||||
private string $street;
|
||||
private string $zip;
|
||||
private string $phone;
|
||||
private string $dob;
|
||||
private string $ssn;
|
||||
private string $password;
|
||||
private string $planType;
|
||||
private string $refference;
|
||||
private string $card_number;
|
||||
private string $cvv;
|
||||
private string $expiry;
|
||||
private string $credit_card_token;
|
||||
private string $partial_ssn;
|
||||
private string $sqa_answer;
|
||||
private string $sqa_question;
|
||||
private string $sponsorCodeString = "YHV3QZWXN5";
|
||||
private string $pid = "11885";
|
||||
private string $temporaryPassword;
|
||||
|
||||
private array $logData = [];
|
||||
|
||||
public string $status_code = "";
|
||||
public string $message = "";
|
||||
public $data = [] ;
|
||||
private string $log_id;
|
||||
|
||||
private int $updateId=0;
|
||||
|
||||
private string $prefix = "SMART_CREDIT_API_";
|
||||
|
||||
|
||||
public function __construct($client_key){
|
||||
$this->client_key = $client_key;
|
||||
$this->api_base_url = (config('app.SMART_CREDIT_BASE_URL') ?? '')."/api/signup";
|
||||
$this->pws_base_url = config('app.PWS_SMART_CREDIT_BASE_URL') ?? '';
|
||||
$this->log_id = "LOG_".getSecurityKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
private function setException($responseData){
|
||||
$this->status_code = config('constant.API_FAILED_CODE');
|
||||
if(isset($responseData['errors']) && !empty($responseData['errors'])){
|
||||
$responseData['errors'] = current($responseData['errors']);
|
||||
$this->message = $responseData['errors']['message'];
|
||||
}else{
|
||||
$this->message = "Somethings went to wrong.";
|
||||
}
|
||||
throw new \Exception($this->message);
|
||||
}
|
||||
|
||||
|
||||
public function setData($inputData): SmartCredit
|
||||
{
|
||||
$this->email = $inputData['email'] ?? "";
|
||||
$this->planType = $inputData['planType'] ?? "";
|
||||
$this->password = $inputData['password'] ?? "";
|
||||
$this->first_name = $inputData['first_name'] ?? "";
|
||||
$this->last_name = $inputData['last_name'] ?? "";
|
||||
$this->client_ip = $inputData['client_ip'] ?? "";
|
||||
$this->zip = $inputData['zip'] ?? "";
|
||||
$this->street = $inputData['street'] ?? "";
|
||||
$this->phone = $inputData['phone'] ?? "";
|
||||
$this->dob = $inputData['dob'] ?? "";
|
||||
$this->ssn = $inputData['ssn'] ?? "";
|
||||
$this->partial_ssn = $inputData['partial_ssn'] ?? "";
|
||||
$this->card_number = $inputData['card_number'] ?? "";
|
||||
$this->cvv = $inputData['cvv'] ?? "";
|
||||
$this->expiry = $inputData['expiry'] ?? "";
|
||||
// $this->sqa_answer = $inputData['sqa_answer'];
|
||||
// $this->sqa_question = $inputData['sqa_question'];
|
||||
|
||||
$this->logData['SMART_CREDIT_API_LOG'][$this->log_id]['user_request'] = $inputData;
|
||||
|
||||
if(!empty($this->partial_ssn)){
|
||||
$this->logData['SMART_CREDIT_API_LOG'][$this->log_id]['user_request']['partial_ssn'] = "XXXX";
|
||||
}
|
||||
|
||||
if(!empty($this->ssn)){
|
||||
$this->logData['SMART_CREDIT_API_LOG'][$this->log_id]['user_request']['ssn'] = "XXX-XX-XXXX";
|
||||
}
|
||||
|
||||
if(!empty($this->card_number)){
|
||||
$this->logData['SMART_CREDIT_API_LOG'][$this->log_id]['user_request']['card_number'] = "XXXXXXXXXXXX";
|
||||
}
|
||||
|
||||
if(!empty($this->cvv)){
|
||||
$this->logData['SMART_CREDIT_API_LOG'][$this->log_id]['user_request']['cvv'] = "XXX";
|
||||
}
|
||||
|
||||
if(!empty($this->expiry)){
|
||||
$this->logData['SMART_CREDIT_API_LOG'][$this->log_id]['user_request']['expiry'] = "XXXX";
|
||||
}
|
||||
|
||||
if(!empty($this->password)){
|
||||
$this->logData['SMART_CREDIT_API_LOG'][$this->log_id]['user_request']['password'] = "XXXXXXXX";
|
||||
}
|
||||
|
||||
|
||||
/*$this->logData['SMART_CREDIT_API_LOG'][$this->log_id]['user_request']['sqa_answer'] = "XXXX";
|
||||
$this->logData['SMART_CREDIT_API_LOG'][$this->log_id]['user_request']['sqa_question'] = "XXXX";*/
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
private function start(): void
|
||||
{
|
||||
|
||||
$url = $this->api_base_url . "/start";
|
||||
|
||||
$params = [
|
||||
'clientKey' => $this->client_key,
|
||||
'PID' => $this->pid
|
||||
];
|
||||
|
||||
$responseData = (new HttpAsForm($url))->get($params);
|
||||
|
||||
$this->data = $responseData;
|
||||
|
||||
$this->logData['SMART_CREDIT_API_LOG'][$this->log_id]["START"] = $this->prepareLogData($url,'GET',$params);
|
||||
|
||||
if(!empty($responseData['trackingToken'])){
|
||||
$this->tracking_token = $responseData['trackingToken'];
|
||||
}else{
|
||||
$this->setException($responseData);
|
||||
}
|
||||
|
||||
|
||||
//appLog($this->logData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
private function campaign(): void
|
||||
{
|
||||
|
||||
$url = $this->api_base_url . "/campaign";
|
||||
|
||||
$params = [
|
||||
'clientKey' => $this->client_key,
|
||||
'PID' => $this->pid
|
||||
];
|
||||
$responseData = (new HttpAsForm($url))->get($params);
|
||||
|
||||
$this->data = $responseData;
|
||||
|
||||
$this->logData['SMART_CREDIT_API_LOG'][$this->log_id]["CAMPAIGN"] = $this->prepareLogData($url,'GET',$params);
|
||||
|
||||
if(isset($responseData['errors']) && !empty($responseData['errors'])){
|
||||
$this->setException($responseData);
|
||||
}
|
||||
|
||||
|
||||
//appLog($this->logData);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
private function validateEmail(): void
|
||||
{
|
||||
|
||||
$url = $this->api_base_url ."/validate/email";
|
||||
|
||||
$params = [
|
||||
'clientKey' => $this->client_key,
|
||||
'email'=>$this->email,
|
||||
'trackingToken'=>$this->tracking_token
|
||||
];
|
||||
|
||||
$responseData = (new HttpAsForm($url))->get($params);
|
||||
|
||||
$this->data = $responseData;
|
||||
|
||||
$this->logData['SMART_CREDIT_API_LOG'][$this->log_id]["VALIDATE_EMAIL"] = $this->prepareLogData($url,'GET',$params);
|
||||
|
||||
if(isset($responseData['errors']) && !empty($responseData['errors'])){
|
||||
$this->setException($responseData);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
private function validateSponsorCode(): void
|
||||
{
|
||||
|
||||
$url = $this->api_base_url ."/validate/sponsor-code";
|
||||
|
||||
$params = [
|
||||
'clientKey' => $this->client_key,
|
||||
'sponsorCode '=>$this->sponsorCodeString,
|
||||
'trackingToken'=>$this->tracking_token
|
||||
];
|
||||
|
||||
$responseData = (new HttpAsForm($url))->get($params);
|
||||
|
||||
$this->data = $responseData;
|
||||
|
||||
$this->logData['SMART_CREDIT_API_LOG'][$this->log_id]["VALIDATE_SPONSOR_CODE"] = $this->prepareLogData($url,'GET',$params);
|
||||
|
||||
if(isset($responseData['errors']) && !empty($responseData['errors'])){
|
||||
$this->setException($responseData);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
private function validateSsn(): void
|
||||
{
|
||||
$url = $this->api_base_url . "/validate/ssn";
|
||||
|
||||
$params = [
|
||||
'clientKey' => $this->client_key,
|
||||
'ssn' => $this->ssn,
|
||||
'trackingToken' => $this->tracking_token
|
||||
];
|
||||
|
||||
// optional parameter customer token
|
||||
if (!empty($this->customer_token)) {
|
||||
$params['customerToken'] = $this->customer_token;
|
||||
}
|
||||
|
||||
$responseData = (new HttpAsForm($url))->get($params);
|
||||
|
||||
$this->data = $responseData;
|
||||
|
||||
$this->logData['SMART_CREDIT_API_LOG'][$this->log_id]["VALIDATE_SSN"] = $this->prepareLogData($url, 'GET', $params);
|
||||
|
||||
if (isset($responseData['errors']) && !empty($responseData['errors'])) {
|
||||
$this->setException($responseData);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
private function create(): void
|
||||
{
|
||||
|
||||
$url = $this->api_base_url ."/customer/create";
|
||||
|
||||
$params = [
|
||||
'clientKey' => $this->client_key,
|
||||
'email'=>$this->email,
|
||||
'trackingToken'=>$this->tracking_token,
|
||||
'password'=>$this->password,
|
||||
'planType'=>$this->planType,
|
||||
'sponsorCodeString'=>$this->sponsorCodeString
|
||||
];
|
||||
|
||||
|
||||
$responseData = (new HttpAsForm($url))->post($params);
|
||||
|
||||
$this->data = $responseData;
|
||||
|
||||
$this->logData['SMART_CREDIT_API_LOG'][$this->log_id]["CREATE"] = $this->prepareLogData($url,'POST',$params);
|
||||
|
||||
if(!empty($responseData['customerToken'])){
|
||||
$this->customer_token = $responseData['customerToken'];
|
||||
}else{
|
||||
$this->setException($responseData);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
private function updateIdentity(): void
|
||||
{
|
||||
|
||||
$url = $this->api_base_url . "/customer/update/identity";
|
||||
|
||||
$params = [
|
||||
'clientKey' => $this->client_key,
|
||||
'trackingToken' => $this->tracking_token,
|
||||
'customerToken' => $this->customer_token,
|
||||
'firstName' => $this->first_name,
|
||||
'lastName' => $this->last_name,
|
||||
'homeAddress.street' => $this->street,
|
||||
'homeAddress.zip' => $this->zip,
|
||||
'homePhone' => $this->phone,
|
||||
'identity.birthDate' => $this->dob,
|
||||
'identity.ssnPartial' => $this->partial_ssn,
|
||||
'identity.ssn' => $this->ssn,
|
||||
'isConfirmedTerms' => true,
|
||||
// 'securityQuestionAnswer.answer' => $this->sqa_answer,
|
||||
// 'securityQuestionAnswer.securityQuestionId' => $this->sqa_question,
|
||||
'confirmTermsBrowserIpAddress' => $this->client_ip
|
||||
];
|
||||
|
||||
$responseData = (new HttpAsForm($url))->post($params);
|
||||
|
||||
$this->data = $responseData;
|
||||
|
||||
// $action=($this->updateId==1)?"UPDATE_IDENTITY_1":"UPDATE_IDENTITY";
|
||||
|
||||
$this->logData['SMART_CREDIT_API_LOG'][$this->log_id]["UPDATE_IDENTITY"] = $this->prepareLogData($url, 'POST', $params);
|
||||
|
||||
if (isset($responseData['errors']) && !empty($responseData['errors'])) {
|
||||
$this->setException($responseData);
|
||||
}
|
||||
|
||||
|
||||
//appLog($this->logData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
private function getIdVerification(): void
|
||||
{
|
||||
$url = $this->api_base_url ."/id-verification";
|
||||
|
||||
$params = [
|
||||
'clientKey' => $this->client_key,
|
||||
'trackingToken'=>$this->tracking_token,
|
||||
'customerToken'=>$this->customer_token
|
||||
];
|
||||
|
||||
$this->getIdVerificationApiCall($url,$params,1);
|
||||
|
||||
if($this->status_code == config('constant.API_FAILED_CODE')){
|
||||
$this->getIdVerificationApiCall($url,$params,2);
|
||||
}
|
||||
|
||||
if($this->status_code == config('constant.API_FAILED_CODE')) {
|
||||
$this->setException($this->data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function getIdVerificationApiCall($url,$params,$count){
|
||||
|
||||
$responseData = (new HttpAsForm($url))->get($params);
|
||||
//$responseData = $this->identityQuestionAnswer();
|
||||
$this->data = $responseData;
|
||||
|
||||
$this->logData['SMART_CREDIT_API_LOG'][$this->log_id]["GET_ID_VERIFICATION"][$count] = $this->prepareLogData($url,'GET',$params);
|
||||
|
||||
if(isset($responseData['errors']) && !empty($responseData['errors'])){
|
||||
$this->status_code = config('constant.API_FAILED_CODE');
|
||||
}else{
|
||||
$this->status_code = config('constant.API_SUCCESS_CODE');
|
||||
$this->message = __('Account has been created successfully');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function prepareLogData($url,$method,$request_data){
|
||||
|
||||
if(isset($request_data['identity.ssnPartial'])){
|
||||
$request_data['identity.ssnPartial'] = "XXXX";
|
||||
}
|
||||
|
||||
if(isset($request_data['identity.ssn'])){
|
||||
$request_data['identity.ssn'] = "XXX-XX-XXXX";
|
||||
}
|
||||
|
||||
if(isset($request_data['ssn'])){
|
||||
$request_data['ssn'] = "XXX-XX-XXXX";
|
||||
}
|
||||
|
||||
if(isset($request_data['password'])){
|
||||
$request_data['password'] = "XXXXXXX";
|
||||
}
|
||||
|
||||
if(isset($request_data['j_password']))
|
||||
{
|
||||
$request_data['j_password'] = "*********";
|
||||
}
|
||||
|
||||
return [
|
||||
'request' => [
|
||||
'url' => $url,
|
||||
'method' => $method,
|
||||
'body'=> $request_data,
|
||||
'Header'=>[
|
||||
'ContentType' => 'application/x-www-form-urlencoded'
|
||||
]
|
||||
],
|
||||
'response' => $this->data
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
// private function postIdVerification(): void
|
||||
// {
|
||||
//
|
||||
// $this->logData['action'][] = $this->prefix."POST_ID_VERIFICATION";
|
||||
//
|
||||
// $url = $this->api_base_url ."/id-verification";
|
||||
//
|
||||
// $params = [
|
||||
// 'clientKey' => $this->client_key,
|
||||
// 'trackingToken'=>$this->tracking_token,
|
||||
// 'customerToken'=>$this->customer_token,
|
||||
// 'idVerificationCriteria.answer1'=>'2003',
|
||||
// 'idVerificationCriteria.answer2'=>'ConsumerDirect',
|
||||
// 'idVerificationCriteria.answer3'=>'J. C. R. Licklider',
|
||||
// 'idVerificationCriteria.answer4'=>'123 Main',
|
||||
// 'idVerificationCriteria.answer5'=>'$450,000',
|
||||
// 'idVerificationCriteria.referenceNumber'=>$this->refference
|
||||
// ];
|
||||
//
|
||||
// $responseData = (new HttpAsForm($url))->post($params);
|
||||
//
|
||||
// if(isset($responseData['errors']) && !empty($responseData['errors'])){
|
||||
// $this->setException($responseData);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
private function identityQuestionAnswer()
|
||||
{
|
||||
$data='{
|
||||
"idVerificationCriteria": {
|
||||
"referenceNumber": "50fdbbbd-50a0-452a-8a86-9be0af826fdb",
|
||||
"question1": {
|
||||
"name": "ASSOC_ST_NAME",
|
||||
"displayName": "Which of these street names are you associated with?",
|
||||
"type": "IDMA",
|
||||
"questionId": 2389852099,
|
||||
"choiceList": {
|
||||
"choice": [
|
||||
{
|
||||
"key": "10742928663",
|
||||
"display": "138th"
|
||||
},
|
||||
{
|
||||
"key": "10742928665",
|
||||
"display": "Chamblee"
|
||||
},
|
||||
{
|
||||
"key": "10742928667",
|
||||
"display": "Moonlake"
|
||||
},
|
||||
{
|
||||
"key": "10742928669",
|
||||
"display": "Portland"
|
||||
},
|
||||
{
|
||||
"key": "10742928671",
|
||||
"display": "None of the Above"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"question2": {
|
||||
"name": "SSN_ISSUED",
|
||||
"displayName": "What state was your social security number issued (this could be the state in which you were born or had your first job)?",
|
||||
"type": "IDMA",
|
||||
"questionId": 2389852101,
|
||||
"choiceList": {
|
||||
"choice": [
|
||||
{
|
||||
"key": "10742928673",
|
||||
"display": "Colorado"
|
||||
},
|
||||
{
|
||||
"key": "10742928675",
|
||||
"display": "Florida"
|
||||
},
|
||||
{
|
||||
"key": "10742928677",
|
||||
"display": "Louisiana"
|
||||
},
|
||||
{
|
||||
"key": "10742928679",
|
||||
"display": "Massachusetts"
|
||||
},
|
||||
{
|
||||
"key": "10742928681",
|
||||
"display": "None of the Above"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"question3": {
|
||||
"name": "AUTO_TERM",
|
||||
"displayName": "What is the term (in months) of your most recent auto loan or lease?",
|
||||
"type": "IDMA",
|
||||
"questionId": 2389852103,
|
||||
"choiceList": {
|
||||
"choice": [
|
||||
{
|
||||
"key": "10742928683",
|
||||
"display": "25 - 36"
|
||||
},
|
||||
{
|
||||
"key": "10742928685",
|
||||
"display": "37 - 48"
|
||||
},
|
||||
{
|
||||
"key": "10742928687",
|
||||
"display": "49 - 60"
|
||||
},
|
||||
{
|
||||
"key": "10742928689",
|
||||
"display": "61 - 72"
|
||||
},
|
||||
{
|
||||
"key": "10742928691",
|
||||
"display": "None of the Above"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"question4": {
|
||||
"name": "ST_LOAN_PYMT",
|
||||
"displayName": "What is the monthly payment of your student loan?",
|
||||
"type": "IDMA",
|
||||
"questionId": 2389852105,
|
||||
"choiceList": {
|
||||
"choice": [
|
||||
{
|
||||
"key": "10742928693",
|
||||
"display": "$ 1 - $ 50"
|
||||
},
|
||||
{
|
||||
"key": "10742928695",
|
||||
"display": "$ 151 - $ 200"
|
||||
},
|
||||
{
|
||||
"key": "10742928697",
|
||||
"display": "$ 201 - $ 250"
|
||||
},
|
||||
{
|
||||
"key": "10742928699",
|
||||
"display": "$ 51 - $ 100"
|
||||
},
|
||||
{
|
||||
"key": "10742928701",
|
||||
"display": "None of the Above"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}';
|
||||
$returnData['data']=json_decode($data,true);
|
||||
$returnData['message']='success';
|
||||
$returnData['status_code']='100';
|
||||
// $questionAnswerList=(new SmartCredit(config('app.CLIENT_KEY')))->security_questions();
|
||||
return $returnData['data'];
|
||||
}
|
||||
|
||||
private function validateCardNumber(): void
|
||||
{
|
||||
|
||||
$this->logData['action'][] = $this->prefix."VALIDATE_CARD_NUMBER";
|
||||
|
||||
$url = $this->api_base_url ."/validate/credit-card-number";
|
||||
$params = [
|
||||
'clientKey' => $this->client_key,
|
||||
'trackingToken'=>$this->tracking_token,
|
||||
'number'=>$this->card_number
|
||||
];
|
||||
|
||||
$responseData = (new HttpAsForm($url))->get($params);
|
||||
|
||||
if(!empty($responseData['creditCardToken'])){
|
||||
$this->credit_card_token = $responseData['creditCardToken'];
|
||||
}else{
|
||||
$this->setException($responseData);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
private function updateCardNumber(): void
|
||||
{
|
||||
|
||||
$this->logData['action'][] = $this->prefix."UPDATE_CARD_NUMBER";
|
||||
|
||||
$url = $this->api_base_url ."/customer/update/credit-card";
|
||||
|
||||
$exploded = explode("/",$this->expiry);
|
||||
$expirationMonth = $exploded[0];
|
||||
$expirationYear = $exploded[1];
|
||||
|
||||
$params = [
|
||||
'clientKey' => $this->client_key,
|
||||
'trackingToken'=>$this->tracking_token,
|
||||
'customerToken'=>$this->customer_token,
|
||||
'confirmTermsBrowserIpAddress'=>$this->client_ip,
|
||||
'creditCard.cvv'=>$this->cvv,
|
||||
'creditCard.expirationMonth'=>$expirationMonth,
|
||||
'creditCard.expirationYear'=>$expirationYear,
|
||||
'isConfirmedTerms'=>true,
|
||||
'creditCard.token'=>$this->credit_card_token
|
||||
];
|
||||
|
||||
$responseData = (new HttpAsForm($url))->post($params);
|
||||
|
||||
if(!$responseData['isFinancialObligationMet']){
|
||||
$this->setException($responseData);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
private function complete($inputData): void
|
||||
{
|
||||
|
||||
$url = $this->api_base_url ."/complete";
|
||||
|
||||
$params = [
|
||||
'clientKey' => $this->client_key,
|
||||
'trackingToken'=>$inputData['trackingToken'],
|
||||
'customerToken'=>$inputData['customerToken']
|
||||
];
|
||||
|
||||
$responseData = (new HttpAsForm($url))->post($params);
|
||||
|
||||
$this->data = $responseData;
|
||||
|
||||
$params['email'] = $inputData['email'];
|
||||
|
||||
$this->logData['SMART_CREDIT_API_LOG'][$this->log_id]['COMPLETE'] = $this->prepareLogData($url,'POST',$params);
|
||||
|
||||
if(isset($responseData['errors']) && !empty($responseData['errors'])){
|
||||
$this->setException($responseData);
|
||||
}else{
|
||||
$this->planType = $responseData['planType'] ?? "";
|
||||
$this->temporaryPassword = $responseData['temporaryPassword'] ?? "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function checkIsEmailExistOnSmartCredit(){
|
||||
|
||||
$result['status'] = false;
|
||||
$result['message'] = "";
|
||||
|
||||
try {
|
||||
$this->start();
|
||||
$this->validateEmail();
|
||||
}catch (\Exception $ex){
|
||||
$this->status_code = config('constant.API_FAILED_CODE');;
|
||||
$this->message = $ex->getMessage();
|
||||
}
|
||||
|
||||
$this->logData['SMART_CREDIT_EMAIL_VALIDATION_LOG'][$this->log_id]["START"] = $this->logData['SMART_CREDIT_API_LOG'][$this->log_id]["START"];
|
||||
$this->logData['SMART_CREDIT_EMAIL_VALIDATION_LOG'][$this->log_id]["VALIDATE_EMAIL"] = $this->logData['SMART_CREDIT_API_LOG'][$this->log_id]["VALIDATE_EMAIL"];
|
||||
|
||||
unset($this->logData['SMART_CREDIT_API_LOG']);
|
||||
|
||||
$this->logData['SMART_CREDIT_EMAIL_VALIDATION_LOG'][$this->log_id]['email'] = $this->email;
|
||||
$this->logData['SMART_CREDIT_EMAIL_VALIDATION_LOG'][$this->log_id]['message'] = $this->message;
|
||||
$this->logData['SMART_CREDIT_EMAIL_VALIDATION_LOG'][$this->log_id]['status_code'] = $this->status_code;
|
||||
|
||||
if(!empty($this->data['errors'])){
|
||||
$errors = collect($this->data['errors'])->firstWhere('code','=','EMAIL_USED');
|
||||
if(!empty($errors)){
|
||||
$result['status'] = true;
|
||||
$result['message'] = "You already have an account with Smartcredit and would not open the questions";
|
||||
}
|
||||
}
|
||||
|
||||
appLog($this->logData);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function checkIsSsnExistOnSmartCredit(){
|
||||
|
||||
$result['status'] = false;
|
||||
$result['message'] = "";
|
||||
|
||||
$this->status_code = config('constant.API_SUCCESS_CODE');
|
||||
|
||||
try {
|
||||
|
||||
$this->start();
|
||||
$this->validateSsn();
|
||||
|
||||
}catch (\Exception $ex){
|
||||
$this->status_code = config('constant.API_FAILED_CODE');
|
||||
$this->message = $ex->getMessage();
|
||||
}
|
||||
|
||||
$this->logData['SMART_CREDIT_SSN_VALIDATION_LOG'][$this->log_id]["START"] = $this->logData['SMART_CREDIT_API_LOG'][$this->log_id]["START"];
|
||||
$this->logData['SMART_CREDIT_SSN_VALIDATION_LOG'][$this->log_id]["VALIDATE_SSN"] = $this->logData['SMART_CREDIT_API_LOG'][$this->log_id]["VALIDATE_SSN"];
|
||||
|
||||
unset($this->logData['SMART_CREDIT_API_LOG']);
|
||||
|
||||
$this->logData['SMART_CREDIT_SSN_VALIDATION_LOG'][$this->log_id]['email'] = $this->email;
|
||||
$this->logData['SMART_CREDIT_SSN_VALIDATION_LOG'][$this->log_id]['message'] = $this->message;
|
||||
$this->logData['SMART_CREDIT_SSN_VALIDATION_LOG'][$this->log_id]['status_code'] = $this->status_code;
|
||||
|
||||
if(!empty($this->data['errors'])){
|
||||
$errors = collect($this->data['errors'])->first();
|
||||
if(!empty($errors)){
|
||||
$result['status'] = true;
|
||||
$result['message'] = $this->message;
|
||||
}
|
||||
}
|
||||
|
||||
appLog($this->logData);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function register(): SmartCredit
|
||||
{
|
||||
try{
|
||||
$this->start();
|
||||
$this->campaign();
|
||||
$this->validateEmail();
|
||||
$this->validateSponsorCode();
|
||||
$this->create();
|
||||
$this->updateIdentity();
|
||||
// $this->updateId=1;
|
||||
// $this->updateIdentity();
|
||||
$this->getIdVerification();
|
||||
|
||||
}catch (\Exception $ex){
|
||||
$this->status_code = config('constant.API_FAILED_CODE');;
|
||||
$this->message = $ex->getMessage();
|
||||
|
||||
}
|
||||
|
||||
$this->logData['email'] = $this->email;
|
||||
$this->logData['message'] = $this->message;
|
||||
$this->logData['status_code'] = $this->status_code;
|
||||
|
||||
appLog($this->logData);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function security_question($inputData): SmartCredit{
|
||||
|
||||
try{
|
||||
$this->postIdVerification($inputData);
|
||||
$this->complete($inputData);
|
||||
}
|
||||
catch (\Exception $ex){
|
||||
$this->status_code = config('constant.API_FAILED_CODE');
|
||||
$this->message = $ex->getMessage();
|
||||
}
|
||||
|
||||
appLog($this->logData);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function security_questions(): SmartCredit{
|
||||
|
||||
try{
|
||||
$this->start();
|
||||
$this->logData['action'][] = $this->prefix."SECURITY_QUESTIONS";
|
||||
$url = $this->api_base_url . "/security-questions";
|
||||
$params = [
|
||||
'clientKey' => $this->client_key,
|
||||
'trackingToken'=>$this->tracking_token
|
||||
];
|
||||
$responseData = (new HttpAsForm($url))->get($params);
|
||||
|
||||
if(!empty($responseData['securityQuestions'])){
|
||||
$this->status_code = config('constant.API_SUCCESS_CODE');
|
||||
$this->message = __('Security Question has been gotten successfully');
|
||||
$this->data=$responseData['securityQuestions'];
|
||||
|
||||
}else{
|
||||
$this->setException($responseData);
|
||||
}
|
||||
|
||||
}catch (\Exception $ex){
|
||||
$this->status_code = config('constant.API_FAILED_CODE');
|
||||
$this->message = $ex->getMessage();
|
||||
}
|
||||
appLog($this->logData);
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function postIdVerification($inputData)
|
||||
{
|
||||
|
||||
$url = $this->api_base_url ."/id-verification";
|
||||
|
||||
$params = [
|
||||
'clientKey' => $this->client_key,
|
||||
'trackingToken'=>$inputData['trackingToken'],
|
||||
'customerToken'=>$inputData['customerToken'],
|
||||
'idVerificationCriteria.referenceNumber'=>$inputData['referenceNumber']
|
||||
];
|
||||
|
||||
if(!empty($inputData['security_question_answer'])){
|
||||
foreach ($inputData['security_question_answer'] as $key => $sqa){
|
||||
$params['idVerificationCriteria.'.$key] = $sqa['answer']['id'];
|
||||
}
|
||||
}
|
||||
|
||||
$responseData = (new HttpAsForm($url))->post($params);
|
||||
|
||||
$this->data = $responseData;
|
||||
|
||||
$params['email'] = $inputData['email'];
|
||||
|
||||
$this->logData['SMART_CREDIT_API_LOG'][$this->log_id]['POST_ID_VERIFICATION'] = $this->prepareLogData($url,'POST',$params);
|
||||
|
||||
if(isset($responseData['errors']) && !empty($responseData['errors'])){
|
||||
$this->setException($responseData);
|
||||
}
|
||||
|
||||
$this->status_code = config('constant.API_SUCCESS_CODE');
|
||||
$this->message = __('Save successfully');
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function getCustomerTokenByCredential($email,$password){
|
||||
|
||||
$this->api_base_url = (config('app.SMART_CREDIT_BASE_URL') ?? '');
|
||||
$url = $this->api_base_url . '/external-login';
|
||||
$loginType = config('app.LOGIN_TYPE') ?? 'PARTNER_API';
|
||||
$params = [
|
||||
'loginType' => $loginType,
|
||||
'j_username' => $email,
|
||||
'j_password' => $password,
|
||||
];
|
||||
$responseData = (new HttpAsForm($url))->post($params);
|
||||
|
||||
$this->data = $responseData;
|
||||
|
||||
$this->logData['SMART_CREDIT_API_LOG'][$this->log_id]['EXTERNAL_LOGIN'] = $this->prepareLogData($url,'POST',$params);
|
||||
|
||||
if ($responseData['success']) {
|
||||
$this->pws_customer_token = $responseData['customerToken'];
|
||||
}else{
|
||||
$this->setPwsException($responseData);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
private function customerAccountStatus($type){
|
||||
|
||||
$url = $this->pws_base_url . '/customer/account/status?'.'customerToken='.$this->pws_customer_token;
|
||||
$params = [
|
||||
'status' => $type,
|
||||
];
|
||||
|
||||
$responseData = (new HttpAsForm($url))->put($params,HttpAsForm::CONTENT_TYPE_JSON);
|
||||
|
||||
$this->data = $responseData;
|
||||
|
||||
$this->logData['SMART_CREDIT_API_LOG'][$this->log_id]['CUSTOMER_ACCOUNT_STATUS'] = $this->prepareLogData($url,'PUT',$params);
|
||||
|
||||
if (!empty($responseData['accountStatus'])) {
|
||||
$this->data = $responseData;
|
||||
}else{
|
||||
$this->setPwsException($responseData);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function customerSubscription($inputData)
|
||||
{
|
||||
try{
|
||||
$this->getCustomerTokenByCredential($inputData['email'],$inputData['password']);
|
||||
$this->customerAccountStatus($inputData['type']);
|
||||
}catch (\Exception $ex){
|
||||
$this->status_code = config('constant.API_FAILED_CODE');
|
||||
$this->message = $ex->getMessage();
|
||||
}
|
||||
|
||||
$this->logData['email'] = $inputData['email'];
|
||||
$this->logData['message'] = $this->message;
|
||||
$this->logData['status_code'] = $this->status_code;
|
||||
|
||||
appLog($this->logData);
|
||||
return $this;
|
||||
}
|
||||
private function setPwsException($responseData){
|
||||
$this->status_code = config('constant.API_FAILED_CODE');
|
||||
if(isset($responseData['errors']) && !empty($responseData['errors'])){
|
||||
$responseData['errors'] = current($responseData['errors']);
|
||||
$this->message = $responseData['errors']['message'];
|
||||
}else{
|
||||
$this->message = "Somethings went to wrong.";
|
||||
}
|
||||
throw new \Exception($this->message);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
442
app/Services/SmartCreditJsonToHtml.php
Normal file
442
app/Services/SmartCreditJsonToHtml.php
Normal file
@@ -0,0 +1,442 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
class SmartCreditJsonToHtml
|
||||
{
|
||||
// convert to html start
|
||||
|
||||
public function generateHtml($json_data)
|
||||
{
|
||||
$json_data = json_decode($json_data,true);
|
||||
|
||||
if(!empty($json_data['BundleComponents']['BundleComponent'][6]['TrueLinkCreditReportType'])) {
|
||||
|
||||
$json_data = $json_data['BundleComponents']['BundleComponent'][6]['TrueLinkCreditReportType'];
|
||||
|
||||
$borrower_info = $json_data['Borrower'];
|
||||
|
||||
$credit_scores = $borrower_info['CreditScore'];
|
||||
|
||||
$creditScore = [
|
||||
'title' => 'Vantage Score® 3.0 credit score',
|
||||
'TransUnion' => $credit_scores[0]['riskScore'],
|
||||
'Experian' => $credit_scores[1]['riskScore'],
|
||||
'Equifax' => $credit_scores[2]['riskScore'],
|
||||
];
|
||||
|
||||
$personal_infos = $this->personal_information_data_binding($borrower_info);
|
||||
|
||||
$consumer_statement_data_set = $this->consumer_statement_data_binding($borrower_info);
|
||||
|
||||
$summary_info_data_set = $this->summary_info_data_binding($json_data);
|
||||
|
||||
$creditor_contact_data_set = $this->creditor_contacts_data_binding($json_data);
|
||||
|
||||
$inquiries_data_set = $this->inquiries_data_binding($json_data);
|
||||
|
||||
$account_history_data = $this->account_history_data_binding($json_data['TradeLinePartition']);
|
||||
|
||||
$account_history_data_set = $this->account_history_filter_by_account_type($account_history_data);
|
||||
|
||||
$data_set = ['creditScore'=>$creditScore,'personal_infos'=>$personal_infos,'consumer_statement_data_set'=>$consumer_statement_data_set,'summary_info_data_set'=>$summary_info_data_set,'creditor_contact_data_set'=>$creditor_contact_data_set,'inquiries_data_set'=>$inquiries_data_set,'account_history_data_set'=>$account_history_data_set];
|
||||
|
||||
return $data_set;
|
||||
// $html = view('partials.credit_report.main_report', compact('creditScore', 'personal_infos','consumer_statement_data_set','summary_info_data_set', 'creditor_contact_data_set', 'inquiries_data_set', 'account_history_data_set'))->render();
|
||||
// dd($html);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private function personal_information_data_binding($borrower_info)
|
||||
{
|
||||
$personal_info_employer = [];
|
||||
$personal_info_birth = [];
|
||||
$personal_info_borrowerName = [];
|
||||
$personal_info_borrowerAddress = [];
|
||||
$personal_info_previousAddress = [];
|
||||
$personal_info_creditScore = [];
|
||||
|
||||
if(isset($borrower_info['Employer']))
|
||||
{
|
||||
$personal_info_employer = $borrower_info['Employer'];
|
||||
}
|
||||
if(isset($borrower_info['Birth']))
|
||||
{
|
||||
$personal_info_birth = $borrower_info['Birth'];
|
||||
}
|
||||
if(isset($borrower_info['BorrowerName']))
|
||||
{
|
||||
$personal_info_borrowerName = $borrower_info['BorrowerName'];
|
||||
}
|
||||
if(isset($borrower_info['BorrowerAddress']))
|
||||
{
|
||||
$personal_info_borrowerAddress = $borrower_info['BorrowerAddress'];
|
||||
}
|
||||
if(isset($borrower_info['PreviousAddress']))
|
||||
{
|
||||
$personal_info_previousAddress = $borrower_info['PreviousAddress'];
|
||||
}
|
||||
if(isset($borrower_info['CreditScore']))
|
||||
{
|
||||
$personal_info_creditScore = $borrower_info['CreditScore'];
|
||||
}
|
||||
|
||||
$personal_info_data_set = [
|
||||
'CREDIT_REPORT_DATE' =>[
|
||||
'title' => 'CREDIT REPORT DATE',
|
||||
'data' => $this->common_data_binding($personal_info_creditScore)
|
||||
],
|
||||
'NAME' =>[
|
||||
'title' => 'NAME',
|
||||
'data' => $this->data_binding_for_name($personal_info_borrowerName)
|
||||
],
|
||||
'ALSO_KNOWN_AS' =>[
|
||||
'title' => 'ALSO KNOWN AS',
|
||||
'data' => $this->data_binding_for_also_known_name($personal_info_borrowerName)
|
||||
],
|
||||
'DATE_OF_BIRTH'=>[
|
||||
'title' => 'DATE OF BIRTH',
|
||||
'data' => $this->common_data_binding($personal_info_birth)
|
||||
|
||||
],
|
||||
'CURRENT_ADDRESS'=>[
|
||||
'title' => 'CURRENT ADDRESS',
|
||||
'data' => $this->common_data_binding($personal_info_borrowerAddress)
|
||||
|
||||
],
|
||||
'PREVIOUS_ADDRESS'=>[
|
||||
'title' => 'PREVIOUS ADDRESS',
|
||||
'data' => $this->common_data_binding($personal_info_previousAddress)
|
||||
],
|
||||
'EMPLOYER'=>[
|
||||
'title' => 'EMPLOYER',
|
||||
'data' => $this->common_data_binding($personal_info_employer)
|
||||
],
|
||||
];
|
||||
|
||||
return $personal_info_data_set;
|
||||
}
|
||||
|
||||
private function consumer_statement_data_binding($borrower_info):array
|
||||
{
|
||||
$personal_info_consumer_statement = [];
|
||||
|
||||
if(isset($borrower_info['CreditStatement']))
|
||||
{
|
||||
$personal_info_consumer_statement = $borrower_info['CreditStatement'];
|
||||
}
|
||||
|
||||
return $this->common_data_binding($personal_info_consumer_statement);
|
||||
}
|
||||
|
||||
private function inquiries_data_binding($inquiryPartition)
|
||||
{
|
||||
|
||||
$inquiries_info = [];
|
||||
|
||||
if(isset($inquiryPartition['InquiryPartition']))
|
||||
{
|
||||
$inquiries_info = $inquiryPartition['InquiryPartition'];
|
||||
if(count($inquiries_info)== 1) {
|
||||
$inquiries_info['Inquiry'] = $inquiryPartition['InquiryPartition'];
|
||||
}
|
||||
}
|
||||
return $inquiries_info;
|
||||
}
|
||||
|
||||
private function creditor_contacts_data_binding($creditor_contact)
|
||||
{
|
||||
|
||||
$creditor_contacts_info = [];
|
||||
|
||||
if(isset($creditor_contact['Subscriber']))
|
||||
{
|
||||
$creditor_contacts_info = $creditor_contact['Subscriber'];
|
||||
}
|
||||
return $creditor_contacts_info;
|
||||
}
|
||||
|
||||
private function summary_info_data_binding($summary)
|
||||
{
|
||||
|
||||
$summary_info = [];
|
||||
|
||||
if(isset($summary['Summary']))
|
||||
{
|
||||
$summary_info = $summary['Summary'];
|
||||
}
|
||||
|
||||
$summary_info_data = [
|
||||
'TOTAL_ACCOUNTS' => [
|
||||
'title' => 'TOTAL ACCOUNTS',
|
||||
'TransUnion'=> $summary_info['TradelineSummary']['TransUnion']['TotalAccounts'],
|
||||
'Experian'=> $summary_info['TradelineSummary']['Experian']['TotalAccounts'],
|
||||
'Equifax'=> $summary_info['TradelineSummary']['Equifax']['TotalAccounts'],
|
||||
],
|
||||
'OPEN_ACCOUNTS' => [
|
||||
'title' => 'OPEN ACCOUNTS',
|
||||
'TransUnion'=> $summary_info['TradelineSummary']['TransUnion']['OpenAccounts'],
|
||||
'Experian'=> $summary_info['TradelineSummary']['Experian']['OpenAccounts'],
|
||||
'Equifax'=> $summary_info['TradelineSummary']['Equifax']['OpenAccounts'],
|
||||
],
|
||||
'CLOSED_ACCOUNTS' =>[
|
||||
'title' => 'CLOSED ACCOUNTS',
|
||||
'TransUnion'=> $summary_info['TradelineSummary']['TransUnion']['CloseAccounts'],
|
||||
'Experian'=> $summary_info['TradelineSummary']['Experian']['CloseAccounts'],
|
||||
'Equifax'=> $summary_info['TradelineSummary']['Equifax']['CloseAccounts'],
|
||||
],
|
||||
'DELINQUENT'=>[
|
||||
'title' => 'DELINQUENT',
|
||||
'TransUnion'=> $summary_info['TradelineSummary']['TransUnion']['DelinquentAccounts'],
|
||||
'Experian'=> $summary_info['TradelineSummary']['Experian']['DelinquentAccounts'],
|
||||
'Equifax'=> $summary_info['TradelineSummary']['Equifax']['DelinquentAccounts'],
|
||||
],
|
||||
'DEROGATORY'=>[
|
||||
'title' => 'DEROGATORY',
|
||||
'TransUnion'=> $summary_info['TradelineSummary']['TransUnion']['DerogatoryAccounts'],
|
||||
'Experian'=> $summary_info['TradelineSummary']['Experian']['DerogatoryAccounts'],
|
||||
'Equifax'=> '--',
|
||||
],
|
||||
'BALANCES'=>[
|
||||
'title' => 'BALANCES',
|
||||
'TransUnion'=> amountFormatter($summary_info['TradelineSummary']['TransUnion']['TotalBalances']),
|
||||
'Experian'=>amountFormatter($summary_info['TradelineSummary']['Experian']['TotalBalances']),
|
||||
'Equifax'=>amountFormatter($summary_info['TradelineSummary']['Equifax']['TotalBalances']),
|
||||
],
|
||||
'PAYMENTS'=>[
|
||||
'title' => 'PAYMENTS',
|
||||
'TransUnion'=>amountFormatter($summary_info['TradelineSummary']['TransUnion']['TotalMonthlyPayments']),
|
||||
'Experian'=>amountFormatter($summary_info['TradelineSummary']['Experian']['TotalMonthlyPayments']),
|
||||
'Equifax'=>amountFormatter($summary_info['TradelineSummary']['Equifax']['TotalMonthlyPayments']),
|
||||
],
|
||||
'PUBLIC_RECORDS'=>[
|
||||
'title' => 'PUBLIC RECORDS',
|
||||
'TransUnion'=> $summary_info['PublicRecordSummary']['TransUnion']['NumberOfRecords'],
|
||||
'Experian'=> $summary_info['PublicRecordSummary']['Experian']['NumberOfRecords'],
|
||||
'Equifax'=> $summary_info['PublicRecordSummary']['Equifax']['NumberOfRecords'],
|
||||
],
|
||||
'INQUIRIES'=>[
|
||||
'title' => 'INQUIRIES (2 years)',
|
||||
'TransUnion'=> $summary_info['InquirySummary']['TransUnion']['NumberInLast2Years'],
|
||||
'Experian'=> $summary_info['InquirySummary']['Experian']['NumberInLast2Years'],
|
||||
'Equifax'=> $summary_info['InquirySummary']['Equifax']['NumberInLast2Years'],
|
||||
]
|
||||
];
|
||||
|
||||
return $summary_info_data;
|
||||
}
|
||||
|
||||
private function account_history_data_binding($account_historys)
|
||||
{
|
||||
$account_history_data = [];
|
||||
|
||||
foreach ($account_historys as $account_history )
|
||||
{
|
||||
$tradelines = $account_history['Tradeline'];
|
||||
|
||||
if(isset($tradelines['subscriberCode']) && isset($tradelines['accountNumber'])
|
||||
&& isset($tradelines['creditorName'])){
|
||||
|
||||
$tradelines = [ $tradelines ];
|
||||
}
|
||||
|
||||
$data = $this->common_data_binding($tradelines);
|
||||
|
||||
$account_history_data[] = [
|
||||
'title'=> $tradelines[0]['creditorName'],
|
||||
'key_data'=>$this->sub_account_history_data_bindings(),
|
||||
"accountTypeDescription" => $account_history['accountTypeDescription'],
|
||||
"accountTypeSymbol" => $account_history['accountTypeSymbol'],
|
||||
"accountTypeAbbreviation" => $account_history['accountTypeAbbreviation'],
|
||||
'data'=> $data];
|
||||
}
|
||||
|
||||
return $account_history_data;
|
||||
}
|
||||
|
||||
private function sub_account_history_data_bindings()
|
||||
{
|
||||
$return_data = [
|
||||
|
||||
'ACCOUNT'=> [
|
||||
'title' => 'Account #',
|
||||
|
||||
],
|
||||
'HIGH_BALANCE' => [
|
||||
'title' => 'High Balance',
|
||||
],
|
||||
'LAST_VERIFIED' =>[
|
||||
'title' => 'Last Verified',
|
||||
],
|
||||
|
||||
'DATE_OF_LAST_ACTIVITY' =>[
|
||||
'title' => 'Date of Last Activity',
|
||||
],
|
||||
'DATE_REPORTED'=>[
|
||||
'title' => 'Date Reported',
|
||||
],
|
||||
'DATE_OPENED'=>[
|
||||
'title' => 'Date Opened',
|
||||
],
|
||||
|
||||
'BALANCE_OWED'=>[
|
||||
'title' => 'Balance Owed',
|
||||
],
|
||||
'CLOSED_DATE'=>[
|
||||
'title' => 'Closed Date',
|
||||
],
|
||||
'ACCOUNT_RATING'=>[
|
||||
'title' => 'Account Rating',
|
||||
],
|
||||
|
||||
'ACCOUNT_DESCRIPTION'=>[
|
||||
'title' => 'Account Description',
|
||||
],
|
||||
|
||||
'DISPUTE_STATUS'=>[
|
||||
'title' => 'Dispute Status',
|
||||
],
|
||||
'CREDITOR_TYPE'=> [
|
||||
'title' => 'Creditor Type',
|
||||
],
|
||||
|
||||
'ACCOUNT_STATUS'=>[
|
||||
'title' => 'Account Status',
|
||||
],
|
||||
'PAYMENT_STATUS'=> [
|
||||
'title' => 'Payment Status',
|
||||
],
|
||||
'CREDITOR_REMARKS'=>[
|
||||
'title' => 'Creditor Remarks',
|
||||
],
|
||||
'ORIGINAL_CREDITOR'=>[
|
||||
'title' => 'Original Creditor',
|
||||
],
|
||||
'PAYMENT_AMOUNT'=> [
|
||||
'title' => 'Payment Amount',
|
||||
],
|
||||
'LAST_PAYMENT'=>[
|
||||
'title' => 'Last Payment',
|
||||
],
|
||||
'TERM_LENGTH'=>[
|
||||
'title' => 'Term Length',
|
||||
],
|
||||
'PAST_DUE_AMOUNT'=>[
|
||||
'title' => 'Past Due Amount',
|
||||
],
|
||||
'ACCOUNT_TYPE'=>[
|
||||
'title' => 'Account Type',
|
||||
],
|
||||
'PAYMENT_FREQUENCY'=>[
|
||||
'title' => 'Payment Frequency',
|
||||
],
|
||||
'CREDIT_LIMIT'=>[
|
||||
'title' => 'Credit Limit',
|
||||
],
|
||||
];
|
||||
|
||||
return $return_data;
|
||||
}
|
||||
|
||||
private function common_data_binding($data)
|
||||
{
|
||||
$data_set = [
|
||||
'TransUnion'=> array_filter($data,function ($item){
|
||||
if($item['Source']['Bureau']['symbol'] == 'TUC'){
|
||||
return $item;
|
||||
}
|
||||
}),
|
||||
'Experian'=>array_filter($data,function ($item){
|
||||
if($item['Source']['Bureau']['symbol'] == 'EXP'){
|
||||
return $item;
|
||||
}
|
||||
}),
|
||||
'Equifax'=>array_filter($data,function ($item){
|
||||
if($item['Source']['Bureau']['symbol'] == 'EQF'){
|
||||
return $item;
|
||||
}
|
||||
}),
|
||||
];
|
||||
|
||||
return $data_set;
|
||||
}
|
||||
private function data_binding_for_name($data)
|
||||
{
|
||||
$data_set = [
|
||||
'TransUnion'=> array_filter($data,function ($item){
|
||||
if($item['Source']['Bureau']['symbol'] == 'TUC' && $item['NameType']['symbol'] == '1'){
|
||||
return $item;
|
||||
}
|
||||
}),
|
||||
'Experian'=>array_filter($data,function ($item){
|
||||
if($item['Source']['Bureau']['symbol'] == 'EXP' && $item['NameType']['symbol'] == '1'){
|
||||
return $item;
|
||||
}
|
||||
}),
|
||||
'Equifax'=>array_filter($data,function ($item){
|
||||
if($item['Source']['Bureau']['symbol'] == 'EQF' && $item['NameType']['symbol'] == '1'){
|
||||
return $item;
|
||||
}
|
||||
}),
|
||||
];
|
||||
|
||||
return $data_set;
|
||||
}
|
||||
private function data_binding_for_also_known_name($data)
|
||||
{
|
||||
$data_set = [
|
||||
'TransUnion'=> array_filter($data,function ($item){
|
||||
if($item['Source']['Bureau']['symbol'] == 'TUC' && $item['NameType']['symbol'] == 'A'){
|
||||
return $item;
|
||||
}
|
||||
}),
|
||||
'Experian'=>array_filter($data,function ($item){
|
||||
if($item['Source']['Bureau']['symbol'] == 'EXP' && $item['NameType']['symbol'] == 'A'){
|
||||
return $item;
|
||||
}
|
||||
}),
|
||||
'Equifax'=>array_filter($data,function ($item){
|
||||
if($item['Source']['Bureau']['symbol'] == 'EQF' && $item['NameType']['symbol'] == 'A'){
|
||||
return $item;
|
||||
}
|
||||
}),
|
||||
];
|
||||
|
||||
return $data_set;
|
||||
}
|
||||
private function account_history_filter_by_account_type($data){
|
||||
|
||||
$data_set = [
|
||||
'Revolving'=> array_filter($data,function ($item){
|
||||
if($item['accountTypeSymbol'] == 'R'){
|
||||
return $item;
|
||||
}
|
||||
}),
|
||||
'Installment' => array_filter($data,function ($item){
|
||||
if($item['accountTypeSymbol'] == 'I'){
|
||||
return $item;
|
||||
}
|
||||
}),
|
||||
'Line_of_credit' => array_filter($data,function ($item){
|
||||
if($item['accountTypeSymbol'] == 'C'){
|
||||
return $item;
|
||||
}
|
||||
}),
|
||||
'Collection' => array_filter($data,function ($item){
|
||||
if($item['accountTypeSymbol'] == 'Y'){
|
||||
return $item;
|
||||
}
|
||||
}),
|
||||
'Other' => array_filter($data,function ($item){
|
||||
if($item['accountTypeSymbol'] == 'O'){
|
||||
return $item;
|
||||
}
|
||||
}),
|
||||
|
||||
];
|
||||
|
||||
return $data_set;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
107
app/Services/UploadMedia.php
Normal file
107
app/Services/UploadMedia.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
class UploadMedia
|
||||
{
|
||||
private $user_request = null;
|
||||
|
||||
public function __construct($request)
|
||||
{
|
||||
$this->user_request = $request;
|
||||
}
|
||||
|
||||
public function uploadmedia()
|
||||
{
|
||||
|
||||
$auth_id = auth()->id();
|
||||
if (isset($this->user_request['uploadmedia']['identification'])) {
|
||||
$rtg_letter_image_id = 1;
|
||||
$image_path = 'identification';
|
||||
$this->uploadOrupdateMeadiaFile($image_path, $auth_id, $rtg_letter_image_id);
|
||||
}
|
||||
|
||||
if (isset($this->user_request['uploadmedia']['mail_doc'])) {
|
||||
$rtg_letter_image_id = 2;
|
||||
$image_path = 'mail_doc';
|
||||
$this->uploadOrupdateMeadiaFile($image_path, $auth_id, $rtg_letter_image_id);
|
||||
}
|
||||
|
||||
if (isset($this->user_request['uploadmedia']['ssn'])) {
|
||||
$rtg_letter_image_id = 3;
|
||||
$image_path = 'ssn';
|
||||
$this->uploadOrupdateMeadiaFile($image_path, $auth_id, $rtg_letter_image_id);
|
||||
}
|
||||
|
||||
if (isset($this->user_request['uploadmedia']['state_photo_id'])) {
|
||||
$rtg_letter_image_id = 4;
|
||||
$image_path = 'state_photo_id';
|
||||
$this->uploadOrupdateMeadiaFile($image_path, $auth_id, $rtg_letter_image_id);
|
||||
}
|
||||
|
||||
if (isset($this->user_request['uploadmedia']['notarized_letter'])) {
|
||||
$rtg_letter_image_id = 5;
|
||||
$image_path = 'notarized_letter';
|
||||
$this->uploadOrupdateMeadiaFile($image_path, $auth_id, $rtg_letter_image_id);
|
||||
}
|
||||
|
||||
if (isset($this->user_request['uploadmedia']['cr_report'])) {
|
||||
$rtg_letter_image_id = 6;
|
||||
$image_path = 'cr_report';
|
||||
$this->uploadOrupdateMeadiaFile($image_path, $auth_id, $rtg_letter_image_id);
|
||||
}
|
||||
|
||||
if (isset($this->user_request['uploadmedia']['trouble_mark_file'])) {
|
||||
$rtg_letter_image_id = 7;
|
||||
$image_path = 'trouble_mark_file';
|
||||
$this->uploadOrupdateMeadiaFile($image_path, $auth_id, $rtg_letter_image_id);
|
||||
}
|
||||
|
||||
if (isset($this->user_request['uploadmedia']['item_challenge_file'])) {
|
||||
$rtg_letter_image_id = 8;
|
||||
$image_path = 'item_challenge_file';
|
||||
$this->uploadOrupdateMeadiaFile($image_path, $auth_id, $rtg_letter_image_id);
|
||||
}
|
||||
|
||||
if (isset($this->user_request['uploadmedia']['profile_pic'])) {
|
||||
$rtg_letter_image_id = 9;
|
||||
$image_path = 'profile_pic';
|
||||
$this->uploadOrupdateMeadiaFile($image_path, $auth_id, $rtg_letter_image_id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function uploadOrupdateMeadiaFile($image_path, $auth_id, $rtg_letter_image_id)
|
||||
{
|
||||
|
||||
if (!empty($this->user_request->file('uploadmedia.'.$image_path))) {
|
||||
$uploadMediaObj = app(\App\Models\Uploadmedia::class);
|
||||
$clasue['user_id'] = $auth_id;
|
||||
$clasue['image_type_id'] = $rtg_letter_image_id;
|
||||
$uploadmedia = $uploadMediaObj->where($clasue)->first();
|
||||
//$this->user_request['uploadmedia'][$image_path]
|
||||
$file = $this->user_request->file('uploadmedia.'.$image_path);
|
||||
$image_data = imageFileRotate($this->user_request->file('uploadmedia.'.$image_path));
|
||||
|
||||
$file_name = time()."_".removeAnySpaces($file->getClientOriginalName(),'_');
|
||||
|
||||
$file_path = config('constant.UPLOAD_MEDIA_PATH').DIRECTORY_SEPARATOR.$auth_id;
|
||||
|
||||
if (empty($uploadmedia)) {
|
||||
$uploadMediaObj->create([
|
||||
'user_id'=>$auth_id,
|
||||
'image_type_id'=>$rtg_letter_image_id,
|
||||
'image_path'=>$file_name
|
||||
]);
|
||||
uploadFile($file_path,$file_name,$image_data);
|
||||
} else {
|
||||
deleteFile($file_path.DIRECTORY_SEPARATOR.$uploadmedia->image_path);
|
||||
uploadFile($file_path,$file_name,$image_data);
|
||||
$uploadmedia->update(['image_path'=>$file_name]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
23
app/Services/ViewExport.php
Normal file
23
app/Services/ViewExport.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Maatwebsite\Excel\Concerns\FromView;
|
||||
|
||||
class ViewExport implements FromView
|
||||
{
|
||||
public function __construct($data,$view)
|
||||
{
|
||||
$this->data = $data;
|
||||
$this->view = $view;
|
||||
|
||||
}
|
||||
|
||||
public function view(): View
|
||||
{
|
||||
//dd($this->data);
|
||||
return view($this->view, $this->data);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user