Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .husky/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ echo "🟢 Pint Ok!"

echo "\n"

# echo "============================================="
# echo "Running PHPStan tests 🧪"
# echo "============================================="
echo "============================================="
echo "Running PHPStan tests 🧪"
echo "============================================="

# pint_output=$(./vendor/bin/phpstan analyse -l 9 src tests 2>&1)
pint_output=$(./vendor/bin/phpstan analyse -l 9 src tests 2>&1)

# if [ $? -ne 0 ]; then
# echo "PHPStan tests failed. Please fix the issues before pushing."
# exit 1
# fi
if [ $? -ne 0 ]; then
echo "PHPStan tests failed. Please fix the issues before pushing."
exit 1
fi

# echo "🟢 PHPStan Ok!"
echo "🟢 PHPStan Ok!"

# echo "\n"
echo "\n"

# echo "============================================="
# echo "Running pest tests 🧪"
Expand Down
20 changes: 20 additions & 0 deletions src/Contracts/GatewayInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,27 @@

interface GatewayInterface
{
/**
* get resource customer from gateway.
*
* @param array<mixed> $customer
* @return object
*/
public function customer(array $customer = []): object;

/**
* get resource charge from gateway.
*
* @param array<mixed> $charge
* @return object
*/
public function charge(array $charge = []): object;

/**
* get resource webhook from gateway.
*
* @param array<mixed> $webhook
* @return object
*/
public function webhook(array $webhook = []): object;
}
6 changes: 3 additions & 3 deletions src/Gateways/Asaas/AsaasGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(
/**
* customer
*
* @param array $customer
* @param array<mixed> $customer
* @return Customer
*/
public function customer(array $customer = []): Customer
Expand All @@ -50,7 +50,7 @@ public function customer(array $customer = []): Customer
/**
* charge
*
* @param array $charge
* @param array<mixed> $charge
* @return Charge
*/
public function charge(array $charge = []): Charge
Expand All @@ -61,7 +61,7 @@ public function charge(array $charge = []): Charge
/**
* webhook
*
* @param array $webhook
* @param array<mixed> $webhook
* @return Webhook
*/
public function webhook(array $webhook = []): Webhook
Expand Down
14 changes: 7 additions & 7 deletions src/Gateways/Asaas/Enums/InvoiceStatusEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ enum InvoiceStatusEnum: string
case OVERDUE = 'OVERDUE';
case REFUNDED = 'REFUNDED';
case REFUND_REQUESTED = 'REFUNDED_REQUESTED';
case REFUND_IN_PROGRESS = 'REFUNDED_REQUESTED';
case CHARGEBACK_REQUESTED = 'REFUNDED_REQUESTED';
case CHARGEBACK_DISPUT = 'REFUNDED_REQUESTED';
case AWAITING_CHARGEBACK_REVERSAL = 'REFUNDED_REQUESTED';
case DUNNING_REQUESTED = 'DUNING';
case DUNNING_RECEIVED = 'DUNING';
case AWAITING_RISK_ANALYSIS = 'REFUNDED_REQUESTED';
case REFUND_IN_PROGRESS = 'REFUND_IN_PROGRESS';
case CHARGEBACK_REQUESTED = 'CHARGEBACK_REQUESTED';
case CHARGEBACK_DISPUT = 'CHARGEBACK_DISPUT';
case AWAITING_CHARGEBACK_REVERSAL = 'AWAITING_CHARGEBACK_REVERSAL';
case DUNNING_REQUESTED = 'DUNNING_REQUESTED';
case DUNNING_RECEIVED = 'DUNNING_RECEIVED';
case AWAITING_RISK_ANALYSIS = 'AWAITING_RISK_ANALYSIS';
}
20 changes: 20 additions & 0 deletions src/Gateways/Asaas/Interface/AsaasGatewayInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,27 @@

