From 86e9321d254228176af759ae719c218fdc8601bc Mon Sep 17 00:00:00 2001 From: Nicollas Braga Date: Wed, 18 Jan 2017 16:02:26 -0200 Subject: [PATCH 01/34] Update Payment populate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Os dados vindos do Webservice não estavam sendo completamente populados na classe Payment --- src/Cielo/API30/Ecommerce/Payment.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Cielo/API30/Ecommerce/Payment.php b/src/Cielo/API30/Ecommerce/Payment.php index a4be185..b46f136 100644 --- a/src/Cielo/API30/Ecommerce/Payment.php +++ b/src/Cielo/API30/Ecommerce/Payment.php @@ -82,6 +82,8 @@ class Payment implements \JsonSerializable private $number; + private $boletoNumber; + private $barCodeNumber; private $digitableLine; @@ -123,6 +125,13 @@ public function populate(\stdClass $data) $this->debitCard = new CreditCard(); $this->debitCard->populate($data->DebitCard); } + + $this->expirationDate = isset($data->ExpirationDate)?$data->ExpirationDate: null; + $this->url = isset($data->Url)?$data->ExpirationDate: null; + $this->boletoNumber = isset($data->BoletoNumber)? $data->BoletoNumber: null; + $this->barCodeNumber = isset($data->BarCodeNumber)?$data->BarCodeNumber: null; + $this->digitableLine = isset($data->DigitableLine)?$data->DigitableLine: null; + $this->address = isset($data->Address)?$data->Address: null; $this->authenticationUrl = isset($data->AuthenticationUrl)? $data->AuthenticationUrl: null; $this->tid = isset($data->Tid)? $data->Tid: null; @@ -545,6 +554,17 @@ public function setNumber($number) { $this->number = $number; return $this; + } + + public function getBoletoNumber() + { + return $this->boletoNumber; + } + + public function setBoletoNumber($boletoNumber) + { + $this->boletoNumber = $boletoNumber; + return $this; } public function getBarCodeNumber() From 881328e89b46e2603961d93d35d4277ee5b35f2a Mon Sep 17 00:00:00 2001 From: Nicollas Braga Date: Thu, 19 Jan 2017 09:15:57 -0200 Subject: [PATCH 02/34] Update Payment.php --- src/Cielo/API30/Ecommerce/Payment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cielo/API30/Ecommerce/Payment.php b/src/Cielo/API30/Ecommerce/Payment.php index b46f136..6efc389 100644 --- a/src/Cielo/API30/Ecommerce/Payment.php +++ b/src/Cielo/API30/Ecommerce/Payment.php @@ -127,7 +127,7 @@ public function populate(\stdClass $data) } $this->expirationDate = isset($data->ExpirationDate)?$data->ExpirationDate: null; - $this->url = isset($data->Url)?$data->ExpirationDate: null; + $this->url = isset($data->Url)?$data->Url: null; $this->boletoNumber = isset($data->BoletoNumber)? $data->BoletoNumber: null; $this->barCodeNumber = isset($data->BarCodeNumber)?$data->BarCodeNumber: null; $this->digitableLine = isset($data->DigitableLine)?$data->DigitableLine: null; From f9420d8cbc431268788b1cb764821aa997993c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Batista=20Neto?= Date: Mon, 23 Jan 2017 12:26:30 -0200 Subject: [PATCH 03/34] Adiciona propriedades ausentes --- .../API30/Ecommerce/RecurrentPayment.php | 117 ++++++++++++++++-- 1 file changed, 110 insertions(+), 7 deletions(-) diff --git a/src/Cielo/API30/Ecommerce/RecurrentPayment.php b/src/Cielo/API30/Ecommerce/RecurrentPayment.php index 61255d6..2236502 100644 --- a/src/Cielo/API30/Ecommerce/RecurrentPayment.php +++ b/src/Cielo/API30/Ecommerce/RecurrentPayment.php @@ -15,14 +15,26 @@ class RecurrentPayment implements \JsonSerializable const INTERVAL_ANNUAL = 'Annual'; private $authorizeNow; - + private $recurrentPaymentId; + private $nextRecurrency; private $startDate; - private $endDate; - private $interval; - - public function __construct($authorizeNow) + private $amount; + private $country; + private $createDate; + private $currency; + private $currentRecurrencyTry; + private $provider; + private $recurrencyDay; + private $successfulRecurrences; + private $links; + private $recurrentTransactions; + private $reasonCode; + private $reasonMessage; + private $status; + + public function __construct($authorizeNow = true) { $this->setAuthorizeNow($authorizeNow); } @@ -35,9 +47,100 @@ public function jsonSerialize() public function populate(\stdClass $data) { $this->authorizeNow = isset($data->AuthorizeNow)? !!$data->AuthorizeNow: false; + $this->recurrentPaymentId = isset($data->RecurrentPaymentId)? $data->RecurrentPaymentId: null; + $this->nextRecurrency = isset($data->NextRecurrency)? $data->NextRecurrency: null; $this->startDate = isset($data->StartDate)? $data->StartDate: null; $this->endDate = isset($data->EndDate)? $data->EndDate: null; - $this->interval = isset($data->Interval)? !!$data->Interval: null; + $this->interval = isset($data->Interval)? $data->Interval: null; + + $this->amount = isset($data->Amount)? $data->Amount: null; + $this->country = isset($data->Country)? $data->Country: null; + $this->createDate = isset($data->CreateDate)? $data->CreateDate: null; + $this->currency = isset($data->Currency)? $data->Currency: null; + $this->currentRecurrencyTry = isset($data->CurrentRecurrencyTry)? $data->CurrentRecurrencyTry: null; + $this->provider = isset($data->Provider)? $data->Provider: null; + $this->recurrencyDay = isset($data->RecurrencyDay)? $data->RecurrencyDay: null; + $this->successfulRecurrences = isset($data->SuccessfulRecurrences)? $data->SuccessfulRecurrences: null; + + $this->links = isset($data->Interval)? $data->Interval: []; + $this->recurrentTransactions = isset($data->Interval)? $data->Interval: []; + + $this->reasonCode = isset($data->ReasonCode)? $data->ReasonCode: null; + $this->reasonMessage = isset($data->ReasonMessage)? $data->ReasonMessage: null; + $this->status = isset($data->Status)? $data->Status: null; + } + + public static function fromJson($json) + { + $object = json_decode($json); + + $recurrentPayment = new RecurrentPayment(); + + if (isset($object->RecurrentPayment)) { + $recurrentPayment->populate($object->RecurrentPayment); + } + + return $recurrentPayment; + } + + public function getRecurrentPaymentId() + { + return $this->recurrentPaymentId; + } + + public function getReasonCode() + { + return $this->reasonCode; + } + + public function getReasonMessage() + { + return $this->reasonMessage; + } + + public function gerNextRecurrency() + { + return $this->nextRecurrency; + } + + public function getAmount() + { + return $this->amount; + } + + public function getCountry() + { + return $this->country; + } + + public function getCreateDate() + { + return $this->createDate; + } + + public function getCurrency() + { + return $this->currency; + } + + public function getCurrentRecurrencyTry() + { + return $this->currentRecurrencyTry; + } + + public function getProvider() + { + return $this->provider; + } + + public function getRecurrencyDay() + { + return $this->recurrencyDay; + } + + public function getSuccessfulRecurrences() + { + return $this->successfulRecurrences; } public function getAuthorizeNow() @@ -83,4 +186,4 @@ public function setInterval($interval) $this->interval = $interval; return $this; } -} \ No newline at end of file +} From dcec00867d9b0e5850017d13a7ecff5c6b77c757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Batista=20Neto?= Date: Mon, 23 Jan 2017 12:28:09 -0200 Subject: [PATCH 04/34] =?UTF-8?q?FIX=20#19=20-=20Adiciona=20suporte=20para?= =?UTF-8?q?=20consulta=20de=20recorr=C3=AAncia?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Cielo/API30/Ecommerce/CieloEcommerce.php | 37 ++++++++++++++----- .../Request/QueryRecurrentPaymentRequest.php | 32 ++++++++++++++++ 2 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 src/Cielo/API30/Ecommerce/Request/QueryRecurrentPaymentRequest.php diff --git a/src/Cielo/API30/Ecommerce/CieloEcommerce.php b/src/Cielo/API30/Ecommerce/CieloEcommerce.php index 733ad8f..0bf0d3b 100644 --- a/src/Cielo/API30/Ecommerce/CieloEcommerce.php +++ b/src/Cielo/API30/Ecommerce/CieloEcommerce.php @@ -5,6 +5,7 @@ use Cielo\API30\Ecommerce\Request\CreateSaleRequest; use Cielo\API30\Ecommerce\Request\QuerySaleRequest; use Cielo\API30\Ecommerce\Request\UpdateSaleRequest; +use Cielo\API30\Ecommerce\Request\QueryRecurrentPaymentRequest; /** * The Cielo Ecommerce SDK front-end; @@ -33,7 +34,7 @@ public function __construct(Merchant $merchant, Environment $environment = null) if ($environment == null) { $environment = Environment::production(); } - + $this->merchant = $merchant; $this->environment = $environment; } @@ -53,7 +54,7 @@ public function __construct(Merchant $merchant, Environment $environment = null) public function createSale(Sale $sale) { $createSaleRequest = new CreateSaleRequest($this->merchant, $this->environment); - + return $createSaleRequest->execute($sale); } @@ -71,10 +72,28 @@ public function createSale(Sale $sale) public function getSale($paymentId) { $querySaleRequest = new QuerySaleRequest($this->merchant, $this->environment); - + return $querySaleRequest->execute($paymentId); } + /** + * Query a RecurrentPayment on Cielo by RecurrentPaymentId + * + * @param string $recurrentPaymentId + * The RecurrentPaymentId to be queried + * @return \Cielo\API30\Ecommerce\RecurrentPayment The RecurrentPayment with authorization, tid, etc. returned by Cielo. + * @throws CieloRequestException if anything gets wrong. + * @see Error + * Codes + */ + public function getRecurrentPayment($recurrentPaymentId) + { + $queryRecurrentPaymentRequest = new queryRecurrentPaymentRequest($this->merchant, $this->environment); + + return $queryRecurrentPaymentRequest->execute($recurrentPaymentId); + } + /** * Cancel a Sale on Cielo by paymentId and speficying the amount * @@ -91,9 +110,9 @@ public function getSale($paymentId) public function cancelSale($paymentId, $amount = null) { $updateSaleRequest = new UpdateSaleRequest('void', $this->merchant, $this->environment); - + $updateSaleRequest->setAmount($amount); - + return $updateSaleRequest->execute($paymentId); } @@ -109,7 +128,7 @@ public function cancelSale($paymentId, $amount = null) * Amount of the authorization should be destined for the service * charge * @return \Cielo\API30\Ecommerce\Payment The captured Payment. - * + * * @throws CieloRequestException if anything gets wrong. * @see Error @@ -118,10 +137,10 @@ public function cancelSale($paymentId, $amount = null) public function captureSale($paymentId, $amount = null, $serviceTaxAmount = null) { $updateSaleRequest = new UpdateSaleRequest('capture', $this->merchant, $this->environment); - + $updateSaleRequest->setAmount($amount); $updateSaleRequest->setServiceTaxAmount($serviceTaxAmount); - + return $updateSaleRequest->execute($paymentId); } -} \ No newline at end of file +} diff --git a/src/Cielo/API30/Ecommerce/Request/QueryRecurrentPaymentRequest.php b/src/Cielo/API30/Ecommerce/Request/QueryRecurrentPaymentRequest.php new file mode 100644 index 0000000..ce7449e --- /dev/null +++ b/src/Cielo/API30/Ecommerce/Request/QueryRecurrentPaymentRequest.php @@ -0,0 +1,32 @@ +environment = $environment; + } + + public function execute($recurrentPaymentId) + { + $url = $this->environment->getApiQueryURL() . '1/RecurrentPayment/' . $recurrentPaymentId; + + return $this->sendRequest('GET', $url); + } + + protected function unserialize($json) + { + return RecurrentPayment::fromJson($json); + } +} From 8b9af622ff11d8476f2f7ecedea486bd838f3e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Batista=20Neto?= Date: Tue, 18 Apr 2017 12:21:15 -0300 Subject: [PATCH 05/34] =?UTF-8?q?Instru=C3=A7=C3=B5es=20de=20instala=C3=A7?= =?UTF-8?q?=C3=A3o=20e=20requisitos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index b6f20a5..5561cab 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,32 @@ SDK API-3.0 PHP Por envolver a interface de usuário da aplicação, o SDK funciona apenas como um framework para criação das transações. Nos casos onde a autorização é direta, não há limitação; mas nos casos onde é necessário a autenticação ou qualquer tipo de redirecionamento do usuário, o desenvolvedor deverá utilizar o SDK para gerar o pagamento e, com o link retornado pela Cielo, providenciar o redirecionamento do usuário. +## Dependências + +* PHP >= 5.6 + +## Instalando o SDK + +Se já possui um arquivo `composer.json`, basta adicionar a seguinte dependência ao seu projeto: + +```json +"require": { + "developercielo/api-3.0-php": "^1.0" +} +``` + +Com a dependência adicionada ao `composer.json`, basta executar: + +``` +composer install +``` + +Alternativamente, você pode executar diretamente em seu terminal: + +``` +composer require "developercielo/api-3.0-php" +``` + ## Utilizando o SDK Para criar um pagamento simples com cartão de crédito com o SDK, basta fazer: From 8eadd62a6bb6060761860e3dd2a0d21090658847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Batista=20Neto?= Date: Tue, 16 May 2017 13:28:50 -0300 Subject: [PATCH 06/34] Fix #42: adiciona exemplo de pagamento recorrente --- README.md | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/README.md b/README.md index 5561cab..33dae18 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,71 @@ try { // ... ``` +### Criando um pagamento recorrente + +```php +customer('Fulano de Tal'); + +// Configure a recorrência +$recurrent = $recurrent->setInterval(RecurrentPayment::INTERVAL_MONTHLY) + ->setAuthorizeNow(true); + +// Crie uma instância de Payment informando o valor do pagamento +$payment = $sale->payment(15700); + +// Crie uma instância de Credit Card utilizando os dados de teste +// esses dados estão disponíveis no manual de integração +$payment->setRecurrentPayment($recurrent) + ->setType(Payment::PAYMENTTYPE_CREDITCARD) + ->creditCard("123", "Visa") + ->setExpirationDate("12/2018") + ->setCardNumber("0000000000000001") + ->setHolder("Fulano de Tal"); + +// Crie o pagamento na Cielo +try { + // Configure o SDK com seu merchant e o ambiente apropriado para criar a venda + $sale = (new CieloEcommerce($merchant, $environment))->createSale($sale); + + // Com a venda criada na Cielo, já temos o ID do pagamento, TID e demais + // dados retornados pela Cielo + $paymentId = $sale->getPayment()->getPaymentId(); + + // Com o ID do pagamento, podemos fazer sua captura, se ela não tiver sido capturada ainda + $sale = (new CieloEcommerce($merchant, $environment))->captureSale($paymentId, 15700, 0); + + // E também podemos fazer seu cancelamento, se for o caso + $sale = (new CieloEcommerce($merchant, $environment))->cancelSale($paymentId, 15700); +} catch (CieloRequestException $e) { + // Em caso de erros de integração, podemos tratar o erro aqui. + // os códigos de erro estão todos disponíveis no manual de integração. + $error = $e->getCieloError(); +} +// ... +``` + ### Criando transações com cartão de débito ```php From 93ab2dbb85ba9c8458304c1113deaf833d981447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Batista=20Neto?= Date: Mon, 22 May 2017 12:13:46 -0300 Subject: [PATCH 07/34] FIX 38: Adiciona suporte e exemplo para Boleto --- README.md | 66 +++++++++++++++++++++++++ src/Cielo/API30/Ecommerce/Address.php | 16 ++++++- src/Cielo/API30/Ecommerce/Payment.php | 69 +++++++++++++++++++++++++-- 3 files changed, 146 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 33dae18..d472eae 100644 --- a/README.md +++ b/README.md @@ -235,6 +235,72 @@ try { // ... ``` +### Criando uma venda com Boleto + +```php +customer('Fulano de Tal') + ->setIdentity('00000000001') + ->setIdentityType('CPF') + ->address()->setZipCode('22750012') + ->setCountry('BRA') + ->setState('RJ') + ->setCity('Rio de Janeiro') + ->setDistrict('Centro') + ->setStreet('Av Marechal Camara') + ->setNumber('123'); + +// Crie uma instância de Payment informando o valor do pagamento +$payment = $sale->payment(15700) + ->setType(Payment::PAYMENTTYPE_BOLETO) + ->setAddress('Rua de Teste') + ->setBoletoNumber('1234') + ->setAssignor('Empresa de Teste') + ->setDemonstrative('Desmonstrative Teste') + ->setExpirationDate(date('d/m/Y', strtotime('+1 month'))) + ->setIdentification('11884926754') + ->setInstructions('Esse é um boleto de exemplo'); + +// Crie o pagamento na Cielo +try { + // Configure o SDK com seu merchant e o ambiente apropriado para criar a venda + $sale = (new CieloEcommerce($merchant, $environment))->createSale($sale); + + // Com a venda criada na Cielo, já temos o ID do pagamento, TID e demais + // dados retornados pela Cielo + $paymentId = $sale->getPayment()->getPaymentId(); + $boletoURL = $sale->getPayment()->getUrl(); + + printf("URL Boleto: %s\n", $boletoURL); +} catch (CieloRequestException $e) { + // Em caso de erros de integração, podemos tratar o erro aqui. + // os códigos de erro estão todos disponíveis no manual de integração. + $error = $e->getCieloError(); +} +``` + ## Manual Para mais informações sobre a integração com a API 3.0 da Cielo, vide o manual em: [Integração API 3.0](https://developercielo.github.io/Webservice-3.0/) diff --git a/src/Cielo/API30/Ecommerce/Address.php b/src/Cielo/API30/Ecommerce/Address.php index 1cc0bb4..4fe655b 100644 --- a/src/Cielo/API30/Ecommerce/Address.php +++ b/src/Cielo/API30/Ecommerce/Address.php @@ -18,6 +18,8 @@ class Address implements CieloSerializable private $country; + private $district; + public function jsonSerialize() { return get_object_vars($this); @@ -32,6 +34,18 @@ public function populate(\stdClass $data) $this->city = isset($data->City)? $data->City: null; $this->state = isset($data->State)? $data->State: null; $this->country = isset($data->Country)? $data->Country: null; + $this->district = isset($data->District)? $data->District: null; + } + + public function getDistrict() + { + return $this->district; + } + + public function setDistrict($district) + { + $this->district = $district; + return $this; } public function getStreet() @@ -110,4 +124,4 @@ public function setCountry($country) $this->country = $country; return $this; } -} \ No newline at end of file +} diff --git a/src/Cielo/API30/Ecommerce/Payment.php b/src/Cielo/API30/Ecommerce/Payment.php index 6efc389..b4b4655 100644 --- a/src/Cielo/API30/Ecommerce/Payment.php +++ b/src/Cielo/API30/Ecommerce/Payment.php @@ -90,6 +90,14 @@ class Payment implements \JsonSerializable private $address; + private $assignor; + + private $demonstrative; + + private $identification; + + private $instructions; + public function __construct($amount = 0, $installments = 1) { $this->setAmount($amount); @@ -125,7 +133,7 @@ public function populate(\stdClass $data) $this->debitCard = new CreditCard(); $this->debitCard->populate($data->DebitCard); } - + $this->expirationDate = isset($data->ExpirationDate)?$data->ExpirationDate: null; $this->url = isset($data->Url)?$data->Url: null; $this->boletoNumber = isset($data->BoletoNumber)? $data->BoletoNumber: null; @@ -150,6 +158,11 @@ public function populate(\stdClass $data) $this->status = isset($data->Status)? $data->Status: null; $this->links = isset($data->Links)? $data->Links: []; + + $this->assignor = isset($data->Assignor)? $data->Assignor: null; + $this->demonstrative = isset($data->Demonstrative)? $data->Demonstrative: null; + $this->identification = isset($data->Identification)? $data->Identification: null; + $this->instructions = isset($data->Instructions)? $data->Instructions: null; } public static function fromJson($json) @@ -554,13 +567,13 @@ public function setNumber($number) { $this->number = $number; return $this; - } - + } + public function getBoletoNumber() { return $this->boletoNumber; } - + public function setBoletoNumber($boletoNumber) { $this->boletoNumber = $boletoNumber; @@ -599,4 +612,52 @@ public function setAddress($address) $this->address = $address; return $this; } + + public function getAssignor() + { + return $this->assignor; + } + + public function setAssignor($assignor) + { + $this->assignor = $assignor; + + return $this; + } + + public function getDemonstrative() + { + return $this->demonstrative; + } + + public function setDemonstrative($demonstrative) + { + $this->demonstrative = $demonstrative; + + return $this; + } + + public function getIdentification() + { + return $this->identification; + } + + public function setIdentification($identification) + { + $this->identification = $identification; + + return $this; + } + + public function getInstructions() + { + return $this->instructions; + } + + public function setInstructions($instructions) + { + $this->instructions = $instructions; + + return $this; + } } From bff3b1a5130aa2b47002392e26d3b4568d75a589 Mon Sep 17 00:00:00 2001 From: Renato Montagna Junior Date: Tue, 11 Jul 2017 18:01:13 -0300 Subject: [PATCH 08/34] Adiciona retornos Capured e Voided no Payment --- src/Cielo/API30/Ecommerce/Payment.php | 32 ++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/Cielo/API30/Ecommerce/Payment.php b/src/Cielo/API30/Ecommerce/Payment.php index b4b4655..b6a7b62 100644 --- a/src/Cielo/API30/Ecommerce/Payment.php +++ b/src/Cielo/API30/Ecommerce/Payment.php @@ -62,6 +62,10 @@ class Payment implements \JsonSerializable private $capturedDate; + private $voidedAmount; + + private $voidedDate; + private $currency; private $country; @@ -95,7 +99,7 @@ class Payment implements \JsonSerializable private $demonstrative; private $identification; - + private $instructions; public function __construct($amount = 0, $installments = 1) @@ -151,6 +155,10 @@ public function populate(\stdClass $data) $this->type = isset($data->Type)? $data->Type: null; $this->amount = isset($data->Amount)? $data->Amount: null; $this->receivedDate = isset($data->ReceivedDate)? $data->ReceivedDate: null; + $this->capturedAmount = isset($data->CapturedAmount)? $data->CapturedAmount: null; + $this->capturedDate = isset($data->CapturedDate)? $data->CapturedDate: null; + $this->voidedAmount = isset($data->VoidedAmount)? $data->VoidedAmount: null; + $this->voidedDate = isset($data->VoidedDate)? $data->VoidedDate: null; $this->currency = isset($data->Currency)? $data->Currency: null; $this->country = isset($data->Country)? $data->Country: null; $this->returnCode = isset($data->ReturnCode)? $data->ReturnCode: null; @@ -459,6 +467,28 @@ public function setCapturedDate($capturedDate) return $this; } + public function getVoidedAmount() + { + return $this->voidedAmount; + } + + public function setVoidedAmount($voidedAmount) + { + $this->voidedAmount = $voidedAmount; + return $this; + } + + public function getVoidedDate() + { + return $this->voidedDate; + } + + public function setVoidedDate($voidedDate) + { + $this->voidedDate = $voidedDate; + return $this; + } + public function getCurrency() { return $this->currency; From 7ab14c67f9c429863f71d5abbc8e045d572253c4 Mon Sep 17 00:00:00 2001 From: Murillo Vasconcelos Date: Wed, 16 Aug 2017 17:03:59 -0300 Subject: [PATCH 09/34] =?UTF-8?q?Corrige=20erro=20de=20digita=C3=A7=C3=A3o?= =?UTF-8?q?=20no=20metodo=20getNextRecurrency=20da=20classe=20RecurrentPay?= =?UTF-8?q?ment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Cielo/API30/Ecommerce/RecurrentPayment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cielo/API30/Ecommerce/RecurrentPayment.php b/src/Cielo/API30/Ecommerce/RecurrentPayment.php index 2236502..77e2c0e 100644 --- a/src/Cielo/API30/Ecommerce/RecurrentPayment.php +++ b/src/Cielo/API30/Ecommerce/RecurrentPayment.php @@ -98,7 +98,7 @@ public function getReasonMessage() return $this->reasonMessage; } - public function gerNextRecurrency() + public function getNextRecurrency() { return $this->nextRecurrency; } From 4cfaa727b94ee8fde449921a47fcd9423e780b5b Mon Sep 17 00:00:00 2001 From: Murillo Vasconcelos Date: Wed, 16 Aug 2017 17:08:02 -0300 Subject: [PATCH 10/34] Corrige atributos Links e RecurrentPayments no metodo populate da classe RecurrentPayment --- src/Cielo/API30/Ecommerce/RecurrentPayment.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Cielo/API30/Ecommerce/RecurrentPayment.php b/src/Cielo/API30/Ecommerce/RecurrentPayment.php index 77e2c0e..49501b3 100644 --- a/src/Cielo/API30/Ecommerce/RecurrentPayment.php +++ b/src/Cielo/API30/Ecommerce/RecurrentPayment.php @@ -62,8 +62,8 @@ public function populate(\stdClass $data) $this->recurrencyDay = isset($data->RecurrencyDay)? $data->RecurrencyDay: null; $this->successfulRecurrences = isset($data->SuccessfulRecurrences)? $data->SuccessfulRecurrences: null; - $this->links = isset($data->Interval)? $data->Interval: []; - $this->recurrentTransactions = isset($data->Interval)? $data->Interval: []; + $this->links = isset($data->Links)? $data->Links: []; + $this->recurrentTransactions = isset($data->RecurrentTransactions)? $data->RecurrentTransactions: []; $this->reasonCode = isset($data->ReasonCode)? $data->ReasonCode: null; $this->reasonMessage = isset($data->ReasonMessage)? $data->ReasonMessage: null; From cfb4c54087d72846666ef5c8a5db85de98dde4d7 Mon Sep 17 00:00:00 2001 From: Murillo Vasconcelos Date: Wed, 16 Aug 2017 17:46:34 -0300 Subject: [PATCH 11/34] Adiciona metodo getStatus na classe RecurrentPayment --- src/Cielo/API30/Ecommerce/RecurrentPayment.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Cielo/API30/Ecommerce/RecurrentPayment.php b/src/Cielo/API30/Ecommerce/RecurrentPayment.php index 49501b3..2e5cb78 100644 --- a/src/Cielo/API30/Ecommerce/RecurrentPayment.php +++ b/src/Cielo/API30/Ecommerce/RecurrentPayment.php @@ -143,6 +143,11 @@ public function getSuccessfulRecurrences() return $this->successfulRecurrences; } + public function getStatus() + { + return $this->status; + } + public function getAuthorizeNow() { return $this->authorizeNow; From 9b9de814ac9b2f42fba722fe9e475b28d5a110b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Batista=20Neto?= Date: Wed, 23 Aug 2017 14:39:33 -0300 Subject: [PATCH 12/34] Ajuste no exemplo de pagamento recorrente. --- README.md | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index d472eae..91aaaf4 100644 --- a/README.md +++ b/README.md @@ -123,11 +123,12 @@ use Cielo\API30\Ecommerce\Payment; use Cielo\API30\Ecommerce\Request\CieloRequestException; // ... +// ... // Configure o ambiente $environment = $environment = Environment::sandbox(); // Configure seu merchant -$merchant = new Merchant('MERCHANT ID', 'MERCHANT KEY'); +$merchant = new Merchant('MID', 'MKEY'); // Crie uma instância de Sale informando o ID do pagamento $sale = new Sale('123'); @@ -135,36 +136,26 @@ $sale = new Sale('123'); // Crie uma instância de Customer informando o nome do cliente $customer = $sale->customer('Fulano de Tal'); -// Configure a recorrência -$recurrent = $recurrent->setInterval(RecurrentPayment::INTERVAL_MONTHLY) - ->setAuthorizeNow(true); - // Crie uma instância de Payment informando o valor do pagamento $payment = $sale->payment(15700); // Crie uma instância de Credit Card utilizando os dados de teste // esses dados estão disponíveis no manual de integração -$payment->setRecurrentPayment($recurrent) - ->setType(Payment::PAYMENTTYPE_CREDITCARD) +$payment->setType(Payment::PAYMENTTYPE_CREDITCARD) ->creditCard("123", "Visa") ->setExpirationDate("12/2018") ->setCardNumber("0000000000000001") ->setHolder("Fulano de Tal"); +// Configure o pagamento recorrente +$payment->recurrentPayment(true)->setInterval(RecurrentPayment::INTERVAL_MONTHLY); + // Crie o pagamento na Cielo try { // Configure o SDK com seu merchant e o ambiente apropriado para criar a venda $sale = (new CieloEcommerce($merchant, $environment))->createSale($sale); - // Com a venda criada na Cielo, já temos o ID do pagamento, TID e demais - // dados retornados pela Cielo - $paymentId = $sale->getPayment()->getPaymentId(); - - // Com o ID do pagamento, podemos fazer sua captura, se ela não tiver sido capturada ainda - $sale = (new CieloEcommerce($merchant, $environment))->captureSale($paymentId, 15700, 0); - - // E também podemos fazer seu cancelamento, se for o caso - $sale = (new CieloEcommerce($merchant, $environment))->cancelSale($paymentId, 15700); + $recurrentPaymentId = $sale->getPayment()->getRecurrentPayment()->getRecurrentPaymentId; } catch (CieloRequestException $e) { // Em caso de erros de integração, podemos tratar o erro aqui. // os códigos de erro estão todos disponíveis no manual de integração. From c2d4012cfeed6a26a2230dce2ab8933d15aae75c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Batista=20Neto?= Date: Wed, 23 Aug 2017 14:44:28 -0300 Subject: [PATCH 13/34] =?UTF-8?q?Ajuste=20na=20chamada=20do=20m=C3=A9todo.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 91aaaf4..31c1962 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,7 @@ try { // Configure o SDK com seu merchant e o ambiente apropriado para criar a venda $sale = (new CieloEcommerce($merchant, $environment))->createSale($sale); - $recurrentPaymentId = $sale->getPayment()->getRecurrentPayment()->getRecurrentPaymentId; + $recurrentPaymentId = $sale->getPayment()->getRecurrentPayment()->getRecurrentPaymentId(); } catch (CieloRequestException $e) { // Em caso de erros de integração, podemos tratar o erro aqui. // os códigos de erro estão todos disponíveis no manual de integração. From b3aca0fe7397d08c3f19d1e0e388f9625f656c1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Meze=CC=82ncio?= Date: Thu, 24 Aug 2017 10:38:02 -0300 Subject: [PATCH 14/34] Melhora o PHPDoc existente e adiciona novos MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ajuda no autocomplete de IDEs e o melhor entendimento do código --- src/Cielo/API30/Ecommerce/Address.php | 75 ++++ src/Cielo/API30/Ecommerce/CieloEcommerce.php | 42 +- .../API30/Ecommerce/CieloSerializable.php | 12 +- src/Cielo/API30/Ecommerce/CreditCard.php | 69 +++- src/Cielo/API30/Ecommerce/Customer.php | 94 ++++- src/Cielo/API30/Ecommerce/Environment.php | 27 +- src/Cielo/API30/Ecommerce/Payment.php | 375 ++++++++++++++++++ .../API30/Ecommerce/RecurrentPayment.php | 92 +++++ .../Ecommerce/Request/AbstractSaleRequest.php | 68 +++- .../API30/Ecommerce/Request/CieloError.php | 29 +- .../Request/CieloRequestException.php | 22 +- .../Ecommerce/Request/CreateSaleRequest.php | 27 +- .../Request/QueryRecurrentPaymentRequest.php | 21 + .../Ecommerce/Request/QuerySaleRequest.php | 27 +- .../Ecommerce/Request/UpdateSaleRequest.php | 50 ++- src/Cielo/API30/Ecommerce/Sale.php | 74 +++- src/Cielo/API30/Environment.php | 13 +- src/Cielo/API30/Merchant.php | 23 +- 18 files changed, 1062 insertions(+), 78 deletions(-) diff --git a/src/Cielo/API30/Ecommerce/Address.php b/src/Cielo/API30/Ecommerce/Address.php index 4fe655b..06ce5c9 100644 --- a/src/Cielo/API30/Ecommerce/Address.php +++ b/src/Cielo/API30/Ecommerce/Address.php @@ -1,6 +1,11 @@ street = isset($data->Street)? $data->Street: null; @@ -37,88 +48,152 @@ public function populate(\stdClass $data) $this->district = isset($data->District)? $data->District: null; } + /** + * @return mixed + */ public function getDistrict() { return $this->district; } + /** + * @param $district + * + * @return $this + */ public function setDistrict($district) { $this->district = $district; return $this; } + /** + * @return mixed + */ public function getStreet() { return $this->street; } + /** + * @param $street + * + * @return $this + */ public function setStreet($street) { $this->street = $street; return $this; } + /** + * @return mixed + */ public function getNumber() { return $this->number; } + /** + * @param $number + * + * @return $this + */ public function setNumber($number) { $this->number = $number; return $this; } + /** + * @return mixed + */ public function getComplement() { return $this->complement; } + /** + * @param $complement + * + * @return $this + */ public function setComplement($complement) { $this->complement = $complement; return $this; } + /** + * @return mixed + */ public function getZipCode() { return $this->zipCode; } + /** + * @param $zipCode + * + * @return $this + */ public function setZipCode($zipCode) { $this->zipCode = $zipCode; return $this; } + /** + * @return mixed + */ public function getCity() { return $this->city; } + /** + * @param $city + * + * @return $this + */ public function setCity($city) { $this->city = $city; return $this; } + /** + * @return mixed + */ public function getState() { return $this->state; } + /** + * @param $state + * + * @return $this + */ public function setState($state) { $this->state = $state; return $this; } + /** + * @return mixed + */ public function getCountry() { return $this->country; } + /** + * @param $country + * + * @return $this + */ public function setCountry($country) { $this->country = $country; diff --git a/src/Cielo/API30/Ecommerce/CieloEcommerce.php b/src/Cielo/API30/Ecommerce/CieloEcommerce.php index 0bf0d3b..e0ca5c9 100644 --- a/src/Cielo/API30/Ecommerce/CieloEcommerce.php +++ b/src/Cielo/API30/Ecommerce/CieloEcommerce.php @@ -21,11 +21,9 @@ class CieloEcommerce * Create an instance of CieloEcommerce choosing the environment where the * requests will be send * - * @param - * \Cielo\API30\Ecommerce\Merchant merchant + * @param Merchant $merchant * The merchant credentials - * @param - * \Cielo\API30\Ecommerce\Environment environment + * @param Environment environment * The environment: {@link Environment::production()} or * {@link Environment::sandbox()} */ @@ -43,10 +41,13 @@ public function __construct(Merchant $merchant, Environment $environment = null) * Send the Sale to be created and return the Sale with tid and the status * returned by Cielo. * - * @param \Cielo\API30\Ecommerce\Sale $sale + * @param Sale $sale * The preconfigured Sale - * @return \Cielo\API30\Ecommerce\Sale The Sale with authorization, tid, etc. returned by Cielo. - * @throws CieloRequestException if anything gets wrong. + * + * @return Sale The Sale with authorization, tid, etc. returned by Cielo. + * + * @throws \Cielo\API30\Ecommerce\Request\CieloRequestException if anything gets wrong. + * * @see Error * Codes @@ -63,8 +64,11 @@ public function createSale(Sale $sale) * * @param string $paymentId * The paymentId to be queried - * @return \Cielo\API30\Ecommerce\Sale The Sale with authorization, tid, etc. returned by Cielo. - * @throws CieloRequestException if anything gets wrong. + * + * @return Sale The Sale with authorization, tid, etc. returned by Cielo. + * + * @throws \Cielo\API30\Ecommerce\Request\CieloRequestException if anything gets wrong. + * * @see Error * Codes @@ -81,8 +85,12 @@ public function getSale($paymentId) * * @param string $recurrentPaymentId * The RecurrentPaymentId to be queried - * @return \Cielo\API30\Ecommerce\RecurrentPayment The RecurrentPayment with authorization, tid, etc. returned by Cielo. - * @throws CieloRequestException if anything gets wrong. + * + * @return \Cielo\API30\Ecommerce\RecurrentPayment + * The RecurrentPayment with authorization, tid, etc. returned by Cielo. + * + * @throws \Cielo\API30\Ecommerce\Request\CieloRequestException if anything gets wrong. + * * @see Error * Codes @@ -101,8 +109,11 @@ public function getRecurrentPayment($recurrentPaymentId) * The paymentId to be queried * @param integer $amount * Order value in cents - * @return \Cielo\API30\Ecommerce\Sale The Sale with authorization, tid, etc. returned by Cielo. - * @throws CieloRequestException if anything gets wrong. + * + * @return Sale The Sale with authorization, tid, etc. returned by Cielo. + * + * @throws \Cielo\API30\Ecommerce\Request\CieloRequestException if anything gets wrong. + * * @see Error * Codes @@ -127,9 +138,12 @@ public function cancelSale($paymentId, $amount = null) * @param integer $serviceTaxAmount * Amount of the authorization should be destined for the service * charge + * * @return \Cielo\API30\Ecommerce\Payment The captured Payment. * - * @throws CieloRequestException if anything gets wrong. + * + * @throws \Cielo\API30\Ecommerce\Request\CieloRequestException if anything gets wrong. + * * @see Error * Codes diff --git a/src/Cielo/API30/Ecommerce/CieloSerializable.php b/src/Cielo/API30/Ecommerce/CieloSerializable.php index cdda657..c64edd4 100644 --- a/src/Cielo/API30/Ecommerce/CieloSerializable.php +++ b/src/Cielo/API30/Ecommerce/CieloSerializable.php @@ -1,7 +1,17 @@ cardNumber = isset($data->CardNumber)? $data->CardNumber: null; @@ -34,80 +45,136 @@ public function populate(\stdClass $data) $this->cardToken = isset($data->CardToken)? $data->CardToken: null; } + /** + * @return mixed + */ public function getCardNumber() { return $this->cardNumber; } + /** + * @param $cardNumber + * + * @return $this + */ public function setCardNumber($cardNumber) { $this->cardNumber = $cardNumber; return $this; } + /** + * @return mixed + */ public function getHolder() { return $this->holder; } + /** + * @param $holder + * + * @return $this + */ public function setHolder($holder) { $this->holder = $holder; return $this; } + /** + * @return mixed + */ public function getExpirationDate() { return $this->expirationDate; } + /** + * @param $expirationDate + * + * @return $this + */ public function setExpirationDate($expirationDate) { $this->expirationDate = $expirationDate; return $this; } + /** + * @return mixed + */ public function getSecurityCode() { return $this->securityCode; } + /** + * @param $securityCode + * + * @return $this + */ public function setSecurityCode($securityCode) { $this->securityCode = $securityCode; return $this; } + /** + * @return bool + */ public function getSaveCard() { return $this->saveCard; } + /** + * @param $saveCard + * + * @return $this + */ public function setSaveCard($saveCard) { $this->saveCard = $saveCard; return $this; } + /** + * @return mixed + */ public function getBrand() { return $this->brand; } + /** + * @param $brand + * + * @return $this + */ public function setBrand($brand) { $this->brand = $brand; return $this; } + /** + * @return mixed + */ public function getCardToken() { return $this->cardToken; } + /** + * @param $cardToken + * + * @return $this + */ public function setCardToken($cardToken) { $this->cardToken = $cardToken; return $this; } -} \ No newline at end of file +} diff --git a/src/Cielo/API30/Ecommerce/Customer.php b/src/Cielo/API30/Ecommerce/Customer.php index 90cf85c..222b603 100644 --- a/src/Cielo/API30/Ecommerce/Customer.php +++ b/src/Cielo/API30/Ecommerce/Customer.php @@ -1,6 +1,11 @@ setName($name); } + /** + * @return array + */ public function jsonSerialize() { return get_object_vars($this); } + /** + * @param \stdClass $data + */ public function populate(\stdClass $data) { $this->name = isset($data->Name) ? $data->Name : null; $this->email = isset($data->Email) ? $data->Email : null; $this->birthDate = isset($data->Birthdate) ? $data->Birthdate : null; - + $this->identity = isset($data->Identity) ? $data->Identity : null; $this->identityType = isset($data->IdentityType) ? $data->IdentityType : null; - + if (isset($data->Address)) { $this->address = new Address(); $this->address->populate($data->Address); } - + if (isset($data->DeliveryAddress)) { $this->deliveryAddress = new Address(); $this->deliveryAddress->populate($data->DeliveryAddress); } } + /** + * @return Address + */ public function address() { $address = new Address(); - + $this->setAddress($address); - + return $address; } + /** + * @return Address + */ public function deliveryAddress() { $address = new Address(); - + $this->setDeliveryAddress($address); - + return $address; } + /** + * @return mixed + */ public function getName() { return $this->name; } + /** + * @param $name + * + * @return $this + */ public function setName($name) { $this->name = $name; return $this; } + /** + * @return mixed + */ public function getEmail() { return $this->email; } + /** + * @param $email + * + * @return $this + */ public function setEmail($email) { $this->email = $email; return $this; } + /** + * @return mixed + */ public function getBirthDate() { return $this->birthDate; } + /** + * @param $birthDate + * + * @return $this + */ public function setBirthDate($birthDate) { $this->birthDate = $birthDate; return $this; } + /** + * @return mixed + */ public function getIdentity() { return $this->identity; } + /** + * @param $identity + * + * @return $this + */ public function setIdentity($identity) { $this->identity = $identity; return $this; } + /** + * @return mixed + */ public function getIdentityType() { return $this->identityType; } + /** + * @param $identityType + * + * @return $this + */ public function setIdentityType($identityType) { $this->identityType = $identityType; return $this; } + /** + * @return mixed + */ public function getAddress() { return $this->address; } + /** + * @param $address + * + * @return $this + */ public function setAddress($address) { $this->address = $address; return $this; } + /** + * @return mixed + */ public function getDeliveryAddress() { return $this->deliveryAddress; } + /** + * @param $deliveryAddress + * + * @return $this + */ public function setDeliveryAddress($deliveryAddress) { $this->deliveryAddress = $deliveryAddress; return $this; } -} \ No newline at end of file +} diff --git a/src/Cielo/API30/Ecommerce/Environment.php b/src/Cielo/API30/Ecommerce/Environment.php index 38c1bfe..b2c3ba4 100644 --- a/src/Cielo/API30/Ecommerce/Environment.php +++ b/src/Cielo/API30/Ecommerce/Environment.php @@ -1,38 +1,55 @@ api = $api; $this->apiQuery = $apiQuery; } + /** + * @return Environment + */ public static function sandbox() { $api = 'https://apisandbox.cieloecommerce.cielo.com.br/'; $apiQuery = 'https://apiquerysandbox.cieloecommerce.cielo.com.br/'; - + return new Environment($api, $apiQuery); } + /** + * @return Environment + */ public static function production() { $api = 'https://api.cieloecommerce.cielo.com.br/'; $apiQuery = 'https://apiquery.cieloecommerce.cielo.com.br/'; - + return new Environment($api, $apiQuery); } /** * Gets the environment's Api URL * - * @return the Api URL + * @return string the Api URL */ public function getApiUrl() { @@ -42,10 +59,10 @@ public function getApiUrl() /** * Gets the environment's Api Query URL * - * @return the Api Query URL + * @return string Api Query URL */ public function getApiQueryURL() { return $this->apiQuery; } -} \ No newline at end of file +} diff --git a/src/Cielo/API30/Ecommerce/Payment.php b/src/Cielo/API30/Ecommerce/Payment.php index b6a7b62..61404cb 100644 --- a/src/Cielo/API30/Ecommerce/Payment.php +++ b/src/Cielo/API30/Ecommerce/Payment.php @@ -1,6 +1,11 @@ setAmount($amount); $this->setInstallments($installments); } + /** + * @return array + */ public function jsonSerialize() { return get_object_vars($this); } + /** + * @param \stdClass $data + */ public function populate(\stdClass $data) { @@ -173,6 +190,11 @@ public function populate(\stdClass $data) $this->instructions = isset($data->Instructions)? $data->Instructions: null; } + /** + * @param $json + * + * @return Payment + */ public static function fromJson($json) { $payment = new Payment(); @@ -181,6 +203,12 @@ public static function fromJson($json) return $payment; } + /** + * @param $securityCode + * @param $brand + * + * @return CreditCard + */ private function newCard($securityCode, $brand) { $card = new CreditCard(); @@ -190,6 +218,12 @@ private function newCard($securityCode, $brand) return $card; } + /** + * @param $securityCode + * @param $brand + * + * @return CreditCard + */ public function creditCard($securityCode, $brand) { $card = $this->newCard($securityCode, $brand); @@ -200,6 +234,12 @@ public function creditCard($securityCode, $brand) return $card; } + /** + * @param $securityCode + * @param $brand + * + * @return CreditCard + */ public function debitCard($securityCode, $brand) { $card = $this->newCard($securityCode, $brand); @@ -210,6 +250,11 @@ public function debitCard($securityCode, $brand) return $card; } + /** + * @param bool $authorizeNow + * + * @return RecurrentPayment + */ public function recurrentPayment($authorizeNow = true) { $recurrentPayment = new RecurrentPayment($authorizeNow); @@ -219,88 +264,152 @@ public function recurrentPayment($authorizeNow = true) return $recurrentPayment; } + /** + * @return mixed + */ public function getServiceTaxAmount() { return $this->serviceTaxAmount; } + /** + * @param $serviceTaxAmount + * + * @return $this + */ public function setServiceTaxAmount($serviceTaxAmount) { $this->serviceTaxAmount = $serviceTaxAmount; return $this; } + /** + * @return mixed + */ public function getInstallments() { return $this->installments; } + /** + * @param $installments + * + * @return $this + */ public function setInstallments($installments) { $this->installments = $installments; return $this; } + /** + * @return mixed + */ public function getInterest() { return $this->interest; } + /** + * @param $interest + * + * @return $this + */ public function setInterest($interest) { $this->interest = $interest; return $this; } + /** + * @return bool + */ public function getCapture() { return $this->capture; } + /** + * @param $capture + * + * @return $this + */ public function setCapture($capture) { $this->capture = $capture; return $this; } + /** + * @return bool + */ public function getAuthenticate() { return $this->authenticate; } + /** + * @param $authenticate + * + * @return $this + */ public function setAuthenticate($authenticate) { $this->authenticate = $authenticate; return $this; } + /** + * @return mixed + */ public function getRecurrent() { return $this->recurrent; } + /** + * @param $recurrent + * + * @return $this + */ public function setRecurrent($recurrent) { $this->recurrent = $recurrent; return $this; } + /** + * @return mixed + */ public function getRecurrentPayment() { return $this->recurrentPayment; } + /** + * @param $recurrentPayment + * + * @return $this + */ public function setRecurrentPayment($recurrentPayment) { $this->recurrentPayment = $recurrentPayment; return $this; } + /** + * @return mixed + */ public function getCreditCard() { return $this->creditCard; } + /** + * @param CreditCard $creditCard + * + * @return $this + */ public function setCreditCard(CreditCard $creditCard) { $this->creditCard = $creditCard; @@ -317,6 +426,8 @@ public function getDebitCard() /** * @param mixed $debitCard + * + * @return $this */ public function setDebitCard($debitCard) { @@ -324,330 +435,570 @@ public function setDebitCard($debitCard) return $this; } + /** + * @return mixed + */ public function getAuthenticationUrl() { return $this->authenticationUrl; } + /** + * @param $authenticationUrl + * + * @return $this + */ public function setAuthenticationUrl($authenticationUrl) { $this->authenticationUrl = $authenticationUrl; return $this; } + /** + * @return mixed + */ public function getTid() { return $this->tid; } + /** + * @param $tid + * + * @return $this + */ public function setTid($tid) { $this->tid = $tid; return $this; } + /** + * @return mixed + */ public function getProofOfSale() { return $this->proofOfSale; } + /** + * @param $proofOfSale + * + * @return $this + */ public function setProofOfSale($proofOfSale) { $this->proofOfSale = $proofOfSale; return $this; } + /** + * @return mixed + */ public function getAuthorizationCode() { return $this->authorizationCode; } + /** + * @param $authorizationCode + * + * @return $this + */ public function setAuthorizationCode($authorizationCode) { $this->authorizationCode = $authorizationCode; return $this; } + /** + * @return string + */ public function getSoftDescriptor() { return $this->softDescriptor; } + /** + * @param $softDescriptor + * + * @return $this + */ public function setSoftDescriptor($softDescriptor) { $this->softDescriptor = $softDescriptor; return $this; } + /** + * @return mixed + */ public function getReturnUrl() { return $this->returnUrl; } + /** + * @param $returnUrl + * + * @return $this + */ public function setReturnUrl($returnUrl) { $this->returnUrl = $returnUrl; return $this; } + /** + * @return mixed + */ public function getProvider() { return $this->provider; } + /** + * @param $provider + * + * @return $this + */ public function setProvider($provider) { $this->provider = $provider; return $this; } + /** + * @return mixed + */ public function getPaymentId() { return $this->paymentId; } + /** + * @param $paymentId + * + * @return $this + */ public function setPaymentId($paymentId) { $this->paymentId = $paymentId; return $this; } + /** + * @return mixed + */ public function getType() { return $this->type; } + /** + * @param $type + * + * @return $this + */ public function setType($type) { $this->type = $type; return $this; } + /** + * @return mixed + */ public function getAmount() { return $this->amount; } + /** + * @param $amount + * + * @return $this + */ public function setAmount($amount) { $this->amount = $amount; return $this; } + /** + * @return mixed + */ public function getReceivedDate() { return $this->receivedDate; } + /** + * @param $receivedDate + * + * @return $this + */ public function setReceivedDate($receivedDate) { $this->receivedDate = $receivedDate; return $this; } + /** + * @return mixed + */ public function getCapturedAmount() { return $this->capturedAmount; } + /** + * @param $capturedAmount + * + * @return $this + */ public function setCapturedAmount($capturedAmount) { $this->capturedAmount = $capturedAmount; return $this; } + /** + * @return mixed + */ public function getCapturedDate() { return $this->capturedDate; } + /** + * @param $capturedDate + * + * @return $this + */ public function setCapturedDate($capturedDate) { $this->capturedDate = $capturedDate; return $this; } + /** + * @return mixed + */ public function getVoidedAmount() { return $this->voidedAmount; } + /** + * @param $voidedAmount + * + * @return $this + */ public function setVoidedAmount($voidedAmount) { $this->voidedAmount = $voidedAmount; return $this; } + /** + * @return mixed + */ public function getVoidedDate() { return $this->voidedDate; } + /** + * @param $voidedDate + * + * @return $this + */ public function setVoidedDate($voidedDate) { $this->voidedDate = $voidedDate; return $this; } + /** + * @return mixed + */ public function getCurrency() { return $this->currency; } + /** + * @param $currency + * + * @return $this + */ public function setCurrency($currency) { $this->currency = $currency; return $this; } + /** + * @return mixed + */ public function getCountry() { return $this->country; } + /** + * @param $country + * + * @return $this + */ public function setCountry($country) { $this->country = $country; return $this; } + /** + * @return mixed + */ public function getReturnCode() { return $this->returnCode; } + /** + * @param $returnCode + * + * @return $this + */ public function setReturnCode($returnCode) { $this->returnCode = $returnCode; return $this; } + /** + * @return mixed + */ public function getReturnMessage() { return $this->returnMessage; } + /** + * @param $returnMessage + * + * @return $this + */ public function setReturnMessage($returnMessage) { $this->returnMessage = $returnMessage; return $this; } + /** + * @return mixed + */ public function getStatus() { return $this->status; } + /** + * @param $status + * + * @return $this + */ public function setStatus($status) { $this->status = $status; return $this; } + /** + * @return mixed + */ public function getLinks() { return $this->links; } + /** + * @param $links + * + * @return $this + */ public function setLinks($links) { $this->links = $links; return $this; } + /** + * @return mixed + */ public function getExtraDataCollection() { return $this->extraDataCollection; } + /** + * @param $extraDataCollection + * + * @return $this + */ public function setExtraDataCollection($extraDataCollection) { $this->extraDataCollection = $extraDataCollection; return $this; } + /** + * @return mixed + */ public function getExpirationDate() { return $this->expirationDate; } + /** + * @param $expirationDate + * + * @return $this + */ public function setExpirationDate($expirationDate) { $this->expirationDate = $expirationDate; return $this; } + /** + * @return mixed + */ public function getUrl() { return $this->url; } + /** + * @param $url + * + * @return $this + */ public function setUrl($url) { $this->url = $url; return $this; } + /** + * @return mixed + */ public function getNumber() { return $this->number; } + /** + * @param $number + * + * @return $this + */ public function setNumber($number) { $this->number = $number; return $this; } + /** + * @return mixed + */ public function getBoletoNumber() { return $this->boletoNumber; } + /** + * @param $boletoNumber + * + * @return $this + */ public function setBoletoNumber($boletoNumber) { $this->boletoNumber = $boletoNumber; return $this; } + /** + * @return mixed + */ public function getBarCodeNumber() { return $this->barCodeNumber; } + /** + * @param $barCodeNumber + * + * @return $this + */ public function setBarCodeNumber($barCodeNumber) { $this->barCodeNumber = $barCodeNumber; return $this; } + /** + * @return mixed + */ public function getDigitableLine() { return $this->digitableLine; } + /** + * @param $digitableLine + * + * @return $this + */ public function setDigitableLine($digitableLine) { $this->digitableLine = $digitableLine; return $this; } + /** + * @return mixed + */ public function getAddress() { return $this->address; } + /** + * @param $address + * + * @return $this + */ public function setAddress($address) { $this->address = $address; return $this; } + /** + * @return mixed + */ public function getAssignor() { return $this->assignor; } + /** + * @param $assignor + * + * @return $this + */ public function setAssignor($assignor) { $this->assignor = $assignor; @@ -655,11 +1006,19 @@ public function setAssignor($assignor) return $this; } + /** + * @return mixed + */ public function getDemonstrative() { return $this->demonstrative; } + /** + * @param $demonstrative + * + * @return $this + */ public function setDemonstrative($demonstrative) { $this->demonstrative = $demonstrative; @@ -667,11 +1026,19 @@ public function setDemonstrative($demonstrative) return $this; } + /** + * @return mixed + */ public function getIdentification() { return $this->identification; } + /** + * @param $identification + * + * @return $this + */ public function setIdentification($identification) { $this->identification = $identification; @@ -679,11 +1046,19 @@ public function setIdentification($identification) return $this; } + /** + * @return mixed + */ public function getInstructions() { return $this->instructions; } + /** + * @param $instructions + * + * @return $this + */ public function setInstructions($instructions) { $this->instructions = $instructions; diff --git a/src/Cielo/API30/Ecommerce/RecurrentPayment.php b/src/Cielo/API30/Ecommerce/RecurrentPayment.php index 2e5cb78..b51fef8 100644 --- a/src/Cielo/API30/Ecommerce/RecurrentPayment.php +++ b/src/Cielo/API30/Ecommerce/RecurrentPayment.php @@ -1,6 +1,11 @@ setAuthorizeNow($authorizeNow); } + /** + * @return array + */ public function jsonSerialize() { return get_object_vars($this); } + /** + * @param \stdClass $data + */ public function populate(\stdClass $data) { $this->authorizeNow = isset($data->AuthorizeNow)? !!$data->AuthorizeNow: false; @@ -70,6 +86,11 @@ public function populate(\stdClass $data) $this->status = isset($data->Status)? $data->Status: null; } + /** + * @param $json + * + * @return RecurrentPayment + */ public static function fromJson($json) { $object = json_decode($json); @@ -83,109 +104,180 @@ public static function fromJson($json) return $recurrentPayment; } + /** + * @return mixed + */ public function getRecurrentPaymentId() { return $this->recurrentPaymentId; } + /** + * @return mixed + */ public function getReasonCode() { return $this->reasonCode; } + /** + * @return mixed + */ public function getReasonMessage() { return $this->reasonMessage; } + /** + * @return mixed + */ public function getNextRecurrency() { return $this->nextRecurrency; } + /** + * @return mixed + */ public function getAmount() { return $this->amount; } + /** + * @return mixed + */ public function getCountry() { return $this->country; } + /** + * @return mixed + */ public function getCreateDate() { return $this->createDate; } + /** + * @return mixed + */ public function getCurrency() { return $this->currency; } + /** + * @return mixed + */ public function getCurrentRecurrencyTry() { return $this->currentRecurrencyTry; } + /** + * @return mixed + */ public function getProvider() { return $this->provider; } + /** + * @return mixed + */ public function getRecurrencyDay() { return $this->recurrencyDay; } + /** + * @return mixed + */ public function getSuccessfulRecurrences() { return $this->successfulRecurrences; } + /** + * @return mixed + */ public function getStatus() { return $this->status; } + /** + * @return mixed + */ public function getAuthorizeNow() { return $this->authorizeNow; } + /** + * @param $authorizeNow + * + * @return $this + */ public function setAuthorizeNow($authorizeNow) { $this->authorizeNow = $authorizeNow; return $this; } + /** + * @return mixed + */ public function getStartDate() { return $this->startDate; } + /** + * @param $startDate + * + * @return $this + */ public function setStartDate($startDate) { $this->startDate = $startDate; return $this; } + /** + * @return mixed + */ public function getEndDate() { return $this->endDate; } + /** + * @param $endDate + * + * @return $this + */ public function setEndDate($endDate) { $this->endDate = $endDate; return $this; } + /** + * @return mixed + */ public function getInterval() { return $this->interval; } + /** + * @param $interval + * + * @return $this + */ public function setInterval($interval) { $this->interval = $interval; diff --git a/src/Cielo/API30/Ecommerce/Request/AbstractSaleRequest.php b/src/Cielo/API30/Ecommerce/Request/AbstractSaleRequest.php index d3759e6..95c1645 100644 --- a/src/Cielo/API30/Ecommerce/Request/AbstractSaleRequest.php +++ b/src/Cielo/API30/Ecommerce/Request/AbstractSaleRequest.php @@ -4,20 +4,50 @@ use Cielo\API30\Merchant; use Cielo\API30\Ecommerce\Sale; +/** + * Class AbstractSaleRequest + * + * @package Cielo\API30\Ecommerce\Request + */ abstract class AbstractSaleRequest { private $merchant; + /** + * AbstractSaleRequest constructor. + * + * @param Merchant $merchant + */ public function __construct(Merchant $merchant) { $this->merchant = $merchant; } + /** + * @param $param + * + * @return mixed + */ public abstract function execute($param); + /** + * @param $json + * + * @return mixed + */ protected abstract function unserialize($json); + /** + * @param $method + * @param $url + * @param Sale|null $sale + * + * @return mixed + * + * @throws \Cielo\API30\Ecommerce\Request\CieloRequestException + * @throws \RuntimeException + */ protected function sendRequest($method, $url, Sale $sale = null) { $headers = [ @@ -28,12 +58,12 @@ protected function sendRequest($method, $url, Sale $sale = null) 'MerchantKey: ' . $this->merchant->getKey(), 'RequestId: ' . uniqid() ]; - + $curl = curl_init($url); - + curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); - + switch ($method) { case 'GET': break; @@ -43,34 +73,42 @@ protected function sendRequest($method, $url, Sale $sale = null) default: curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); } - + if ($sale !== null) { curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($sale)); - + $headers[] = 'Content-Type: application/json'; } else { $headers[] = 'Content-Length: 0'; } - + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); - + $response = curl_exec($curl); $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); - + if (curl_errno($curl)) { throw new \RuntimeException('Curl error: ' . curl_error($curl)); } - + curl_close($curl); - + return $this->readResponse($statusCode, $response); } + /** + * @param $statusCode + * @param $responseBody + * + * @return mixed + * + * @throws CieloRequestException + */ protected function readResponse($statusCode, $responseBody) { $unserialized = null; - + switch ($statusCode) { case 200: case 201: @@ -79,20 +117,20 @@ protected function readResponse($statusCode, $responseBody) case 400: $exception = null; $response = json_decode($responseBody); - + foreach ($response as $error) { $cieloError = new CieloError($error->Message, $error->Code); $exception = new CieloRequestException('Request Error', $statusCode, $exception); $exception->setCieloError($cieloError); } - + throw $exception; case 404: throw new CieloRequestException('Resource not found', 404, null); default: throw new CieloRequestException('Unknown status', $statusCode); } - + return $unserialized; } -} \ No newline at end of file +} diff --git a/src/Cielo/API30/Ecommerce/Request/CieloError.php b/src/Cielo/API30/Ecommerce/Request/CieloError.php index 4e36d01..e2ccd7b 100644 --- a/src/Cielo/API30/Ecommerce/Request/CieloError.php +++ b/src/Cielo/API30/Ecommerce/Request/CieloError.php @@ -1,6 +1,11 @@ setMessage($message); $this->setCode($code); } + /** + * @return mixed + */ public function getCode() { return $this->code; } + /** + * @param $code + * + * @return $this + */ public function setCode($code) { $this->code = $code; return $this; } + /** + * @return mixed + */ public function getMessage() { return $this->message; } + /** + * @param $message + * + * @return $this + */ public function setMessage($message) { $this->message = $message; return $this; } -} \ No newline at end of file +} diff --git a/src/Cielo/API30/Ecommerce/Request/CieloRequestException.php b/src/Cielo/API30/Ecommerce/Request/CieloRequestException.php index b5f483e..db4adf6 100644 --- a/src/Cielo/API30/Ecommerce/Request/CieloRequestException.php +++ b/src/Cielo/API30/Ecommerce/Request/CieloRequestException.php @@ -1,24 +1,44 @@ cieloError; } + /** + * @param CieloError $cieloError + * + * @return $this + */ public function setCieloError(CieloError $cieloError) { $this->cieloError = $cieloError; return $this; } -} \ No newline at end of file +} diff --git a/src/Cielo/API30/Ecommerce/Request/CreateSaleRequest.php b/src/Cielo/API30/Ecommerce/Request/CreateSaleRequest.php index 35e9c41..2ffc171 100644 --- a/src/Cielo/API30/Ecommerce/Request/CreateSaleRequest.php +++ b/src/Cielo/API30/Ecommerce/Request/CreateSaleRequest.php @@ -6,27 +6,48 @@ use Cielo\API30\Merchant; use Cielo\API30\Ecommerce\Sale; +/** + * Class CreateSaleRequest + * + * @package Cielo\API30\Ecommerce\Request + */ class CreateSaleRequest extends AbstractSaleRequest { private $environment; + /** + * CreateSaleRequest constructor. + * + * @param Merchant $merchant + * @param Environment $environment + */ public function __construct(Merchant $merchant, Environment $environment) { parent::__construct($merchant); - + $this->environment = $environment; } + /** + * @param $sale + * + * @return null + */ public function execute($sale) { $url = $this->environment->getApiUrl() . '1/sales/'; - + return $this->sendRequest('POST', $url, $sale); } + /** + * @param $json + * + * @return Sale + */ protected function unserialize($json) { return Sale::fromJson($json); } -} \ No newline at end of file +} diff --git a/src/Cielo/API30/Ecommerce/Request/QueryRecurrentPaymentRequest.php b/src/Cielo/API30/Ecommerce/Request/QueryRecurrentPaymentRequest.php index ce7449e..cdab8e8 100644 --- a/src/Cielo/API30/Ecommerce/Request/QueryRecurrentPaymentRequest.php +++ b/src/Cielo/API30/Ecommerce/Request/QueryRecurrentPaymentRequest.php @@ -6,11 +6,22 @@ use Cielo\API30\Merchant; use Cielo\API30\Ecommerce\RecurrentPayment; +/** + * Class QueryRecurrentPaymentRequest + * + * @package Cielo\API30\Ecommerce\Request + */ class QueryRecurrentPaymentRequest extends AbstractSaleRequest { private $environment; + /** + * QueryRecurrentPaymentRequest constructor. + * + * @param Merchant $merchant + * @param Environment $environment + */ public function __construct(Merchant $merchant, Environment $environment) { parent::__construct($merchant); @@ -18,6 +29,11 @@ public function __construct(Merchant $merchant, Environment $environment) $this->environment = $environment; } + /** + * @param $recurrentPaymentId + * + * @return null + */ public function execute($recurrentPaymentId) { $url = $this->environment->getApiQueryURL() . '1/RecurrentPayment/' . $recurrentPaymentId; @@ -25,6 +41,11 @@ public function execute($recurrentPaymentId) return $this->sendRequest('GET', $url); } + /** + * @param $json + * + * @return RecurrentPayment + */ protected function unserialize($json) { return RecurrentPayment::fromJson($json); diff --git a/src/Cielo/API30/Ecommerce/Request/QuerySaleRequest.php b/src/Cielo/API30/Ecommerce/Request/QuerySaleRequest.php index 8b7c266..3e63aba 100644 --- a/src/Cielo/API30/Ecommerce/Request/QuerySaleRequest.php +++ b/src/Cielo/API30/Ecommerce/Request/QuerySaleRequest.php @@ -6,27 +6,48 @@ use Cielo\API30\Merchant; use Cielo\API30\Ecommerce\Sale; +/** + * Class QuerySaleRequest + * + * @package Cielo\API30\Ecommerce\Request + */ class QuerySaleRequest extends AbstractSaleRequest { private $environment; + /** + * QuerySaleRequest constructor. + * + * @param Merchant $merchant + * @param Environment $environment + */ public function __construct(Merchant $merchant, Environment $environment) { parent::__construct($merchant); - + $this->environment = $environment; } + /** + * @param $paymentId + * + * @return null + */ public function execute($paymentId) { $url = $this->environment->getApiQueryURL() . '1/sales/' . $paymentId; - + return $this->sendRequest('GET', $url); } + /** + * @param $json + * + * @return Sale + */ protected function unserialize($json) { return Sale::fromJson($json); } -} \ No newline at end of file +} diff --git a/src/Cielo/API30/Ecommerce/Request/UpdateSaleRequest.php b/src/Cielo/API30/Ecommerce/Request/UpdateSaleRequest.php index 718014e..73862b3 100644 --- a/src/Cielo/API30/Ecommerce/Request/UpdateSaleRequest.php +++ b/src/Cielo/API30/Ecommerce/Request/UpdateSaleRequest.php @@ -6,6 +6,11 @@ use Cielo\API30\Merchant; use Cielo\API30\Ecommerce\Payment; +/** + * Class UpdateSaleRequest + * + * @package Cielo\API30\Ecommerce\Request + */ class UpdateSaleRequest extends AbstractSaleRequest { @@ -17,56 +22,89 @@ class UpdateSaleRequest extends AbstractSaleRequest private $amount; + /** + * UpdateSaleRequest constructor. + * + * @param Merchant $type + * @param Merchant $merchant + * @param Environment $environment + */ public function __construct($type, Merchant $merchant, Environment $environment) { parent::__construct($merchant); - + $this->environment = $environment; $this->type = $type; } + /** + * @param $paymentId + * + * @return null + */ public function execute($paymentId) { $url = $this->environment->getApiUrl() . '1/sales/' . $paymentId . '/' . $this->type; $params = []; - + if ($this->amount != null) { $params['amount'] = $this->amount; } - + if ($this->serviceTaxAmount != null) { $params['serviceTaxAmount'] = $this->serviceTaxAmount; } - + $url .= '?' . http_build_query($params); - + return $this->sendRequest('PUT', $url); } + /** + * @param $json + * + * @return Payment + */ protected function unserialize($json) { return Payment::fromJson($json); } + /** + * @return mixed + */ public function getServiceTaxAmount() { return $this->serviceTaxAmount; } + /** + * @param $serviceTaxAmount + * + * @return $this + */ public function setServiceTaxAmount($serviceTaxAmount) { $this->serviceTaxAmount = $serviceTaxAmount; return $this; } + /** + * @return mixed + */ public function getAmount() { return $this->amount; } + /** + * @param $amount + * + * @return $this + */ public function setAmount($amount) { $this->amount = $amount; return $this; } -} \ No newline at end of file +} diff --git a/src/Cielo/API30/Ecommerce/Sale.php b/src/Cielo/API30/Ecommerce/Sale.php index 891d9cf..b3c2b97 100644 --- a/src/Cielo/API30/Ecommerce/Sale.php +++ b/src/Cielo/API30/Ecommerce/Sale.php @@ -1,6 +1,11 @@ setMerchantOrderId($merchantOrderId); } + /** + * @return array + */ public function jsonSerialize() { return get_object_vars($this); } + /** + * @param \stdClass $data + */ public function populate(\stdClass $data) { $dataProps = get_object_vars($data); - + if (isset($dataProps['Customer'])) { $this->customer = new \Cielo\API30\Ecommerce\Customer(); $this->customer->populate($data->Customer); } - + if (isset($dataProps['Payment'])) { $this->payment = new \Cielo\API30\Ecommerce\Payment(); $this->payment->populate($data->Payment); } - + if (isset($dataProps['MerchantOrderId'])) { $this->merchantOrderId = $data->MerchantOrderId; } } + /** + * @param $json + * + * @return Sale + */ public static function fromJson($json) { $object = json_decode($json); - + $sale = new Sale(); $sale->populate($object); - + return $sale; } + /** + * @param $name + * + * @return Customer + */ public function customer($name) { $customer = new Customer($name); - + $this->setCustomer($customer); - + return $customer; } + /** + * @param $amount + * @param int $installments + * + * @return Payment + */ public function payment($amount, $installments = 1) { $payment = new Payment($amount, $installments); - + $this->setPayment($payment); - + return $payment; } + /** + * @return mixed + */ public function getMerchantOrderId() { return $this->merchantOrderId; } + /** + * @param $merchantOrderId + * + * @return $this + */ public function setMerchantOrderId($merchantOrderId) { $this->merchantOrderId = $merchantOrderId; return $this; } + /** + * @return mixed + */ public function getCustomer() { return $this->customer; } + /** + * @param Customer $customer + * + * @return $this + */ public function setCustomer(Customer $customer) { $this->customer = $customer; return $this; } + /** + * @return mixed + */ public function getPayment() { return $this->payment; } + /* + * + */ public function setPayment(Payment $payment) { $this->payment = $payment; return $this; } -} \ No newline at end of file +} diff --git a/src/Cielo/API30/Environment.php b/src/Cielo/API30/Environment.php index f92b791..d885e66 100644 --- a/src/Cielo/API30/Environment.php +++ b/src/Cielo/API30/Environment.php @@ -1,19 +1,24 @@ id = $id; $this->key = $key; } - + /** * Gets the merchant identification number * - * @return the merchant identification number on Cielo + * @return string the merchant identification number on Cielo */ public function getId() { return $this->id; } - + /** * Gets the merchant identification key * - * @return the merchant identification key on Cielo + * @return string the merchant identification key on Cielo */ public function getKey() { return $this->key; } -} \ No newline at end of file +} From 22144740a376b68c7910831c15e24f147068aaac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Batista=20Neto?= Date: Wed, 1 Nov 2017 12:39:48 -0200 Subject: [PATCH 15/34] =?UTF-8?q?FIX=20#88:=20Adiciona=20exemplo=20de=20to?= =?UTF-8?q?keniza=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Adiciona exemplo de geração de token * Adiciona exemplo de utilização do token gerado --- README.md | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/README.md b/README.md index 31c1962..824a556 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,113 @@ try { // ... ``` +### Criando um pagamento com cartão de crédito + +```php +customer('Fulano de Tal'); + +// Crie uma instância de Payment informando o valor do pagamento +$payment = $sale->payment(15700); + +// Crie uma instância de Credit Card utilizando os dados de teste +// esses dados estão disponíveis no manual de integração. +// Utilize setSaveCard(true) para obter o token do cartão +$payment->setType(Payment::PAYMENTTYPE_CREDITCARD) + ->creditCard("123", "Visa") + ->setExpirationDate("12/2018") + ->setCardNumber("0000000000000001") + ->setHolder("Fulano de Tal") + ->setSaveCard(true); + +// Crie o pagamento na Cielo +try { + // Configure o SDK com seu merchant e o ambiente apropriado para criar a venda + $sale = (new CieloEcommerce($merchant, $environment))->createSale($sale); + + // O token gerado pode ser armazenado em banco de dados para vendar futuras + $token = $sale->getPayment()->getCreditCard()->getCardToken(); +} catch (CieloRequestException $e) { + // Em caso de erros de integração, podemos tratar o erro aqui. + // os códigos de erro estão todos disponíveis no manual de integração. + $error = $e->getCieloError(); +} +// ... +``` + +### Criando um pagamento com cartão de crédito tokenizado + +```php +customer('Fulano de Tal'); + +// Crie uma instância de Payment informando o valor do pagamento +$payment = $sale->payment(15700); + +// Crie uma instância de Credit Card utilizando os dados de teste +// esses dados estão disponíveis no manual de integração +$payment->setType(Payment::PAYMENTTYPE_CREDITCARD) + ->creditCard("123", "Visa") + ->setCardToken("TOKEN-PREVIAMENTE-ARMAZENADO"); + +// Crie o pagamento na Cielo +try { + // Configure o SDK com seu merchant e o ambiente apropriado para criar a venda + $sale = (new CieloEcommerce($merchant, $environment))->createSale($sale); + + // Com a venda criada na Cielo, já temos o ID do pagamento, TID e demais + // dados retornados pela Cielo + $paymentId = $sale->getPayment()->getPaymentId(); +} catch (CieloRequestException $e) { + // Em caso de erros de integração, podemos tratar o erro aqui. + // os códigos de erro estão todos disponíveis no manual de integração. + $error = $e->getCieloError(); +} +// ... +``` + ### Criando um pagamento recorrente ```php From d937ca8231720c3e743e953916ae1c90c3b70f4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Batista=20Neto?= Date: Wed, 1 Nov 2017 12:40:55 -0200 Subject: [PATCH 16/34] =?UTF-8?q?Corre=C3=A7=C3=A3o=20do=20t=C3=ADtulo=20d?= =?UTF-8?q?a=20se=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 824a556..2107fe3 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ try { // ... ``` -### Criando um pagamento com cartão de crédito +### Criando um pagamento e gerando o token do cartão de crédito ```php Date: Thu, 7 Dec 2017 10:13:55 -0200 Subject: [PATCH 17/34] =?UTF-8?q?Adicionando=20recurso=20de=20tokeniza?= =?UTF-8?q?=C3=A7=C3=A3o=20do=20cart=C3=A3o=20ao=20SDK?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 50 +++++ src/Cielo/API30/Ecommerce/Card.php | 193 ++++++++++++++++++ src/Cielo/API30/Ecommerce/CieloEcommerce.php | 12 ++ ...actSaleRequest.php => AbstractRequest.php} | 12 +- .../Ecommerce/Request/CreateSaleRequest.php | 4 +- .../Request/QueryRecurrentPaymentRequest.php | 4 +- .../Ecommerce/Request/QuerySaleRequest.php | 3 +- .../Ecommerce/Request/TokenizeCardRequest.php | 51 +++++ .../Ecommerce/Request/UpdateSaleRequest.php | 4 +- 9 files changed, 319 insertions(+), 14 deletions(-) create mode 100644 src/Cielo/API30/Ecommerce/Card.php rename src/Cielo/API30/Ecommerce/Request/{AbstractSaleRequest.php => AbstractRequest.php} (94%) create mode 100644 src/Cielo/API30/Ecommerce/Request/TokenizeCardRequest.php diff --git a/README.md b/README.md index 2107fe3..8a4e949 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ SDK API-3.0 PHP * [x] Pagamentos por transferência eletrônica. * [x] Cancelamento de autorização. * [x] Consulta de pagamentos. +* [x] Tokenização de cartão. ## Limitações @@ -399,6 +400,55 @@ try { } ``` +### Tokenizando um cartão + +```php +cieloEcommerce = new CieloEcommerce($merchant, $environment); +$this->createCardTokenRequestHandler = new TokenizeCardRequest($merchant, $environment); + +// Crie uma instância do objeto que irá retornar o token do cartão +$card = new Card(); +$card->setCustomerName('Fulano de Tal'); +$card->setCardNumber('0000000000000001'); +$card->setHolder('Fulano de Tal'); +$card->setExpirationDate('10/2020'); +$card->setBrand('Visa'); + +try { + // Configure o SDK com seu merchant e o ambiente apropriado para recuperar o cartão + $card = (new CieloEcommerce($merchant, $environment))->tokenizeCard($card); + + // Get the token + $cardToken = $card->getCardToken(); +} catch (CieloRequestException $e) { + // Em caso de erros de integração, podemos tratar o erro aqui. + // os códigos de erro estão todos disponíveis no manual de integração. + $error = $e->getCieloError(); +} +// ... +``` + ## Manual Para mais informações sobre a integração com a API 3.0 da Cielo, vide o manual em: [Integração API 3.0](https://developercielo.github.io/Webservice-3.0/) diff --git a/src/Cielo/API30/Ecommerce/Card.php b/src/Cielo/API30/Ecommerce/Card.php new file mode 100644 index 0000000..284ce2d --- /dev/null +++ b/src/Cielo/API30/Ecommerce/Card.php @@ -0,0 +1,193 @@ +brand; + } + + /** + * @param string $brand + */ + public function setBrand($brand) + { + $this->brand = $brand; + } + + /** + * @return string + */ + public function getCardNumber() + { + return $this->cardNumber; + } + + /** + * @param string $cardNumber + */ + public function setCardNumber($cardNumber) + { + $this->cardNumber = $cardNumber; + } + + /** + * @return string + */ + public function getCardToken() + { + return $this->cardToken; + } + + /** + * @param string $cardToken + */ + public function setCardToken($cardToken) + { + $this->cardToken = $cardToken; + } + + /** + * @return string + */ + public function getCustomerName() + { + return $this->customerName; + } + + /** + * @param string $customerName + */ + public function setCustomerName($customerName) + { + $this->customerName = $customerName; + } + + /** + * @return string + */ + public function getExpirationDate() + { + return $this->expirationDate; + } + + /** + * @param string $expirationDate + */ + public function setExpirationDate($expirationDate) + { + $this->expirationDate = $expirationDate; + } + + /** + * @return string + */ + public function getHolder() + { + return $this->holder; + } + + /** + * @param string $holder + */ + public function setHolder($holder) + { + $this->holder = $holder; + } + + /** + * @return \stdClass + */ + public function getLinks() + { + return $this->links; + } + + /** + * @param \stdClass $links + */ + public function setLinks($links) + { + $this->links = $links; + } + + /** + * @param string $json + * @return Card + */ + public static function fromJson($json) + { + $object = \json_decode($json); + $cardToken = new Card(); + $cardToken->populate($object); + + return $cardToken; + } + + /** + * @inheritdoc + */ + public function populate(\stdClass $data) + { + $data = \get_object_vars($data); + $this->setCardToken(isset($data['CardToken']) ? $data['CardToken'] : ''); + $this->setLinks(isset($data['Links']) ? $data['Links'] : new \stdClass()); + } + + /** + * Specify data which should be serialized to JSON + * @link http://php.net/manual/en/jsonserializable.jsonserialize.php + * @return mixed data which can be serialized by json_encode, + * which is a value of any type other than a resource. + * @since 5.4.0 + */ + public function jsonSerialize() + { + return get_object_vars($this); + } +} diff --git a/src/Cielo/API30/Ecommerce/CieloEcommerce.php b/src/Cielo/API30/Ecommerce/CieloEcommerce.php index e0ca5c9..554d069 100644 --- a/src/Cielo/API30/Ecommerce/CieloEcommerce.php +++ b/src/Cielo/API30/Ecommerce/CieloEcommerce.php @@ -1,6 +1,7 @@ execute($paymentId); } + + /** + * @param Card $card + * @return Card + */ + public function tokenizeCard(Card $card) + { + $updateSaleRequest = new TokenizeCardRequest($this->merchant, $this->environment); + + return $updateSaleRequest->execute($card); + } } diff --git a/src/Cielo/API30/Ecommerce/Request/AbstractSaleRequest.php b/src/Cielo/API30/Ecommerce/Request/AbstractRequest.php similarity index 94% rename from src/Cielo/API30/Ecommerce/Request/AbstractSaleRequest.php rename to src/Cielo/API30/Ecommerce/Request/AbstractRequest.php index 95c1645..191daaa 100644 --- a/src/Cielo/API30/Ecommerce/Request/AbstractSaleRequest.php +++ b/src/Cielo/API30/Ecommerce/Request/AbstractRequest.php @@ -1,15 +1,15 @@ merchant = $merchant; + $this->environment = $environment; + } + + /** + * @inheritdoc + */ + public function execute($param) + { + $url = $this->environment->getApiUrl() . '1/card/'; + + return $this->sendRequest('POST', $url, $param); + } + + /** + * @inheritdoc + */ + protected function unserialize($json) + { + return Card::fromJson($json); + } +} diff --git a/src/Cielo/API30/Ecommerce/Request/UpdateSaleRequest.php b/src/Cielo/API30/Ecommerce/Request/UpdateSaleRequest.php index 73862b3..697fcce 100644 --- a/src/Cielo/API30/Ecommerce/Request/UpdateSaleRequest.php +++ b/src/Cielo/API30/Ecommerce/Request/UpdateSaleRequest.php @@ -1,7 +1,7 @@ Date: Thu, 7 Dec 2017 10:17:06 -0200 Subject: [PATCH 18/34] Fix namespace --- README.md | 2 +- src/Cielo/API30/Ecommerce/Request/TokenizeCardRequest.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8a4e949..e14265e 100644 --- a/README.md +++ b/README.md @@ -412,7 +412,7 @@ use Cielo\API30\Merchant; use Cielo\API30\Ecommerce\Environment; use Cielo\API30\Ecommerce\Card; use Cielo\API30\Ecommerce\CieloEcommerce; -use AppBundle\Handler\Cielo\TokenizeCardRequest; +use Cielo\API30\Ecommerce\Request\TokenizeCardRequest; use Cielo\API30\Ecommerce\Request\CieloRequestException; diff --git a/src/Cielo/API30/Ecommerce/Request/TokenizeCardRequest.php b/src/Cielo/API30/Ecommerce/Request/TokenizeCardRequest.php index e47f9ed..c59e497 100644 --- a/src/Cielo/API30/Ecommerce/Request/TokenizeCardRequest.php +++ b/src/Cielo/API30/Ecommerce/Request/TokenizeCardRequest.php @@ -1,10 +1,9 @@ Date: Thu, 7 Dec 2017 11:58:28 -0200 Subject: [PATCH 19/34] =?UTF-8?q?Corre=C3=A7=C3=A3o=20na=20corre=C3=A7?= =?UTF-8?q?=C3=A3o=20da=20classe=20card=20desnecess=C3=A1ria=20e=20adapta?= =?UTF-8?q?=C3=A7=C3=A3o=20da=20classe=20CreditCard.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +- src/Cielo/API30/Ecommerce/Card.php | 193 ------------------ src/Cielo/API30/Ecommerce/CieloEcommerce.php | 9 +- src/Cielo/API30/Ecommerce/CreditCard.php | 61 ++++++ .../Ecommerce/Request/TokenizeCardRequest.php | 4 +- .../Ecommerce/Request/UpdateSaleRequest.php | 1 - 6 files changed, 70 insertions(+), 203 deletions(-) delete mode 100644 src/Cielo/API30/Ecommerce/Card.php diff --git a/README.md b/README.md index e14265e..a1fb627 100644 --- a/README.md +++ b/README.md @@ -410,7 +410,7 @@ require 'vendor/autoload.php'; use Cielo\API30\Merchant; use Cielo\API30\Ecommerce\Environment; -use Cielo\API30\Ecommerce\Card; +use Cielo\API30\Ecommerce\CreditCard; use Cielo\API30\Ecommerce\CieloEcommerce; use Cielo\API30\Ecommerce\Request\TokenizeCardRequest; @@ -428,8 +428,7 @@ $this->cieloEcommerce = new CieloEcommerce($merchant, $environment); $this->createCardTokenRequestHandler = new TokenizeCardRequest($merchant, $environment); // Crie uma instância do objeto que irá retornar o token do cartão -$card = new Card(); -$card->setCustomerName('Fulano de Tal'); +$card = new CreditCard(); $card->setCardNumber('0000000000000001'); $card->setHolder('Fulano de Tal'); $card->setExpirationDate('10/2020'); diff --git a/src/Cielo/API30/Ecommerce/Card.php b/src/Cielo/API30/Ecommerce/Card.php deleted file mode 100644 index 284ce2d..0000000 --- a/src/Cielo/API30/Ecommerce/Card.php +++ /dev/null @@ -1,193 +0,0 @@ -brand; - } - - /** - * @param string $brand - */ - public function setBrand($brand) - { - $this->brand = $brand; - } - - /** - * @return string - */ - public function getCardNumber() - { - return $this->cardNumber; - } - - /** - * @param string $cardNumber - */ - public function setCardNumber($cardNumber) - { - $this->cardNumber = $cardNumber; - } - - /** - * @return string - */ - public function getCardToken() - { - return $this->cardToken; - } - - /** - * @param string $cardToken - */ - public function setCardToken($cardToken) - { - $this->cardToken = $cardToken; - } - - /** - * @return string - */ - public function getCustomerName() - { - return $this->customerName; - } - - /** - * @param string $customerName - */ - public function setCustomerName($customerName) - { - $this->customerName = $customerName; - } - - /** - * @return string - */ - public function getExpirationDate() - { - return $this->expirationDate; - } - - /** - * @param string $expirationDate - */ - public function setExpirationDate($expirationDate) - { - $this->expirationDate = $expirationDate; - } - - /** - * @return string - */ - public function getHolder() - { - return $this->holder; - } - - /** - * @param string $holder - */ - public function setHolder($holder) - { - $this->holder = $holder; - } - - /** - * @return \stdClass - */ - public function getLinks() - { - return $this->links; - } - - /** - * @param \stdClass $links - */ - public function setLinks($links) - { - $this->links = $links; - } - - /** - * @param string $json - * @return Card - */ - public static function fromJson($json) - { - $object = \json_decode($json); - $cardToken = new Card(); - $cardToken->populate($object); - - return $cardToken; - } - - /** - * @inheritdoc - */ - public function populate(\stdClass $data) - { - $data = \get_object_vars($data); - $this->setCardToken(isset($data['CardToken']) ? $data['CardToken'] : ''); - $this->setLinks(isset($data['Links']) ? $data['Links'] : new \stdClass()); - } - - /** - * Specify data which should be serialized to JSON - * @link http://php.net/manual/en/jsonserializable.jsonserialize.php - * @return mixed data which can be serialized by json_encode, - * which is a value of any type other than a resource. - * @since 5.4.0 - */ - public function jsonSerialize() - { - return get_object_vars($this); - } -} diff --git a/src/Cielo/API30/Ecommerce/CieloEcommerce.php b/src/Cielo/API30/Ecommerce/CieloEcommerce.php index 554d069..63dfcde 100644 --- a/src/Cielo/API30/Ecommerce/CieloEcommerce.php +++ b/src/Cielo/API30/Ecommerce/CieloEcommerce.php @@ -1,7 +1,8 @@ merchant, $this->environment); diff --git a/src/Cielo/API30/Ecommerce/CreditCard.php b/src/Cielo/API30/Ecommerce/CreditCard.php index ea18ec4..0e9e982 100644 --- a/src/Cielo/API30/Ecommerce/CreditCard.php +++ b/src/Cielo/API30/Ecommerce/CreditCard.php @@ -1,4 +1,5 @@ saveCard = isset($data->SaveCard)? !!$data->SaveCard: false; $this->brand = isset($data->Brand)? $data->Brand: null; $this->cardToken = isset($data->CardToken)? $data->CardToken: null; + $this->links = isset($data->Links)? $data->Links : new \stdClass(); + $this->customerName = isset($data->CustomerName)? $data->CustomerName : null; } /** @@ -177,4 +193,49 @@ public function setCardToken($cardToken) $this->cardToken = $cardToken; return $this; } + + /** + * @return string + */ + public function getCustomerName() + { + return $this->customerName; + } + + /** + * @param string $customerName + */ + public function setCustomerName($customerName) + { + $this->customerName = $customerName; + } + + /** + * @return \stdClass + */ + public function getLinks() + { + return $this->links; + } + + /** + * @param \stdClass $links + */ + public function setLinks($links) + { + $this->links = $links; + } + + /** + * @param string $json + * @return CreditCard + */ + public static function fromJson($json) + { + $object = \json_decode($json); + $cardToken = new CreditCard(); + $cardToken->populate($object); + + return $cardToken; + } } diff --git a/src/Cielo/API30/Ecommerce/Request/TokenizeCardRequest.php b/src/Cielo/API30/Ecommerce/Request/TokenizeCardRequest.php index c59e497..9117cc7 100644 --- a/src/Cielo/API30/Ecommerce/Request/TokenizeCardRequest.php +++ b/src/Cielo/API30/Ecommerce/Request/TokenizeCardRequest.php @@ -2,7 +2,7 @@ namespace Cielo\API30\Ecommerce\Request; -use Cielo\API30\Ecommerce\Card; +use Cielo\API30\Ecommerce\CreditCard; use Cielo\API30\Ecommerce\Environment; use Cielo\API30\Merchant; @@ -45,6 +45,6 @@ public function execute($param) */ protected function unserialize($json) { - return Card::fromJson($json); + return CreditCard::fromJson($json); } } diff --git a/src/Cielo/API30/Ecommerce/Request/UpdateSaleRequest.php b/src/Cielo/API30/Ecommerce/Request/UpdateSaleRequest.php index 697fcce..df82667 100644 --- a/src/Cielo/API30/Ecommerce/Request/UpdateSaleRequest.php +++ b/src/Cielo/API30/Ecommerce/Request/UpdateSaleRequest.php @@ -1,7 +1,6 @@ Date: Thu, 7 Dec 2017 11:59:20 -0200 Subject: [PATCH 20/34] Fix php doc --- src/Cielo/API30/Ecommerce/CreditCard.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Cielo/API30/Ecommerce/CreditCard.php b/src/Cielo/API30/Ecommerce/CreditCard.php index 0e9e982..caa558b 100644 --- a/src/Cielo/API30/Ecommerce/CreditCard.php +++ b/src/Cielo/API30/Ecommerce/CreditCard.php @@ -7,7 +7,7 @@ * * @package Cielo\API30\Ecommerce */ -class CreditCard implements \JsonSerializable +class CreditCard implements \JsonSerializable, CieloSerializable { /** @var string $cardNumber */ @@ -46,7 +46,7 @@ public function jsonSerialize() } /** - * @param \stdClass $data + * @inheritdoc */ public function populate(\stdClass $data) { From 3759205fd57a2ee4eb745797c353f6cbde97d250 Mon Sep 17 00:00:00 2001 From: Ayrton Ricardo Date: Thu, 7 Dec 2017 12:01:04 -0200 Subject: [PATCH 21/34] Fix README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a1fb627..ecab579 100644 --- a/README.md +++ b/README.md @@ -429,6 +429,7 @@ $this->createCardTokenRequestHandler = new TokenizeCardRequest($merchant, $envir // Crie uma instância do objeto que irá retornar o token do cartão $card = new CreditCard(); +$card->setCustomerName('Fulano de Tal'); $card->setCardNumber('0000000000000001'); $card->setHolder('Fulano de Tal'); $card->setExpirationDate('10/2020'); From d2e94c67b49b06eaf1047e571cf1329c59c74fb1 Mon Sep 17 00:00:00 2001 From: Ayrton Ricardo Date: Thu, 7 Dec 2017 12:01:38 -0200 Subject: [PATCH 22/34] =?UTF-8?q?Corre=C3=A7=C3=A3o=20no=20nome=20da=20var?= =?UTF-8?q?i=C3=A1vel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Cielo/API30/Ecommerce/CieloEcommerce.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Cielo/API30/Ecommerce/CieloEcommerce.php b/src/Cielo/API30/Ecommerce/CieloEcommerce.php index 63dfcde..8cc4d1f 100644 --- a/src/Cielo/API30/Ecommerce/CieloEcommerce.php +++ b/src/Cielo/API30/Ecommerce/CieloEcommerce.php @@ -166,8 +166,8 @@ public function captureSale($paymentId, $amount = null, $serviceTaxAmount = null */ public function tokenizeCard(CreditCard $card) { - $updateSaleRequest = new TokenizeCardRequest($this->merchant, $this->environment); + $tokenizeCardRequest = new TokenizeCardRequest($this->merchant, $this->environment); - return $updateSaleRequest->execute($card); + return $tokenizeCardRequest->execute($card); } } From 2bf376081d677492cbb2af39c412eb9b7e58806e Mon Sep 17 00:00:00 2001 From: Ayrton Ricardo Date: Thu, 7 Dec 2017 12:10:41 -0200 Subject: [PATCH 23/34] =?UTF-8?q?Corre=C3=A7=C3=A3o=20no=20README.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index ecab579..5aab456 100644 --- a/README.md +++ b/README.md @@ -424,9 +424,6 @@ $environment = Environment::sandbox(); // Configure seu merchant $merchant = new Merchant('MID', 'MKEY'); -$this->cieloEcommerce = new CieloEcommerce($merchant, $environment); -$this->createCardTokenRequestHandler = new TokenizeCardRequest($merchant, $environment); - // Crie uma instância do objeto que irá retornar o token do cartão $card = new CreditCard(); $card->setCustomerName('Fulano de Tal'); From c1b4799587576cc976e1a4acc4851a788566f011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B4nio=20Oliveira?= Date: Wed, 20 Dec 2017 11:23:24 -0200 Subject: [PATCH 24/34] Melhoria na nomenclatura do exemplo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Creio que existe esse pequeno erro na nomenclatura dos exemplos. Não faz sentido eu ter que informar o ID do pagamento (que não existe ainda), sendo que posteriormente eu irei criar um novo pagamento com base nos dados capturados. Acredito que o correto seja passar o ID do pedido na loja. Desculpe-me se eu estiver equivocado. --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5aab456..0d56ccf 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ $environment = $environment = Environment::sandbox(); // Configure seu merchant $merchant = new Merchant('MERCHANT ID', 'MERCHANT KEY'); -// Crie uma instância de Sale informando o ID do pagamento +// Crie uma instância de Sale informando o ID do pedido na loja $sale = new Sale('123'); // Crie uma instância de Customer informando o nome do cliente @@ -130,7 +130,7 @@ $environment = $environment = Environment::sandbox(); // Configure seu merchant $merchant = new Merchant('MERCHANT ID', 'MERCHANT KEY'); -// Crie uma instância de Sale informando o ID do pagamento +// Crie uma instância de Sale informando o ID do pedido na loja $sale = new Sale('123'); // Crie uma instância de Customer informando o nome do cliente @@ -185,7 +185,7 @@ $environment = $environment = Environment::sandbox(); // Configure seu merchant $merchant = new Merchant('MERCHANT ID', 'MERCHANT KEY'); -// Crie uma instância de Sale informando o ID do pagamento +// Crie uma instância de Sale informando o ID do pedido na loja $sale = new Sale('123'); // Crie uma instância de Customer informando o nome do cliente @@ -238,7 +238,7 @@ $environment = $environment = Environment::sandbox(); // Configure seu merchant $merchant = new Merchant('MID', 'MKEY'); -// Crie uma instância de Sale informando o ID do pagamento +// Crie uma instância de Sale informando o ID do pedido na loja $sale = new Sale('123'); // Crie uma instância de Customer informando o nome do cliente @@ -294,7 +294,7 @@ $environment = $environment = Environment::sandbox(); // Configure seu merchant $merchant = new Merchant('MERCHANT ID', 'MERCHANT KEY'); -// Crie uma instância de Sale informando o ID do pagamento +// Crie uma instância de Sale informando o ID do pedido na loja $sale = new Sale('123'); // Crie uma instância de Customer informando o nome do cliente @@ -355,7 +355,7 @@ $environment = $environment = Environment::sandbox(); // Configure seu merchant $merchant = new Merchant('MERCHANT ID', 'MERCHANT KEY'); -// Crie uma instância de Sale informando o ID do pagamento +// Crie uma instância de Sale informando o ID do pedido na loja $sale = new Sale('123'); // Crie uma instância de Customer informando o nome do cliente, From 1683d55245f88cbd29fd21022150d191f257a613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Batista=20Neto?= Date: Thu, 11 Jan 2018 15:52:16 -0200 Subject: [PATCH 25/34] Ignora coisas da IDE --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 987e2a2..5d13a24 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ composer.lock vendor +.idea From a92f1b4a1b902776d0a5a7ecb135e76eb4eff74e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Batista=20Neto?= Date: Thu, 11 Jan 2018 15:53:47 -0200 Subject: [PATCH 26/34] FIX #100: Adiciona constantes para as strings das bandeiras Adiciona constantes em CreditCard para as strings das bandeiras Atualiza o README.md para utilizar as constantes em vez dos literais Atualiza a URL do manual no README.md --- README.md | 42 ++++++++-- src/Cielo/API30/Ecommerce/CreditCard.php | 102 +++++++++++++++++------ 2 files changed, 110 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 0d56ccf..ac30069 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,26 @@ Alternativamente, você pode executar diretamente em seu terminal: composer require "developercielo/api-3.0-php" ``` +## Produtos e Bandeiras suportadas e suas constantes + +```php +payment(15700); // Crie uma instância de Credit Card utilizando os dados de teste // esses dados estão disponíveis no manual de integração $payment->setType(Payment::PAYMENTTYPE_CREDITCARD) - ->creditCard("123", "Visa") + ->creditCard("123", CreditCard::VISA) ->setExpirationDate("12/2018") ->setCardNumber("0000000000000001") ->setHolder("Fulano de Tal"); @@ -121,6 +142,7 @@ use Cielo\API30\Ecommerce\Environment; use Cielo\API30\Ecommerce\Sale; use Cielo\API30\Ecommerce\CieloEcommerce; use Cielo\API30\Ecommerce\Payment; +use Cielo\API30\Ecommerce\CreditCard; use Cielo\API30\Ecommerce\Request\CieloRequestException; // ... @@ -143,7 +165,7 @@ $payment = $sale->payment(15700); // esses dados estão disponíveis no manual de integração. // Utilize setSaveCard(true) para obter o token do cartão $payment->setType(Payment::PAYMENTTYPE_CREDITCARD) - ->creditCard("123", "Visa") + ->creditCard("123", CreditCard::VISA) ->setExpirationDate("12/2018") ->setCardNumber("0000000000000001") ->setHolder("Fulano de Tal") @@ -176,6 +198,7 @@ use Cielo\API30\Ecommerce\Environment; use Cielo\API30\Ecommerce\Sale; use Cielo\API30\Ecommerce\CieloEcommerce; use Cielo\API30\Ecommerce\Payment; +use Cielo\API30\Ecommerce\CreditCard; use Cielo\API30\Ecommerce\Request\CieloRequestException; // ... @@ -197,7 +220,7 @@ $payment = $sale->payment(15700); // Crie uma instância de Credit Card utilizando os dados de teste // esses dados estão disponíveis no manual de integração $payment->setType(Payment::PAYMENTTYPE_CREDITCARD) - ->creditCard("123", "Visa") + ->creditCard("123", CreditCard::VISA) ->setCardToken("TOKEN-PREVIAMENTE-ARMAZENADO"); // Crie o pagamento na Cielo @@ -228,6 +251,7 @@ use Cielo\API30\Ecommerce\Environment; use Cielo\API30\Ecommerce\Sale; use Cielo\API30\Ecommerce\CieloEcommerce; use Cielo\API30\Ecommerce\Payment; +use Cielo\API30\Ecommerce\CreditCard; use Cielo\API30\Ecommerce\Request\CieloRequestException; // ... @@ -250,7 +274,7 @@ $payment = $sale->payment(15700); // Crie uma instância de Credit Card utilizando os dados de teste // esses dados estão disponíveis no manual de integração $payment->setType(Payment::PAYMENTTYPE_CREDITCARD) - ->creditCard("123", "Visa") + ->creditCard("123", CreditCard::VISA) ->setExpirationDate("12/2018") ->setCardNumber("0000000000000001") ->setHolder("Fulano de Tal"); @@ -283,7 +307,7 @@ use Cielo\API30\Merchant; use Cielo\API30\Ecommerce\Environment; use Cielo\API30\Ecommerce\Sale; use Cielo\API30\Ecommerce\CieloEcommerce; -use Cielo\API30\Ecommerce\Payment; +use Cielo\API30\Ecommerce\CreditCard; use Cielo\API30\Ecommerce\Request\CieloRequestException; @@ -309,7 +333,7 @@ $payment->setReturnUrl('https://localhost/test'); // Crie uma instância de Debit Card utilizando os dados de teste // esses dados estão disponíveis no manual de integração -$payment->debitCard("123", "Visa") +$payment->debitCard("123", CreditCard::VISA) ->setExpirationDate("12/2018") ->setCardNumber("0000000000000001") ->setHolder("Fulano de Tal"); @@ -412,7 +436,7 @@ use Cielo\API30\Merchant; use Cielo\API30\Ecommerce\Environment; use Cielo\API30\Ecommerce\CreditCard; use Cielo\API30\Ecommerce\CieloEcommerce; -use Cielo\API30\Ecommerce\Request\TokenizeCardRequest; +use Cielo\API30\Ecommerce\CreditCard; use Cielo\API30\Ecommerce\Request\CieloRequestException; @@ -430,7 +454,7 @@ $card->setCustomerName('Fulano de Tal'); $card->setCardNumber('0000000000000001'); $card->setHolder('Fulano de Tal'); $card->setExpirationDate('10/2020'); -$card->setBrand('Visa'); +$card->setBrand(CreditCard::VISA); try { // Configure o SDK com seu merchant e o ambiente apropriado para recuperar o cartão @@ -448,4 +472,4 @@ try { ## Manual -Para mais informações sobre a integração com a API 3.0 da Cielo, vide o manual em: [Integração API 3.0](https://developercielo.github.io/Webservice-3.0/) +Para mais informações sobre a integração com a API 3.0 da Cielo, vide o manual em: [Integração API 3.0](https://developercielo.github.io/manual/cielo-ecommerce) diff --git a/src/Cielo/API30/Ecommerce/CreditCard.php b/src/Cielo/API30/Ecommerce/CreditCard.php index caa558b..e83b4b8 100644 --- a/src/Cielo/API30/Ecommerce/CreditCard.php +++ b/src/Cielo/API30/Ecommerce/CreditCard.php @@ -9,6 +9,50 @@ */ class CreditCard implements \JsonSerializable, CieloSerializable { + /** + * Bandeira Visa + */ + const VISA = 'Visa'; + + /** + * Bandeira Mastercard + */ + const MASTERCARD = 'Master'; + + /** + * Bandeira American Express + */ + const AMEX = 'Amex'; + + /** + * Bandeira ELO + */ + const ELO = 'Elo'; + + /** + * Bandeira Aura + */ + const AURA = 'Aura'; + + /** + * Bandeira JCB + */ + const JCB = 'JCB'; + + /** + * Bandeira Diners + */ + const DINERS = 'Diners'; + + /** + * Bandeira Discover + */ + const DISCOVER = 'Discover'; + + /** + * Bandeira Hipercard + */ + const HIPERCARD = 'Hipercard'; /** @var string $cardNumber */ private $cardNumber; @@ -38,11 +82,17 @@ class CreditCard implements \JsonSerializable, CieloSerializable private $links; /** - * @return array + * @param string $json + * + * @return CreditCard */ - public function jsonSerialize() + public static function fromJson($json) { - return get_object_vars($this); + $object = \json_decode($json); + $cardToken = new CreditCard(); + $cardToken->populate($object); + + return $cardToken; } /** @@ -50,15 +100,23 @@ public function jsonSerialize() */ public function populate(\stdClass $data) { - $this->cardNumber = isset($data->CardNumber)? $data->CardNumber: null; - $this->holder = isset($data->Holder)? $data->Holder: null; - $this->expirationDate = isset($data->ExpirationDate)? $data->ExpirationDate: null; - $this->securityCode = isset($data->SecurityCode)? $data->SecurityCode: null; - $this->saveCard = isset($data->SaveCard)? !!$data->SaveCard: false; - $this->brand = isset($data->Brand)? $data->Brand: null; - $this->cardToken = isset($data->CardToken)? $data->CardToken: null; - $this->links = isset($data->Links)? $data->Links : new \stdClass(); - $this->customerName = isset($data->CustomerName)? $data->CustomerName : null; + $this->cardNumber = isset($data->CardNumber) ? $data->CardNumber : null; + $this->holder = isset($data->Holder) ? $data->Holder : null; + $this->expirationDate = isset($data->ExpirationDate) ? $data->ExpirationDate : null; + $this->securityCode = isset($data->SecurityCode) ? $data->SecurityCode : null; + $this->saveCard = isset($data->SaveCard) ? !!$data->SaveCard : false; + $this->brand = isset($data->Brand) ? $data->Brand : null; + $this->cardToken = isset($data->CardToken) ? $data->CardToken : null; + $this->links = isset($data->Links) ? $data->Links : new \stdClass(); + $this->customerName = isset($data->CustomerName) ? $data->CustomerName : null; + } + + /** + * @return array + */ + public function jsonSerialize() + { + return get_object_vars($this); } /** @@ -77,6 +135,7 @@ public function getCardNumber() public function setCardNumber($cardNumber) { $this->cardNumber = $cardNumber; + return $this; } @@ -96,6 +155,7 @@ public function getHolder() public function setHolder($holder) { $this->holder = $holder; + return $this; } @@ -115,6 +175,7 @@ public function getExpirationDate() public function setExpirationDate($expirationDate) { $this->expirationDate = $expirationDate; + return $this; } @@ -134,6 +195,7 @@ public function getSecurityCode() public function setSecurityCode($securityCode) { $this->securityCode = $securityCode; + return $this; } @@ -153,6 +215,7 @@ public function getSaveCard() public function setSaveCard($saveCard) { $this->saveCard = $saveCard; + return $this; } @@ -172,6 +235,7 @@ public function getBrand() public function setBrand($brand) { $this->brand = $brand; + return $this; } @@ -191,6 +255,7 @@ public function getCardToken() public function setCardToken($cardToken) { $this->cardToken = $cardToken; + return $this; } @@ -225,17 +290,4 @@ public function setLinks($links) { $this->links = $links; } - - /** - * @param string $json - * @return CreditCard - */ - public static function fromJson($json) - { - $object = \json_decode($json); - $cardToken = new CreditCard(); - $cardToken->populate($object); - - return $cardToken; - } } From 40dd1a00e32d1709db8ba0fd385a744d28b1ab3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Batista=20Neto?= Date: Thu, 11 Jan 2018 16:03:53 -0200 Subject: [PATCH 27/34] =?UTF-8?q?Corre=C3=A7=C3=B5es=20de=20formata=C3=A7?= =?UTF-8?q?=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 - composer.json | 26 +-- src/Cielo/API30/Ecommerce/Address.php | 25 ++- src/Cielo/API30/Ecommerce/CieloEcommerce.php | 13 +- .../API30/Ecommerce/CieloSerializable.php | 1 + src/Cielo/API30/Ecommerce/Customer.php | 14 +- src/Cielo/API30/Ecommerce/Environment.php | 7 +- src/Cielo/API30/Ecommerce/Payment.php | 157 +++++++++++------- .../API30/Ecommerce/RecurrentPayment.php | 79 ++++----- .../Ecommerce/Request/AbstractRequest.php | 24 +-- .../API30/Ecommerce/Request/CieloError.php | 3 + .../Request/CieloRequestException.php | 6 +- .../Ecommerce/Request/CreateSaleRequest.php | 8 +- .../Request/QueryRecurrentPaymentRequest.php | 8 +- .../Ecommerce/Request/QuerySaleRequest.php | 7 +- .../Ecommerce/Request/TokenizeCardRequest.php | 6 +- .../Ecommerce/Request/UpdateSaleRequest.php | 15 +- src/Cielo/API30/Ecommerce/Sale.php | 36 ++-- src/Cielo/API30/Environment.php | 1 + src/Cielo/API30/Merchant.php | 3 +- 20 files changed, 264 insertions(+), 176 deletions(-) diff --git a/README.md b/README.md index ac30069..7e96dfe 100644 --- a/README.md +++ b/README.md @@ -436,7 +436,6 @@ use Cielo\API30\Merchant; use Cielo\API30\Ecommerce\Environment; use Cielo\API30\Ecommerce\CreditCard; use Cielo\API30\Ecommerce\CieloEcommerce; -use Cielo\API30\Ecommerce\CreditCard; use Cielo\API30\Ecommerce\Request\CieloRequestException; diff --git a/composer.json b/composer.json index 7cbb89a..c392fbd 100644 --- a/composer.json +++ b/composer.json @@ -1,15 +1,15 @@ { - "autoload" : { - "psr-0" : { - "Cielo" : "src" - } - }, - "name" : "developercielo/api-3.0-php", - "description" : "Integração com a API 3.0 da Cielo", - "license" : "MIT", - "type" : "library", - "require" : { - "php" : ">=5.6" - }, - "homepage" : "https://github.com/DeveloperCielo/API-3.0-PHP" + "autoload": { + "psr-0": { + "Cielo": "src" + } + }, + "name": "developercielo/api-3.0-php", + "description": "Integração com a API 3.0 da Cielo", + "license": "MIT", + "type": "library", + "require": { + "php": ">=5.6" + }, + "homepage": "https://github.com/DeveloperCielo/API-3.0-PHP" } diff --git a/src/Cielo/API30/Ecommerce/Address.php b/src/Cielo/API30/Ecommerce/Address.php index 06ce5c9..d16e71e 100644 --- a/src/Cielo/API30/Ecommerce/Address.php +++ b/src/Cielo/API30/Ecommerce/Address.php @@ -1,4 +1,5 @@ street = isset($data->Street)? $data->Street: null; - $this->number = isset($data->Number)? $data->Number: null; - $this->complement = isset($data->Complement)? $data->Complement: null; - $this->zipCode = isset($data->ZipCode)? $data->ZipCode: null; - $this->city = isset($data->City)? $data->City: null; - $this->state = isset($data->State)? $data->State: null; - $this->country = isset($data->Country)? $data->Country: null; - $this->district = isset($data->District)? $data->District: null; + $this->street = isset($data->Street) ? $data->Street : null; + $this->number = isset($data->Number) ? $data->Number : null; + $this->complement = isset($data->Complement) ? $data->Complement : null; + $this->zipCode = isset($data->ZipCode) ? $data->ZipCode : null; + $this->city = isset($data->City) ? $data->City : null; + $this->state = isset($data->State) ? $data->State : null; + $this->country = isset($data->Country) ? $data->Country : null; + $this->district = isset($data->District) ? $data->District : null; } /** @@ -64,6 +65,7 @@ public function getDistrict() public function setDistrict($district) { $this->district = $district; + return $this; } @@ -83,6 +85,7 @@ public function getStreet() public function setStreet($street) { $this->street = $street; + return $this; } @@ -102,6 +105,7 @@ public function getNumber() public function setNumber($number) { $this->number = $number; + return $this; } @@ -121,6 +125,7 @@ public function getComplement() public function setComplement($complement) { $this->complement = $complement; + return $this; } @@ -140,6 +145,7 @@ public function getZipCode() public function setZipCode($zipCode) { $this->zipCode = $zipCode; + return $this; } @@ -159,6 +165,7 @@ public function getCity() public function setCity($city) { $this->city = $city; + return $this; } @@ -178,6 +185,7 @@ public function getState() public function setState($state) { $this->state = $state; + return $this; } @@ -197,6 +205,7 @@ public function getCountry() public function setCountry($country) { $this->country = $country; + return $this; } } diff --git a/src/Cielo/API30/Ecommerce/CieloEcommerce.php b/src/Cielo/API30/Ecommerce/CieloEcommerce.php index 8cc4d1f..3bdde5f 100644 --- a/src/Cielo/API30/Ecommerce/CieloEcommerce.php +++ b/src/Cielo/API30/Ecommerce/CieloEcommerce.php @@ -2,12 +2,12 @@ namespace Cielo\API30\Ecommerce; -use Cielo\API30\Ecommerce\Request\TokenizeCardRequest; -use Cielo\API30\Merchant; use Cielo\API30\Ecommerce\Request\CreateSaleRequest; +use Cielo\API30\Ecommerce\Request\QueryRecurrentPaymentRequest; use Cielo\API30\Ecommerce\Request\QuerySaleRequest; +use Cielo\API30\Ecommerce\Request\TokenizeCardRequest; use Cielo\API30\Ecommerce\Request\UpdateSaleRequest; -use Cielo\API30\Ecommerce\Request\QueryRecurrentPaymentRequest; +use Cielo\API30\Merchant; /** * The Cielo Ecommerce SDK front-end; @@ -35,7 +35,7 @@ public function __construct(Merchant $merchant, Environment $environment = null) $environment = Environment::production(); } - $this->merchant = $merchant; + $this->merchant = $merchant; $this->environment = $environment; } @@ -107,7 +107,7 @@ public function getRecurrentPayment($recurrentPaymentId) /** * Cancel a Sale on Cielo by paymentId and speficying the amount * - * @param string $paymentId + * @param string $paymentId * The paymentId to be queried * @param integer $amount * Order value in cents @@ -133,7 +133,7 @@ public function cancelSale($paymentId, $amount = null) * Capture a Sale on Cielo by paymentId and specifying the amount and the * serviceTaxAmount * - * @param string $paymentId + * @param string $paymentId * The paymentId to be captured * @param integer $amount * Amount of the authorization to be captured @@ -162,6 +162,7 @@ public function captureSale($paymentId, $amount = null, $serviceTaxAmount = null /** * @param CreditCard $card + * * @return CreditCard */ public function tokenizeCard(CreditCard $card) diff --git a/src/Cielo/API30/Ecommerce/CieloSerializable.php b/src/Cielo/API30/Ecommerce/CieloSerializable.php index c64edd4..05d13a7 100644 --- a/src/Cielo/API30/Ecommerce/CieloSerializable.php +++ b/src/Cielo/API30/Ecommerce/CieloSerializable.php @@ -1,4 +1,5 @@ name = isset($data->Name) ? $data->Name : null; - $this->email = isset($data->Email) ? $data->Email : null; + $this->name = isset($data->Name) ? $data->Name : null; + $this->email = isset($data->Email) ? $data->Email : null; $this->birthDate = isset($data->Birthdate) ? $data->Birthdate : null; - $this->identity = isset($data->Identity) ? $data->Identity : null; + $this->identity = isset($data->Identity) ? $data->Identity : null; $this->identityType = isset($data->IdentityType) ? $data->IdentityType : null; if (isset($data->Address)) { @@ -104,6 +105,7 @@ public function getName() public function setName($name) { $this->name = $name; + return $this; } @@ -123,6 +125,7 @@ public function getEmail() public function setEmail($email) { $this->email = $email; + return $this; } @@ -142,6 +145,7 @@ public function getBirthDate() public function setBirthDate($birthDate) { $this->birthDate = $birthDate; + return $this; } @@ -161,6 +165,7 @@ public function getIdentity() public function setIdentity($identity) { $this->identity = $identity; + return $this; } @@ -180,6 +185,7 @@ public function getIdentityType() public function setIdentityType($identityType) { $this->identityType = $identityType; + return $this; } @@ -199,6 +205,7 @@ public function getAddress() public function setAddress($address) { $this->address = $address; + return $this; } @@ -218,6 +225,7 @@ public function getDeliveryAddress() public function setDeliveryAddress($deliveryAddress) { $this->deliveryAddress = $deliveryAddress; + return $this; } } diff --git a/src/Cielo/API30/Ecommerce/Environment.php b/src/Cielo/API30/Ecommerce/Environment.php index b2c3ba4..1b1334c 100644 --- a/src/Cielo/API30/Ecommerce/Environment.php +++ b/src/Cielo/API30/Ecommerce/Environment.php @@ -1,4 +1,5 @@ api = $api; + $this->api = $api; $this->apiQuery = $apiQuery; } @@ -29,7 +30,7 @@ private function __construct($api, $apiQuery) */ public static function sandbox() { - $api = 'https://apisandbox.cieloecommerce.cielo.com.br/'; + $api = 'https://apisandbox.cieloecommerce.cielo.com.br/'; $apiQuery = 'https://apiquerysandbox.cieloecommerce.cielo.com.br/'; return new Environment($api, $apiQuery); @@ -40,7 +41,7 @@ public static function sandbox() */ public static function production() { - $api = 'https://api.cieloecommerce.cielo.com.br/'; + $api = 'https://api.cieloecommerce.cielo.com.br/'; $apiQuery = 'https://apiquery.cieloecommerce.cielo.com.br/'; return new Environment($api, $apiQuery); diff --git a/src/Cielo/API30/Ecommerce/Payment.php b/src/Cielo/API30/Ecommerce/Payment.php index 61404cb..574f88a 100644 --- a/src/Cielo/API30/Ecommerce/Payment.php +++ b/src/Cielo/API30/Ecommerce/Payment.php @@ -1,4 +1,5 @@ populate(json_decode($json)); + + return $payment; } /** @@ -133,12 +139,12 @@ public function jsonSerialize() public function populate(\stdClass $data) { - $this->serviceTaxAmount = isset($data->ServiceTaxAmount)? $data->ServiceTaxAmount: null; - $this->installments = isset($data->Installments)? $data->Installments: null; - $this->interest = isset($data->Interest)? $data->Interest: null; - $this->capture = isset($data->Capture)? ! ! $data->Capture: false; - $this->authenticate = isset($data->Authenticate)? ! ! $data->Authenticate: false; - $this->recurrent = isset($data->Recurrent)? ! ! $data->Recurrent: false; + $this->serviceTaxAmount = isset($data->ServiceTaxAmount) ? $data->ServiceTaxAmount : null; + $this->installments = isset($data->Installments) ? $data->Installments : null; + $this->interest = isset($data->Interest) ? $data->Interest : null; + $this->capture = isset($data->Capture) ? !!$data->Capture : false; + $this->authenticate = isset($data->Authenticate) ? !!$data->Authenticate : false; + $this->recurrent = isset($data->Recurrent) ? !!$data->Recurrent : false; if (isset($data->RecurrentPayment)) { $this->recurrentPayment = new RecurrentPayment(false); @@ -155,52 +161,47 @@ public function populate(\stdClass $data) $this->debitCard->populate($data->DebitCard); } - $this->expirationDate = isset($data->ExpirationDate)?$data->ExpirationDate: null; - $this->url = isset($data->Url)?$data->Url: null; - $this->boletoNumber = isset($data->BoletoNumber)? $data->BoletoNumber: null; - $this->barCodeNumber = isset($data->BarCodeNumber)?$data->BarCodeNumber: null; - $this->digitableLine = isset($data->DigitableLine)?$data->DigitableLine: null; - $this->address = isset($data->Address)?$data->Address: null; - - $this->authenticationUrl = isset($data->AuthenticationUrl)? $data->AuthenticationUrl: null; - $this->tid = isset($data->Tid)? $data->Tid: null; - $this->proofOfSale = isset($data->ProofOfSale)? $data->ProofOfSale: null; - $this->authorizationCode = isset($data->AuthorizationCode)? $data->AuthorizationCode: null; - $this->softDescriptor = isset($data->SoftDescriptor)? $data->SoftDescriptor: null; - $this->provider = isset($data->Provider)? $data->Provider: null; - $this->paymentId = isset($data->PaymentId)? $data->PaymentId: null; - $this->type = isset($data->Type)? $data->Type: null; - $this->amount = isset($data->Amount)? $data->Amount: null; - $this->receivedDate = isset($data->ReceivedDate)? $data->ReceivedDate: null; - $this->capturedAmount = isset($data->CapturedAmount)? $data->CapturedAmount: null; - $this->capturedDate = isset($data->CapturedDate)? $data->CapturedDate: null; - $this->voidedAmount = isset($data->VoidedAmount)? $data->VoidedAmount: null; - $this->voidedDate = isset($data->VoidedDate)? $data->VoidedDate: null; - $this->currency = isset($data->Currency)? $data->Currency: null; - $this->country = isset($data->Country)? $data->Country: null; - $this->returnCode = isset($data->ReturnCode)? $data->ReturnCode: null; - $this->returnMessage = isset($data->ReturnMessage)? $data->ReturnMessage: null; - $this->status = isset($data->Status)? $data->Status: null; - - $this->links = isset($data->Links)? $data->Links: []; - - $this->assignor = isset($data->Assignor)? $data->Assignor: null; - $this->demonstrative = isset($data->Demonstrative)? $data->Demonstrative: null; - $this->identification = isset($data->Identification)? $data->Identification: null; - $this->instructions = isset($data->Instructions)? $data->Instructions: null; + $this->expirationDate = isset($data->ExpirationDate) ? $data->ExpirationDate : null; + $this->url = isset($data->Url) ? $data->Url : null; + $this->boletoNumber = isset($data->BoletoNumber) ? $data->BoletoNumber : null; + $this->barCodeNumber = isset($data->BarCodeNumber) ? $data->BarCodeNumber : null; + $this->digitableLine = isset($data->DigitableLine) ? $data->DigitableLine : null; + $this->address = isset($data->Address) ? $data->Address : null; + + $this->authenticationUrl = isset($data->AuthenticationUrl) ? $data->AuthenticationUrl : null; + $this->tid = isset($data->Tid) ? $data->Tid : null; + $this->proofOfSale = isset($data->ProofOfSale) ? $data->ProofOfSale : null; + $this->authorizationCode = isset($data->AuthorizationCode) ? $data->AuthorizationCode : null; + $this->softDescriptor = isset($data->SoftDescriptor) ? $data->SoftDescriptor : null; + $this->provider = isset($data->Provider) ? $data->Provider : null; + $this->paymentId = isset($data->PaymentId) ? $data->PaymentId : null; + $this->type = isset($data->Type) ? $data->Type : null; + $this->amount = isset($data->Amount) ? $data->Amount : null; + $this->receivedDate = isset($data->ReceivedDate) ? $data->ReceivedDate : null; + $this->capturedAmount = isset($data->CapturedAmount) ? $data->CapturedAmount : null; + $this->capturedDate = isset($data->CapturedDate) ? $data->CapturedDate : null; + $this->voidedAmount = isset($data->VoidedAmount) ? $data->VoidedAmount : null; + $this->voidedDate = isset($data->VoidedDate) ? $data->VoidedDate : null; + $this->currency = isset($data->Currency) ? $data->Currency : null; + $this->country = isset($data->Country) ? $data->Country : null; + $this->returnCode = isset($data->ReturnCode) ? $data->ReturnCode : null; + $this->returnMessage = isset($data->ReturnMessage) ? $data->ReturnMessage : null; + $this->status = isset($data->Status) ? $data->Status : null; + + $this->links = isset($data->Links) ? $data->Links : []; + + $this->assignor = isset($data->Assignor) ? $data->Assignor : null; + $this->demonstrative = isset($data->Demonstrative) ? $data->Demonstrative : null; + $this->identification = isset($data->Identification) ? $data->Identification : null; + $this->instructions = isset($data->Instructions) ? $data->Instructions : null; } /** - * @param $json - * - * @return Payment + * @return array */ - public static function fromJson($json) + public function jsonSerialize() { - $payment = new Payment(); - $payment->populate(json_decode($json)); - - return $payment; + return get_object_vars($this); } /** @@ -209,11 +210,12 @@ public static function fromJson($json) * * @return CreditCard */ - private function newCard($securityCode, $brand) + public function creditCard($securityCode, $brand) { - $card = new CreditCard(); - $card->setSecurityCode($securityCode); - $card->setBrand($brand); + $card = $this->newCard($securityCode, $brand); + + $this->setType(self::PAYMENTTYPE_CREDITCARD); + $this->setCreditCard($card); return $card; } @@ -224,12 +226,11 @@ private function newCard($securityCode, $brand) * * @return CreditCard */ - public function creditCard($securityCode, $brand) + private function newCard($securityCode, $brand) { - $card = $this->newCard($securityCode, $brand); - - $this->setType(self::PAYMENTTYPE_CREDITCARD); - $this->setCreditCard($card); + $card = new CreditCard(); + $card->setSecurityCode($securityCode); + $card->setBrand($brand); return $card; } @@ -280,6 +281,7 @@ public function getServiceTaxAmount() public function setServiceTaxAmount($serviceTaxAmount) { $this->serviceTaxAmount = $serviceTaxAmount; + return $this; } @@ -299,6 +301,7 @@ public function getInstallments() public function setInstallments($installments) { $this->installments = $installments; + return $this; } @@ -318,6 +321,7 @@ public function getInterest() public function setInterest($interest) { $this->interest = $interest; + return $this; } @@ -337,6 +341,7 @@ public function getCapture() public function setCapture($capture) { $this->capture = $capture; + return $this; } @@ -356,6 +361,7 @@ public function getAuthenticate() public function setAuthenticate($authenticate) { $this->authenticate = $authenticate; + return $this; } @@ -375,6 +381,7 @@ public function getRecurrent() public function setRecurrent($recurrent) { $this->recurrent = $recurrent; + return $this; } @@ -394,6 +401,7 @@ public function getRecurrentPayment() public function setRecurrentPayment($recurrentPayment) { $this->recurrentPayment = $recurrentPayment; + return $this; } @@ -413,6 +421,7 @@ public function getCreditCard() public function setCreditCard(CreditCard $creditCard) { $this->creditCard = $creditCard; + return $this; } @@ -432,6 +441,7 @@ public function getDebitCard() public function setDebitCard($debitCard) { $this->debitCard = $debitCard; + return $this; } @@ -451,6 +461,7 @@ public function getAuthenticationUrl() public function setAuthenticationUrl($authenticationUrl) { $this->authenticationUrl = $authenticationUrl; + return $this; } @@ -470,6 +481,7 @@ public function getTid() public function setTid($tid) { $this->tid = $tid; + return $this; } @@ -489,6 +501,7 @@ public function getProofOfSale() public function setProofOfSale($proofOfSale) { $this->proofOfSale = $proofOfSale; + return $this; } @@ -508,6 +521,7 @@ public function getAuthorizationCode() public function setAuthorizationCode($authorizationCode) { $this->authorizationCode = $authorizationCode; + return $this; } @@ -527,6 +541,7 @@ public function getSoftDescriptor() public function setSoftDescriptor($softDescriptor) { $this->softDescriptor = $softDescriptor; + return $this; } @@ -546,6 +561,7 @@ public function getReturnUrl() public function setReturnUrl($returnUrl) { $this->returnUrl = $returnUrl; + return $this; } @@ -565,6 +581,7 @@ public function getProvider() public function setProvider($provider) { $this->provider = $provider; + return $this; } @@ -584,6 +601,7 @@ public function getPaymentId() public function setPaymentId($paymentId) { $this->paymentId = $paymentId; + return $this; } @@ -603,6 +621,7 @@ public function getType() public function setType($type) { $this->type = $type; + return $this; } @@ -622,6 +641,7 @@ public function getAmount() public function setAmount($amount) { $this->amount = $amount; + return $this; } @@ -641,6 +661,7 @@ public function getReceivedDate() public function setReceivedDate($receivedDate) { $this->receivedDate = $receivedDate; + return $this; } @@ -660,6 +681,7 @@ public function getCapturedAmount() public function setCapturedAmount($capturedAmount) { $this->capturedAmount = $capturedAmount; + return $this; } @@ -679,6 +701,7 @@ public function getCapturedDate() public function setCapturedDate($capturedDate) { $this->capturedDate = $capturedDate; + return $this; } @@ -698,6 +721,7 @@ public function getVoidedAmount() public function setVoidedAmount($voidedAmount) { $this->voidedAmount = $voidedAmount; + return $this; } @@ -717,6 +741,7 @@ public function getVoidedDate() public function setVoidedDate($voidedDate) { $this->voidedDate = $voidedDate; + return $this; } @@ -736,6 +761,7 @@ public function getCurrency() public function setCurrency($currency) { $this->currency = $currency; + return $this; } @@ -755,6 +781,7 @@ public function getCountry() public function setCountry($country) { $this->country = $country; + return $this; } @@ -774,6 +801,7 @@ public function getReturnCode() public function setReturnCode($returnCode) { $this->returnCode = $returnCode; + return $this; } @@ -793,6 +821,7 @@ public function getReturnMessage() public function setReturnMessage($returnMessage) { $this->returnMessage = $returnMessage; + return $this; } @@ -812,6 +841,7 @@ public function getStatus() public function setStatus($status) { $this->status = $status; + return $this; } @@ -831,6 +861,7 @@ public function getLinks() public function setLinks($links) { $this->links = $links; + return $this; } @@ -850,6 +881,7 @@ public function getExtraDataCollection() public function setExtraDataCollection($extraDataCollection) { $this->extraDataCollection = $extraDataCollection; + return $this; } @@ -869,6 +901,7 @@ public function getExpirationDate() public function setExpirationDate($expirationDate) { $this->expirationDate = $expirationDate; + return $this; } @@ -888,6 +921,7 @@ public function getUrl() public function setUrl($url) { $this->url = $url; + return $this; } @@ -907,6 +941,7 @@ public function getNumber() public function setNumber($number) { $this->number = $number; + return $this; } @@ -926,6 +961,7 @@ public function getBoletoNumber() public function setBoletoNumber($boletoNumber) { $this->boletoNumber = $boletoNumber; + return $this; } @@ -945,6 +981,7 @@ public function getBarCodeNumber() public function setBarCodeNumber($barCodeNumber) { $this->barCodeNumber = $barCodeNumber; + return $this; } @@ -964,6 +1001,7 @@ public function getDigitableLine() public function setDigitableLine($digitableLine) { $this->digitableLine = $digitableLine; + return $this; } @@ -983,6 +1021,7 @@ public function getAddress() public function setAddress($address) { $this->address = $address; + return $this; } diff --git a/src/Cielo/API30/Ecommerce/RecurrentPayment.php b/src/Cielo/API30/Ecommerce/RecurrentPayment.php index b51fef8..088ccf8 100644 --- a/src/Cielo/API30/Ecommerce/RecurrentPayment.php +++ b/src/Cielo/API30/Ecommerce/RecurrentPayment.php @@ -1,4 +1,5 @@ setAuthorizeNow($authorizeNow); } - /** - * @return array - */ - public function jsonSerialize() - { - return get_object_vars($this); - } - - /** - * @param \stdClass $data - */ - public function populate(\stdClass $data) - { - $this->authorizeNow = isset($data->AuthorizeNow)? !!$data->AuthorizeNow: false; - $this->recurrentPaymentId = isset($data->RecurrentPaymentId)? $data->RecurrentPaymentId: null; - $this->nextRecurrency = isset($data->NextRecurrency)? $data->NextRecurrency: null; - $this->startDate = isset($data->StartDate)? $data->StartDate: null; - $this->endDate = isset($data->EndDate)? $data->EndDate: null; - $this->interval = isset($data->Interval)? $data->Interval: null; - - $this->amount = isset($data->Amount)? $data->Amount: null; - $this->country = isset($data->Country)? $data->Country: null; - $this->createDate = isset($data->CreateDate)? $data->CreateDate: null; - $this->currency = isset($data->Currency)? $data->Currency: null; - $this->currentRecurrencyTry = isset($data->CurrentRecurrencyTry)? $data->CurrentRecurrencyTry: null; - $this->provider = isset($data->Provider)? $data->Provider: null; - $this->recurrencyDay = isset($data->RecurrencyDay)? $data->RecurrencyDay: null; - $this->successfulRecurrences = isset($data->SuccessfulRecurrences)? $data->SuccessfulRecurrences: null; - - $this->links = isset($data->Links)? $data->Links: []; - $this->recurrentTransactions = isset($data->RecurrentTransactions)? $data->RecurrentTransactions: []; - - $this->reasonCode = isset($data->ReasonCode)? $data->ReasonCode: null; - $this->reasonMessage = isset($data->ReasonMessage)? $data->ReasonMessage: null; - $this->status = isset($data->Status)? $data->Status: null; - } - /** * @param $json * @@ -104,6 +68,43 @@ public static function fromJson($json) return $recurrentPayment; } + /** + * @param \stdClass $data + */ + public function populate(\stdClass $data) + { + $this->authorizeNow = isset($data->AuthorizeNow) ? !!$data->AuthorizeNow : false; + $this->recurrentPaymentId = isset($data->RecurrentPaymentId) ? $data->RecurrentPaymentId : null; + $this->nextRecurrency = isset($data->NextRecurrency) ? $data->NextRecurrency : null; + $this->startDate = isset($data->StartDate) ? $data->StartDate : null; + $this->endDate = isset($data->EndDate) ? $data->EndDate : null; + $this->interval = isset($data->Interval) ? $data->Interval : null; + + $this->amount = isset($data->Amount) ? $data->Amount : null; + $this->country = isset($data->Country) ? $data->Country : null; + $this->createDate = isset($data->CreateDate) ? $data->CreateDate : null; + $this->currency = isset($data->Currency) ? $data->Currency : null; + $this->currentRecurrencyTry = isset($data->CurrentRecurrencyTry) ? $data->CurrentRecurrencyTry : null; + $this->provider = isset($data->Provider) ? $data->Provider : null; + $this->recurrencyDay = isset($data->RecurrencyDay) ? $data->RecurrencyDay : null; + $this->successfulRecurrences = isset($data->SuccessfulRecurrences) ? $data->SuccessfulRecurrences : null; + + $this->links = isset($data->Links) ? $data->Links : []; + $this->recurrentTransactions = isset($data->RecurrentTransactions) ? $data->RecurrentTransactions : []; + + $this->reasonCode = isset($data->ReasonCode) ? $data->ReasonCode : null; + $this->reasonMessage = isset($data->ReasonMessage) ? $data->ReasonMessage : null; + $this->status = isset($data->Status) ? $data->Status : null; + } + + /** + * @return array + */ + public function jsonSerialize() + { + return get_object_vars($this); + } + /** * @return mixed */ @@ -224,6 +225,7 @@ public function getAuthorizeNow() public function setAuthorizeNow($authorizeNow) { $this->authorizeNow = $authorizeNow; + return $this; } @@ -243,6 +245,7 @@ public function getStartDate() public function setStartDate($startDate) { $this->startDate = $startDate; + return $this; } @@ -262,6 +265,7 @@ public function getEndDate() public function setEndDate($endDate) { $this->endDate = $endDate; + return $this; } @@ -281,6 +285,7 @@ public function getInterval() public function setInterval($interval) { $this->interval = $interval; + return $this; } } diff --git a/src/Cielo/API30/Ecommerce/Request/AbstractRequest.php b/src/Cielo/API30/Ecommerce/Request/AbstractRequest.php index 191daaa..5f97f40 100644 --- a/src/Cielo/API30/Ecommerce/Request/AbstractRequest.php +++ b/src/Cielo/API30/Ecommerce/Request/AbstractRequest.php @@ -32,15 +32,8 @@ public function __construct(Merchant $merchant) public abstract function execute($param); /** - * @param $json - * - * @return mixed - */ - protected abstract function unserialize($json); - - /** - * @param $method - * @param $url + * @param $method + * @param $url * @param \JsonSerializable|null $content * * @return mixed @@ -85,7 +78,7 @@ protected function sendRequest($method, $url, \JsonSerializable $content = null) curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); - $response = curl_exec($curl); + $response = curl_exec($curl); $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); if (curl_errno($curl)) { @@ -116,11 +109,11 @@ protected function readResponse($statusCode, $responseBody) break; case 400: $exception = null; - $response = json_decode($responseBody); + $response = json_decode($responseBody); foreach ($response as $error) { $cieloError = new CieloError($error->Message, $error->Code); - $exception = new CieloRequestException('Request Error', $statusCode, $exception); + $exception = new CieloRequestException('Request Error', $statusCode, $exception); $exception->setCieloError($cieloError); } @@ -133,4 +126,11 @@ protected function readResponse($statusCode, $responseBody) return $unserialized; } + + /** + * @param $json + * + * @return mixed + */ + protected abstract function unserialize($json); } diff --git a/src/Cielo/API30/Ecommerce/Request/CieloError.php b/src/Cielo/API30/Ecommerce/Request/CieloError.php index e2ccd7b..1d4b20a 100644 --- a/src/Cielo/API30/Ecommerce/Request/CieloError.php +++ b/src/Cielo/API30/Ecommerce/Request/CieloError.php @@ -1,4 +1,5 @@ code = $code; + return $this; } @@ -60,6 +62,7 @@ public function getMessage() public function setMessage($message) { $this->message = $message; + return $this; } } diff --git a/src/Cielo/API30/Ecommerce/Request/CieloRequestException.php b/src/Cielo/API30/Ecommerce/Request/CieloRequestException.php index db4adf6..640f87e 100644 --- a/src/Cielo/API30/Ecommerce/Request/CieloRequestException.php +++ b/src/Cielo/API30/Ecommerce/Request/CieloRequestException.php @@ -1,4 +1,5 @@ cieloError = $cieloError; + return $this; } } diff --git a/src/Cielo/API30/Ecommerce/Request/CreateSaleRequest.php b/src/Cielo/API30/Ecommerce/Request/CreateSaleRequest.php index cae9945..7718c8b 100644 --- a/src/Cielo/API30/Ecommerce/Request/CreateSaleRequest.php +++ b/src/Cielo/API30/Ecommerce/Request/CreateSaleRequest.php @@ -1,10 +1,10 @@ merchant = $merchant; + $this->merchant = $merchant; $this->environment = $environment; } diff --git a/src/Cielo/API30/Ecommerce/Request/UpdateSaleRequest.php b/src/Cielo/API30/Ecommerce/Request/UpdateSaleRequest.php index df82667..43b9b80 100644 --- a/src/Cielo/API30/Ecommerce/Request/UpdateSaleRequest.php +++ b/src/Cielo/API30/Ecommerce/Request/UpdateSaleRequest.php @@ -1,9 +1,10 @@ environment = $environment; - $this->type = $type; + $this->type = $type; } /** * @param $paymentId * * @return null + * @throws \Cielo\API30\Ecommerce\Request\CieloRequestException + * @throws \RuntimeException */ public function execute($paymentId) { - $url = $this->environment->getApiUrl() . '1/sales/' . $paymentId . '/' . $this->type; + $url = $this->environment->getApiUrl() . '1/sales/' . $paymentId . '/' . $this->type; $params = []; if ($this->amount != null) { @@ -85,6 +88,7 @@ public function getServiceTaxAmount() public function setServiceTaxAmount($serviceTaxAmount) { $this->serviceTaxAmount = $serviceTaxAmount; + return $this; } @@ -104,6 +108,7 @@ public function getAmount() public function setAmount($amount) { $this->amount = $amount; + return $this; } } diff --git a/src/Cielo/API30/Ecommerce/Sale.php b/src/Cielo/API30/Ecommerce/Sale.php index b3c2b97..07639e7 100644 --- a/src/Cielo/API30/Ecommerce/Sale.php +++ b/src/Cielo/API30/Ecommerce/Sale.php @@ -1,4 +1,5 @@ populate($object); + + return $sale; } /** @@ -41,12 +49,12 @@ public function populate(\stdClass $data) $dataProps = get_object_vars($data); if (isset($dataProps['Customer'])) { - $this->customer = new \Cielo\API30\Ecommerce\Customer(); + $this->customer = new Customer(); $this->customer->populate($data->Customer); } if (isset($dataProps['Payment'])) { - $this->payment = new \Cielo\API30\Ecommerce\Payment(); + $this->payment = new Payment(); $this->payment->populate($data->Payment); } @@ -56,18 +64,11 @@ public function populate(\stdClass $data) } /** - * @param $json - * - * @return Sale + * @return array */ - public static function fromJson($json) + public function jsonSerialize() { - $object = json_decode($json); - - $sale = new Sale(); - $sale->populate($object); - - return $sale; + return get_object_vars($this); } /** @@ -85,7 +86,7 @@ public function customer($name) } /** - * @param $amount + * @param $amount * @param int $installments * * @return Payment @@ -115,6 +116,7 @@ public function getMerchantOrderId() public function setMerchantOrderId($merchantOrderId) { $this->merchantOrderId = $merchantOrderId; + return $this; } @@ -134,6 +136,7 @@ public function getCustomer() public function setCustomer(Customer $customer) { $this->customer = $customer; + return $this; } @@ -151,6 +154,7 @@ public function getPayment() public function setPayment(Payment $payment) { $this->payment = $payment; + return $this; } } diff --git a/src/Cielo/API30/Environment.php b/src/Cielo/API30/Environment.php index d885e66..92846ad 100644 --- a/src/Cielo/API30/Environment.php +++ b/src/Cielo/API30/Environment.php @@ -1,4 +1,5 @@ id = $id; + $this->id = $id; $this->key = $key; } From 0d442fc13fff22a2304e0f182bb92d396fc2b65a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Batista=20Neto?= Date: Wed, 18 Sep 2019 13:13:53 -0300 Subject: [PATCH 28/34] Adiciona possibilidade de logs --- composer.json | 8 +++- src/Cielo/API30/Ecommerce/CieloEcommerce.php | 39 ++++++++++-------- .../Ecommerce/Request/AbstractRequest.php | 41 +++++++++++++++---- .../Ecommerce/Request/CreateSaleRequest.php | 18 ++++---- .../Request/QueryRecurrentPaymentRequest.php | 18 ++++---- .../Ecommerce/Request/QuerySaleRequest.php | 18 ++++---- .../Ecommerce/Request/TokenizeCardRequest.php | 18 ++++---- .../Ecommerce/Request/UpdateSaleRequest.php | 20 +++++---- 8 files changed, 114 insertions(+), 66 deletions(-) diff --git a/composer.json b/composer.json index c392fbd..60c692e 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,13 @@ "license": "MIT", "type": "library", "require": { - "php": ">=5.6" + "php": ">=5.6", + "ext-curl": "*", + "ext-json": "*", + "psr/log":"^1.1" + }, + "suggest": { + "monolog/monolog": "Allows more advanced logging of the application flow" }, "homepage": "https://github.com/DeveloperCielo/API-3.0-PHP" } diff --git a/src/Cielo/API30/Ecommerce/CieloEcommerce.php b/src/Cielo/API30/Ecommerce/CieloEcommerce.php index 3bdde5f..f297d73 100644 --- a/src/Cielo/API30/Ecommerce/CieloEcommerce.php +++ b/src/Cielo/API30/Ecommerce/CieloEcommerce.php @@ -8,6 +8,7 @@ use Cielo\API30\Ecommerce\Request\TokenizeCardRequest; use Cielo\API30\Ecommerce\Request\UpdateSaleRequest; use Cielo\API30\Merchant; +use Psr\Log\LoggerInterface; /** * The Cielo Ecommerce SDK front-end; @@ -19,17 +20,20 @@ class CieloEcommerce private $environment; - /** - * Create an instance of CieloEcommerce choosing the environment where the - * requests will be send - * - * @param Merchant $merchant - * The merchant credentials - * @param Environment environment - * The environment: {@link Environment::production()} or - * {@link Environment::sandbox()} - */ - public function __construct(Merchant $merchant, Environment $environment = null) + private $logger; + + /** + * Create an instance of CieloEcommerce choosing the environment where the + * requests will be send + * + * @param Merchant $merchant + * The merchant credentials + * @param Environment environment + * The environment: {@link Environment::production()} or + * {@link Environment::sandbox()} + * @param LoggerInterface|null $logger + */ + public function __construct(Merchant $merchant, Environment $environment = null, LoggerInterface $logger = null) { if ($environment == null) { $environment = Environment::production(); @@ -37,6 +41,7 @@ public function __construct(Merchant $merchant, Environment $environment = null) $this->merchant = $merchant; $this->environment = $environment; + $this->logger = $logger; } /** @@ -56,7 +61,7 @@ public function __construct(Merchant $merchant, Environment $environment = null) */ public function createSale(Sale $sale) { - $createSaleRequest = new CreateSaleRequest($this->merchant, $this->environment); + $createSaleRequest = new CreateSaleRequest($this->merchant, $this->environment, $this->logger); return $createSaleRequest->execute($sale); } @@ -77,7 +82,7 @@ public function createSale(Sale $sale) */ public function getSale($paymentId) { - $querySaleRequest = new QuerySaleRequest($this->merchant, $this->environment); + $querySaleRequest = new QuerySaleRequest($this->merchant, $this->environment, $this->logger); return $querySaleRequest->execute($paymentId); } @@ -99,7 +104,7 @@ public function getSale($paymentId) */ public function getRecurrentPayment($recurrentPaymentId) { - $queryRecurrentPaymentRequest = new queryRecurrentPaymentRequest($this->merchant, $this->environment); + $queryRecurrentPaymentRequest = new queryRecurrentPaymentRequest($this->merchant, $this->environment, $this->logger); return $queryRecurrentPaymentRequest->execute($recurrentPaymentId); } @@ -122,7 +127,7 @@ public function getRecurrentPayment($recurrentPaymentId) */ public function cancelSale($paymentId, $amount = null) { - $updateSaleRequest = new UpdateSaleRequest('void', $this->merchant, $this->environment); + $updateSaleRequest = new UpdateSaleRequest('void', $this->merchant, $this->environment, $this->logger); $updateSaleRequest->setAmount($amount); @@ -152,7 +157,7 @@ public function cancelSale($paymentId, $amount = null) */ public function captureSale($paymentId, $amount = null, $serviceTaxAmount = null) { - $updateSaleRequest = new UpdateSaleRequest('capture', $this->merchant, $this->environment); + $updateSaleRequest = new UpdateSaleRequest('capture', $this->merchant, $this->environment, $this->logger); $updateSaleRequest->setAmount($amount); $updateSaleRequest->setServiceTaxAmount($serviceTaxAmount); @@ -167,7 +172,7 @@ public function captureSale($paymentId, $amount = null, $serviceTaxAmount = null */ public function tokenizeCard(CreditCard $card) { - $tokenizeCardRequest = new TokenizeCardRequest($this->merchant, $this->environment); + $tokenizeCardRequest = new TokenizeCardRequest($this->merchant, $this->environment, $this->logger); return $tokenizeCardRequest->execute($card); } diff --git a/src/Cielo/API30/Ecommerce/Request/AbstractRequest.php b/src/Cielo/API30/Ecommerce/Request/AbstractRequest.php index 5f97f40..71e7643 100644 --- a/src/Cielo/API30/Ecommerce/Request/AbstractRequest.php +++ b/src/Cielo/API30/Ecommerce/Request/AbstractRequest.php @@ -3,6 +3,7 @@ namespace Cielo\API30\Ecommerce\Request; use Cielo\API30\Merchant; +use Psr\Log\LoggerInterface; /** * Class AbstractSaleRequest @@ -13,15 +14,18 @@ abstract class AbstractRequest { private $merchant; - - /** - * AbstractSaleRequest constructor. - * - * @param Merchant $merchant - */ - public function __construct(Merchant $merchant) + private $logger; + + /** + * AbstractSaleRequest constructor. + * + * @param Merchant $merchant + * @param LoggerInterface|null $logger + */ + public function __construct(Merchant $merchant, LoggerInterface $logger = null) { $this->merchant = $merchant; + $this->logger = $logger; } /** @@ -78,9 +82,32 @@ protected function sendRequest($method, $url, \JsonSerializable $content = null) curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); + if ($this->logger !== null) { + $this->logger->debug( + trim( + sprintf("Requisição\n%s %s\n%s\n\n%s\n\n", + $method, $url, + implode("\n", $headers), + preg_replace('/("cardnumber"):"([^"]{6})[^"]+([^"]{4})"/i', '$1:"$2******$3"', json_encode($content)) + ) + ) + ); + } + $response = curl_exec($curl); $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); + if ($this->logger !== null) { + $this->logger->debug( + trim( + sprintf("Resposta\n%d\n\n%s\n\n", + $statusCode, + $response + ) + ) + ); + } + if (curl_errno($curl)) { throw new \RuntimeException('Curl error: ' . curl_error($curl)); } diff --git a/src/Cielo/API30/Ecommerce/Request/CreateSaleRequest.php b/src/Cielo/API30/Ecommerce/Request/CreateSaleRequest.php index 7718c8b..f3c9659 100644 --- a/src/Cielo/API30/Ecommerce/Request/CreateSaleRequest.php +++ b/src/Cielo/API30/Ecommerce/Request/CreateSaleRequest.php @@ -5,6 +5,7 @@ use Cielo\API30\Ecommerce\Sale; use Cielo\API30\Environment; use Cielo\API30\Merchant; +use Psr\Log\LoggerInterface; /** * Class CreateSaleRequest @@ -16,15 +17,16 @@ class CreateSaleRequest extends AbstractRequest private $environment; - /** - * CreateSaleRequest constructor. - * - * @param Merchant $merchant - * @param Environment $environment - */ - public function __construct(Merchant $merchant, Environment $environment) + /** + * CreateSaleRequest constructor. + * + * @param Merchant $merchant + * @param Environment $environment + * @param LoggerInterface|null $logger + */ + public function __construct(Merchant $merchant, Environment $environment, LoggerInterface $logger = null) { - parent::__construct($merchant); + parent::__construct($merchant, $logger); $this->environment = $environment; } diff --git a/src/Cielo/API30/Ecommerce/Request/QueryRecurrentPaymentRequest.php b/src/Cielo/API30/Ecommerce/Request/QueryRecurrentPaymentRequest.php index 70d38ec..8309772 100644 --- a/src/Cielo/API30/Ecommerce/Request/QueryRecurrentPaymentRequest.php +++ b/src/Cielo/API30/Ecommerce/Request/QueryRecurrentPaymentRequest.php @@ -5,6 +5,7 @@ use Cielo\API30\Ecommerce\RecurrentPayment; use Cielo\API30\Environment; use Cielo\API30\Merchant; +use Psr\Log\LoggerInterface; /** * Class QueryRecurrentPaymentRequest @@ -16,15 +17,16 @@ class QueryRecurrentPaymentRequest extends AbstractRequest private $environment; - /** - * QueryRecurrentPaymentRequest constructor. - * - * @param Merchant $merchant - * @param Environment $environment - */ - public function __construct(Merchant $merchant, Environment $environment) + /** + * QueryRecurrentPaymentRequest constructor. + * + * @param Merchant $merchant + * @param Environment $environment + * @param LoggerInterface|null $logger + */ + public function __construct(Merchant $merchant, Environment $environment, LoggerInterface $logger = null) { - parent::__construct($merchant); + parent::__construct($merchant, $logger); $this->environment = $environment; } diff --git a/src/Cielo/API30/Ecommerce/Request/QuerySaleRequest.php b/src/Cielo/API30/Ecommerce/Request/QuerySaleRequest.php index 3bbfe23..e7953b2 100644 --- a/src/Cielo/API30/Ecommerce/Request/QuerySaleRequest.php +++ b/src/Cielo/API30/Ecommerce/Request/QuerySaleRequest.php @@ -5,6 +5,7 @@ use Cielo\API30\Ecommerce\Sale; use Cielo\API30\Environment; use Cielo\API30\Merchant; +use Psr\Log\LoggerInterface; /** * Class QuerySaleRequest @@ -16,15 +17,16 @@ class QuerySaleRequest extends AbstractRequest private $environment; - /** - * QuerySaleRequest constructor. - * - * @param Merchant $merchant - * @param Environment $environment - */ - public function __construct(Merchant $merchant, Environment $environment) + /** + * QuerySaleRequest constructor. + * + * @param Merchant $merchant + * @param Environment $environment + * @param LoggerInterface|null $logger + */ + public function __construct(Merchant $merchant, Environment $environment, LoggerInterface $logger = null) { - parent::__construct($merchant); + parent::__construct($merchant, $logger); $this->environment = $environment; } diff --git a/src/Cielo/API30/Ecommerce/Request/TokenizeCardRequest.php b/src/Cielo/API30/Ecommerce/Request/TokenizeCardRequest.php index 5d1fb75..722e367 100644 --- a/src/Cielo/API30/Ecommerce/Request/TokenizeCardRequest.php +++ b/src/Cielo/API30/Ecommerce/Request/TokenizeCardRequest.php @@ -5,6 +5,7 @@ use Cielo\API30\Ecommerce\CreditCard; use Cielo\API30\Ecommerce\Environment; use Cielo\API30\Merchant; +use Psr\Log\LoggerInterface; /** * Class CreateCardTokenRequestHandler @@ -18,15 +19,16 @@ class TokenizeCardRequest extends AbstractRequest /** @var Merchant $merchant */ private $merchant; - /** - * CreateCardTokenRequestHandler constructor. - * - * @param Merchant $merchant - * @param Environment $environment - */ - public function __construct(Merchant $merchant, Environment $environment) + /** + * CreateCardTokenRequestHandler constructor. + * + * @param Merchant $merchant + * @param Environment $environment + * @param LoggerInterface|null $logger + */ + public function __construct(Merchant $merchant, Environment $environment, LoggerInterface $logger = null) { - parent::__construct($merchant); + parent::__construct($merchant, $logger); $this->merchant = $merchant; $this->environment = $environment; diff --git a/src/Cielo/API30/Ecommerce/Request/UpdateSaleRequest.php b/src/Cielo/API30/Ecommerce/Request/UpdateSaleRequest.php index 43b9b80..54b9b02 100644 --- a/src/Cielo/API30/Ecommerce/Request/UpdateSaleRequest.php +++ b/src/Cielo/API30/Ecommerce/Request/UpdateSaleRequest.php @@ -5,6 +5,7 @@ use Cielo\API30\Ecommerce\Payment; use Cielo\API30\Environment; use Cielo\API30\Merchant; +use Psr\Log\LoggerInterface; /** * Class UpdateSaleRequest @@ -22,16 +23,17 @@ class UpdateSaleRequest extends AbstractRequest private $amount; - /** - * UpdateSaleRequest constructor. - * - * @param Merchant $type - * @param Merchant $merchant - * @param Environment $environment - */ - public function __construct($type, Merchant $merchant, Environment $environment) + /** + * UpdateSaleRequest constructor. + * + * @param Merchant $type + * @param Merchant $merchant + * @param Environment $environment + * @param LoggerInterface|null $logger + */ + public function __construct($type, Merchant $merchant, Environment $environment, LoggerInterface $logger = null) { - parent::__construct($merchant); + parent::__construct($merchant, $logger); $this->environment = $environment; $this->type = $type; From ad3f57731910f58f8baa6cb56e4f605baea38efa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Batista=20Neto?= Date: Wed, 20 Nov 2019 16:44:20 -0300 Subject: [PATCH 29/34] Ajusta log --- .../Ecommerce/Request/AbstractRequest.php | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/Cielo/API30/Ecommerce/Request/AbstractRequest.php b/src/Cielo/API30/Ecommerce/Request/AbstractRequest.php index 71e7643..4c4da2a 100644 --- a/src/Cielo/API30/Ecommerce/Request/AbstractRequest.php +++ b/src/Cielo/API30/Ecommerce/Request/AbstractRequest.php @@ -82,34 +82,31 @@ protected function sendRequest($method, $url, \JsonSerializable $content = null) curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); - if ($this->logger !== null) { - $this->logger->debug( - trim( - sprintf("Requisição\n%s %s\n%s\n\n%s\n\n", - $method, $url, - implode("\n", $headers), - preg_replace('/("cardnumber"):"([^"]{6})[^"]+([^"]{4})"/i', '$1:"$2******$3"', json_encode($content)) - ) - ) - ); - } + if ($this->logger !== null) { + $this->logger->debug('Requisição', [ + sprintf('%s %s', $method, $url), + $headers, + json_decode(preg_replace('/("cardnumber"):"([^"]{6})[^"]+([^"]{4})"/i', '$1:"$2******$3"', json_encode($content))) + ] + ); + } $response = curl_exec($curl); $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); - if ($this->logger !== null) { - $this->logger->debug( - trim( - sprintf("Resposta\n%d\n\n%s\n\n", - $statusCode, - $response - ) - ) - ); - } + if ($this->logger !== null) { + $this->logger->debug('Resposta', [ + sprintf('Código de status: %s', $statusCode), + json_decode($response) + ]); + } if (curl_errno($curl)) { - throw new \RuntimeException('Curl error: ' . curl_error($curl)); + $message = sprintf('cURL error[%s]: %s', curl_errno($curl), curl_error($curl)); + + $this->logger->error($message); + + throw new \RuntimeException($message); } curl_close($curl); From 758338dfc9857f10206fbf4b84702631c9c47a31 Mon Sep 17 00:00:00 2001 From: Joao Hernandes Date: Tue, 27 Jun 2023 16:39:58 -0300 Subject: [PATCH 30/34] =?UTF-8?q?Ajustado=20convers=C3=A3o=20json=20quando?= =?UTF-8?q?=20=C3=A9=20retornado=20status=20400.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Ecommerce/Request/AbstractRequest.php | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/Cielo/API30/Ecommerce/Request/AbstractRequest.php b/src/Cielo/API30/Ecommerce/Request/AbstractRequest.php index 4c4da2a..6c0c2ed 100644 --- a/src/Cielo/API30/Ecommerce/Request/AbstractRequest.php +++ b/src/Cielo/API30/Ecommerce/Request/AbstractRequest.php @@ -16,12 +16,12 @@ abstract class AbstractRequest private $merchant; private $logger; - /** - * AbstractSaleRequest constructor. - * - * @param Merchant $merchant - * @param LoggerInterface|null $logger - */ + /** + * AbstractSaleRequest constructor. + * + * @param Merchant $merchant + * @param LoggerInterface|null $logger + */ public function __construct(Merchant $merchant, LoggerInterface $logger = null) { $this->merchant = $merchant; @@ -83,7 +83,9 @@ protected function sendRequest($method, $url, \JsonSerializable $content = null) curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); if ($this->logger !== null) { - $this->logger->debug('Requisição', [ + $this->logger->debug( + 'Requisição', + [ sprintf('%s %s', $method, $url), $headers, json_decode(preg_replace('/("cardnumber"):"([^"]{6})[^"]+([^"]{4})"/i', '$1:"$2******$3"', json_encode($content))) @@ -135,6 +137,18 @@ protected function readResponse($statusCode, $responseBody) $exception = null; $response = json_decode($responseBody); + if (is_string($response)) { + $response = json_decode($response); + } + + if (json_last_error() !== JSON_ERROR_NONE || !is_array($response)) { + $cieloError = new CieloError($responseBody, $statusCode); + $exception = new CieloRequestException('Bad Request', 400); + $exception->setCieloError($cieloError); + + throw $exception; + } + foreach ($response as $error) { $cieloError = new CieloError($error->Message, $error->Code); $exception = new CieloRequestException('Request Error', $statusCode, $exception); From d89754773323204b301c89d12a545140396bf92a Mon Sep 17 00:00:00 2001 From: Joao Hernandes Date: Tue, 27 Jun 2023 16:47:17 -0300 Subject: [PATCH 31/34] Alterado caminho do repo --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 60c692e..1155ed3 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "Cielo": "src" } }, - "name": "developercielo/api-3.0-php", + "name": "ipagdevs/api-3.0-php", "description": "Integração com a API 3.0 da Cielo", "license": "MIT", "type": "library", From a83e70e2dea429d7137f6b4ca5cd80bf15cf69b9 Mon Sep 17 00:00:00 2001 From: Joao Hernandes Date: Wed, 12 Jul 2023 16:45:36 -0300 Subject: [PATCH 32/34] Adicionado campos para enviar ExternalAuthentication --- .../Ecommerce/ExternalAuthentication.php | 172 ++++++++++++++++++ src/Cielo/API30/Ecommerce/Payment.php | 50 +++++ 2 files changed, 222 insertions(+) create mode 100644 src/Cielo/API30/Ecommerce/ExternalAuthentication.php diff --git a/src/Cielo/API30/Ecommerce/ExternalAuthentication.php b/src/Cielo/API30/Ecommerce/ExternalAuthentication.php new file mode 100644 index 0000000..e3c8f47 --- /dev/null +++ b/src/Cielo/API30/Ecommerce/ExternalAuthentication.php @@ -0,0 +1,172 @@ +populate($object); + + return $auth; + } + + /** + * @inheritdoc + */ + public function populate(\stdClass $data) + { + $this->cavv = isset($data->Cavv) ? $data->Cavv : null; + $this->xid = isset($data->Xid) ? $data->Xid : null; + $this->eci = isset($data->Eci) ? $data->Eci : null; + $this->version = isset($data->Version) ? $data->Version : null; + $this->referenceId = isset($data->ReferenceId) ? $data->ReferenceId : null; + $this->links = isset($data->Links) ? $data->Links : new \stdClass(); + } + + /** + * @return array + */ + public function jsonSerialize() + { + return get_object_vars($this); + } + + /** + * @return mixed + */ + public function getCavv() + { + return $this->cavv; + } + + /** + * @param $cavv + * + * @return $this + */ + public function setCavv($cavv) + { + $this->cavv = $cavv; + + return $this; + } + + /** + * @return mixed + */ + public function getXid() + { + return $this->xid; + } + + /** + * @param $xid + * + * @return $this + */ + public function setXid($xid) + { + $this->xid = $xid; + + return $this; + } + + /** + * @return mixed + */ + public function getEci() + { + return $this->eci; + } + + /** + * @param $eci + * + * @return $this + */ + public function setEci($eci) + { + $this->eci = $eci; + + return $this; + } + + /** + * @return mixed + */ + public function getVersion() + { + return $this->version; + } + + /** + * @param $version + * + * @return $this + */ + public function setVersion($version) + { + $this->version = $version; + + return $this; + } + + /** + * @return mixed + */ + public function getReferenceId() + { + return $this->referenceId; + } + + /** + * @param $referenceId + * + * @return $this + */ + public function setReferenceId($referenceId) + { + $this->referenceId = $referenceId; + + return $this; + } + + /** + * @return \stdClass + */ + public function getLinks() + { + return $this->links; + } + + /** + * @param \stdClass $links + */ + public function setLinks($links) + { + $this->links = $links; + } +} diff --git a/src/Cielo/API30/Ecommerce/Payment.php b/src/Cielo/API30/Ecommerce/Payment.php index 574f88a..2811632 100644 --- a/src/Cielo/API30/Ecommerce/Payment.php +++ b/src/Cielo/API30/Ecommerce/Payment.php @@ -42,6 +42,8 @@ class Payment implements \JsonSerializable private $debitCard; + private $externalAuthentication; + private $authenticationUrl; private $tid; @@ -161,6 +163,11 @@ public function populate(\stdClass $data) $this->debitCard->populate($data->DebitCard); } + if (isset($data->ExternalAuthentication)) { + $this->externalAuthentication = new ExternalAuthentication(); + $this->externalAuthentication->populate($data->ExternalAuthentication); + } + $this->expirationDate = isset($data->ExpirationDate) ? $data->ExpirationDate : null; $this->url = isset($data->Url) ? $data->Url : null; $this->boletoNumber = isset($data->BoletoNumber) ? $data->BoletoNumber : null; @@ -251,6 +258,29 @@ public function debitCard($securityCode, $brand) return $card; } + /** + * @param type $cavv + * @param type $xid + * @param type $eci + * @param type $version + * @param type $referenceId + * + * @return ExternalAuthentication + */ + public function externalAuthentication($cavv, $xid, $eci, $version, $referenceId) + { + $auth = new ExternalAuthentication(); + $auth->setCavv($cavv); + $auth->setXid($xid); + $auth->setEci($eci); + $auth->setVersion($version); + $auth->setReferenceId($referenceId); + + $this->setExternalAuthentication($auth); + + return $auth; + } + /** * @param bool $authorizeNow * @@ -445,6 +475,26 @@ public function setDebitCard($debitCard) return $this; } + /** + * @return mixed + */ + public function getExternalAuthentication() + { + return $this->externalAuthentication; + } + + /** + * @param $externalAuthentication + * + * @return $this + */ + public function setExternalAuthentication($externalAuthentication) + { + $this->externalAuthentication = $externalAuthentication; + + return $this; + } + /** * @return mixed */ From effa4592f1d18661d346fe2da8c05a9eda17a18f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Val=C3=B5es=20Novaes=20Ribeiro?= Date: Fri, 5 Jul 2024 11:35:37 -0300 Subject: [PATCH 33/34] Add: Classes PaymentFacilitator e SubEstablishment --- .../API30/Ecommerce/PaymentFacilitator.php | 95 ++++++++ .../API30/Ecommerce/SubEstablishment.php | 230 ++++++++++++++++++ 2 files changed, 325 insertions(+) create mode 100644 src/Cielo/API30/Ecommerce/PaymentFacilitator.php create mode 100644 src/Cielo/API30/Ecommerce/SubEstablishment.php diff --git a/src/Cielo/API30/Ecommerce/PaymentFacilitator.php b/src/Cielo/API30/Ecommerce/PaymentFacilitator.php new file mode 100644 index 0000000..1786835 --- /dev/null +++ b/src/Cielo/API30/Ecommerce/PaymentFacilitator.php @@ -0,0 +1,95 @@ +paymentFacilitator = $paymentFacilitator; + } + + /** + * @param $json + * + * @return PaymentFacilitator + */ + public static function fromJson($json) + { + $paymentFacilitator = new PaymentFacilitator(json_decode($json)); + $paymentFacilitator->populate(json_decode($json)); + + return $paymentFacilitator; + } + + /** + * @param \stdClass $data + */ + public function populate(\stdClass $data) + { + $this->paymentFacilitator = $data->paymentFacilitator ?? $data->paymentFacilitator; + $this->subEstablishment = new SubEstablishment(); + $this->subEstablishment->populate($data); + } + + /** + * @return array + */ + public function jsonSerialize() + { + return get_object_vars($this); + } + + /** + * Get the value of paymentFacilitator + */ + public function getPaymentFacilitator() + { + return $this->paymentFacilitator; + } + + /** + * Set the value of paymentFacilitator + * + * @return self + */ + public function setPaymentFacilitator($paymentFacilitator) + { + $this->paymentFacilitator = $paymentFacilitator; + + return $this; + } + + /** + * Get the value of subEstablishment + */ + public function getSubEstablishment() + { + return $this->subEstablishment; + } + + /** + * Set the value of subEstablishment + * + * @return self + */ + public function setSubEstablishment($subEstablishment) + { + $this->subEstablishment = $subEstablishment; + + return $this; + } +} \ No newline at end of file diff --git a/src/Cielo/API30/Ecommerce/SubEstablishment.php b/src/Cielo/API30/Ecommerce/SubEstablishment.php new file mode 100644 index 0000000..c08361e --- /dev/null +++ b/src/Cielo/API30/Ecommerce/SubEstablishment.php @@ -0,0 +1,230 @@ +countryCode = "076"; + } + /** + * @param \stdClass $data + */ + public function populate(\stdClass $data) + { + $this->establishmentCode = $data->establishmentCode ?? $data->establishmentCode; + $this->identity = $data->identity ?? $data->identity; + $this->mcc = $data->mcc ?? $data->mcc; + $this->address = $data->address ?? $data->address; + $this->city = $data->city ?? $data->city; + $this->state = $data->state ?? $data->state; + $this->countryCode = $data->countryCode ?? $data->countryCode; + $this->postalCode = $data->postalCode ?? $data->postalCode; + $this->phoneNumber = $data->phoneNumber ?? $data->phoneNumber; + } + + public function jsonSerialize() + { + return get_object_vars($this); + } + + + /** + * Get the value of establishmentCode + */ + public function getEstablishmentCode() + { + return $this->establishmentCode; + } + + /** + * Set the value of establishmentCode + * + * @return self + */ + public function setEstablishmentCode($establishmentCode) + { + $this->establishmentCode = $establishmentCode; + + return $this; + } + + /** + * Get the value of identity + */ + public function getIdentity() + { + return $this->identity; + } + + /** + * Set the value of identity + * + * @return self + */ + public function setIdentity($identity) + { + $this->identity = $identity; + + return $this; + } + + /** + * Get the value of mcc + */ + public function getMcc() + { + return $this->mcc; + } + + /** + * Set the value of mcc + * + * @return self + */ + public function setMcc($mcc) + { + $this->mcc = $mcc; + + return $this; + } + + /** + * Get the value of address + */ + public function getAddress() + { + return $this->address; + } + + /** + * Set the value of address + * + * @return self + */ + public function setAddress($address) + { + $this->address = $address; + + return $this; + } + + /** + * Get the value of city + */ + public function getCity() + { + return $this->city; + } + + /** + * Set the value of city + * + * @return self + */ + public function setCity($city) + { + $this->city = $city; + + return $this; + } + + /** + * Get the value of state + */ + public function getState() + { + return $this->state; + } + + /** + * Set the value of state + * + * @return self + */ + public function setState($state) + { + $this->state = $state; + + return $this; + } + + /** + * Get the value of countryCode + */ + public function getCountryCode() + { + return $this->countryCode; + } + + /** + * Set the value of countryCode + * + * @return self + */ + public function setCountryCode($countryCode) + { + $this->countryCode = $countryCode; + + return $this; + } + + /** + * Get the value of postalCode + */ + public function getPostalCode() + { + return $this->postalCode; + } + + /** + * Set the value of postalCode + * + * @return self + */ + public function setPostalCode($postalCode) + { + $this->postalCode = $postalCode; + + return $this; + } + + /** + * Get the value of phoneNumber + */ + public function getPhoneNumber() + { + return $this->phoneNumber; + } + + /** + * Set the value of phoneNumber + * + * @return self + */ + public function setPhoneNumber($phoneNumber) + { + $this->phoneNumber = $phoneNumber; + + return $this; + } +} \ No newline at end of file From 51c8f2a54a0bfc3814958da0141fea88eb573134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Val=C3=B5es?= Date: Fri, 5 Jul 2024 12:39:54 -0300 Subject: [PATCH 34/34] Melhorado cs --- src/Cielo/API30/Ecommerce/Payment.php | 35 ++++++++++++ .../API30/Ecommerce/PaymentFacilitator.php | 55 ++++--------------- .../API30/Ecommerce/SubEstablishment.php | 41 ++++++++------ 3 files changed, 72 insertions(+), 59 deletions(-) diff --git a/src/Cielo/API30/Ecommerce/Payment.php b/src/Cielo/API30/Ecommerce/Payment.php index 2811632..85ffa3b 100644 --- a/src/Cielo/API30/Ecommerce/Payment.php +++ b/src/Cielo/API30/Ecommerce/Payment.php @@ -110,6 +110,8 @@ class Payment implements \JsonSerializable private $instructions; + private $paymentFacilitator; + /** * Payment constructor. * @@ -168,6 +170,10 @@ public function populate(\stdClass $data) $this->externalAuthentication->populate($data->ExternalAuthentication); } + if (isset($data->PaymentFacilitator)) { + $this->paymentFacilitator()->populate($data->paymentFacilitator); + } + $this->expirationDate = isset($data->ExpirationDate) ? $data->ExpirationDate : null; $this->url = isset($data->Url) ? $data->Url : null; $this->boletoNumber = isset($data->BoletoNumber) ? $data->BoletoNumber : null; @@ -1154,4 +1160,33 @@ public function setInstructions($instructions) return $this; } + + public function paymentFacilitator() + { + if (is_null($this->paymentFacilitator)) { + $this->setPaymentFacilitator(new PaymentFacilitator()); + } + + return $this->getPaymentFacilitator(); + } + + /** + * Get the value of paymentFacilitator + */ + public function getPaymentFacilitator() + { + return $this->paymentFacilitator; + } + + /** + * Set the value of paymentFacilitator + * + * @return self + */ + public function setPaymentFacilitator($paymentFacilitator) + { + $this->paymentFacilitator = $paymentFacilitator; + + return $this; + } } diff --git a/src/Cielo/API30/Ecommerce/PaymentFacilitator.php b/src/Cielo/API30/Ecommerce/PaymentFacilitator.php index 1786835..c894cd8 100644 --- a/src/Cielo/API30/Ecommerce/PaymentFacilitator.php +++ b/src/Cielo/API30/Ecommerce/PaymentFacilitator.php @@ -3,36 +3,17 @@ namespace Cielo\API30\Ecommerce; /** - * Class Payment + * Class PaymentFacilitator * * @package Cielo\API30\Ecommerce */ - - class PaymentFacilitator implements \JsonSerializable { - - private $paymentFacilitator; - private $subEstablishment; - - public function __construct($paymentFacilitator) + public function __construct($subEstablishment = null) { - $this->paymentFacilitator = $paymentFacilitator; - } - - /** - * @param $json - * - * @return PaymentFacilitator - */ - public static function fromJson($json) - { - $paymentFacilitator = new PaymentFacilitator(json_decode($json)); - $paymentFacilitator->populate(json_decode($json)); - - return $paymentFacilitator; + $this->subEstablishment = $subEstablishment; } /** @@ -40,7 +21,6 @@ public static function fromJson($json) */ public function populate(\stdClass $data) { - $this->paymentFacilitator = $data->paymentFacilitator ?? $data->paymentFacilitator; $this->subEstablishment = new SubEstablishment(); $this->subEstablishment->populate($data); } @@ -53,29 +33,18 @@ public function jsonSerialize() return get_object_vars($this); } - /** - * Get the value of paymentFacilitator - */ - public function getPaymentFacilitator() + public function subEstablishment() { - return $this->paymentFacilitator; - } - - /** - * Set the value of paymentFacilitator - * - * @return self - */ - public function setPaymentFacilitator($paymentFacilitator) - { - $this->paymentFacilitator = $paymentFacilitator; - - return $this; + if (is_null($this->subEstablishment)) { + $this->setSubEstablishment(new SubEstablishment()); + } + + return $this->getSubEstablishment(); } /** * Get the value of subEstablishment - */ + */ public function getSubEstablishment() { return $this->subEstablishment; @@ -85,8 +54,8 @@ public function getSubEstablishment() * Set the value of subEstablishment * * @return self - */ - public function setSubEstablishment($subEstablishment) + */ + public function setSubEstablishment(SubEstablishment $subEstablishment) { $this->subEstablishment = $subEstablishment; diff --git a/src/Cielo/API30/Ecommerce/SubEstablishment.php b/src/Cielo/API30/Ecommerce/SubEstablishment.php index c08361e..f4186bd 100644 --- a/src/Cielo/API30/Ecommerce/SubEstablishment.php +++ b/src/Cielo/API30/Ecommerce/SubEstablishment.php @@ -3,43 +3,52 @@ namespace Cielo\API30\Ecommerce; /** - * Class Payment + * Class SubEstablishment * * @package Cielo\API30\Ecommerce */ - - class SubEstablishment implements \JsonSerializable { + const DEFAULT_COUTRY_CODE = "076"; + private $establishmentCode; private $identity; private $mcc; private $address; private $city; private $state; - private $countryCode; private $postalCode; + private $countryCode; private $phoneNumber; - public function __construct() { - $this->countryCode = "076"; + $this->countryCode = self::DEFAULT_COUTRY_CODE; + $this->establishmentCode = null; + $this->identity = null; + $this->mcc = null; + $this->address = null; + $this->city = null; + $this->state = null; + $this->countryCode = null; + $this->postalCode = null; + $this->phoneNumber = null; } + /** * @param \stdClass $data */ public function populate(\stdClass $data) { - $this->establishmentCode = $data->establishmentCode ?? $data->establishmentCode; - $this->identity = $data->identity ?? $data->identity; - $this->mcc = $data->mcc ?? $data->mcc; - $this->address = $data->address ?? $data->address; - $this->city = $data->city ?? $data->city; - $this->state = $data->state ?? $data->state; - $this->countryCode = $data->countryCode ?? $data->countryCode; - $this->postalCode = $data->postalCode ?? $data->postalCode; - $this->phoneNumber = $data->phoneNumber ?? $data->phoneNumber; + $this->establishmentCode = $data->EstablishmentCode ?? null; + $this->identity = $data->Identity ?? null; + $this->mcc = $data->Mcc ?? null; + $this->address = $data->Address ?? null; + $this->city = $data->City ?? null; + $this->state = $data->State ?? null; + $this->countryCode = $data->CountryCode ?? null; + $this->postalCode = $data->PostalCode ?? null; + $this->phoneNumber = $data->PhoneNumber ?? null; } public function jsonSerialize() @@ -227,4 +236,4 @@ public function setPhoneNumber($phoneNumber) return $this; } -} \ No newline at end of file +}