Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atualização para a V3 API #23

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
c65e771
Merge pull request #1 from softr/master
fernandochagas Jan 26, 2016
5ebd5bc
Merge pull request #2 from softr/master
fernandochagas Mar 18, 2016
68c6f25
Fix HandleError() error message
skaisser Mar 28, 2016
fc2f392
Added the Installment Atribute
skaisser Jul 22, 2016
f2000f7
add get payment by installment id
skaisser Jul 22, 2016
2f0c8d0
Merge pull request #3 from skaisser/master
fernandochagas Aug 5, 2016
40efb48
Update README.md
joasgarcia Dec 8, 2017
99b0ade
Merge pull request #5 from joasgarcia/patch-1
fernandochagas Dec 8, 2017
0c0e9e7
Atualização de Endpoint
gildonei Feb 27, 2019
4b00f89
Atualização das propriedades para v3
gildonei Feb 27, 2019
7aac4a9
Atualizado versão de referência da API
gildonei Feb 27, 2019
0e54976
Fix propertyName $externalReference
gildonei Feb 27, 2019
7914915
Inclusão de métodos getByCpfCnpj e getByName
gildonei Feb 28, 2019
89068e4
Fix PHPDoc getByEmail
gildonei Feb 28, 2019
cf7ba16
Atualizado endereço Homologação
gildonei Feb 28, 2019
7e231fc
Atualizações para a V3
gildonei Mar 20, 2019
916e10d
Update subscription fields
lz-eduardo Aug 16, 2021
c36d961
Update post request content-type
lz-eduardo Aug 16, 2021
f640d97
Merge pull request #1 from Luizea-dev/master
gildonei Aug 16, 2021
34bb2a8
Update GuzzleHttpAdapter.php
gildonei Dec 28, 2022
6ceae91
Update composer.json
lupainformatica Jan 16, 2023
a547c61
Ajustado erro em ::getAll() e add ::getList()
lz-eduardo Feb 15, 2023
74c1d73
Paginate method
lz-eduardo Feb 15, 2023
53670f3
Paymet.php
gildonei Nov 22, 2023
869903d
Merge pull request #1 from gildonei/master
lupainformatica Nov 23, 2023
cc2b0e5
Update GuzzleHttpAdapter.php
lupainformatica Nov 24, 2023
59487f7
Update Payment.php
lupainformatica Nov 24, 2023
ce92500
Merge pull request #2 from lupainformatica/main
gildonei Nov 24, 2023
9e057c5
Update AbstractEntity.php
lupainformatica Nov 24, 2023
2b2b4dc
Merge pull request #3 from lupainformatica/master
gildonei Nov 24, 2023
edce393
Merge pull request #2 from gildonei/master
lupainformatica Nov 24, 2023
c121ca2
Merge pull request #4 from lupainformatica/main
gildonei Jun 13, 2024
5e89e8b
Add files via upload
lupainformatica Jun 13, 2024
f4f27f3
Update Payment.php
lupainformatica Jun 13, 2024
8c13427
Merge pull request #5 from lupainformatica/main
gildonei Jun 13, 2024
0b8c633
Update Payment.php
lupainformatica Jun 13, 2024
211b984
Merge pull request #6 from lupainformatica/main
gildonei Jun 13, 2024
4877322
Update Payment.php
lupainformatica Jun 13, 2024
4afa934
Merge pull request #7 from lupainformatica/main
gildonei Jun 13, 2024
e435eee
Update Payment.php
lupainformatica Jun 13, 2024
b5cbda4
Merge pull request #8 from lupainformatica/main
gildonei Jun 13, 2024
a1e685e
chore: update asaas production endpoint
gildonei Sep 18, 2024
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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# VSCode
##########################
.history/
.svn/