interface AsaasGatewayInterface extends GatewayInterface
{
/**
* get resource customer from gateway.
*
* @param array<mixed> $customer
* @return Customer
*/
public function customer(array $customer = []): Customer;

/**
* get resource charge from gateway.
*
* @param array<mixed> $charge
* @return Charge
*/
public function charge(array $charge = []): Charge;

/**
* get resource webhook from gateway.
*
* @param array<mixed> $webhook
* @return Webhook
*/
public function webhook(array $webhook = []): Webhook;
}
8 changes: 6 additions & 2 deletions src/Gateways/Asaas/Requests/AsaasChargeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,33 @@ class AsaasChargeRequest
/**
* validate customer and charge data
*
* @param array $customer
* @param array $charge
* @param array<mixed> $charge
* @return void
*/
public static function validate(array $charge): void
{
if (!isset($charge['customer']) && !is_string($charge['customer'])) {
/** @phpstan-ignore property.notFound */
throw new \InvalidArgumentException(self::messages()->charge->customer, 400);
}

if (!isset($charge['billingType'])) {
/** @phpstan-ignore property.notFound */
throw new \InvalidArgumentException(self::messages()->charge->billingType, 400);
}

if (!BillingTypeEnum::tryFrom($charge['billingType'])) {
/** @phpstan-ignore property.notFound */
throw new \InvalidArgumentException(self::messages()->charge->billingType, 400);
}

if (!isset($charge['value']) && !is_numeric($charge['value'])) {
/** @phpstan-ignore property.notFound */
throw new \InvalidArgumentException(self::messages()->charge->value, 400);
}

if (!isset($charge['dueDate']) && !is_string($charge['dueDate'])) {
/** @phpstan-ignore property.notFound */
throw new \InvalidArgumentException(self::messages()->charge->dueDate, 400);
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/Gateways/Asaas/Requests/AsaasCustomerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ class AsaasCustomerRequest
/**
* validate customer
*
* @param array $customer
* @param array<mixed> $customer
* @property-read string $name
* @property-read string $cpfCnpj
* @return void
*/
public static function validate(array $customer): void
{
if (!isset($customer['name'])) {
/** @phpstan-ignore property.notFound */
throw new \InvalidArgumentException(self::messages()->name, 400);
}

if (!isset($customer['cpfCnpj'])) {
/** @phpstan-ignore property.notFound */
throw new \InvalidArgumentException(self::messages()->cpfCnpj, 400);
}
}
Expand Down
14 changes: 11 additions & 3 deletions src/Gateways/Asaas/Requests/AsaasPixRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,38 @@

namespace PHPay\Gateways\Asaas\Requests;

use stdClass;

class AsaasPixRequest
{
/**
* validate pix
*
* @param array<mixed> $pix
* @return void
*/
public static function validate(array $pix): void
{
if (!isset($pix['description'])) {
/** @phpstan-ignore property.notFound */
throw new \InvalidArgumentException(self::messages()->description);
}

if (!isset($pix['amount'])) {
/** @phpstan-ignore property.notFound */
throw new \InvalidArgumentException(self::messages()->amount);
}

if (!isset($pix['due_date'])) {
/** @phpstan-ignore property.notFound */
throw new \InvalidArgumentException(self::messages()->due_date->required);
}

if ($pix['due_date'] < date('Y-m-d')) {
/** @phpstan-ignore property.notFound */
throw new \InvalidArgumentException(self::messages()->due_date->date);
}
}

public static function messages(): stdClass
public static function messages(): object
{
return (object) [
'description' => 'Asaas: Descrição do pagamento é obrigatório para o Asaas',
Expand Down
35 changes: 17 additions & 18 deletions src/Gateways/Asaas/Resources/Charge/Charge.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ class Charge implements ChargeInterface
private Client $client;

/**
* @var array
* @var array<mixed>
*/
private array $filter = [];

/**
* construct
*
* @param array $charge
* @param array<mixed> $charge
*/
public function __construct(
private string $token,
Expand All @@ -39,14 +39,12 @@ public function __construct(
if (!empty($charge)) {
$this->charge = $charge;
}

return $this;
}

/**
* set filters
*
* @param array $filters
* @param array<mixed> $filters
* @return ChargeInterface
*/
public function setFilters(array $filters): ChargeInterface
Expand All @@ -72,7 +70,7 @@ public function setCustomer(string $customerId): ChargeInterface
/**
* find charges by id
*
* @return array
* @return array<array|mixed>
*/
public function find(string $id): array
{
Expand All @@ -82,7 +80,7 @@ public function find(string $id): array
/**
* get all charges
*
* @return array
* @return array<array|mixed>
*/
public function getAll(): array
{
Expand All @@ -95,6 +93,7 @@ public function getAll(): array
* create charge
*
* @return string
* @return array<mixed>
* @see fields available in https://docs.asaas.com/reference/criar-nova-cobranca
*/
public function create(): array
Expand All @@ -108,8 +107,8 @@ public function create(): array
* update charge
*
* @param string $id
* @param array $data
* @return array
* @param array<mixed> $data
* @return array<mixed>
*/
public function update(string $id, array $data): array
{
Expand All @@ -120,7 +119,7 @@ public function update(string $id, array $data): array
* destroy charge
*
* @param string $id
* @return array
* @return bool
*/
public function destroy(string $id): bool
{
Expand All @@ -131,7 +130,7 @@ public function destroy(string $id): bool
* restore charge
*
* @param string $id
* @return array
* @return array<mixed>
*/
public function restore(string $id): array
{
Expand All @@ -142,7 +141,7 @@ public function restore(string $id): array
* get status charge
*
* @param string $id
* @return array
* @return array<array|mixed>
*/
public function getStatus(string $id): array
{
Expand All @@ -153,9 +152,9 @@ public function getStatus(string $id): array
* get digitable line
*
* @param string $id
* @return array
* @return mixed
*/
public function getDigitableLine(string $id): string
public function getDigitableLine(string $id): mixed
{
return $this->get("payments/{$id}/identificationField")['identificationField'];
}
Expand All @@ -164,7 +163,7 @@ public function getDigitableLine(string $id): string
* get qrcode pix
*
* @param string $id
* @return array
* @return array<array|mixed>
*/
public function getQrCodePix(string $id): array
{
Expand All @@ -175,8 +174,8 @@ public function getQrCodePix(string $id): array
* confirm receipt
*
* @param string $id
* @param array $data
* @return array
* @param array<mixed> $data
* @return array<mixed>
*/
public function confirmReceipt(string $id, array $data): array
{
Expand All @@ -187,7 +186,7 @@ public function confirmReceipt(string $id, array $data): array
* undo confirm receipt
*
* @param string $id
* @return array
* @return array<mixed>
*/
public function undoConfirmReceipt(string $id): array
{
Expand Down
Loading