├── .gitignore ├── composer.json ├── readme.md └── src ├── Exception ├── BaseException.php ├── PaymentException.php └── RequestException.php ├── Manager.php └── Model ├── Required3DS.php └── Transaction.php /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "cloudpayments/cloud-payments-client", 3 | "description": "Client for CloudPayments.ru", 4 | "version" : "0.0.9", 5 | "type" : "library", 6 | "license" : "MIT", 7 | "require" : { 8 | "php": ">=5.5" 9 | }, 10 | "autoload" : { 11 | "psr-4" : { 12 | "CloudPayments\\" : "src/" 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # CloudPayments PHP Client Library 2 | 3 | Клиент для платежного сервиса [CloudPayments](http://cloudpayments.ru/). 4 | Позволяет обращаться к [API CloudPayments](http://cloudpayments.ru/Docs/Api) из кода на PHP. 5 | 6 | ## Установка 7 | ```bash 8 | composer require cloudpayments/cloudpayments-php-client 9 | ``` 10 | 11 | ## Использование 12 | ```php 13 | $client = new \CloudPayments\Manager($publicKey, $privateKey); 14 | $transaction = $client->chargeToken($amount, $currency, $accountId, $cardToken); 15 | 16 | echo $transaction->getId(); 17 | ``` 18 | 19 | ## Передача чека в онлайн-кассу 20 | ```php 21 | $items[] = array( 22 | "label" => 'Товар реальный', //наименование товара 23 | "price" => 30.00, //цена 24 | "quantity" => 3.00, //количество 25 | "amount" => 90.00, //сумма 26 | "vat" => 18, //ставка НДС 27 | "ean13" => '460123456789' //штрих-код, необязательный 28 | ); 29 | $client->sendReceipt($inn, $invoiceId, $accountId, $items, $taxationSystem, $email, $phone); 30 | ``` -------------------------------------------------------------------------------- /src/Exception/BaseException.php: -------------------------------------------------------------------------------- 1 | reason = $response['Model']['Reason']; 30 | $this->reasonCode = $response['Model']['ReasonCode']; 31 | $this->cardHolderMessage = $response['Model']['CardHolderMessage']; 32 | $this->transaction = $response['Model']; 33 | 34 | parent::__construct($this->reason); 35 | } 36 | 37 | /** 38 | * @return string 39 | */ 40 | public function getReason() 41 | { 42 | return $this->reason; 43 | } 44 | 45 | /** 46 | * @return integer 47 | */ 48 | public function getReasonCode() 49 | { 50 | return $this->reasonCode; 51 | } 52 | 53 | /** 54 | * @return string 55 | */ 56 | public function getCardHolderMessage() 57 | { 58 | return $this->cardHolderMessage; 59 | } 60 | 61 | /** 62 | * @return \CloudPayments\Model\Transaction 63 | */ 64 | public function getTransaction() 65 | { 66 | return $this->transaction; 67 | } 68 | } -------------------------------------------------------------------------------- /src/Exception/RequestException.php: -------------------------------------------------------------------------------- 1 | publicKey = $publicKey; 40 | $this->privateKey = $privateKey; 41 | $this->enableSSL = $enableSSL ? 2 : 0; 42 | } 43 | 44 | /** 45 | * @param string $endpoint 46 | * @param array $params 47 | * @return array 48 | */ 49 | protected function sendRequest($endpoint, array $params = []) 50 | { 51 | $params['CultureName'] = $this->locale; 52 | 53 | $curl = curl_init(); 54 | 55 | curl_setopt($curl, CURLOPT_URL, $this->url . $endpoint); 56 | curl_setopt($curl, CURLOPT_USERPWD, sprintf('%s:%s', $this->publicKey, $this->privateKey)); 57 | curl_setopt($curl, CURLOPT_TIMEOUT, 20); 58 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 59 | curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 60 | curl_setopt($curl, CURLOPT_POST, 1); 61 | curl_setopt($curl, CURLOPT_POSTFIELDS, $params); 62 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, $this->enableSSL); 63 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->enableSSL); 64 | 65 | $result = curl_exec($curl); 66 | 67 | curl_close($curl); 68 | 69 | return (array)json_decode($result, true); 70 | } 71 | 72 | /** 73 | * @param string $endpoint 74 | * @param $params 75 | * @return array 76 | */ 77 | protected function sendJSONRequest($endpoint, $params) 78 | { 79 | $params['CultureName'] = $this->locale; 80 | 81 | $curl = curl_init(); 82 | 83 | curl_setopt($curl, CURLOPT_URL, $this->url . $endpoint); 84 | curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json")); 85 | curl_setopt($curl, CURLOPT_USERPWD, sprintf('%s:%s', $this->publicKey, $this->privateKey)); 86 | curl_setopt($curl, CURLOPT_TIMEOUT, 20); 87 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 88 | curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 89 | curl_setopt($curl, CURLOPT_POST, 1); 90 | curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params)); 91 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, $this->enableSSL); 92 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->enableSSL); 93 | 94 | $result = curl_exec($curl); 95 | 96 | curl_close($curl); 97 | 98 | return (array)json_decode($result, true); 99 | } 100 | 101 | /** 102 | * @return string 103 | */ 104 | public function getLocale() 105 | { 106 | return $this->locale; 107 | } 108 | 109 | /** 110 | * @param string $locale 111 | */ 112 | public function setLocale($locale) 113 | { 114 | $this->locale = $locale; 115 | } 116 | 117 | /** 118 | * @throws Exception\RequestException 119 | */ 120 | public function test() 121 | { 122 | $response = $this->sendRequest('/test'); 123 | if (!$response['Success']) { 124 | throw new Exception\RequestException($response); 125 | } 126 | } 127 | 128 | /** 129 | * @param $amount 130 | * @param $currency 131 | * @param $ipAddress 132 | * @param $cardHolderName 133 | * @param $cryptogram 134 | * @param array $params 135 | * @param bool $requireConfirmation 136 | * @return Model\Required3DS|Model\Transaction 137 | * @throws Exception\PaymentException 138 | * @throws Exception\RequestException 139 | */ 140 | public function chargeCard($amount, $currency, $ipAddress, $cardHolderName, $cryptogram, $params = [], $requireConfirmation = false) 141 | { 142 | $endpoint = $requireConfirmation ? '/payments/cards/auth' : '/payments/cards/charge'; 143 | $defaultParams = [ 144 | 'Amount' => $amount, 145 | 'Currency' => $currency, 146 | 'IpAddress' => $ipAddress, 147 | 'Name' => $cardHolderName, 148 | 'CardCryptogramPacket' => $cryptogram 149 | ]; 150 | 151 | $response = $this->sendRequest($endpoint, array_merge($defaultParams, $params)); 152 | 153 | if ($response['Success']) { 154 | return Model\Transaction::fromArray($response['Model']); 155 | } 156 | 157 | if ($response['Message']) { 158 | throw new Exception\RequestException($response); 159 | } 160 | 161 | if (isset($response['Model']['ReasonCode']) && $response['Model']['ReasonCode'] !== 0) { 162 | throw new Exception\PaymentException($response); 163 | } 164 | 165 | return Model\Required3DS::fromArray($response['Model']); 166 | } 167 | 168 | /** 169 | * @param $amount 170 | * @param $currency 171 | * @param $accountId 172 | * @param $token 173 | * @param array $params 174 | * @param bool $requireConfirmation 175 | * @return Model\Required3DS|Model\Transaction 176 | * @throws Exception\PaymentException 177 | * @throws Exception\RequestException 178 | */ 179 | public function chargeToken($amount, $currency, $accountId, $token, $params = [], $requireConfirmation = false) 180 | { 181 | $endpoint = $requireConfirmation ? '/payments/tokens/auth' : '/payments/tokens/charge'; 182 | $defaultParams = [ 183 | 'Amount' => $amount, 184 | 'Currency' => $currency, 185 | 'AccountId' => $accountId, 186 | 'Token' => $token, 187 | ]; 188 | 189 | $response = $this->sendRequest($endpoint, array_merge($defaultParams, $params)); 190 | 191 | if ($response['Success']) { 192 | return Model\Transaction::fromArray($response['Model']); 193 | } 194 | 195 | if ($response['Message']) { 196 | throw new Exception\RequestException($response); 197 | } 198 | 199 | if (isset($response['Model']['ReasonCode']) && $response['Model']['ReasonCode'] !== 0) { 200 | throw new Exception\PaymentException($response); 201 | } 202 | 203 | return Model\Required3DS::fromArray($response['Model']); 204 | } 205 | 206 | /** 207 | * @param $transactionId 208 | * @param $token 209 | * @return Model\Transaction 210 | * @throws Exception\PaymentException 211 | * @throws Exception\RequestException 212 | */ 213 | public function confirm3DS($transactionId, $token) 214 | { 215 | $response = $this->sendRequest('/payments/cards/post3ds', [ 216 | 'TransactionId' => $transactionId, 217 | 'PaRes' => $token 218 | ]); 219 | 220 | if ($response['Message']) { 221 | throw new Exception\RequestException($response); 222 | } 223 | 224 | if (isset($response['Model']['ReasonCode']) && $response['Model']['ReasonCode'] !== 0) { 225 | throw new Exception\PaymentException($response); 226 | } 227 | 228 | return Model\Transaction::fromArray($response['Model']); 229 | } 230 | 231 | /** 232 | * @param $transactionId 233 | * @param $amount 234 | * @throws Exception\RequestException 235 | */ 236 | public function confirmPayment($transactionId, $amount) 237 | { 238 | $response = $this->sendRequest('/payments/confirm', [ 239 | 'TransactionId' => $transactionId, 240 | 'Amount' => $amount 241 | ]); 242 | 243 | if (!$response['Success']) { 244 | throw new Exception\RequestException($response); 245 | } 246 | } 247 | 248 | /** 249 | * @param $transactionId 250 | * @throws Exception\RequestException 251 | */ 252 | public function voidPayment($transactionId) 253 | { 254 | $response = $this->sendRequest('/payments/void', [ 255 | 'TransactionId' => $transactionId 256 | ]); 257 | 258 | if (!$response['Success']) { 259 | throw new Exception\RequestException($response); 260 | } 261 | } 262 | 263 | /** 264 | * @param $transactionId 265 | * @param $amount 266 | * @throws Exception\RequestException 267 | */ 268 | public function refundPayment($transactionId, $amount) 269 | { 270 | $response = $this->sendRequest('/payments/refund', [ 271 | 'TransactionId' => $transactionId, 272 | 'Amount' => $amount 273 | ]); 274 | 275 | if (!$response['Success']) { 276 | throw new Exception\RequestException($response); 277 | } 278 | } 279 | 280 | /** 281 | * @param $invoiceId 282 | * @return Model\Transaction 283 | * @throws Exception\RequestException 284 | */ 285 | public function findPayment($invoiceId) 286 | { 287 | $response = $this->sendRequest('/payments/find', [ 288 | 'InvoiceId' => $invoiceId 289 | ]); 290 | 291 | if (!$response['Success']) { 292 | throw new Exception\RequestException($response); 293 | } 294 | 295 | return Model\Transaction::fromArray($response['Model']); 296 | } 297 | 298 | /** 299 | * @param $inn 300 | * @param $invoiceId 301 | * @param $accountId 302 | * @param array $items 303 | * @param $taxationSystem 304 | * @param $email 305 | * @param $phone 306 | * @param $income 307 | * @param array $params 308 | * @throws Exception\RequestException 309 | */ 310 | public function sendReceipt($inn, $invoiceId, $accountId, array $items, $taxationSystem, $email, $phone, $income = true, $params = []) 311 | { 312 | $receiptArray = [ 313 | 'Items' => $items, 314 | 'taxationSystem' => $taxationSystem, 315 | 'email' => $email, 316 | 'phone' => $phone 317 | ]; 318 | 319 | $defaultParams = [ 320 | 'Inn' => $inn, 321 | 'InvoiceId' => $invoiceId, 322 | 'AccountId' => $accountId, 323 | 'Type' => $income ? 'Income' : 'IncomeReturn', 324 | 'CustomerReceipt' => $receiptArray 325 | ]; 326 | 327 | $response = $this->sendJSONRequest('/kkt/receipt', array_merge($defaultParams, $params)); 328 | 329 | if (!$response['Success']) { 330 | throw new Exception\RequestException($response); 331 | } 332 | } 333 | 334 | /** 335 | * @return string 336 | */ 337 | public function getUrl() 338 | { 339 | return $this->url; 340 | } 341 | 342 | /** 343 | * @param string $value 344 | * @return $this 345 | */ 346 | public function setUrl($value) 347 | { 348 | $this->url = $value; 349 | 350 | return $this; 351 | } 352 | 353 | /** 354 | * @return string 355 | */ 356 | public function getPublicKey() 357 | { 358 | return $this->publicKey; 359 | } 360 | 361 | /** 362 | * @param string $value 363 | * @return $this 364 | */ 365 | public function setPublicKey($value) 366 | { 367 | $this->publicKey = $value; 368 | 369 | return $this; 370 | } 371 | 372 | /** 373 | * @return string 374 | */ 375 | public function getPrivateKey() 376 | { 377 | return $this->privateKey; 378 | } 379 | 380 | /** 381 | * @param string $value 382 | * @return $this 383 | */ 384 | public function setPrivateKey($value) 385 | { 386 | $this->privateKey = $value; 387 | 388 | return $this; 389 | } 390 | } -------------------------------------------------------------------------------- /src/Model/Required3DS.php: -------------------------------------------------------------------------------- 1 | transactionId; 28 | } 29 | 30 | /** 31 | * @param integer $value 32 | * @return $this 33 | */ 34 | public function setTransactionId($value) 35 | { 36 | $this->transactionId = $value; 37 | 38 | return $this; 39 | } 40 | 41 | /** 42 | * @return string 43 | */ 44 | public function getToken() 45 | { 46 | return $this->token; 47 | } 48 | 49 | /** 50 | * @param string $value 51 | * @return $this 52 | */ 53 | public function setToken($value) 54 | { 55 | $this->token = $value; 56 | 57 | return $this; 58 | } 59 | 60 | /** 61 | * @return string 62 | */ 63 | public function getUrl() 64 | { 65 | return $this->url; 66 | } 67 | 68 | /** 69 | * @param string $value 70 | * @return $this 71 | */ 72 | public function setUrl($value) 73 | { 74 | $this->url = $value; 75 | 76 | return $this; 77 | } 78 | 79 | /** 80 | * @param $params 81 | * @return Required3DS 82 | */ 83 | public static function fromArray($params) 84 | { 85 | $model = new Required3DS(); 86 | $model->setTransactionId($params['TransactionId']); 87 | $model->setToken($params['PaReq']); 88 | $model->setUrl($params['AcsUrl']); 89 | 90 | return $model; 91 | } 92 | } -------------------------------------------------------------------------------- /src/Model/Transaction.php: -------------------------------------------------------------------------------- 1 | id; 193 | } 194 | 195 | /** 196 | * @param integer $value 197 | * @return $this 198 | */ 199 | public function setId($value) 200 | { 201 | $this->id = $value; 202 | 203 | return $this; 204 | } 205 | 206 | /** 207 | * @return float 208 | */ 209 | public function getAmount() 210 | { 211 | return $this->amount; 212 | } 213 | 214 | /** 215 | * @param float $value 216 | * @return $this 217 | */ 218 | public function setAmount($value) 219 | { 220 | $this->amount = $value; 221 | 222 | return $this; 223 | } 224 | 225 | /** 226 | * @return string 227 | */ 228 | public function getCurrency() 229 | { 230 | return $this->currency; 231 | } 232 | 233 | /** 234 | * @param string $value 235 | * @return $this 236 | */ 237 | public function setCurrency($value) 238 | { 239 | $this->currency = $value; 240 | 241 | return $this; 242 | } 243 | 244 | /** 245 | * @return integer 246 | */ 247 | public function getCurrencyCode() 248 | { 249 | return $this->currencyCode; 250 | } 251 | 252 | /** 253 | * @param integer $value 254 | * @return $this 255 | */ 256 | public function setCurrencyCode($value) 257 | { 258 | $this->currencyCode = $value; 259 | 260 | return $this; 261 | } 262 | 263 | /** 264 | * @return string 265 | */ 266 | public function getInvoiceId() 267 | { 268 | return $this->invoiceId; 269 | } 270 | 271 | /** 272 | * @param string $value 273 | * @return $this 274 | */ 275 | public function setInvoiceId($value) 276 | { 277 | $this->invoiceId = $value; 278 | 279 | return $this; 280 | } 281 | 282 | /** 283 | * @return string 284 | */ 285 | public function getAccountId() 286 | { 287 | return $this->accountId; 288 | } 289 | 290 | /** 291 | * @param string $value 292 | * @return $this 293 | */ 294 | public function setAccountId($value) 295 | { 296 | $this->accountId = $value; 297 | 298 | return $this; 299 | } 300 | 301 | /** 302 | * @return string 303 | */ 304 | public function getEmail() 305 | { 306 | return $this->email; 307 | } 308 | 309 | /** 310 | * @param string $value 311 | * @return $this 312 | */ 313 | public function setEmail($value) 314 | { 315 | $this->email = $value; 316 | 317 | return $this; 318 | } 319 | 320 | /** 321 | * @return string 322 | */ 323 | public function getDescription() 324 | { 325 | return $this->description; 326 | } 327 | 328 | /** 329 | * @param string $value 330 | * @return $this 331 | */ 332 | public function setDescription($value) 333 | { 334 | $this->description = $value; 335 | 336 | return $this; 337 | } 338 | 339 | /** 340 | * @return array 341 | */ 342 | public function getData() 343 | { 344 | return $this->data; 345 | } 346 | 347 | /** 348 | * @param array $value 349 | * @return $this 350 | */ 351 | public function setData($value) 352 | { 353 | $this->data = $value; 354 | 355 | return $this; 356 | } 357 | 358 | /** 359 | * @return \DateTime 360 | */ 361 | public function getCreatedAt() 362 | { 363 | return $this->createdAt; 364 | } 365 | 366 | /** 367 | * @param \DateTime $value 368 | * @return $this 369 | */ 370 | public function setCreatedAt($value) 371 | { 372 | $this->createdAt = $value; 373 | 374 | return $this; 375 | } 376 | 377 | /** 378 | * @return \DateTime 379 | */ 380 | public function getAuthorizedAt() 381 | { 382 | return $this->authorizedAt; 383 | } 384 | 385 | /** 386 | * @param \DateTime $value 387 | * @return $this 388 | */ 389 | public function setAuthorizedAt($value) 390 | { 391 | $this->authorizedAt = $value; 392 | 393 | return $this; 394 | } 395 | 396 | /** 397 | * @return \DateTime 398 | */ 399 | public function getConfirmedAt() 400 | { 401 | return $this->confirmedAt; 402 | } 403 | 404 | /** 405 | * @param \DateTime $value 406 | * @return $this 407 | */ 408 | public function setConfirmedAt($value) 409 | { 410 | $this->confirmedAt = $value; 411 | 412 | return $this; 413 | } 414 | 415 | /** 416 | * @return string 417 | */ 418 | public function getAuthCode() 419 | { 420 | return $this->authCode; 421 | } 422 | 423 | /** 424 | * @param string $value 425 | * @return $this 426 | */ 427 | public function setAuthCode($value) 428 | { 429 | $this->authCode = $value; 430 | 431 | return $this; 432 | } 433 | 434 | /** 435 | * @return boolean 436 | */ 437 | public function isTestMode() 438 | { 439 | return $this->testMode; 440 | } 441 | 442 | /** 443 | * @param boolean $value 444 | * @return $this 445 | */ 446 | public function setTestMode($value) 447 | { 448 | $this->testMode = $value; 449 | 450 | return $this; 451 | } 452 | 453 | /** 454 | * @return string 455 | */ 456 | public function getIpAddress() 457 | { 458 | return $this->ipAddress; 459 | } 460 | 461 | /** 462 | * @param string $value 463 | * @return $this 464 | */ 465 | public function setIpAddress($value) 466 | { 467 | $this->ipAddress = $value; 468 | 469 | return $this; 470 | } 471 | 472 | /** 473 | * @return string 474 | */ 475 | public function getIpCountry() 476 | { 477 | return $this->ipCountry; 478 | } 479 | 480 | /** 481 | * @param string $value 482 | * @return $this 483 | */ 484 | public function setIpCountry($value) 485 | { 486 | $this->ipCountry = $value; 487 | 488 | return $this; 489 | } 490 | 491 | /** 492 | * @return string 493 | */ 494 | public function getIpCity() 495 | { 496 | return $this->ipCity; 497 | } 498 | 499 | /** 500 | * @param string $value 501 | * @return $this 502 | */ 503 | public function setIpCity($value) 504 | { 505 | $this->ipCity = $value; 506 | 507 | return $this; 508 | } 509 | 510 | /** 511 | * @return string 512 | */ 513 | public function getIpRegion() 514 | { 515 | return $this->ipRegion; 516 | } 517 | 518 | /** 519 | * @param string $value 520 | * @return $this 521 | */ 522 | public function setIpRegion($value) 523 | { 524 | $this->ipRegion = $value; 525 | 526 | return $this; 527 | } 528 | 529 | /** 530 | * @return string 531 | */ 532 | public function getIpDistrict() 533 | { 534 | return $this->ipDistrict; 535 | } 536 | 537 | /** 538 | * @param string $value 539 | * @return $this 540 | */ 541 | public function setIpDistrict($value) 542 | { 543 | $this->ipDistrict = $value; 544 | 545 | return $this; 546 | } 547 | 548 | /** 549 | * @return float 550 | */ 551 | public function getIpLatitude() 552 | { 553 | return $this->ipLatitude; 554 | } 555 | 556 | /** 557 | * @param float $value 558 | * @return $this 559 | */ 560 | public function setIpLatitude($value) 561 | { 562 | $this->ipLatitude = $value; 563 | 564 | return $this; 565 | } 566 | 567 | /** 568 | * @return float 569 | */ 570 | public function getIpLongitude() 571 | { 572 | return $this->ipLongitude; 573 | } 574 | 575 | /** 576 | * @param float $value 577 | * @return $this 578 | */ 579 | public function setIpLongitude($value) 580 | { 581 | $this->ipLongitude = $value; 582 | 583 | return $this; 584 | } 585 | 586 | /** 587 | * @return string 588 | */ 589 | public function getCardFirstSix() 590 | { 591 | return $this->cardFirstSix; 592 | } 593 | 594 | /** 595 | * @param string $value 596 | * @return $this 597 | */ 598 | public function setCardFirstSix($value) 599 | { 600 | $this->cardFirstSix = $value; 601 | 602 | return $this; 603 | } 604 | 605 | /** 606 | * @return string 607 | */ 608 | public function getCardLastFour() 609 | { 610 | return $this->cardLastFour; 611 | } 612 | 613 | /** 614 | * @param string $value 615 | * @return $this 616 | */ 617 | public function setCardLastFour($value) 618 | { 619 | $this->cardLastFour = $value; 620 | 621 | return $this; 622 | } 623 | 624 | /** 625 | * @return integer 626 | */ 627 | public function getCardExpiredMonth() 628 | { 629 | return $this->cardExpiredMonth; 630 | } 631 | 632 | /** 633 | * @param integer $value 634 | * @return $this 635 | */ 636 | public function setCardExpiredMonth($value) 637 | { 638 | $this->cardExpiredMonth = $value; 639 | 640 | return $this; 641 | } 642 | 643 | /** 644 | * @return integer 645 | */ 646 | public function getCardExpiredYear() 647 | { 648 | return $this->cardExpiredYear; 649 | } 650 | 651 | /** 652 | * @param integer $value 653 | * @return $this 654 | */ 655 | public function setCardExpiredYear($value) 656 | { 657 | $this->cardExpiredYear = $value; 658 | 659 | return $this; 660 | } 661 | 662 | /** 663 | * @return string 664 | */ 665 | public function getCardType() 666 | { 667 | return $this->cardType; 668 | } 669 | 670 | /** 671 | * @param string $value 672 | * @return $this 673 | */ 674 | public function setCardType($value) 675 | { 676 | $this->cardType = $value; 677 | 678 | return $this; 679 | } 680 | 681 | /** 682 | * @return integer 683 | */ 684 | public function getCardTypeCode() 685 | { 686 | return $this->cardTypeCode; 687 | } 688 | 689 | /** 690 | * @param integer $value 691 | * @return $this 692 | */ 693 | public function setCardTypeCode($value) 694 | { 695 | $this->cardTypeCode = $value; 696 | 697 | return $this; 698 | } 699 | 700 | /** 701 | * @return string 702 | */ 703 | public function getIssuer() 704 | { 705 | return $this->issuer; 706 | } 707 | 708 | /** 709 | * @param string $value 710 | * @return $this 711 | */ 712 | public function setIssuer($value) 713 | { 714 | $this->issuer = $value; 715 | 716 | return $this; 717 | } 718 | 719 | /** 720 | * @return string 721 | */ 722 | public function getIssuerBankCountry() 723 | { 724 | return $this->issuerBankCountry; 725 | } 726 | 727 | /** 728 | * @param string $value 729 | * @return $this 730 | */ 731 | public function setIssuerBankCountry($value) 732 | { 733 | $this->issuerBankCountry = $value; 734 | 735 | return $this; 736 | } 737 | 738 | /** 739 | * @return string 740 | */ 741 | public function getStatus() 742 | { 743 | return $this->status; 744 | } 745 | 746 | /** 747 | * @param string $value 748 | * @return $this 749 | */ 750 | public function setStatus($value) 751 | { 752 | $this->status = $value; 753 | 754 | return $this; 755 | } 756 | 757 | /** 758 | * @return integer 759 | */ 760 | public function getStatusCode() 761 | { 762 | return $this->statusCode; 763 | } 764 | 765 | /** 766 | * @param integer $value 767 | * @return $this 768 | */ 769 | public function setStatusCode($value) 770 | { 771 | $this->statusCode = $value; 772 | 773 | return $this; 774 | } 775 | 776 | /** 777 | * @return string 778 | */ 779 | public function getReason() 780 | { 781 | return $this->reason; 782 | } 783 | 784 | /** 785 | * @param string $value 786 | * @return $this 787 | */ 788 | public function setReason($value) 789 | { 790 | $this->reason = $value; 791 | 792 | return $this; 793 | } 794 | 795 | /** 796 | * @return integer 797 | */ 798 | public function getReasonCode() 799 | { 800 | return $this->reasonCode; 801 | } 802 | 803 | /** 804 | * @param integer $value 805 | * @return $this 806 | */ 807 | public function setReasonCode($value) 808 | { 809 | $this->reasonCode = $value; 810 | 811 | return $this; 812 | } 813 | 814 | /** 815 | * @return string 816 | */ 817 | public function getCardHolderMessage() 818 | { 819 | return $this->cardHolderMessage; 820 | } 821 | 822 | /** 823 | * @param string $value 824 | * @return $this 825 | */ 826 | public function setCardHolderMessage($value) 827 | { 828 | $this->cardHolderMessage = $value; 829 | 830 | return $this; 831 | } 832 | 833 | /** 834 | * @return string 835 | */ 836 | public function getCardHolderName() 837 | { 838 | return $this->cardHolderName; 839 | } 840 | 841 | /** 842 | * @param string $value 843 | * @return $this 844 | */ 845 | public function setCardHolderName($value) 846 | { 847 | $this->cardHolderName = $value; 848 | 849 | return $this; 850 | } 851 | 852 | /** 853 | * @return string 854 | */ 855 | public function getToken() 856 | { 857 | return $this->token; 858 | } 859 | 860 | /** 861 | * @param string $value 862 | * @return $this 863 | */ 864 | public function setToken($value) 865 | { 866 | $this->token = $value; 867 | 868 | return $this; 869 | } 870 | 871 | /** 872 | * @param $params 873 | * @return Transaction 874 | */ 875 | public static function fromArray($params) 876 | { 877 | $transaction = new Transaction(); 878 | 879 | $transaction->setId($params['TransactionId']); 880 | $transaction->setAmount($params['Amount']); 881 | $transaction->setCurrency($params['Currency']); 882 | $transaction->setCurrencyCode($params['CurrencyCode']); 883 | $transaction->setCardFirstSix($params['CardFirstSix']); 884 | $transaction->setCardLastFour($params['CardLastFour']); 885 | $transaction->setCardExpiredMonth(explode('/', $params['CardExpDate'])[0]); 886 | $transaction->setCardExpiredYear(substr(date('Y'), 0, 2) . explode('/', $params['CardExpDate'])[1]); 887 | 888 | if (isset($params['InvoiceId'])) { 889 | $transaction->setInvoiceId($params['InvoiceId']); 890 | } 891 | 892 | if (isset($params['AccountId'])) { 893 | $transaction->setAccountId($params['AccountId']); 894 | } 895 | 896 | if (isset($params['Email'])) { 897 | $transaction->setEmail($params['Email']); 898 | } 899 | 900 | if (isset($params['Description'])) { 901 | $transaction->setDescription($params['Description']); 902 | } 903 | 904 | if (isset($params['JsonData'])) { 905 | $transaction->setData((array)$params['JsonData']); 906 | } 907 | 908 | if (isset($params['CreatedDateIso'])) { 909 | $transaction->setCreatedAt(new \DateTime($params['CreatedDateIso'])); 910 | } 911 | 912 | if (isset($params['AuthDateIso'])) { 913 | $transaction->setAuthorizedAt(new \DateTime($params['AuthDateIso'])); 914 | } 915 | 916 | if (isset($params['ConfirmDateIso'])) { 917 | $transaction->setConfirmedAt(new \DateTime($params['ConfirmDateIso'])); 918 | } 919 | 920 | if (isset($params['AuthCode'])) { 921 | $transaction->setAuthCode($params['AuthCode']); 922 | } 923 | 924 | if (isset($params['TestMode'])) { 925 | $transaction->setTestMode($params['TestMode']); 926 | } 927 | 928 | if (isset($params['IpAddress'])) { 929 | $transaction->setIpAddress($params['IpAddress']); 930 | } 931 | 932 | if (isset($params['IpCountry'])) { 933 | $transaction->setIpCountry($params['IpCountry']); 934 | } 935 | 936 | if (isset($params['IpCity'])) { 937 | $transaction->setIpCity($params['IpCity']); 938 | } 939 | 940 | if (isset($params['IpRegion'])) { 941 | $transaction->setIpRegion($params['IpRegion']); 942 | } 943 | 944 | if (isset($params['IpDistrict'])) { 945 | $transaction->setIpDistrict($params['IpDistrict']); 946 | } 947 | 948 | if (isset($params['IpLatitude'])) { 949 | $transaction->setIpLatitude($params['IpLatitude']); 950 | } 951 | 952 | if (isset($params['IpLongitude'])) { 953 | $transaction->setIpLongitude($params['IpLongitude']); 954 | } 955 | 956 | if (isset($params['CardType'])) { 957 | $transaction->setCardType(strtolower($params['CardType'])); 958 | } 959 | 960 | if (isset($params['CardTypeCode'])) { 961 | $transaction->setCardTypeCode($params['CardTypeCode']); 962 | } 963 | 964 | if (isset($params['Issuer'])) { 965 | $transaction->setIssuer($params['Issuer']); 966 | } 967 | 968 | if (isset($params['IssuerBankCountry'])) { 969 | $transaction->setIssuerBankCountry($params['IssuerBankCountry']); 970 | } 971 | 972 | if (isset($params['Status'])) { 973 | $transaction->setStatus(strtolower($params['Status'])); 974 | } 975 | 976 | if (isset($params['StatusCode'])) { 977 | $transaction->setStatusCode($params['StatusCode']); 978 | } 979 | 980 | if (isset($params['Reason'])) { 981 | $transaction->setReason($params['Reason']); 982 | } 983 | 984 | if (isset($params['ReasonCode'])) { 985 | $transaction->setReasonCode($params['ReasonCode']); 986 | } 987 | 988 | if (isset($params['CardHolderMessage'])) { 989 | $transaction->setCardHolderMessage($params['CardHolderMessage']); 990 | } 991 | 992 | if (isset($params['Name'])) { 993 | $transaction->setCardHolderName($params['Name']); 994 | } 995 | 996 | if (isset($params['Token'])) { 997 | $transaction->setToken($params['Token']); 998 | } 999 | 1000 | return $transaction; 1001 | } 1002 | } 1003 | --------------------------------------------------------------------------------