diff --git a/CHANGELOG.md b/CHANGELOG.md index 129c73d..7ef04c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ Changelog --------- +3.4.0 +- Atualizada biblioteca PHP do PagSeguro para versão 3.3.0 +- Fix: erro no "credit card holder phone" (não estava sendo enviado o telefone do usuário) +- Melhoria: adicionada validação para, caso os dados do cartão de crédito não tenham sido inseridos corretamente (como senha errada, validada errada), exibir mensagem na tela de checkout (antes a compra era finalizada com erro) +- Fix: erro ao exibir o parcelamento máximo na tela do produto + 3.3.0 - Adicionada compatibilidade com One Step Checkout Brasil 6 Pro (Inovarti) diff --git a/README.md b/README.md index 03a228f..f792569 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Com o módulo instalado e configurado, você pode pode oferecer o PagSeguro como - Certifique-se de que não há instalação de outros módulos para o PagSeguro em seu sistema; - Caso utilize a compilação do Magento, desative-a e limpe-a *(Sistema -> Ferramentas -> Compilação)*; -- Baixe a última versão do módulo **[nesse link](https://github.com/pagseguro/magento/raw/master/UOL_PagSeguro-3.3.0.tgz)** ou então baixe o repositório como arquivo zip através do botão do GitHub; +- Baixe a última versão do módulo **[nesse link](https://github.com/pagseguro/magento/raw/master/UOL_PagSeguro-3.4.0.tgz)** ou então baixe o repositório como arquivo zip através do botão do GitHub; - Na área administrativa do seu Magento, acesse o menu *Sistema/System -> Magento Connect -> Magento Connect Manager*. Caso tenha uma versão anterior do módulo instalada faça a remoção agora; - No Magento Connect Manger, dentro da seção Direct package file upload, clique em **Escolher arquivo/Choose file**, selecione o arquivo UOL_PagSeguro-x.x.x.tgz (baixado anteriormente), clique no botão de upload e acompanhe a instalação do módulo no console da página; - Caso utilize a compilação, volte para a área administrativa do Magento, ative-a e execute-a novamente; diff --git a/UOL_PagSeguro-3.3.0.tgz b/UOL_PagSeguro-3.3.0.tgz deleted file mode 100644 index 5e79de7..0000000 Binary files a/UOL_PagSeguro-3.3.0.tgz and /dev/null differ diff --git a/UOL_PagSeguro-3.4.0.tgz b/UOL_PagSeguro-3.4.0.tgz new file mode 100644 index 0000000..2f95dca Binary files /dev/null and b/UOL_PagSeguro-3.4.0.tgz differ diff --git a/app/code/community/UOL/PagSeguro/Model/InstallmentsMethod.php b/app/code/community/UOL/PagSeguro/Model/InstallmentsMethod.php index 92756c8..5022b37 100644 --- a/app/code/community/UOL/PagSeguro/Model/InstallmentsMethod.php +++ b/app/code/community/UOL/PagSeguro/Model/InstallmentsMethod.php @@ -50,13 +50,11 @@ public function create($amount, $brand = '') { $this->helper = Mage::helper('pagseguro'); try { - $session = PagSeguro\Services\Session::create($this->library->getAccountCredentials()); $installments = PagSeguro\Services\Installment::create( $this->library->getAccountCredentials(), [ - $session, - $amount, - $brand, + 'amount' => $amount, + 'card_brand' => $brand ] ); $format = $this->output($installments, true); @@ -80,7 +78,7 @@ public function create($amount, $brand = '') private function output($installments, $maxInstallment) { return ($maxInstallment) ? - $this->formatOutput($this->getMaxInstallment($installments)) : + $this->formatOutput($this->getMaxInstallment($installments->getInstallments())) : $this->formatOutput($installments); } @@ -112,7 +110,7 @@ private function formatInstallments($installment) { return array( 'quantity' => $installment->getQuantity(), - 'amount' => $installment->getInstallmentAmount(), + 'amount' => $installment->getAmount(), 'totalAmount' => PagSeguro\Helpers\Currency::toDecimal($installment->getTotalAmount()), 'text' => str_replace('.', ',', $this->getInstallmentText($installment)), ); @@ -130,7 +128,7 @@ private function getInstallmentText($installment) return sprintf( "%s x de R$ %.2f %s juros", $installment->getQuantity(), - $installment->getInstallmentAmount(), + $installment->getAmount(), $this->getInterestFreeText($installment->getInterestFree())); } diff --git a/app/code/community/UOL/PagSeguro/Model/PaymentMethod.php b/app/code/community/UOL/PagSeguro/Model/PaymentMethod.php index 457f701..72e1425 100644 --- a/app/code/community/UOL/PagSeguro/Model/PaymentMethod.php +++ b/app/code/community/UOL/PagSeguro/Model/PaymentMethod.php @@ -200,7 +200,10 @@ public function paymentDirect($paymentMethod, $paymentData) number_format($paymentData['creditCardInstallmentValue'], 2, '.', '')); $payment->setHolder()->setBirthdate($paymentData['creditCardBirthdate']); $payment->setHolder()->setName($paymentData['creditCardHolder']); - $payment->setHolder()->setPhone()->withArray($this->helper->formatPhone($this->order->getBillingAddress()->getTelephone())); + + $phone = $this->helper->formatPhone($this->order->getBillingAddress()->getTelephone()); + $payment->setHolder()->setPhone()->withParameters($phone['areaCode'], $phone['number']); + $payment->setHolder()->setDocument()->withParameters( $formatedDocument['type'], $formatedDocument['number'] diff --git a/app/code/community/UOL/PagSeguro/etc/config.xml b/app/code/community/UOL/PagSeguro/etc/config.xml index c312c55..f16a648 100644 --- a/app/code/community/UOL/PagSeguro/etc/config.xml +++ b/app/code/community/UOL/PagSeguro/etc/config.xml @@ -19,7 +19,7 @@ limitations under the License. - 3.3.0 + 3.4.0 diff --git a/app/design/frontend/base/default/template/uol/pagseguro/form/creditcard.phtml b/app/design/frontend/base/default/template/uol/pagseguro/form/creditcard.phtml index 70555b2..630b093 100644 --- a/app/design/frontend/base/default/template/uol/pagseguro/form/creditcard.phtml +++ b/app/design/frontend/base/default/template/uol/pagseguro/form/creditcard.phtml @@ -108,8 +108,8 @@ - + onblur="validateCreditCardCode(this)" required> + @@ -168,6 +168,14 @@ +
+ + + +
+
    @@ -178,7 +186,3 @@
- - - - diff --git a/lib/PagseguroPhpSdk/.gitignore b/lib/PagseguroPhpSdk/.gitignore index b7b3fd9..efbd545 100644 --- a/lib/PagseguroPhpSdk/.gitignore +++ b/lib/PagseguroPhpSdk/.gitignore @@ -189,4 +189,11 @@ nbproject/ ## Composer ################# composer.phar -/vendor/* \ No newline at end of file +composer.lock +/vendor/* + + +################# +## Lib +################# +*.log \ No newline at end of file diff --git a/lib/PagseguroPhpSdk/CHANGELOG.md b/lib/PagseguroPhpSdk/CHANGELOG.md new file mode 100644 index 0000000..b801ad5 --- /dev/null +++ b/lib/PagseguroPhpSdk/CHANGELOG.md @@ -0,0 +1,54 @@ +3.3.0 +- Removidas funcionalidades depreciadas +- Correções e melhorias gerais + +3.2.0 +- Adicionado serviço de assinatura transparente + +3.1.0 +- Alterada URL do checkout transparente +- Correções e melhorias gerais + +3.0.8 +- Corrigido problema de conversão de tipo bool em string na geração de URL +- Corrigido erro *undefined index* no serviço de parcelamento + +3.0.6 +- Corrigidos nomes e siglas dos estados brasileiros +- Corrigido bug no serviço de parcelamento +- Correções e melhorias gerais + +3.0.0 + - Criar requisições de pagamentos + - Criar requisições de pagamentos com assinaturas + - Criar requisições de cancelamento de transações + - Criar requisições de estorno de transações + - Consultar transações por código + - Consultar transações por intervalo de datas + - Consultar transações abandonadas + - Consultar transações por código de referência + - Criar requisições de autorizações + - Consultar autorizações por código + - Consultar autorizações por intervalo de datas + - Consultar autorizações por código de notificação + - Consultar autorizações por código de referência + - Criar requisições de assinaturas + - Criar requisições de cancelamento de assinaturas + - Criar requisições de cobrança de assinaturas + - Consultar assinaturas por código + - Consultar assinaturas por intervalo de datas + - Consultar assinaturas por intervalo de dias + - Consultar assinaturas por código de notificação + - Receber notificações de autorizações + - Receber notificações de assinaturas + - Receber notificações de transações + - Criar requisições de checkout transparente utilizando boleto + - Criar requisições de checkout transparente utilizando debito online + - Criar requisições de checkout transparente utilizando cartão de crédito + - Criar requisições de checkout transparente utilizando cartão de crédito internacional + - Criar requisições de checkout transparente utilizando boleto com split payment + - Criar requisições de checkout transparente utilizando debito online com split payment + - Criar requisições de checkout transparente utilizando cartão de crédito com split payment + - Criar requisições de checkout transparente utilizando cartão de crédito internacional com split payment + - Atualização do código da biblioteca, aderindo ao uso de *namespaces*. + - Refatoração do código base. diff --git a/lib/PagseguroPhpSdk/README.md b/lib/PagseguroPhpSdk/README.md index b7dfd92..66d0346 100644 --- a/lib/PagseguroPhpSdk/README.md +++ b/lib/PagseguroPhpSdk/README.md @@ -12,6 +12,7 @@ Descrição A biblioteca PagSeguro em PHP é um conjunto de classes de domínio que facilitam, para o desenvolvedor PHP, a utilização das funcionalidades que o PagSeguro oferece na forma de APIs. Com a biblioteca instalada e configurada, você pode facilmente integrar funcionalidades como: - Criar [requisições de pagamentos] + - Criar [requisições de assinaturas transparentes] e gerenciá-las - Criar [requisições de assinaturas] - Cancelar [assinaturas] - Consultar [assinaturas] @@ -28,34 +29,43 @@ Requisitos - [SPL] - [cURL] - [SimpleXml] + - [Composer] Instalação ---------- - - - Baixe o repositório como arquivo zip ou faça um clone; +> Nota: Recomendamos a instalação via **Composer**. Você também pode baixar o repositório como [arquivo zip] ou fazer um clone via Git. + + ### Instalação via Composer +> Para baixar e instalar o Composer no seu ambiente acesse https://getcomposer.org/download/ e caso tenha dúvidas de como utilizá-lo consulte a [documentação oficial do Composer]. + +É possível instalar a biblioteca pagseguro-php-sdk([pagseguro/pagseguro-php-sdk]) via Composer de duas maneiras: + +- Executando o comando para adicionar a dependência automaticamente + ``` + php composer.phar require pagseguro/pagseguro-php-sdk + ``` + +**OU** + +- Adicionando a dependência ao seu arquivo ```composer.json``` + ```composer.json + { + "require": { + "pagseguro/pagseguro-php-sdk" : "*" + } + } + ``` + +### Instalação manual + - Baixe o repositório como [arquivo zip] ou faça um clone; - Descompacte os arquivos em seu computador; - - Execute o comando ```composer install``` - - O diretório *public* contém exemplos de chamadas utilizando a API e o diretório *source* contém a biblioteca propriamente dita. - -Instalação via Composer - -- Alternativamente, é possível utilizar o [Composer] para carregar a biblioteca ([pagseguro/pagseguro-php-sdk]). - -Adicionando a dependência ao seu arquivo ```composer.json``` -```composer.json -{ - "require": { - "pagseguro/pagseguro-php-sdk" : "*" - } -} -``` - -OU - -Executando o comando para adicionar a dependência automaticamente - -```php composer.phar require pagseguro/pagseguro-php-sdk``` + - Execute o comando ```php composer.phar install``` no local onde extraiu os arquivos. + + + Como usar + --------- + O diretório *[public](public)* contém exemplos das mais diversas chamadas à API do PagSeguro utilizando a biblioteca (pagamento, assinatura, notificação) e o diretório *[source](source)* contém a biblioteca propriamente dita (código fonte). Configuração @@ -73,41 +83,8 @@ Caso tenha dúvidas ou precise de suporte, acesse nosso [fórum]. Changelog --------- +Para consultar o log de alterações acesse o arquivo [CHANGELOG.md](CHANGELOG.md). -3.0.0 - - Criar requisições de pagamentos - - Criar requisições de pagamentos com assinaturas - - Criar requisições de cancelamento de transações - - Criar requisições de estorno de transações - - Consultar transações por código - - Consultar transações por intervalo de datas - - Consultar transações abandonadas - - Consultar transações por código de referência - - Criar requisições de autorizações - - Consultar autorizações por código - - Consultar autorizações por intervalo de datas - - Consultar autorizações por código de notificação - - Consultar autorizações por código de referência - - Criar requisições de assinaturas - - Criar requisições de cancelamento de assinaturas - - Criar requisições de cobrança de assinaturas - - Consultar assinaturas por código - - Consultar assinaturas por intervalo de datas - - Consultar assinaturas por intervalo de dias - - Consultar assinaturas por código de notificação - - Receber notificações de autorizações - - Receber notificações de assinaturas - - Receber notificações de transações - - Criar requisições de checkout transparente utilizando boleto - - Criar requisições de checkout transparente utilizando debito online - - Criar requisições de checkout transparente utilizando cartão de crédito - - Criar requisições de checkout transparente utilizando cartão de crédito internacional - - Criar requisições de checkout transparente utilizando boleto com split payment - - Criar requisições de checkout transparente utilizando debito online com split payment - - Criar requisições de checkout transparente utilizando cartão de crédito com split payment - - Criar requisições de checkout transparente utilizando cartão de crédito internacional com split payment - - Atualização do código da biblioteca, aderindo ao uso de *namespaces*. - - Refatoração do código base. Licença ------- @@ -150,7 +127,7 @@ Achou e corrigiu um bug ou tem alguma feature em mente e deseja contribuir? * Obs.: Adicione exemplos para sua nova feature. Se seu Pull Request for relacionado a uma versão específica, o Pull Request não deve ser enviado para o branch master e sim para o branch correspondente a versão. * Obs2: Não serão aceitos PR's na branch master. Utilizar a branch de desenvolvimento. - + [requisições de assinaturas transparentes]: https://dev.pagseguro.uol.com.br/documentacao/pagamento-online/pagamentos/pagamento-recorrente-transparente [requisições de assinaturas]: http://download.uol.com.br/pagseguro/docs/pagseguro-assinatura-automatica.pdf [assinaturas]: http://download.uol.com.br/pagseguro/docs/pagseguro-assinatura-automatica.pdf [requisições de pagamentos]: https://dev.pagseguro.uol.com.br/documentacao/pagamentos @@ -169,5 +146,6 @@ Achou e corrigiu um bug ou tem alguma feature em mente e deseja contribuir? [Composer]: https://getcomposer.org [pagseguro/pagseguro-php-sdk]: https://packagist.org/packages/pagseguro/pagseguro-php-sdk [Como receber pagamentos pelo PagSeguro]: https://pagseguro.uol.com.br/receba-pagamentos.jhtml#checkout-transparent - - + [Composer]: https://getcomposer.org/ + [arquivo zip]: https://github.com/pagseguro/pagseguro-php-sdk/archive/master.zip + [documentação oficial do Composer]: https://getcomposer.org/doc/ diff --git a/lib/PagseguroPhpSdk/composer.json b/lib/PagseguroPhpSdk/composer.json index 39e0a8f..d427f50 100644 --- a/lib/PagseguroPhpSdk/composer.json +++ b/lib/PagseguroPhpSdk/composer.json @@ -13,6 +13,9 @@ "lib-curl": "*", "lib-openssl": "*" }, + "require-dev": { + "phpunit/phpunit": "^5.7" + }, "autoload": { "psr-4": { "PagSeguro\\": "source/" diff --git a/lib/PagseguroPhpSdk/public/Authorization/Search/searchAuthorizationByCode.php b/lib/PagseguroPhpSdk/public/Authorization/Search/searchAuthorizationByCode.php index 99da1bd..553f08b 100644 --- a/lib/PagseguroPhpSdk/public/Authorization/Search/searchAuthorizationByCode.php +++ b/lib/PagseguroPhpSdk/public/Authorization/Search/searchAuthorizationByCode.php @@ -4,7 +4,7 @@ \PagSeguro\Library::initialize(); -$code = 'FD3AF1B214EC40F0B0A6745D041BF50D'; +$code = '2ED002E234444A0D9469EF14F0D5A9C1'; try { $response = \PagSeguro\Services\Application\Search\Code::search( diff --git a/lib/PagseguroPhpSdk/public/Authorization/Search/searchAuthorizationByNotification.php b/lib/PagseguroPhpSdk/public/Authorization/Search/searchAuthorizationByNotification.php index a419e79..948d010 100644 --- a/lib/PagseguroPhpSdk/public/Authorization/Search/searchAuthorizationByNotification.php +++ b/lib/PagseguroPhpSdk/public/Authorization/Search/searchAuthorizationByNotification.php @@ -4,7 +4,7 @@ \PagSeguro\Library::initialize(); -$code = '7BD4A616E8C3E8C3F57BB440FFA9ABEAE6F2'; +$code = '7DD98273EB72EB7238388469DF9008F43A14'; try { $response = \PagSeguro\Services\Application\Search\Notification::search( diff --git a/lib/PagseguroPhpSdk/public/DirectPreApproval/accession.php b/lib/PagseguroPhpSdk/public/DirectPreApproval/accession.php new file mode 100644 index 0000000..b72a800 --- /dev/null +++ b/lib/PagseguroPhpSdk/public/DirectPreApproval/accession.php @@ -0,0 +1,45 @@ +setName("Nome")->setRelease("1.0.0"); +\PagSeguro\Library::moduleVersion()->setName("Nome")->setRelease("1.0.0"); +/** + * Para usa o ambiente de testes (sandbox) descomentar a linha abaixo + */ +//\PagSeguro\Configuration\Configure::setEnvironment('sandbox'); +//\PagSeguro\Configuration\Configure::setLog(true, '/var/www/git/pagseguro/pagseguro-php-sdk/Log.log'); + +$preApproval = new \PagSeguro\Domains\Requests\DirectPreApproval\Accession(); +$preApproval->setPlan('código do plano'); +$preApproval->setReference('referência da assinatura'); +$preApproval->setSender()->setName('nome');//assinante +$preApproval->setSender()->setEmail('email');//assinante +$preApproval->setSender()->setIp('ip');//assinante +$preApproval->setSender()->setAddress()->withParameters('logradouro', 'numero', 'bairro', 'cep', 'cidade', 'UF', + 'BRA');//assinante +$document = new \PagSeguro\Domains\DirectPreApproval\Document(); +$document->withParameters('CPF', 'cpf'); //assinante +$preApproval->setSender()->setDocuments($document); +$preApproval->setSender()->setPhone()->withParameters('ddd', 'telefone'); //assinante +$preApproval->setPaymentMethod()->setCreditCard()->setToken('token'); //token do cartão de crédito gerado via javascript +$preApproval->setPaymentMethod()->setCreditCard()->setHolder()->setName('Nome Teste'); //nome do titular do cartão de crédito +$preApproval->setPaymentMethod()->setCreditCard()->setHolder()->setBirthDate('10/10/1990'); //data de nascimento do titular do cartão de crédito +$document = new \PagSeguro\Domains\DirectPreApproval\Document(); +$document->withParameters('CPF', 'cpf'); //cpf do titular do cartão de crédito +$preApproval->setPaymentMethod()->setCreditCard()->setHolder()->setDocuments($document); +$preApproval->setPaymentMethod()->setCreditCard()->setHolder()->setPhone()->withParameters('ddd', 'telefone'); //telefone do titular do cartão de crédito +$preApproval->setPaymentMethod()->setCreditCard()->setHolder()->setBillingAddress()->withParameters('logradouro', 'numero', + 'bairro', 'cep', 'cidade', 'UF', 'BRA'); //endereço do titular do cartão de crédito + +try { + $response = $preApproval->register( + new \PagSeguro\Domains\AccountCredentials('email vendedor', 'token vendedor') // credencias do vendedor no pagseguro + ); + + echo '
';
+    print_r($response);
+} catch (Exception $e) {
+    die($e->getMessage());
+}
+
diff --git a/lib/PagseguroPhpSdk/public/DirectPreApproval/cancel.php b/lib/PagseguroPhpSdk/public/DirectPreApproval/cancel.php
new file mode 100644
index 0000000..045d9c3
--- /dev/null
+++ b/lib/PagseguroPhpSdk/public/DirectPreApproval/cancel.php
@@ -0,0 +1,25 @@
+setName("Nome")->setRelease("1.0.0");
+\PagSeguro\Library::moduleVersion()->setName("Nome")->setRelease("1.0.0");
+/**
+ *  Para usa o ambiente de testes (sandbox) descomentar a linha abaixo
+ */
+//\PagSeguro\Configuration\Configure::setEnvironment('sandbox');
+
+$status = new \PagSeguro\Domains\Requests\DirectPreApproval\Cancel();
+$status->setPreApprovalCode('EE3283468282A96AA4984FB4F7B40252');
+
+try {
+    $response = $status->register(
+	    new \PagSeguro\Domains\AccountCredentials('email vendedor', 'token vendedor') // credencias do vendedor no pagseguro
+    );
+
+    echo '
';
+    print_r($response);
+} catch (Exception $e) {
+    die($e->getMessage());
+}
+
diff --git a/lib/PagseguroPhpSdk/public/DirectPreApproval/changePayment.php b/lib/PagseguroPhpSdk/public/DirectPreApproval/changePayment.php
new file mode 100644
index 0000000..44ef2e2
--- /dev/null
+++ b/lib/PagseguroPhpSdk/public/DirectPreApproval/changePayment.php
@@ -0,0 +1,39 @@
+setName("Nome")->setRelease("1.0.0");
+\PagSeguro\Library::moduleVersion()->setName("Nome")->setRelease("1.0.0");
+/**
+ *  Para usa o ambiente de testes (sandbox) descomentar a linha abaixo
+ */
+//\PagSeguro\Configuration\Configure::setEnvironment('sandbox');
+
+$changePayment = new \PagSeguro\Domains\Requests\DirectPreApproval\ChangePayment();
+$changePayment->setPreApprovalCode('q213213123');
+/*
+ * usar setHash ou setIp
+ */
+//$changePayment->setSender()->setHash('asdasd');
+$changePayment->setSender()->setIp('ip');
+$changePayment->setCreditCard()->setToken('token'); //token do cartão de crédito gerado via javascript
+$changePayment->setCreditCard()->setHolder()->setName('Nome Teste'); //nome do titular do cartão de crédito
+$changePayment->setCreditCard()->setHolder()->setBirthDate('10/10/1990'); //data de nascimento do titular do cartão de crédito
+$document = new \PagSeguro\Domains\DirectPreApproval\Document();
+$document->withParameters('CPF', 'cpf');  //cpf do titular do cartão de crédito
+$changePayment->setCreditCard()->setHolder()->setDocuments($document);
+$changePayment->setCreditCard()->setHolder()->setPhone()->withParameters('ddd', 'telefone'); //telefone do titular do cartão de crédito
+$changePayment->setCreditCard()->setHolder()->setBillingAddress()->withParameters('logradouro', 'numero',
+	'bairro', 'cep', 'cidade', 'UF', 'BRA'); //endereço do titular do cartão de crédito
+
+try {
+    $response = $changePayment->register(
+	    new \PagSeguro\Domains\AccountCredentials('email vendedor', 'token vendedor') // credencias do vendedor no pagseguro
+    );
+
+    echo '
';
+    print_r($response);
+} catch (Exception $e) {
+    die($e->getMessage());
+}
+
diff --git a/lib/PagseguroPhpSdk/public/DirectPreApproval/createPlan.php b/lib/PagseguroPhpSdk/public/DirectPreApproval/createPlan.php
new file mode 100644
index 0000000..5195f02
--- /dev/null
+++ b/lib/PagseguroPhpSdk/public/DirectPreApproval/createPlan.php
@@ -0,0 +1,37 @@
+setName("Nome")->setRelease("1.0.0");
+\PagSeguro\Library::moduleVersion()->setName("Nome")->setRelease("1.0.0");
+/**
+ *  Para usa o ambiente de testes (sandbox) descomentar a linha abaixo
+ */
+//\PagSeguro\Configuration\Configure::setEnvironment('sandbox');
+
+$plan = new \PagSeguro\Domains\Requests\DirectPreApproval\Plan();
+$plan->setRedirectURL('http://meusite.com');
+$plan->setReference('http://meusite.com');
+$plan->setPreApproval()->setName('Plano XXXX');
+$plan->setPreApproval()->setCharge('AUTO');
+$plan->setPreApproval()->setPeriod('MONTHLY');
+$plan->setPreApproval()->setAmountPerPayment('100.00');
+$plan->setPreApproval()->setTrialPeriodDuration(28);
+$plan->setPreApproval()->setDetails('detalhes do plano');
+$plan->setPreApproval()->setFinalDate('2018-09-03');
+$plan->setPreApproval()->setCancelURL("http://meusite.com");
+$plan->setReviewURL('http://meusite.com./review');
+$plan->setMaxUses(100);
+$plan->setReceiver()->withParameters('exemplo@sandbox');
+
+try {
+    $response = $plan->register(
+	    new \PagSeguro\Domains\AccountCredentials('email vendedor', 'token vendedor') // credencias do vendedor no pagseguro
+    );
+
+    echo '
';
+    print_r($response);
+} catch (Exception $e) {
+    die($e->getMessage());
+}
+
diff --git a/lib/PagseguroPhpSdk/public/DirectPreApproval/discount.php b/lib/PagseguroPhpSdk/public/DirectPreApproval/discount.php
new file mode 100644
index 0000000..d89cf89
--- /dev/null
+++ b/lib/PagseguroPhpSdk/public/DirectPreApproval/discount.php
@@ -0,0 +1,27 @@
+setName("Nome")->setRelease("1.0.0");
+\PagSeguro\Library::moduleVersion()->setName("Nome")->setRelease("1.0.0");
+/**
+ *  Para usa o ambiente de testes (sandbox) descomentar a linha abaixo
+ */
+//\PagSeguro\Configuration\Configure::setEnvironment('sandbox');
+
+$status = new \PagSeguro\Domains\Requests\DirectPreApproval\Discount();
+$status->setPreApprovalCode('código da assinatura');
+$status->setType('DISCOUNT_PERCENT'); //tipo de desconto
+$status->setValue('10.00'); //valor do desconto
+
+try {
+    $response = $status->register(
+	    new \PagSeguro\Domains\AccountCredentials('email vendedor', 'token vendedor') // credencias do vendedor no pagseguro
+    );
+
+    echo '
';
+    print_r($response);
+} catch (Exception $e) {
+    die($e->getMessage());
+}
+
diff --git a/lib/PagseguroPhpSdk/public/DirectPreApproval/payment.php b/lib/PagseguroPhpSdk/public/DirectPreApproval/payment.php
new file mode 100644
index 0000000..390853d
--- /dev/null
+++ b/lib/PagseguroPhpSdk/public/DirectPreApproval/payment.php
@@ -0,0 +1,30 @@
+setName("Nome")->setRelease("1.0.0");
+\PagSeguro\Library::moduleVersion()->setName("Nome")->setRelease("1.0.0");
+/**
+ *  Para usa o ambiente de testes (sandbox) descomentar a linha abaixo
+ */
+//\PagSeguro\Configuration\Configure::setEnvironment('sandbox');
+
+$plan = new \PagSeguro\Domains\Requests\DirectPreApproval\Payment();
+$plan->setPreApprovalCode('código da assinatura');
+$plan->setReference('referência');
+$plan->setSenderIp('ip');
+$item = new \PagSeguro\Domains\DirectPreApproval\Item();
+$item->withParameters('id da assinatura', 'descrição da assinatura', 'quantidade', 'valor decimal');
+$plan->addItems($item);
+
+try {
+    $response = $plan->register(
+	    new \PagSeguro\Domains\AccountCredentials('email vendedor', 'token vendedor') // credencias do vendedor no pagseguro
+    );
+
+    echo '
';
+    print_r($response);
+} catch (Exception $e) {
+    die($e->getMessage());
+}
+
diff --git a/lib/PagseguroPhpSdk/public/DirectPreApproval/query.php b/lib/PagseguroPhpSdk/public/DirectPreApproval/query.php
new file mode 100644
index 0000000..56250d7
--- /dev/null
+++ b/lib/PagseguroPhpSdk/public/DirectPreApproval/query.php
@@ -0,0 +1,33 @@
+setName("Nome")->setRelease("1.0.0");
+\PagSeguro\Library::moduleVersion()->setName("Nome")->setRelease("1.0.0");
+/**
+ *  Para usa o ambiente de testes (sandbox) descomentar a linha abaixo
+ */
+//\PagSeguro\Configuration\Configure::setEnvironment('sandbox');
+
+/**
+ * @param $page
+ * @param $maxPageResults
+ * @param $initialDate
+ * @param $finalDate
+ * @param $status
+ * @param $preApprovalRequest
+ * @param $senderEmail
+ */
+$queryPreApproval = new \PagSeguro\Domains\Requests\DirectPreApproval\Query(null, null, '2017-08-01', '2017-08-02');
+
+try {
+    $response = $queryPreApproval->register(
+	    new \PagSeguro\Domains\AccountCredentials('email vendedor', 'token vendedor') // credencias do vendedor no pagseguro
+    );
+
+    echo '
';
+    print_r($response);
+} catch (Exception $e) {
+    die($e->getMessage());
+}
+
diff --git a/lib/PagseguroPhpSdk/public/DirectPreApproval/queryNotifications.php b/lib/PagseguroPhpSdk/public/DirectPreApproval/queryNotifications.php
new file mode 100644
index 0000000..2160540
--- /dev/null
+++ b/lib/PagseguroPhpSdk/public/DirectPreApproval/queryNotifications.php
@@ -0,0 +1,32 @@
+setName("Nome")->setRelease("1.0.0");
+\PagSeguro\Library::moduleVersion()->setName("Nome")->setRelease("1.0.0");
+/**
+ *  Para usa o ambiente de testes (sandbox) descomentar a linha abaixo
+ */
+//\PagSeguro\Configuration\Configure::setEnvironment('sandbox');
+
+/**
+ * QueryNotificationRequest constructor.
+ *
+ * @param int  $page
+ * @param int  $maxPageResults
+ * @param      $interval
+ * @param null $notificationCode
+ */
+$queryNotification = new \PagSeguro\Domains\Requests\DirectPreApproval\QueryNotification(null, null, 20, 'código da notificação');
+
+try {
+    $response = $queryNotification->register(
+	    new \PagSeguro\Domains\AccountCredentials('email vendedor', 'token vendedor') // credencias do vendedor no pagseguro
+    );
+
+    echo '
';
+    print_r($response);
+} catch (Exception $e) {
+    die($e->getMessage());
+}
+
diff --git a/lib/PagseguroPhpSdk/public/DirectPreApproval/queryPaymentOrder.php b/lib/PagseguroPhpSdk/public/DirectPreApproval/queryPaymentOrder.php
new file mode 100644
index 0000000..1b8a1d4
--- /dev/null
+++ b/lib/PagseguroPhpSdk/public/DirectPreApproval/queryPaymentOrder.php
@@ -0,0 +1,30 @@
+setName("Nome")->setRelease("1.0.0");
+\PagSeguro\Library::moduleVersion()->setName("Nome")->setRelease("1.0.0");
+/**
+ *  Para usa o ambiente de testes (sandbox) descomentar a linha abaixo
+ */
+//\PagSeguro\Configuration\Configure::setEnvironment('sandbox');
+
+/**
+ * @param $preApprovalCode
+ * @param $status
+ * @param $page
+ * @param $maxPageResults
+ */
+$queryPreApproval = new \PagSeguro\Domains\Requests\DirectPreApproval\QueryPaymentOrder('código da assinatura', 3);
+
+try {
+    $response = $queryPreApproval->register(
+	    new \PagSeguro\Domains\AccountCredentials('email vendedor', 'token vendedor') // credencias do vendedor no pagseguro
+    );
+
+    echo '
';
+    print_r($response);
+} catch (Exception $e) {
+    die($e->getMessage());
+}
+
diff --git a/lib/PagseguroPhpSdk/public/DirectPreApproval/retryPaymentOrder.php b/lib/PagseguroPhpSdk/public/DirectPreApproval/retryPaymentOrder.php
new file mode 100644
index 0000000..1b2de5a
--- /dev/null
+++ b/lib/PagseguroPhpSdk/public/DirectPreApproval/retryPaymentOrder.php
@@ -0,0 +1,26 @@
+setName("Nome")->setRelease("1.0.0");
+\PagSeguro\Library::moduleVersion()->setName("Nome")->setRelease("1.0.0");
+/**
+ *  Para usa o ambiente de testes (sandbox) descomentar a linha abaixo
+ */
+//\PagSeguro\Configuration\Configure::setEnvironment('sandbox');
+
+$plan = new \PagSeguro\Domains\Requests\DirectPreApproval\RetryPaymentOrder();
+$plan->setPreApprovalCode('código da assinatura');
+$plan->setPaymentOrderCode('código da ordem de pagamento');
+
+try {
+    $response = $plan->register(
+	    new \PagSeguro\Domains\AccountCredentials('email vendedor', 'token vendedor') // credencias do vendedor no pagseguro
+    );
+
+    echo '
';
+    print_r($response);
+} catch (Exception $e) {
+    die($e->getMessage());
+}
+
diff --git a/lib/PagseguroPhpSdk/public/DirectPreApproval/status.php b/lib/PagseguroPhpSdk/public/DirectPreApproval/status.php
new file mode 100644
index 0000000..a1e63db
--- /dev/null
+++ b/lib/PagseguroPhpSdk/public/DirectPreApproval/status.php
@@ -0,0 +1,26 @@
+setName("Nome")->setRelease("1.0.0");
+\PagSeguro\Library::moduleVersion()->setName("Nome")->setRelease("1.0.0");
+/**
+ *  Para usa o ambiente de testes (sandbox) descomentar a linha abaixo
+ */
+//\PagSeguro\Configuration\Configure::setEnvironment('sandbox');
+
+$status = new \PagSeguro\Domains\Requests\DirectPreApproval\Status();
+$status->setPreApprovalCode('CA2A46');
+$status->setStatus('SUPENDED');
+
+try {
+    $response = $status->register(
+	    new \PagSeguro\Domains\AccountCredentials('email vendedor', 'token vendedor') // credencias do vendedor no pagseguro
+    );
+
+    echo '
';
+    print_r($response);
+} catch (Exception $e) {
+    die($e->getMessage());
+}
+
diff --git a/lib/PagseguroPhpSdk/public/Split/usingBoleto.php b/lib/PagseguroPhpSdk/public/Split/usingBoleto.php
deleted file mode 100644
index 9d535e6..0000000
--- a/lib/PagseguroPhpSdk/public/Split/usingBoleto.php
+++ /dev/null
@@ -1,113 +0,0 @@
-setName("Nome")->setRelease("1.0.0");
-\PagSeguro\Library::moduleVersion()->setName("Nome")->setRelease("1.0.0");
-
-//Instantiate a new Boleto Object
-$boleto = new \PagSeguro\Domains\Requests\DirectPayment\Boleto();
-
-// Set the Payment Mode for this payment request
-$boleto->setMode('DEFAULT');
-
-// Set the currency
-$boleto->setCurrency("BRL");
-
-// Add an item for this payment request
-$boleto->addItems()->withParameters(
-    '0001',
-    'Notebook prata',
-    2,
-    130.00
-);
-
-// Add an item for this payment request
-$boleto->addItems()->withParameters(
-    '0002',
-    'Notebook preto',
-    2,
-    430.00
-);
-
-// Set a reference code for this payment request. It is useful to identify this payment
-// in future notifications.
-$boleto->setReference("LIBPHP000001");
-
-
-// Set your customer information.
-// If you using SANDBOX you must use an email @sandbox.pagseguro.com.br
-$boleto->setSender()->setName('João Comprador');
-$boleto->setSender()->setEmail('email@comprador.com.br');
-
-$boleto->setSender()->setPhone()->withParameters(
-    11,
-    56273440
-);
-
-$boleto->setSender()->setDocument()->withParameters(
-    'CPF',
-    'insira um numero de CPF valido'
-);
-
-$boleto->setSender()->setHash('3dc25e8a7cb3fd3104e77ae5ad0e7df04621caa33e300b27aeeb9ea1adf1a24f');
-
-$boleto->setSender()->setIp('127.0.0.0');
-
-// Set shipping information for this payment request
-$boleto->setShipping()->setAddress()->withParameters(
-    'Av. Brig. Faria Lima',
-    '1384',
-    'Jardim Paulistano',
-    '01452002',
-    'São Paulo',
-    'SP',
-    'BRA',
-    'apto. 114'
-);
-
-// Add a primary receiver for split this payment request
-$boleto->setSplit()->setPrimaryReceiver("PUBBD8F184FEE144EADA6DA746D61FAA688");
-
-// Add an receiver for split this payment request
-$boleto->setSplit()->addReceiver()->withParameters(
-    'PUBF0944ADDDD844957ABA278D8645A52C3',
-    200.00,
-    20,
-    0
-);
-
-try {
-    //Get the crendentials and register the boleto payment
-    $result = $boleto->register(
-        \PagSeguro\Configuration\Configure::getApplicationCredentials()
-    );
-
-    echo "
";
-    print_r($result);
-} catch (Exception $e) {
-    die($e->getMessage());
-}
diff --git a/lib/PagseguroPhpSdk/public/Split/usingCreditCard.php b/lib/PagseguroPhpSdk/public/Split/usingCreditCard.php
deleted file mode 100644
index 0eda5c0..0000000
--- a/lib/PagseguroPhpSdk/public/Split/usingCreditCard.php
+++ /dev/null
@@ -1,150 +0,0 @@
-setName("Nome")->setRelease("1.0.0");
-\PagSeguro\Library::moduleVersion()->setName("Nome")->setRelease("1.0.0");
-
-//Instantiate a new direct payment request, using Credit Card
-$creditCard = new \PagSeguro\Domains\Requests\DirectPayment\CreditCard();
-
-/**
- * @todo Change the receiver Email
- */
-$creditCard->setReceiverEmail('vendedor@lojamodelo.com.br');
-
-// Set a reference code for this payment request. It is useful to identify this payment
-// in future notifications.
-$creditCard->setReference("LIBPHP000001");
-
-// Set the currency
-$creditCard->setCurrency("BRL");
-
-// Add an item for this payment request
-$creditCard->addItems()->withParameters(
-    '0001',
-    'Notebook prata',
-    2,
-    10.00
-);
-
-// Add an item for this payment request
-$creditCard->addItems()->withParameters(
-    '0002',
-    'Notebook preto',
-    2,
-    5.00
-);
-
-// Set your customer information.
-// If you using SANDBOX you must use an email @sandbox.pagseguro.com.br
-$creditCard->setSender()->setName('João Comprador');
-$creditCard->setSender()->setEmail('email@comprador.com.br');
-
-$creditCard->setSender()->setPhone()->withParameters(
-    11,
-    56273440
-);
-
-$creditCard->setSender()->setDocument()->withParameters(
-    'CPF',
-    'insira um numero de CPF valido'
-);
-
-$creditCard->setSender()->setHash('d94d002b6998ca9cd69092746518e50aded5a54aef64c4877ccea02573694986');
-
-$creditCard->setSender()->setIp('127.0.0.0');
-
-// Set shipping information for this payment request
-$creditCard->setShipping()->setAddress()->withParameters(
-    'Av. Brig. Faria Lima',
-    '1384',
-    'Jardim Paulistano',
-    '01452002',
-    'São Paulo',
-    'SP',
-    'BRA',
-    'apto. 114'
-);
-
-//Set billing information for credit card
-$creditCard->setBilling()->setAddress()->withParameters(
-    'Av. Brig. Faria Lima',
-    '1384',
-    'Jardim Paulistano',
-    '01452002',
-    'São Paulo',
-    'SP',
-    'BRA',
-    'apto. 114'
-);
-
-// Set credit card token
-$creditCard->setToken('1fcb2333ca7c46e38089dd9f2cac525c');
-
-// Set the installment quantity and value (could be obtained using the Installments 
-// service, that have an example here in \public\getInstallments.php)
-$creditCard->setInstallment()->withParameters(1, '30.00');
-
-// Set the credit card holder information
-$creditCard->setHolder()->setBirthdate('01/10/1979');
-$creditCard->setHolder()->setName('João Comprador'); // Equals in Credit Card
-
-$creditCard->setHolder()->setPhone()->withParameters(
-    11,
-    56273440
-);
-
-$creditCard->setHolder()->setDocument()->withParameters(
-    'CPF',
-    'insira um numero de CPF valido'
-);
-
-// Set the Payment Mode for this payment request
-$creditCard->setMode('DEFAULT');
-
-// Add a primary receiver for split this payment request
-$creditCard->setSplit()->setPrimaryReceiver("PUBBD8F184FEE144EADA6DA746D61FAA688");
-
-// Add an receiver for split this payment request
-$creditCard->setSplit()->addReceiver()->withParameters(
-    'PUBF0944ADDDD844957ABA278D8645A52C3',
-    20.00,
-    20,
-    0
-);
-
-try {
-    //Get the crendentials and register the boleto payment
-    $result = $creditCard->register(
-        \PagSeguro\Configuration\Configure::getApplicationCredentials()
-    );
-    echo "
";
-    print_r($result);
-} catch (Exception $e) {
-    echo "
"; - die($e->getMessage()); -} diff --git a/lib/PagseguroPhpSdk/public/Split/usingInternationalCreditCard.php b/lib/PagseguroPhpSdk/public/Split/usingInternationalCreditCard.php deleted file mode 100644 index bf7b2f8..0000000 --- a/lib/PagseguroPhpSdk/public/Split/usingInternationalCreditCard.php +++ /dev/null @@ -1,113 +0,0 @@ -setName("Nome")->setRelease("1.0.0"); -\PagSeguro\Library::moduleVersion()->setName("Nome")->setRelease("1.0.0"); - -//Instantiate a new direct payment request, using Credit Card -$internationalCreditCard = new \PagSeguro\Domains\Requests\DirectPayment\InternationalCreditCard(); - -// Set the Payment Mode for this payment request -$internationalCreditCard->setMode('DEFAULT'); - -/** - * @todo Change the receiver Email - */ -$internationalCreditCard->setReceiverEmail('vendedor@lojamodelo.com.br'); - -// Set a reference code for this payment request. It is useful to identify this payment -// in future notifications. -$internationalCreditCard->setReference("LIBPHP000001"); - -// Set the currency -$internationalCreditCard->setCurrency("BRL"); - -// Add an item for this payment request -$internationalCreditCard->addItems()->withParameters( - '0001', - 'Notebook prata', - 2, - 10.00 -); - -// Add an item for this payment request -$internationalCreditCard->addItems()->withParameters( - '0002', - 'Notebook preto', - 2, - 5.00 -); - -// Set your customer information. -// If you using SANDBOX you must use an email @sandbox.pagseguro.com.br -$internationalCreditCard->setSender()->setName('João Comprador'); -$internationalCreditCard->setSender()->setEmail('comprador@email.combr'); - -$internationalCreditCard->setSender()->setPhone()->withParameters( - 11, - 56273440 -); - -$internationalCreditCard->setSender()->setDocument()->withParameters( - 'CPF', - 'insira um numero de CPF valido' -); - -$internationalCreditCard->setSender()->setHash('a2fd31b1024da2100d490d338aa3e2ade0a237b397a267177b8ff3ec88a06026'); - -$internationalCreditCard->setSender()->setIp('127.0.0.0'); - -// Set credit card token -$internationalCreditCard->setToken('5a0573d3f03143f29415793c285513ec'); - -// Set the installment quantity and value (could be obtained using the Installments -// service, that have an example here in \public\getInstallments.php) -$internationalCreditCard->setInstallment()->withParameters(1, '30.00'); - - -// Add a primary receiver for split this payment request -$internationalCreditCard->setSplit()->setPrimaryReceiver("PUBBD8F184FEE144EADA6DA746D61FAA688"); - -// Add an receiver for split this payment request -$internationalCreditCard->setSplit()->addReceiver()->withParameters( - 'PUBF0944ADDDD844957ABA278D8645A52C3', - 20.00, - 20, - 0 -); - -try { - //Get the crendentials and register the boleto payment - $result = $internationalCreditCard->register( - \PagSeguro\Configuration\Configure::getApplicationCredentials() - ); - echo "
";
-    print_r($result);
-} catch (Exception $e) {
-    echo "
"; - die($e->getMessage()); -} diff --git a/lib/PagseguroPhpSdk/public/Split/usingOnlineDebit.php b/lib/PagseguroPhpSdk/public/Split/usingOnlineDebit.php deleted file mode 100644 index f1c8770..0000000 --- a/lib/PagseguroPhpSdk/public/Split/usingOnlineDebit.php +++ /dev/null @@ -1,124 +0,0 @@ -setName("Nome")->setRelease("1.0.0"); -\PagSeguro\Library::moduleVersion()->setName("Nome")->setRelease("1.0.0"); - -//Instantiate a new Boleto Object -$onlineDebit = new \PagSeguro\Domains\Requests\DirectPayment\OnlineDebit(); - -// Set the Payment Mode for this payment request -$onlineDebit->setMode('DEFAULT'); - -// Set bank for this payment request -$onlineDebit->setBankName('nomedobanco'); - -/** - * @todo Change the receiver Email - */ -$onlineDebit->setReceiverEmail('vendedor@lojamodelo.com.br'); - -// Set a reference code for this payment request. It is useful to identify this payment -// in future notifications. -$onlineDebit->setReference("LIBPHP000001"); - -// Set the currency -$onlineDebit->setCurrency("BRL"); - -// Add an item for this payment request -$onlineDebit->addItems()->withParameters( - '0001', - 'Notebook prata', - 2, - 130.00 -); - -// Add an item for this payment request -$onlineDebit->addItems()->withParameters( - '0002', - 'Notebook preto', - 2, - 430.00 -); - -//set extra amount -$onlineDebit->setExtraAmount(11.5); - -// Set your customer information. -// If you using SANDBOX you must use an email @sandbox.pagseguro.com.br -$onlineDebit->setSender()->setName('João Comprador'); -$onlineDebit->setSender()->setEmail('email@comprador.com.br'); - -$onlineDebit->setSender()->setPhone()->withParameters( - 11, - 56273440 -); - -$onlineDebit->setSender()->setDocument()->withParameters( - 'CPF', - 'insira um numero de CPF valido' -); - -$onlineDebit->setSender()->setHash('3dc25e8a7cb3fd3104e77ae5ad0e7df04621caa33e300b27aeeb9ed5fdf1a24f'); - -$onlineDebit->setSender()->setIp('127.0.0.0'); - -// Set shipping information for this payment request -$onlineDebit->setShipping()->setAddress()->withParameters( - 'Av. Brig. Faria Lima', - '1384', - 'Jardim Paulistano', - '01452002', - 'São Paulo', - 'SP', - 'BRA', - 'apto. 114' -); - -// Add a primary receiver for split this payment request -$onlineDebit->setSplit()->setPrimaryReceiver("PUBBD8F184FEE144EADA6DA746D61FAA688"); - -// Add an receiver for split this payment request -$onlineDebit->setSplit()->addReceiver()->withParameters( - 'PUBF0944ADDDD844957ABA278D8645A52C3', - 200.00, - 20, - 0 -); - -try { - //Get the crendentials and register the boleto payment - $result = $onlineDebit->register( - \PagSeguro\Configuration\Configure::getApplicationCredentials() - ); - - echo "
";
-    print_r($result);
-} catch (Exception $e) {
-    echo "
"; - die($e->getMessage()); -} diff --git a/lib/PagseguroPhpSdk/public/Transactions/Search/searchTransactionByCode.php b/lib/PagseguroPhpSdk/public/Transactions/Search/searchTransactionByCode.php index 231dc16..4b59659 100644 --- a/lib/PagseguroPhpSdk/public/Transactions/Search/searchTransactionByCode.php +++ b/lib/PagseguroPhpSdk/public/Transactions/Search/searchTransactionByCode.php @@ -4,7 +4,7 @@ \PagSeguro\Library::initialize(); -$code = '0B64FD7B4F9641378E9C9462982A8B95'; +$code = '8F17A22C51C641C1B6A40AF8C2FF94E2'; try { $response = \PagSeguro\Services\Transactions\Search\Code::search( diff --git a/lib/PagseguroPhpSdk/public/Transactions/Search/searchTransactionByDate.php b/lib/PagseguroPhpSdk/public/Transactions/Search/searchTransactionByDate.php index 98c40dc..e92a0b0 100644 --- a/lib/PagseguroPhpSdk/public/Transactions/Search/searchTransactionByDate.php +++ b/lib/PagseguroPhpSdk/public/Transactions/Search/searchTransactionByDate.php @@ -5,8 +5,8 @@ \PagSeguro\Library::initialize(); $options = [ - 'initial_date' => '2016-04-01T14:55', - 'final_date' => '2016-04-24T09:55', //Optional + 'initial_date' => '2017-07-19T14:55', + 'final_date' => '2017-08-18T09:55', //Optional 'page' => 1, //Optional 'max_per_page' => 20, //Optional ]; diff --git a/lib/PagseguroPhpSdk/source/Configuration/Properties/Resources.xml b/lib/PagseguroPhpSdk/source/Configuration/Properties/Resources.xml index 06a2de3..5125399 100644 --- a/lib/PagseguroPhpSdk/source/Configuration/Properties/Resources.xml +++ b/lib/PagseguroPhpSdk/source/Configuration/Properties/Resources.xml @@ -95,12 +95,44 @@ v2/pre-approvals - + + pre-approvals + + pre-approvals + + + pre-approvals/request + + + pre-approvals + + + pre-approvals/payment + + + pre-approvals + + + pre-approvals + + + pre-approvals + + + pre-approvals + + + pre-approvals + + + pre-approvals/notifications + + + pre-approvals + + - transactions/ + v2/transactions/ diff --git a/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Address.php b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Address.php new file mode 100644 index 0000000..cad04e0 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Address.php @@ -0,0 +1,100 @@ +street = $street; + $this->number = $number; + $this->district = $district; + $this->postalCode = $postalCode; + $this->city = $city; + $this->state = $state; + $this->country = $country; + $this->complement = $complement; + + return $this; + } +} \ No newline at end of file diff --git a/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/BillingAddress.php b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/BillingAddress.php new file mode 100644 index 0000000..7c07a1e --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/BillingAddress.php @@ -0,0 +1,34 @@ +split = InitializeObject::initialize($this->split, '\PagSeguro\Domains\Split'); - return new \PagSeguro\Domains\Requests\Adapter\Split($this->split); + $this->ip = $ip; + + return $this; } /** - * @return mixed + * @param $hash + * + * @return $this */ - public function getSplit() + public function setHash($hash) { - return $this->split; + $this->hash = $hash; + + return $this; } -} +} \ No newline at end of file diff --git a/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/CreditCard.php b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/CreditCard.php new file mode 100644 index 0000000..f7bcac9 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/CreditCard.php @@ -0,0 +1,66 @@ +holder = new Holder(); + } + + /** + * @param $token + */ + public function setToken($token) + { + $this->token = $token; + } + + /** + * @return Holder + */ + public function setHolder() + { + return $this->holder; + } +} \ No newline at end of file diff --git a/lib/PagseguroPhpSdk/source/Domains/Requests/Adapter/Split.php b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Document.php similarity index 66% rename from lib/PagseguroPhpSdk/source/Domains/Requests/Adapter/Split.php rename to lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Document.php index 5475b12..c9de17d 100644 --- a/lib/PagseguroPhpSdk/source/Domains/Requests/Adapter/Split.php +++ b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Document.php @@ -22,31 +22,37 @@ * */ -namespace PagSeguro\Domains\Requests\Adapter; - -use PagSeguro\Domains\Requests\Split\Primary; -use PagSeguro\Domains\Requests\Split\Receiver; +namespace PagSeguro\Domains\DirectPreApproval; /** - * Class Split - * @package PagSeguro\Domains\Requests\Adapter + * Class Document + * + * @package PagSeguro\Domains\DirectPreApproval */ -class Split +class Document { - use Receiver; - use Primary; - /** * @var */ - private $split; + public $type; + /** + * @var + */ + public $value; /** - * Split constructor. - * @param $split + * @param $type + * @param $value + * + * @return $this */ - public function __construct($split) - { - $this->split = $split; + public function withParameters( + $type, + $value + ) { + $this->type = $type; + $this->value = $value; + + return $this; } -} +} \ No newline at end of file diff --git a/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Expiration.php b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Expiration.php new file mode 100644 index 0000000..f57e6ef --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Expiration.php @@ -0,0 +1,58 @@ +value = $value; + $this->unit = $unit; + + return $this; + } +} \ No newline at end of file diff --git a/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Holder.php b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Holder.php new file mode 100644 index 0000000..5c869b1 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Holder.php @@ -0,0 +1,116 @@ +billingAddress = new BillingAddress(); + } + + /** + * @param $name + * + * @return $this + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * @param $birthDate + * + * @return $this + */ + public function setBirthDate($birthDate) + { + $this->birthDate = $birthDate; + + return $this; + } + + /** + * @param Document $document + * + * @return $this + */ + public function setDocuments(Document $document) + { + $this->documents[] = $document; + + return $this; + } + + /** + * @return Phone + */ + public function setPhone() + { + $this->phone = new Phone(); + + return $this->phone; + } + + /** + * @return BillingAddress + */ + public function setBillingAddress() + { + return $this->billingAddress; + } +} \ No newline at end of file diff --git a/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Item.php b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Item.php new file mode 100644 index 0000000..3b003a4 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Item.php @@ -0,0 +1,80 @@ +id = $id; + $this->description = $description; + $this->quantity = $quantity; + $this->amount = $amount; + $this->weight = $weight; + $this->shippingCost = $shippingCost; + + return $this; + } +} \ No newline at end of file diff --git a/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/PaymentMethod.php b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/PaymentMethod.php new file mode 100644 index 0000000..86d496a --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/PaymentMethod.php @@ -0,0 +1,58 @@ +creditCard = new CreditCard(); + } + + /** + * @return CreditCard + */ + public function setCreditCard() + { + return $this->creditCard; + } +} \ No newline at end of file diff --git a/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Phone.php b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Phone.php new file mode 100644 index 0000000..ee5dec7 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Phone.php @@ -0,0 +1,58 @@ +areaCode = $areaCode; + $this->number = $number; + + return $this; + } +} \ No newline at end of file diff --git a/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Plan.php b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Plan.php new file mode 100644 index 0000000..5ef0d80 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Plan.php @@ -0,0 +1,115 @@ +preApproval = new PreApproval(); + $this->receiver = new Receiver(); + } + + /** + * @param $redirectURL + */ + public function setRedirectURL($redirectURL) + { + $this->redirectURL = $redirectURL; + } + + /** + * @param $reference + */ + function setReference($reference) + { + $this->reference = $reference; + } + + /** + * @return PreApproval + */ + public function setPreApproval() + { + return $this->preApproval; + } + + /** + * @param $reviewURL + */ + public function setReviewURL($reviewURL) + { + $this->reviewURL = $reviewURL; + } + + /** + * @param $maxUsers + */ + public function setMaxUsers($maxUsers) + { + $this->maxUsers = $maxUsers; + } + + /** + * @return Receiver + */ + public function setReceiver() + { + return $this->receiver; + } +} \ No newline at end of file diff --git a/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/PreApproval.php b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/PreApproval.php new file mode 100644 index 0000000..a4291af --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/PreApproval.php @@ -0,0 +1,258 @@ +expiration = new Expiration(); + } + + /** + * @param $name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * @param $charge + */ + public function setCharge($charge) + { + $this->charge = $charge; + } + + /** + * @param $period + */ + public function setPeriod($period) + { + $this->period = $period; + } + + /** + * @param $amountPerPayment + */ + public function setAmountPerPayment($amountPerPayment) + { + $this->amountPerPayment = $amountPerPayment; + } + + /** + * @param $membershipFee + */ + public function setMembershipFee($membershipFee) + { + $this->membershipFee = $membershipFee; + } + + /** + * @param $trialPeriodDuration + */ + public function setTrialPeriodDuration($trialPeriodDuration) + { + $this->trialPeriodDuration = $trialPeriodDuration; + } + + /** + * @return Expiration + */ + public function setExpiration() + { + return $this->expiration; + } + + /** + * @param $details + */ + public function setDetails($details) + { + $this->details = $details; + } + + /** + * @param $maxAmountPerPeriod + */ + public function setMaxAmountPerPeriod($maxAmountPerPeriod) + { + $this->maxAmountPerPeriod = $maxAmountPerPeriod; + } + + /** + * @param $maxAmountPerPayment + */ + public function setMaxAmountPerPayment($maxAmountPerPayment) + { + $this->maxAmountPerPayment = $maxAmountPerPayment; + } + + /** + * @param $maxTotalAmount + */ + public function setMaxTotalAmount($maxTotalAmount) + { + $this->maxTotalAmount = $maxTotalAmount; + } + + /** + * @param $maxPaymentsPerPeriod + */ + public function setMaxPaymentsPerPeriod($maxPaymentsPerPeriod) + { + $this->maxPaymentsPerPeriod = $maxPaymentsPerPeriod; + } + + /** + * @param $initialDate + */ + public function setInitialDate($initialDate) + { + $this->initialDate = $initialDate; + } + + /** + * @param $finalDate + */ + public function setFinalDate($finalDate) + { + $this->finalDate = $finalDate; + } + + /** + * @param $dayOfYear + */ + public function setDayOfYear($dayOfYear) + { + $this->dayOfYear = $dayOfYear; + } + + /** + * @param $dayOfMonth + */ + public function setDayOfMonth($dayOfMonth) + { + $this->dayOfMonth = $dayOfMonth; + } + + /** + * @param $dayOfWeek + */ + public function setDayOfWeek($dayOfWeek) + { + $this->dayOfWeek = $dayOfWeek; + } + + /** + * @param $cancelURL + */ + public function setCancelURL($cancelURL) + { + $this->cancelURL = $cancelURL; + } +} \ No newline at end of file diff --git a/lib/PagseguroPhpSdk/source/Domains/Requests/Split/Primary.php b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Receiver.php similarity index 69% rename from lib/PagseguroPhpSdk/source/Domains/Requests/Split/Primary.php rename to lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Receiver.php index 600b0ca..d32a6cd 100644 --- a/lib/PagseguroPhpSdk/source/Domains/Requests/Split/Primary.php +++ b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Receiver.php @@ -22,27 +22,29 @@ * */ -namespace PagSeguro\Domains\Requests\Split; +namespace PagSeguro\Domains\DirectPreApproval; /** * Class Receiver - * @package PagSeguro\Domains\Requests\Split + * + * @package PagSeguro\Domains\DirectPreApproval */ -trait Primary +class Receiver { /** - * @return mixed + * @var */ - public function getPrimaryReceiver() - { - return $this->split->primaryReceiver; - } + public $email; /** - * @param mixed $primaryReceiver + * @param $email + * + * @return $this */ - public function setPrimaryReceiver($primaryReceiver) + public function withParameters($email) { - $this->split->setPrimaryReceiver($primaryReceiver); + $this->email = $email; + + return $this; } -} +} \ No newline at end of file diff --git a/lib/PagseguroPhpSdk/source/Domains/Split/Receiver.php b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Sender.php similarity index 50% rename from lib/PagseguroPhpSdk/source/Domains/Split/Receiver.php rename to lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Sender.php index 66ce9b8..8430b34 100644 --- a/lib/PagseguroPhpSdk/source/Domains/Split/Receiver.php +++ b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Sender.php @@ -22,100 +22,121 @@ * */ -namespace PagSeguro\Domains\Split; +namespace PagSeguro\Domains\DirectPreApproval; /** - * Class Receiver - * @package PagSeguro\Domains + * Class Sender + * + * @package PagSeguro\Domains\DirectPreApproval */ -class Receiver +class Sender { /** * @var */ - private $publicKey; + public $name; /** * @var */ - private $amount; + public $email; /** * @var */ - private $ratePercent; + public $ip; /** * @var */ - private $feePercent; - + public $hash; /** - * @return mixed + * @var */ - public function getAmount() - { - return $this->amount; - } + public $phone; + /** + * @var + */ + public $documents; + /** + * @var + */ + public $address; /** - * @param mixed $amount - * @return Receiver + * @param $name + * + * @return $this */ - public function setAmount($amount) + public function setName($name) { - $this->amount = $amount; + $this->name = $name; + return $this; } /** - * @return mixed + * @param $email + * + * @return $this */ - public function getFeePercent() + public function setEmail($email) { - return $this->feePercent; + $this->email = $email; + + return $this; } /** - * @param mixed $feePercent - * @return Receiver + * @param $ip + * + * @return $this */ - public function setFeePercent($feePercent) + public function setIp($ip) { - $this->feePercent = $feePercent; + $this->ip = $ip; + return $this; } /** - * @return mixed + * @param $hash + * + * @return $this */ - public function getPublicKey() + public function setHash($hash) { - return $this->publicKey; + $this->hash = $hash; + + return $this; } /** - * @param mixed $publicKey - * @return Receiver + * @return Phone */ - public function setPublicKey($publicKey) + public function setPhone() { - $this->publicKey = $publicKey; - return $this; + $this->phone = new Phone(); + + return $this->phone; } /** - * @return mixed + * @param Document $document + * + * @return $this */ - public function getRatePercent() + public function setDocuments(Document $document) { - return $this->ratePercent; + $this->documents[] = $document; + + return $this; } /** - * @param mixed $ratePercent - * @return Receiver + * @return Address */ - public function setRatePercent($ratePercent) + public function setAddress() { - $this->ratePercent = $ratePercent; - return $this; + $this->address = new Address(); + + return $this->address; } -} +} \ No newline at end of file diff --git a/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Traits/ParserTrait.php b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Traits/ParserTrait.php new file mode 100644 index 0000000..8b86b41 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Domains/DirectPreApproval/Traits/ParserTrait.php @@ -0,0 +1,52 @@ + $value) { + $result[$key] = $this->object_to_array($value); + } + + return $result; + } + + return $data; + } +} \ No newline at end of file diff --git a/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPayment/Boleto/Request.php b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPayment/Boleto/Request.php index 03b17c1..9b2f0b5 100644 --- a/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPayment/Boleto/Request.php +++ b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPayment/Boleto/Request.php @@ -34,7 +34,6 @@ use PagSeguro\Domains\Requests\Reference; use PagSeguro\Domains\Requests\Requests; use PagSeguro\Domains\Requests\Shipping; -use PagSeguro\Domains\Requests\Split; /** * Class Request @@ -54,7 +53,6 @@ class Request implements Requests use ReceiverEmail; use Sender; use Shipping; - use Split; use Reference; use Redirect { Redirect::getUrl as getRedirectUrl; diff --git a/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPayment/CreditCard/Request.php b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPayment/CreditCard/Request.php index 6c304c4..b76b69b 100644 --- a/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPayment/CreditCard/Request.php +++ b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPayment/CreditCard/Request.php @@ -36,7 +36,6 @@ use PagSeguro\Domains\Requests\Reference; use PagSeguro\Domains\Requests\Requests; use PagSeguro\Domains\Requests\Shipping; -use PagSeguro\Domains\Requests\Split; /** * Class Request @@ -59,7 +58,6 @@ class Request implements Requests use ReceiverEmail; use Sender; use Shipping; - use Split; use Reference; use Redirect { Redirect::getUrl as getRedirectUrl; diff --git a/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPayment/InternationalCreditCard/Request.php b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPayment/InternationalCreditCard/Request.php index a13374a..8ad7708 100644 --- a/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPayment/InternationalCreditCard/Request.php +++ b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPayment/InternationalCreditCard/Request.php @@ -35,7 +35,6 @@ use PagSeguro\Domains\Requests\Redirect; use PagSeguro\Domains\Requests\Reference; use PagSeguro\Domains\Requests\Requests; -use PagSeguro\Domains\Requests\Split; /** * The Request Class for International Credit Card direct payments @@ -55,7 +54,6 @@ class Request implements Requests } use ReceiverEmail; use Sender; - use Split; use Reference; use Redirect { Redirect::getUrl as getRedirectUrl; diff --git a/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPayment/OnlineDebit/Request.php b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPayment/OnlineDebit/Request.php index e150f17..df76555 100644 --- a/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPayment/OnlineDebit/Request.php +++ b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPayment/OnlineDebit/Request.php @@ -34,7 +34,6 @@ use PagSeguro\Domains\Requests\Reference; use PagSeguro\Domains\Requests\Requests; use PagSeguro\Domains\Requests\Shipping; -use PagSeguro\Domains\Requests\Split; /** * Class Request @@ -54,7 +53,6 @@ class Request implements Requests use ReceiverEmail; use Sender; use Shipping; - use Split; use Reference; use Redirect { Redirect::getUrl as getRedirectUrl; diff --git a/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/Accession.php b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/Accession.php new file mode 100644 index 0000000..5ff5718 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/Accession.php @@ -0,0 +1,45 @@ +paymentMethod = new PaymentMethod(); + $this->sender = new Sender(); + } + + /** + * @param $plan + */ + public function setPlan($plan) + { + $this->plan = $plan; + } + + /** + * @param $reference + */ + public function setReference($reference) + { + $this->reference = $reference; + } + + /** + * @return PaymentMethod + */ + public function setPaymentMethod() + { + return $this->paymentMethod; + } + + /** + * @return Sender + */ + public function setSender() + { + return $this->sender; + } +} diff --git a/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/Cancel.php b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/Cancel.php new file mode 100644 index 0000000..be110a4 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/Cancel.php @@ -0,0 +1,45 @@ +preApprovalCode = $preApprovalCode; + } +} diff --git a/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/ChangePayment.php b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/ChangePayment.php new file mode 100644 index 0000000..ba6dc7c --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/ChangePayment.php @@ -0,0 +1,45 @@ +type = 'CREDITCARD'; + $this->creditCard = new CreditCard(); + $this->sender = new ChangePlanSender(); + } + + /** + * @return CreditCard + */ + public function setCreditCard() + { + return $this->creditCard; + } + + /** + * @return ChangePlanSender + */ + public function setSender() + { + return $this->sender; + } + + /** + * @param $preApprovalCode + */ + public function setPreApprovalCode($preApprovalCode) + { + $this->preApprovalCode = $preApprovalCode; + } +} diff --git a/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/Discount.php b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/Discount.php new file mode 100644 index 0000000..7c92dda --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/Discount.php @@ -0,0 +1,45 @@ +type = $type; + } + + /** + * @param $value + */ + public function setValue($value) + { + $this->value = $value; + } + + /** + * @param $preApprovalCode + */ + public function setPreApprovalCode($preApprovalCode) + { + $this->preApprovalCode = $preApprovalCode; + } +} diff --git a/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/Payment.php b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/Payment.php new file mode 100644 index 0000000..8bd1120 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/Payment.php @@ -0,0 +1,45 @@ +items = []; + } + + /** + * @param $preApprovalCode + */ + public function setPreApprovalCode($preApprovalCode) + { + $this->preApprovalCode = $preApprovalCode; + } + + /** + * @param $reference + */ + public function setReference($reference) + { + $this->reference = $reference; + } + + /** + * @param $senderHash + */ + public function setSenderHash($senderHash) + { + $this->senderHash = $senderHash; + } + + /** + * @param $senderIp + */ + public function setSenderIp($senderIp) + { + $this->senderIp = $senderIp; + } + + /** + * @param Item $item + * + * @return array + */ + public function addItems(Item $item) + { + $this->items[] = $item; + + return $this->items; + } +} diff --git a/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/Plan.php b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/Plan.php new file mode 100644 index 0000000..c848d60 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/Plan.php @@ -0,0 +1,45 @@ +preApproval = new PreApproval(); + $this->receiver = new Receiver(); + } + + /** + * @param $redirectURL + */ + public function setRedirectURL($redirectURL) + { + $this->redirectURL = $redirectURL; + } + + /** + * @param $reference + */ + function setReference($reference) + { + $this->reference = $reference; + } + + /** + * @return PreApproval + */ + public function setPreApproval() + { + return $this->preApproval; + } + + /** + * @param $reviewURL + */ + public function setReviewURL($reviewURL) + { + $this->reviewURL = $reviewURL; + } + + /** + * @param $maxUsers + */ + public function setMaxUses($maxUsers) + { + $this->maxUses = $maxUsers; + } + + /** + * @return Receiver + */ + public function setReceiver() + { + return $this->receiver; + } +} diff --git a/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/Query.php b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/Query.php new file mode 100644 index 0000000..3cf8680 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/Query.php @@ -0,0 +1,45 @@ +page = $page; + $this->maxPageResults = $maxPageResults; + $this->interval = $interval; + $this->notificationCode = $notificationCode; + } +} diff --git a/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/QueryPaymentOrder.php b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/QueryPaymentOrder.php new file mode 100644 index 0000000..7c61a50 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/QueryPaymentOrder.php @@ -0,0 +1,45 @@ +preApprovalCode = $preApprovalCode; + $this->status = $status; + $this->page = $page; + $this->maxPageResults = $maxPageResults; + } +} diff --git a/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/QueryRequest.php b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/QueryRequest.php new file mode 100644 index 0000000..5885640 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/QueryRequest.php @@ -0,0 +1,101 @@ +page = $page; + $this->maxPageResults = $maxPageResults; + $this->initialDate = gmdate('Y-m-d\TH:i:s.z\T\Z\D', strtotime($initialDate)); + $this->finalDate = gmdate('Y-m-d\TH:i:s.z\T\Z\D', strtotime($finalDate)); + $this->status = $status; + $this->preApprovalRequest = $preApprovalRequest; + $this->senderEmail = $senderEmail; + $this->preApprovalCode = $preApprovalCode; + } +} diff --git a/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/RetryPaymentOrder.php b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/RetryPaymentOrder.php new file mode 100644 index 0000000..e9740b8 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/RetryPaymentOrder.php @@ -0,0 +1,45 @@ +preApprovalCode = $preApprovalCode; + } + + /** + * @param mixed $paymentOrderCode + */ + public function setPaymentOrderCode($paymentOrderCode) + { + $this->paymentOrderCode = $paymentOrderCode; + } +} diff --git a/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/Status.php b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/Status.php new file mode 100644 index 0000000..efd77bb --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Domains/Requests/DirectPreApproval/Status.php @@ -0,0 +1,45 @@ +status = $status; + } + + /** + * @param $preApprovalCode + */ + public function setPreApprovalCode($preApprovalCode) + { + $this->preApprovalCode = $preApprovalCode; + } +} diff --git a/lib/PagseguroPhpSdk/source/Domains/Requests/Split/Receiver.php b/lib/PagseguroPhpSdk/source/Domains/Requests/Split/Receiver.php deleted file mode 100644 index 842e669..0000000 --- a/lib/PagseguroPhpSdk/source/Domains/Requests/Split/Receiver.php +++ /dev/null @@ -1,82 +0,0 @@ -receivers = new \PagSeguro\Resources\Factory\Split\Receiver($this->split); - return $this->receivers; - } - - /** - * @param $receivers - */ - public function setReceivers($receivers) - { - if (is_array($receivers)) { - $arr = array(); - foreach ($receivers as $key => $receiver) { - if ($receiver instanceof \PagSeguro\Domains\Split\Receiver) { - $arr[$key] = $receiver; - } else { - if (is_array($receiver)) { - $arr[$key] = new \PagSeguro\Domains\Split\Receiver($receiver); - } - } - } - $this->receivers = $arr; - } - } - - /** - * @return mixed - */ - public function getReceivers() - { - return current($this->receivers); - } - - /** - * @return int - */ - public function receiverLenght() - { - return count(current($this->receivers)); - } -} diff --git a/lib/PagseguroPhpSdk/source/Domains/Split.php b/lib/PagseguroPhpSdk/source/Domains/Split.php deleted file mode 100644 index 831147c..0000000 --- a/lib/PagseguroPhpSdk/source/Domains/Split.php +++ /dev/null @@ -1,84 +0,0 @@ -primaryReceiver; - } - - /** - * @param mixed $primaryReceiver - */ - public function setPrimaryReceiver($primaryReceiver) - { - $this->primaryReceiver = $primaryReceiver; - } - - /** - * @return mixed - */ - public function getReceivers() - { - return $this->receivers; - } - - /** - * @param mixed $receivers - */ - public function setReceivers($receivers) - { - if (is_array($receivers)) { - $arr = array(); - foreach ($receivers as $receiver) { - if ($receiver instanceof \PagSeguro\Domains\Split\Receiver) { - $arr[] = $receiver; - } - } - $this->receivers[] = $receivers; - } elseif ($receivers instanceof \PagSeguro\Domains\Split\Receiver) { - $this->receivers[] = $receivers; - } - } -} diff --git a/lib/PagseguroPhpSdk/source/Enum/Address.php b/lib/PagseguroPhpSdk/source/Enum/Address.php index 96eced8..0706fde 100644 --- a/lib/PagseguroPhpSdk/source/Enum/Address.php +++ b/lib/PagseguroPhpSdk/source/Enum/Address.php @@ -63,7 +63,7 @@ class Address extends Enum /** * Acronym for Espírito Santo */ - const ES = 'Espírito Santos'; + const ES = 'Espírito Santo'; /** * Acronym for Goiás diff --git a/lib/PagseguroPhpSdk/source/Enum/PaymentMethod/Name.php b/lib/PagseguroPhpSdk/source/Enum/PaymentMethod/Name.php index 686eef2..b71d100 100644 --- a/lib/PagseguroPhpSdk/source/Enum/PaymentMethod/Name.php +++ b/lib/PagseguroPhpSdk/source/Enum/PaymentMethod/Name.php @@ -24,10 +24,6 @@ namespace PagSeguro\Enum\PaymentMethod; -/** - * Class Name - * @package PagSeguro\Enum\PaymentMethod\Config - */ /** * Class Name * @package PagSeguro\Enum\PaymentMethod @@ -59,11 +55,6 @@ class Name */ const DEBITO_BANRISUL = "DEBITO_BANRISUL"; - /** - * Débito HSBC - */ - const DEBITO_HSBC = "DEBITO_HSBC"; - /** * Boleto */ diff --git a/lib/PagseguroPhpSdk/source/Enum/Properties/BackwardCompatibility.php b/lib/PagseguroPhpSdk/source/Enum/Properties/BackwardCompatibility.php index 6d8da0c..a71e845 100644 --- a/lib/PagseguroPhpSdk/source/Enum/Properties/BackwardCompatibility.php +++ b/lib/PagseguroPhpSdk/source/Enum/Properties/BackwardCompatibility.php @@ -191,21 +191,6 @@ class BackwardCompatibility */ const RECEIVER_PUBLIC_KEY = "receiver[%s].publicKey"; - /** - * Receiver split amount - */ - const RECEIVER_SPLIT_AMOUNT = "receiver[%s].split.amount"; - - /** - * Receiver split rate percent - */ - const RECEIVER_SPLIT_RATE_PERCENT = "receiver[%s].split.ratePercent"; - - /** - * Receiver split fee percent - */ - const RECEIVER_SPLIT_FEE_PERCENT = "receiver[%s].split.feePercent"; - /** * Redirect Url */ diff --git a/lib/PagseguroPhpSdk/source/Parsers/DirectPayment/Boleto/Request.php b/lib/PagseguroPhpSdk/source/Parsers/DirectPayment/Boleto/Request.php index 5977984..33200fc 100644 --- a/lib/PagseguroPhpSdk/source/Parsers/DirectPayment/Boleto/Request.php +++ b/lib/PagseguroPhpSdk/source/Parsers/DirectPayment/Boleto/Request.php @@ -29,7 +29,7 @@ * * @package PagSeguro\Parsers\DirectPayment\Boleto */ -use PagSeguro\Enum\Properties\BackwardCompatibility; +use PagSeguro\Enum\Properties\Current; use PagSeguro\Parsers\Basic; use PagSeguro\Parsers\Currency; use PagSeguro\Parsers\DirectPayment\Mode; @@ -39,7 +39,6 @@ use PagSeguro\Parsers\ReceiverEmail; use PagSeguro\Parsers\Sender; use PagSeguro\Parsers\Shipping; -use PagSeguro\Parsers\Split; use PagSeguro\Resources\Http; use PagSeguro\Parsers\Transaction\Boleto\Response; @@ -66,7 +65,7 @@ public static function getData(\PagSeguro\Domains\Requests\DirectPayment\Boleto { $data = []; - $properties = new BackwardCompatibility(); + $properties = new Current(); return array_merge( $data, @@ -76,7 +75,6 @@ public static function getData(\PagSeguro\Domains\Requests\DirectPayment\Boleto Method::getData($properties), Mode::getData($boleto, $properties), ReceiverEmail::getData($boleto, $properties), - Split::getData($boleto, $properties), Sender::getData($boleto, $properties), Shipping::getData($boleto, $properties) ); diff --git a/lib/PagseguroPhpSdk/source/Parsers/DirectPayment/CreditCard/Request.php b/lib/PagseguroPhpSdk/source/Parsers/DirectPayment/CreditCard/Request.php index 0927558..72e453f 100644 --- a/lib/PagseguroPhpSdk/source/Parsers/DirectPayment/CreditCard/Request.php +++ b/lib/PagseguroPhpSdk/source/Parsers/DirectPayment/CreditCard/Request.php @@ -28,7 +28,6 @@ * Request from the Credit Card direct payment * @package PagSeguro\Parsers\DirectPayment\CreditCard */ -use PagSeguro\Enum\Properties\BackwardCompatibility; use PagSeguro\Enum\Properties\Current; use PagSeguro\Parsers\Basic; use PagSeguro\Parsers\Currency; @@ -43,7 +42,6 @@ use PagSeguro\Parsers\ReceiverEmail; use PagSeguro\Parsers\Sender; use PagSeguro\Parsers\Shipping; -use PagSeguro\Parsers\Split; use PagSeguro\Resources\Http; use PagSeguro\Parsers\Transaction\CreditCard\Response; @@ -72,7 +70,7 @@ public static function getData(\PagSeguro\Domains\Requests\DirectPayment\CreditC { $data = []; - $properties = new BackwardCompatibility(); + $properties = new Current(); return array_merge( $data, Basic::getData($creditCard, $properties), @@ -86,8 +84,7 @@ public static function getData(\PagSeguro\Domains\Requests\DirectPayment\CreditC ReceiverEmail::getData($creditCard, $properties), Sender::getData($creditCard, $properties), Shipping::getData($creditCard, $properties), - Token::getData($creditCard, $properties), - Split::getData($creditCard, $properties) + Token::getData($creditCard, $properties) ); } diff --git a/lib/PagseguroPhpSdk/source/Parsers/DirectPayment/InternationalCreditCard/Request.php b/lib/PagseguroPhpSdk/source/Parsers/DirectPayment/InternationalCreditCard/Request.php index 88e78b0..12b1a2f 100644 --- a/lib/PagseguroPhpSdk/source/Parsers/DirectPayment/InternationalCreditCard/Request.php +++ b/lib/PagseguroPhpSdk/source/Parsers/DirectPayment/InternationalCreditCard/Request.php @@ -28,7 +28,6 @@ * Request from the Credit Card direct payment * @package PagSeguro\Parsers\DirectPayment\CreditCard */ -use PagSeguro\Enum\Properties\BackwardCompatibility; use PagSeguro\Enum\Properties\Current; use PagSeguro\Parsers\Basic; use PagSeguro\Parsers\Currency; @@ -41,7 +40,6 @@ use PagSeguro\Parsers\Parser; use PagSeguro\Parsers\ReceiverEmail; use PagSeguro\Parsers\Sender; -use PagSeguro\Parsers\Split; use PagSeguro\Resources\Http; use PagSeguro\Parsers\Transaction\InternationalCreditCard\Response; @@ -68,7 +66,7 @@ class Request extends Error implements Parser public static function getData(\PagSeguro\Domains\Requests\Requests $creditCard) { $data = []; - $properties = new BackwardCompatibility(); + $properties = new Current(); return array_merge( $data, Basic::getData($creditCard, $properties), @@ -79,7 +77,6 @@ public static function getData(\PagSeguro\Domains\Requests\Requests $creditCard) Mode::getData($creditCard, $properties), ReceiverEmail::getData($creditCard, $properties), Sender::getData($creditCard, $properties), - Split::getData($creditCard, $properties), Token::getData($creditCard, $properties) ); } diff --git a/lib/PagseguroPhpSdk/source/Parsers/DirectPayment/OnlineDebit/Request.php b/lib/PagseguroPhpSdk/source/Parsers/DirectPayment/OnlineDebit/Request.php index 50f6371..f41e1a7 100644 --- a/lib/PagseguroPhpSdk/source/Parsers/DirectPayment/OnlineDebit/Request.php +++ b/lib/PagseguroPhpSdk/source/Parsers/DirectPayment/OnlineDebit/Request.php @@ -28,7 +28,6 @@ * Request from the Online debit direct payment * @package PagSeguro\Parsers\DirectPayment\OnlineDebit */ -use PagSeguro\Enum\Properties\BackwardCompatibility; use PagSeguro\Enum\Properties\Current; use PagSeguro\Parsers\Basic; use PagSeguro\Parsers\Currency; @@ -39,7 +38,6 @@ use PagSeguro\Parsers\ReceiverEmail; use PagSeguro\Parsers\Sender; use PagSeguro\Parsers\Shipping; -use PagSeguro\Parsers\Split; use PagSeguro\Resources\Http; use PagSeguro\Parsers\Transaction\OnlineDebit\Response; @@ -66,7 +64,7 @@ class Request extends Error implements Parser public static function getData(\PagSeguro\Domains\Requests\DirectPayment\OnlineDebit $onlineDebit) { $data = []; - $properties = new BackwardCompatibility(); + $properties = new Current(); return array_merge( $data, BankName::getData($onlineDebit, $properties), @@ -77,8 +75,7 @@ public static function getData(\PagSeguro\Domains\Requests\DirectPayment\OnlineD Mode::getData($onlineDebit, $properties), ReceiverEmail::getData($onlineDebit, $properties), Sender::getData($onlineDebit, $properties), - Shipping::getData($onlineDebit, $properties), - Split::getData($onlineDebit, $properties) + Shipping::getData($onlineDebit, $properties) ); } diff --git a/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/AccessionParser.php b/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/AccessionParser.php new file mode 100644 index 0000000..36b9974 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/AccessionParser.php @@ -0,0 +1,70 @@ +object_to_array($directPreApproval); + } + + /** + * @param Http $http + * + * @return mixed + */ + public static function success(Http $http) + { + $json = json_decode($http->getResponse()); + + return $json; + } + + /** + * @param Http $http + * + * @return \PagSeguro\Domains\Error + */ + public static function error(Http $http) + { + return parent::error($http); + } +} diff --git a/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/CancelParser.php b/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/CancelParser.php new file mode 100644 index 0000000..fd708b5 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/CancelParser.php @@ -0,0 +1,86 @@ +object_to_array($status); + unset($status['status']); + + return $status['preApprovalCode']; + } + + /** + * @param Cancel $status + * + * @return array|Cancel + */ + public static function getData(Cancel $status) + { + $status = $status->object_to_array($status); + unset($status['preApprovalCode']); + + return $status; + } + + /** + * @param Http $http + * + * @return mixed + */ + public static function success(Http $http) + { + $json = json_decode($http->getResponse()); + + return $json; + } + + /** + * @param Http $http + * + * @return \PagSeguro\Domains\Error + */ + public static function error(Http $http) + { + return parent::error($http); + } +} diff --git a/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/ChangePaymentParser.php b/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/ChangePaymentParser.php new file mode 100644 index 0000000..7312c0c --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/ChangePaymentParser.php @@ -0,0 +1,85 @@ +object_to_array($changePayment); + + return $changePayment['preApprovalCode']; + } + + /** + * @param ChangePayment $changePayment + * + * @return array + */ + public static function getData(ChangePayment $changePayment) + { + $changePayment = $changePayment->object_to_array($changePayment); + unset($changePayment['preApprovalCode']); + + return $changePayment; + } + + /** + * @param Http $http + * + * @return mixed + */ + public static function success(Http $http) + { + $json = json_decode($http->getResponse()); + + return $json; + } + + /** + * @param Http $http + * + * @return \PagSeguro\Domains\Error + */ + public static function error(Http $http) + { + return parent::error($http); + } +} diff --git a/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/DiscountParser.php b/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/DiscountParser.php new file mode 100644 index 0000000..114848e --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/DiscountParser.php @@ -0,0 +1,86 @@ +object_to_array($discount); + unset($discount['status']); + + return $discount['preApprovalCode']; + } + + /** + * @param Discount $discount + * + * @return array|Discount + */ + public static function getData(Discount $discount) + { + $discount = $discount->object_to_array($discount); + unset($discount['preApprovalCode']); + + return $discount; + } + + /** + * @param Http $http + * + * @return mixed + */ + public static function success(Http $http) + { + $json = json_decode($http->getResponse()); + + return $json; + } + + /** + * @param Http $http + * + * @return \PagSeguro\Domains\Error + */ + public static function error(Http $http) + { + return parent::error($http); + } +} diff --git a/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/PaymentParser.php b/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/PaymentParser.php new file mode 100644 index 0000000..02024ae --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/PaymentParser.php @@ -0,0 +1,70 @@ +object_to_array($directPreApproval); + } + + /** + * @param Http $http + * + * @return mixed + */ + public static function success(Http $http) + { + $json = json_decode($http->getResponse()); + + return $json; + } + + /** + * @param Http $http + * + * @return \PagSeguro\Domains\Error + */ + public static function error(Http $http) + { + return parent::error($http); + } +} diff --git a/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/PlanParser.php b/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/PlanParser.php new file mode 100644 index 0000000..3119d56 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/PlanParser.php @@ -0,0 +1,70 @@ +object_to_array($data); + } + + /** + * @param Http $http + * + * @return mixed + */ + public static function success(Http $http) + { + $json = json_decode($http->getResponse()); + + return $json; + } + + /** + * @param Http $http + * + * @return \PagSeguro\Domains\Error + */ + public static function error(Http $http) + { + return parent::error($http); + } +} diff --git a/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/QueryNotificationParser.php b/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/QueryNotificationParser.php new file mode 100644 index 0000000..67130da --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/QueryNotificationParser.php @@ -0,0 +1,85 @@ +object_to_array($queryNotification); + + return $queryNotification['notificationCode']; + } + + /** + * @param QueryNotification $directPreApproval + * + * @return string + */ + public static function getData(QueryNotification $directPreApproval) + { + $directPreApproval = $directPreApproval->object_to_array($directPreApproval); + unset($directPreApproval['notificationCode']); + + return http_build_query($directPreApproval); + } + + /** + * @param Http $http + * + * @return mixed + */ + public static function success(Http $http) + { + $json = json_decode($http->getResponse()); + + return $json; + } + + /** + * @param Http $http + * + * @return \PagSeguro\Domains\Error + */ + public static function error(Http $http) + { + return parent::error($http); + } +} diff --git a/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/QueryParsers.php b/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/QueryParsers.php new file mode 100644 index 0000000..d81183f --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/QueryParsers.php @@ -0,0 +1,70 @@ +getResponse()); + + return $json; + } + + /** + * @param Http $http + * + * @return \PagSeguro\Domains\Error + */ + public static function error(Http $http) + { + return parent::error($http); + } +} diff --git a/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/QueryPaymentOrderParsers.php b/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/QueryPaymentOrderParsers.php new file mode 100644 index 0000000..98d59c1 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/QueryPaymentOrderParsers.php @@ -0,0 +1,85 @@ +object_to_array($queryPaymentOrder); + + return $queryPaymentOrder['preApprovalCode']; + } + + /** + * @param QueryPaymentOrder $queryPaymentOrder + * + * @return string + */ + public static function getData(QueryPaymentOrder $queryPaymentOrder) + { + $queryPaymentOrder = $queryPaymentOrder->object_to_array($queryPaymentOrder); + unset($queryPaymentOrder['preApprovalCode']); + + return http_build_query($queryPaymentOrder); + } + + /** + * @param Http $http + * + * @return mixed + */ + public static function success(Http $http) + { + $json = json_decode($http->getResponse()); + + return $json; + } + + /** + * @param Http $http + * + * @return \PagSeguro\Domains\Error + */ + public static function error(Http $http) + { + return parent::error($http); + } +} diff --git a/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/RetryPaymentOrderParser.php b/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/RetryPaymentOrderParser.php new file mode 100644 index 0000000..695ddee --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/RetryPaymentOrderParser.php @@ -0,0 +1,70 @@ +object_to_array($retryPaymentOrder); + } + + /** + * @param Http $http + * + * @return mixed + */ + public static function success(Http $http) + { + $json = json_decode($http->getResponse()); + + return $json; + } + + /** + * @param Http $http + * + * @return \PagSeguro\Domains\Error + */ + public static function error(Http $http) + { + return parent::error($http); + } +} diff --git a/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/StatusParser.php b/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/StatusParser.php new file mode 100644 index 0000000..db33412 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Parsers/DirectPreApproval/StatusParser.php @@ -0,0 +1,85 @@ +object_to_array($status); + + return $status['preApprovalCode']; + } + + /** + * @param Status $status + * + * @return array|Status + */ + public static function getData(Status $status) + { + $status = $status->object_to_array($status); + unset($status['preApprovalCode']); + + return $status; + } + + /** + * @param Http $http + * + * @return mixed + */ + public static function success(Http $http) + { + $json = json_decode($http->getResponse()); + + return $json; + } + + /** + * @param Http $http + * + * @return \PagSeguro\Domains\Error + */ + public static function error(Http $http) + { + return parent::error($http); + } +} diff --git a/lib/PagseguroPhpSdk/source/Parsers/Response/CreditorFees.php b/lib/PagseguroPhpSdk/source/Parsers/Response/CreditorFees.php index 4b501ed..a3bfe39 100644 --- a/lib/PagseguroPhpSdk/source/Parsers/Response/CreditorFees.php +++ b/lib/PagseguroPhpSdk/source/Parsers/Response/CreditorFees.php @@ -52,8 +52,15 @@ public function getCreditorFees() public function setCreditorFees($creditorFees) { $creditor = new \PagSeguro\Domains\CreditorFees(); - $creditor->setIntermediationRateAmount(current($creditorFees->intermediationRateAmount)) - ->setIntermediationFeeAmount(current($creditorFees->intermediationFeeAmount)); + + if (!is_null($creditorFees->intermediationRateAmount)) { + $creditor->setIntermediationRateAmount(current($creditorFees->intermediationRateAmount)); + } + + if (!is_null($creditorFees->intermediationFeeAmount)) { + $creditor->setIntermediationFeeAmount(current($creditorFees->intermediationFeeAmount)); + } + $this->creditorFees = $creditor; return $this; } diff --git a/lib/PagseguroPhpSdk/source/Parsers/Response/Shipping.php b/lib/PagseguroPhpSdk/source/Parsers/Response/Shipping.php index f1a0c79..41c1d23 100644 --- a/lib/PagseguroPhpSdk/source/Parsers/Response/Shipping.php +++ b/lib/PagseguroPhpSdk/source/Parsers/Response/Shipping.php @@ -54,28 +54,30 @@ public function getShipping() */ public function setShipping($shipping) { - $shippingClass = new \PagSeguro\Domains\Shipping(); + if (current($shipping) !== FALSE) { + $shippingClass = new \PagSeguro\Domains\Shipping(); - $shippingAddress = new Address($shippingClass); + $shippingAddress = new Address($shippingClass); - $shippingAddress->withParameters( - current($shipping->address->street), - current($shipping->address->number), - current($shipping->address->district), - current($shipping->address->postalCode), - current($shipping->address->city), - current($shipping->address->state), - current($shipping->address->country), - current($shipping->address->complement) - ); + $shippingAddress->withParameters( + current($shipping->address->street), + current($shipping->address->number), + current($shipping->address->district), + current($shipping->address->postalCode), + current($shipping->address->city), + current($shipping->address->state), + current($shipping->address->country), + current($shipping->address->complement) + ); - $shippingType = new Type($shippingClass); - $shippingType->withParameters(current($shipping->type)); + $shippingType = new Type($shippingClass); + $shippingType->withParameters(current($shipping->type)); - $shippingCost = new Cost($shippingClass); - $shippingCost->withParameters(current($shipping->cost)); + $shippingCost = new Cost($shippingClass); + $shippingCost->withParameters(current($shipping->cost)); - $this->shipping = $shippingClass; + $this->shipping = $shippingClass; + } return $this; } } diff --git a/lib/PagseguroPhpSdk/source/Parsers/Split.php b/lib/PagseguroPhpSdk/source/Parsers/Split.php deleted file mode 100644 index 83174b1..0000000 --- a/lib/PagseguroPhpSdk/source/Parsers/Split.php +++ /dev/null @@ -1,73 +0,0 @@ -getSplit())) { - if (!is_null($request->getSplit()->getPrimaryReceiver())) { - $data[$properties::PRIMARY_RECEIVER_PUBLIC_KEY] = $request->getSplit()->getPrimaryReceiver(); - } - if (count($request->getSplit()->getReceivers()) > 0) { - $receivers = $request->getSplit()->getReceivers(); - $count = 0; - foreach ($receivers as $key => $value) { - $count++; - if (!is_null($receivers[$key]->getPublicKey())) { - $data[sprintf($properties::RECEIVER_PUBLIC_KEY, $count)] = - $receivers[$key]->getPublicKey(); - } - if (!is_null($receivers[$key]->getAmount())) { - $data[sprintf($properties::RECEIVER_SPLIT_AMOUNT, $count)] = - \PagSeguro\Helpers\Currency::toDecimal($receivers[$key]->getAmount()); - } - if (!is_null($receivers[$key]->getRatePercent())) { - $data[sprintf($properties::RECEIVER_SPLIT_RATE_PERCENT, $count)] = - \PagSeguro\Helpers\Currency::toDecimal($receivers[$key]->getRatePercent()); - } - if (!is_null($receivers[$key]->getFeePercent())) { - $data[sprintf($properties::RECEIVER_SPLIT_FEE_PERCENT, $count)] = - \PagSeguro\Helpers\Currency::toDecimal($receivers[$key]->getFeePercent()); - } - } - } - } - return $data; - } -} diff --git a/lib/PagseguroPhpSdk/source/Parsers/Transaction/Response.php b/lib/PagseguroPhpSdk/source/Parsers/Transaction/Response.php index 856516e..d98fd67 100644 --- a/lib/PagseguroPhpSdk/source/Parsers/Transaction/Response.php +++ b/lib/PagseguroPhpSdk/source/Parsers/Transaction/Response.php @@ -27,7 +27,6 @@ use PagSeguro\Parsers\Response\CreditorFees; use PagSeguro\Parsers\Response\Currency; use PagSeguro\Parsers\Response\Item; -use PagSeguro\Parsers\Response\PaymentLink; use PagSeguro\Parsers\Response\PaymentMethod; use PagSeguro\Parsers\Response\Sender; use PagSeguro\Parsers\Response\Shipping; diff --git a/lib/PagseguroPhpSdk/source/Parsers/Transaction/Search/Code/Request.php b/lib/PagseguroPhpSdk/source/Parsers/Transaction/Search/Code/Request.php index 0d9fac0..4cfd8ed 100644 --- a/lib/PagseguroPhpSdk/source/Parsers/Transaction/Search/Code/Request.php +++ b/lib/PagseguroPhpSdk/source/Parsers/Transaction/Search/Code/Request.php @@ -27,7 +27,7 @@ use PagSeguro\Enum\Properties\Current; use PagSeguro\Parsers\Error; use PagSeguro\Parsers\Parser; -use PagSeguro\Parsers\Transaction\Response; +use PagSeguro\Parsers\Transaction\Search\Code\Response; use PagSeguro\Resources\Http; /** @@ -67,6 +67,7 @@ public static function success(Http $http) ->setStatus(current($xml->status)) ->setLastEventDate(current($xml->lastEventDate)) ->setPaymentMethod($xml->paymentMethod) + ->setPaymentLink(current($xml->paymentLink)) ->setGrossAmount(current($xml->grossAmount)) ->setDiscountAmount(current($xml->discountAmount)) ->setCreditorFees($xml->creditorFees) diff --git a/lib/PagseguroPhpSdk/source/Parsers/Transaction/Search/Code/Response.php b/lib/PagseguroPhpSdk/source/Parsers/Transaction/Search/Code/Response.php new file mode 100644 index 0000000..c9d8bc8 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Parsers/Transaction/Search/Code/Response.php @@ -0,0 +1,36 @@ +setId($array[$properties::ITEM_ID]) ->setAmount($array[$properties::ITEM_AMOUNT]) ->setDescription($array[$properties::ITEM_DESCRIPTION]) - ->setQuantity($array[$properties::ITEM_DESCRIPTION]) + ->setQuantity($array[$properties::ITEM_QUANTITY]) ->setWeight($array[$properties::ITEM_WEIGHT]) ->setShippingCost($array[$properties::ITEM_SHIPPING_COST]); diff --git a/lib/PagseguroPhpSdk/source/Resources/Factory/Split/Receiver.php b/lib/PagseguroPhpSdk/source/Resources/Factory/Split/Receiver.php deleted file mode 100644 index 67419cc..0000000 --- a/lib/PagseguroPhpSdk/source/Resources/Factory/Split/Receiver.php +++ /dev/null @@ -1,100 +0,0 @@ -split = $split; - $this->receiver = new \PagSeguro\Domains\Split\Receiver(); - } - - /** - * @param \PagSeguro\Domains\Split\Receiver $receiver - * @return \PagSeguro\Domains\Split\Receiver - */ - public function instance(\PagSeguro\Domains\Split\Receiver $receiver) - { - $this->split->setReceivers($receiver); - return $this->split; - } - - /** - * @param $array - * @return \PagSeguro\Domains\Split\Receiver - */ - public function withArray($array) - { - $properties = new BackwardCompatibility(); - - $this->receiver->setPublicKey($array[$properties::RECEIVER_PUBLIC_KEY]) - ->setAmount($properties::RECEIVER_SPLIT_AMOUNT) - ->setRatePercent($properties::RECEIVER_SPLIT_RATE_PERCENT) - ->setFeePercent($properties::RECEIVER_SPLIT_FEE_PERCENT); - $this->split->setReceivers($this->receiver); - return $this->split; - } - - /** - * @param $publicKey - * @param $amount - * @param $ratePercent - * @param $feePercent - * @return \PagSeguro\Domains\Split\Receiver - */ - public function withParameters( - $publicKey, - $amount, - $ratePercent, - $feePercent - ) { - $this->receiver->setPublicKey($publicKey) - ->setAmount($amount) - ->setRatePercent($ratePercent) - ->setFeePercent($feePercent); - $this->split->setReceivers($this->receiver); - return $this->split; - } -} diff --git a/lib/PagseguroPhpSdk/source/Resources/Http.php b/lib/PagseguroPhpSdk/source/Resources/Http.php index 5fe502b..9eaacd3 100644 --- a/lib/PagseguroPhpSdk/source/Resources/Http.php +++ b/lib/PagseguroPhpSdk/source/Resources/Http.php @@ -40,12 +40,22 @@ class Http * @var */ private $response; + private $contentType = 'Content-Type: application/x-www-form-urlencoded;'; + private $accept = ''; /** * Http constructor. + * + * @param string $contentType + * + * @throws \Exception */ - public function __construct() + public function __construct($contentType = 'x-www-form') { + if($contentType === 'json') { + $this->contentType = 'Content-Type: application/json;'; + $this->accept = 'Accept: application/vnd.pagseguro.com.br.v3+json;charset=ISO-8859-1'; + } if (!function_exists('curl_init')) { throw new \Exception('PagSeguro Library: cURL library is required.'); } @@ -85,17 +95,30 @@ public function setResponse($response) /** * @param $url - * @param array $data + * @param array|string $data * @param int $timeout * @param string $charset * @return bool * @throws \Exception */ - public function post($url, array $data = array(), $timeout = 20, $charset = 'ISO-8859-1') + public function post($url, $data = null, $timeout = 20, $charset = 'ISO-8859-1') { return $this->curlConnection('POST', $url, $timeout, $charset, $data); } + /** + * @param $url + * @param $data + * @param int $timeout + * @param string $charset + * + * @return bool + */ + public function put($url, $data, $timeout = 20, $charset = 'ISO-8859-1') + { + return $this->curlConnection('PUT', $url, $timeout, $charset, $data); + } + /** * @param $url * @param int $timeout @@ -113,19 +136,34 @@ public function get($url, $timeout = 20, $charset = 'ISO-8859-1') * @param $url * @param $timeout * @param $charset - * @param array|null $data + * @param array|string $data * @return bool * @throws \Exception */ - private function curlConnection($method, $url, $timeout, $charset, array $data = null) + private function curlConnection($method, $url, $timeout, $charset, $data = null) { if (strtoupper($method) === 'POST') { - $postFields = ($data ? http_build_query($data, '', '&') : ""); + if($this->contentType === 'Content-Type: application/json;'){ + $postFields = json_encode($data); + } else { + $postFields = (is_array($data) ? http_build_query($data, '', '&') : $data); + } $contentLength = "Content-length: " . strlen($postFields); $methodOptions = array( CURLOPT_POST => true, CURLOPT_POSTFIELDS => $postFields, ); + } elseif (strtoupper($method) === 'PUT') { + if($this->contentType === 'Content-Type: application/json;'){ + $postFields = json_encode($data); + } else { + $postFields = (is_array($data) ? http_build_query($data, '', '&') : $data); + } + $contentLength = "Content-length: " . strlen($postFields); + $methodOptions = array( + CURLOPT_CUSTOMREQUEST => 'PUT', + CURLOPT_POSTFIELDS => $postFields, + ); } else { $contentLength = null; $methodOptions = array( @@ -134,12 +172,7 @@ private function curlConnection($method, $url, $timeout, $charset, array $data = } $options = array( - CURLOPT_HTTPHEADER => array( - "Content-Type: application/x-www-form-urlencoded; charset=" . $charset, - $contentLength, - 'lib-description: php:' . Library::libraryVersion(), - 'language-engine-description: php:' . Library::phpVersion() - ), + CURLOPT_HTTPHEADER => $this->setHeader($charset, $contentLength), CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, @@ -158,7 +191,7 @@ private function curlConnection($method, $url, $timeout, $charset, array $data = sprintf('module-version: %s', Library::moduleVersion()->getRelease()) ); } - + if (!is_null(Library::cmsVersion()->getRelease())) { array_push( $options[CURLOPT_HTTPHEADER], @@ -182,4 +215,25 @@ private function curlConnection($method, $url, $timeout, $charset, array $data = return true; } } + + /** + * @param $charset + * @param $contentLength + * + * @return array + */ + private function setHeader($charset, $contentLength) + { + $httpHeader = array( + "$this->contentType charset= $charset", + $contentLength, + 'lib-description: php:'.Library::libraryVersion(), + 'language-engine-description: php:'.Library::phpVersion(), + ); + if ($this->accept) { + $httpHeader[] = $this->accept; + } + + return $httpHeader; + } } diff --git a/lib/PagseguroPhpSdk/source/Resources/Responsibility/Configuration/File.php b/lib/PagseguroPhpSdk/source/Resources/Responsibility/Configuration/File.php index a8a3443..1052582 100644 --- a/lib/PagseguroPhpSdk/source/Resources/Responsibility/Configuration/File.php +++ b/lib/PagseguroPhpSdk/source/Resources/Responsibility/Configuration/File.php @@ -48,6 +48,6 @@ public function handler($action, $class) \PagSeguro\Helpers\Wrapper::log($wrapper) ); } - return $this->handler($action, $class); + return $this->successor->handler($action, $class); } } diff --git a/lib/PagseguroPhpSdk/source/Services/Application/Authorization.php b/lib/PagseguroPhpSdk/source/Services/Application/Authorization.php index 7a4ea79..be92c17 100644 --- a/lib/PagseguroPhpSdk/source/Services/Application/Authorization.php +++ b/lib/PagseguroPhpSdk/source/Services/Application/Authorization.php @@ -50,7 +50,9 @@ public static function create(Credentials $credentials, \PagSeguro\Domains\Reque ); $http->post( self::request($connection), - \PagSeguro\Parsers\Authorization\Request::getData($authorization) + \PagSeguro\Parsers\Authorization\Request::getData($authorization), + 20, + \PagSeguro\Configuration\Configure::getCharset()->getEncoding() ); $response = Responsibility::http( diff --git a/lib/PagseguroPhpSdk/source/Services/Application/Notification.php b/lib/PagseguroPhpSdk/source/Services/Application/Notification.php index 7561843..98d39d2 100644 --- a/lib/PagseguroPhpSdk/source/Services/Application/Notification.php +++ b/lib/PagseguroPhpSdk/source/Services/Application/Notification.php @@ -50,7 +50,9 @@ public static function check(Credentials $credentials) $http = new Http(); Logger::info(sprintf("GET: %s", self::request($connection)), ['service' => 'Application.Notification']); $http->get( - self::request($connection) + self::request($connection), + 20, + \PagSeguro\Configuration\Configure::getCharset()->getEncoding() ); $response = Responsibility::http( diff --git a/lib/PagseguroPhpSdk/source/Services/Application/Search/Code.php b/lib/PagseguroPhpSdk/source/Services/Application/Search/Code.php index 1e85c99..4e3c0c9 100644 --- a/lib/PagseguroPhpSdk/source/Services/Application/Search/Code.php +++ b/lib/PagseguroPhpSdk/source/Services/Application/Search/Code.php @@ -55,7 +55,9 @@ public static function search(Credentials $credentials, $code) ['service' => 'Application.Search.Code'] ); $http->get( - self::request($connection, $code) + self::request($connection, $code), + 20, + \PagSeguro\Configuration\Configure::getCharset()->getEncoding() ); $response = Responsibility::http( diff --git a/lib/PagseguroPhpSdk/source/Services/Application/Search/Date.php b/lib/PagseguroPhpSdk/source/Services/Application/Search/Date.php index bb8eb7c..23b5411 100644 --- a/lib/PagseguroPhpSdk/source/Services/Application/Search/Date.php +++ b/lib/PagseguroPhpSdk/source/Services/Application/Search/Date.php @@ -61,7 +61,9 @@ public static function search( ['service' => 'Application.Search.Date'] ); $http->get( - self::request($connection, $options) + self::request($connection, $options), + 20, + \PagSeguro\Configuration\Configure::getCharset()->getEncoding() ); $response = Responsibility::http( diff --git a/lib/PagseguroPhpSdk/source/Services/Application/Search/Notification.php b/lib/PagseguroPhpSdk/source/Services/Application/Search/Notification.php index 5a6880d..a1ea130 100644 --- a/lib/PagseguroPhpSdk/source/Services/Application/Search/Notification.php +++ b/lib/PagseguroPhpSdk/source/Services/Application/Search/Notification.php @@ -55,7 +55,9 @@ public static function search(Credentials $credentials, $code) ['service' => 'Application.Search.Notification'] ); $http->get( - self::request($connection, $code) + self::request($connection, $code), + 20, + \PagSeguro\Configuration\Configure::getCharset()->getEncoding() ); $response = Responsibility::http( diff --git a/lib/PagseguroPhpSdk/source/Services/Application/Search/Reference.php b/lib/PagseguroPhpSdk/source/Services/Application/Search/Reference.php index 0ce7ccc..1098b4c 100644 --- a/lib/PagseguroPhpSdk/source/Services/Application/Search/Reference.php +++ b/lib/PagseguroPhpSdk/source/Services/Application/Search/Reference.php @@ -63,7 +63,9 @@ public static function search( ['service' => 'Application.Search.Reference'] ); $http->get( - self::request($connection, $reference, $options) + self::request($connection, $reference, $options), + 20, + \PagSeguro\Configuration\Configure::getCharset()->getEncoding() ); $response = Responsibility::http( diff --git a/lib/PagseguroPhpSdk/source/Services/DirectPayment/Boleto.php b/lib/PagseguroPhpSdk/source/Services/DirectPayment/Boleto.php index 9057f66..6d5d853 100644 --- a/lib/PagseguroPhpSdk/source/Services/DirectPayment/Boleto.php +++ b/lib/PagseguroPhpSdk/source/Services/DirectPayment/Boleto.php @@ -68,7 +68,9 @@ public static function checkout( $http->post( self::request($connection), - Request::getData($payment) + Request::getData($payment), + 20, + \PagSeguro\Configuration\Configure::getCharset()->getEncoding() ); $response = Responsibility::http( @@ -87,7 +89,7 @@ public static function checkout( throw $exception; } } - + /** * @param Connection\Data $connection * @return string diff --git a/lib/PagseguroPhpSdk/source/Services/DirectPayment/CreditCard.php b/lib/PagseguroPhpSdk/source/Services/DirectPayment/CreditCard.php index 99c2a83..a540784 100644 --- a/lib/PagseguroPhpSdk/source/Services/DirectPayment/CreditCard.php +++ b/lib/PagseguroPhpSdk/source/Services/DirectPayment/CreditCard.php @@ -63,7 +63,9 @@ public static function checkout( ); $http->post( self::request($connection), - Request::getData($payment) + Request::getData($payment), + 20, + \PagSeguro\Configuration\Configure::getCharset()->getEncoding() ); $response = Responsibility::http( @@ -82,7 +84,7 @@ public static function checkout( throw $exception; } } - + /** * @param Connection\Data $connection * @return string diff --git a/lib/PagseguroPhpSdk/source/Services/DirectPayment/InternationalCreditCard.php b/lib/PagseguroPhpSdk/source/Services/DirectPayment/InternationalCreditCard.php index 171c4c4..8707c3a 100644 --- a/lib/PagseguroPhpSdk/source/Services/DirectPayment/InternationalCreditCard.php +++ b/lib/PagseguroPhpSdk/source/Services/DirectPayment/InternationalCreditCard.php @@ -66,7 +66,9 @@ public static function checkout( ); $http->post( self::request($connection), - Request::getData($payment) + Request::getData($payment), + 20, + \PagSeguro\Configuration\Configure::getCharset()->getEncoding() ); $response = Responsibility::http( diff --git a/lib/PagseguroPhpSdk/source/Services/DirectPayment/OnlineDebit.php b/lib/PagseguroPhpSdk/source/Services/DirectPayment/OnlineDebit.php index 3dc4696..c0e3d70 100644 --- a/lib/PagseguroPhpSdk/source/Services/DirectPayment/OnlineDebit.php +++ b/lib/PagseguroPhpSdk/source/Services/DirectPayment/OnlineDebit.php @@ -66,7 +66,9 @@ public static function checkout( ); $http->post( self::request($connection), - Request::getData($payment) + Request::getData($payment), + 20, + \PagSeguro\Configuration\Configure::getCharset()->getEncoding() ); $response = Responsibility::http( diff --git a/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/AccessionService.php b/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/AccessionService.php new file mode 100644 index 0000000..651aa8d --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/AccessionService.php @@ -0,0 +1,104 @@ + 'DirectPreApproval']); + try { + $connection = new Connection\Data($credentials); + $http = new Http('json'); + Logger::info(sprintf("POST: %s", self::request($connection)), ['service' => 'DirectPreApproval']); + Logger::info( + sprintf( + "Params: %s", + json_encode(AccessionParser::getData($directPreApproval)) + ), + ['service' => 'DirectPreApproval'] + ); + $http->post( + self::request($connection), + AccessionParser::getData($directPreApproval), + 20, + \PagSeguro\Configuration\Configure::getCharset()->getEncoding() + ); + $response = Responsibility::http( + $http, + new AccessionParser + ); + Logger::info( + sprintf("DirectPreApproval URL: %s", json_encode(self::response($response))), + ['service' => 'DirectPreApproval'] + ); + + return self::response($response); + } catch (\Exception $exception) { + Logger::error($exception->getMessage(), ['service' => 'DirectPreApproval']); + throw $exception; + } + } + + /** + * @param Connection\Data $connection + * + * @return string + */ + private static function request(Connection\Data $connection) + { + return $connection->buildDirectPreApprovalAccessionRequestUrl()."?".$connection->buildCredentialsQuery(); + } + + /** + * @param $response + * + * @return mixed + */ + private static function response($response) + { + return $response; + } +} diff --git a/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/CancelService.php b/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/CancelService.php new file mode 100644 index 0000000..83e34d3 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/CancelService.php @@ -0,0 +1,106 @@ + 'DirectPreApproval']); + try { + $connection = new Connection\Data($credentials); + $http = new Http('json'); + Logger::info(sprintf("POST: %s", self::request($connection, CancelParser::getPreApprovalCode($cancel))), + ['service' => 'DirectPreApproval']); + Logger::info( + sprintf( + "Params: %s", + json_encode(CancelParser::getData($cancel)) + ), + ['service' => 'DirectPreApproval'] + ); + $http->put( + self::request($connection, CancelParser::getPreApprovalCode($cancel)), + CancelParser::getData($cancel), + 20, + \PagSeguro\Configuration\Configure::getCharset()->getEncoding() + ); + $response = Responsibility::http( + $http, + new CancelParser + ); + Logger::info( + sprintf("DirectPreApproval URL: %s", json_encode(self::response($response))), + ['service' => 'DirectPreApproval'] + ); + + return self::response($response); + } catch (\Exception $exception) { + Logger::error($exception->getMessage(), ['service' => 'DirectPreApproval']); + throw $exception; + } + } + + /** + * @param Connection\Data $connection + * @param $preApprovalCode + * + * @return string + */ + private static function request(Connection\Data $connection, $preApprovalCode) + { + return $connection->buildDirectPreApprovalCancelRequestUrl($preApprovalCode)."?".$connection->buildCredentialsQuery(); + } + + /** + * @param $response + * + * @return mixed + */ + private static function response($response) + { + return $response; + } +} diff --git a/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/ChangePaymentService.php b/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/ChangePaymentService.php new file mode 100644 index 0000000..a532f07 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/ChangePaymentService.php @@ -0,0 +1,107 @@ + 'DirectPreApproval']); + try { + $connection = new Connection\Data($credentials); + $http = new Http('json'); + Logger::info(sprintf("POST: %s", + self::request($connection, ChangePaymentParser::getPreApprovalCode($changePayment))), + ['service' => 'DirectPreApproval']); + Logger::info( + sprintf( + "Params: %s", + json_encode(ChangePaymentParser::getData($changePayment)) + ), + ['service' => 'DirectPreApproval'] + ); + $http->put( + self::request($connection, ChangePaymentParser::getPreApprovalCode($changePayment)), + ChangePaymentParser::getData($changePayment), + 20, + \PagSeguro\Configuration\Configure::getCharset()->getEncoding() + ); + $response = Responsibility::http( + $http, + new ChangePaymentParser + ); + Logger::info( + sprintf("DirectPreApproval URL: %s", json_encode(self::response($response))), + ['service' => 'DirectPreApproval'] + ); + + return self::response($response); + } catch (\Exception $exception) { + Logger::error($exception->getMessage(), ['service' => 'DirectPreApproval']); + throw $exception; + } + } + + /** + * @param Connection\Data $connection + * @param $preApprovalCode + * + * @return string + */ + private static function request(Connection\Data $connection, $preApprovalCode) + { + return $connection->buildDirectPreApprovalChangePaymentRequestUrl($preApprovalCode)."?".$connection->buildCredentialsQuery(); + } + + /** + * @param $response + * + * @return mixed + */ + private static function response($response) + { + return $response; + } +} diff --git a/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/DiscountService.php b/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/DiscountService.php new file mode 100644 index 0000000..ae5f021 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/DiscountService.php @@ -0,0 +1,106 @@ + 'DirectPreApproval']); + try { + $connection = new Connection\Data($credentials); + $http = new Http('json'); + Logger::info(sprintf("PUT: %s", self::request($connection, DiscountParser::getPreApprovalCode($discount))), + ['service' => 'DirectPreApproval']); + Logger::info( + sprintf( + "Params: %s", + json_encode(DiscountParser::getData($discount)) + ), + ['service' => 'DirectPreApproval'] + ); + $http->put( + self::request($connection, DiscountParser::getPreApprovalCode($discount)), + DiscountParser::getData($discount), + 20, + \PagSeguro\Configuration\Configure::getCharset()->getEncoding() + ); + $response = Responsibility::http( + $http, + new DiscountParser + ); + Logger::info( + sprintf("DirectPreApproval URL: %s", json_encode(self::response($response))), + ['service' => 'DirectPreApproval'] + ); + + return self::response($response); + } catch (\Exception $exception) { + Logger::error($exception->getMessage(), ['service' => 'DirectPreApproval']); + throw $exception; + } + } + + /** + * @param Connection\Data $connection + * @param $preApprovalCode + * + * @return string + */ + private static function request(Connection\Data $connection, $preApprovalCode) + { + return $connection->buildDirectPreApprovalDiscountRequestUrl($preApprovalCode)."?".$connection->buildCredentialsQuery(); + } + + /** + * @param $response + * + * @return mixed + */ + private static function response($response) + { + return $response; + } +} diff --git a/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/PaymentService.php b/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/PaymentService.php new file mode 100644 index 0000000..48f1804 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/PaymentService.php @@ -0,0 +1,104 @@ + 'DirectPreApproval']); + try { + $connection = new Connection\Data($credentials); + $http = new Http('json'); + Logger::info(sprintf("POST: %s", self::request($connection)), ['service' => 'DirectPreApproval']); + Logger::info( + sprintf( + "Params: %s", + json_encode(PaymentParser::getData($payment)) + ), + ['service' => 'DirectPreApproval'] + ); + $http->post( + self::request($connection), + PaymentParser::getData($payment), + 20, + \PagSeguro\Configuration\Configure::getCharset()->getEncoding() + ); + $response = Responsibility::http( + $http, + new PaymentParser + ); + Logger::info( + sprintf("DirectPreApproval URL: %s", json_encode(self::response($response))), + ['service' => 'DirectPreApproval'] + ); + + return self::response($response); + } catch (\Exception $exception) { + Logger::error($exception->getMessage(), ['service' => 'DirectPreApproval']); + throw $exception; + } + } + + /** + * @param Connection\Data $connection + * + * @return string + */ + private static function request(Connection\Data $connection) + { + return $connection->buildDirectPreApprovalPaymentRequestUrl()."?".$connection->buildCredentialsQuery(); + } + + /** + * @param $response + * + * @return mixed + */ + private static function response($response) + { + return $response; + } +} diff --git a/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/PlanService.php b/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/PlanService.php new file mode 100644 index 0000000..f487ea5 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/PlanService.php @@ -0,0 +1,103 @@ + 'DirectPreApproval']); + try { + $connection = new Connection\Data($credentials); + $http = new Http('json'); + Logger::info(sprintf("POST: %s", self::request($connection)), ['service' => 'DirectPreApproval']); + Logger::info( + sprintf( + "Params: %s", + json_encode(PlanParser::getData($data)) + ), + ['service' => 'DirectPreApproval'] + ); + $http->post( + self::request($connection), + PlanParser::getData($data), + 20, + \PagSeguro\Configuration\Configure::getCharset()->getEncoding() + ); + $response = Responsibility::http( + $http, + new PlanParser() + ); + Logger::info( + sprintf("DirectPreApproval URL: %s", json_encode(self::response($response))), + ['service' => 'DirectPreApproval'] + ); + + return self::response($response); + } catch (\Exception $exception) { + Logger::error($exception->getMessage(), ['service' => 'DirectPreApproval']); + throw $exception; + } + } + + /** + * @param Connection\Data $connection + * + * @return string + */ + private static function request(Connection\Data $connection) + { + return $connection->buildDirectPreApprovalPlanRequestUrl()."?".$connection->buildCredentialsQuery(); + } + + /** + * @param $response + * + * @return mixed + */ + private static function response($response) + { + return $response; + } +} diff --git a/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/QueryNotificationService.php b/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/QueryNotificationService.php new file mode 100644 index 0000000..98011e7 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/QueryNotificationService.php @@ -0,0 +1,107 @@ + 'DirectPreApproval']); + try { + $connection = new Connection\Data($credentials); + $http = new Http('json'); + Logger::info(sprintf("GET: %s", self::request($connection, QueryNotificationParser::getData($queryNotification), + QueryNotificationParser::getNotificationCode($queryNotification))), ['service' => 'DirectPreApproval']); + Logger::info( + sprintf( + "Params: %s", + json_encode(QueryNotificationParser::getData($queryNotification)) + ), + ['service' => 'DirectPreApproval'] + ); + $http->get( + self::request($connection, QueryNotificationParser::getData($queryNotification), + QueryNotificationParser::getNotificationCode($queryNotification)), + 20, + \PagSeguro\Configuration\Configure::getCharset()->getEncoding() + ); + $response = Responsibility::http( + $http, + new QueryNotificationParser + ); + Logger::info( + sprintf("DirectPreApproval URL: %s", json_encode(self::response($response))), + ['service' => 'DirectPreApproval'] + ); + + return self::response($response); + } catch (\Exception $exception) { + Logger::error($exception->getMessage(), ['service' => 'DirectPreApproval']); + throw $exception; + } + } + + /** + * @param Connection\Data $connection + * @param null $params + * @param null $preApprovalCode + * + * @return string + */ + private static function request(Connection\Data $connection, $params = null, $preApprovalCode = null) + { + return $connection->buildDirectPreApprovalQueryNotificationRequestUrl($preApprovalCode)."?".$connection->buildCredentialsQuery().($params ? '&'.$params : ''); + } + + /** + * @param $response + * + * @return mixed + */ + private static function response($response) + { + return $response; + } +} diff --git a/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/QueryPaymentOrderService.php b/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/QueryPaymentOrderService.php new file mode 100644 index 0000000..a7a4ff6 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/QueryPaymentOrderService.php @@ -0,0 +1,105 @@ + 'DirectPreApproval']); + try { + $connection = new Connection\Data($credentials); + $http = new Http('json'); + Logger::info(sprintf("POST: %s", self::request($connection, QueryPaymentOrderParsers::getPreApprovalCode($queryPaymentOrder))), ['service' => 'DirectPreApproval']); + Logger::info( + sprintf( + "Params: %s", + json_encode(QueryPaymentOrderParsers::getData($queryPaymentOrder)) + ), + ['service' => 'DirectPreApproval'] + ); + $http->get( + self::request($connection, QueryPaymentOrderParsers::getPreApprovalCode($queryPaymentOrder), QueryPaymentOrderParsers::getData($queryPaymentOrder)), + 20, + \PagSeguro\Configuration\Configure::getCharset()->getEncoding() + ); + $response = Responsibility::http( + $http, + new QueryPaymentOrderParsers + ); + Logger::info( + sprintf("DirectPreApproval URL: %s", json_encode(self::response($response))), + ['service' => 'DirectPreApproval'] + ); + + return self::response($response); + } catch (\Exception $exception) { + Logger::error($exception->getMessage(), ['service' => 'DirectPreApproval']); + throw $exception; + } + } + + /** + * @param Connection\Data $connection + * @param $preApprovalCode + * @param null $params + * + * @return string + */ + private static function request(Connection\Data $connection, $preApprovalCode , $params = null) + { + return $connection->buildDirectPreApprovalQueryPaymentOrderRequestUrl($preApprovalCode)."?".$connection->buildCredentialsQuery().($params ? '&'.$params : ''); + } + + /** + * @param $response + * + * @return mixed + */ + private static function response($response) + { + return $response; + } +} diff --git a/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/QueryService.php b/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/QueryService.php new file mode 100644 index 0000000..9150ba2 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/QueryService.php @@ -0,0 +1,108 @@ + 'DirectPreApproval']); + try { + $connection = new Connection\Data($credentials); + $http = new Http('json'); + Logger::info(sprintf("POST: %s", self::request($connection)), ['service' => 'DirectPreApproval']); + Logger::info( + sprintf( + "Params: %s", + json_encode(QueryParsers::getData($directPreApproval)) + ), + ['service' => 'DirectPreApproval'] + ); + $http->get( + self::request($connection, QueryParsers::getData($directPreApproval), $directPreApproval->preApprovalCode), + 20, + \PagSeguro\Configuration\Configure::getCharset()->getEncoding() + ); + $response = Responsibility::http( + $http, + new QueryParsers + ); + Logger::info( + sprintf("DirectPreApproval URL: %s", json_encode(self::response($response))), + ['service' => 'DirectPreApproval'] + ); + + return self::response($response); + } catch (\Exception $exception) { + Logger::error($exception->getMessage(), ['service' => 'DirectPreApproval']); + throw $exception; + } + } + + /** + * @param Connection\Data $connection + * @param null $params + * + * @return string + */ + private static function request(Connection\Data $connection, $params = null, $preApprovalCode = null) + { + if ($preApprovalCode) { + return $connection->buildDirectPreApprovalQueryRequestUrl() . '/' . $preApprovalCode . "?" . $connection->buildCredentialsQuery(); + } + + return $connection->buildDirectPreApprovalQueryRequestUrl() . "?" . $connection->buildCredentialsQuery() . ($params ? '&' . $params : ''); + } + + /** + * @param $response + * + * @return mixed + */ + private static function response($response) + { + return $response; + } +} diff --git a/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/RetryPaymentOrderService.php b/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/RetryPaymentOrderService.php new file mode 100644 index 0000000..2893f25 --- /dev/null +++ b/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/RetryPaymentOrderService.php @@ -0,0 +1,111 @@ + 'DirectPreApproval']); + try { + $connection = new Connection\Data($credentials); + $http = new Http('json'); + Logger::info(sprintf("POST: %s", self::request($connection)), ['service' => 'DirectPreApproval']); + Logger::info( + sprintf( + "Params: %s", + json_encode(RetryPaymentOrderParser::getData($retryPaymentOrder)) + ), + ['service' => 'DirectPreApproval'] + ); + $http->post( + self::request($connection, RetryPaymentOrderParser::getData($retryPaymentOrder)), + RetryPaymentOrderParser::getData($retryPaymentOrder), + 20, + \PagSeguro\Configuration\Configure::getCharset()->getEncoding() + ); + $response = Responsibility::http( + $http, + new RetryPaymentOrderParser + ); + Logger::info( + sprintf("DirectPreApproval URL: %s", json_encode(self::response($response))), + ['service' => 'DirectPreApproval'] + ); + + return self::response($response); + } catch (\Exception $exception) { + Logger::error($exception->getMessage(), ['service' => 'DirectPreApproval']); + throw $exception; + } + } + + /** + * @param Connection\Data $connection + * + * @param $data + * + * @return string + */ + private static function request(Connection\Data $connection, $data) + { + echo '
';
+        print_r($data);
+        print_r($connection->buildDirectPreApprovalRetryPaymentOrderUrl() . "?" . $connection->buildCredentialsQuery());
+        exit;
+
+        return $connection->buildDirectPreApprovalRetryPaymentOrderUrl() . "?" . $connection->buildCredentialsQuery();
+    }
+
+    /**
+     * @param $response
+     *
+     * @return mixed
+     */
+    private static function response($response)
+    {
+        return $response;
+    }
+}
diff --git a/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/StatusService.php b/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/StatusService.php
new file mode 100644
index 0000000..c4a898d
--- /dev/null
+++ b/lib/PagseguroPhpSdk/source/Services/DirectPreApproval/StatusService.php
@@ -0,0 +1,106 @@
+ 'DirectPreApproval']);
+        try {
+            $connection = new Connection\Data($credentials);
+            $http = new Http('json');
+            Logger::info(sprintf("PUT: %s", self::request($connection, StatusParser::getPreApprovalCode($status))),
+                ['service' => 'DirectPreApproval']);
+            Logger::info(
+                sprintf(
+                    "Params: %s",
+                    json_encode(StatusParser::getData($status))
+                ),
+                ['service' => 'DirectPreApproval']
+            );
+            $http->put(
+                self::request($connection, StatusParser::getPreApprovalCode($status)),
+                StatusParser::getData($status),
+                20,
+                \PagSeguro\Configuration\Configure::getCharset()->getEncoding()
+            );
+            $response = Responsibility::http(
+                $http,
+                new StatusParser
+            );
+            Logger::info(
+                sprintf("DirectPreApproval URL: %s", json_encode(self::response($response))),
+                ['service' => 'DirectPreApproval']
+            );
+
+            return self::response($response);
+        } catch (\Exception $exception) {
+            Logger::error($exception->getMessage(), ['service' => 'DirectPreApproval']);
+            throw $exception;
+        }
+    }
+
+    /**
+     * @param Connection\Data $connection
+     * @param                 $preApprovalCode
+     *
+     * @return string
+     */
+    private static function request(Connection\Data $connection, $preApprovalCode)
+    {
+        return $connection->buildDirectPreApprovalStatusRequestUrl($preApprovalCode)."?".$connection->buildCredentialsQuery();
+    }
+
+    /**
+     * @param $response
+     *
+     * @return mixed
+     */
+    private static function response($response)
+    {
+        return $response;
+    }
+}
diff --git a/lib/PagseguroPhpSdk/source/Services/Installment.php b/lib/PagseguroPhpSdk/source/Services/Installment.php
index dc92904..475e222 100644
--- a/lib/PagseguroPhpSdk/source/Services/Installment.php
+++ b/lib/PagseguroPhpSdk/source/Services/Installment.php
@@ -36,7 +36,9 @@ public static function create(Credentials $credentials, $params)
             $connection = new Connection\Data($credentials);
             $http = new Http();
             Logger::info(sprintf("GET: %s", self::request($connection, $params)), ['service' => 'Installment']);