!.vendor/
.vendor/*
!.vendor/.gitkeep
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ $action123 = $asaas->city()->getById(123);
Documentação Oficial
--------------------

Obs.: Esta é uma API não oficial. Foi feita com base na documentação disponibilizada [neste link](https://docs.google.com/document/d/1XUJRHY_0nd45CzFK5EmjDK92qgaQJGMxT0rjZriTk-g).
Obs.: Esta é uma API não oficial baseada na API ASAAS v3. A documentação oficial da API ASAAS está disponibilizada [neste link](https://asaasv3.docs.apiary.io).


Creditos
Créditos
--------

* [Agência Softr Ltda - www.softr.com.br](http://www.softr.com.br)
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name" : "softr/asaas-php-sdk",
"name" : "lupainformatica/asaas-php-sdk",
"type" : "library",
"description": "Asaas.com PHP API Wrapper",
"keywords" : ["Asaas", "API", "Payment SaaS", "Credit Card", "Boleto"],
Expand Down Expand Up @@ -31,4 +31,4 @@
}
},
"minimum-stability": "dev"
}
}
17 changes: 14 additions & 3 deletions src/Adapter/GuzzleHttpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class GuzzleHttpAdapter implements AdapterInterface
*/
public function __construct($token, ClientInterface $client = null)
{
if(version_compare(ClientInterface::VERSION, '6') === 1)
if(version_compare(ClientInterface::MAJOR_VERSION, '6') === 1)
{
$this->client = $client ?: new Client(['headers' => ['access_token' => $token]]);
}
Expand Down Expand Up @@ -119,7 +119,7 @@ public function put($url, $content = '')
public function post($url, $content = '')
{
$options = [];
$options['form_params'] = $content;
$options['json'] = $content;

try
{
Expand Down Expand Up @@ -161,7 +161,18 @@ protected function handleError()
$code = (int) $this->response->getStatusCode();

$content = json_decode($body);

$errors = [];
if (isset($content->errors)) {
foreach ((array)$content->errors as $error) {
$errors[] = $error->code . ': ' . $error->description;
}
}

if (!empty($errors)) {
throw new HttpException(implode('<br>', $errors), $code);
}

throw new HttpException(isset($content->message) ? $content->message : 'Request not processed.', $code);
}
}
}
24 changes: 20 additions & 4 deletions src/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@ abstract class AbstractApi
*
* @var string
*/
const ENDPOINT_PRODUCAO = 'https://www.asaas.com/api/v2';
const ENDPOINT_PRODUCAO = 'https://api.asaas.com/v3';

/**
* Endpoint Homologação
*
* @var string
*/
const ENDPOINT_HOMOLOGACAO = 'http://homolog.asaas.com/api/v2';
const ENDPOINT_HOMOLOGACAO = 'https://sandbox.asaas.com/api/v3';

/**
* Endpoint Sandbox
*
* @var string
*/
const ENDPOINT_SANDBOX = 'https://sandbox.asaas.com/api/v3';

/**
* Http Adapter Instance
Expand Down Expand Up @@ -54,7 +61,16 @@ public function __construct(AdapterInterface $adapter, $ambiente = 'producao')
{
$this->adapter = $adapter;

$this->endpoint = $ambiente == 'homologacao' ? static::ENDPOINT_HOMOLOGACAO : static::ENDPOINT_PRODUCAO;
switch ($ambiente) {
case 'sandbox':
$this->endpoint = static::ENDPOINT_SANDBOX;
break;
case 'homologacao':
$this->endpoint = static::ENDPOINT_HOMOLOGACAO;
break;
default:
$this->endpoint = static::ENDPOINT_PRODUCAO;
}
}

/**
Expand All @@ -79,4 +95,4 @@ public function getMeta()
{
return $this->meta;
}
}
}
36 changes: 25 additions & 11 deletions src/Api/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function getAll(array $filters = [])

return array_map(function($customer)
{
return new CustomerEntity($customer->customer);
return new CustomerEntity($customer);
}, $customers->data);
}

Expand All @@ -46,23 +46,37 @@ public function getById($id)
return new CustomerEntity($customer);
}

/**
* Get Customer By Name
*
* @param string $name Customer Name
* @return CustomerEntity
*/
public function getByName($name)
{
return $this->getAll(['name' => $name]);
}

/**
* Get Customer By CPF/CNPJ
*
* @param string $cpfCnpj Customer CPF / CNPJ
* @return CustomerEntity
*/
public function getByCpfCnpj($cpfCnpj)
{
return $this->getAll(['cpfCnpj' => $cpfCnpj]);
}

/**
* Get Customer By Email
*
* @param string $email Customer Id
* @param string $email Customer e-mail
* @return CustomerEntity
*/
public function getByEmail($email)
{
foreach($this->getAll(['name' => $email]) as $customer)
{
if($customer->email == $email)
{
return $customer;
}
}

return;
return $this->getAll(['email' => $email]);
}

