├── .env.example ├── LICENSE ├── codeception.yml ├── composer.json └── src ├── Client.php ├── Comgate.php ├── Config.php ├── Entity ├── Codes │ ├── CategoryCode.php │ ├── CountryCode.php │ ├── CurrencyCode.php │ ├── DeliveryCode.php │ ├── LangCode.php │ ├── PaymentMethodCode.php │ ├── PaymentStatusCode.php │ ├── RequestCode.php │ └── TypeCode.php ├── Method.php ├── Money.php ├── MotoPayment.php ├── Payment.php ├── PaymentCard.php ├── PaymentInfo.php ├── PaymentNotification.php ├── Refund.php ├── Request │ ├── AboSingleTransferRequest.php │ ├── CsvSingleTransferRequest.php │ ├── IRequest.php │ ├── MethodsRequest.php │ ├── MotoPaymentCreateRequest.php │ ├── PaymentCancelRequest.php │ ├── PaymentCreateRequest.php │ ├── PaymentRefundRequest.php │ ├── PaymentStatusRequest.php │ ├── PreauthCancelRequest.php │ ├── PreauthCaptureRequest.php │ ├── PublicCryptoKeyRequest.php │ ├── RecurringPaymentRequest.php │ ├── SimulationRequest.php │ ├── SingleTransferRequest.php │ └── TransferListRequest.php ├── Response │ ├── AboSingleTransferResponse.php │ ├── CsvSingleTransferResponse.php │ ├── FileResponse.php │ ├── MethodsResponse.php │ ├── MotoPaymentCreateResponse.php │ ├── PaymentCancelResponse.php │ ├── PaymentCreateResponse.php │ ├── PaymentStatusResponse.php │ ├── PreauthCancelResponse.php │ ├── PreauthCaptureResponse.php │ ├── PublicCryptoKeyResponse.php │ ├── RecurringPaymentResponse.php │ ├── RefundResponse.php │ ├── SimulationResponse.php │ ├── SingleTransferResponse.php │ └── TransferListResponse.php └── Transfer.php ├── Exception ├── Api │ ├── MissingParamException.php │ ├── PaymentNotFoundException.php │ └── PreauthException.php ├── ApiException.php ├── Logical │ └── ParamIsNotSetException.php ├── LogicalException.php ├── Runtime │ └── ComgateException.php └── RuntimeException.php ├── Http ├── ITransport.php ├── PsrResponse.php ├── PsrStream.php ├── Query.php ├── Response.php └── Transport.php ├── Logging ├── FileLogger.php └── StdoutLogger.php └── Utils └── Helpers.php /.env.example: -------------------------------------------------------------------------------- 1 | API_MERCHANT=112233 2 | API_SECRET=foobarfoobaz 3 | API_URL=https://payments.comgate.cz/v1.0/ 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Comgate a.s. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /codeception.yml: -------------------------------------------------------------------------------- 1 | namespace: Tests 2 | support_namespace: Support 3 | paths: 4 | tests: tests 5 | output: tests/_output 6 | data: tests/Support/Data 7 | support: tests/Support 8 | envs: tests/_envs 9 | actor_suffix: Tester 10 | extensions: 11 | enabled: 12 | - Codeception\Extension\RunFailed 13 | bootstrap: _bootstrap.php 14 | coverage: 15 | enabled: true 16 | show_uncovered: true 17 | include: 18 | - src/* 19 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "comgate/sdk", 3 | "description": "Comgate PHP SDK", 4 | "keywords": [ 5 | "comgate", 6 | "payment", 7 | "php", 8 | "api", 9 | "money" 10 | ], 11 | "type": "library", 12 | "license": "MIT", 13 | "homepage": "https://github.com/comgate/sdk-php", 14 | "authors": [ 15 | { 16 | "name": "Milan Felix Šulc", 17 | "homepage": "https://f3l1x.io" 18 | } 19 | ], 20 | "require": { 21 | "php": "^7.3 || ^8.0", 22 | "psr/log": "^1.1|^2|^3", 23 | "psr/http-message": "^1.0.1|^2", 24 | "phpseclib/phpseclib": "^3.0" 25 | }, 26 | "require-dev": { 27 | "codeception/codeception": "^4.2 || ^5.0", 28 | "codeception/module-asserts": "^1.3 || ^2.0 || ^3.0", 29 | "codeception/module-phpbrowser": "^1.0 || ^2.0", 30 | "codeception/stub": "^3.0 || ^4.0", 31 | "friendsofphp/php-cs-fixer": "^3.0", 32 | "mockery/mockery": "^1.5", 33 | "phpstan/phpstan": "^1.11", 34 | "phpstan/phpstan-deprecation-rules": "^1.1", 35 | "phpstan/phpstan-strict-rules": "^1.5", 36 | "squizlabs/php_codesniffer": "^3.7", 37 | "vlucas/phpdotenv": "^5.5" 38 | }, 39 | "autoload": { 40 | "psr-4": { 41 | "Comgate\\SDK\\": "src/" 42 | } 43 | }, 44 | "autoload-dev": { 45 | "psr-4": { 46 | "Tests\\Cases\\": "tests/cases", 47 | "Tests\\Toolkit\\": "tests/toolkit", 48 | "Tests\\PHPStanRule\\": "tests/PHPStanRule" 49 | } 50 | }, 51 | "minimum-stability": "dev", 52 | "prefer-stable": true, 53 | "config": { 54 | "sort-packages": true, 55 | "allow-plugins": { 56 | "dealerdirect/phpcodesniffer-composer-installer": true 57 | } 58 | }, 59 | "extra": { 60 | "branch-alias": { 61 | "dev-master": "0.2.x-dev" 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/Client.php: -------------------------------------------------------------------------------- 1 | transport = $transport; 54 | } 55 | 56 | public function createPayment(Payment $payment): PaymentCreateResponse 57 | { 58 | $paymentCreateRequest = new PaymentCreateRequest($payment); 59 | $paymentCreateResponse = $this->transport->post($paymentCreateRequest->getUrn(), 60 | $paymentCreateRequest->toArray()); 61 | return new PaymentCreateResponse($paymentCreateResponse); 62 | } 63 | 64 | public function getStatus(string $transId): PaymentStatusResponse 65 | { 66 | $paymentStatusRequest = new PaymentStatusRequest($transId); 67 | $statusResponse = $this->transport->post($paymentStatusRequest->getUrn(), $paymentStatusRequest->toArray()); 68 | return new PaymentStatusResponse($statusResponse); 69 | } 70 | 71 | public function getMethods(MethodsRequest $methodsRequest = null): MethodsResponse 72 | { 73 | if (($methodsRequest instanceof MethodsRequest) === false) { 74 | $methodsRequest = new MethodsRequest(); 75 | } 76 | 77 | $methodsResponse = $this->transport->post($methodsRequest->getUrn(), $methodsRequest->toArray()); 78 | 79 | return new MethodsResponse($methodsResponse); 80 | } 81 | 82 | public function cancelPayment(string $transId): PaymentCancelResponse 83 | { 84 | $cancelPaymentRequest = new PaymentCancelRequest($transId); 85 | $cancelResponse = $this->transport->post($cancelPaymentRequest->getUrn(), $cancelPaymentRequest->toArray()); 86 | return new PaymentCancelResponse($cancelResponse); 87 | } 88 | 89 | public function capturePreauth(string $transId, Money $amount): PreauthCaptureResponse 90 | { 91 | $capturePreauthRequest = new PreauthCaptureRequest($transId, $amount); 92 | $captureResponse = $this->transport->post($capturePreauthRequest->getUrn(), $capturePreauthRequest->toArray()); 93 | return new PreauthCaptureResponse($captureResponse); 94 | } 95 | 96 | public function cancelPreauth(string $transId): PreauthCancelResponse 97 | { 98 | $cancelPreauthRequest = new PreauthCancelRequest($transId); 99 | $cancelResponse = $this->transport->post($cancelPreauthRequest->getUrn(), $cancelPreauthRequest->toArray()); 100 | return new PreauthCancelResponse($cancelResponse); 101 | } 102 | 103 | public function refundPayment(Refund $refund): RefundResponse 104 | { 105 | $refundRequest = new PaymentRefundRequest($refund); 106 | $refundResponse = $this->transport->post($refundRequest->getUrn(), $refundRequest->toArray()); 107 | return new RefundResponse($refundResponse); 108 | } 109 | 110 | public function initRecurringPayment(Payment $payment): RecurringPaymentResponse 111 | { 112 | $recurringRequest = new RecurringPaymentRequest($payment); 113 | $recurringResponse = $this->transport->post($recurringRequest->getUrn(), $recurringRequest->toArray()); 114 | return new RecurringPaymentResponse($recurringResponse); 115 | } 116 | 117 | /** 118 | * 119 | * @param array $params 120 | * @return SimulationResponse 121 | */ 122 | public function simulation(array $params): SimulationResponse 123 | { 124 | $simulationRequest = new SimulationRequest($params); 125 | $simulationResponse = $this->transport->post($simulationRequest->getUrn(), $simulationRequest->toArray()); 126 | return new SimulationResponse($simulationResponse); 127 | } 128 | 129 | /** 130 | * @param DateTimeInterface $date 131 | * @param bool $test 132 | * @return TransferListResponse 133 | * @see https://help.comgate.cz/docs/api-protokol#seznam-p%C5%99evod%C5%AF-v-r%C3%A1mci-dne 134 | */ 135 | public function transferList(DateTimeInterface $date, bool $test): TransferListResponse 136 | { 137 | $transferListRequest = new TransferListRequest($date, $test); 138 | $transferListResponse = $this->transport->post($transferListRequest->getUrn(), $transferListRequest->toArray()); 139 | return new TransferListResponse($transferListResponse); 140 | } 141 | 142 | public function singleTransfer(int $transferId, bool $test): SingleTransferResponse 143 | { 144 | $singleTransferRequest = new SingleTransferRequest($transferId, $test); 145 | $singleTransferResponse = $this->transport->post($singleTransferRequest->getUrn(), 146 | $singleTransferRequest->toArray()); 147 | return new SingleTransferResponse($singleTransferResponse); 148 | } 149 | 150 | public function csvSingleTransfer(string $transferId, bool $test): CsvSingleTransferResponse 151 | { 152 | $csvSingleTransferRequest = new CsvSingleTransferRequest($transferId, $test); 153 | $csvSingleTransferResponse = $this->transport->post($csvSingleTransferRequest->getUrn(), 154 | $csvSingleTransferRequest->toArray()); 155 | return new CsvSingleTransferResponse($csvSingleTransferResponse); 156 | } 157 | 158 | public function aboSingleTransfer(string $transferId, bool $test, string $type, string $encoding): AboSingleTransferResponse 159 | { 160 | $aboSingleTransferRequest = new AboSingleTransferRequest($transferId, $test, $type, $encoding); 161 | $aboSingleTransferResponse = $this->transport->post($aboSingleTransferRequest->getUrn(), 162 | $aboSingleTransferRequest->toArray()); 163 | return new AboSingleTransferResponse($aboSingleTransferResponse); 164 | } 165 | 166 | /** 167 | * Method only for specific merchant, who are PCI DSS certified 168 | * @param Payment $payment 169 | * @param PaymentCard $paymentCard 170 | * @return MotoPaymentCreateResponse|null 171 | * @throws Exception 172 | */ 173 | public function createMotoPayment(Payment $payment, PaymentCard $paymentCard): ?MotoPaymentCreateResponse 174 | { 175 | $publicCryptoKeyRequest = new PublicCryptoKeyRequest(); 176 | $publicCryptoKeyResponse = new PublicCryptoKeyResponse($this->transport->post($publicCryptoKeyRequest->getUrn(), $publicCryptoKeyRequest->toArray())); 177 | 178 | $publicJkwKey = null; 179 | $jwkData = json_decode(base64_decode($publicCryptoKeyResponse->getKey(), true), true); 180 | if (isset($jwkData['jwk'])){ 181 | $publicJkwKey = json_encode($jwkData['jwk']); 182 | } 183 | if (is_null($publicJkwKey) || $publicJkwKey == '') { 184 | throw new Exception('No public encryption key for encrypting card data'); 185 | } 186 | 187 | /** @var \phpseclib3\Crypt\RSA\PublicKey $rsa */ 188 | $rsa = RSA::loadPublicKey($publicJkwKey); 189 | 190 | $motoPayment = new MotoPayment(); 191 | $motoPayment->setParams($payment->getParams()); 192 | 193 | if (!is_null($paymentCard->getCardNumber()) && $paymentCard->getCardNumber() !== '') { 194 | $motoPayment->setEncryptedCardNumber(base64_encode($rsa->encrypt($paymentCard->getCardNumber()))); 195 | } else { 196 | throw new Exception('No card number for encrypting card data'); 197 | } 198 | 199 | if (!is_null($paymentCard->getCardExpiration()) && $paymentCard->getCardExpiration() !== '') { 200 | $motoPayment->setEncryptedCardExpiration(base64_encode($rsa->encrypt($paymentCard->getCardExpiration()))); 201 | } else { 202 | throw new Exception('No card expiration for encrypting card data'); 203 | } 204 | 205 | if (!is_null($paymentCard->getCardCvv()) && $paymentCard->getCardCvv() !== '') { 206 | $motoPayment->setEncryptedCardCvv(base64_encode($rsa->encrypt($paymentCard->getCardCvv()))); 207 | } 208 | 209 | $motoPaymentCreateRequest = new MotoPaymentCreateRequest($motoPayment); 210 | $motoPaymentCreateResponse = $this->transport->post($motoPaymentCreateRequest->getUrn(), $motoPaymentCreateRequest->toArray()); 211 | return new MotoPaymentCreateResponse($motoPaymentCreateResponse); 212 | } 213 | 214 | /** 215 | * @return ITransport 216 | */ 217 | public function getTransport(): ITransport 218 | { 219 | return $this->transport; 220 | } 221 | 222 | /** 223 | * @param ITransport $transport 224 | * @return Client 225 | */ 226 | public function setTransport(ITransport $transport): Client 227 | { 228 | $this->transport = $transport; 229 | return $this; 230 | } 231 | } 232 | 233 | -------------------------------------------------------------------------------- /src/Comgate.php: -------------------------------------------------------------------------------- 1 | url = Config::URL; 35 | 36 | return $self; 37 | } 38 | 39 | /** 40 | * @return static 41 | */ 42 | public function setUrl(string $url): self 43 | { 44 | $this->url = $url; 45 | 46 | return $this; 47 | } 48 | 49 | /** 50 | * @return static 51 | */ 52 | public function setMerchant(string $merchant): self 53 | { 54 | $this->merchant = $merchant; 55 | 56 | return $this; 57 | } 58 | 59 | /** 60 | * @return static 61 | */ 62 | public function setSecret(string $secret): self 63 | { 64 | $this->secret = $secret; 65 | 66 | return $this; 67 | } 68 | 69 | /** 70 | * @return static 71 | */ 72 | public function setLogger(LoggerInterface $logger): self 73 | { 74 | $this->logger = $logger; 75 | 76 | return $this; 77 | } 78 | 79 | public function createClient(): Client 80 | { 81 | return new Client($this->createTransport()); 82 | } 83 | 84 | protected function createConfig(): Config 85 | { 86 | return new Config($this->merchant, $this->secret, $this->url); 87 | } 88 | 89 | protected function createTransport(): ITransport 90 | { 91 | return new Transport($this->createConfig(), $this->logger); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/Config.php: -------------------------------------------------------------------------------- 1 | merchant = $merchant; 22 | $this->secret = $secret; 23 | $this->setUrl($url); 24 | } 25 | 26 | public function getMerchant(): string 27 | { 28 | return $this->merchant; 29 | } 30 | 31 | public function getSecret(): string 32 | { 33 | return $this->secret; 34 | } 35 | 36 | /** 37 | * @return string 38 | */ 39 | public function getUrl(): string 40 | { 41 | return $this->url; 42 | } 43 | 44 | /** 45 | * @param string $merchant 46 | * @return Config 47 | */ 48 | public function setMerchant(string $merchant): Config 49 | { 50 | $this->merchant = $merchant; 51 | return $this; 52 | } 53 | 54 | /** 55 | * @param string $secret 56 | * @return Config 57 | */ 58 | public function setSecret(string $secret): Config 59 | { 60 | $this->secret = $secret; 61 | return $this; 62 | } 63 | 64 | /** 65 | * @param string $url 66 | */ 67 | public function setUrl(string $url): void 68 | { 69 | $this->url = rtrim($url, "/") . "/"; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Entity/Codes/CategoryCode.php: -------------------------------------------------------------------------------- 1 | $methodData 22 | * @return $this 23 | */ 24 | public function fromArray(array $methodData): self 25 | { 26 | $this->setId($methodData['id']) 27 | ->setName($methodData['name']) 28 | ->setDescription($methodData['description']) 29 | ->setLogo($methodData['logo']) 30 | ->setGroup($methodData['group']) 31 | ->setGroupLabel($methodData['groupLabel']); 32 | 33 | return $this; 34 | } 35 | 36 | /** 37 | * @return array 38 | */ 39 | public function toArray(): array 40 | { 41 | return [ 42 | 'id' => $this->getId(), 43 | 'name' => $this->getName(), 44 | 'description' => $this->getDescription(), 45 | 'logo' => $this->getLogo(), 46 | 'group' => $this->getGroup(), 47 | 'groupLabel' => $this->getGroupLabel(), 48 | ]; 49 | } 50 | 51 | /** 52 | * @return string 53 | */ 54 | public function getId(): string 55 | { 56 | return $this->id; 57 | } 58 | 59 | /** 60 | * @param string $id 61 | * @return Method 62 | */ 63 | public function setId(string $id): self 64 | { 65 | $this->id = $id; 66 | return $this; 67 | } 68 | 69 | /** 70 | * @return string 71 | */ 72 | public function getName(): string 73 | { 74 | return $this->name; 75 | } 76 | 77 | /** 78 | * @param string $name 79 | * @return Method 80 | */ 81 | public function setName(string $name): self 82 | { 83 | $this->name = $name; 84 | return $this; 85 | } 86 | 87 | /** 88 | * @return string 89 | */ 90 | public function getDescription(): string 91 | { 92 | return $this->description; 93 | } 94 | 95 | /** 96 | * @param string $description 97 | * @return Method 98 | */ 99 | public function setDescription(string $description): self 100 | { 101 | $this->description = $description; 102 | return $this; 103 | } 104 | 105 | /** 106 | * @return string 107 | */ 108 | public function getLogo(): string 109 | { 110 | return $this->logo; 111 | } 112 | 113 | /** 114 | * @param string $logo 115 | * @return Method 116 | */ 117 | public function setLogo(string $logo): self 118 | { 119 | $this->logo = $logo; 120 | return $this; 121 | } 122 | 123 | public function getGroup(): string 124 | { 125 | return $this->group; 126 | } 127 | 128 | public function setGroup(string $group): Method 129 | { 130 | $this->group = $group; 131 | return $this; 132 | } 133 | 134 | public function getGroupLabel(): string 135 | { 136 | return $this->groupLabel; 137 | } 138 | 139 | public function setGroupLabel(string $groupLabel): Method 140 | { 141 | $this->groupLabel = $groupLabel; 142 | return $this; 143 | } 144 | 145 | } 146 | -------------------------------------------------------------------------------- /src/Entity/Money.php: -------------------------------------------------------------------------------- 1 | value = $value; 16 | } 17 | 18 | /** 19 | * @param mixed $money 20 | * @return static 21 | */ 22 | public static function of($money): self 23 | { 24 | if (is_int($money)) { 25 | return self::ofInt($money); 26 | } 27 | 28 | if (is_float($money)) { 29 | return self::ofFloat($money); 30 | } 31 | 32 | if ($money instanceof static) { 33 | return $money; 34 | } 35 | 36 | throw new LogicalException(sprintf('Only int|float|Money is supported, %s given.', gettype($money))); 37 | } 38 | 39 | /** 40 | * @return static 41 | */ 42 | public static function ofInt(int $money): self 43 | { 44 | return new static($money * 100); 45 | } 46 | 47 | /** 48 | * @return static 49 | */ 50 | public static function ofFloat(float $money): self 51 | { 52 | if ($money !== round($money, 2)) { 53 | throw new LogicalException('The price must be a maximum of two valid decimal numbers.'); 54 | } 55 | 56 | return new static((int) round($money * 100)); 57 | } 58 | 59 | /** 60 | * @return static 61 | */ 62 | public static function ofCents(int $money): self 63 | { 64 | return new static($money); 65 | } 66 | 67 | public function get(): int 68 | { 69 | return $this->value; 70 | } 71 | 72 | public function getReal(): float 73 | { 74 | return $this->value / 100; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/Entity/MotoPayment.php: -------------------------------------------------------------------------------- 1 | params['encryptedCardNumber'] = ''; 10 | $this->params['encryptedCardExpiration'] = ''; 11 | $this->params['encryptedCardCvv'] = ''; 12 | } 13 | 14 | public function getEncryptedCardNumber(): ?string 15 | { 16 | return (string) $this->getParamWithoutMoney('encryptedCardNumber'); 17 | } 18 | 19 | public function setEncryptedCardNumber(string $encryptedCardNumber): self 20 | { 21 | $this->setParam('encryptedCardNumber', $encryptedCardNumber); 22 | 23 | return $this; 24 | } 25 | 26 | public function getEncryptedCardExpiration(): ?string 27 | { 28 | return (string) $this->getParamWithoutMoney('encryptedCardExpiration'); 29 | } 30 | 31 | public function setEncryptedCardExpiration(string $encryptedCardExpiration): self 32 | { 33 | $this->setParam('encryptedCardExpiration', $encryptedCardExpiration); 34 | 35 | return $this; 36 | } 37 | 38 | public function getEncryptedCardCvv(): ?string 39 | { 40 | return (string) $this->getParamWithoutMoney('encryptedCardCvv'); 41 | } 42 | 43 | public function setEncryptedCardCvv(string $encryptedCardCvv): self 44 | { 45 | $this->setParam('encryptedCardCvv', $encryptedCardCvv); 46 | 47 | return $this; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Entity/Payment.php: -------------------------------------------------------------------------------- 1 | > 14 | */ 15 | protected $params = [ 16 | 'test' => false, 17 | 'prepareOnly' => true, 18 | 'initRecurring' => false, 19 | 'preauth' => false, 20 | 'verification' => false, 21 | 'embedded' => false, 22 | 'dynamicExpiration' => false, 23 | 'allowedMethods' => [], 24 | 'excludedMethods' => [], 25 | 'account' => '', 26 | 'name' => '', 27 | // 'fullName' => '', 28 | // 'phone' => '', 29 | // 'billingAddrCity' => '', 30 | // 'billingAddrStreet' => '', 31 | // 'billingAddrPostalCode' => '', 32 | // 'billingAddrCountry' => '', 33 | // 'delivery' => '', 34 | // 'homeDeliveryCity' => '', 35 | // 'homeDeliveryStreet' => '', 36 | // 'homeDeliveryPostalCode' => '', 37 | // 'homeDeliveryCountry' => '', 38 | // 'category' => '', 39 | // 'chargeUnregulatedCardFees' => false, 40 | // 'enableApplePayGooglePay' => false, 41 | ]; 42 | 43 | /** 44 | * @param string $paramName 45 | * @param mixed $value 46 | * @return $this 47 | */ 48 | public function setParam(string $paramName, $value): self 49 | { 50 | $this->params[$paramName] = $value; 51 | 52 | return $this; 53 | } 54 | 55 | /** 56 | * @param string $paramName 57 | * @return bool|int|string|Money|array 58 | * @throws ParamIsNotSetException 59 | */ 60 | public function getParam($paramName) 61 | { 62 | if (isset($this->params[$paramName])) { 63 | return $this->params[$paramName]; 64 | } 65 | 66 | throw new ParamIsNotSetException("Param {$paramName} is not set."); 67 | } 68 | 69 | /** 70 | * @return array> 71 | */ 72 | public function getParams(): array 73 | { 74 | return $this->params; 75 | } 76 | 77 | /** 78 | * @param array $params 79 | * @return self 80 | */ 81 | public function setParams(array $params): self 82 | { 83 | $this->params = $params; 84 | 85 | return $this; 86 | } 87 | 88 | public function setRedirect(): self 89 | { 90 | $this->setPrepareOnly(true); 91 | 92 | return $this; 93 | } 94 | 95 | public function setIframe(): self 96 | { 97 | $this->setPrepareOnly(true); 98 | $this->setEmbedded(true); 99 | 100 | return $this; 101 | } 102 | 103 | /** 104 | * 105 | * @return Money 106 | */ 107 | public function getPrice(): Money 108 | { 109 | $param = $this->getParam('price'); 110 | if (!($param instanceof Money)) { 111 | throw new Exception("The Money value is not instance of Money"); 112 | } 113 | 114 | return $param; 115 | } 116 | 117 | /** 118 | * @param int|float|Money $price 119 | */ 120 | public function setPrice($price): self 121 | { 122 | $this->setParam('price', Money::of($price)); 123 | 124 | return $this; 125 | } 126 | 127 | public function getCurrency(): string 128 | { 129 | return (string) $this->getParamWithoutMoney('curr'); 130 | } 131 | 132 | public function setCurrency(string $currency): self 133 | { 134 | $this->setParam('curr', $currency); 135 | 136 | return $this; 137 | } 138 | 139 | public function getLabel(): string 140 | { 141 | return (string) $this->getParamWithoutMoney('label'); 142 | } 143 | 144 | public function setLabel(string $label): self 145 | { 146 | $this->setParam('label', $label); 147 | 148 | return $this; 149 | } 150 | 151 | public function getReferenceId(): string 152 | { 153 | return (string) $this->getParamWithoutMoney('refId'); 154 | } 155 | 156 | public function setReferenceId(string $referenceId): self 157 | { 158 | $this->setParam('refId', $referenceId); 159 | 160 | return $this; 161 | } 162 | 163 | public function getEmail(): string 164 | { 165 | return (string) $this->getParamWithoutMoney('email'); 166 | } 167 | 168 | public function isTest(): bool 169 | { 170 | return (bool)$this->getParam('test'); 171 | } 172 | 173 | public function setTest(bool $test): self 174 | { 175 | $this->setParam('test', $test); 176 | 177 | return $this; 178 | } 179 | 180 | public function setEmail(string $email): self 181 | { 182 | $this->setParam('email', $email); 183 | 184 | return $this; 185 | } 186 | 187 | /** 188 | * @return array 189 | */ 190 | public function getAllowedMethods(): array 191 | { 192 | return (array)$this->getParam('allowedMethods'); 193 | } 194 | 195 | /** 196 | * @return array 197 | */ 198 | public function getExcludedMethods(): array 199 | { 200 | return (array)$this->getParam('excludedMethods'); 201 | } 202 | 203 | /** 204 | * 205 | * @param array $methods 206 | * @return self 207 | */ 208 | public function setMethods(array $methods): self 209 | { 210 | $this->params['allowedMethods'] = $methods; 211 | 212 | return $this; 213 | } 214 | 215 | /** 216 | * 217 | * @param string $method 218 | * @return self 219 | */ 220 | public function addMethod(string $method): self 221 | { 222 | if (!isset($this->params['allowedMethods']) || !is_array($this->params['allowedMethods'])) { 223 | $this->params['allowedMethods'] = []; 224 | } 225 | 226 | $this->params['allowedMethods'][] = $method; 227 | 228 | return $this; 229 | } 230 | 231 | public function setoutMethod(string $method): self 232 | { 233 | if (!isset($this->params['excludedMethods']) || !is_array($this->params['excludedMethods'])) { 234 | $this->params['excludedMethods'] = []; 235 | } 236 | 237 | $this->params['excludedMethods'][] = $method; 238 | 239 | return $this; 240 | } 241 | 242 | public function getCountry(): ?string 243 | { 244 | return (string) $this->getParamWithoutMoney('country'); 245 | } 246 | 247 | public function setCountry(string $country): self 248 | { 249 | $this->setParam('country', $country); 250 | 251 | return $this; 252 | } 253 | 254 | public function getAccount(): ?string 255 | { 256 | return (string) $this->getParamWithoutMoney('account'); 257 | } 258 | 259 | public function setAccount(string $account): self 260 | { 261 | $this->setParam('account', $account); 262 | 263 | return $this; 264 | } 265 | 266 | public function getName(): ?string 267 | { 268 | return (string) $this->getParamWithoutMoney('name'); 269 | } 270 | 271 | public function setName(string $name): self 272 | { 273 | $this->setParam('name', $name); 274 | 275 | return $this; 276 | } 277 | 278 | public function getLang(): ?string 279 | { 280 | return (string) $this->getParamWithoutMoney('lang'); 281 | } 282 | 283 | public function setLang(string $lang): self 284 | { 285 | $this->setParam('lang', $lang); 286 | 287 | return $this; 288 | } 289 | 290 | public function getTransactionId(): ?string 291 | { 292 | return (string) $this->getParamWithoutMoney('transactionId'); 293 | } 294 | 295 | public function setTransactionId(string $transactionId): self 296 | { 297 | $this->setParam('transactionId', $transactionId); 298 | 299 | return $this; 300 | } 301 | 302 | public function isPrepareOnly(): bool 303 | { 304 | return (bool)$this->getParam('prepareOnly'); 305 | } 306 | 307 | public function setPrepareOnly(bool $prepareOnly): self 308 | { 309 | $this->setParam('prepareOnly', $prepareOnly); 310 | 311 | return $this; 312 | } 313 | 314 | public function isPreauth(): bool 315 | { 316 | return (bool)$this->getParam('preauth'); 317 | } 318 | 319 | public function setPreauth(bool $preauth): self 320 | { 321 | $this->setParam('preauth', $preauth); 322 | 323 | return $this; 324 | } 325 | 326 | public function isInitRecurring(): bool 327 | { 328 | return (bool)$this->getParam('initRecurring'); 329 | } 330 | 331 | public function setInitRecurring(bool $initRecurring): self 332 | { 333 | $this->setParam('initRecurring', $initRecurring); 334 | 335 | return $this; 336 | } 337 | 338 | public function isVerification(): bool 339 | { 340 | return (bool)$this->getParam('verification'); 341 | } 342 | 343 | public function setVerification(bool $verification): self 344 | { 345 | $this->setParam('verification', $verification); 346 | 347 | return $this; 348 | } 349 | 350 | public function isEmbedded(): bool 351 | { 352 | return (bool)$this->getParam('embedded'); 353 | } 354 | 355 | public function setEmbedded(bool $embedded): self 356 | { 357 | $this->setParam('embedded', $embedded); 358 | 359 | return $this; 360 | } 361 | 362 | /** 363 | * @return string|null 364 | */ 365 | public function getPayerId(): ?string 366 | { 367 | return (string) $this->getParamWithoutMoney('payerId'); 368 | } 369 | 370 | /** 371 | * @param string|null $payerId 372 | * @return Payment 373 | */ 374 | public function setPayerId(?string $payerId): Payment 375 | { 376 | $this->setParam('payerId', $payerId); 377 | return $this; 378 | } 379 | 380 | /** 381 | * @return string|null 382 | */ 383 | public function getApplePayPayload(): ?string 384 | { 385 | return (string) $this->getParamWithoutMoney('applePayPayload'); 386 | } 387 | 388 | /** 389 | * @param string|null $applePayPayload 390 | * @return Payment 391 | */ 392 | public function setApplePayPayload(?string $applePayPayload): Payment 393 | { 394 | $this->setParam('applePayPayload', $applePayPayload); 395 | return $this; 396 | } 397 | 398 | /** 399 | * @return string|null 400 | */ 401 | public function getExpirationTime(): ?string 402 | { 403 | return (string) $this->getParamWithoutMoney('expirationTime'); 404 | } 405 | 406 | /** 407 | * @param string|null $expirationTime 408 | * @return Payment 409 | */ 410 | public function setExpirationTime(?string $expirationTime): Payment 411 | { 412 | $this->setParam('expirationTime', $expirationTime); 413 | return $this; 414 | } 415 | 416 | 417 | /** 418 | * @return string|null 419 | */ 420 | public function getInitRecurringId(): ?string 421 | { 422 | return (string) $this->getParamWithoutMoney('initRecurringId'); 423 | } 424 | 425 | /** 426 | * @param string|null $initRecurringId 427 | * @return Payment 428 | */ 429 | public function setInitRecurringId(?string $initRecurringId): Payment 430 | { 431 | $this->setParam('initRecurringId', $initRecurringId); 432 | return $this; 433 | } 434 | 435 | public function isDynamicExpiration(): bool 436 | { 437 | return (bool)$this->getParam('dynamicExpiration'); 438 | } 439 | 440 | public function setDynamicExpiration(bool $dynamicExpiration): self 441 | { 442 | $this->setParam('dynamicExpiration', $dynamicExpiration); 443 | 444 | return $this; 445 | } 446 | 447 | public function getPhone(): ?string 448 | { 449 | return (string) $this->getParamWithoutMoney('phone'); 450 | } 451 | 452 | public function setPhone(string $phone): self 453 | { 454 | $this->setParam('phone', $phone); 455 | 456 | return $this; 457 | } 458 | 459 | public function getFullName(): ?string 460 | { 461 | return (string) $this->getParamWithoutMoney('fullName'); 462 | } 463 | 464 | public function setFullName(string $fullName): self 465 | { 466 | $this->setParam('fullName', $fullName); 467 | 468 | return $this; 469 | } 470 | 471 | public function getBillingAddrCity(): ?string 472 | { 473 | return (string) $this->getParamWithoutMoney('billingAddrCity'); 474 | } 475 | 476 | public function setBillingAddrCity(string $billingAddrCity): self 477 | { 478 | $this->setParam('billingAddrCity', $billingAddrCity); 479 | 480 | return $this; 481 | } 482 | 483 | public function getBillingAddrStreet(): ?string 484 | { 485 | return (string) $this->getParamWithoutMoney('billingAddrStreet'); 486 | } 487 | 488 | public function setBillingAddrStreet(string $billingAddrStreet): self 489 | { 490 | $this->setParam('billingAddrStreet', $billingAddrStreet); 491 | 492 | return $this; 493 | } 494 | 495 | public function getBillingAddrPostalCode(): ?string 496 | { 497 | return (string) $this->getParamWithoutMoney('billingAddrPostalCode'); 498 | } 499 | 500 | public function setBillingAddrPostalCode(string $billingAddrPostalCode): self 501 | { 502 | $this->setParam('billingAddrPostalCode', $billingAddrPostalCode); 503 | 504 | return $this; 505 | } 506 | 507 | public function getBillingAddrCountry(): ?string 508 | { 509 | return (string) $this->getParamWithoutMoney('billingAddrCountry'); 510 | } 511 | 512 | public function setBillingAddrCountry(string $billingAddrCountry): self 513 | { 514 | $this->setParam('billingAddrCountry', $billingAddrCountry); 515 | 516 | return $this; 517 | } 518 | 519 | public function getDelivery(): ?string 520 | { 521 | return (string) $this->getParamWithoutMoney('delivery'); 522 | } 523 | 524 | public function setDelivery(string $delivery): self 525 | { 526 | $this->setParam('delivery', $delivery); 527 | 528 | return $this; 529 | } 530 | 531 | public function getHomeDeliveryCity(): ?string 532 | { 533 | return (string) $this->getParamWithoutMoney('homeDeliveryCity'); 534 | } 535 | 536 | public function setHomeDeliveryCity(string $homeDeliveryCity): self 537 | { 538 | $this->setParam('homeDeliveryCity', $homeDeliveryCity); 539 | 540 | return $this; 541 | } 542 | 543 | public function getHomeDeliveryStreet(): ?string 544 | { 545 | return (string) $this->getParamWithoutMoney('homeDeliveryStreet'); 546 | } 547 | 548 | public function setHomeDeliveryStreet(string $homeDeliveryStreet): self 549 | { 550 | $this->setParam('homeDeliveryStreet', $homeDeliveryStreet); 551 | 552 | return $this; 553 | } 554 | 555 | public function getHomeDeliveryPostalCode(): ?string 556 | { 557 | return (string) $this->getParamWithoutMoney('homeDeliveryPostalCode'); 558 | } 559 | 560 | public function setHomeDeliveryPostalCode(string $homeDeliveryPostalCode): self 561 | { 562 | $this->setParam('homeDeliveryPostalCode', $homeDeliveryPostalCode); 563 | 564 | return $this; 565 | } 566 | 567 | public function getHomeDeliveryCountry(): ?string 568 | { 569 | return (string) $this->getParamWithoutMoney('homeDeliveryCountry'); 570 | } 571 | 572 | public function setHomeDeliveryCountry(string $homeDeliveryCountry): self 573 | { 574 | $this->setParam('homeDeliveryCountry', $homeDeliveryCountry); 575 | 576 | return $this; 577 | } 578 | 579 | public function getCategory(): ?string 580 | { 581 | return (string) $this->getParamWithoutMoney('category'); 582 | } 583 | 584 | public function setCategory(string $category): self 585 | { 586 | $this->setParam('category', $category); 587 | 588 | return $this; 589 | } 590 | 591 | public function getChargeUnregulatedCardFees(): bool 592 | { 593 | return $this->getParam('chargeUnregulatedCardFees'); 594 | } 595 | 596 | public function setChargeUnregulatedCardFees(bool $chargeUnregulatedCardFees): self 597 | { 598 | $this->setParam('chargeUnregulatedCardFees', $chargeUnregulatedCardFees); 599 | 600 | return $this; 601 | } 602 | 603 | /** 604 | * Vrací true/false/null hodnotu zapnutého Google/Apple pay. 605 | * @return null|bool 606 | */ 607 | public function getEnableApplePayGooglePay() 608 | { 609 | return $this->getParam('enableApplePayGooglePay'); 610 | } 611 | 612 | /** 613 | * Explicitně umožňuje povolení Apple Pay a Google Pay na platbách s přirážkami za neregulovanou kartu. Případně pro přímé zakázání pro konkrétní platbu 614 | * 615 | * @param null|bool $enableApplePayGooglePay 616 | * @return Payment 617 | */ 618 | // Použit komentář místo parametrového typu kvůli nekompatibilitě s null hodnotou. 619 | public function setEnableApplePayGooglePay($enableApplePayGooglePay): self 620 | { 621 | $this->setParam('enableApplePayGooglePay', $enableApplePayGooglePay); 622 | 623 | return $this; 624 | } 625 | 626 | /** 627 | * @param string $attributeName 628 | * @return bool|int|string 629 | * @throws Exception 630 | */ 631 | protected function getParamWithoutMoney(string $attributeName) 632 | { 633 | $param = $this->getParam($attributeName); 634 | if ($param instanceof Money) { 635 | throw new Exception("There is a Money value in {$attributeName} attribute"); 636 | } 637 | 638 | return $param; 639 | } 640 | } 641 | -------------------------------------------------------------------------------- /src/Entity/PaymentCard.php: -------------------------------------------------------------------------------- 1 | cardNumber = $cardNumber; 21 | $this->cardExpiration = $cardExpiration; 22 | $this->cardCvv = $cardCvv; 23 | 24 | $this->validate(); 25 | } 26 | 27 | /** 28 | * @return string|null 29 | */ 30 | public function getCardNumber(): ?string 31 | { 32 | return $this->cardNumber; 33 | } 34 | 35 | /** 36 | * @param string $cardNumber 37 | * @return PaymentCard 38 | */ 39 | public function setCardNumber(string $cardNumber): PaymentCard 40 | { 41 | $this->cardNumber = $cardNumber; 42 | $this->validate(); 43 | return $this; 44 | } 45 | 46 | /** 47 | * @return string|null 48 | */ 49 | public function getCardExpiration(): ?string 50 | { 51 | return $this->cardExpiration; 52 | } 53 | 54 | /** 55 | * @param string $cardExpiration 56 | * @return PaymentCard 57 | */ 58 | public function setCardExpiration(string $cardExpiration): PaymentCard 59 | { 60 | $this->cardExpiration = $cardExpiration; 61 | $this->validate(); 62 | return $this; 63 | } 64 | 65 | /** 66 | * @return string|null 67 | */ 68 | public function getCardCvv(): ?string 69 | { 70 | return $this->cardCvv; 71 | } 72 | 73 | /** 74 | * @param string $cardCvv 75 | * @return PaymentCard 76 | */ 77 | public function setCardCvv(string $cardCvv): PaymentCard 78 | { 79 | $this->cardCvv = $cardCvv; 80 | $this->validate(); 81 | return $this; 82 | } 83 | 84 | /** 85 | * @return true 86 | * @throws Exception 87 | */ 88 | private function validate() { 89 | if (!is_null($this->cardNumber) && !preg_match('/^[0-9]{16}$/', $this->cardNumber)) { 90 | throw new Exception(sprintf('Invalid card number: %s. (Required 16 digits)', $this->cardNumber)); 91 | } 92 | if (!is_null($this->cardExpiration) && !preg_match('/^[0-9]{6}$/', $this->cardExpiration)) { 93 | throw new Exception(sprintf('Invalid card expiration: %s. (Required format YYYYMM)', $this->cardExpiration)); 94 | } 95 | if (!is_null($this->cardCvv) && !preg_match('/^[0-9]{3}$/', $this->cardCvv)) { 96 | throw new Exception(sprintf('Invalid card CVV: %s. (Required 3 digits)', $this->cardCvv)); 97 | } 98 | return true; 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/Entity/PaymentInfo.php: -------------------------------------------------------------------------------- 1 | 10 | */ 11 | protected array $data = []; 12 | 13 | /** 14 | * 15 | * @param array $data 16 | * @return self 17 | */ 18 | public function fromArray(array $data): self 19 | { 20 | $this->setData($data); 21 | return $this; 22 | } 23 | 24 | /** 25 | * @return array 26 | */ 27 | public function getData(): array 28 | { 29 | return $this->data; 30 | } 31 | 32 | /** 33 | * @param array $data 34 | * @return PaymentInfo 35 | */ 36 | public function setData(array $data): PaymentInfo 37 | { 38 | $this->data = $data; 39 | return $this; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Entity/PaymentNotification.php: -------------------------------------------------------------------------------- 1 | merchant = $data['merchant'] ?? null; 75 | $self->test = filter_var($data['test'] ?? null, FILTER_VALIDATE_BOOLEAN); 76 | $self->price = isset($data['price']) ? Money::ofCents((int) $data['price']) : null; 77 | $self->currency = $data['curr'] ?? null; 78 | $self->label = $data['label'] ?? null; 79 | $self->referenceId = $data['refId'] ?? null; 80 | $self->email = $data['email'] ?? null; 81 | $self->transactionId = $data['transId'] ?? null; 82 | $self->status = $data['status'] ?? null; 83 | $self->fee = $data['fee'] ?? null; 84 | $self->vs = $data['vs'] ?? null; 85 | $self->method = $data['method'] ?? null; 86 | $self->secret = $data['secret'] ?? null; 87 | 88 | return $self; 89 | } 90 | 91 | public function getTransactionId(): ?string 92 | { 93 | return $this->transactionId; 94 | } 95 | 96 | public function getMerchant(): ?string 97 | { 98 | return $this->merchant; 99 | } 100 | 101 | public function isTest(): ?bool 102 | { 103 | return $this->test; 104 | } 105 | 106 | public function getPrice(): ?Money 107 | { 108 | return $this->price; 109 | } 110 | 111 | public function getCurrency(): ?string 112 | { 113 | return $this->currency; 114 | } 115 | 116 | public function getLabel(): ?string 117 | { 118 | return $this->label; 119 | } 120 | 121 | public function getReferenceId(): ?string 122 | { 123 | return $this->referenceId; 124 | } 125 | 126 | public function getEmail(): ?string 127 | { 128 | return $this->email; 129 | } 130 | 131 | public function getStatus(): ?string 132 | { 133 | return $this->status; 134 | } 135 | 136 | public function getFee(): ?string 137 | { 138 | return $this->fee; 139 | } 140 | 141 | /** 142 | * @return string|null 143 | */ 144 | public function getVs(): ?string 145 | { 146 | return $this->vs; 147 | } 148 | 149 | /** 150 | * @param string|null $vs 151 | */ 152 | public function setVs(?string $vs): void 153 | { 154 | $this->vs = $vs; 155 | } 156 | 157 | /** 158 | * @return string|null 159 | */ 160 | public function getMethod(): ?string 161 | { 162 | return $this->method; 163 | } 164 | 165 | /** 166 | * @param string|null $method 167 | */ 168 | public function setMethod(?string $method): void 169 | { 170 | $this->method = $method; 171 | } 172 | 173 | /** 174 | * @return string|null 175 | */ 176 | public function getSecret(): ?string 177 | { 178 | return $this->secret; 179 | } 180 | 181 | /** 182 | * @param string|null $secret 183 | * @return PaymentNotification 184 | */ 185 | public function setSecret(?string $secret): PaymentNotification 186 | { 187 | $this->secret = $secret; 188 | return $this; 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /src/Entity/Refund.php: -------------------------------------------------------------------------------- 1 | transId; 21 | } 22 | 23 | /** 24 | * @param string $transId 25 | * @return Refund 26 | */ 27 | public function setTransId(string $transId): Refund 28 | { 29 | $this->transId = $transId; 30 | return $this; 31 | } 32 | 33 | /** 34 | * @return Money 35 | */ 36 | public function getAmount(): Money 37 | { 38 | return $this->amount; 39 | } 40 | 41 | /** 42 | * @param Money $amount 43 | * @return Refund 44 | */ 45 | public function setAmount(Money $amount): Refund 46 | { 47 | $this->amount = $amount; 48 | return $this; 49 | } 50 | 51 | /** 52 | * @return string 53 | */ 54 | public function getCurrency(): string 55 | { 56 | return $this->currency; 57 | } 58 | 59 | /** 60 | * @param string $currency 61 | * @return Refund 62 | */ 63 | public function setCurrency(string $currency): Refund 64 | { 65 | $this->currency = $currency; 66 | return $this; 67 | } 68 | 69 | /** 70 | * @return bool 71 | */ 72 | public function isTest(): bool 73 | { 74 | return $this->test; 75 | } 76 | 77 | /** 78 | * @param bool $test 79 | * @return Refund 80 | */ 81 | public function setTest(bool $test): Refund 82 | { 83 | $this->test = $test; 84 | return $this; 85 | } 86 | 87 | /** 88 | * @return string 89 | */ 90 | public function getRefId(): string 91 | { 92 | return $this->refId; 93 | } 94 | 95 | /** 96 | * @param string $refId 97 | * @return Refund 98 | */ 99 | public function setRefId(string $refId): Refund 100 | { 101 | $this->refId = $refId; 102 | return $this; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/Entity/Request/AboSingleTransferRequest.php: -------------------------------------------------------------------------------- 1 | setTransferId($transferId) 24 | ->setTest($test) 25 | ->setType($type) 26 | ->setEncoding($encoding); 27 | } 28 | 29 | /** 30 | * @return string 31 | */ 32 | public function getUrn(): string 33 | { 34 | return 'aboSingleTransfer'; 35 | } 36 | 37 | /** 38 | * @return array 39 | */ 40 | public function toArray(): array 41 | { 42 | return [ 43 | 'transferId' => $this->getTransferId(), 44 | 'download' => 'false', 45 | 'test' => $this->isTest() ? 'true' : 'false', 46 | 'type' => $this->getType(), 47 | 'encoding' => $this->getEncoding(), 48 | ]; 49 | } 50 | 51 | /** 52 | * @return string 53 | */ 54 | public function getTransferId(): string 55 | { 56 | return $this->transferId; 57 | } 58 | 59 | /** 60 | * @param string $transferId 61 | * @return AboSingleTransferRequest 62 | */ 63 | public function setTransferId(string $transferId): AboSingleTransferRequest 64 | { 65 | $this->transferId = $transferId; 66 | return $this; 67 | } 68 | 69 | /** 70 | * @return bool 71 | */ 72 | public function isTest(): bool 73 | { 74 | return $this->test; 75 | } 76 | 77 | /** 78 | * @param bool $test 79 | * @return AboSingleTransferRequest 80 | */ 81 | public function setTest(bool $test): AboSingleTransferRequest 82 | { 83 | $this->test = $test; 84 | return $this; 85 | } 86 | 87 | /** 88 | * @return string 89 | */ 90 | public function getType(): string 91 | { 92 | return $this->type; 93 | } 94 | 95 | /** 96 | * @param string $type 97 | * @return AboSingleTransferRequest 98 | */ 99 | public function setType(string $type): AboSingleTransferRequest 100 | { 101 | $this->type = $type; 102 | return $this; 103 | } 104 | 105 | /** 106 | * @return string 107 | */ 108 | public function getEncoding(): string 109 | { 110 | return $this->encoding; 111 | } 112 | 113 | /** 114 | * @param string $encoding 115 | * @return AboSingleTransferRequest 116 | */ 117 | public function setEncoding(string $encoding): AboSingleTransferRequest 118 | { 119 | $this->encoding = $encoding; 120 | return $this; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/Entity/Request/CsvSingleTransferRequest.php: -------------------------------------------------------------------------------- 1 | setTransferId($transferId) 15 | ->setTest($test); 16 | } 17 | 18 | /** 19 | * @return string 20 | */ 21 | public function getUrn(): string 22 | { 23 | return 'csvSingleTransfer'; 24 | } 25 | 26 | /** 27 | * @return array 28 | */ 29 | public function toArray(): array 30 | { 31 | return [ 32 | 'transferId' => $this->getTransferId(), 33 | 'download' => 'false', 34 | 'test' => $this->isTest() ? 'true' : 'false', 35 | ]; 36 | } 37 | 38 | /** 39 | * @return string 40 | */ 41 | public function getTransferId(): string 42 | { 43 | return $this->transferId; 44 | } 45 | 46 | /** 47 | * @param string $transferId 48 | * @return CsvSingleTransferRequest 49 | */ 50 | public function setTransferId(string $transferId): CsvSingleTransferRequest 51 | { 52 | $this->transferId = $transferId; 53 | return $this; 54 | } 55 | 56 | /** 57 | * @return bool 58 | */ 59 | public function isTest(): bool 60 | { 61 | return $this->test; 62 | } 63 | 64 | /** 65 | * @param bool $test 66 | * @return CsvSingleTransferRequest 67 | */ 68 | public function setTest(bool $test): CsvSingleTransferRequest 69 | { 70 | $this->test = $test; 71 | return $this; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Entity/Request/IRequest.php: -------------------------------------------------------------------------------- 1 | 21 | */ 22 | public function toArray(): array; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/Entity/Request/MethodsRequest.php: -------------------------------------------------------------------------------- 1 | 21 | */ 22 | public function toArray(): array 23 | { 24 | $requestArray = [ 25 | 'type' => $this->getType(), 26 | ]; 27 | 28 | if(!is_null($this->getLang())){ 29 | $requestArray['lang'] = $this->getLang(); 30 | } 31 | 32 | if(!is_null($this->getCurrency())){ 33 | $requestArray['curr'] = $this->getCurrency(); 34 | } 35 | 36 | if(!is_null($this->getCountry())){ 37 | $requestArray['country'] = $this->getCountry(); 38 | } 39 | 40 | return $requestArray; 41 | } 42 | 43 | /** 44 | * @return string 45 | */ 46 | public function getType(): string 47 | { 48 | return $this->type; 49 | } 50 | 51 | /** 52 | * @param string $type 53 | * @return MethodsRequest 54 | */ 55 | public function setType(string $type): MethodsRequest 56 | { 57 | $this->type = $type; 58 | return $this; 59 | } 60 | 61 | /** 62 | * @return string|null 63 | */ 64 | public function getLang(): ?string 65 | { 66 | return $this->lang; 67 | } 68 | 69 | /** 70 | * @param string|null $lang 71 | * @return MethodsRequest 72 | */ 73 | public function setLang(?string $lang): MethodsRequest 74 | { 75 | $this->lang = $lang; 76 | return $this; 77 | } 78 | 79 | /** 80 | * @return string|null 81 | */ 82 | public function getCurrency(): ?string 83 | { 84 | return $this->currency; 85 | } 86 | 87 | /** 88 | * @param string|null $currency 89 | * @return MethodsRequest 90 | */ 91 | public function setCurrency(?string $currency): MethodsRequest 92 | { 93 | $this->currency = $currency; 94 | return $this; 95 | } 96 | 97 | /** 98 | * @return string|null 99 | */ 100 | public function getCountry(): ?string 101 | { 102 | return $this->country; 103 | } 104 | 105 | /** 106 | * @param string|null $country 107 | * @return MethodsRequest 108 | */ 109 | public function setCountry(?string $country): MethodsRequest 110 | { 111 | $this->country = $country; 112 | return $this; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/Entity/Request/MotoPaymentCreateRequest.php: -------------------------------------------------------------------------------- 1 | 27 | */ 28 | public function toArray(): array 29 | { 30 | $output = parent::toArray(); 31 | 32 | $output['embedded'] = $this->payment->isEmbedded() ? 'true' : 'false'; 33 | $output['initRecurring'] = $this->payment->isInitRecurring() ? 'true' : 'false'; 34 | $output['dynamicExpiration'] = $this->payment->isDynamicExpiration() ? 'true' : 'false'; 35 | 36 | return $output; 37 | } 38 | 39 | } 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/Entity/Request/PaymentCancelRequest.php: -------------------------------------------------------------------------------- 1 | setTransId($transId); 16 | } 17 | 18 | /** 19 | * @return string 20 | */ 21 | public function getUrn(): string 22 | { 23 | return 'cancel'; 24 | } 25 | 26 | /** 27 | * @return array 28 | */ 29 | public function toArray(): array 30 | { 31 | return [ 32 | 'transId' => $this->getTransId(), 33 | ]; 34 | } 35 | 36 | /** 37 | * @return string 38 | */ 39 | public function getTransId(): string 40 | { 41 | return $this->transId; 42 | } 43 | 44 | /** 45 | * @param string $transId 46 | * @return PaymentCancelRequest 47 | */ 48 | public function setTransId(string $transId): PaymentCancelRequest 49 | { 50 | $this->transId = $transId; 51 | return $this; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Entity/Request/PaymentCreateRequest.php: -------------------------------------------------------------------------------- 1 | payment = $payment; 18 | } 19 | 20 | /** 21 | * @return string 22 | */ 23 | public function getUrn(): string 24 | { 25 | return 'create'; 26 | } 27 | 28 | /** 29 | * @return array 30 | */ 31 | public function toArray(): array 32 | { 33 | // Required 34 | $output = $this->payment->getParams(); 35 | 36 | $output['price'] = $this->payment->getPrice()->get(); // in cents 10.25 => 1025 37 | $output['prepareOnly'] = $this->payment->isPrepareOnly() ? 'true' : 'false'; 38 | $output['method'] = implode('+', $this->payment->getAllowedMethods()); 39 | unset($output['allowedMethods']); 40 | 41 | if (count($this->payment->getExcludedMethods()) > 0) { 42 | $output['method'] = ltrim($output['method'] . '-' . implode('-', $this->payment->getExcludedMethods()), '-'); 43 | } 44 | unset($output['excludedMethods']); 45 | 46 | // Optional 47 | $output['preauth'] = $this->payment->isPreauth() ? 'true' : 'false'; 48 | $output['test'] = $this->payment->isTest() ? 'true' : 'false'; 49 | $output['verification'] = $this->payment->isVerification() ? 'true' : 'false'; 50 | $output['embedded'] = $this->payment->isEmbedded() ? 'true' : 'false'; 51 | $output['initRecurring'] = $this->payment->isInitRecurring() ? 'true' : 'false'; 52 | $output['dynamicExpiration'] = $this->payment->isDynamicExpiration() ? 'true' : 'false'; 53 | 54 | return $output; 55 | } 56 | 57 | } 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /src/Entity/Request/PaymentRefundRequest.php: -------------------------------------------------------------------------------- 1 | setRefund($refund); 19 | } 20 | 21 | /** 22 | * @return string 23 | */ 24 | public function getUrn(): string 25 | { 26 | return 'refund'; 27 | } 28 | 29 | /** 30 | * @return array 31 | */ 32 | public function toArray(): array 33 | { 34 | return [ 35 | 'transId' => $this->getRefund()->getTransId(), 36 | 'amount' => $this->getRefund()->getAmount()->get(), 37 | 'curr' => $this->getRefund()->getCurrency(), 38 | 'test' => $this->getRefund()->isTest() ? 'true' : 'false', 39 | 'refId' => $this->getRefund()->getRefId(), 40 | ]; 41 | } 42 | 43 | /** 44 | * @return Refund 45 | */ 46 | public function getRefund(): Refund 47 | { 48 | return $this->refund; 49 | } 50 | 51 | /** 52 | * @param Refund $refund 53 | * @return PaymentRefundRequest 54 | */ 55 | public function setRefund(Refund $refund): self 56 | { 57 | $this->refund = $refund; 58 | return $this; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/Entity/Request/PaymentStatusRequest.php: -------------------------------------------------------------------------------- 1 | setTransId($transId); 16 | } 17 | 18 | /** 19 | * @return string 20 | */ 21 | public function getUrn(): string 22 | { 23 | return 'status'; 24 | } 25 | 26 | /** 27 | * @return array 28 | */ 29 | public function toArray(): array 30 | { 31 | return [ 32 | 'transId' => $this->getTransId(), 33 | ]; 34 | } 35 | 36 | /** 37 | * @return string 38 | */ 39 | public function getTransId(): string 40 | { 41 | return $this->transId; 42 | } 43 | 44 | /** 45 | * @param string $transId 46 | * @return PaymentStatusRequest 47 | */ 48 | public function setTransId(string $transId): PaymentStatusRequest 49 | { 50 | $this->transId = $transId; 51 | return $this; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Entity/Request/PreauthCancelRequest.php: -------------------------------------------------------------------------------- 1 | setTransId($transId); 15 | } 16 | 17 | /** 18 | * @return string 19 | */ 20 | public function getUrn(): string 21 | { 22 | return 'cancelPreauth'; 23 | } 24 | 25 | /** 26 | * @return array 27 | */ 28 | public function toArray(): array 29 | { 30 | // Required 31 | $output = [ 32 | 'transId' => $this->getTransId(), 33 | ]; 34 | 35 | return $output; 36 | } 37 | 38 | /** 39 | * @return string 40 | */ 41 | public function getTransId(): string 42 | { 43 | return $this->transId; 44 | } 45 | 46 | /** 47 | * @param string $transId 48 | * @return PreauthCancelRequest 49 | */ 50 | public function setTransId(string $transId): self 51 | { 52 | $this->transId = $transId; 53 | return $this; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Entity/Request/PreauthCaptureRequest.php: -------------------------------------------------------------------------------- 1 | setTransId($transId) 17 | ->setAmount($amount); 18 | } 19 | 20 | /** 21 | * @return string 22 | */ 23 | public function getUrn(): string 24 | { 25 | return 'capturePreauth'; 26 | } 27 | 28 | /** 29 | * @return array 30 | */ 31 | public function toArray(): array 32 | { 33 | // Required 34 | $output = [ 35 | 'transId' => $this->getTransId(), 36 | 'amount' => $this->getAmount()->get(), 37 | ]; 38 | 39 | return $output; 40 | } 41 | 42 | /** 43 | * @return string 44 | */ 45 | public function getTransId(): string 46 | { 47 | return $this->transId; 48 | } 49 | 50 | /** 51 | * @param string $transId 52 | * @return PreauthCaptureRequest 53 | */ 54 | public function setTransId(string $transId): self 55 | { 56 | $this->transId = $transId; 57 | return $this; 58 | } 59 | 60 | /** 61 | * @return Money 62 | */ 63 | public function getAmount(): Money 64 | { 65 | return $this->amount; 66 | } 67 | 68 | /** 69 | * @param Money $amount 70 | * @return PreauthCaptureRequest 71 | */ 72 | public function setAmount(Money $amount): self 73 | { 74 | $this->amount = $amount; 75 | return $this; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/Entity/Request/PublicCryptoKeyRequest.php: -------------------------------------------------------------------------------- 1 | 19 | */ 20 | public function toArray(): array 21 | { 22 | return []; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Entity/Request/RecurringPaymentRequest.php: -------------------------------------------------------------------------------- 1 | setPayment($payment); 15 | } 16 | 17 | /** 18 | * @return string 19 | */ 20 | public function getUrn(): string 21 | { 22 | return 'recurring'; 23 | } 24 | 25 | /** 26 | * @return array 27 | */ 28 | public function toArray(): array 29 | { 30 | // Required 31 | $output = [ 32 | 'country' => $this->getPayment()->getCountry(), 33 | 'test' => $this->getPayment()->isTest(), 34 | 'price' => $this->getPayment()->getPrice()->get(), 35 | 'curr' => $this->getPayment()->getCurrency(), 36 | 'label' => $this->getPayment()->getLabel(), 37 | 'refId' => $this->getPayment()->getReferenceId(), 38 | 'account' => $this->getPayment()->getAccount(), 39 | 'email' => $this->getPayment()->getEmail(), 40 | 'name' => $this->getPayment()->getName(), 41 | 'prepareOnly' => $this->getPayment()->isPrepareOnly(), 42 | 'initRecurringId' => $this->getPayment()->getInitRecurringId(), 43 | ]; 44 | 45 | return $output; 46 | } 47 | 48 | /** 49 | * @return Payment 50 | */ 51 | public function getPayment(): Payment 52 | { 53 | return $this->payment; 54 | } 55 | 56 | /** 57 | * @param Payment $payment 58 | * @return RecurringPaymentRequest 59 | */ 60 | public function setPayment(Payment $payment): RecurringPaymentRequest 61 | { 62 | $this->payment = $payment; 63 | return $this; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Entity/Request/SimulationRequest.php: -------------------------------------------------------------------------------- 1 | $params 12 | */ 13 | protected array $params = []; 14 | 15 | /** 16 | * @param array $params 17 | */ 18 | public function __construct(array $params) 19 | { 20 | $this->setParams($params); 21 | } 22 | 23 | public function getUrn(): string 24 | { 25 | return 'simulation'; 26 | } 27 | 28 | /** 29 | * @return array 30 | */ 31 | public function toArray(): array 32 | { 33 | return $this->getParams(); 34 | } 35 | 36 | /** 37 | * @return array 38 | */ 39 | public function getParams(): array 40 | { 41 | return $this->params; 42 | } 43 | 44 | /** 45 | * @param array $params 46 | * @return SimulationRequest 47 | */ 48 | public function setParams(array $params): SimulationRequest 49 | { 50 | $this->params = $params; 51 | return $this; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Entity/Request/SingleTransferRequest.php: -------------------------------------------------------------------------------- 1 | setTransferId($transferId) 14 | ->setTest($test); 15 | } 16 | 17 | /** 18 | * @return string 19 | */ 20 | public function getUrn(): string 21 | { 22 | return 'singleTransfer'; 23 | } 24 | 25 | /** 26 | * @return array 27 | */ 28 | public function toArray(): array 29 | { 30 | return [ 31 | 'transferId' => $this->getTransferId(), 32 | 'test' => $this->isTest() ? 'true' : 'false', 33 | ]; 34 | } 35 | 36 | /** 37 | * @return int 38 | */ 39 | public function getTransferId(): int 40 | { 41 | return $this->transferId; 42 | } 43 | 44 | /** 45 | * @param int $transferId 46 | * @return SingleTransferRequest 47 | */ 48 | public function setTransferId(int $transferId): self 49 | { 50 | $this->transferId = $transferId; 51 | return $this; 52 | } 53 | 54 | public function isTest(): bool 55 | { 56 | return $this->test; 57 | } 58 | 59 | /** 60 | * @param bool $test 61 | * @return SingleTransferRequest 62 | */ 63 | public function setTest(bool $test): self 64 | { 65 | $this->test = $test; 66 | return $this; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Entity/Request/TransferListRequest.php: -------------------------------------------------------------------------------- 1 | setDate($date) 21 | ->setTest($test); 22 | } 23 | 24 | /** 25 | * @return string 26 | */ 27 | public function getUrn(): string 28 | { 29 | return 'transferList'; 30 | } 31 | 32 | /** 33 | * @return array 34 | */ 35 | public function toArray(): array 36 | { 37 | return [ 38 | 'date' => $this->getDate()->format(self::DATE_FORMAT), 39 | 'test' => $this->isTest() ? 'true' : 'false', 40 | ]; 41 | } 42 | 43 | /** 44 | * @return DateTimeInterface 45 | */ 46 | public function getDate(): DateTimeInterface 47 | { 48 | return $this->date; 49 | } 50 | 51 | /** 52 | * @param DateTimeInterface $date 53 | * @return TransferListRequest 54 | */ 55 | public function setDate(DateTimeInterface $date): TransferListRequest 56 | { 57 | $this->date = $date; 58 | return $this; 59 | } 60 | 61 | /** 62 | * @return bool 63 | */ 64 | public function isTest(): bool 65 | { 66 | return $this->test; 67 | } 68 | 69 | /** 70 | * @param bool $test 71 | * @return TransferListRequest 72 | */ 73 | public function setTest(bool $test): TransferListRequest 74 | { 75 | $this->test = $test; 76 | return $this; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Entity/Response/AboSingleTransferResponse.php: -------------------------------------------------------------------------------- 1 | getContent(); 17 | $aboData = json_decode($aboJson, true); 18 | 19 | if (isset($aboData['code']) && isset($aboData['message'])) { 20 | throw new ApiException($aboData['message'], $aboData['code']); 21 | } 22 | 23 | $decodedContent = base64_decode($aboData['abo'], true); 24 | $this->setFilename($aboData['nazev']) 25 | ->setFileContent($decodedContent !== false ? $decodedContent : ''); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Entity/Response/CsvSingleTransferResponse.php: -------------------------------------------------------------------------------- 1 | getContent(); 18 | $csvData = json_decode($csvJson, true); 19 | 20 | if (isset($csvData['code']) && isset($csvData['message'])) { 21 | throw new ApiException($csvData['message'], $csvData['code']); 22 | } 23 | 24 | $decodedContent = base64_decode($csvData['csv'], true); 25 | $this->setFilename($csvData['nazev']) 26 | ->setFileContent($decodedContent !== false ? $decodedContent : ''); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Entity/Response/FileResponse.php: -------------------------------------------------------------------------------- 1 | getFilename(); 22 | } 23 | 24 | if (!is_dir($directory) || !is_writable($directory)) { 25 | throw new LogicalException("Path {$directory} is not a directory or is not writable"); 26 | } 27 | 28 | file_put_contents($directory . DIRECTORY_SEPARATOR . $fileName, $this->getFileContent()); 29 | } 30 | 31 | /** 32 | * @return string 33 | */ 34 | public function getFilename(): string 35 | { 36 | return $this->filename; 37 | } 38 | 39 | /** 40 | * @param string $filename 41 | * @return self 42 | */ 43 | public function setFilename(string $filename): self 44 | { 45 | $this->filename = $filename; 46 | return $this; 47 | } 48 | 49 | /** 50 | * @return string 51 | */ 52 | public function getFileContent(): string 53 | { 54 | return $this->fileContent; 55 | } 56 | 57 | /** 58 | * @param string $fileContent 59 | * @return self 60 | */ 61 | public function setFileContent(string $fileContent): self 62 | { 63 | $this->fileContent = $fileContent; 64 | return $this; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Entity/Response/MethodsResponse.php: -------------------------------------------------------------------------------- 1 | 14 | */ 15 | private array $methodsList = []; 16 | 17 | /** 18 | * @param Response $methodsResponse 19 | * @throws ApiException 20 | * @return MethodsResponse 21 | */ 22 | public function __construct(Response $methodsResponse) 23 | { 24 | $methodsJson = $methodsResponse->getContent(); 25 | $methodsArray = json_decode($methodsJson, true); 26 | 27 | if (isset($methodsArray['methods'])) { 28 | foreach ((array)$methodsArray['methods'] as $methodData) { 29 | $method = (new Method())->fromArray((array)$methodData); 30 | 31 | $this->methodsList[] = $method; 32 | } 33 | } 34 | 35 | if (isset($methodsArray['error'])) { 36 | $code = (int)$methodsArray['error']['code']; 37 | $message = $methodsArray['error']['message']; 38 | 39 | throw new ApiException((string)$message, $code); 40 | } 41 | } 42 | 43 | /** 44 | * @return array 45 | */ 46 | public function getMethodsList(): array 47 | { 48 | return $this->methodsList; 49 | } 50 | 51 | /** 52 | * @param array $methodsList 53 | * @return MethodsResponse 54 | */ 55 | public function setMethodsList(array $methodsList): MethodsResponse 56 | { 57 | $this->methodsList = $methodsList; 58 | return $this; 59 | } 60 | 61 | /** 62 | * @return array> 63 | */ 64 | public function toArray(): array 65 | { 66 | $methodsArray = []; 67 | 68 | foreach ($this->methodsList as $method) { 69 | $methodsArray[] = $method->toArray(); 70 | } 71 | 72 | return $methodsArray; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/Entity/Response/MotoPaymentCreateResponse.php: -------------------------------------------------------------------------------- 1 | getContent()); 29 | 30 | $code = (int) $parsedResponse['code']; 31 | $message = $parsedResponse['message']; 32 | 33 | switch ($code) { 34 | case 0: 35 | $this->setCode($code) 36 | ->setMessage($message) 37 | ->setTransId($parsedResponse['transId']) 38 | ->setStatus($parsedResponse['status']); 39 | 40 | break; 41 | 42 | case 1400: 43 | throw new MissingParamException($message, $code); 44 | 45 | default: 46 | if (isset($parsedResponse['transId'])) { 47 | $message .= ' - ' . $parsedResponse['transId']; 48 | } 49 | if (isset($parsedResponse['status'])) { 50 | $message .= ' - ' . $parsedResponse['status']; 51 | } 52 | throw new ApiException($message, $code); 53 | } 54 | } 55 | 56 | /** 57 | * @return array 58 | */ 59 | public function toArray(): array 60 | { 61 | return [ 62 | 'code' => $this->getCode(), 63 | 'message' => $this->getMessage(), 64 | 'transId' => $this->getTransId(), 65 | 'status' => $this->getStatus(), 66 | ]; 67 | } 68 | 69 | /** 70 | * @return int 71 | */ 72 | public function getCode(): int 73 | { 74 | return $this->code; 75 | } 76 | 77 | /** 78 | * @param int $code 79 | * @return MotoPaymentCreateResponse 80 | */ 81 | public function setCode(int $code): MotoPaymentCreateResponse 82 | { 83 | $this->code = $code; 84 | return $this; 85 | } 86 | 87 | /** 88 | * @return string 89 | */ 90 | public function getMessage(): string 91 | { 92 | return $this->message; 93 | } 94 | 95 | /** 96 | * @param string $message 97 | * @return MotoPaymentCreateResponse 98 | */ 99 | public function setMessage(string $message): MotoPaymentCreateResponse 100 | { 101 | $this->message = $message; 102 | return $this; 103 | } 104 | 105 | /** 106 | * @return string 107 | */ 108 | public function getTransId(): string 109 | { 110 | return $this->transId; 111 | } 112 | 113 | /** 114 | * @param string $transId 115 | * @return MotoPaymentCreateResponse 116 | */ 117 | public function setTransId(string $transId): MotoPaymentCreateResponse 118 | { 119 | $this->transId = $transId; 120 | return $this; 121 | } 122 | 123 | /** 124 | * @return string 125 | */ 126 | public function getStatus(): string 127 | { 128 | return $this->status; 129 | } 130 | 131 | /** 132 | * @param string $status 133 | * @return MotoPaymentCreateResponse 134 | */ 135 | public function setStatus(string $status): MotoPaymentCreateResponse 136 | { 137 | $this->status = $status; 138 | return $this; 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /src/Entity/Response/PaymentCancelResponse.php: -------------------------------------------------------------------------------- 1 | getContent()); 25 | 26 | $code = (int) $parsedResponse['code']; 27 | $message = $parsedResponse['message']; 28 | 29 | switch ($code) { 30 | case 0: 31 | $this->setCode($code) 32 | ->setMessage($message); 33 | 34 | break; 35 | 36 | case 1400: 37 | throw new MissingParamException($message, $code); 38 | 39 | default: 40 | throw new ApiException($message, $code); 41 | } 42 | } 43 | 44 | /** 45 | * 46 | * @return array 47 | */ 48 | public function toArray() : array 49 | { 50 | return [ 51 | 'code' => $this->getCode(), 52 | 'message' => $this->getMessage(), 53 | ]; 54 | } 55 | 56 | /** 57 | * @return int 58 | */ 59 | public function getCode(): int 60 | { 61 | return $this->code; 62 | } 63 | 64 | /** 65 | * @param int $code 66 | * @return PaymentCancelResponse 67 | */ 68 | public function setCode(int $code): self 69 | { 70 | $this->code = $code; 71 | return $this; 72 | } 73 | 74 | /** 75 | * @return string 76 | */ 77 | public function getMessage(): string 78 | { 79 | return $this->message; 80 | } 81 | 82 | /** 83 | * @param string $message 84 | * @return PaymentCancelResponse 85 | */ 86 | public function setMessage(string $message): self 87 | { 88 | $this->message = $message; 89 | return $this; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/Entity/Response/PaymentCreateResponse.php: -------------------------------------------------------------------------------- 1 | getContent()); 29 | 30 | $code = (int) $parsedResponse['code']; 31 | $message = $parsedResponse['message']; 32 | 33 | switch ($code) { 34 | case 0: 35 | $this->setCode($code) 36 | ->setMessage($message) 37 | ->setTransId($parsedResponse['transId']) 38 | ->setRedirect($parsedResponse['redirect']); 39 | 40 | break; 41 | 42 | case 1400: 43 | throw new MissingParamException($message, $code); 44 | 45 | default: 46 | throw new ApiException($message, $code); 47 | } 48 | } 49 | 50 | /** 51 | * @return array 52 | */ 53 | public function toArray(): array 54 | { 55 | return [ 56 | 'code' => $this->getCode(), 57 | 'message' => $this->getMessage(), 58 | 'transId' => $this->getTransId(), 59 | 'redirect' => $this->getRedirect(), 60 | ]; 61 | } 62 | 63 | /** 64 | * @return int 65 | */ 66 | public function getCode(): int 67 | { 68 | return $this->code; 69 | } 70 | 71 | /** 72 | * @param int $code 73 | * @return PaymentCreateResponse 74 | */ 75 | public function setCode(int $code): PaymentCreateResponse 76 | { 77 | $this->code = $code; 78 | return $this; 79 | } 80 | 81 | /** 82 | * @return string 83 | */ 84 | public function getMessage(): string 85 | { 86 | return $this->message; 87 | } 88 | 89 | /** 90 | * @param string $message 91 | * @return PaymentCreateResponse 92 | */ 93 | public function setMessage(string $message): PaymentCreateResponse 94 | { 95 | $this->message = $message; 96 | return $this; 97 | } 98 | 99 | /** 100 | * @return string 101 | */ 102 | public function getTransId(): string 103 | { 104 | return $this->transId; 105 | } 106 | 107 | /** 108 | * @param string $transId 109 | * @return PaymentCreateResponse 110 | */ 111 | public function setTransId(string $transId): PaymentCreateResponse 112 | { 113 | $this->transId = $transId; 114 | return $this; 115 | } 116 | 117 | /** 118 | * @return string 119 | */ 120 | public function getRedirect(): string 121 | { 122 | return $this->redirect; 123 | } 124 | 125 | /** 126 | * @param string $redirect 127 | * @return PaymentCreateResponse 128 | */ 129 | public function setRedirect(string $redirect): PaymentCreateResponse 130 | { 131 | $this->redirect = $redirect; 132 | return $this; 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/Entity/Response/PaymentStatusResponse.php: -------------------------------------------------------------------------------- 1 | getContent()); 41 | 42 | $code = (int) $parsedResponse['code']; 43 | $message = $parsedResponse['message']; 44 | 45 | switch ($code) { 46 | case 0: 47 | $this->setCode($code) 48 | ->setMessage($message) 49 | ->setMerchant($parsedResponse['merchant']) 50 | ->setTest($parsedResponse['test'] === 'true') 51 | ->setPrice(Money::ofCents((int) $parsedResponse['price'])) 52 | ->setCurrency($parsedResponse['curr']) 53 | ->setLabel($parsedResponse['label']) 54 | ->setRefId($parsedResponse['refId']) 55 | ->setPayerId($parsedResponse['payerId'] ?? '') 56 | ->setMethod($parsedResponse['method']) 57 | ->setAccount($parsedResponse['account'] ?? '') 58 | ->setEmail($parsedResponse['email'] ?? '') 59 | ->setName($parsedResponse['name']) 60 | ->setTransId($parsedResponse['transId']) 61 | ->setSecret($parsedResponse['secret']) 62 | ->setStatus($parsedResponse['status']) 63 | ->setPayerName($parsedResponse['payerName']) 64 | ->setFee($parsedResponse['fee']); 65 | 66 | break; 67 | 68 | case 1400: 69 | throw new PaymentNotFoundException($message, $code); 70 | 71 | default: 72 | throw new ApiException($message, $code); 73 | } 74 | } 75 | 76 | /** 77 | * @return array 78 | */ 79 | public function toArray(): array 80 | { 81 | $output = [ 82 | 'code' => $this->getCode(), 83 | 'message' => $this->getMessage(), 84 | 'merchant' => $this->getMerchant(), 85 | 'test' => $this->isTest(), 86 | 'price' => $this->getPrice()->get(), 87 | 'curr' => $this->getCurrency(), 88 | 'label' => $this->getLabel(), 89 | 'refId' => $this->getRefId(), 90 | 'payerId' => $this->getPayerId(), 91 | 'method' => $this->getMethod(), 92 | 'account' => $this->getAccount(), 93 | 'email' => $this->getEmail(), 94 | 'name' => $this->getName(), 95 | 'transId' => $this->getTransId(), 96 | 'secret' => $this->getSecret(), 97 | 'status' => $this->getStatus(), 98 | 'payerName' => $this->getPayerName(), 99 | 'fee' => $this->getFee(), 100 | ]; 101 | 102 | return $output; 103 | } 104 | 105 | /** 106 | * @return int 107 | */ 108 | public function getCode(): int 109 | { 110 | return $this->code; 111 | } 112 | 113 | /** 114 | * @param int $code 115 | * @return PaymentStatusResponse 116 | */ 117 | public function setCode(int $code): PaymentStatusResponse 118 | { 119 | $this->code = $code; 120 | return $this; 121 | } 122 | 123 | /** 124 | * @return string 125 | */ 126 | public function getMessage(): string 127 | { 128 | return $this->message; 129 | } 130 | 131 | /** 132 | * @param string $message 133 | * @return PaymentStatusResponse 134 | */ 135 | public function setMessage(string $message): PaymentStatusResponse 136 | { 137 | $this->message = $message; 138 | return $this; 139 | } 140 | 141 | /** 142 | * @return string 143 | */ 144 | public function getMerchant(): string 145 | { 146 | return $this->merchant; 147 | } 148 | 149 | /** 150 | * @param string $merchant 151 | * @return PaymentStatusResponse 152 | */ 153 | public function setMerchant(string $merchant): PaymentStatusResponse 154 | { 155 | $this->merchant = $merchant; 156 | return $this; 157 | } 158 | 159 | /** 160 | * @return bool 161 | */ 162 | public function isTest(): bool 163 | { 164 | return $this->test; 165 | } 166 | 167 | /** 168 | * @param bool $test 169 | * @return PaymentStatusResponse 170 | */ 171 | public function setTest(bool $test): PaymentStatusResponse 172 | { 173 | $this->test = $test; 174 | return $this; 175 | } 176 | 177 | /** 178 | * @return Money 179 | */ 180 | public function getPrice(): Money 181 | { 182 | return $this->price; 183 | } 184 | 185 | /** 186 | * @param Money $price 187 | * @return PaymentStatusResponse 188 | */ 189 | public function setPrice(Money $price): PaymentStatusResponse 190 | { 191 | $this->price = $price; 192 | return $this; 193 | } 194 | 195 | /** 196 | * @return string 197 | */ 198 | public function getCurrency(): string 199 | { 200 | return $this->curr; 201 | } 202 | 203 | /** 204 | * @param string $curr 205 | * @return PaymentStatusResponse 206 | */ 207 | public function setCurrency(string $curr): PaymentStatusResponse 208 | { 209 | $this->curr = $curr; 210 | return $this; 211 | } 212 | 213 | /** 214 | * @return string 215 | */ 216 | public function getLabel(): string 217 | { 218 | return $this->label; 219 | } 220 | 221 | /** 222 | * @param string $label 223 | * @return PaymentStatusResponse 224 | */ 225 | public function setLabel(string $label): PaymentStatusResponse 226 | { 227 | $this->label = $label; 228 | return $this; 229 | } 230 | 231 | /** 232 | * @return string 233 | */ 234 | public function getRefId(): string 235 | { 236 | return $this->refId; 237 | } 238 | 239 | /** 240 | * @param string $refId 241 | * @return PaymentStatusResponse 242 | */ 243 | public function setRefId(string $refId): PaymentStatusResponse 244 | { 245 | $this->refId = $refId; 246 | return $this; 247 | } 248 | 249 | /** 250 | * @return string 251 | */ 252 | public function getPayerId(): string 253 | { 254 | return $this->payerId; 255 | } 256 | 257 | /** 258 | * @param string $payerId 259 | * @return PaymentStatusResponse 260 | */ 261 | public function setPayerId(string $payerId): PaymentStatusResponse 262 | { 263 | $this->payerId = $payerId; 264 | return $this; 265 | } 266 | 267 | /** 268 | * @return string 269 | */ 270 | public function getMethod(): string 271 | { 272 | return $this->method; 273 | } 274 | 275 | /** 276 | * @param string $method 277 | * @return PaymentStatusResponse 278 | */ 279 | public function setMethod(string $method): PaymentStatusResponse 280 | { 281 | $this->method = $method; 282 | return $this; 283 | } 284 | 285 | /** 286 | * @return string 287 | */ 288 | public function getAccount(): string 289 | { 290 | return $this->account; 291 | } 292 | 293 | /** 294 | * @param string $account 295 | * @return PaymentStatusResponse 296 | */ 297 | public function setAccount(string $account): PaymentStatusResponse 298 | { 299 | $this->account = $account; 300 | return $this; 301 | } 302 | 303 | /** 304 | * @return string 305 | */ 306 | public function getEmail(): string 307 | { 308 | return $this->email; 309 | } 310 | 311 | /** 312 | * @param string $email 313 | * @return PaymentStatusResponse 314 | */ 315 | public function setEmail(string $email): PaymentStatusResponse 316 | { 317 | $this->email = $email; 318 | return $this; 319 | } 320 | 321 | /** 322 | * @return string 323 | */ 324 | public function getName(): string 325 | { 326 | return $this->name; 327 | } 328 | 329 | /** 330 | * @param string $name 331 | * @return PaymentStatusResponse 332 | */ 333 | public function setName(string $name): PaymentStatusResponse 334 | { 335 | $this->name = $name; 336 | return $this; 337 | } 338 | 339 | /** 340 | * @return string 341 | */ 342 | public function getTransId(): string 343 | { 344 | return $this->transId; 345 | } 346 | 347 | /** 348 | * @param string $transId 349 | * @return PaymentStatusResponse 350 | */ 351 | public function setTransId(string $transId): PaymentStatusResponse 352 | { 353 | $this->transId = $transId; 354 | return $this; 355 | } 356 | 357 | /** 358 | * @return string 359 | */ 360 | public function getSecret(): string 361 | { 362 | return $this->secret; 363 | } 364 | 365 | /** 366 | * @param string $secret 367 | * @return PaymentStatusResponse 368 | */ 369 | public function setSecret(string $secret): PaymentStatusResponse 370 | { 371 | $this->secret = $secret; 372 | return $this; 373 | } 374 | 375 | /** 376 | * @return string 377 | */ 378 | public function getStatus(): string 379 | { 380 | return $this->status; 381 | } 382 | 383 | /** 384 | * @param string $status 385 | * @return PaymentStatusResponse 386 | */ 387 | public function setStatus(string $status): PaymentStatusResponse 388 | { 389 | $this->status = $status; 390 | return $this; 391 | } 392 | 393 | /** 394 | * @return string 395 | */ 396 | public function getPayerName(): string 397 | { 398 | return $this->payerName; 399 | } 400 | 401 | /** 402 | * @param string $payerName 403 | * @return PaymentStatusResponse 404 | */ 405 | public function setPayerName(string $payerName): PaymentStatusResponse 406 | { 407 | $this->payerName = $payerName; 408 | return $this; 409 | } 410 | 411 | /** 412 | * @return string 413 | */ 414 | public function getFee(): string 415 | { 416 | return $this->fee; 417 | } 418 | 419 | /** 420 | * @param string $fee 421 | * @return PaymentStatusResponse 422 | */ 423 | public function setFee(string $fee): PaymentStatusResponse 424 | { 425 | $this->fee = $fee; 426 | return $this; 427 | } 428 | } 429 | -------------------------------------------------------------------------------- /src/Entity/Response/PreauthCancelResponse.php: -------------------------------------------------------------------------------- 1 | getContent()); 27 | 28 | $code = (int) $parsedResponse['code']; 29 | $message = $parsedResponse['message']; 30 | 31 | switch ($code) { 32 | case 0: 33 | $this->setCode($code) 34 | ->setMessage($message); 35 | 36 | break; 37 | 38 | case 1400: 39 | throw new MissingParamException($message, $code); 40 | 41 | case 1401: 42 | throw new PreauthException($message, $code); 43 | 44 | default: 45 | throw new ApiException($message, $code); 46 | } 47 | } 48 | 49 | /** 50 | * @return int 51 | */ 52 | public function getCode(): int 53 | { 54 | return $this->code; 55 | } 56 | 57 | /** 58 | * @param int $code 59 | * @return PreauthCancelResponse 60 | */ 61 | public function setCode(int $code): PreauthCancelResponse 62 | { 63 | $this->code = $code; 64 | return $this; 65 | } 66 | 67 | /** 68 | * @return string 69 | */ 70 | public function getMessage(): string 71 | { 72 | return $this->message; 73 | } 74 | 75 | /** 76 | * @param string $message 77 | * @return PreauthCancelResponse 78 | */ 79 | public function setMessage(string $message): PreauthCancelResponse 80 | { 81 | $this->message = $message; 82 | return $this; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/Entity/Response/PreauthCaptureResponse.php: -------------------------------------------------------------------------------- 1 | getContent()); 27 | 28 | $code = (int) $parsedResponse['code']; 29 | $message = $parsedResponse['message']; 30 | 31 | switch ($code) { 32 | case 0: 33 | $this->setCode($code) 34 | ->setMessage($message); 35 | 36 | break; 37 | 38 | case 1400: 39 | throw new MissingParamException($message, $code); 40 | 41 | case 1401: 42 | throw new PreauthException($message, $code); 43 | 44 | default: 45 | throw new ApiException($message, $code); 46 | } 47 | } 48 | 49 | /** 50 | * 51 | * @return array 52 | */ 53 | public function toArray(): array 54 | { 55 | return [ 56 | 'code' => $this->getCode(), 57 | 'message' => $this->getMessage(), 58 | ]; 59 | } 60 | 61 | /** 62 | * @return int 63 | */ 64 | public function getCode(): int 65 | { 66 | return $this->code; 67 | } 68 | 69 | /** 70 | * @param int $code 71 | * @return PreauthCaptureResponse 72 | */ 73 | public function setCode(int $code): self 74 | { 75 | $this->code = $code; 76 | return $this; 77 | } 78 | 79 | /** 80 | * @return string 81 | */ 82 | public function getMessage(): string 83 | { 84 | return $this->message; 85 | } 86 | 87 | /** 88 | * @param string $message 89 | * @return PreauthCaptureResponse 90 | */ 91 | public function setMessage(string $message): self 92 | { 93 | $this->message = $message; 94 | return $this; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/Entity/Response/PublicCryptoKeyResponse.php: -------------------------------------------------------------------------------- 1 | getContent()); 22 | 23 | $code = (int) $parsedResponse['code']; 24 | $message = $parsedResponse['message'] ?? ''; 25 | 26 | switch ($code) { 27 | case 0: 28 | $this->setCode($code) 29 | ->setMessage($message) 30 | ->setKey($parsedResponse['key']); 31 | break; 32 | 33 | default: 34 | throw new ApiException($message, $code); 35 | } 36 | } 37 | 38 | /** 39 | * @return array 40 | */ 41 | public function toArray(): array 42 | { 43 | $output = [ 44 | 'code' => $this->getCode(), 45 | 'message' => $this->getMessage(), 46 | 'key' => $this->getKey(), 47 | ]; 48 | 49 | return $output; 50 | } 51 | 52 | /** 53 | * @return int 54 | */ 55 | public function getCode(): int 56 | { 57 | return $this->code; 58 | } 59 | 60 | /** 61 | * @param int $code 62 | * @return PublicCryptoKeyResponse 63 | */ 64 | public function setCode(int $code): PublicCryptoKeyResponse 65 | { 66 | $this->code = $code; 67 | return $this; 68 | } 69 | 70 | /** 71 | * @return string 72 | */ 73 | public function getMessage(): string 74 | { 75 | return $this->message; 76 | } 77 | 78 | /** 79 | * @param string $message 80 | * @return PublicCryptoKeyResponse 81 | */ 82 | public function setMessage(string $message): PublicCryptoKeyResponse 83 | { 84 | $this->message = $message; 85 | return $this; 86 | } 87 | 88 | /** 89 | * @return string 90 | */ 91 | public function getKey(): string 92 | { 93 | return $this->key; 94 | } 95 | 96 | /** 97 | * @param string $key 98 | * @return PublicCryptoKeyResponse 99 | */ 100 | public function setKey(string $key): PublicCryptoKeyResponse 101 | { 102 | $this->key = $key; 103 | return $this; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/Entity/Response/RecurringPaymentResponse.php: -------------------------------------------------------------------------------- 1 | getContent()); 27 | 28 | $code = (int) $parsedResponse['code']; 29 | $message = $parsedResponse['message']; 30 | 31 | switch ($code) { 32 | case 0: 33 | $this->setCode($code) 34 | ->setMessage($message) 35 | ->setTransId($parsedResponse['transId']); 36 | 37 | break; 38 | 39 | case 1400: 40 | throw new MissingParamException($message, $code); 41 | 42 | default: 43 | throw new ApiException($message, $code); 44 | } 45 | } 46 | 47 | /** 48 | * 49 | * @return array 50 | */ 51 | public function toArray(): array 52 | { 53 | return [ 54 | 'code' => $this->getCode(), 55 | 'message' => $this->getMessage(), 56 | 'transId' => $this->getTransId(), 57 | ]; 58 | } 59 | 60 | /** 61 | * @return int 62 | */ 63 | public function getCode(): int 64 | { 65 | return $this->code; 66 | } 67 | 68 | /** 69 | * @param int $code 70 | * @return RecurringPaymentResponse 71 | */ 72 | public function setCode(int $code): self 73 | { 74 | $this->code = $code; 75 | return $this; 76 | } 77 | 78 | /** 79 | * @return string 80 | */ 81 | public function getMessage(): string 82 | { 83 | return $this->message; 84 | } 85 | 86 | /** 87 | * @param string $message 88 | * @return RecurringPaymentResponse 89 | */ 90 | public function setMessage(string $message): self 91 | { 92 | $this->message = $message; 93 | return $this; 94 | } 95 | 96 | /** 97 | * @return string 98 | */ 99 | public function getTransId(): string 100 | { 101 | return $this->transId; 102 | } 103 | 104 | /** 105 | * @param string $transId 106 | * @return RecurringPaymentResponse 107 | */ 108 | public function setTransId(string $transId): RecurringPaymentResponse 109 | { 110 | $this->transId = $transId; 111 | return $this; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/Entity/Response/RefundResponse.php: -------------------------------------------------------------------------------- 1 | getContent()); 26 | 27 | $code = (int) $parsedResponse['code']; 28 | $message = $parsedResponse['message']; 29 | 30 | switch ($code) { 31 | case 0: 32 | $this->setCode($code) 33 | ->setMessage($message); 34 | 35 | break; 36 | 37 | case 1400: 38 | throw new MissingParamException($message, $code); 39 | 40 | default: 41 | throw new ApiException($message, $code); 42 | } 43 | } 44 | 45 | /** 46 | * 47 | * @return array 48 | */ 49 | public function toArray(): array 50 | { 51 | return [ 52 | 'code' => $this->getCode(), 53 | 'message' => $this->getMessage(), 54 | ]; 55 | } 56 | 57 | /** 58 | * @return int 59 | */ 60 | public function getCode(): int 61 | { 62 | return $this->code; 63 | } 64 | 65 | /** 66 | * @param int $code 67 | * @return RefundResponse 68 | */ 69 | public function setCode(int $code): self 70 | { 71 | $this->code = $code; 72 | return $this; 73 | } 74 | 75 | /** 76 | * @return string 77 | */ 78 | public function getMessage(): string 79 | { 80 | return $this->message; 81 | } 82 | 83 | /** 84 | * @param string $message 85 | * @return RefundResponse 86 | */ 87 | public function setMessage(string $message): self 88 | { 89 | $this->message = $message; 90 | return $this; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/Entity/Response/SimulationResponse.php: -------------------------------------------------------------------------------- 1 | getContent()); 25 | 26 | $code = (int) $parsedResponse['code']; 27 | $message = $parsedResponse['message']; 28 | 29 | switch ($code) { 30 | case 0: 31 | $this->setCode($code) 32 | ->setMessage($message); 33 | 34 | break; 35 | 36 | default: 37 | throw new ApiException($message, $code); 38 | } 39 | } 40 | 41 | /** 42 | * 43 | * @return array 44 | */ 45 | public function toArray(): array 46 | { 47 | return [ 48 | 'code' => $this->getCode(), 49 | 'message' => $this->getMessage(), 50 | ]; 51 | } 52 | 53 | /** 54 | * @return int 55 | */ 56 | public function getCode(): int 57 | { 58 | return $this->code; 59 | } 60 | 61 | /** 62 | * @param int $code 63 | * @return SimulationResponse 64 | */ 65 | public function setCode(int $code): self 66 | { 67 | $this->code = $code; 68 | return $this; 69 | } 70 | 71 | /** 72 | * @return string 73 | */ 74 | public function getMessage(): string 75 | { 76 | return $this->message; 77 | } 78 | 79 | /** 80 | * @param string $message 81 | * @return SimulationResponse 82 | */ 83 | public function setMessage(string $message): self 84 | { 85 | $this->message = $message; 86 | return $this; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/Entity/Response/SingleTransferResponse.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | protected array $paymentsList = []; 18 | 19 | /** 20 | * @param Response $singleTransferResponse 21 | */ 22 | public function __construct(Response $singleTransferResponse) 23 | { 24 | $paymentsListJson = $singleTransferResponse->getContent(); 25 | $paymentsInfoList = json_decode($singleTransferResponse->getContent(), true); 26 | 27 | 28 | foreach ($paymentsInfoList as $paymentData) { 29 | $paymentInfo = (new PaymentInfo())->fromArray($paymentData); 30 | $this->addPaymentInfo($paymentInfo); 31 | } 32 | } 33 | 34 | /** 35 | * @return array 36 | */ 37 | public function getPaymentsList(): array 38 | { 39 | return $this->paymentsList; 40 | } 41 | 42 | /** 43 | * @param array $paymentsList 44 | * @return SingleTransferResponse 45 | */ 46 | public function setPaymentsList(array $paymentsList): self 47 | { 48 | $this->paymentsList = $paymentsList; 49 | return $this; 50 | } 51 | 52 | public function addPaymentInfo(PaymentInfo $paymentInfo): self 53 | { 54 | $this->paymentsList[] = $paymentInfo; 55 | return $this; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Entity/Response/TransferListResponse.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | protected array $transferList = []; 17 | 18 | /** 19 | * @param Response $transferListResponse 20 | */ 21 | public function __construct(Response $transferListResponse) 22 | { 23 | $transferListJson = $transferListResponse->getContent(); 24 | $transferList = (array) json_decode($transferListResponse->getContent(), true); 25 | 26 | foreach ($transferList as $transferData) { 27 | $transfer = (new Transfer())->fromArray($transferData); 28 | $this->addTransfer($transfer); 29 | } 30 | } 31 | 32 | /** 33 | * @return array 34 | */ 35 | public function getTransferList(): array 36 | { 37 | return $this->transferList; 38 | } 39 | 40 | /** 41 | * @param array $transferList 42 | * @return TransferListResponse 43 | */ 44 | public function setTransferList(array $transferList): self 45 | { 46 | $this->transferList = $transferList; 47 | return $this; 48 | } 49 | 50 | public function addTransfer(Transfer $transfer): self 51 | { 52 | $this->transferList[] = $transfer; 53 | return $this; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Entity/Transfer.php: -------------------------------------------------------------------------------- 1 | $transferData 18 | * @return $this 19 | * @throws \Exception 20 | */ 21 | public function fromArray(array $transferData){ 22 | $this->setTransferId((int) $transferData['transferId']) 23 | ->setTransferDate(new DateTime((string) $transferData['transferDate'])) 24 | ->setAccountCounterparty((string) $transferData['accountCounterparty']) 25 | ->setAccountOutgoing((string) $transferData['accountOutgoing']) 26 | ->setVariableSymbol((string) $transferData['variableSymbol']); 27 | 28 | return $this; 29 | } 30 | 31 | /** 32 | * @return int 33 | */ 34 | public function getTransferId(): int 35 | { 36 | return $this->transferId; 37 | } 38 | 39 | /** 40 | * @param int $transferId 41 | * @return Transfer 42 | */ 43 | public function setTransferId(int $transferId): Transfer 44 | { 45 | $this->transferId = $transferId; 46 | return $this; 47 | } 48 | 49 | /** 50 | * @return DateTimeInterface 51 | */ 52 | public function getTransferDate(): DateTimeInterface 53 | { 54 | return $this->transferDate; 55 | } 56 | 57 | /** 58 | * @param DateTimeInterface $transferDate 59 | * @return Transfer 60 | */ 61 | public function setTransferDate(DateTimeInterface $transferDate): Transfer 62 | { 63 | $this->transferDate = $transferDate; 64 | return $this; 65 | } 66 | 67 | /** 68 | * @return string 69 | */ 70 | public function getAccountCounterparty(): string 71 | { 72 | return $this->accountCounterparty; 73 | } 74 | 75 | /** 76 | * @param string $accountCounterparty 77 | * @return Transfer 78 | */ 79 | public function setAccountCounterparty(string $accountCounterparty): Transfer 80 | { 81 | $this->accountCounterparty = $accountCounterparty; 82 | return $this; 83 | } 84 | 85 | /** 86 | * @return string 87 | */ 88 | public function getAccountOutgoing(): string 89 | { 90 | return $this->accountOutgoing; 91 | } 92 | 93 | /** 94 | * @param string $accountOutgoing 95 | * @return Transfer 96 | */ 97 | public function setAccountOutgoing(string $accountOutgoing): Transfer 98 | { 99 | $this->accountOutgoing = $accountOutgoing; 100 | return $this; 101 | } 102 | 103 | /** 104 | * @return string 105 | */ 106 | public function getVariableSymbol(): string 107 | { 108 | return $this->variableSymbol; 109 | } 110 | 111 | /** 112 | * @param string $variableSymbol 113 | * @return Transfer 114 | */ 115 | public function setVariableSymbol(string $variableSymbol): Transfer 116 | { 117 | $this->variableSymbol = $variableSymbol; 118 | return $this; 119 | } 120 | 121 | 122 | } 123 | -------------------------------------------------------------------------------- /src/Exception/Api/MissingParamException.php: -------------------------------------------------------------------------------- 1 | > 12 | */ 13 | private $headers; 14 | 15 | /** 16 | * @var StreamInterface 17 | */ 18 | private $body; 19 | 20 | /** 21 | * @var string 22 | */ 23 | private $protocolVersion = "1.1"; 24 | 25 | public function getHeaders(): array 26 | { 27 | return $this->headers; 28 | } 29 | 30 | public function hasHeader($name): bool 31 | { 32 | return isset($this->headers[$name]); 33 | } 34 | 35 | public function getHeader($name): array 36 | { 37 | return $this->headers[$name] ?? []; 38 | } 39 | 40 | public function getHeaderLine($name): string 41 | { 42 | return join(", ", $this->getHeader($name)); 43 | } 44 | 45 | public function withHeader($name, $value): MessageInterface 46 | { 47 | $out = clone $this; 48 | $out->headers[$name] = is_array($value) ? $value : [$value]; 49 | 50 | return $out; 51 | } 52 | 53 | public function withAddedHeader($name, $value): MessageInterface 54 | { 55 | $out = clone $this; 56 | 57 | if (!$out->hasHeader($name)) { 58 | $out->headers[$name] = []; 59 | } 60 | $out->headers[$name][] = $value; 61 | 62 | return $out; 63 | } 64 | 65 | public function withoutHeader($name): MessageInterface 66 | { 67 | $out = clone $this; 68 | unset($out->headers[$name]); 69 | 70 | return $out; 71 | } 72 | 73 | public function getBody(): StreamInterface 74 | { 75 | return $this->body; 76 | } 77 | 78 | public function withBody(StreamInterface $body): MessageInterface 79 | { 80 | $out = clone $this; 81 | $out->body = $body; 82 | 83 | return $out; 84 | } 85 | 86 | public function getProtocolVersion(): string 87 | { 88 | return $this->protocolVersion; 89 | } 90 | 91 | public function withProtocolVersion($version): MessageInterface 92 | { 93 | $out = clone $this; 94 | $out->protocolVersion = $version; 95 | 96 | return $out; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/Http/PsrStream.php: -------------------------------------------------------------------------------- 1 | stream = $stream; 18 | fwrite($this->stream, $content); 19 | rewind($this->stream); 20 | } 21 | } 22 | 23 | public function __toString(): string 24 | { 25 | rewind($this->stream); 26 | $streamString = stream_get_contents($this->stream); 27 | return $streamString !== false ? $streamString : ''; 28 | } 29 | 30 | public function close(): void 31 | { 32 | fclose($this->stream); 33 | } 34 | 35 | public function detach() 36 | { 37 | $detached = $this->stream; 38 | return $detached; 39 | } 40 | 41 | public function getSize(): ?int 42 | { 43 | $stats = fstat($this->stream); 44 | if ($stats !== false) { 45 | return $stats['size']; 46 | } 47 | return null; 48 | } 49 | 50 | public function tell(): int 51 | { 52 | $stream = ftell($this->stream); 53 | return $stream !== false ? $stream : 0; 54 | } 55 | 56 | public function eof(): bool 57 | { 58 | return feof($this->stream); 59 | } 60 | 61 | public function isSeekable(): bool 62 | { 63 | return true; 64 | } 65 | 66 | public function seek($offset, $whence = SEEK_SET): void 67 | { 68 | fseek($this->stream, $offset, $whence); 69 | } 70 | 71 | public function rewind(): void 72 | { 73 | $this->seek(0); 74 | } 75 | 76 | public function isWritable(): bool 77 | { 78 | return true; 79 | } 80 | 81 | public function write($string): int 82 | { 83 | $stream = fwrite($this->stream, $string); 84 | return $stream !== false ? $stream : 0; 85 | } 86 | 87 | public function isReadable(): bool 88 | { 89 | return true; 90 | } 91 | 92 | public function read($length): string 93 | { 94 | $length = max($length, 0); 95 | 96 | $stream = fread($this->stream, $length); 97 | return $stream == false ? '' : $stream; 98 | } 99 | 100 | public function getContents(): string 101 | { 102 | $stream = stream_get_contents($this->stream); 103 | return $stream !== false ? $stream : ''; 104 | } 105 | 106 | public function getMetadata($key = null) 107 | { 108 | return $key != false ? stream_get_meta_data($this->stream)[$key] ?? null : stream_get_meta_data($this->stream); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/Http/Query.php: -------------------------------------------------------------------------------- 1 | 10 | */ 11 | public static function parse(string $string): array 12 | { 13 | /** @var array */ 14 | $result = []; 15 | 16 | foreach (explode("&", $string) as $keyValuePair) { 17 | $exploded = explode("=", rawurldecode($keyValuePair), 2); 18 | $key = $exploded[0]; 19 | $value = $exploded[1] ?? ""; 20 | $result[$key] = $value; 21 | // $exploded = explode("=", rawurldecode($keyValuePair), 2); 22 | // $key = $exploded[0]; 23 | // $value = $exploded[1] ?? ""; 24 | // if (array_key_exists($key, $result)) { 25 | // if (!is_array($result[$key])) { 26 | // $result[$key] = [$result[$key]]; 27 | // } 28 | // $result[$key][] = $value; 29 | // } else { 30 | // $result[$key] = $value; 31 | // } 32 | } 33 | 34 | return $result; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Http/Response.php: -------------------------------------------------------------------------------- 1 | */ 10 | protected $parsed; 11 | 12 | /** @var string */ 13 | protected $content; 14 | 15 | /** 16 | * @var MessageInterface 17 | */ 18 | protected $origin; 19 | 20 | public function __construct(MessageInterface $origin) 21 | { 22 | $this->origin = $origin; 23 | } 24 | 25 | /** 26 | * @return string 27 | */ 28 | public function getContent(): string 29 | { 30 | if ($this->content === null) { 31 | $body = $this->origin->getBody(); 32 | $body->rewind(); 33 | 34 | $this->content = $body->getContents(); 35 | } 36 | 37 | return $this->content; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Http/Transport.php: -------------------------------------------------------------------------------- 1 | config = $config; 23 | $this->logger = $logger; 24 | } 25 | 26 | /** 27 | * @param mixed[] $data 28 | * @param mixed[] $options 29 | */ 30 | public function post(string $urn, array $data, array $options = []): Response 31 | { 32 | $data = array_merge([ 33 | 'merchant' => $this->config->getMerchant(), 34 | 'secret' => $this->config->getSecret(), 35 | ], $data); 36 | 37 | $curl = curl_init(); 38 | 39 | curl_setopt($curl, CURLOPT_URL, $this->config->getUrl() . $urn); 40 | curl_setopt($curl, CURLOPT_POST, 1); 41 | curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data)); 42 | curl_setopt($curl, CURLOPT_HTTPHEADER, ["content-type: application/x-www-form-urlencoded",]); 43 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 44 | 45 | $response = curl_exec($curl); 46 | $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); 47 | $e = curl_error($curl); 48 | 49 | if ($this->logger !== null) { 50 | $this->logger->log(LogLevel::INFO, 'Request to "' . $this->config->getUrl() . $urn . '" sent'); 51 | $this->logger->log(LogLevel::DEBUG, 'Response: ' . $response); 52 | $this->logger->log(LogLevel::DEBUG, 'cURL info: ' . json_encode(curl_getinfo($curl))); 53 | 54 | // => [level, message] 55 | switch (true){ 56 | case ($response === false): 57 | $log = [LogLevel::ERROR, 'cURL request failed: ' . $e]; 58 | break; 59 | case ($httpCode >= 500): 60 | $log = [LogLevel::CRITICAL, 'Server error: HTTP code ' . $httpCode]; 61 | break; 62 | case ($httpCode >= 400): 63 | $log = [LogLevel::ERROR, 'Client error: HTTP code ' . $httpCode]; 64 | break; 65 | default: 66 | $log = [LogLevel::INFO, 'cURL request completed successfully.']; 67 | break; 68 | } 69 | $this->logger->log(...$log); 70 | } 71 | 72 | curl_close($curl); 73 | 74 | if ($e != '') { 75 | throw new ComgateException("Request failed: {$e}", 0); 76 | } 77 | 78 | return new Response(self::createResponse($response)); 79 | } 80 | 81 | /** 82 | * @return Config 83 | */ 84 | public function getConfig(): Config 85 | { 86 | return $this->config; 87 | } 88 | 89 | /** 90 | * @param Config $config 91 | * @return ITransport 92 | */ 93 | public function setConfig(Config $config): ITransport 94 | { 95 | $this->config = $config; 96 | return $this; 97 | } 98 | 99 | /** 100 | * @param bool|string $curlResponse 101 | * @return MessageInterface 102 | */ 103 | private function createResponse($curlResponse): MessageInterface 104 | { 105 | $response = new PsrResponse(); 106 | 107 | if (strstr((string)$curlResponse, "\r\n\r\n") === false) { 108 | $curlResponse = "\r\n\r\n" . $curlResponse; 109 | } 110 | 111 | $headerSplit = explode("\r\n\r\n", (string)$curlResponse, 2); 112 | $headers = $headerSplit[0]; 113 | $body = $headerSplit[1]; 114 | 115 | foreach (explode("\r\n", $headers) as $h) { 116 | if (strstr($h, ": ") !== false) { 117 | [$name, $value] = explode(": ", $h, 2); 118 | $response = $response->withAddedHeader($name, $value); 119 | } 120 | } 121 | 122 | $response = $response->withBody(new PsrStream($body)); 123 | 124 | return $response; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/Logging/FileLogger.php: -------------------------------------------------------------------------------- 1 | file = $file; 17 | } 18 | 19 | /** 20 | * @param mixed $level 21 | * @param string|Stringable $message 22 | * @param array $context 23 | */ 24 | public function log($level, $message, array $context = []): void 25 | { 26 | file_put_contents($this->file, $message . "\n", FILE_APPEND); 27 | } 28 | 29 | /** 30 | * @param string|Stringable $message 31 | * @param array $context 32 | */ 33 | public function emergency($message, array $context = []): void 34 | { 35 | $this->log(LogLevel::EMERGENCY, $message, $context); 36 | } 37 | 38 | /** 39 | * @param string|Stringable $message 40 | * @param array $context 41 | */ 42 | public function alert($message, array $context = []): void 43 | { 44 | $this->log(LogLevel::ALERT, $message, $context); 45 | } 46 | 47 | /** 48 | * @param string|Stringable $message 49 | * @param array $context 50 | */ 51 | public function critical($message, array $context = []): void 52 | { 53 | $this->log(LogLevel::CRITICAL, $message, $context); 54 | } 55 | 56 | /** 57 | * @param string|Stringable $message 58 | * @param array $context 59 | */ 60 | public function error($message, array $context = []): void 61 | { 62 | $this->log(LogLevel::ERROR, $message, $context); 63 | } 64 | 65 | /** 66 | * @param string|Stringable $message 67 | * @param array $context 68 | */ 69 | public function warning($message, array $context = []): void 70 | { 71 | $this->log(LogLevel::WARNING, $message, $context); 72 | } 73 | 74 | /** 75 | * @param string|Stringable $message 76 | * @param array $context 77 | */ 78 | public function notice($message, array $context = []): void 79 | { 80 | $this->log(LogLevel::NOTICE, $message, $context); 81 | } 82 | 83 | /** 84 | * @param string|Stringable $message 85 | * @param array $context 86 | */ 87 | public function info($message, array $context = []): void 88 | { 89 | $this->log(LogLevel::INFO, $message, $context); 90 | } 91 | 92 | /** 93 | * @param string|Stringable $message 94 | * @param array $context 95 | */ 96 | public function debug($message, array $context = []): void 97 | { 98 | $this->log(LogLevel::DEBUG, $message, $context); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/Logging/StdoutLogger.php: -------------------------------------------------------------------------------- 1 | $context 16 | * @return void 17 | */ 18 | public function log($level, $message, array $context = []): void 19 | { 20 | $level = (string) $level; 21 | echo "[{$level}]: {$message}"; 22 | } 23 | 24 | /** 25 | * @param string|Stringable $message 26 | * @param array $context 27 | * @return void 28 | */ 29 | public function emergency($message, array $context = []): void 30 | { 31 | $this->log(LogLevel::EMERGENCY, $message, $context); 32 | } 33 | 34 | /** 35 | * @param string|Stringable $message 36 | * @param array $context 37 | * @return void 38 | */ 39 | public function alert($message, array $context = []): void 40 | { 41 | $this->log(LogLevel::ALERT, $message, $context); 42 | } 43 | 44 | /** 45 | * @param string|Stringable $message 46 | * @param array $context 47 | * @return void 48 | */ 49 | public function critical($message, array $context = []): void 50 | { 51 | $this->log(LogLevel::CRITICAL, $message, $context); 52 | } 53 | 54 | /** 55 | * @param string|Stringable $message 56 | * @param array $context 57 | * @return void 58 | */ 59 | public function error($message, array $context = []): void 60 | { 61 | $this->log(LogLevel::ERROR, $message, $context); 62 | } 63 | 64 | /** 65 | * @param string|Stringable $message 66 | * @param array $context 67 | * @return void 68 | */ 69 | public function warning($message, array $context = []): void 70 | { 71 | $this->log(LogLevel::WARNING, $message, $context); 72 | } 73 | 74 | /** 75 | * @param string|Stringable $message 76 | * @param array $context 77 | * @return void 78 | */ 79 | public function notice($message, array $context = []): void 80 | { 81 | $this->log(LogLevel::NOTICE, $message, $context); 82 | } 83 | 84 | /** 85 | * @param string|Stringable $message 86 | * @param array $context 87 | * @return void 88 | */ 89 | public function info($message, array $context = []): void 90 | { 91 | $this->log(LogLevel::INFO, $message, $context); 92 | } 93 | 94 | /** 95 | * @param string|Stringable $message 96 | * @param array $context 97 | * @return void 98 | */ 99 | public function debug($message, array $context = []): void 100 | { 101 | $this->log(LogLevel::DEBUG, $message, $context); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/Utils/Helpers.php: -------------------------------------------------------------------------------- 1 |