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
88 changes: 88 additions & 0 deletions examples/asaas/webhook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

use PHPay\Gateways\Asaas\AsaasGateway;
use PHPay\PHPay;

require_once __DIR__ . '/../../vendor/autoload.php';

require_once __DIR__ . '/credentials.php';

$customer = [
'name' => NAME,
'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
*/
$phpay = PHPay::getInstance(new AsaasGateway(TOKEN_ASAAS_SANDBOX))
->getGateway();

/**
* store a new webhook
*
* @return array
* @see available fields in https://docs.asaas.com/reference/criar-novo-webhook
*/
$webhook = $phpay
->webhook($webhook)
->create();

/**
* get all webhooks
*
* @return array
*/
$webhooks = $phpay
->webhook()
->getAll();

/**
* find a webhook
*
* @return array
*/
$webhook = $phpay
->webhook()
->find('84c3c34b-9d23-44a3-95b2-d232c3f06dba');

/**
* update a webhook
*
* @return array
* @see available fields in https://docs.asaas.com/reference/atualizar-webhook-existente
*/
$webhookUpdated = $phpay
->webhook()
->update('84c3c34b-9d23-44a3-95b2-d232c3f06dba', [
'name' => 'Webhook de Teste Atualizado',
'url' => 'https://sixtec.com.br/webhook/atualizado',
]);

/**
* delete a webhook
*
* @return bool
*/
$webhookDeleted = $phpay
->webhook()
->destroy('84c3c34b-9d23-44a3-95b2-d232c3f06dba');
2 changes: 2 additions & 0 deletions src/Contracts/GatewayInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

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;
}
12 changes: 12 additions & 0 deletions src/Gateways/Asaas/AsaasGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

Expand Down Expand Up @@ -46,8 +47,19 @@ public function customer(array $customer = []): Customer
return $this->customer;
}

/**
* charge
*
* @param array $charge
* @return Charge
*/
public function charge(array $charge = []): Charge
{
return new Charge($charge, $this->token, $this->sandbox);
}

public function webhook(array $webhook = []): Webhook
{
return new Webhook($webhook, $this->token, $this->sandbox);
}
}
6 changes: 6 additions & 0 deletions src/Gateways/Asaas/Resources/Charge/Charge.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ public function confirmReceipt(string $id, array $data): array
return $this->post("payments/{$id}/receiveInCash", $data);
}

/**
* undo confirm receipt
*
* @param string $id
* @return array
*/
public function undoConfirmReceipt(string $id): array
{
return $this->post("payments/{$id}/undoReceivedInCash");
Expand Down
34 changes: 34 additions & 0 deletions src/Gateways/Asaas/Resources/Charge/Enum/WebhookEventsEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Asaas\Resources\Webhook\Enum;

enum WebhookEventsEnum: string
{
case PAYMENT_CREATED = 'PAYMENT_CREATED';
case PAYMENT_UPDATED = 'PAYMENT_UPDATED';
case PAYMENT_CONFIRMED = 'PAYMENT_CONFIRMED';
case PAYMENT_RECEIVED = 'PAYMENT_RECEIVED';
case PAYMENT_OVERDUE = 'PAYMENT_OVERDUE';
case PAYMENT_DELETED = 'PAYMENT_DELETED';
case PAYMENT_AWAITING_RISK_ANALYSIS = 'PAYMENT_AWAITING_RISK_ANALYSIS';
case PAYMENT_APPROVED_BY_RISK_ANALYSIS = 'PAYMENT_APPROVED_BY_RISK_ANALYSIS';
case PAYMENT_REPROVED_BY_RISK_ANALYSIS = 'PAYMENT_REPROVED_BY_RISK_ANALYSIS';
case PAYMENT_AUTHORIZED = 'PAYMENT_AUTHORIZED';
case PAYMENT_CREDIT_CARD_CAPTURE_REFUSED = 'PAYMENT_CREDIT_CARD_CAPTURE_REFUSED';
case PAYMENT_ANTICIPATED = 'PAYMENT_ANTICIPATED';
case PAYMENT_RESTORED = 'PAYMENT_RESTORED';
case PAYMENT_REFUNDED = 'PAYMENT_REFUNDED';
case PAYMENT_PARTIALLY_REFUNDED = 'PAYMENT_PARTIALLY_REFUNDED';
case PAYMENT_REFUND_IN_PROGRESS = 'PAYMENT_REFUND_IN_PROGRESS';
case PAYMENT_RECEIVED_IN_CASH_UNDONE = 'PAYMENT_RECEIVED_IN_CASH_UNDONE';
case PAYMENT_CHARGEBACK_REQUESTED = 'PAYMENT_CHARGEBACK_REQUESTED';
case PAYMENT_CHARGEBACK_DISPUTE = 'PAYMENT_CHARGEBACK_DISPUTE';
case PAYMENT_AWAITING_CHARGEBACK_REVERSAL = 'PAYMENT_AWAITING_CHARGEBACK_REVERSAL';
case PAYMENT_DUNNING_RECEIVED = 'PAYMENT_DUNNING_RECEIVED';
case PAYMENT_DUNNING_REQUESTED = 'PAYMENT_DUNNING_REQUESTED';
case PAYMENT_BANK_SLIP_VIEWED = 'PAYMENT_BANK_SLIP_VIEWED';
case PAYMENT_CHECKOUT_VIEWED = 'PAYMENT_CHECKOUT_VIEWED';
case PAYMENT_SPLIT_CANCELLED = 'PAYMENT_SPLIT_CANCELLED';
case PAYMENT_SPLIT_DIVERGENCE_BLOCK = 'PAYMENT_SPLIT_DIVERGENCE_BLOCK';
case PAYMENT_SPLIT_DIVERGENCE_BLOCK_FINISHED = 'PAYMENT_SPLIT_DIVERGENCE_BLOCK_FINISHED';
}
13 changes: 0 additions & 13 deletions src/Gateways/Asaas/Resources/Interfaces/InvoiceInterface.php

This file was deleted.

107 changes: 0 additions & 107 deletions src/Gateways/Asaas/Resources/Invoice.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Asaas\Resources\Webhook\Interface;

interface WebhookInterface
{
public function create(array $webhook = []): array;
public function getAll(): array;
public function find(string $id): array;
public function update(string $id, array $webhook = []): array;
public function destroy(string $id): bool;
}
Loading