paygo-dev/paygo-sdk-php

There is no license information available for the latest version (0.1.2) of this package.

Cliente em PHP para integração com as APIs de consulta de transações

Installs: 1 447

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 3

Forks: 0

Open Issues: 0

Type:libraries

0.1.2 2018-12-07 17:56 UTC

This package is not auto-updated.

Last update: 2024-11-11 21:52:28 UTC


README

Build Status Code Climate Scrutinizer Code Quality Code Coverage

Total Downloads Monthly Downloads Daily Downloads

Latest Stable Version Latest Unstable Version License

Dependências

require

  • PHP >= 5.6
  • guzzlehttp/guzzle 5.3.1

require-dev

  • phpunit/phpunit ^4.8

Instalação

Execute em seu shell:

composer require paygo-dev/paygo-sdk-php

Adicionando a dependência ao seu arquivo composer.json

{
    "require": {
       "paygo-dev/paygo-sdk-php" : "*"
    }
}

Variáveis de ambiente

PAYGO_TRANSACTIONS_HOST=http://api.paygomais.com.br
PAYGO_TRANSACTIONS_TIMEOUT=10
PAYGO_TRANSACTIONS_TOKEN=e258c0g0-4795-4bf3-bf12-483737e9cac3

Configurando a autenticação

Informar parâmetros de integração

Para que o SDK consiga acessar as API's é necessário informar os parâmetros conforme exemplo abaixo, caso não seja específicado o SDK irá aferir através de variáveis de ambiente.

$client = new \PayGo\Client([
    'PAYGO_TRANSACTIONS_HOST' => "http://api.paygomais.com.br",
    'PAYGO_TRANSACTIONS_TIMEOUT' => 10,
    'PAYGO_TRANSACTIONS_TOKEN' => "e258c0g0-4795-4bf3-bf12-483737e9cac3",
]);

$transactionApi = new \PayGo\Transactions\API\TransactionAPI($client);

Os parâmetros poder ser definidos ou alterados conforme abaixo.

$client = (new Client())
            ->setParameter('PAYGO_TRANSACTIONS_HOST', "http://api.paygomais.com.br")
            ->setParameter('PAYGO_TRANSACTIONS_TIMEOUT', 10)
            ->setParameter('PAYGO_TRANSACTIONS_TOKEN', "e258c0g0-4795-4bf3-bf12-483737e9cac3");

$transactionApi = new \PayGo\Transactions\API\TransactionAPI($client);

Caso os parâmetros não sejam informados o SDK irá aferir através de variáveis de ambiente caso tenha sido configuradas

$transactionApi = new \PayGo\Transactions\API\TransactionAPI();

Exemplos de utilização

Exemplo de consulta por intervalo de data, retornando apenas um registro.

$response = $transactionApi->filter(
            (new \PayGo\Transactions\Contracts\Query\Query())
                ->setLimit(1)
                ->setFilters(
                    (new \PayGo\Transactions\Contracts\Query\Filters())
                        ->setServerDateRange(
                            (new \PayGo\Transactions\Contracts\Query\DateRange())
                                ->setFromDate(\DateTime::createFromFormat('Y-m-d', '2015-01-01'))
                                ->setEndDate(\DateTime::createFromFormat('Y-m-d', '2018-12-01'))
                        )
                )
        );

print_r($response->getStatusCode());
print_r($response->json());

Resposta

