From 054ba8c51e84948040dccc780660f368189e0e41 Mon Sep 17 00:00:00 2001 From: Lucas Rosa Date: Mon, 7 Oct 2024 11:39:36 -0300 Subject: [PATCH 1/9] feat: adiciona novo endpoint de listagem de Links de Pagamentos --- README.md | 7 ++ .../payment_links/03-payment-link-list.php | 31 +++++++ src/Core/IpagClient.php | 6 ++ src/Endpoint/PaymentLinksEndpointV2.php | 22 +++++ tests/Endpoint/PaymentEndpointV2Test.php | 89 +++++++++++++++++++ 5 files changed, 155 insertions(+) create mode 100644 examples/payment_links/03-payment-link-list.php create mode 100644 src/Endpoint/PaymentLinksEndpointV2.php create mode 100644 tests/Endpoint/PaymentEndpointV2Test.php diff --git a/README.md b/README.md index faa74bf..df6adf7 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,7 @@ Este SDK, não necessariamente, reflete todos dos recursos e funcionalidades dis - [Novo Link de Pagamento](#novo-link-de-pagamento) - [Obter Link de Pagamento (Por Id)](#obter-link-de-pagamento-por-id) - [Obter Link de Pagamento (Por External Code)](#obter-link-de-pagamento-por-external-code) + - [Listar Links de pagamento](#listar-links-de-pagamento) - [Webhook](#webhook) - [Novo Webhook](#novo-webhook) - [Obter Webhook](#obter-webhook) @@ -1105,6 +1106,12 @@ $responsePaymentLink = $ipagClient->paymentLinks()->getById($paymentLinkId); $responsePaymentLink = $ipagClient->paymentLinks()->getByExternalCode($externalCode); ``` +### Listar Links de Pagamento + +```php +$responsePaymentLink = $ipagClient->paymentLinksV2()->list(); +``` + > Todos os exemplos: [examples/payment_links/](https://github.com/ipagdevs/ipag-sdk-php/tree/master/examples/payment_links/) # Webhook diff --git a/examples/payment_links/03-payment-link-list.php b/examples/payment_links/03-payment-link-list.php new file mode 100644 index 0000000..751d2fa --- /dev/null +++ b/examples/payment_links/03-payment-link-list.php @@ -0,0 +1,31 @@ +paymentLinksV2()->list([ + "id" => 9 + ]); + $data = $responsePaymentLink->getData(); + + echo "
" . PHP_EOL;
+    print_r($data);
+    echo "
" . PHP_EOL; + +} catch (Ipag\Sdk\Exception\HttpException $e) { + $code = $e->getResponse()->getStatusCode(); + $errors = $e->getErrors(); + + echo "
" . PHP_EOL;
+    var_dump($code, $errors);
+    echo "
" . PHP_EOL; + +} catch (Exception $e) { + $error = $e->getMessage(); + + echo "
" . PHP_EOL;
+    var_dump($error);
+    echo "
" . PHP_EOL; + +} \ No newline at end of file diff --git a/src/Core/IpagClient.php b/src/Core/IpagClient.php index 224bdf2..b46e84b 100644 --- a/src/Core/IpagClient.php +++ b/src/Core/IpagClient.php @@ -9,6 +9,7 @@ use Ipag\Sdk\Endpoint\EstablishmentEndpoint; use Ipag\Sdk\Endpoint\PaymentEndpoint; use Ipag\Sdk\Endpoint\PaymentLinksEndpoint; +use Ipag\Sdk\Endpoint\PaymentLinksEndpointV2; use Ipag\Sdk\Endpoint\SellerEndpoint; use Ipag\Sdk\Endpoint\SplitRulesEndpoint; use Ipag\Sdk\Endpoint\SubscriptionEndpoint; @@ -102,6 +103,11 @@ public function paymentLinks(): PaymentLinksEndpoint return PaymentLinksEndpoint::make($this, $this); } + public function paymentLinksV2(): PaymentLinksEndpointV2 + { + return PaymentLinksEndpointV2::make($this, $this); + } + public function webhook(): WebhookEndpoint { return WebhookEndpoint::make($this, $this); diff --git a/src/Endpoint/PaymentLinksEndpointV2.php b/src/Endpoint/PaymentLinksEndpointV2.php new file mode 100644 index 0000000..c6e97fa --- /dev/null +++ b/src/Endpoint/PaymentLinksEndpointV2.php @@ -0,0 +1,22 @@ +_GET($filters ?? []); + } +} \ No newline at end of file diff --git a/tests/Endpoint/PaymentEndpointV2Test.php b/tests/Endpoint/PaymentEndpointV2Test.php new file mode 100644 index 0000000..20aad56 --- /dev/null +++ b/tests/Endpoint/PaymentEndpointV2Test.php @@ -0,0 +1,89 @@ +instanceClient([ + new Response( + 201, + [], + json_encode(((object) [])) + ) + ]); + + $responsePaymentLink = $this->client->paymentLinksV2()->list([]); + + $this->assertIsObject($responsePaymentLink); + } + + public function testShouldResponseFailUnprocessableDataClient() + { + $this->expectException(HttpException::class); + + $this->instanceClient([ + new Response( + 406, + [], + json_encode( + (object) [ + "code" => "406", + "message" => + [ + "description" => + [ + "Description is required", + "Description must be at least 10 characters long", + ] + ] + ] + ) + ) + ]); + + $this->client->paymentLinksV2()->list([]); + } + + public function testShouldResponseFailUnauthenticatedClient() + { + $this->expectException(HttpException::class); + + $this->instanceClient([ + new Response( + 401, + [], + json_encode( + (object) [ + "code" => 401, + "message" => "Unauthorized", + "resource" => "authorization" + ] + ) + ) + ]); + + $this->client->paymentLinksV2()->list([]); + } + + public function testThrowsServerExceptionOnServerError() + { + $this->expectException(HttpServerException::class); + + $this->instanceClient([ + new Response( + 500, + [], + json_encode(((object) [])) + ) + ]); + + $this->client->paymentLinksV2()->list([]); + } +} \ No newline at end of file From cacaa1b408be6c7bf6a5dbdec21c267e4033549e Mon Sep 17 00:00:00 2001 From: Lucas Rosa Date: Mon, 7 Oct 2024 12:09:34 -0300 Subject: [PATCH 2/9] feat: adiciona novo atributo (redirect_url) no Model PaymentTransaction --- src/Model/PaymentTransaction.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Model/PaymentTransaction.php b/src/Model/PaymentTransaction.php index f3843c0..71f71b9 100644 --- a/src/Model/PaymentTransaction.php +++ b/src/Model/PaymentTransaction.php @@ -22,6 +22,7 @@ final class PaymentTransaction extends Model * + [`'amount'`] float. * + [`'order_id'`] string. * + [`'callback_url'`] string. + * + [`'redirect_url'`] string. * * + [`'antifraud'`] array (opcional) dos dados do Antifraud. * +   [`'fingerprint'`] string. @@ -114,6 +115,7 @@ public function schema(SchemaBuilder $schema): Schema $schema->float('amount')->nullable(); $schema->string('order_id')->nullable(); $schema->string('callback_url')->nullable(); + $schema->string('redirect_url')->nullable(); $schema->has('antifraud', PaymentAntifraud::class)->nullable(); $schema->has('payment', Payment::class)->nullable(); @@ -205,6 +207,22 @@ public function setCallbackUrl(?string $callbackUrl = null): self return $this; } + /** + * Retorna o valor da propriedade `redirect_url`. + * + * @return string|null + */ + public function getRedirectUrl(): ?string + { + return $this->get('redirect_url'); + } + + public function setRedirectUrl(?string $redirectUrl = null): self + { + $this->set('redirect_url', $redirectUrl); + return $this; + } + /** * Retorna o valor da propriedade `PaymentAntifraud`. * From e248ae194b50061e539204a9e7a508fbf23ebd58 Mon Sep 17 00:00:00 2001 From: Lucas Rosa Date: Mon, 7 Oct 2024 15:15:42 -0300 Subject: [PATCH 3/9] feat: adiciona novos endpoints no SubscriptionEndpoint e AccountEndpoint --- examples/account/00-my-fees.php | 29 +++++++++++++++++ .../07-subscription-charge-notify.php | 31 +++++++++++++++++++ src/Core/IpagClient.php | 12 +++++++ src/Endpoint/AccountEndpoint.php | 17 ++++++++++ src/Endpoint/PaymentLinksEndpointV2.php | 5 +++ src/Endpoint/SubscriptionEndpointV2.php | 27 ++++++++++++++++ 6 files changed, 121 insertions(+) create mode 100644 examples/account/00-my-fees.php create mode 100644 examples/subscription/07-subscription-charge-notify.php create mode 100644 src/Endpoint/AccountEndpoint.php create mode 100644 src/Endpoint/SubscriptionEndpointV2.php diff --git a/examples/account/00-my-fees.php b/examples/account/00-my-fees.php new file mode 100644 index 0000000..79819dd --- /dev/null +++ b/examples/account/00-my-fees.php @@ -0,0 +1,29 @@ +account()->myFees(); + $data = $responseMyFees->getData(); + + echo "
" . PHP_EOL;
+    print_r($data);
+    echo "
" . PHP_EOL; + +} catch (Ipag\Sdk\Exception\HttpException $e) { + $code = $e->getResponse()->getStatusCode(); + $errors = $e->getErrors(); + + echo "
" . PHP_EOL;
+    var_dump($code, $errors);
+    echo "
" . PHP_EOL; + +} catch (Exception $e) { + $error = $e->getMessage(); + + echo "
" . PHP_EOL;
+    var_dump($error);
+    echo "
" . PHP_EOL; + +} \ No newline at end of file diff --git a/examples/subscription/07-subscription-charge-notify.php b/examples/subscription/07-subscription-charge-notify.php new file mode 100644 index 0000000..710a33d --- /dev/null +++ b/examples/subscription/07-subscription-charge-notify.php @@ -0,0 +1,31 @@ +subscriptionV2()->notify($subscription_id); + $data = $responseSubscriptionNotify->getData(); + + echo "
" . PHP_EOL;
+    print_r($data);
+    echo "
" . PHP_EOL; + +} catch (Ipag\Sdk\Exception\HttpException $e) { + $code = $e->getResponse()->getStatusCode(); + $errors = $e->getErrors(); + + echo "
" . PHP_EOL;
+    var_dump($code, $errors);
+    echo "
" . PHP_EOL; + +} catch (Exception $e) { + $error = $e->getMessage(); + + echo "
" . PHP_EOL;
+    var_dump($error);
+    echo "
" . PHP_EOL; + +} \ No newline at end of file diff --git a/src/Core/IpagClient.php b/src/Core/IpagClient.php index b46e84b..6b2d75b 100644 --- a/src/Core/IpagClient.php +++ b/src/Core/IpagClient.php @@ -3,6 +3,7 @@ namespace Ipag\Sdk\Core; use Ipag\Sdk\Core\IpagEnvironment; +use Ipag\Sdk\Endpoint\AccountEndpoint; use Ipag\Sdk\Endpoint\ChargeEndpoint; use Ipag\Sdk\Endpoint\CheckoutEndpoint; use Ipag\Sdk\Endpoint\CustomerEndpoint; @@ -13,6 +14,7 @@ use Ipag\Sdk\Endpoint\SellerEndpoint; use Ipag\Sdk\Endpoint\SplitRulesEndpoint; use Ipag\Sdk\Endpoint\SubscriptionEndpoint; +use Ipag\Sdk\Endpoint\SubscriptionEndpointV2; use Ipag\Sdk\Endpoint\SubscriptionPlanEndpoint; use Ipag\Sdk\Endpoint\TokenEndpoint; use Ipag\Sdk\Endpoint\TransactionEndpoint; @@ -73,6 +75,11 @@ public function subscription(): SubscriptionEndpoint return SubscriptionEndpoint::make($this, $this); } + public function subscriptionV2(): SubscriptionEndpointV2 + { + return SubscriptionEndpointV2::make($this, $this); + } + public function transaction(): TransactionEndpoint { return TransactionEndpoint::make($this, $this); @@ -138,4 +145,9 @@ public function payment(): PaymentEndpoint return PaymentEndpoint::make($this, $this); } + public function account(): AccountEndpoint + { + return AccountEndpoint::make($this, $this); + } + } \ No newline at end of file diff --git a/src/Endpoint/AccountEndpoint.php b/src/Endpoint/AccountEndpoint.php new file mode 100644 index 0000000..9a7b9e8 --- /dev/null +++ b/src/Endpoint/AccountEndpoint.php @@ -0,0 +1,17 @@ +_GET([], [], '/my-fees'); + } + +} \ No newline at end of file diff --git a/src/Endpoint/PaymentLinksEndpointV2.php b/src/Endpoint/PaymentLinksEndpointV2.php index c6e97fa..e93d79f 100644 --- a/src/Endpoint/PaymentLinksEndpointV2.php +++ b/src/Endpoint/PaymentLinksEndpointV2.php @@ -5,6 +5,11 @@ use Ipag\Sdk\Core\Endpoint; use Ipag\Sdk\Http\Response; +/** + * PaymentLinksEndpoint class + * + * Classe responsável pelo controle dos endpoints do recurso Payment Links versão `2`. + */ class PaymentLinksEndpointV2 extends Endpoint { protected string $location = '/service/v2/payment_links'; diff --git a/src/Endpoint/SubscriptionEndpointV2.php b/src/Endpoint/SubscriptionEndpointV2.php new file mode 100644 index 0000000..02972de --- /dev/null +++ b/src/Endpoint/SubscriptionEndpointV2.php @@ -0,0 +1,27 @@ +_POST([], [], [], "/$subscription_id/notify"); + } +} \ No newline at end of file From ebae0e30fede32877d61751257a2f300b9ed19e8 Mon Sep 17 00:00:00 2001 From: Lucas Rosa Date: Mon, 7 Oct 2024 17:25:50 -0300 Subject: [PATCH 4/9] feat: adiciona novos endpoints no CheckEndpoint e EstablishmentEndpoint --- .../checkout/01-get-installments-checkout.php | 34 ++++++ .../09-establishment-get-disputes.php | 29 +++++ .../10-establishment-apply-dispute.php | 30 ++++++ .../11-establishment-apply-chargebacks.php | 30 ++++++ src/Core/IpagClient.php | 6 ++ src/Endpoint/CheckoutEndpointV2.php | 28 +++++ src/Endpoint/EstablishmentDisputeEndpoint.php | 50 +++++++++ src/Endpoint/EstablishmentEndpoint.php | 9 ++ src/Model/CheckoutInstallments.php | 102 ++++++++++++++++++ 9 files changed, 318 insertions(+) create mode 100644 examples/checkout/01-get-installments-checkout.php create mode 100644 examples/establishment/09-establishment-get-disputes.php create mode 100644 examples/establishment/10-establishment-apply-dispute.php create mode 100644 examples/establishment/11-establishment-apply-chargebacks.php create mode 100644 src/Endpoint/CheckoutEndpointV2.php create mode 100644 src/Endpoint/EstablishmentDisputeEndpoint.php create mode 100644 src/Model/CheckoutInstallments.php diff --git a/examples/checkout/01-get-installments-checkout.php b/examples/checkout/01-get-installments-checkout.php new file mode 100644 index 0000000..e7536db --- /dev/null +++ b/examples/checkout/01-get-installments-checkout.php @@ -0,0 +1,34 @@ +checkoutV2()->getInstallments( + new CheckoutInstallments([ + 'amount' => 100.00 + ]) + ); + $data = $responseInstallmentsCheckout->getData(); + + echo "
" . PHP_EOL;
+    print_r($data);
+    echo "
" . PHP_EOL; + +} catch (Ipag\Sdk\Exception\HttpException $e) { + $code = $e->getResponse()->getStatusCode(); + $errors = $e->getErrors(); + + echo "
" . PHP_EOL;
+    var_dump($code, $errors);
+    echo "
" . PHP_EOL; + +} catch (Exception $e) { + $error = $e->getMessage(); + + echo "
" . PHP_EOL;
+    var_dump($error);
+    echo "
" . PHP_EOL; + +} \ No newline at end of file diff --git a/examples/establishment/09-establishment-get-disputes.php b/examples/establishment/09-establishment-get-disputes.php new file mode 100644 index 0000000..2cc8d79 --- /dev/null +++ b/examples/establishment/09-establishment-get-disputes.php @@ -0,0 +1,29 @@ +establishment()->disputes()->list($establishment_id); + $data = $responseDisputes->getData(); + + echo "
" . PHP_EOL;
+    print_r($data);
+    echo "
" . PHP_EOL; + +} catch (\Ipag\Sdk\Exception\HttpException $e) { + $code = $e->getResponse()->getStatusCode(); + $errors = $e->getErrors(); + + echo "
" . PHP_EOL;
+    var_dump($code, $errors);
+    echo "
" . PHP_EOL; +} catch (Exception $e) { + $error = $e->getMessage(); + + echo "
" . PHP_EOL;
+    var_dump($error);
+    echo "
" . PHP_EOL; +} \ No newline at end of file diff --git a/examples/establishment/10-establishment-apply-dispute.php b/examples/establishment/10-establishment-apply-dispute.php new file mode 100644 index 0000000..ffde91f --- /dev/null +++ b/examples/establishment/10-establishment-apply-dispute.php @@ -0,0 +1,30 @@ +establishment()->disputes()->applyDisputes($establishment_id, $transactions); + $data = $responseDisputes->getData(); + + echo "
" . PHP_EOL;
+    print_r($data);
+    echo "
" . PHP_EOL; + +} catch (\Ipag\Sdk\Exception\HttpException $e) { + $code = $e->getResponse()->getStatusCode(); + $errors = $e->getErrors(); + + echo "
" . PHP_EOL;
+    var_dump($code, $errors);
+    echo "
" . PHP_EOL; +} catch (Exception $e) { + $error = $e->getMessage(); + + echo "
" . PHP_EOL;
+    var_dump($error);
+    echo "
" . PHP_EOL; +} \ No newline at end of file diff --git a/examples/establishment/11-establishment-apply-chargebacks.php b/examples/establishment/11-establishment-apply-chargebacks.php new file mode 100644 index 0000000..f4a6e26 --- /dev/null +++ b/examples/establishment/11-establishment-apply-chargebacks.php @@ -0,0 +1,30 @@ +establishment()->disputes()->applyChargeBacks($establishment_id, $transactions); + $data = $responseChargeBacks->getData(); + + echo "
" . PHP_EOL;
+    print_r($data);
+    echo "
" . PHP_EOL; + +} catch (\Ipag\Sdk\Exception\HttpException $e) { + $code = $e->getResponse()->getStatusCode(); + $errors = $e->getErrors(); + + echo "
" . PHP_EOL;
+    var_dump($code, $errors);
+    echo "
" . PHP_EOL; +} catch (Exception $e) { + $error = $e->getMessage(); + + echo "
" . PHP_EOL;
+    var_dump($error);
+    echo "
" . PHP_EOL; +} \ No newline at end of file diff --git a/src/Core/IpagClient.php b/src/Core/IpagClient.php index 6b2d75b..2bc5c86 100644 --- a/src/Core/IpagClient.php +++ b/src/Core/IpagClient.php @@ -6,6 +6,7 @@ use Ipag\Sdk\Endpoint\AccountEndpoint; use Ipag\Sdk\Endpoint\ChargeEndpoint; use Ipag\Sdk\Endpoint\CheckoutEndpoint; +use Ipag\Sdk\Endpoint\CheckoutEndpointV2; use Ipag\Sdk\Endpoint\CustomerEndpoint; use Ipag\Sdk\Endpoint\EstablishmentEndpoint; use Ipag\Sdk\Endpoint\PaymentEndpoint; @@ -140,6 +141,11 @@ public function checkout(): CheckoutEndpoint return CheckoutEndpoint::make($this, $this); } + public function checkoutV2(): CheckoutEndpointV2 + { + return CheckoutEndpointV2::make($this, $this); + } + public function payment(): PaymentEndpoint { return PaymentEndpoint::make($this, $this); diff --git a/src/Endpoint/CheckoutEndpointV2.php b/src/Endpoint/CheckoutEndpointV2.php new file mode 100644 index 0000000..ddcfb73 --- /dev/null +++ b/src/Endpoint/CheckoutEndpointV2.php @@ -0,0 +1,28 @@ +_GET($checkoutInstallments->jsonSerialize(), [], '/installments'); + } +} \ No newline at end of file diff --git a/src/Endpoint/EstablishmentDisputeEndpoint.php b/src/Endpoint/EstablishmentDisputeEndpoint.php new file mode 100644 index 0000000..091f78a --- /dev/null +++ b/src/Endpoint/EstablishmentDisputeEndpoint.php @@ -0,0 +1,50 @@ +_GET([], [], "/$establishment_id/transactions/disputes"); + } + + /** + * Endpoint para aplicar disputas aos recursos `Transactions` + * @param string $establishment_id + * @param array $transactions + * @return Response + */ + public function applyDisputes(string $establishment_id, array $transactions): Response + { + return $this->_POST(compact('transactions'), [], [], "/$establishment_id/transactions/dispute"); + } + + /** + * Endpoint para aplicar charge back aos recursos `Transactions` + * @param string $establishment_id + * @param array $transactions + * @return Response + */ + public function applyChargeBacks(string $establishment_id, array $transactions): Response + { + return $this->_POST(compact('transactions'), [], [], "/$establishment_id/transactions/chargeback"); + } +} \ No newline at end of file diff --git a/src/Endpoint/EstablishmentEndpoint.php b/src/Endpoint/EstablishmentEndpoint.php index a3531d4..dba577e 100644 --- a/src/Endpoint/EstablishmentEndpoint.php +++ b/src/Endpoint/EstablishmentEndpoint.php @@ -103,4 +103,13 @@ public function antifraud(): EstablishmentAntifraudEndpoint { return EstablishmentAntifraudEndpoint::make($this->parent, $this->parent); } + + /** + * Endpoint `Dispute` do recurso `Establishment` + * @return EstablishmentDisputeEndpoint + */ + public function disputes(): EstablishmentDisputeEndpoint + { + return EstablishmentDisputeEndpoint::make($this->parent, $this->parent); + } } \ No newline at end of file diff --git a/src/Model/CheckoutInstallments.php b/src/Model/CheckoutInstallments.php new file mode 100644 index 0000000..cb95927 --- /dev/null +++ b/src/Model/CheckoutInstallments.php @@ -0,0 +1,102 @@ +float('amount')->nullable(); + $schema->int('max_installment')->nullable(); + $schema->int('installments_without_interest')->nullable(); + $schema->int('installment_min_amount')->nullable(); + $schema->float('installment_tax')->nullable(); + + return $schema->build(); + } + + protected function amount(): Mutator + { + return new Mutator( + null, + fn($value, $ctx) => + is_null($value) ? $value : + ( + Assert::value(floatval($value))->gte(0)->get() + ?? $ctx->raise('inválido') + ) + ); + } + + protected function max_installment(): Mutator + { + return new Mutator( + null, + fn($value, $ctx) => + is_null($value) ? $value : + ( + Assert::value(floatval($value))->gte(0)->get() + ?? $ctx->raise('inválido') + ) + ); + } + + protected function installments_without_interest(): Mutator + { + return new Mutator( + null, + fn($value, $ctx) => + is_null($value) ? $value : + ( + Assert::value(floatval($value))->gte(0)->get() + ?? $ctx->raise('inválido') + ) + ); + } + + protected function installment_min_amount(): Mutator + { + return new Mutator( + null, + fn($value, $ctx) => + is_null($value) ? $value : + ( + Assert::value(floatval($value))->gte(0)->get() + ?? $ctx->raise('inválido') + ) + ); + } + + protected function installment_tax(): Mutator + { + return new Mutator( + null, + fn($value, $ctx) => + is_null($value) ? $value : + ( + Assert::value(floatval($value))->gte(0)->get() + ?? $ctx->raise('inválido') + ) + ); + } +} \ No newline at end of file From 3488bd84b9e11918b48a32e8be04a83935af1954 Mon Sep 17 00:00:00 2001 From: Lucas Rosa Date: Tue, 8 Oct 2024 10:26:23 -0300 Subject: [PATCH 5/9] feat: adiciona novos endpoints nos: ChargeEndpoint, TokenEndpoint, ReceivableEndpoint --- examples/charge/04-charge-billing-notify.php | 31 +++++++++++++++++++ examples/receivable/00-receivables-list.php | 31 +++++++++++++++++++ ...php => 07-subscription-billing-notify.php} | 0 examples/token/02-token-list.php | 31 +++++++++++++++++++ src/Core/IpagClient.php | 11 +++++++ src/Endpoint/ChargeEndpointV2.php | 27 ++++++++++++++++ src/Endpoint/ReceivableEndpoint.php | 27 ++++++++++++++++ src/Endpoint/SubscriptionEndpointV2.php | 2 +- src/Endpoint/TokenEndpoint.php | 4 +++ 9 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 examples/charge/04-charge-billing-notify.php create mode 100644 examples/receivable/00-receivables-list.php rename examples/subscription/{07-subscription-charge-notify.php => 07-subscription-billing-notify.php} (100%) create mode 100644 examples/token/02-token-list.php create mode 100644 src/Endpoint/ChargeEndpointV2.php create mode 100644 src/Endpoint/ReceivableEndpoint.php diff --git a/examples/charge/04-charge-billing-notify.php b/examples/charge/04-charge-billing-notify.php new file mode 100644 index 0000000..9326963 --- /dev/null +++ b/examples/charge/04-charge-billing-notify.php @@ -0,0 +1,31 @@ +chargeV2()->notify($charge_id); + $data = $chargeNotifyResponse->getData(); + + echo "
" . PHP_EOL;
+    print_r($data);
+    echo "
" . PHP_EOL; + +} catch (Ipag\Sdk\Exception\HttpException $e) { + $code = $e->getResponse()->getStatusCode(); + $errors = $e->getErrors(); + + echo "
" . PHP_EOL;
+    var_dump($code, $errors);
+    echo "
" . PHP_EOL; + +} catch (Exception $e) { + $error = $e->getMessage(); + + echo "
" . PHP_EOL;
+    var_dump($error);
+    echo "
" . PHP_EOL; + +} \ No newline at end of file diff --git a/examples/receivable/00-receivables-list.php b/examples/receivable/00-receivables-list.php new file mode 100644 index 0000000..eefa9fa --- /dev/null +++ b/examples/receivable/00-receivables-list.php @@ -0,0 +1,31 @@ +receivable()->list([ + 'from' => '2024-08-27' + ]); + $data = $receivablesResponse->getData(); + + echo "
" . PHP_EOL;
+    print_r($data);
+    echo "
" . PHP_EOL; + +} catch (Ipag\Sdk\Exception\HttpException $e) { + $code = $e->getResponse()->getStatusCode(); + $errors = $e->getErrors(); + + echo "
" . PHP_EOL;
+    var_dump($code, $errors);
+    echo "
" . PHP_EOL; + +} catch (Exception $e) { + $error = $e->getMessage(); + + echo "
" . PHP_EOL;
+    var_dump($error);
+    echo "
" . PHP_EOL; + +} \ No newline at end of file diff --git a/examples/subscription/07-subscription-charge-notify.php b/examples/subscription/07-subscription-billing-notify.php similarity index 100% rename from examples/subscription/07-subscription-charge-notify.php rename to examples/subscription/07-subscription-billing-notify.php diff --git a/examples/token/02-token-list.php b/examples/token/02-token-list.php new file mode 100644 index 0000000..476b25b --- /dev/null +++ b/examples/token/02-token-list.php @@ -0,0 +1,31 @@ +token()->list([ + 'limit' => 10 + ]); + $data = $tokensResponse->getData(); + + echo "
" . PHP_EOL;
+    print_r($data);
+    echo "
" . PHP_EOL; + +} catch (Ipag\Sdk\Exception\HttpException $e) { + $code = $e->getResponse()->getStatusCode(); + $errors = $e->getErrors(); + + echo "
" . PHP_EOL;
+    var_dump($code, $errors);
+    echo "
" . PHP_EOL; + +} catch (Exception $e) { + $error = $e->getMessage(); + + echo "
" . PHP_EOL;
+    var_dump($error);
+    echo "
" . PHP_EOL; + +} \ No newline at end of file diff --git a/src/Core/IpagClient.php b/src/Core/IpagClient.php index 2bc5c86..ceecfd9 100644 --- a/src/Core/IpagClient.php +++ b/src/Core/IpagClient.php @@ -5,6 +5,7 @@ use Ipag\Sdk\Core\IpagEnvironment; use Ipag\Sdk\Endpoint\AccountEndpoint; use Ipag\Sdk\Endpoint\ChargeEndpoint; +use Ipag\Sdk\Endpoint\ChargeEndpointV2; use Ipag\Sdk\Endpoint\CheckoutEndpoint; use Ipag\Sdk\Endpoint\CheckoutEndpointV2; use Ipag\Sdk\Endpoint\CustomerEndpoint; @@ -12,6 +13,7 @@ use Ipag\Sdk\Endpoint\PaymentEndpoint; use Ipag\Sdk\Endpoint\PaymentLinksEndpoint; use Ipag\Sdk\Endpoint\PaymentLinksEndpointV2; +use Ipag\Sdk\Endpoint\ReceivableEndpoint; use Ipag\Sdk\Endpoint\SellerEndpoint; use Ipag\Sdk\Endpoint\SplitRulesEndpoint; use Ipag\Sdk\Endpoint\SubscriptionEndpoint; @@ -96,6 +98,11 @@ public function charge(): ChargeEndpoint return ChargeEndpoint::make($this, $this); } + public function chargeV2(): ChargeEndpointV2 + { + return ChargeEndpointV2::make($this, $this); + } + public function establishment(): EstablishmentEndpoint { return EstablishmentEndpoint::make($this, $this); @@ -156,4 +163,8 @@ public function account(): AccountEndpoint return AccountEndpoint::make($this, $this); } + public function receivable(): ReceivableEndpoint + { + return ReceivableEndpoint::make($this, $this); + } } \ No newline at end of file diff --git a/src/Endpoint/ChargeEndpointV2.php b/src/Endpoint/ChargeEndpointV2.php new file mode 100644 index 0000000..7bc7ede --- /dev/null +++ b/src/Endpoint/ChargeEndpointV2.php @@ -0,0 +1,27 @@ +_POST([], [], [], "/$charge_id/notify"); + } +} \ No newline at end of file diff --git a/src/Endpoint/ReceivableEndpoint.php b/src/Endpoint/ReceivableEndpoint.php new file mode 100644 index 0000000..60d7c8b --- /dev/null +++ b/src/Endpoint/ReceivableEndpoint.php @@ -0,0 +1,27 @@ +_GET($filters ?? [], [], '/upcoming'); + } +} \ No newline at end of file diff --git a/src/Endpoint/SubscriptionEndpointV2.php b/src/Endpoint/SubscriptionEndpointV2.php index 02972de..c876b54 100644 --- a/src/Endpoint/SubscriptionEndpointV2.php +++ b/src/Endpoint/SubscriptionEndpointV2.php @@ -12,7 +12,7 @@ */ class SubscriptionEndpointV2 extends Endpoint { - protected string $location = 'service/v2/subscription'; + protected string $location = '/service/v2/subscription'; /** * Endpoint para envio de email de cobrança ao cliente. diff --git a/src/Endpoint/TokenEndpoint.php b/src/Endpoint/TokenEndpoint.php index 696947c..467df47 100644 --- a/src/Endpoint/TokenEndpoint.php +++ b/src/Endpoint/TokenEndpoint.php @@ -39,4 +39,8 @@ public function get(string $token): Response return $this->_GET(['token' => $token]); } + public function list(?array $filters = []): Response + { + return $this->_GET($filters ?? []); + } } \ No newline at end of file From 498a82dac14be2a6b8ea84d06e66724280a4c2c4 Mon Sep 17 00:00:00 2001 From: Lucas Rosa Date: Tue, 8 Oct 2024 11:43:01 -0300 Subject: [PATCH 6/9] =?UTF-8?q?feat(docs):=20Atualiza=20documenta=C3=A7?= =?UTF-8?q?=C3=A3o=20com=20novos=20endpoints=20dispon=C3=ADveis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/README.md b/README.md index df6adf7..5c7b2ee 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ Este SDK, não necessariamente, reflete todos dos recursos e funcionalidades dis - [Desvincular Token da Assinatura](#desvincular-token-da-assinatura) - [Quitar Parcela da Assinatura](#quitar-parcela-da-assinatura) - [Agendar Parcelamento da Assinatura](#agendar-parcelamento-da-assinatura) + - [Enviar Notificação de Assinatura](#enviar-notificação-de-assinatura) - [Transação (Transaction)](#transação-transaction) - [Obter Transação](#obter-transação) - [Listar Transações](#listar-transações) @@ -63,11 +64,15 @@ Este SDK, não necessariamente, reflete todos dos recursos e funcionalidades dis - [Token (Card Token)](#token-card-token) - [Novo Token](#novo-token) - [Obter Token](#obter-token) + - [Listar Tokens](#listar-tokens) - [Cobrança (Charge)](#cobrança-charge) - [Nova Cobrança](#nova-cobrança) - [Alterar Cobrança](#alterar-cobrança) - [Obter Cobrança](#obter-cobrança) - [Listar Cobranças](#listar-cobranças) + - [Enviar Notificação de Cobrança](#enviar-notificação-de-cobrança) +- [Conta (Account)](#conta-account) + - [Listar Taxas](#listar-taxas) - [Estabelecimento (Establishment)](#estabelecimento-establishment) - [Novo Estabelecimento](#novo-estabelecimento) - [Alterar Estabelecimento](#alterar-estabelecimento) @@ -77,6 +82,9 @@ Este SDK, não necessariamente, reflete todos dos recursos e funcionalidades dis - [Listar todas Transações dos Estabelecimentos](#listar-todas-transações-dos-estabelecimentos) - [Listar Transações dos Estabelecimentos](#listar-transações-dos-estabelecimentos) - [Obter Transação de um Estabelecimento](#obter-transação-de-um-estabelecimento) + - [Aplicar Disputas de Transações](#aplicar-disputas-de-transações) + - [Aplicar Chargebacks de Transações](#aplicar-chargebacks-de-transações) + - [Listar Disputas de um Estabelecimento](#listar-disputas-de-um-estabelecimento) - [Métodos de Pagamento (Payment Methods)](#métodos-de-pagamento-payment-methods) - [Configurar Métodos de Pagamento](#configurar-métodos-de-pagamento) - [Antifraudes (Antifraud)](#antifraudes-antifraud) @@ -101,6 +109,7 @@ Este SDK, não necessariamente, reflete todos dos recursos e funcionalidades dis - [Listar Lançamentos Futuros](#listar-lançamentos-futuros) - [Listar Lançamentos Futuros de Vendedor (Por Id)](#listar-lançamentos-futuros-de-vendedor-por-id) - [Listar Lançamentos Futuros de Vendedor (Por CPF/CNPJ)](#listar-lançamentos-futuros-de-vendedor-por-cpfcnpj) + - [Listar Recebíveis](#listar-recebíveis) - [Link de Pagamento (Payment Links)](#link-de-pagamento-payment-links) - [Novo Link de Pagamento](#novo-link-de-pagamento) - [Obter Link de Pagamento (Por Id)](#obter-link-de-pagamento-por-id) @@ -113,6 +122,7 @@ Este SDK, não necessariamente, reflete todos dos recursos e funcionalidades dis - [Deletar Webhook](#deletar-webhook) - [Checkout](#checkout) - [Novo Checkout](#novo-checkout) + - [Obter Parcelamento](#obter-parcelamento) - [Voucher](#voucher) - [Novo Voucher](#novo-voucher) - [Helpers](#helpers) @@ -571,6 +581,12 @@ $responseSubscription = $ipagClient->subscription()->payOffInstallment($subscrip $responseSubscription = $ipagClient->subscription()->scheduleInstallmentPayment($subscriptionId, $invoiceNumber); ``` +### Enviar Notificação de Assinatura + +```php +$responseSubscriptionNotify = $ipagClient->subscriptionV2()->notify($subscriptionId); +``` + > Todos os exemplos: [examples/subscription/](https://github.com/ipagdevs/ipag-sdk-php/tree/master/examples/subscription/) # Transação (Transaction) @@ -661,6 +677,14 @@ $responseToken = $ipagClient->token()->create($token); $responseToken = $ipagClient->token()->get($tokenValue); ``` +### Listar Tokens + +```php +$tokensResponse = $ipagClient->token()->list([ + 'limit' => 10 +]); +``` + > Todos os exemplos: [examples/token/](https://github.com/ipagdevs/ipag-sdk-php/tree/master/examples/token/) # Cobrança (Charge) @@ -738,8 +762,22 @@ $responseCharge = $ipagClient->charge()->list([ ]); ``` +### Enviar Notificação de Cobrança + +```php +$chargeNotifyResponse = $ipagClient->chargeV2()->notify($chargeId); +``` + > Todos os exemplos: [examples/charge/](https://github.com/ipagdevs/ipag-sdk-php/tree/master/examples/charge/) +# Conta (Account) + +### Listar taxas + +```php +$responseMyFees = $ipagClient->account()->myFees(); +``` + # Estabelecimento (Establishment) ```php @@ -820,6 +858,26 @@ $responseTransactions = $ipagClient->establishment()->transaction()->listByEstab $responseTransactions = $ipagClient->establishment()->transaction()->getByEstablishment($establishmentTid, $transactionTid); ``` +### Aplicar Disputas de Transações + +```php +$transactions = [00001, 00002, 00003]; +$responseDisputes = $ipagClient->establishment()->disputes()->applyDisputes($establishmentId, $transactions); +``` + +### Aplicar Chargebacks de Transações + +```php +$transactions = [00001, 00002, 00003]; +$responseChargeBacks = $ipagClient->establishment()->disputes()->applyChargeBacks($establishmentId, $transactions); +``` + +### Listar Disputas de um Estabelecimento + +```php +$responseDisputes = $ipagClient->establishment()->disputes()->list($establishmentId); +``` + ## Métodos de Pagamento (Payment Methods) ```php @@ -1053,6 +1111,14 @@ $responseTransfers = $ipagClient->transfer()->future()->listBySellerId($sellerId $responseTransfers = $ipagClient->transfer()->future()->listBySellerCpfCnpj($sellerCpf); ``` +## Listar Recebíveis + +```php +$receivablesResponse = $ipagClient->receivable()->list([ + 'from' => '2024-08-27' +]); +``` + > Todos os exemplos: [examples/transfer/](https://github.com/ipagdevs/ipag-sdk-php/tree/master/examples/transfer/) # Link de Pagamento (Payment Links) @@ -1268,6 +1334,16 @@ $checkout = (new \Ipag\Sdk\Model\Checkout()) $responseCheckout = $ipagClient->checkout()->create($checkout); ``` +### Obter Parcelamento + +```php + $responseInstallmentsCheckout = $ipagClient->checkoutV2()->getInstallments( + new CheckoutInstallments([ + 'amount' => 100.00 + ]) + ); +``` + > Todos os exemplos: [examples/checkout/](https://github.com/ipagdevs/ipag-sdk-php/tree/master/examples/checkout/) # Voucher From d5ef4c0625f629d9c588c32743f24c157b14756b Mon Sep 17 00:00:00 2001 From: Lucas Rosa Date: Tue, 8 Oct 2024 16:55:14 -0300 Subject: [PATCH 7/9] feat: adiciona tests dos novos endpoints e models --- src/Endpoint/CheckoutEndpointV2.php | 2 +- src/Model/CheckoutInstallments.php | 63 +++++++++++- tests/Endpoint/AccountEndpointTest.php | 90 +++++++++++++++++ tests/Endpoint/ChargeEndpointV2Test.php | 98 +++++++++++++++++++ tests/Endpoint/CheckoutEndpointV2Test.php | 89 +++++++++++++++++ .../EstablishmentDisputeEndpointTest.php | 97 ++++++++++++++++++ tests/Endpoint/PaymentLinksEndpointV2Test.php | 90 +++++++++++++++++ tests/Endpoint/ReceivableEndpointTest.php | 89 +++++++++++++++++ tests/Endpoint/SubscriptionEndpointV2Test.php | 97 ++++++++++++++++++ tests/Model/CheckoutInstallmentsTest.php | 82 ++++++++++++++++ tests/Model/PaymentTransactionTest.php | 8 ++ 11 files changed, 800 insertions(+), 5 deletions(-) create mode 100644 tests/Endpoint/AccountEndpointTest.php create mode 100644 tests/Endpoint/ChargeEndpointV2Test.php create mode 100644 tests/Endpoint/CheckoutEndpointV2Test.php create mode 100644 tests/Endpoint/EstablishmentDisputeEndpointTest.php create mode 100644 tests/Endpoint/PaymentLinksEndpointV2Test.php create mode 100644 tests/Endpoint/ReceivableEndpointTest.php create mode 100644 tests/Endpoint/SubscriptionEndpointV2Test.php create mode 100644 tests/Model/CheckoutInstallmentsTest.php diff --git a/src/Endpoint/CheckoutEndpointV2.php b/src/Endpoint/CheckoutEndpointV2.php index ddcfb73..5f3b8e3 100644 --- a/src/Endpoint/CheckoutEndpointV2.php +++ b/src/Endpoint/CheckoutEndpointV2.php @@ -23,6 +23,6 @@ class CheckoutEndpointV2 extends Endpoint */ public function getInstallments(?CheckoutInstallments $checkoutInstallments = null): Response { - return $this->_GET($checkoutInstallments->jsonSerialize(), [], '/installments'); + return $this->_GET(empty($checkoutInstallments) ? [] : $checkoutInstallments->jsonSerialize(), [], '/installments'); } } \ No newline at end of file diff --git a/src/Model/CheckoutInstallments.php b/src/Model/CheckoutInstallments.php index cb95927..19236b8 100644 --- a/src/Model/CheckoutInstallments.php +++ b/src/Model/CheckoutInstallments.php @@ -16,7 +16,7 @@ final class CheckoutInstallments extends Model * + [`'amount'`] float (opcional). * + [`'max_installment'`] int (opcional). * + [`'installments_without_interest'`] int (opcional). - * + [`'installment_min_amount'`] int (opcional). + * + [`'installment_min_amount'`] float (opcional). * + [`'installment_tax'`] float (opcional). */ public function __construct(?array $data = []) @@ -29,7 +29,7 @@ public function schema(SchemaBuilder $schema): Schema $schema->float('amount')->nullable(); $schema->int('max_installment')->nullable(); $schema->int('installments_without_interest')->nullable(); - $schema->int('installment_min_amount')->nullable(); + $schema->float('installment_min_amount')->nullable(); $schema->float('installment_tax')->nullable(); return $schema->build(); @@ -55,7 +55,7 @@ protected function max_installment(): Mutator fn($value, $ctx) => is_null($value) ? $value : ( - Assert::value(floatval($value))->gte(0)->get() + Assert::value(intval($value))->gte(0)->get() ?? $ctx->raise('inválido') ) ); @@ -68,7 +68,7 @@ protected function installments_without_interest(): Mutator fn($value, $ctx) => is_null($value) ? $value : ( - Assert::value(floatval($value))->gte(0)->get() + Assert::value(intval($value))->gte(0)->get() ?? $ctx->raise('inválido') ) ); @@ -99,4 +99,59 @@ protected function installment_tax(): Mutator ) ); } + + public function getAmount(): ?float + { + return $this->get('amount'); + } + + public function setAmount(?float $amount = null): self + { + $this->set('amount', $amount); + return $this; + } + + public function getMaxInstallment(): ?int + { + return $this->get('max_installment'); + } + + public function setMaxInstallment(?int $max_installment = null): self + { + $this->set('max_installment', $max_installment); + return $this; + } + + public function getInstallmentsWithoutInterest(): ?int + { + return $this->get('installments_without_interest'); + } + + public function setInstallmentsWithoutInterest(?int $installments_without_interest = null): self + { + $this->set('installments_without_interest', $installments_without_interest); + return $this; + } + + public function getInstallmentMinAmount(): ?float + { + return $this->get('installment_min_amount'); + } + + public function setInstallmentMinAmount(?float $installment_min_amount = null): self + { + $this->set('installment_min_amount', $installment_min_amount); + return $this; + } + + public function getInstallmentTax(): ?float + { + return $this->get('installment_tax'); + } + + public function setInstallmentTax(?float $installment_tax = null): self + { + $this->set('installment_tax', $installment_tax); + return $this; + } } \ No newline at end of file diff --git a/tests/Endpoint/AccountEndpointTest.php b/tests/Endpoint/AccountEndpointTest.php new file mode 100644 index 0000000..e9fd1d2 --- /dev/null +++ b/tests/Endpoint/AccountEndpointTest.php @@ -0,0 +1,90 @@ +instanceClient([ + new Response( + 201, + [], + json_encode(((object) [])) + ) + ]); + + $accountResponse = $this->client->account()->myFees(); + + $this->assertIsObject($accountResponse); + } + + public function testShouldResponseFailUnprocessableDataClient() + { + $this->expectException(HttpException::class); + + $this->instanceClient([ + new Response( + 406, + [], + json_encode( + (object) [ + "code" => "406", + "message" => + [ + "description" => + [ + "Description is required", + "Description must be at least 10 characters long", + ] + ] + ] + ) + ) + ]); + + $this->client->account()->myFees(); + + } + + public function testShouldResponseFailUnauthenticatedClient() + { + $this->expectException(HttpException::class); + + $this->instanceClient([ + new Response( + 401, + [], + json_encode( + (object) [ + "code" => 401, + "message" => "Unauthorized", + "resource" => "authorization" + ] + ) + ) + ]); + + $this->client->account()->myFees(); + } + + public function testThrowsServerExceptionOnServerError() + { + $this->expectException(HttpServerException::class); + + $this->instanceClient([ + new Response( + 500, + [], + json_encode(((object) [])) + ) + ]); + + $this->client->paymentLinksV2()->list([]); + } +} \ No newline at end of file diff --git a/tests/Endpoint/ChargeEndpointV2Test.php b/tests/Endpoint/ChargeEndpointV2Test.php new file mode 100644 index 0000000..0ac91ba --- /dev/null +++ b/tests/Endpoint/ChargeEndpointV2Test.php @@ -0,0 +1,98 @@ +instanceClient([ + new Response( + 201, + [], + json_encode(((object) [])) + ) + ]); + + $charge_id = 1; + + $chargeResponse = $this->client->chargeV2()->notify($charge_id); + + $this->assertIsObject($chargeResponse); + } + + public function testShouldResponseFailUnprocessableDataClient() + { + $this->expectException(HttpException::class); + + $this->instanceClient([ + new Response( + 406, + [], + json_encode( + (object) [ + "code" => "406", + "message" => + [ + "description" => + [ + "Description is required", + "Description must be at least 10 characters long", + ] + ] + ] + ) + ) + ]); + + $charge_id = 1; + + $this->client->chargeV2()->notify($charge_id); + } + + public function testShouldResponseFailUnauthenticatedClient() + { + $this->expectException(HttpException::class); + + $this->instanceClient([ + new Response( + 401, + [], + json_encode( + (object) [ + "code" => 401, + "message" => "Unauthorized", + "resource" => "authorization" + ] + ) + ) + ]); + + $charge_id = 1; + + $this->client->chargeV2()->notify($charge_id); + } + + public function testThrowsServerExceptionOnServerError() + { + $this->expectException(HttpServerException::class); + + $this->instanceClient([ + new Response( + 500, + [], + json_encode(((object) [])) + ) + ]); + + $charge_id = 1; + + $this->client->chargeV2()->notify($charge_id); + } + +} \ No newline at end of file diff --git a/tests/Endpoint/CheckoutEndpointV2Test.php b/tests/Endpoint/CheckoutEndpointV2Test.php new file mode 100644 index 0000000..71442ca --- /dev/null +++ b/tests/Endpoint/CheckoutEndpointV2Test.php @@ -0,0 +1,89 @@ +instanceClient([ + new Response( + 201, + [], + json_encode(((object) [])) + ) + ]); + + $checkoutResponse = $this->client->checkoutV2()->getInstallments(); + + $this->assertIsObject($checkoutResponse); + } + + public function testShouldResponseFailUnprocessableDataClient() + { + $this->expectException(HttpException::class); + + $this->instanceClient([ + new Response( + 406, + [], + json_encode( + (object) [ + "code" => "406", + "message" => + [ + "description" => + [ + "Description is required", + "Description must be at least 10 characters long", + ] + ] + ] + ) + ) + ]); + + $this->client->checkoutV2()->getInstallments(); + } + + public function testShouldResponseFailUnauthenticatedClient() + { + $this->expectException(HttpException::class); + + $this->instanceClient([ + new Response( + 401, + [], + json_encode( + (object) [ + "code" => 401, + "message" => "Unauthorized", + "resource" => "authorization" + ] + ) + ) + ]); + + $this->client->checkoutV2()->getInstallments(); + } + + public function testThrowsServerExceptionOnServerError() + { + $this->expectException(HttpServerException::class); + + $this->instanceClient([ + new Response( + 500, + [], + json_encode(((object) [])) + ) + ]); + + $this->client->checkoutV2()->getInstallments(); + } +} \ No newline at end of file diff --git a/tests/Endpoint/EstablishmentDisputeEndpointTest.php b/tests/Endpoint/EstablishmentDisputeEndpointTest.php new file mode 100644 index 0000000..0fc244d --- /dev/null +++ b/tests/Endpoint/EstablishmentDisputeEndpointTest.php @@ -0,0 +1,97 @@ +instanceClient([ + new Response( + 201, + [], + json_encode(((object) [])) + ) + ]); + + $establishment_id = 100000; + + $disputeResponse = $this->client->establishment()->disputes()->list($establishment_id); + + $this->assertIsObject($disputeResponse); + } + + public function testShouldResponseFailUnprocessableDataClient() + { + $this->expectException(HttpException::class); + + $this->instanceClient([ + new Response( + 406, + [], + json_encode( + (object) [ + "code" => "406", + "message" => + [ + "description" => + [ + "Description is required", + "Description must be at least 10 characters long", + ] + ] + ] + ) + ) + ]); + + $establishment_id = 100000; + + $this->client->establishment()->disputes()->list($establishment_id); + } + + public function testShouldResponseFailUnauthenticatedClient() + { + $this->expectException(HttpException::class); + + $this->instanceClient([ + new Response( + 401, + [], + json_encode( + (object) [ + "code" => 401, + "message" => "Unauthorized", + "resource" => "authorization" + ] + ) + ) + ]); + + $establishment_id = 100000; + + $this->client->establishment()->disputes()->list($establishment_id); + } + + public function testThrowsServerExceptionOnServerError() + { + $this->expectException(HttpServerException::class); + + $this->instanceClient([ + new Response( + 500, + [], + json_encode(((object) [])) + ) + ]); + + $establishment_id = 100000; + + $this->client->establishment()->disputes()->list($establishment_id); + } +} \ No newline at end of file diff --git a/tests/Endpoint/PaymentLinksEndpointV2Test.php b/tests/Endpoint/PaymentLinksEndpointV2Test.php new file mode 100644 index 0000000..226e90f --- /dev/null +++ b/tests/Endpoint/PaymentLinksEndpointV2Test.php @@ -0,0 +1,90 @@ +instanceClient([ + new Response( + 201, + [], + json_encode(((object) [])) + ) + ]); + + $paymentLinksResponse = $this->client->paymentLinksV2()->list(); + + $this->assertIsObject($paymentLinksResponse); + + } + + public function testShouldResponseFailUnprocessableDataClient() + { + $this->expectException(HttpException::class); + + $this->instanceClient([ + new Response( + 406, + [], + json_encode( + (object) [ + "code" => "406", + "message" => + [ + "description" => + [ + "Description is required", + "Description must be at least 10 characters long", + ] + ] + ] + ) + ) + ]); + + $this->client->paymentLinksV2()->list(); + } + + public function testShouldResponseFailUnauthenticatedClient() + { + $this->expectException(HttpException::class); + + $this->instanceClient([ + new Response( + 401, + [], + json_encode( + (object) [ + "code" => 401, + "message" => "Unauthorized", + "resource" => "authorization" + ] + ) + ) + ]); + + $this->client->paymentLinksV2()->list(); + } + + public function testThrowsServerExceptionOnServerError() + { + $this->expectException(HttpServerException::class); + + $this->instanceClient([ + new Response( + 500, + [], + json_encode(((object) [])) + ) + ]); + + $this->client->paymentLinksV2()->list(); + } +} \ No newline at end of file diff --git a/tests/Endpoint/ReceivableEndpointTest.php b/tests/Endpoint/ReceivableEndpointTest.php new file mode 100644 index 0000000..d07b011 --- /dev/null +++ b/tests/Endpoint/ReceivableEndpointTest.php @@ -0,0 +1,89 @@ +instanceClient([ + new Response( + 201, + [], + json_encode(((object) [])) + ) + ]); + + $receivableResponse = $this->client->receivable()->list(); + + $this->assertIsObject($receivableResponse); + } + + public function testShouldResponseFailUnprocessableDataClient() + { + $this->expectException(HttpException::class); + + $this->instanceClient([ + new Response( + 406, + [], + json_encode( + (object) [ + "code" => "406", + "message" => + [ + "description" => + [ + "Description is required", + "Description must be at least 10 characters long", + ] + ] + ] + ) + ) + ]); + + $this->client->receivable()->list(); + } + + public function testShouldResponseFailUnauthenticatedClient() + { + $this->expectException(HttpException::class); + + $this->instanceClient([ + new Response( + 401, + [], + json_encode( + (object) [ + "code" => 401, + "message" => "Unauthorized", + "resource" => "authorization" + ] + ) + ) + ]); + + $this->client->receivable()->list(); + } + + public function testThrowsServerExceptionOnServerError() + { + $this->expectException(HttpServerException::class); + + $this->instanceClient([ + new Response( + 500, + [], + json_encode(((object) [])) + ) + ]); + + $this->client->receivable()->list(); + } +} \ No newline at end of file diff --git a/tests/Endpoint/SubscriptionEndpointV2Test.php b/tests/Endpoint/SubscriptionEndpointV2Test.php new file mode 100644 index 0000000..1c317f5 --- /dev/null +++ b/tests/Endpoint/SubscriptionEndpointV2Test.php @@ -0,0 +1,97 @@ +instanceClient([ + new Response( + 201, + [], + json_encode(((object) [])) + ) + ]); + + $subscription_id = 1; + + $notifyResponse = $this->client->subscriptionV2()->notify($subscription_id); + + $this->assertIsObject($notifyResponse); + } + + public function testShouldResponseFailUnprocessableDataClient() + { + $this->expectException(HttpException::class); + + $this->instanceClient([ + new Response( + 406, + [], + json_encode( + (object) [ + "code" => "406", + "message" => + [ + "description" => + [ + "Description is required", + "Description must be at least 10 characters long", + ] + ] + ] + ) + ) + ]); + + $subscription_id = 1; + + $this->client->subscriptionV2()->notify($subscription_id); + } + + public function testShouldResponseFailUnauthenticatedClient() + { + $this->expectException(HttpException::class); + + $this->instanceClient([ + new Response( + 401, + [], + json_encode( + (object) [ + "code" => 401, + "message" => "Unauthorized", + "resource" => "authorization" + ] + ) + ) + ]); + + $subscription_id = 1; + + $this->client->subscriptionV2()->notify($subscription_id); + } + + public function testThrowsServerExceptionOnServerError() + { + $this->expectException(HttpServerException::class); + + $this->instanceClient([ + new Response( + 500, + [], + json_encode(((object) [])) + ) + ]); + + $subscription_id = 1; + + $this->client->subscriptionV2()->notify($subscription_id); + } +} \ No newline at end of file diff --git a/tests/Model/CheckoutInstallmentsTest.php b/tests/Model/CheckoutInstallmentsTest.php new file mode 100644 index 0000000..016b846 --- /dev/null +++ b/tests/Model/CheckoutInstallmentsTest.php @@ -0,0 +1,82 @@ + 100.00, + 'max_installment' => 12, + 'installments_without_interest' => 3, + 'installment_min_amount' => 5.00, + 'installment_tax' => 2.24, + ]); + + $this->assertEquals(100.00, $checkoutInstallments->getAmount()); + $this->assertEquals(12, $checkoutInstallments->getMaxInstallment()); + $this->assertEquals(3, $checkoutInstallments->getInstallmentsWithoutInterest()); + $this->assertEquals(5.00, $checkoutInstallments->getInstallmentMinAmount()); + $this->assertEquals(2.24, $checkoutInstallments->getInstallmentTax()); + + } + + public function testShouldCreateCheckoutInstallmentsObjectAndSetTheValuesSuccessfully() + { + $checkoutInstallments = (new \Ipag\Sdk\Model\CheckoutInstallments()) + ->setAmount(100.00) + ->setMaxInstallment(12) + ->setInstallmentsWithoutInterest(3) + ->setInstallmentMinAmount(5.00) + ->setInstallmentTax(2.24); + + $this->assertEquals(100.00, $checkoutInstallments->getAmount()); + $this->assertEquals(12, $checkoutInstallments->getMaxInstallment()); + $this->assertEquals(3, $checkoutInstallments->getInstallmentsWithoutInterest()); + $this->assertEquals(5.00, $checkoutInstallments->getInstallmentMinAmount()); + $this->assertEquals(2.24, $checkoutInstallments->getInstallmentTax()); + + } + + public function testShouldCreateEmptyCheckoutInstallmentsObjectSuccessfully() + { + $checkoutInstallments = new \Ipag\Sdk\Model\CheckoutInstallments(); + + $this->assertEmpty($checkoutInstallments->getAmount()); + $this->assertEmpty($checkoutInstallments->getMaxInstallment()); + $this->assertEmpty($checkoutInstallments->getInstallmentsWithoutInterest()); + $this->assertEmpty($checkoutInstallments->getInstallmentMinAmount()); + $this->assertEmpty($checkoutInstallments->getInstallmentTax()); + + } + + public function testCreateAndSetEmptyPropertiesCheckoutInstallmentsObjectSuccessfully() + { + $checkoutInstallments = new \Ipag\Sdk\Model\CheckoutInstallments([ + 'amount' => 100.00, + 'max_installment' => 12, + 'installments_without_interest' => 3, + 'installment_min_amount' => 5.00, + 'installment_tax' => 2.24, + ]); + + $checkoutInstallments + ->setAmount(null) + ->setMaxInstallment(null) + ->setInstallmentsWithoutInterest(null) + ->setInstallmentMinAmount(null) + ->setInstallmentTax(null); + + $this->assertEmpty($checkoutInstallments->getAmount()); + $this->assertEmpty($checkoutInstallments->getMaxInstallment()); + $this->assertEmpty($checkoutInstallments->getInstallmentsWithoutInterest()); + $this->assertEmpty($checkoutInstallments->getInstallmentMinAmount()); + $this->assertEmpty($checkoutInstallments->getInstallmentTax()); + + } +} \ No newline at end of file diff --git a/tests/Model/PaymentTransactionTest.php b/tests/Model/PaymentTransactionTest.php index 14ef922..ee40557 100644 --- a/tests/Model/PaymentTransactionTest.php +++ b/tests/Model/PaymentTransactionTest.php @@ -13,6 +13,7 @@ public function testShouldCreatePaymentTransactionObjectWithConstructorSuccessfu 'amount' => 100.0, 'order_id' => '123456', 'callback_url' => 'https://ipag-sdk.requestcatcher.com/callback', + 'redirect_url' => 'https://ipag-sdk.requestcatcher.com/callback', 'antifraud' => [ 'fingerprint' => '123', 'provider' => 'test', @@ -88,6 +89,7 @@ public function testShouldCreatePaymentTransactionObjectWithConstructorSuccessfu $this->assertEquals(100.0, $paymentTransaction->getAmount()); $this->assertEquals('123456', $paymentTransaction->getOrderId()); $this->assertEquals('https://ipag-sdk.requestcatcher.com/callback', $paymentTransaction->getCallbackUrl()); + $this->assertEquals('https://ipag-sdk.requestcatcher.com/callback', $paymentTransaction->getRedirectUrl()); $this->assertEquals('123', $paymentTransaction->getAntifraud()->getFingerprint()); $this->assertEquals('test', $paymentTransaction->getAntifraud()->getProvider()); @@ -155,6 +157,7 @@ public function testShouldCreatePaymentTransactionObjectAndSetTheValuesSuccessfu ->setAmount(100.0) ->setOrderId('123456') ->setCallbackUrl('https://ipag-sdk.requestcatcher.com/callback') + ->setRedirectUrl('https://ipag-sdk.requestcatcher.com/callback') ->setAntifraud( (new \Ipag\Sdk\Model\PaymentAntifraud()) ->setFingerprint('123') @@ -238,6 +241,7 @@ public function testShouldCreatePaymentTransactionObjectAndSetTheValuesSuccessfu $this->assertEquals(100.0, $paymentTransaction->getAmount()); $this->assertEquals('123456', $paymentTransaction->getOrderId()); $this->assertEquals('https://ipag-sdk.requestcatcher.com/callback', $paymentTransaction->getCallbackUrl()); + $this->assertEquals('https://ipag-sdk.requestcatcher.com/callback', $paymentTransaction->getRedirectUrl()); $this->assertEquals('123', $paymentTransaction->getAntifraud()->getFingerprint()); $this->assertEquals('test', $paymentTransaction->getAntifraud()->getProvider()); @@ -306,6 +310,7 @@ public function testShouldCreateEmptyPaymentTransactionObjectSuccessfully() $this->assertEmpty($paymentTransaction->getAmount()); $this->assertEmpty($paymentTransaction->getOrderId()); $this->assertEmpty($paymentTransaction->getCallbackUrl()); + $this->assertEmpty($paymentTransaction->getRedirectUrl()); $this->assertEmpty($paymentTransaction->getAntifraud()); $this->assertEmpty($paymentTransaction->getPayment()); $this->assertEmpty($paymentTransaction->getCustomer()); @@ -322,6 +327,7 @@ public function testCreateAndSetEmptyPropertiesPaymentTransactionObjectSuccessfu 'amount' => 100.0, 'order_id' => '123456', 'callback_url' => 'https://ipag-sdk.requestcatcher.com/callback', + 'redirect_url' => 'https://ipag-sdk.requestcatcher.com/callback', 'antifraud' => [ 'fingerprint' => '123', 'provider' => 'test', @@ -398,6 +404,7 @@ public function testCreateAndSetEmptyPropertiesPaymentTransactionObjectSuccessfu ->setAmount(null) ->setOrderId(null) ->setCallbackUrl(null) + ->setRedirectUrl(null) ->setAntifraud(null) ->setPayment(null) ->setCustomer(null) @@ -409,6 +416,7 @@ public function testCreateAndSetEmptyPropertiesPaymentTransactionObjectSuccessfu $this->assertEmpty($paymentTransaction->getAmount()); $this->assertEmpty($paymentTransaction->getOrderId()); $this->assertEmpty($paymentTransaction->getCallbackUrl()); + $this->assertEmpty($paymentTransaction->getRedirectUrl()); $this->assertEmpty($paymentTransaction->getAntifraud()); $this->assertEmpty($paymentTransaction->getPayment()); $this->assertEmpty($paymentTransaction->getCustomer()); From d433204179844d455640469d5b1e13acdcde6319 Mon Sep 17 00:00:00 2001 From: Lucas Rosa Date: Tue, 8 Oct 2024 17:17:46 -0300 Subject: [PATCH 8/9] =?UTF-8?q?fix:=20corrige=20parametro=20n=C3=A3o=20uti?= =?UTF-8?q?lizado=20recebido=20do=20endpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Endpoint/EstablishmentDisputeEndpoint.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Endpoint/EstablishmentDisputeEndpoint.php b/src/Endpoint/EstablishmentDisputeEndpoint.php index 091f78a..7c1d637 100644 --- a/src/Endpoint/EstablishmentDisputeEndpoint.php +++ b/src/Endpoint/EstablishmentDisputeEndpoint.php @@ -23,7 +23,7 @@ class EstablishmentDisputeEndpoint extends Endpoint */ public function list(string $establishment_id, ?array $filters = []): Response { - return $this->_GET([], [], "/$establishment_id/transactions/disputes"); + return $this->_GET($filters, [], "/$establishment_id/transactions/disputes"); } /** From 104085c1b3c15422623cd518971b8ad32e604396 Mon Sep 17 00:00:00 2001 From: Lucas Rosa Date: Tue, 8 Oct 2024 17:38:30 -0300 Subject: [PATCH 9/9] =?UTF-8?q?fix:=20aprimora=20os=20dados=20do=20exemplo?= =?UTF-8?q?=20de=20atualiza=C3=A7=C3=A3o=20de=20cobran=C3=A7a?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/charge/01-charge-update.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/charge/01-charge-update.php b/examples/charge/01-charge-update.php index 1f4a512..cac88c1 100644 --- a/examples/charge/01-charge-update.php +++ b/examples/charge/01-charge-update.php @@ -3,9 +3,9 @@ require_once __DIR__ . '/..' . '/config.php'; $charge = new \Ipag\Sdk\Model\Charge([ - 'amount' => 100, - 'description' => 'Cobrança referente a negociação de débito pendente na Empresa X', - 'due_date' => '2020-10-30', + 'amount' => 99, + 'description' => 'Cobrança referente a negociação de débito pendente na Empresa XX', + 'due_date' => '2020-10-29', 'frequency' => 1, 'interval' => 'month', 'type' => 'charge',