diff --git a/.gitignore b/.gitignore index 987e2a2..5d13a24 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ composer.lock vendor +.idea diff --git a/README.md b/README.md index b6f20a5..7e96dfe 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,58 @@ 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 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" +``` + +## 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"); @@ -82,7 +130,7 @@ try { // ... ``` -### Criando transações com cartão de débito +### Criando um pagamento e gerando o token do 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", CreditCard::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", CreditCard::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 +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", CreditCard::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); + + $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. + $error = $e->getCieloError(); +} +// ... +``` + +### Criando transações com cartão de débito + +```php +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"); @@ -144,6 +358,117 @@ 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(); +} +``` + +### Tokenizando um cartão + +```php +setCustomerName('Fulano de Tal'); +$card->setCardNumber('0000000000000001'); +$card->setHolder('Fulano de Tal'); +$card->setExpirationDate('10/2020'); +$card->setBrand(CreditCard::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/) +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/composer.json b/composer.json index 7cbb89a..1155ed3 100644 --- a/composer.json +++ b/composer.json @@ -1,15 +1,21 @@ { - "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": "ipagdevs/api-3.0-php", + "description": "Integração com a API 3.0 da Cielo", + "license": "MIT", + "type": "library", + "require": { + "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/Address.php b/src/Cielo/API30/Ecommerce/Address.php index 1cc0bb4..d16e71e 100644 --- a/src/Cielo/API30/Ecommerce/Address.php +++ b/src/Cielo/API30/Ecommerce/Address.php @@ -1,6 +1,12 @@ 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->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; + } + + /** + * @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; + return $this; } -} \ No newline at end of file +} diff --git a/src/Cielo/API30/Ecommerce/CieloEcommerce.php b/src/Cielo/API30/Ecommerce/CieloEcommerce.php index 733ad8f..f297d73 100644 --- a/src/Cielo/API30/Ecommerce/CieloEcommerce.php +++ b/src/Cielo/API30/Ecommerce/CieloEcommerce.php @@ -1,10 +1,14 @@ merchant = $merchant; + + $this->merchant = $merchant; $this->environment = $environment; + $this->logger = $logger; } /** * 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 */ 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); } @@ -62,38 +71,66 @@ 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 */ public function getSale($paymentId) { - $querySaleRequest = new QuerySaleRequest($this->merchant, $this->environment); - + $querySaleRequest = new QuerySaleRequest($this->merchant, $this->environment, $this->logger); + 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 \Cielo\API30\Ecommerce\Request\CieloRequestException if anything gets wrong. + * + * @see Error + * Codes + */ + public function getRecurrentPayment($recurrentPaymentId) + { + $queryRecurrentPaymentRequest = new queryRecurrentPaymentRequest($this->merchant, $this->environment, $this->logger); + + return $queryRecurrentPaymentRequest->execute($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 - * @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 */ 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); - + return $updateSaleRequest->execute($paymentId); } @@ -101,27 +138,42 @@ 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 * @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 */ 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); - + return $updateSaleRequest->execute($paymentId); } -} \ No newline at end of file + + /** + * @param CreditCard $card + * + * @return CreditCard + */ + public function tokenizeCard(CreditCard $card) + { + $tokenizeCardRequest = new TokenizeCardRequest($this->merchant, $this->environment, $this->logger); + + return $tokenizeCardRequest->execute($card); + } +} diff --git a/src/Cielo/API30/Ecommerce/CieloSerializable.php b/src/Cielo/API30/Ecommerce/CieloSerializable.php index cdda657..05d13a7 100644 --- a/src/Cielo/API30/Ecommerce/CieloSerializable.php +++ b/src/Cielo/API30/Ecommerce/CieloSerializable.php @@ -1,7 +1,18 @@ populate($object); + + return $cardToken; } + /** + * @inheritdoc + */ 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->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); } + /** + * @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 + + /** + * @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; + } +} diff --git a/src/Cielo/API30/Ecommerce/Customer.php b/src/Cielo/API30/Ecommerce/Customer.php index 90cf85c..c24dc69 100644 --- a/src/Cielo/API30/Ecommerce/Customer.php +++ b/src/Cielo/API30/Ecommerce/Customer.php @@ -1,6 +1,12 @@ 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->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)) { $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..1b1334c 100644 --- a/src/Cielo/API30/Ecommerce/Environment.php +++ b/src/Cielo/API30/Ecommerce/Environment.php @@ -1,38 +1,56 @@ api = $api; + $this->api = $api; $this->apiQuery = $apiQuery; } + /** + * @return Environment + */ 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); } + /** + * @return Environment + */ 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); } /** * Gets the environment's Api URL * - * @return the Api URL + * @return string the Api URL */ public function getApiUrl() { @@ -42,10 +60,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/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 a4be185..85ffa3b 100644 --- a/src/Cielo/API30/Ecommerce/Payment.php +++ b/src/Cielo/API30/Ecommerce/Payment.php @@ -1,6 +1,12 @@ setAmount($amount); $this->setInstallments($installments); } - public function jsonSerialize() + /** + * @param $json + * + * @return Payment + */ + public static function fromJson($json) { - return get_object_vars($this); + $payment = new Payment(); + $payment->populate(json_decode($json)); + + return $payment; } + /** + * @param \stdClass $data + */ 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); @@ -124,42 +165,64 @@ public function populate(\stdClass $data) $this->debitCard->populate($data->DebitCard); } - $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->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: []; - } + if (isset($data->ExternalAuthentication)) { + $this->externalAuthentication = new ExternalAuthentication(); + $this->externalAuthentication->populate($data->ExternalAuthentication); + } - public static function fromJson($json) - { - $payment = new Payment(); - $payment->populate(json_decode($json)); + if (isset($data->PaymentFacilitator)) { + $this->paymentFacilitator()->populate($data->paymentFacilitator); + } - return $payment; + $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; } - private function newCard($securityCode, $brand) + /** + * @return array + */ + public function jsonSerialize() { - $card = new CreditCard(); - $card->setSecurityCode($securityCode); - $card->setBrand($brand); - - return $card; + return get_object_vars($this); } + /** + * @param $securityCode + * @param $brand + * + * @return CreditCard + */ public function creditCard($securityCode, $brand) { $card = $this->newCard($securityCode, $brand); @@ -170,6 +233,27 @@ public function creditCard($securityCode, $brand) return $card; } + /** + * @param $securityCode + * @param $brand + * + * @return CreditCard + */ + private function newCard($securityCode, $brand) + { + $card = new CreditCard(); + $card->setSecurityCode($securityCode); + $card->setBrand($brand); + + return $card; + } + + /** + * @param $securityCode + * @param $brand + * + * @return CreditCard + */ public function debitCard($securityCode, $brand) { $card = $this->newCard($securityCode, $brand); @@ -180,6 +264,34 @@ 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 + * + * @return RecurrentPayment + */ public function recurrentPayment($authorizeNow = true) { $recurrentPayment = new RecurrentPayment($authorizeNow); @@ -189,91 +301,163 @@ 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; + return $this; } @@ -287,296 +471,722 @@ public function getDebitCard() /** * @param mixed $debitCard + * + * @return $this */ public function setDebitCard($debitCard) { $this->debitCard = $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 + */ 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; + + return $this; + } + + /** + * @return mixed + */ + public function getDemonstrative() + { + return $this->demonstrative; + } + + /** + * @param $demonstrative + * + * @return $this + */ + public function setDemonstrative($demonstrative) + { + $this->demonstrative = $demonstrative; + + return $this; + } + + /** + * @return mixed + */ + public function getIdentification() + { + return $this->identification; + } + + /** + * @param $identification + * + * @return $this + */ + public function setIdentification($identification) + { + $this->identification = $identification; + + return $this; + } + + /** + * @return mixed + */ + public function getInstructions() + { + return $this->instructions; + } + + /** + * @param $instructions + * + * @return $this + */ + public function setInstructions($instructions) + { + $this->instructions = $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 new file mode 100644 index 0000000..c894cd8 --- /dev/null +++ b/src/Cielo/API30/Ecommerce/PaymentFacilitator.php @@ -0,0 +1,64 @@ +subEstablishment = $subEstablishment; + } + + /** + * @param \stdClass $data + */ + public function populate(\stdClass $data) + { + $this->subEstablishment = new SubEstablishment(); + $this->subEstablishment->populate($data); + } + + /** + * @return array + */ + public function jsonSerialize() + { + return get_object_vars($this); + } + + public function subEstablishment() + { + if (is_null($this->subEstablishment)) { + $this->setSubEstablishment(new SubEstablishment()); + } + + return $this->getSubEstablishment(); + } + + /** + * Get the value of subEstablishment + */ + public function getSubEstablishment() + { + return $this->subEstablishment; + } + + /** + * Set the value of subEstablishment + * + * @return self + */ + public function setSubEstablishment(SubEstablishment $subEstablishment) + { + $this->subEstablishment = $subEstablishment; + + return $this; + } +} \ No newline at end of file diff --git a/src/Cielo/API30/Ecommerce/RecurrentPayment.php b/src/Cielo/API30/Ecommerce/RecurrentPayment.php index 61255d6..088ccf8 100644 --- a/src/Cielo/API30/Ecommerce/RecurrentPayment.php +++ b/src/Cielo/API30/Ecommerce/RecurrentPayment.php @@ -1,6 +1,12 @@ setAuthorizeNow($authorizeNow); } + /** + * @param $json + * + * @return RecurrentPayment + */ + public static function fromJson($json) + { + $object = json_decode($json); + + $recurrentPayment = new RecurrentPayment(); + + if (isset($object->RecurrentPayment)) { + $recurrentPayment->populate($object->RecurrentPayment); + } + + 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); } - public function populate(\stdClass $data) + /** + * @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() { - $this->authorizeNow = isset($data->AuthorizeNow)? !!$data->AuthorizeNow: false; - $this->startDate = isset($data->StartDate)? $data->StartDate: null; - $this->endDate = isset($data->EndDate)? $data->EndDate: null; - $this->interval = isset($data->Interval)? !!$data->Interval: null; + 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; + return $this; } -} \ No newline at end of file +} diff --git a/src/Cielo/API30/Ecommerce/Request/AbstractRequest.php b/src/Cielo/API30/Ecommerce/Request/AbstractRequest.php new file mode 100644 index 0000000..6c0c2ed --- /dev/null +++ b/src/Cielo/API30/Ecommerce/Request/AbstractRequest.php @@ -0,0 +1,174 @@ +merchant = $merchant; + $this->logger = $logger; + } + + /** + * @param $param + * + * @return mixed + */ + public abstract function execute($param); + + /** + * @param $method + * @param $url + * @param \JsonSerializable|null $content + * + * @return mixed + * + * @throws \Cielo\API30\Ecommerce\Request\CieloRequestException + * @throws \RuntimeException + */ + protected function sendRequest($method, $url, \JsonSerializable $content = null) + { + $headers = [ + 'Accept: application/json', + 'Accept-Encoding: gzip', + 'User-Agent: CieloEcommerce/3.0 PHP SDK', + 'MerchantId: ' . $this->merchant->getId(), + '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; + case 'POST': + curl_setopt($curl, CURLOPT_POST, true); + break; + default: + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); + } + + if ($content !== null) { + curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($content)); + + $headers[] = 'Content-Type: application/json'; + } else { + $headers[] = 'Content-Length: 0'; + } + + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); + + 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('Resposta', [ + sprintf('Código de status: %s', $statusCode), + json_decode($response) + ]); + } + + if (curl_errno($curl)) { + $message = sprintf('cURL error[%s]: %s', curl_errno($curl), curl_error($curl)); + + $this->logger->error($message); + + throw new \RuntimeException($message); + } + + 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: + $unserialized = $this->unserialize($responseBody); + break; + case 400: + $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); + $exception->setCieloError($cieloError); + } + + throw $exception; + case 404: + throw new CieloRequestException('Resource not found', 404, null); + default: + throw new CieloRequestException('Unknown status', $statusCode); + } + + return $unserialized; + } + + /** + * @param $json + * + * @return mixed + */ + protected abstract function unserialize($json); +} diff --git a/src/Cielo/API30/Ecommerce/Request/AbstractSaleRequest.php b/src/Cielo/API30/Ecommerce/Request/AbstractSaleRequest.php deleted file mode 100644 index d3759e6..0000000 --- a/src/Cielo/API30/Ecommerce/Request/AbstractSaleRequest.php +++ /dev/null @@ -1,98 +0,0 @@ -merchant = $merchant; - } - - public abstract function execute($param); - - protected abstract function unserialize($json); - - protected function sendRequest($method, $url, Sale $sale = null) - { - $headers = [ - 'Accept: application/json', - 'Accept-Encoding: gzip', - 'User-Agent: CieloEcommerce/3.0 PHP SDK', - 'MerchantId: ' . $this->merchant->getId(), - '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; - case 'POST': - curl_setopt($curl, CURLOPT_POST, true); - break; - 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); - } - - protected function readResponse($statusCode, $responseBody) - { - $unserialized = null; - - switch ($statusCode) { - case 200: - case 201: - $unserialized = $this->unserialize($responseBody); - break; - 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..1d4b20a 100644 --- a/src/Cielo/API30/Ecommerce/Request/CieloError.php +++ b/src/Cielo/API30/Ecommerce/Request/CieloError.php @@ -1,6 +1,12 @@ 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..640f87e 100644 --- a/src/Cielo/API30/Ecommerce/Request/CieloRequestException.php +++ b/src/Cielo/API30/Ecommerce/Request/CieloRequestException.php @@ -1,24 +1,46 @@ 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..f3c9659 100644 --- a/src/Cielo/API30/Ecommerce/Request/CreateSaleRequest.php +++ b/src/Cielo/API30/Ecommerce/Request/CreateSaleRequest.php @@ -1,32 +1,57 @@ environment = $environment; } + /** + * @param $sale + * + * @return null + * @throws \Cielo\API30\Ecommerce\Request\CieloRequestException + * @throws \RuntimeException + */ 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 new file mode 100644 index 0000000..8309772 --- /dev/null +++ b/src/Cielo/API30/Ecommerce/Request/QueryRecurrentPaymentRequest.php @@ -0,0 +1,57 @@ +environment = $environment; + } + + /** + * @param $recurrentPaymentId + * + * @return null + * @throws \Cielo\API30\Ecommerce\Request\CieloRequestException + * @throws \RuntimeException + */ + public function execute($recurrentPaymentId) + { + $url = $this->environment->getApiQueryURL() . '1/RecurrentPayment/' . $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..e7953b2 100644 --- a/src/Cielo/API30/Ecommerce/Request/QuerySaleRequest.php +++ b/src/Cielo/API30/Ecommerce/Request/QuerySaleRequest.php @@ -1,32 +1,57 @@ environment = $environment; } + /** + * @param $paymentId + * + * @return null + * @throws \Cielo\API30\Ecommerce\Request\CieloRequestException + * @throws \RuntimeException + */ 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/TokenizeCardRequest.php b/src/Cielo/API30/Ecommerce/Request/TokenizeCardRequest.php new file mode 100644 index 0000000..722e367 --- /dev/null +++ b/src/Cielo/API30/Ecommerce/Request/TokenizeCardRequest.php @@ -0,0 +1,54 @@ +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 CreditCard::fromJson($json); + } +} diff --git a/src/Cielo/API30/Ecommerce/Request/UpdateSaleRequest.php b/src/Cielo/API30/Ecommerce/Request/UpdateSaleRequest.php index 718014e..54b9b02 100644 --- a/src/Cielo/API30/Ecommerce/Request/UpdateSaleRequest.php +++ b/src/Cielo/API30/Ecommerce/Request/UpdateSaleRequest.php @@ -1,12 +1,18 @@ 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) { $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..07639e7 100644 --- a/src/Cielo/API30/Ecommerce/Sale.php +++ b/src/Cielo/API30/Ecommerce/Sale.php @@ -1,6 +1,12 @@ setMerchantOrderId($merchantOrderId); } - public function jsonSerialize() + /** + * @param $json + * + * @return Sale + */ + public static function fromJson($json) { - return get_object_vars($this); + $object = json_decode($json); + + $sale = new Sale(); + $sale->populate($object); + + return $sale; } + /** + * @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 = 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); } - + if (isset($dataProps['MerchantOrderId'])) { $this->merchantOrderId = $data->MerchantOrderId; } } - public static function fromJson($json) + /** + * @return array + */ + public function jsonSerialize() { - $object = json_decode($json); - - $sale = new Sale(); - $sale->populate($object); - - return $sale; + return get_object_vars($this); } + /** + * @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/Ecommerce/SubEstablishment.php b/src/Cielo/API30/Ecommerce/SubEstablishment.php new file mode 100644 index 0000000..f4186bd --- /dev/null +++ b/src/Cielo/API30/Ecommerce/SubEstablishment.php @@ -0,0 +1,239 @@ +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 ?? 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() + { + 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; + } +} diff --git a/src/Cielo/API30/Environment.php b/src/Cielo/API30/Environment.php index f92b791..92846ad 100644 --- a/src/Cielo/API30/Environment.php +++ b/src/Cielo/API30/Environment.php @@ -1,19 +1,25 @@ id = $id; + $this->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 +}