PHP code example of paygo-dev / paygo-sdk-php

1. Go to this page and download the library: Download paygo-dev/paygo-sdk-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

paygo-dev / paygo-sdk-php example snippets


$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);

$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);

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

$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());

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)
  }
}

$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());

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)
  }
}

$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());

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)
  }
}

$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());

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)
  }
}

$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());

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)
  }
}

$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());

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)
  }
}