array(1) {
  [0]=>
  array(27) {
    ["AffiliationCompanyDataDisplayName"]=>
    string(4) "TESTE"
    ["AffiliationCompanyDataTaxId"]=>
    string(18) "99.999.999/0001-99"
    ["AffiliationNumber"]=>
    string(32) "********************************"
    ["Amount"]=>
    string(4) "5000"
    ["AuthorizerCode"]=>
    string(5) "STONE"
    ["AuthorizerExternalReference"]=>
    string(14) "19291241077475"
    ["AuthorizerName"]=>
    string(5) "STONE"
    ["CardDataCardName"]=>
    string(10) "MASTERCARD"
    ["CardDataExpirationDate"]=>
    string(4) "2602"
    ["CardDataMaskedCardNumber"]=>
    string(16) "************5768"
    ["CardDataType"]=>
    int(1)
    ["FinancingDataInstallmentsNumber"]=>
    int(1)
    ["FinancingDataType"]=>
    int(1)
    ["FullReceiptCopy"]=>
    string(543) "
     STONE - VIA ESTABELECIMENTO      
     MASTERCARD - CREDITO A VISTA     
CNPJ: 999.999.999/0001-99
2ALL
BELO HORIZONTE - MG
************5766       02/04/18  16:42
EC:128268623                AUT:424973
SAK:&E62D11B67204181A190D83E1EBED4EC
DOC:1585
STONE ID:19281241077495
AC:6B087A3450022121           ONL-CHIP
AID: A0000000041010
Credito                       APROVADO
TOTAL:                        R$ 50,00
     TRANSACAO APROVADA COM SENHA     
----------------------------------------
71666 0000007544 0000002585 

"
    ["InternalLocalReference"]=>
    int(1585)
    ["POSCompanyDataDisplayName"]=>
    string(27) "Adriano M. La Selva"
    ["POSCompanyDataTaxId"]=>
    string(14) "111.111.111-11"
    ["POSDataDescription"]=>
    string(12) "Door to Door"
    ["POSDataIdentifier"]=>
    string(5) "9999999"
    ["POSTimestamp"]=>
    string(19) "2018-04-02 16:43:04"
    ["ProductName"]=>
    string(15) "CREDITO A VISTA"
    ["Result"]=>
    int(0)
    ["ResultMessage"]=>
    string(9) "APROVADO "
    ["ServerTimestamp"]=>
    string(19) "2018-04-02 16:42:46"
    ["Status"]=>
    string(3) "289"
    ["Type"]=>
    int(33)
    ["UniqueId"]=>
    int(33171163)
  }
}

Exemplo de consulta por intervalo de data e tipos de transações, retornando apenas um registro.

$response = $transactionApi->filter(
            (new \PayGo\Transactions\Contracts\Query\Query())
                ->setLimit(1)
                ->setFilters(
                    (new \PayGo\Transactions\Contracts\Query\Filters())
                        ->setTypes([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,33,34])
                        ->setServerDateRange(
                            (new \PayGo\Transactions\Contracts\Query\DateRange())
                                ->setFromDate(\DateTime::createFromFormat('Y-m-d', '2015-01-01'))
                                ->setEndDate(\DateTime::createFromFormat('Y-m-d', '2018-12-01'))
                        )
                )
        );

print_r($response->getStatusCode());
print_r($response->json());

Resposta

array(1) {
  [0]=>
  array(27) {
    ["AffiliationCompanyDataDisplayName"]=>
    string(4) "TESTE"
    ["AffiliationCompanyDataTaxId"]=>
    string(18) "99.999.999/0001-99"
    ["AffiliationNumber"]=>
    string(32) "********************************"
    ["Amount"]=>
    string(4) "5000"
    ["AuthorizerCode"]=>
    string(5) "STONE"
    ["AuthorizerExternalReference"]=>
    string(14) "19291241077475"
    ["AuthorizerName"]=>
    string(5) "STONE"
    ["CardDataCardName"]=>
    string(10) "MASTERCARD"
    ["CardDataExpirationDate"]=>
    string(4) "2602"
    ["CardDataMaskedCardNumber"]=>
    string(16) "************5768"
    ["CardDataType"]=>
    int(1)
    ["FinancingDataInstallmentsNumber"]=>
    int(1)
    ["FinancingDataType"]=>
    int(1)
    ["FullReceiptCopy"]=>
    string(543) "
     STONE - VIA ESTABELECIMENTO      
     MASTERCARD - CREDITO A VISTA     
CNPJ: 999.999.999/0001-99
2ALL
BELO HORIZONTE - MG
************5766       02/04/18  16:42
EC:128268623                AUT:424973
SAK:&E62D11B67204181A190D83E1EBED4EC
DOC:1585
STONE ID:19281241077495
AC:6B087A3450022121           ONL-CHIP
AID: A0000000041010
Credito                       APROVADO
TOTAL:                        R$ 50,00
     TRANSACAO APROVADA COM SENHA     
----------------------------------------
71666 0000007544 0000002585 

"
    ["InternalLocalReference"]=>
    int(1585)
    ["POSCompanyDataDisplayName"]=>
    string(27) "Adriano M. La Selva"
    ["POSCompanyDataTaxId"]=>
    string(14) "111.111.111-11"
    ["POSDataDescription"]=>
    string(12) "Door to Door"
    ["POSDataIdentifier"]=>
    string(5) "9999999"
    ["POSTimestamp"]=>
    string(19) "2018-04-02 16:43:04"
    ["ProductName"]=>
    string(15) "CREDITO A VISTA"
    ["Result"]=>
    int(0)
    ["ResultMessage"]=>
    string(9) "APROVADO "
    ["ServerTimestamp"]=>
    string(19) "2018-04-02 16:42:46"
    ["Status"]=>
    string(3) "289"
    ["Type"]=>
    int(33)
    ["UniqueId"]=>
    int(33171163)
  }
}