/**
Expand Down
55 changes: 48 additions & 7 deletions src/Api/Payment.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Softr\Asaas\Api;

// Entities
Expand All @@ -11,6 +12,23 @@
*/
class Payment extends \Softr\Asaas\Api\AbstractApi
{
/**
* Get paginate payments
*
* @param array $filters (optional) Filters Array
* @return array Payments Array
*/
public function getPaginate(array $filters = [])
{
$payments = $this->adapter->get(sprintf('%s/payments?%s', $this->endpoint, http_build_query($filters)));

$payments = json_decode($payments);

$this->extractMeta($payments);

return $payments;
}

/**
* Get all payments
*
Expand All @@ -25,8 +43,7 @@ public function getAll(array $filters = [])

$this->extractMeta($payments);

return array_map(function($payment)
{
return array_map(function ($payment) {
return new PaymentEntity($payment);
}, $payments->data);
}
Expand Down Expand Up @@ -61,8 +78,7 @@ public function getByCustomer($customerId, array $filters = [])

$this->extractMeta($payments);

return array_map(function($payment)
{
return array_map(function ($payment) {
return new PaymentEntity($payment);
}, $payments->data);
}
Expand All @@ -82,8 +98,7 @@ public function getBySubscription($subscriptionId)

$this->extractMeta($payments);

return array_map(function($payment)
{
return array_map(function ($payment) {
return new PaymentEntity($payment);
}, $payments->data);
}
Expand Down Expand Up @@ -119,6 +134,22 @@ public function update($id, array $data)
return new PaymentEntity($payment);
}

/**
* Refund a Payment By Id
*
* @param string $id Payment Id
* @param array $data Payment Data
* @return PaymentEntity
*/
public function refund($id, array $data)
{
$payment = $this->adapter->post(sprintf('%s/payments/%s/refund', $this->endpoint, $id), $data);

$payment = json_decode($payment);

return new PaymentEntity($payment);
}

/**
* Delete Payment By Id
*
Expand All @@ -128,4 +159,14 @@ public function delete($id)
{
$this->adapter->delete(sprintf('%s/payments/%s', $this->endpoint, $id));
}
}

/**
* Delete Payment By Id
*
* @param string|int $id Payment Id
*/
public function deleteInstallment($id)
{
$this->adapter->delete(sprintf('%s/installments/%s', $this->endpoint, $id));
}
}
30 changes: 23 additions & 7 deletions src/Api/Subscription.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Softr\Asaas\Api;

// Entities
Expand All @@ -11,6 +12,23 @@
*/
class Subscription extends \Softr\Asaas\Api\AbstractApi
{
/**
* Get paginate subscriptions
*
* @param array $filters (optional) Filters Array
* @return array Subscriptions Array
*/
public function getPaginate(array $filters = [])
{
$subscriptions = $this->adapter->get(sprintf('%s/subscriptions?%s', $this->endpoint, http_build_query($filters)));

$subscriptions = json_decode($subscriptions);

$this->extractMeta($subscriptions);

return $subscriptions;
}

/**
* Get all subscriptions
*
Expand All @@ -25,9 +43,8 @@ public function getAll(array $filters = [])

$this->extractMeta($subscriptions);

return array_map(function($subscription)
{
return new SubscriptionEntity($subscription->subscription);
return array_map(function ($subscription) {
return new SubscriptionEntity($subscription);
}, $subscriptions->data);
}

Expand Down Expand Up @@ -61,9 +78,8 @@ public function getByCustomer($customerId)

$this->extractMeta($subscriptions);

return array_map(function($subscription)
{
return new SubscriptionEntity($subscription->subscription);
return array_map(function ($subscription) {
return new SubscriptionEntity($subscription);
}, $subscriptions->data);
}

Expand Down Expand Up @@ -107,4 +123,4 @@ public function delete($id)
{
$this->adapter->delete(sprintf('%s/subscriptions/%s', $this->endpoint, $id));
}
}
}
4 changes: 2 additions & 2 deletions src/Entity/AbstractEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected static function convertDateTime($date)
return;
}

$date = \DateTime::createFromFormat('d/m/Y', $date);
$date = new \DateTime($date);

if(!$date)
{
Expand All @@ -91,4 +91,4 @@ protected static function convertToCamelCase($str)

return lcfirst(preg_replace_callback('/(^|_)([a-z])/', $callback, $str));
}
}
}
Loading