Skip to content

Commit

Permalink
Merge pull request #2 from AstrotechLabs/refactoring-best-user-exp
Browse files Browse the repository at this point in the history
refact: Refactoring for best user experience on sdk usage
  • Loading branch information
MoisesK authored Dec 24, 2023
2 parents 450e866 + 04d6b4a commit d48747c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 37 deletions.
27 changes: 5 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"
Expand Down
13 changes: 10 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/CreatePixCharge/Dto/PixData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/CustomerIdentifierCreator/Dto/CustomerData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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')
));
}

Expand All @@ -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"
Expand All @@ -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);
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ public function testItShouldCreateCustomerUniqueIdentifierWhenProvideOnlyRequire
cpfCnpj: self::$faker->numerify('67981499011')
));

print_r($customerAsaasId);

$this->assertNotEmpty($customerAsaasId->identifier);
$this->assertStringContainsString('cus_', $customerAsaasId->identifier);
}
Expand Down

0 comments on commit d48747c

Please sign in to comment.