diff --git a/README.md b/README.md index cf68b44..4145443 100644 --- a/README.md +++ b/README.md @@ -22,28 +22,7 @@ na seção `require` do seu arquivo `composer.json`. ## Como Usar? ### Minimo para utilização -# -#### 1. Identificador único de cliente -```php -$sut = new CustomerIdentifierCreator($_ENV['ASAAS_API_KEY'], true); - -$customerAsaasId = $sut->generateCustomerIdentifier(new CustomerData( - name: 'Joãozinho Barbosa', - phone: '999999999', - cpfCnpj: '01234567890' -)); - -print_r($customerAsaasId); -``` -#### Saída -``` -[ - 'identifier' => 'cus_xxxxxxxx' -] -``` -# -#### 2. Criar cobrança ```php use AstrotechLabs\AsaasSdk\AssasGateway; use AstrotechLabs\AsaasSdk\Enum\BillingTypes; @@ -56,7 +35,11 @@ $asaasGateway = new AssasGateway(new AssasGatewayParams( )); $pixChargeResponse = $asaasGateway->createCharge(new PixData( - customer: 'cus_xxxxxxxx', // Identificador único de cliente + customer: new CustomerData( + name: 'Joãozinho Barbosa', + phone: '999999999', + cpfCnpj: '01234567890' + ), billingType: BillingTypes::PIX, value: 100.00, dueDate: "2023-12-20" diff --git a/composer.json b/composer.json index fc1a76b..ff93678 100644 --- a/composer.json +++ b/composer.json @@ -1,9 +1,16 @@ { "name": "astrotechlabs/asaas-sdk", "description": "Pacote facilitador para integrações com Asaas Pagamento", - "type": "project", - "license": "BSD-3-Clause", - "minimum-stability": "stable", + "type": "sdk", + "license": "MIT", + "minimum-stability": "dev", + "keywords": [ + "asaas", + "asaas-pix", + "asaas-payments", + "asaas-sdk", + "asaas-php" + ], "scripts": { "test": "XDEBUG_MODE=debug; phpunit --testdox --do-not-cache-result --configuration tests/phpunit.xml", "test:unit": "XDEBUG_MODE=debug; phpunit --do-not-cache-result --configuration tests/phpunit.xml --testdox --testsuite unit", diff --git a/src/CreatePixCharge/Dto/PixData.php b/src/CreatePixCharge/Dto/PixData.php index 2d961d7..ff756b4 100644 --- a/src/CreatePixCharge/Dto/PixData.php +++ b/src/CreatePixCharge/Dto/PixData.php @@ -4,12 +4,13 @@ namespace AstrotechLabs\AsaasSdk\CreatePixCharge\Dto; +use AstrotechLabs\AsaasSdk\CustomerIdentifierCreator\Dto\CustomerData; use AstrotechLabs\AsaasSdk\Enum\BillingTypes; final class PixData { public function __construct( - public readonly string $customer, + public readonly CustomerData $customer, public readonly BillingTypes $billingType, public readonly float $value, public readonly string $dueDate diff --git a/src/CustomerIdentifierCreator/Dto/CustomerData.php b/src/CustomerIdentifierCreator/Dto/CustomerData.php index f82673f..fbeabd5 100644 --- a/src/CustomerIdentifierCreator/Dto/CustomerData.php +++ b/src/CustomerIdentifierCreator/Dto/CustomerData.php @@ -10,6 +10,7 @@ public function __construct( public readonly string $name, public readonly string $phone, public readonly string $cpfCnpj, + public ?string $identifier = null, public readonly ?string $email = null, public readonly ?string $postalCode = null, public readonly ?string $address = null, diff --git a/tests/Integration/CreatePixChargeGateway/CreateAsaasPixChargeGatewayTest.php b/tests/Integration/CreatePixChargeGateway/CreateAsaasPixChargeGatewayTest.php index 0f53511..dec4fb8 100644 --- a/tests/Integration/CreatePixChargeGateway/CreateAsaasPixChargeGatewayTest.php +++ b/tests/Integration/CreatePixChargeGateway/CreateAsaasPixChargeGatewayTest.php @@ -4,6 +4,8 @@ namespace Tests\Integration\CreatePixChargeGateway; +use AstrotechLabs\AsaasSdk\CustomerIdentifierCreator\Dto\CustomerData; +use DateTime; use Tests\TestCase; use AstrotechLabs\AsaasSdk\Enum\BillingTypes; use AstrotechLabs\AsaasSdk\CreatePixCharge\Dto\PixData; @@ -35,16 +37,19 @@ public function testItShouldThrowAnExceptionWhenProvideInvalidCustomerIdentifier { $this->expectException(CreatePixChargeException::class); $this->expectExceptionCode(1001); - $this->expectExceptionMessage('Customer inválido ou não informado.'); $sut = new CreatePixChargeGateway($_ENV['ASAAS_API_KEY'], true); $customerIdentifier = self::$faker->uuid; $response = $sut->createCharge(new PixData( - customer: $customerIdentifier, + customer: new CustomerData( + name: '', + phone: '', + cpfCnpj: '', + ), billingType: BillingTypes::PIX, value: 100.90, - dueDate: "2023-12-20" + dueDate: (new DateTime())->modify('+1 day')->format('Y-m-d') )); } @@ -58,7 +63,11 @@ public function testItShouldThrowAnExceptionWhenProvideInvalidDueDate() $customerIdentifier = 'cus_000005797885'; $response = $sut->createCharge(new PixData( - customer: $customerIdentifier, + customer: new CustomerData( + name: self::$faker->name, + phone: self::$faker->phoneNumber, + cpfCnpj: self::$faker->numerify('67981499011'), + ), billingType: BillingTypes::PIX, value: 100.90, dueDate: "2023-07-20" @@ -68,14 +77,17 @@ public function testItShouldThrowAnExceptionWhenProvideInvalidDueDate() public function testItShouldCreatePaymentCharge() { $sut = new CreatePixChargeGateway($_ENV['ASAAS_API_KEY'], true); - - $customerIdentifier = 'cus_000005797885'; + $customer = new CustomerData( + name: self::$faker->name, + phone: self::$faker->phoneNumber, + cpfCnpj: self::$faker->numerify('67981499011'), + ); $response = $sut->createCharge(new PixData( - customer: $customerIdentifier, + customer: $customer, billingType: BillingTypes::PIX, value: 100.90, - dueDate: "2023-12-20" + dueDate: "2023-12-30" )); $this->assertIsObject($response); @@ -91,7 +103,6 @@ public function testItShouldCreatePaymentCharge() $this->assertArrayHasKey('status', $response->details); $this->assertSame($response->gatewayId, $response->details['id']); $this->assertSame($response->paymentUrl, $response->details['invoiceUrl']); - $this->assertSame($customerIdentifier, $response->details['customer']); } public function testItShouldThrowAnExceptionWhenTryGetQrCodeForInvalidOrNonExistentPayment() diff --git a/tests/Integration/CustomerIdentifierCreator/CustomerIdentifierCreatorTest.php b/tests/Integration/CustomerIdentifierCreator/CustomerIdentifierCreatorTest.php index 24a30a9..49e02d1 100644 --- a/tests/Integration/CustomerIdentifierCreator/CustomerIdentifierCreatorTest.php +++ b/tests/Integration/CustomerIdentifierCreator/CustomerIdentifierCreatorTest.php @@ -48,8 +48,6 @@ public function testItShouldCreateCustomerUniqueIdentifierWhenProvideOnlyRequire cpfCnpj: self::$faker->numerify('67981499011') )); - print_r($customerAsaasId); - $this->assertNotEmpty($customerAsaasId->identifier); $this->assertStringContainsString('cus_', $customerAsaasId->identifier); }