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
File renamed without changes.
File renamed without changes.
Empty file added .github/LICENSE
Empty file.
2 changes: 2 additions & 0 deletions README.md → .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,6 @@ Este projeto está licenciado sob a MIT License. Consulte o arquivo LICENSE para
💻 GitHub: mariolucasdev
📧 Email: mariolucasdev@gmail.com

<iframe src="https://github.com/sponsors/mariolucasdev/button" title="Sponsor mariolucasdev" height="32" width="114" style="border: 0; border-radius: 6px;"></iframe>

🎉 Comece a usar o PHPay e simplifique suas integrações com gateways de pagamento!
21 changes: 18 additions & 3 deletions .husky/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,24 @@ echo "🟢 Pint Ok!"

echo "\n"

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

# 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

# echo "🟢 PHPStan Ok!"

# echo "\n"

# echo "============================================="
# echo "Running pest tests 🧪"
# echo "============================================="

# pest_output=$(./vendor/bin/pest --colors=always --stop-on-failure 2>&1)

Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
],
"require-dev": {
"pestphp/pest": "3.5",
"laravel/pint": "^1.18"
"laravel/pint": "^1.18",
"phpstan/phpstan": "^2.0"
},
"config": {
"allow-plugins": {
Expand All @@ -31,4 +32,4 @@
"scripts": {
"test": "vendor/bin/pest"
}
}
}
60 changes: 59 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions examples/asaas/charges.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@

/**
* initialize phpay
*
* @var AsaasGateway $phpay
*/
$phpay = PHPay::getInstance(new AsaasGateway(TOKEN_ASAAS_SANDBOX))
->getGateway();
$asaas = new PHPay(new AsaasGateway(TOKEN_ASAAS_SANDBOX));

/**
* create customer
*
* @return array customer
*/
$customerCreated = $phpay
->customer($customer)
->create();
->customer()
->create($customer);

/**
* create charge
Expand Down
5 changes: 3 additions & 2 deletions examples/asaas/customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

/**
* initialize phpay
*
* @var AsaasGateway $phpay
*/
$phpay = PHPay::getInstance(new AsaasGateway(TOKEN_ASAAS_SANDBOX))
->getGateway();
$phpay = new PHPay(new AsaasGateway(TOKEN_ASAAS_SANDBOX));

/**
* store asaas customer
Expand Down
5 changes: 3 additions & 2 deletions examples/asaas/webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@

/**
* initialize phpay
*
* @var AsaasGateway $phpay
*/
$phpay = PHPay::getInstance(new AsaasGateway(TOKEN_ASAAS_SANDBOX))
->getGateway();
$phpay = new PHPay(new AsaasGateway(TOKEN_ASAAS_SANDBOX));

/**
* store a new webhook
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 6
paths:
- src
- tests
10 changes: 3 additions & 7 deletions src/Contracts/GatewayInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

namespace PHPay\Contracts;

use Asaas\Resources\Charge\Charge as AsaasCharge;
use Asaas\Resources\Customer\Customer as AsaasCustomer;
use Asaas\Resources\Webhook\Webhook as AsaasWebhook;

interface GatewayInterface
{
public function customer(array $customer = []): AsaasCustomer;
public function charge(array $charge = []): AsaasCharge;
public function webhook(array $webhook = []): AsaasWebhook;
public function customer(array $customer = []): object;
public function charge(array $charge = []): object;
public function webhook(array $webhook = []): object;
}
16 changes: 11 additions & 5 deletions src/Gateways/Asaas/AsaasGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace PHPay\Gateways\Asaas;

use Asaas\Interface\AsaasGatewayInterface;
use Asaas\Resources\Charge\Charge;
use Asaas\Resources\Customer\Customer;
use Asaas\Resources\Webhook\Webhook;
use GuzzleHttp\Client;
use PHPay\Contracts\GatewayInterface;

class AsaasGateway implements GatewayInterface
class AsaasGateway implements AsaasGatewayInterface
{
/**
* client guzzle
Expand Down Expand Up @@ -42,7 +42,7 @@ public function __construct(
*/
public function customer(array $customer = []): Customer
{
$this->customer = new Customer($customer, $this->token, $this->sandbox);
$this->customer = new Customer($this->token, $customer, $this->sandbox);

return $this->customer;
}
Expand All @@ -55,11 +55,17 @@ public function customer(array $customer = []): Customer
*/
public function charge(array $charge = []): Charge
{
return new Charge($charge, $this->token, $this->sandbox);
return new Charge($this->token, $charge, $this->sandbox);
}