Exemplo de consulta por intervalo de data e status de transações, retornando apenas um registro.

$response = $transactionApi->filter(
            (new \PayGo\Transactions\Contracts\Query\Query())
                ->setLimit(1)
                ->setFilters(
                    (new \PayGo\Transactions\Contracts\Query\Filters())
                        ->setStatus([289,8737])
                        ->setServerDateRange(
                            (new \PayGo\Transactions\Contracts\Query\DateRange())
                                ->setFromDate(\DateTime::createFromFormat('Y-m-d', '2015-01-01'))
                                ->setEndDate(\DateTime::createFromFormat('Y-m-d', '2018-12-01'))
                        )
                )
        );

print_r($response->getStatusCode());
print_r($response->json());

Resposta

array(1) {
  [0]=>
  array(27) {
    ["AffiliationCompanyDataDisplayName"]=>
    string(4) "TESTE"
    ["AffiliationCompanyDataTaxId"]=>
    string(18) "99.999.999/0001-99"
    ["AffiliationNumber"]=>
    string(32) "********************************"
    ["Amount"]=>
    string(4) "5000"
    ["AuthorizerCode"]=>
    string(5) "STONE"
    ["AuthorizerExternalReference"]=>
    string(14) "19291241077475"
    ["AuthorizerName"]=>
    string(5) "STONE"
    ["CardDataCardName"]=>
    string(10) "MASTERCARD"
    ["CardDataExpirationDate"]=>
    string(4) "2602"
    ["CardDataMaskedCardNumber"]=>
    string(16) "************5768"
    ["CardDataType"]=>
    int(1)
    ["FinancingDataInstallmentsNumber"]=>
    int(1)
    ["FinancingDataType"]=>
    int(1)
    ["FullReceiptCopy"]=>
    string(543) "
     STONE - VIA ESTABELECIMENTO      
     MASTERCARD - CREDITO A VISTA     
CNPJ: 999.999.999/0001-99
2ALL
BELO HORIZONTE - MG
************5766       02/04/18  16:42
EC:128268623                AUT:424973
SAK:&E62D11B67204181A190D83E1EBED4EC
DOC:1585
STONE ID:19281241077495
AC:6B087A3450022121           ONL-CHIP
AID: A0000000041010
Credito                       APROVADO
TOTAL:                        R$ 50,00
     TRANSACAO APROVADA COM SENHA     
----------------------------------------
71666 0000007544 0000002585 

"
    ["InternalLocalReference"]=>
    int(1585)
    ["POSCompanyDataDisplayName"]=>
    string(27) "Adriano M. La Selva"
    ["POSCompanyDataTaxId"]=>
    string(14) "111.111.111-11"
    ["POSDataDescription"]=>
    string(12) "Door to Door"
    ["POSDataIdentifier"]=>
    string(5) "9999999"
    ["POSTimestamp"]=>
    string(19) "2018-04-02 16:43:04"
    ["ProductName"]=>
    string(15) "CREDITO A VISTA"
    ["Result"]=>
    int(0)
    ["ResultMessage"]=>
    string(9) "APROVADO "
    ["ServerTimestamp"]=>
    string(19) "2018-04-02 16:42:46"
    ["Status"]=>
    string(3) "289"
    ["Type"]=>
    int(33)
    ["UniqueId"]=>
    int(33171163)
  }
}

Exemplo de consulta omitindo alguns campos do retorno.

$response = $transactionApi->filter(
            (new \PayGo\Transactions\Contracts\Query\Query())
                ->setLimit(1)
                ->setSource(
                    (new \PayGo\Transactions\Contracts\Query\Source())
                        ->setExclude([
                            SourceConst::AFFILIATION_COMPANY_DATA_TAX_ID,
                            SourceConst::FULL_RECEIPT_COPY,
                            SourceConst::AFFILIATION_COMPANY_DATA_DISPLAY_NAME
                        ])
                )
        );

print_r($response->getStatusCode());
print_r($response->json());

Resposta