-            $http->get(self::request($connection, $params));
+            $http->get(self::request($connection, $params),
+                20,
+                \PagSeguro\Configuration\Configure::getCharset()->getEncoding());
 
             $response = Responsibility::http(
                 $http,
diff --git a/lib/PagseguroPhpSdk/source/Services/PreApproval/Cancel.php b/lib/PagseguroPhpSdk/source/Services/PreApproval/Cancel.php
index c936120..c77f507 100644
--- a/lib/PagseguroPhpSdk/source/Services/PreApproval/Cancel.php
+++ b/lib/PagseguroPhpSdk/source/Services/PreApproval/Cancel.php
@@ -57,7 +57,9 @@ public static function create(Credentials $credentials, $code)
                 ['service' => 'Cancel']
             );
 
-            $http->get(self::request($connection, $code));
+            $http->get(self::request($connection, $code),
+                20,
+                \PagSeguro\Configuration\Configure::getCharset()->getEncoding());
 
             $response = Responsibility::http(
                 $http,
diff --git a/lib/PagseguroPhpSdk/source/Services/PreApproval/Charge.php b/lib/PagseguroPhpSdk/source/Services/PreApproval/Charge.php
index 0cedeb5..22ce48f 100644
--- a/lib/PagseguroPhpSdk/source/Services/PreApproval/Charge.php
+++ b/lib/PagseguroPhpSdk/source/Services/PreApproval/Charge.php
@@ -51,7 +51,9 @@ public static function create(Credentials $credentials, \PagSeguro\Domains\Reque
             );
             $http->post(
                 self::request($connection),
-                Request::getData($charge)
+                Request::getData($charge),
+                20,
+                \PagSeguro\Configuration\Configure::getCharset()->getEncoding()
             );
 
             return Responsibility::http(
diff --git a/lib/PagseguroPhpSdk/source/Services/PreApproval/Notification.php b/lib/PagseguroPhpSdk/source/Services/PreApproval/Notification.php
index 5241e9b..c11b0db 100644
--- a/lib/PagseguroPhpSdk/source/Services/PreApproval/Notification.php
+++ b/lib/PagseguroPhpSdk/source/Services/PreApproval/Notification.php
@@ -50,7 +50,9 @@ public static function check(Credentials $credentials)
             $http = new Http();
             Logger::info(sprintf("GET: %s", self::request($connection)), ['service' => 'PreApproval.Notification']);
             $http->get(
-                self::request($connection)
+                self::request($connection),
+                20,
+                \PagSeguro\Configuration\Configure::getCharset()->getEncoding()
             );
 
             $response = Responsibility::http(
diff --git a/lib/PagseguroPhpSdk/source/Services/PreApproval/Payment.php b/lib/PagseguroPhpSdk/source/Services/PreApproval/Payment.php
index 79345aa..5514637 100644
--- a/lib/PagseguroPhpSdk/source/Services/PreApproval/Payment.php
+++ b/lib/PagseguroPhpSdk/source/Services/PreApproval/Payment.php
@@ -53,7 +53,9 @@ public static function create(Credentials $credentials, PreApproval $preApproval
 
             $http->post(
                 self::request($connection),
-                Request::getData($preApproval)
+                Request::getData($preApproval),
+                20,
+                \PagSeguro\Configuration\Configure::getCharset()->getEncoding()
             );
 
             $response = Responsibility::http(
diff --git a/lib/PagseguroPhpSdk/source/Services/PreApproval/Search/Code.php b/lib/PagseguroPhpSdk/source/Services/PreApproval/Search/Code.php
index 8830054..e75ff6d 100644
--- a/lib/PagseguroPhpSdk/source/Services/PreApproval/Search/Code.php
+++ b/lib/PagseguroPhpSdk/source/Services/PreApproval/Search/Code.php
@@ -57,7 +57,9 @@ public static function search(Credentials $credentials, $code)
                 ['service' => 'PreApproval.Search.Code']
             );
             $http->get(
-                self::request($connection, $code)
+                self::request($connection, $code),
+                20,
+                \PagSeguro\Configuration\Configure::getCharset()->getEncoding()
             );
 
             $response = Responsibility::http(
diff --git a/lib/PagseguroPhpSdk/source/Services/PreApproval/Search/Date.php b/lib/PagseguroPhpSdk/source/Services/PreApproval/Search/Date.php
index 1b07dcf..f0a5973 100644
--- a/lib/PagseguroPhpSdk/source/Services/PreApproval/Search/Date.php
+++ b/lib/PagseguroPhpSdk/source/Services/PreApproval/Search/Date.php
@@ -58,7 +58,9 @@ public static function search(
                 ['service' => 'PreApproval.Search.Date']
             );
             $http->get(
-                self::request($connection, $options)
+                self::request($connection, $options),
+                20,
+                \PagSeguro\Configuration\Configure::getCharset()->getEncoding()
             );
 
             $response = Responsibility::http(
diff --git a/lib/PagseguroPhpSdk/source/Services/PreApproval/Search/Interval.php b/lib/PagseguroPhpSdk/source/Services/PreApproval/Search/Interval.php
index 8b766f4..0b54e5d 100644
--- a/lib/PagseguroPhpSdk/source/Services/PreApproval/Search/Interval.php
+++ b/lib/PagseguroPhpSdk/source/Services/PreApproval/Search/Interval.php
@@ -57,7 +57,9 @@ public static function search(Credentials $credentials, $days)
                 ['service' => 'PreApproval.Search.Interval']
             );
             $http->get(
-                self::request($connection, $days)
+                self::request($connection, $days),
+                20,
+                \PagSeguro\Configuration\Configure::getCharset()->getEncoding()
             );
 
             $response = Responsibility::http(
diff --git a/lib/PagseguroPhpSdk/source/Services/PreApproval/Search/Notification.php b/lib/PagseguroPhpSdk/source/Services/PreApproval/Search/Notification.php
index 8c463d1..8d6c109 100644
--- a/lib/PagseguroPhpSdk/source/Services/PreApproval/Search/Notification.php
+++ b/lib/PagseguroPhpSdk/source/Services/PreApproval/Search/Notification.php
@@ -55,7 +55,9 @@ public static function search(Credentials $credentials, $code)
                 ['service' => 'PreApproval.Search.Notification']
             );
             $http->get(
-                self::request($connection, $code)
+                self::request($connection, $code),
+                20,
+                \PagSeguro\Configuration\Configure::getCharset()->getEncoding()
             );
 
             $response = Responsibility::http(
diff --git a/lib/PagseguroPhpSdk/source/Services/Session.php b/lib/PagseguroPhpSdk/source/Services/Session.php
index ce8bbbc..7063142 100644
--- a/lib/PagseguroPhpSdk/source/Services/Session.php
+++ b/lib/PagseguroPhpSdk/source/Services/Session.php
@@ -46,7 +46,10 @@ public static function create(Credentials $credentials)
             $connection = new Connection\Data($credentials);
             $http = new Http();
             Logger::info(sprintf("POST: %s", self::request($connection)), ['service' => 'Session']);
-            $http->post(self::request($connection));
+            $http->post(self::request($connection),
+                null,
+                20,
+                \PagSeguro\Configuration\Configure::getCharset()->getEncoding());
 
             $response = Responsibility::http(
                 $http,
diff --git a/lib/PagseguroPhpSdk/source/Services/Transactions/Cancel.php b/lib/PagseguroPhpSdk/source/Services/Transactions/Cancel.php
index 7a8a4ca..ce08c10 100644
--- a/lib/PagseguroPhpSdk/source/Services/Transactions/Cancel.php
+++ b/lib/PagseguroPhpSdk/source/Services/Transactions/Cancel.php
@@ -62,7 +62,9 @@ public static function create(Credentials $credentials, $code)
             );
             $http->post(
                 self::request($connection),
-                Request::getData($code)
+                Request::getData($code),
+                20,
+                \PagSeguro\Configuration\Configure::getCharset()->getEncoding()
             );
 
             $response = Responsibility::http(
diff --git a/lib/PagseguroPhpSdk/source/Services/Transactions/Notification.php b/lib/PagseguroPhpSdk/source/Services/Transactions/Notification.php
index 7ef092a..cfa462f 100644
--- a/lib/PagseguroPhpSdk/source/Services/Transactions/Notification.php
+++ b/lib/PagseguroPhpSdk/source/Services/Transactions/Notification.php
@@ -50,7 +50,9 @@ public static function check(Credentials $credentials)
             $http = new Http();
             Logger::info(sprintf("GET: %s", self::request($connection)), ['service' => 'Transactions.Notification']);
             $http->get(
-                self::request($connection)
+                self::request($connection),
+                20,
+                \PagSeguro\Configuration\Configure::getCharset()->getEncoding()
             );
 
             $response = Responsibility::http(
diff --git a/lib/PagseguroPhpSdk/source/Services/Transactions/Refund.php b/lib/PagseguroPhpSdk/source/Services/Transactions/Refund.php
index c423fae..1fb7c28 100644
--- a/lib/PagseguroPhpSdk/source/Services/Transactions/Refund.php
+++ b/lib/PagseguroPhpSdk/source/Services/Transactions/Refund.php
@@ -62,7 +62,9 @@ public static function create(Credentials $credentials, $code, $value = null)
             );
             $http->post(
                 self::request($connection),
-                Request::getData($code, $value)
+                Request::getData($code, $value),
+                20,
+                \PagSeguro\Configuration\Configure::getCharset()->getEncoding()
             );
 
             $response = Responsibility::http(
diff --git a/lib/PagseguroPhpSdk/source/Services/Transactions/Search/Abandoned.php b/lib/PagseguroPhpSdk/source/Services/Transactions/Search/Abandoned.php
index 5477f7d..ac400a0 100644
--- a/lib/PagseguroPhpSdk/source/Services/Transactions/Search/Abandoned.php
+++ b/lib/PagseguroPhpSdk/source/Services/Transactions/Search/Abandoned.php
@@ -61,7 +61,9 @@ public static function search(
                 ['service' => 'Transactions.Search.Abandoned']
             );
             $http->get(
-                self::request($connection, $options)
+                self::request($connection, $options),
+                20,
+                \PagSeguro\Configuration\Configure::getCharset()->getEncoding()
             );
 
             $response = Responsibility::http(
diff --git a/lib/PagseguroPhpSdk/source/Services/Transactions/Search/Code.php b/lib/PagseguroPhpSdk/source/Services/Transactions/Search/Code.php
index 2455516..cd8ae26 100644
--- a/lib/PagseguroPhpSdk/source/Services/Transactions/Search/Code.php
+++ b/lib/PagseguroPhpSdk/source/Services/Transactions/Search/Code.php
@@ -60,7 +60,9 @@ public static function search(Credentials $credentials, $code)
                 ['service' => 'Transactions.Search.Code']
             );
             $http->get(
-                self::request($connection, $code)
+                self::request($connection, $code),
+                20,
+                \PagSeguro\Configuration\Configure::getCharset()->getEncoding()
             );
 
             $response = Responsibility::http(
diff --git a/lib/PagseguroPhpSdk/source/Services/Transactions/Search/Date.php b/lib/PagseguroPhpSdk/source/Services/Transactions/Search/Date.php
index 8b5b973..fdc9475 100644
--- a/lib/PagseguroPhpSdk/source/Services/Transactions/Search/Date.php
+++ b/lib/PagseguroPhpSdk/source/Services/Transactions/Search/Date.php
@@ -61,7 +61,9 @@ public static function search(
                 ['service' => 'Transactions.Search.Date']
             );
             $http->get(
-                self::request($connection, $options)
+                self::request($connection, $options),
+                20,
+                \PagSeguro\Configuration\Configure::getCharset()->getEncoding()
             );
 
             $response = Responsibility::http(
diff --git a/lib/PagseguroPhpSdk/source/Services/Transactions/Search/Reference.php b/lib/PagseguroPhpSdk/source/Services/Transactions/Search/Reference.php
index 36b0f1a..f1d7d6c 100644
--- a/lib/PagseguroPhpSdk/source/Services/Transactions/Search/Reference.php
+++ b/lib/PagseguroPhpSdk/source/Services/Transactions/Search/Reference.php
@@ -66,7 +66,9 @@ public static function search(
                 ['service' => 'Transactions.Search.Reference']
             );
             $http->get(
-                self::request($connection, $reference, $options)
+                self::request($connection, $reference, $options),
+                20,
+                \PagSeguro\Configuration\Configure::getCharset()->getEncoding()
             );
 
             $response = Responsibility::http(
diff --git a/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/AddressTest.php b/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/AddressTest.php
new file mode 100644
index 0000000..27f19c9
--- /dev/null
+++ b/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/AddressTest.php
@@ -0,0 +1,34 @@
+assertObjectHasAttribute('street', $this->obj);
+        $this->assertObjectHasAttribute('number', $this->obj);
+        $this->assertObjectHasAttribute('district', $this->obj);
+        $this->assertObjectHasAttribute('city', $this->obj);
+        $this->assertObjectHasAttribute('state', $this->obj);
+        $this->assertObjectHasAttribute('country', $this->obj);
+    }
+
+    public function testWithParameters()
+    {
+        $this->assertInstanceOf(Address::class, $this->obj);
+    }
+
+    protected function setUp()
+    {
+        $this->obj = new Address();
+    }
+}
\ No newline at end of file
diff --git a/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/BillingAddressTest.php b/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/BillingAddressTest.php
new file mode 100644
index 0000000..378db6a
--- /dev/null
+++ b/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/BillingAddressTest.php
@@ -0,0 +1,34 @@
+assertObjectHasAttribute('street', $this->obj);
+        $this->assertObjectHasAttribute('number', $this->obj);
+        $this->assertObjectHasAttribute('district', $this->obj);
+        $this->assertObjectHasAttribute('city', $this->obj);
+        $this->assertObjectHasAttribute('state', $this->obj);
+        $this->assertObjectHasAttribute('country', $this->obj);
+    }
+
+    public function testWithParameters()
+    {
+        $this->assertInstanceOf(BillingAddress::class, $this->obj);
+    }
+
+    protected function setUp()
+    {
+        $this->obj = new BillingAddress();
+    }
+}
diff --git a/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/CreditCardTest.php b/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/CreditCardTest.php
new file mode 100644
index 0000000..68dcbbc
--- /dev/null
+++ b/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/CreditCardTest.php
@@ -0,0 +1,24 @@
+assertInstanceOf(CreditCard::class, $this->obj);
+    }
+
+    protected function setUp()
+    {
+        $this->obj = new CreditCard();
+    }
+}
diff --git a/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/DocumentTest.php b/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/DocumentTest.php
new file mode 100644
index 0000000..7857b6a
--- /dev/null
+++ b/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/DocumentTest.php
@@ -0,0 +1,25 @@
+assertObjectHasAttribute('type', $this->obj);
+        $this->assertObjectHasAttribute('value', $this->obj);
+    }
+
+    protected function setUp()
+    {
+        $this->obj = new Document();
+    }
+}
diff --git a/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/ExpirationTest.php b/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/ExpirationTest.php
new file mode 100644
index 0000000..6ae2eab
--- /dev/null
+++ b/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/ExpirationTest.php
@@ -0,0 +1,30 @@
+assertObjectHasAttribute('value', $this->obj);
+        $this->assertObjectHasAttribute('unit', $this->obj);
+    }
+
+    public function testWithParameters()
+    {
+        $this->assertInstanceOf(Expiration::class, $this->obj);
+    }
+
+    protected function setUp()
+    {
+        $this->obj = new Expiration();
+    }
+}
diff --git a/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/HolderTest.php b/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/HolderTest.php
new file mode 100644
index 0000000..defcbc5
--- /dev/null
+++ b/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/HolderTest.php
@@ -0,0 +1,24 @@
+assertInstanceOf(Holder::class, $this->obj);
+    }
+
+    protected function setUp()
+    {
+        $this->obj = new Holder();
+    }
+}
diff --git a/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/ItemTest.php b/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/ItemTest.php
new file mode 100644
index 0000000..7c1c8eb
--- /dev/null
+++ b/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/ItemTest.php
@@ -0,0 +1,34 @@
+assertObjectHasAttribute('id', $this->obj);
+        $this->assertObjectHasAttribute('description', $this->obj);
+        $this->assertObjectHasAttribute('quantity', $this->obj);
+        $this->assertObjectHasAttribute('amount', $this->obj);
+        $this->assertObjectHasAttribute('weight', $this->obj);
+        $this->assertObjectHasAttribute('shippingCost', $this->obj);
+    }
+
+    public function testWithPArameters()
+    {
+        $this->assertInstanceOf(Item::class, $this->obj);
+    }
+
+    protected function setUp()
+    {
+        $this->obj = new Item();
+    }
+}
diff --git a/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/PaymentMethodTest.php b/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/PaymentMethodTest.php
new file mode 100644
index 0000000..54cf2ed
--- /dev/null
+++ b/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/PaymentMethodTest.php
@@ -0,0 +1,29 @@
+assertObjectHasAttribute('type', $this->obj);
+    }
+
+    public function setCreditCard()
+    {
+        $this->assertInstanceOf(PaymentMethod::class, $this->obj);
+    }
+
+    protected function setUp()
+    {
+        $this->obj = new PaymentMethod();
+    }
+}
diff --git a/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/PhoneTest.php b/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/PhoneTest.php
new file mode 100644
index 0000000..da2d3f9
--- /dev/null
+++ b/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/PhoneTest.php
@@ -0,0 +1,30 @@
+assertObjectHasAttribute('areaCode', $this->obj);
+        $this->assertObjectHasAttribute('number', $this->obj);
+    }
+
+    public function testWithParameters()
+    {
+        $this->assertInstanceOf(Phone::class, $this->obj);
+    }
+
+    protected function setUp()
+    {
+        $this->obj = new Phone();
+    }
+}
diff --git a/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/PlanTest.php b/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/PlanTest.php
new file mode 100644
index 0000000..f19650b
--- /dev/null
+++ b/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/PlanTest.php
@@ -0,0 +1,43 @@
+assertInstanceOf(PreApproval::class, $this->obj2);
+    }
+
+    public function testSetReceiver()
+    {
+        $this->assertInstanceOf(Receiver::class, $this->obj3);
+    }
+
+    public function testParameters()
+    {
+        $this->assertObjectHasAttribute('redirectURL', $this->obj);
+        $this->assertObjectHasAttribute('reference', $this->obj);
+        $this->assertObjectHasAttribute('preApproval', $this->obj);
+        $this->assertObjectHasAttribute('reviewURL', $this->obj);
+        $this->assertObjectHasAttribute('maxUsers', $this->obj);
+        $this->assertObjectHasAttribute('receiver', $this->obj);
+    }
+
+    protected function setUp()
+    {
+        $this->obj = new Plan();
+        $this->obj2 = new PreApproval();
+        $this->obj3 = new Receiver();
+    }
+}
diff --git a/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/PreApprovalTest.php b/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/PreApprovalTest.php
new file mode 100644
index 0000000..a6f347a
--- /dev/null
+++ b/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/PreApprovalTest.php
@@ -0,0 +1,45 @@
+assertObjectHasAttribute('name', $this->obj);
+        $this->assertObjectHasAttribute('charge', $this->obj);
+        $this->assertObjectHasAttribute('period', $this->obj);
+        $this->assertObjectHasAttribute('amountPerPayment', $this->obj);
+        $this->assertObjectHasAttribute('membershipFee', $this->obj);
+        $this->assertObjectHasAttribute('expiration', $this->obj);
+        $this->assertObjectHasAttribute('details', $this->obj);
+        $this->assertObjectHasAttribute('maxAmountPerPeriod', $this->obj);
+        $this->assertObjectHasAttribute('maxAmountPerPayment', $this->obj);
+        $this->assertObjectHasAttribute('maxTotalAmount', $this->obj);
+        $this->assertObjectHasAttribute('maxPaymentsPerPeriod', $this->obj);
+        $this->assertObjectHasAttribute('initialDate', $this->obj);
+        $this->assertObjectHasAttribute('finalDate', $this->obj);
+        $this->assertObjectHasAttribute('dayOfYear', $this->obj);
+        $this->assertObjectHasAttribute('dayOfMonth', $this->obj);
+        $this->assertObjectHasAttribute('dayOfWeek', $this->obj);
+        $this->assertObjectHasAttribute('cancelURL', $this->obj);
+    }
+
+    public function testSetExpiration()
+    {
+        $this->assertInstanceOf(Expiration::class, $this->obj->expiration);
+    }
+
+    protected function setUp()
+    {
+        $this->obj = new PreApproval();
+    }
+}
diff --git a/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/ReceiverTest.php b/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/ReceiverTest.php
new file mode 100644
index 0000000..414815e
--- /dev/null
+++ b/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/ReceiverTest.php
@@ -0,0 +1,24 @@
+assertObjectHasAttribute('email', $this->obj);
+    }
+
+    protected function setUp()
+    {
+        $this->obj = new Receiver();
+    }
+}
diff --git a/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/SenderTest.php b/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/SenderTest.php
new file mode 100644
index 0000000..19cff35
--- /dev/null
+++ b/lib/PagseguroPhpSdk/tests/Domains/DirectPreApproval/SenderTest.php
@@ -0,0 +1,30 @@
+assertObjectHasAttribute('name', $this->obj);
+        $this->assertObjectHasAttribute('email', $this->obj);
+        $this->assertObjectHasAttribute('ip', $this->obj);
+        $this->assertObjectHasAttribute('hash', $this->obj);
+        $this->assertObjectHasAttribute('phone', $this->obj);
+        $this->assertObjectHasAttribute('documents', $this->obj);
+        $this->assertObjectHasAttribute('address', $this->obj);
+    }
+
+    protected function setUp()
+    {
+        $this->obj = new Sender();
+    }
+}
diff --git a/skin/frontend/base/default/uol/pagseguro/js/credit-card.js b/skin/frontend/base/default/uol/pagseguro/js/credit-card.js
index a0e703d..8f26658 100644
--- a/skin/frontend/base/default/uol/pagseguro/js/credit-card.js
+++ b/skin/frontend/base/default/uol/pagseguro/js/credit-card.js
@@ -105,6 +105,11 @@ function getInstallments(brand) {
 }
 
 function getBrand(self) {
+  var select = document.getElementById('card_installment_option');
+  select.options.length = 0;
+  select.options[0] = new Option('Escolha o N° de parcelas', null, true, true);
+  select.options[0].disabled = true
+  document.getElementById('card_total').innerHTML = 'selecione o número de parcelas';
   if (validateCreditCard(self)) {
     PagSeguroDirectPayment.getBrand({
       cardBin: unmask(document.getElementById('creditCardNum').value),
@@ -122,40 +127,18 @@ function getBrand(self) {
   }
 }
 
-function createCardToken() {
-    if (validateCreateToken()) {
-      var param = {
-        cardNumber: unmask(document.getElementById('creditCardNum').value),
-        brand: document.getElementById('creditCardBrand').value,
-        cvv: document.getElementById('creditCardCode').value,
-        expirationMonth: document.getElementById('creditCardExpirationMonth').value,
-        expirationYear: document.getElementById('creditCardExpirationYear').value,
-        success: function (response) {
-          document.getElementById('creditCardToken').value = response.card.token;
-        },
-        error: function (error) {
-          console.log(error);
-        },
-    }
-
-    PagSeguroDirectPayment.createCardToken(param)
-  }
-}
-
-function validateCreditCardCode(self, createToken) {
+function validateCreditCardCode(self) {
   if (self.validity.tooLong || self.validity.tooShort || !self.validity.valid) {
     displayError(self)
     return false
   } else {
     displayError(self, false)
-    if (createToken === true && validateCreateToken()) {
-      createCardToken();
-    }
     return true
   }
 }
 
 function validateCreditCardForm() {
+  displayError(document.getElementById('creditCardToken'), false);
   if (
     validateCreditCard(document.querySelector('#creditCardNum')) &&
     validateDocument(document.querySelector('#creditCardDocument')) &&
@@ -163,14 +146,11 @@ function validateCreditCardForm() {
     validateCreditCardHolderBirthdate(document.querySelector('#creditCardHolderBirthdate')) &&
     validateCreditCardMonth(document.querySelector('#creditCardExpirationMonth')) &&
     validateCreditCardYear(document.querySelector('#creditCardExpirationYear')) &&
-    validateCreditCardCode(document.querySelector('#creditCardCode'), false) &&
+    validateCreditCardCode(document.querySelector('#creditCardCode')) &&
     validateCreditCardInstallment(document.querySelector('#card_installment_option'))
   ) {
     document.getElementById('creditCardHash').value = getSenderHash();
-    if (document.getElementById('creditCardToken').value === "" || document.getElementById('creditCardToken').value == "undefined") {
-      createCardToken();
-    }
-   return true;
+    return true;
   }
   
   validateCreditCard(document.querySelector('#creditCardNum'))
@@ -179,7 +159,7 @@ function validateCreditCardForm() {
   validateCreditCardHolderBirthdate(document.querySelector('#creditCardHolderBirthdate'))
   validateCreditCardMonth(document.querySelector('#creditCardExpirationMonth'))
   validateCreditCardYear(document.querySelector('#creditCardExpirationYear'))
-  validateCreditCardCode(document.querySelector('#creditCardCode'), false)
+  validateCreditCardCode(document.querySelector('#creditCardCode'))
   validateCreditCardInstallment(document.querySelector('#card_installment_option'))
   return false;
 }
@@ -188,7 +168,7 @@ function validateCreateToken() {
   if(validateCreditCard(document.querySelector('#creditCardNum')) 
     && validateCreditCardMonth(document.querySelector('#creditCardExpirationMonth'))
     && validateCreditCardYear(document.querySelector('#creditCardExpirationYear'))
-    && validateCreditCardCode(document.querySelector('#creditCardCode'), false)
+    && validateCreditCardCode(document.querySelector('#creditCardCode'))
     && document.getElementById('creditCardBrand').value !== ""
     ) {
       return true
@@ -197,7 +177,7 @@ function validateCreateToken() {
   validateCreditCard(document.querySelector('#creditCardNum'));
   validateCreditCardMonth(document.querySelector('#creditCardExpirationMonth'));
   validateCreditCardYear(document.querySelector('#creditCardExpirationYear'));
-  validateCreditCardCode(document.querySelector('#creditCardCode'), false);
+  validateCreditCardCode(document.querySelector('#creditCardCode'));
 
   return false;
 }
diff --git a/skin/frontend/base/default/uol/pagseguro/js/pagseguro-before-save.js b/skin/frontend/base/default/uol/pagseguro/js/pagseguro-before-save.js
index aad462f..e5d0ceb 100644
--- a/skin/frontend/base/default/uol/pagseguro/js/pagseguro-before-save.js
+++ b/skin/frontend/base/default/uol/pagseguro/js/pagseguro-before-save.js
@@ -4,7 +4,25 @@ Payment.prototype.save = Payment.prototype.save.wrap(function(save) {
   if (this.validate() && validator.validate()) {
     // Do form validations
     if (validatePagSeguroActiveMethod()) {
-      return save();
+      if (document.querySelector('#checkout-payment-method-load .radio:checked').value == 'pagseguro_credit_card') {
+        var param = {
+          cardNumber: unmask(document.getElementById('creditCardNum').value),
+          brand: document.getElementById('creditCardBrand').value,
+          cvv: document.getElementById('creditCardCode').value,
+          expirationMonth: document.getElementById('creditCardExpirationMonth').value,
+          expirationYear: document.getElementById('creditCardExpirationYear').value,
+          success: function (response) {
+            document.getElementById('creditCardToken').value = response.card.token;
+            return save();
+          },
+          error: function (error) {
+            displayError(document.getElementById('creditCardToken'));
+          },
+        }
+        PagSeguroDirectPayment.createCardToken(param);
+      } else {
+        return save();
+      }
     }
   }
 });