Skip to content

Commit 2acf691

Browse files
PHPAY-64: wip(subscription): subscription with asaas (#66)
2 parents c82b1c2 + 053edaf commit 2acf691

File tree

14 files changed

+393
-77
lines changed

14 files changed

+393
-77
lines changed

‎.husky/pre-commit

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fi
88

99
php examples/helper/termwind-cli.php success "Pint Ok!"
1010

11-
phpstan=$(vendor/bin/phpstan analyse --level=9 2>&1)
11+
phpstan=$(vendor/bin/phpstan analyse --level=7 2>&1)
1212

1313
if [ $? -ne 0 ]; then
1414
php examples/helper/termwind-cli.php error "PHPStan tests failed." "$phpstan"

‎.vscode/settings.json

+61-61
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,62 @@
11
{
2-
"cSpell.enabled": false,
3-
"editor.lineHeight": 1.9,
4-
"editor.fontFamily": "JetBrains Mono",
5-
// "editor.fontFamily": "Dank Mono",
6-
// "editor.codeLensFontFamily": "Operator Mono",
7-
"editor.fontLigatures": true,
8-
"editor.formatOnSave": true,
9-
"php-cs-fixer.onsave": true,
10-
"php-cs-fixer.executablePath": "${extensionPath}/php-cs-fixer.phar",
11-
"cSpell.userWords": [
12-
"Assertable",
13-
"autoload",
14-
"Bootstrapper",
15-
"bootstrappers",
16-
"Codeigniter",
17-
"Disable",
18-
"flashdata",
19-
"intelephense",
20-
"junstyle",
21-
"Laravel",
22-
"Livewire",
23-
"onsave",
24-
"phar",
25-
"phpstan",
26-
"Queueable",
27-
"Stancl",
28-
"timesheet",
29-
"userdata"
30-
],
31-
"php-cs-fixer.lastDownload": 1693233566761,
32-
"terminal.integrated.cursorStyle": "underline",
33-
"terminal.integrated.defaultProfile.windows": "Git Bash",
34-
"terminal.integrated.fontFamily": "Hack Nerd Font Mono",
35-
"terminal.integrated.lineHeight": 1.2,
36-
"editor.accessibilitySupport": "off",
37-
"terminal.integrated.copyOnSelection": true,
38-
"terminal.integrated.sendKeybindingsToShell": true,
39-
"redhat.telemetry.enabled": true,
40-
"editor.minimap.enabled": false,
41-
"editor.tabSize": 4,
42-
"editor.insertSpaces": true,
43-
"editor.detectIndentation": false,
44-
".copilot.enable": {
45-
"*": true,
46-
"plaintext": true,
47-
"markdown": false,
48-
"scminput": false
49-
},
50-
"editor.inlineSuggest.enabled": true,
51-
"explorer.confirmDragAndDrop": false,
52-
"[javascript]": {
53-
"editor.defaultFormatter": "esbenp.prettier-vscode"
54-
},
55-
"files.associations": {
56-
"*.js": "javascriptreact"
57-
},
58-
"window.zoomLevel": 1,
59-
"editor.fontVariations": false,
60-
"phpunit.phpunit": "vendor/bin/pest",
61-
"jira-plugin.workingProject": "",
62-
}
2+
"cSpell.enabled": false,
3+
"editor.lineHeight": 2.4,
4+
// "editor.fontFamily": "JetBrains Mono",
5+
// "editor.fontFamily": "Dank Mono",
6+
// "editor.codeLensFontFamily": "Operator Mono",
7+
"editor.fontLigatures": true,
8+
"editor.formatOnSave": true,
9+
"php-cs-fixer.onsave": true,
10+
"php-cs-fixer.executablePath": "${extensionPath}/php-cs-fixer.phar",
11+
"cSpell.userWords": [
12+
"Assertable",
13+
"autoload",
14+
"Bootstrapper",
15+
"bootstrappers",
16+
"Codeigniter",
17+
"Disable",
18+
"flashdata",
19+
"intelephense",
20+
"junstyle",
21+
"Laravel",
22+
"Livewire",
23+
"onsave",
24+
"phar",
25+
"phpstan",
26+
"Queueable",
27+
"Stancl",
28+
"timesheet",
29+
"userdata"
30+
],
31+
"php-cs-fixer.lastDownload": 1693233566761,
32+
"terminal.integrated.cursorStyle": "underline",
33+
"terminal.integrated.defaultProfile.windows": "Git Bash",
34+
"terminal.integrated.fontFamily": "Hack Nerd Font Mono",
35+
"terminal.integrated.lineHeight": 1.2,
36+
"editor.accessibilitySupport": "off",
37+
"terminal.integrated.copyOnSelection": true,
38+
"terminal.integrated.sendKeybindingsToShell": true,
39+
"redhat.telemetry.enabled": true,
40+
"editor.minimap.enabled": false,
41+
"editor.tabSize": 4,
42+
"editor.insertSpaces": true,
43+
"editor.detectIndentation": false,
44+
".copilot.enable": {
45+
"*": true,
46+
"plaintext": true,
47+
"markdown": false,
48+
"scminput": false
49+
},
50+
"editor.inlineSuggest.enabled": true,
51+
"explorer.confirmDragAndDrop": false,
52+
"[javascript]": {
53+
"editor.defaultFormatter": "esbenp.prettier-vscode"
54+
},
55+
"files.associations": {
56+
"*.js": "javascriptreact"
57+
},
58+
"window.zoomLevel": 1,
59+
"editor.fontVariations": false,
60+
"phpunit.phpunit": "vendor/bin/pest",
61+
"jira-plugin.workingProject": ""
62+
}

