app\models\PaymentMethod::lookupBankData PHP Method

lookupBankData() public static method

public static lookupBankData ( $routingNumber ) : mixed | null | stdClass | string
$routingNumber
return mixed | null | stdClass | string
    public static function lookupBankData($routingNumber)
    {
        $cached = Cache::get('bankData:' . $routingNumber);
        if ($cached != null) {
            return $cached == false ? null : $cached;
        }
        $dataPath = base_path('vendor/gatepay/FedACHdir/FedACHdir.txt');
        if (!file_exists($dataPath) || !($size = filesize($dataPath))) {
            return 'Invalid data file';
        }
        $lineSize = 157;
        $numLines = $size / $lineSize;
        if ($numLines % 1 != 0) {
            // The number of lines should be an integer
            return 'Invalid data file';
        }
        // Format: http://www.sco.ca.gov/Files-21C/Bank_Master_Interface_Information_Package.pdf
        $file = fopen($dataPath, 'r');
        // Binary search
        $low = 0;
        $high = $numLines - 1;
        while ($low <= $high) {
            $mid = floor(($low + $high) / 2);
            fseek($file, $mid * $lineSize);
            $thisNumber = fread($file, 9);
            if ($thisNumber > $routingNumber) {
                $high = $mid - 1;
            } else {
                if ($thisNumber < $routingNumber) {
                    $low = $mid + 1;
                } else {
                    $data = new \stdClass();
                    $data->routing_number = $thisNumber;
                    fseek($file, 26, SEEK_CUR);
                    $data->name = trim(fread($file, 36));
                    $data->address = trim(fread($file, 36));
                    $data->city = trim(fread($file, 20));
                    $data->state = fread($file, 2);
                    $data->zip = fread($file, 5) . '-' . fread($file, 4);
                    $data->phone = fread($file, 10);
                    break;
                }
            }
        }
        if (!empty($data)) {
            Cache::put('bankData:' . $routingNumber, $data, 5);
            return $data;
        } else {
            Cache::put('bankData:' . $routingNumber, false, 5);
            return null;
        }
    }

Usage Example

コード例 #1
0
 public function columns()
 {
     return [['invoice_number', function ($model) {
         if (!Auth::user()->can('viewByOwner', [ENTITY_INVOICE, $model->invoice_user_id])) {
             return $model->invoice_number;
         }
         return link_to("invoices/{$model->invoice_public_id}/edit", $model->invoice_number, ['class' => Utils::getEntityRowClass($model)])->toHtml();
     }], ['client_name', function ($model) {
         if (!Auth::user()->can('viewByOwner', [ENTITY_CLIENT, $model->client_user_id])) {
             return Utils::getClientDisplayName($model);
         }
         return $model->client_public_id ? link_to("clients/{$model->client_public_id}", Utils::getClientDisplayName($model))->toHtml() : '';
     }, !$this->hideClient], ['transaction_reference', function ($model) {
         return $model->transaction_reference ? $model->transaction_reference : '<i>' . trans('texts.manual_entry') . '</i>';
     }], ['payment_type', function ($model) {
         return $model->payment_type && !$model->last4 ? $model->payment_type : ($model->account_gateway_id ? $model->gateway_name : '');
     }], ['payment_type_id', function ($model) {
         $code = str_replace(' ', '', strtolower($model->payment_type));
         $card_type = trans('texts.card_' . $code);
         if ($model->payment_type_id != PAYMENT_TYPE_ACH) {
             if ($model->last4) {
                 $expiration = Utils::fromSqlDate($model->expiration, false)->format('m/y');
                 return '<img height="22" src="' . URL::to('/images/credit_cards/' . $code . '.png') . '" alt="' . htmlentities($card_type) . '">&nbsp; &bull;&bull;&bull;' . $model->last4 . ' ' . $expiration;
             } elseif ($model->email) {
                 return $model->email;
             }
         } elseif ($model->last4) {
             if ($model->bank_name) {
                 $bankName = $model->bank_name;
             } else {
                 $bankData = PaymentMethod::lookupBankData($model->routing_number);
                 if ($bankData) {
                     $bankName = $bankData->name;
                 }
             }
             if (!empty($bankName)) {
                 return $bankName . '&nbsp; &bull;&bull;&bull;' . $model->last4;
             } elseif ($model->last4) {
                 return '<img height="22" src="' . URL::to('/images/credit_cards/ach.png') . '" alt="' . htmlentities($card_type) . '">&nbsp; &bull;&bull;&bull;' . $model->last4;
             }
         }
     }], ['amount', function ($model) {
         return Utils::formatMoney($model->amount, $model->currency_id, $model->country_id);
     }], ['payment_date', function ($model) {
         if ($model->is_deleted) {
             return Utils::dateToString($model->payment_date);
         } else {
             return link_to("payments/{$model->public_id}/edit", Utils::dateToString($model->payment_date))->toHtml();
         }
     }], ['payment_status_name', function ($model) {
         return self::getStatusLabel($model);
     }]];
 }
All Usage Examples Of app\models\PaymentMethod::lookupBankData