diff --git a/.docker/php/Dockerfile b/.docker/php/Dockerfile
index b39fe4b..c9d24e3 100644
--- a/.docker/php/Dockerfile
+++ b/.docker/php/Dockerfile
@@ -1,8 +1,15 @@
FROM php:8.2-cli-alpine
+RUN apk add --no-cache \
+ curl \
+ bash \
+ nodejs \
+ npm
+
COPY --from=composer /usr/bin/composer /usr/bin/composer
RUN composer self-update
+
WORKDIR /usr/src/app
COPY . .
diff --git a/.husky/commit-msg b/.husky/commit-msg
index 3e3eea6..4f7ad03 100644
--- a/.husky/commit-msg
+++ b/.husky/commit-msg
@@ -11,7 +11,8 @@ ISSUE_ID=$(echo "$BRANCH_NAME" | grep -o -E "$REGEX_ISSUE_ID")
COMMIT_MESSAGE=$(cat "$1")
if [ -z "$ISSUE_ID" ]; then
- echo "🛑 ${BRed} Branch name does not follow the expected pattern...${KN}"
+ php examples/helper/termwind-cli.php error "${BRed} Branch name does not follow the expected pattern...${KN}"
+
exit 1
fi
@@ -21,4 +22,6 @@ case "$COMMIT_MESSAGE" in
;;
esac
+php examples/helper/termwind-cli.php success "PHPAY-$ISSUE_ID: $COMMIT_MESSAGE"
+
echo "PHPAY-$ISSUE_ID: $COMMIT_MESSAGE" > "$1"
diff --git a/.husky/pre-commit b/.husky/pre-commit
old mode 100644
new mode 100755
index 29a0027..41a28b8
--- a/.husky/pre-commit
+++ b/.husky/pre-commit
@@ -1,33 +1,20 @@
-#!/usr/bin/env sh
-
-echo "============================================="
-echo "Pre Commit Hook - Running pint tests 🧪"
-echo "============================================="
-
-pint_output=$(./vendor/bin/pint --test 2>&1)
+pint_output=$(vendor/bin/pint --test -v 2>&1)
if [ $? -ne 0 ]; then
- echo "Pint tests failed. Please fix the issues before pushing."
+ php examples/helper/termwind-cli.php error "Pint tests failed." "$pint_output"
+
exit 1
fi
-echo "🟢 Pint Ok!"
-
-echo "\n"
+php examples/helper/termwind-cli.php success "Pint Ok!"
-echo "============================================="
-echo "Pre Commit Hook - Running PHPStan tests 🧪"
-echo "============================================="
-
-pint_output=$(./vendor/bin/phpstan analyse -l 9 src tests 2>&1)
+phpstan=$(vendor/bin/phpstan analyse --level=9 2>&1)
if [ $? -ne 0 ]; then
- echo "PHPStan tests failed. Please fix the issues before commit."
+ php examples/helper/termwind-cli.php error "PHPStan tests failed." "$phpstan"
exit 1
fi
-echo "🟢 PHPStan Ok!"
-
-echo "\n"
-
+php examples/helper/termwind-cli.php success "PHPStan Ok!"
+exit 0
\ No newline at end of file
diff --git a/.husky/pre-push b/.husky/pre-push
index 61798db..aefb007 100755
--- a/.husky/pre-push
+++ b/.husky/pre-push
@@ -1,18 +1,11 @@
-#!/usr/bin/env sh
+pest_output=$(./vendor/bin/pest --colors=always --stop-on-failure 2>&1)
-# echo "============================================="
-# echo "Pre Push Hook - Running pest tests 🧪"
-# echo "============================================="
+if [ $? -ne 0 ]; then
+ php examples/helper/termwind-cli.php error "Pest tests failed." "$pest_output"
-# pest_output=$(./vendor/bin/pest --colors=always --stop-on-failure 2>&1)
+ exit 1
+fi
-# if [ $? -ne 0 ]; then
-# echo "🛑 Pest tests failed. Please fix the issues before pushing."
-# echo "$pest_output"
-# exit 1
-# fi
-
-# echo "🟢 Pest Ok!"
-# echo "\n"
+php examples/helper/termwind-cli.php success "Pest Ok!"
exit 0
\ No newline at end of file
diff --git a/.vscode/settings.json b/.vscode/settings.json
index efdb6c2..0add341 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -58,4 +58,5 @@
"window.zoomLevel": 1,
"editor.fontVariations": false,
"phpunit.phpunit": "vendor/bin/pest",
+ "jira-plugin.workingProject": "",
}
\ No newline at end of file
diff --git a/README.md b/README.md
index 31eb5e3..5ecaf5c 100644
--- a/README.md
+++ b/README.md
@@ -17,31 +17,93 @@ composer require phpay-io/phpay
## ⚙️ Como usar o PHPay?
-### Asaas
-
```php
/**
+ * instance with gateway inject
* @var AsaasGateway $phpay
*/
-$phpay = new PHPay(new AsaasGateway(TOKEN_ASAAS_SANDBOX));
+$phpay = (new PHPay(new AsaasGateway(TOKEN_ASAAS_SANDBOX)));
```
-### Efí
+### Cobranças
```php
/**
- * @var EfiGateway $phpay
+ * instance with gateway inject and resource call
+ *
+ * @var Charge $phpay
*/
-$phpay = new PHPay(new EfiGateway(CLIENT_ID, CLIENT_SECRET));
-```
-
-## Gerando uma Cobrança
+$phpay = (new PHPay(new AsaasGateway(TOKEN_ASAAS_SANDBOX)))->charge();
-```php
+/**
+ * create charge
+ */
$phpay
- ->charge($charge)
+ ->setCharge($charge)
->setCustomer($customer)
->create();
+
+/**
+ * find charge
+ */
+$phpay->find($chargeId);
+
+/**
+ * get all charges
+ */
+$phpay->getAll();
+
+/**
+ * get all charges with filters
+ */
+$phpay
+ ->setQueryParams(['limit' => 2])
+ ->getAll();
+
+/**
+ * update charge
+ */
+$phpay->update($chargeId, $data);
+
+/**
+ * destroy charge
+ */
+$phpay->destroy($chargeId);
+
+/**
+ * restore charge
+ */
+$phpay->restore($chargeId);
+
+/**
+ * get status charge
+ */
+$phpay->getStatus($chargeId);
+
+/**
+ * get digitable line charge
+ */
+$phpay->getDigitableLine($chargeId);
+
+/**
+ * get qrcode charge
+ */
+$phpay->getQrCodePix($chargeId);
+
+/**
+ * confirm receipt charge
+ */
+$phpay->confirmReceipt($chargeId, [
+ 'paymentDate' => date('Y-m-d'),
+ 'value' => 100.00,
+ 'notifyCustomer' => true,
+]);
+
+/**
+ * undo confirm receipt
+ */
+$phpay->undoConfirmReceipt($chargeId);
+
```
## 📝 Roadmap
diff --git a/examples/asaas/charges.php b/examples/asaas/charges.php
index 2682fa2..a2d81eb 100644
--- a/examples/asaas/charges.php
+++ b/examples/asaas/charges.php
@@ -1,141 +1,83 @@
NAME,
- 'cpfCnpj' => CPF_CNPJ,
-];
-
-$charge = [
- 'billingType' => 'PIX',
- 'value' => 100.00,
- 'description' => 'Teste de fatura',
- 'dueDate' => date('Y-m-d', strtotime('+1 day')),
-];
-
/**
- * @var AsaasGateway $phpay
+ * @var Charge $phpay
*/
-$phpay = new PHPay(new AsaasGateway(TOKEN_ASAAS_SANDBOX));
+$phpay = (new PHPay(new AsaasGateway(TOKEN_ASAAS_SANDBOX)))->charge();
/**
* create charge
- *
- * @return array charges
*/
$phpay
- ->charge($charge)
+ ->setCharge($charge)
->setCustomer($customer)
->create();
/**
- * get all charges
- *
- * @return array charges
+ * find charge
*/
-$phpay
- ->charge()
- ->find($chargeCreated['id']);
+$phpay->find($chargeId);
/**
* get all charges
- *
- * @return array charges
*/
-$phpay
- ->charge()
- ->getAll();
+$phpay->getAll();
/**
* get all charges with filters
- *
- * @return array charges
*/
$phpay
- ->charge()
- ->setQueryParams(['limit' => 5])
+ ->setQueryParams(['limit' => 2])
->getAll();
/**
* update charge
- *
- * @return array charge
*/
-$phpay
- ->charge()
- ->update($chargeId, [
- 'description' => 'Teste de fatura atualizado',
- ]);
+$phpay->update($chargeId, $data);
/**
* destroy charge
- *
- * @return array bool
*/
-$phpay
- ->charge()
- ->destroy($chargeId);
+$phpay->destroy($chargeId);
/**
* restore charge
- *
- * @return array charge
*/
-$phpay
- ->charge()
- ->restore($chargeId);
+$phpay->restore($chargeId);
/**
- * get charge status
- *
- * @return array charge status
+ * get status charge
*/
-$phpay
- ->charge()
- ->getStatus($chargeId);
+$phpay->getStatus($chargeId);
/**
* get digitable line charge
- *
- * @return string
*/
-$phpay
- ->charge()
- ->getDigitableLine($chargeId);
+$phpay->getDigitableLine($chargeId);
/**
* get qrcode charge
- *
- * @return string
*/
-$qrcode = $phpay
- ->charge()
- ->getQrCodePix($chargeId);
+$phpay->getQrCodePix($chargeId);
/**
* confirm receipt charge
- *
- * @return array charges
*/
-$confirmed = $phpay
- ->charge()
- ->confirmReceipt($chargeId, [
- 'paymentDate' => date('Y-m-d'),
- 'value' => 100.00,
- 'notifyCustomer' => true,
- ]);
+$phpay->confirmReceipt($chargeId, [
+ 'paymentDate' => date('Y-m-d'),
+ 'value' => 100.00,
+ 'notifyCustomer' => true,
+]);
/**
* undo confirm receipt
- *
- * @return array charges
*/
-$phpay
- ->charge()
- ->undoConfirmReceipt($chargeId);
+$phpay->undoConfirmReceipt($chargeId);
diff --git a/examples/asaas/webhook.php b/examples/asaas/webhook.php
index a9999fc..f50371e 100644
--- a/examples/asaas/webhook.php
+++ b/examples/asaas/webhook.php
@@ -12,25 +12,6 @@
'cpfCnpj' => CPF_CNPJ,
];
-$webhook = [
- 'name' => 'Webhook de Teste',
- 'url' => 'https://sixtec.com.br/webhook',
- 'email' => 'mariolucasdev@gmail.com',
- 'enabled' => true,
- 'interrupted' => false,
- 'apiVersion' => 3,
- 'authToken' => '123456',
- 'sendType' => 'SEQUENTIALLY',
- 'events' => [
- 'PAYMENT_CREATED',
- 'PAYMENT_UPDATED',
- 'PAYMENT_CONFIRMED',
- 'PAYMENT_RECEIVED',
- 'PAYMENT_OVERDUE',
- 'PAYMENT_DELETED',
- ],
-];
-
/**
* initialize phpay
*
@@ -45,7 +26,7 @@
* @see available fields in https://docs.asaas.com/reference/criar-novo-webhook
*/
$phpay
- ->webhook($webhook)
+ ->webhook(WEBHOOK)
->create();
/**
diff --git a/examples/helper/termwind-cli.php b/examples/helper/termwind-cli.php
new file mode 100644
index 0000000..bbf74a3
--- /dev/null
+++ b/examples/helper/termwind-cli.php
@@ -0,0 +1,49 @@
+ 1) {
+ $type = $argv[1];
+ $message = $argv[2];
+ $error = $argv[3] ?? null;
+
+ renderCLI($message, $type, $error);
+}
+
+/**
+ * render success message
+ */
+function renderCLI(
+ string $message,
+ string $type,
+ ?string $error
+): void {
+ switch ($type) {
+ case 'success':
+ $icon = '✔️';
+
+ break;
+ case 'error':
+ $icon = '❌';
+
+ break;
+ default:
+ $icon = '⚠️';
+
+ break;
+ }
+
+ $contentError = $error ? "{$error}" : '';
+
+ render(<<
+ $icon
+ {$message}
+ {$contentError}
+
+ HTML);
+}
diff --git a/examples/helper/termwind.php b/examples/helper/termwind.php
new file mode 100644
index 0000000..24889f8
--- /dev/null
+++ b/examples/helper/termwind.php
@@ -0,0 +1,53 @@
+{$content}" : '';
+
+ render(<<
+ {$gateway}
+ {$message}
+ {$aditionalContent}
+
+ HTML);
+}
+
+/**
+ * render error message
+ */
+function renderError(string $message, string $gateway, ?string $content): void
+{
+ $aditionalContent = $content ? "
{$content}" : '';
+
+ render(<<
+ {$gateway}
+ {$message}
+ {$aditionalContent}
+
+ HTML);
+}
+
+/**
+ * render info message
+ */
+function renderMessage(string $message, string $gateway, ?string $content): void
+{
+ $aditionalContent = $content ? "{$content}" : '';
+
+ render(<<
+ {$gateway}
+ {$message}
+ {$aditionalContent}
+
+ HTML);
+}
diff --git a/package.json b/package.json
index c51f063..f55f875 100644
--- a/package.json
+++ b/package.json
@@ -1,9 +1,9 @@
{
- "devDependencies": {
- "husky": "^9.1.7"
- },
- "scripts": {
- "prepare": "husky",
- "postinstall": "husky install"
- }
-}
\ No newline at end of file
+ "devDependencies": {
+ "husky": "^9.1.7"
+ },
+ "scripts": {
+ "prepare": "husky",
+ "postinstall": "husky install"
+ }
+}
diff --git a/src/Contracts/GatewayInterface.php b/src/Contracts/GatewayInterface.php
index 69d296e..425c56d 100644
--- a/src/Contracts/GatewayInterface.php
+++ b/src/Contracts/GatewayInterface.php
@@ -15,10 +15,9 @@ public function customer(array $customer = []): object;
/**
* get resource charge from gateway.
*
- * @param array