array(1) {
  [0]=>
  array(27) {
    ["AffiliationNumber"]=>
    string(32) "********************************"
    ["Amount"]=>
    string(4) "5000"
    ["AuthorizerCode"]=>
    string(5) "STONE"
    ["AuthorizerExternalReference"]=>
    string(14) "19291241077475"
    ["AuthorizerName"]=>
    string(5) "STONE"
    ["CardDataCardName"]=>
    string(10) "MASTERCARD"
    ["CardDataExpirationDate"]=>
    string(4) "2602"
    ["CardDataMaskedCardNumber"]=>
    string(16) "************5768"
    ["CardDataType"]=>
    int(1)
    ["FinancingDataInstallmentsNumber"]=>
    int(1)
    ["FinancingDataType"]=>
    int(1)
    ["InternalLocalReference"]=>
    int(1585)
    ["POSCompanyDataDisplayName"]=>
    string(27) "Adriano M. La Selva"
    ["POSCompanyDataTaxId"]=>
    string(14) "111.111.111-11"
    ["POSDataDescription"]=>
    string(12) "Door to Door"
    ["POSDataIdentifier"]=>
    string(5) "9999999"
    ["POSTimestamp"]=>
    string(19) "2018-04-02 16:43:04"
    ["ProductName"]=>
    string(15) "CREDITO A VISTA"
    ["Result"]=>
    int(0)
    ["ResultMessage"]=>
    string(9) "APROVADO "
    ["ServerTimestamp"]=>
    string(19) "2018-04-02 16:42:46"
    ["Status"]=>
    string(3) "289"
    ["Type"]=>
    int(33)
    ["UniqueId"]=>
    int(33171163)
  }
}

Exemplo de consulta expecificando alguns campos do retorno.

$response = $transactionApi->filter(
            (new \PayGo\Transactions\Contracts\Query\Query())
                ->setLimit(1)
                ->setSource(
                    (new \PayGo\Transactions\Contracts\Query\Source())
                        ->setInclude([
                            SourceConst::AFFILIATION_COMPANY_DATA_TAX_ID,
                            SourceConst::FULL_RECEIPT_COPY,
                            SourceConst::AFFILIATION_COMPANY_DATA_DISPLAY_NAME
                        ])
                )
        );

print_r($response->getStatusCode());
print_r($response->json());

Resposta

array(1) {
  [0]=>
  array(4) {
    ["AffiliationCompanyDataDisplayName"]=>
    string(4) "Teste"
    ["AffiliationCompanyDataTaxId"]=>
    string(18) "999.999.999/0001-99"
    ["FullReceiptCopy"]=>
    string(543) "
     STONE - VIA ESTABELECIMENTO      
     MASTERCARD - CREDITO A VISTA     
CNPJ: 999.999.999/0001-99
2ALL
BELO HORIZONTE - MG
************5766       02/04/18  16:42
EC:128268623                AUT:424973
SAK:&E62D11B67204181A190D83E1EBED4EC
DOC:1585
STONE ID:19281241077495
AC:6B087A3450022121           ONL-CHIP
AID: A0000000041010
Credito                       APROVADO
TOTAL:                        R$ 50,00
     TRANSACAO APROVADA COM SENHA     
----------------------------------------
71666 0000007544 0000002585 

"
    ["Result"]=>
    int(0)
  }
}

Exemplo de consulta expecificando alguns campos do retorno e fintrando por nome da rede adquirente.

$response = $transactionApi->filter(
            (new \PayGo\Transactions\Contracts\Query\Query())
                ->setLimit(1)
                ->setFilters(
                    (new Filters())
                        ->setAuthorizerNames(["REDE"])
                )
                ->setSource(
                    (new \PayGo\Transactions\Contracts\Query\Source())
                        ->setInclude([
                            SourceConst::AFFILIATION_COMPANY_DATA_TAX_ID,
                            SourceConst::FULL_RECEIPT_COPY,
                            SourceConst::AFFILIATION_COMPANY_DATA_DISPLAY_NAME,
                            SourceConst::AUTHORIZER_NAME,
                        ])
                )
        );

print_r($response->getStatusCode());
print_r($response->json());

Resposta

array(1) {
  [0]=>
  array(4) {
    ["AffiliationCompanyDataDisplayName"]=>
    string(4) "Teste"
    ["AuthorizerName"]=>
    string(5) "REDE"
    ["AffiliationCompanyDataTaxId"]=>
    string(18) "999.999.999/0001-99"
    ["FullReceiptCopy"]=>
    string(543) "
     STONE - VIA ESTABELECIMENTO      
     MASTERCARD - CREDITO A VISTA     
CNPJ: 999.999.999/0001-99
TESTE
BELO HORIZONTE - MG
************5766       02/04/18  16:42
EC:128268623                AUT:424973
SAK:&E62D11B67204181A190D83E1EBED4EC
DOC:1585
STONE ID:19281241077495
AC:6B087A3450022121           ONL-CHIP
AID: A0000000041010
Credito                       APROVADO
TOTAL:                        R$ 50,00
     TRANSACAO APROVADA COM SENHA     
----------------------------------------
71666 0000007544 0000002585 

"
    ["Result"]=>
    int(0)
  }
}

Licença

The MIT License