/**
* webhook
*
* @param array $webhook
* @return Webhook
*/
public function webhook(array $webhook = []): Webhook
{
return new Webhook($webhook, $this->token, $this->sandbox);
return new Webhook($this->token, $webhook, $this->sandbox);
}
}
15 changes: 15 additions & 0 deletions src/Gateways/Asaas/Interface/AsaasGatewayInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Asaas\Interface;

use Asaas\Resources\Charge\Charge;
use Asaas\Resources\Customer\Customer;
use Asaas\Resources\Webhook\Webhook;
use PHPay\Contracts\GatewayInterface;

interface AsaasGatewayInterface extends GatewayInterface
{
public function customer(array $customer = []): Customer;
public function charge(array $charge = []): Charge;
public function webhook(array $webhook = []): Webhook;
}
4 changes: 2 additions & 2 deletions src/Gateways/Asaas/Resources/Charge/Charge.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class Charge implements ChargeInterface
* @param array $charge
*/
public function __construct(
private array $charge = [],
private string $token,
private bool $sandbox = true
private array $charge = [],
private bool $sandbox = true,
) {
$this->client = $this->clientAsaasBoot();

Expand Down
2 changes: 1 addition & 1 deletion src/Gateways/Asaas/Resources/Customer/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class Customer implements CustomerInterface
* @param array $customer
*/
public function __construct(
private array $customer = [],
private string $token,
private array $customer = [],
private bool $sandbox = true
) {
$this->client = $this->clientAsaasBoot();
Expand Down
2 changes: 1 addition & 1 deletion src/Gateways/Asaas/Resources/Webhook/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class Webhook implements WebhookInterface
* @param array $webhook
*/
public function __construct(
private array $webhook = [],
private string $token,
private array $webhook = [],
private bool $sandbox = true
) {
$this->client = $this->clientAsaasBoot();
Expand Down
46 changes: 18 additions & 28 deletions src/PHPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,49 @@

use PHPay\Contracts\GatewayInterface;

class PHPay
class PHPay implements GatewayInterface
{
/**
* instance of PHPay.
*
* @var self|null
*/
private static ?self $instance = null;

/**
* private constructor prevents new instances.
*
* @param GatewayInterface $gateway
*/
private function __construct(
private GatewayInterface $gateway
public function __construct(
protected GatewayInterface $gateway
) {
$this->gateway = $gateway;
}

/**
* get instance of PHPay.
* get resource customer from gateway.
*
* @param GatewayInterface $gateway
* @return self
* @param array $customer
* @return object
*/
public static function getInstance(GatewayInterface $gateway): self
public function customer(array $customer = []): object
{
if (self::$instance === null) {
self::$instance = new self($gateway);
}

return self::$instance;
return $this->gateway->customer($customer);
}

/**
* get current gateway.
* get resource charge from gateway.
*
* @return GatewayInterface
* @param array $charge
* @return object
*/
public function getGateway(): GatewayInterface
public function charge(array $charge = []): object
{
return $this->gateway;
return $this->gateway->charge($charge);
}

/**
* set a new gateway.
* get resource webhook from gateway.
*
* @param GatewayInterface $gateway
* @return void
* @param array $webhook
* @return object
*/
public function setGateway(GatewayInterface $gateway): void
public function webhook(array $webhook = []): object
{
$this->gateway = $gateway;
return $this->gateway->webhook($webhook);
}
}
11 changes: 0 additions & 11 deletions tests/Feature/PHPayTest.php

This file was deleted.

6 changes: 3 additions & 3 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
|
*/

expect()->extend('toBeOne', function () {
return $this->toBe(1);
});
// expect()->extend('toBeOne', function () {
// return $this->toBe(1);
// });

/*
|--------------------------------------------------------------------------
Expand Down