‎README.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,29 @@ $phpay->undoConfirmReceipt($chargeId);
112112

113113
```
114114

115+
### Assinaturas
116+
117+
```php
118+
/**
119+
* @var Subscription $phpay
120+
*/
121+
$phpay = PHPay::gateway(new AsaasGateway(TOKEN_ASAAS_SANDBOX))->subscription();
122+
123+
/**
124+
* create a new subscription
125+
*/
126+
$phpay->setCustomer($customer)->create([
127+
'billingType' => 'BOLETO',
128+
'value' => 100,
129+
'nextDueDate' => '2025-04-09',
130+
]);
131+
```
132+
115133
## 📝 Roadmap
116134

117135
- Definições de Arquitetura ✅
118136
- Domínios ✅
119-
- Documentação 🕑
137+
- Documentação ✍️
120138
- Site 🕛
121139
- Gateways ✍️
122140

@@ -125,6 +143,7 @@ $phpay->undoConfirmReceipt($chargeId);
125143
- Cobranças ✅
126144
- Clientes ✅
127145
- Webhook ✅
146+
- Assinaturas ✍️
128147
- Pix 🕥
129148

130149
- Efí.
@@ -133,6 +152,7 @@ $phpay->undoConfirmReceipt($chargeId);
133152
- Cobranças ✅
134153
- Clientes 🕥
135154
- Webhook 🕥
155+
- Assinaturas ✍️
136156
- Pix 🕥
137157

138158
- Lançamento v1.0.0 🚀

‎examples/asaas/subscriptions.php

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
use PHPay\Asaas\AsaasGateway;
4+
use PHPay\Asaas\Resources\Subscription\Subscription;
5+
use PHPay\PHPay;
6+
7+
require_once __DIR__ . '/../../vendor/autoload.php';
8+
9+
require_once __DIR__ . '/credentials.php';
10+
11+
$customer = [
12+
'name' => NAME,
13+
'cpfCnpj' => CPF_CNPJ,
14+
];
15+
16+
$subscriptionId = 'sub_e3knxyfo6ffgb6kg';
17+
18+
/**
19+
* @var Subscription $phpay
20+
*/
21+
$phpay = PHPay::gateway(new AsaasGateway(TOKEN_ASAAS_SANDBOX))->subscription();
22+
23+
/* subscription store */
24+
$phpay->setCustomer($customer)
25+
->create([
26+
'billingType' => 'BOLETO',
27+
'value' => 100,
28+
'nextDueDate' => '2025-04-09',
29+
'discount' => [
30+
'value' => 10,
31+
'dueDateLimitDays' => 5,
32+
'type' => 'FIXED', /* PERCENTAGE */
33+
],
34+
'interest' => [
35+
'value' => 2,
36+
],
37+
'fine' => [
38+
'value' => 1,
39+
'type' => 'FIXED', /* PERCENTAGE */
40+
],
41+
'cycle' => 'MONTHLY',
42+
'description' => 'Teste de assinatura',
43+
'maxPayments' => 12,
44+
'externalReference' => '123456',
45+
// 'split' => [
46+
// [
47+
// 'walletId' => 'rec_123456',
48+
// 'fixedValue' => 50,
49+
// 'percentageValue' => 50,
50+
// 'externalReference' => '123456',
51+
// 'description' => 'Teste de divisão',
52+
// ],
53+
// ],
54+
// 'callback' => [
55+
// 'successUrl' => 'https://example.com/success',
56+
// 'autoRedirect' => true,
57+
// ]
58+
]);
59+
60+
print_r($subscriptionCreated);

‎phpstan.neon

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
parameters:
22
paths:
3-
- src
4-
- tests
3+
- src

‎src/Contracts/GatewayInterface.php

+7
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,11 @@ public function webhook(array $webhook = []): object;
3434
* @return object
3535
*/
3636
public function pix(array $pix = []): object;
37+
38+
/**
39+
* get resource subscription from gateway.
40+
*
41+
* @return object
42+
*/
43+
public function subscription(): object;
3744
}

‎src/Gateways/Asaas/AsaasGateway.php

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PHPay\Asaas\Resources\Charge\Charge;
88
use PHPay\Asaas\Resources\Customer\Customer;
99
use PHPay\Asaas\Resources\Pix\Pix;
10+
use PHPay\Asaas\Resources\Subscription\Subscription;
1011
use PHPay\Asaas\Resources\Webhook\Webhook;
1112

1213
class AsaasGateway implements AsaasGatewayInterface
@@ -79,4 +80,9 @@ public function pix(array $pix = []): Pix
7980
{
8081
return new Pix($this->token, $this->sandbox);
8182
}
83+
84+
public function subscription(): Subscription
85+
{
86+
return new Subscription($this->token, $this->sandbox);
87+
}
8288
}

‎src/Gateways/Asaas/Interface/AsaasGatewayInterface.php

+8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPay\Asaas\Resources\Charge\Charge;
66
use PHPay\Asaas\Resources\Customer\Customer;
77
use PHPay\Asaas\Resources\Pix\Pix;
8+
use PHPay\Asaas\Resources\Subscription\Subscription;
89
use PHPay\Asaas\Resources\Webhook\Webhook;
910
use PHPay\Contracts\GatewayInterface;
1011

@@ -25,6 +26,13 @@ public function customer(array $customer = []): Customer;
2526
*/
2627
public function charge(): Charge;
2728

29+
/**
30+
* get resource subscription from gateway.
31+
*
32+
* @return Subscription
33+
*/
34+
public function subscription(): Subscription;
35+
2836
/**
2937
* get resource webhook from gateway.
3038
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace PHPay\Asaas\Resources\Subscription\Interface;
4+
5+
use PHPay\Asaas\Resources\Subscription\Subscription;
6+
7+
interface SubscriptionInterface
8+
{
9+
public function __construct(string $token, bool $sandbox = true);
10+
11+
/**
12+
* set customer
13+
*
14+
* @param array<mixed> $customer
15+
* @return Subscription
16+
*/
17+
public function setCustomer(array $customer): Subscription;
18+
19+
/**
20+
* create subscription
21+
*
22+
* @param array<mixed> $subscription
23+
* @return array<mixed>
24+
*/
25+
public function create(array $subscription): array;
26+
27+
// public function findAll();
28+
// public function find(string $subscriptionId);
29+
// public function update(string $subscriptionId, array $subscription);
30+
// public function destroy(string $subscriptionId);
31+
// public function findCharges(string $subscriptionId);
32+
// public function generateCarnet(string $subscriptionId);
33+
// public function nfeSettings(string $subscriptionId, array $nfeSettings);
34+
// public function findNfeSettings(string $subscriptionId);
35+
// public function updateNfeSettings(string $subscriptionId, array $nfeSettings);
36+
// public function destroyNfeSettings(string $subscriptionId);
37+
// public function findNfes(string $subscriptionId);
38+
}

0 commit comments

Comments
 (0)