1. Go to this page and download the library: Download astrotechlabs/pay2m-sdk 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/ */
astrotechlabs / pay2m-sdk example snippets
use AstrotechLabs\Pay2MSdk\Pay2MGateway;
use AstrotechLabs\Pay2MSdk\Pay2MGatewayParams;
use AstrotechLabs\Pay2MSdk\CreatePixCharge\Dto\PixData;
use AstrotechLabs\Pay2MSdk\CreatePixCharge\Dto\GeneratorData;
// Crie uma instância de Pay2MGateway utilizando como parâmetros o seu ClientId e sua ClientSecret que podem ser adquiridos em seu painel PAY2M
$createPixChargeGateway = new Pay2MGateway(new Pay2MGatewayParams($_ENV['CLIENT_ID'], $_ENV['CLIENT_SECRET']));
// Chame o método createCharge() para criar uma cobrança, este método gera o token de autenticação e cria a cobrança na Pay2M
$response = $createPixChargeGateway->createCharge(new PixData(
generator: new GeneratorData(
name: 'Dev Teste', // STRING | Deve ser o mesmo nome que está na sua conta Pay2M
document: '###########' // STRING | Deve ser o mesmo documento da sua conta Pay2M
),
value: 1, // FLOAT | Valor mínimo 1;
));
print_r($response);
use AstrotechLabs\Pay2MSdk\Pay2MGateway;
use AstrotechLabs\Pay2MSdk\Pay2MGatewayParams;
use AstrotechLabs\Pay2MSdk\CreatePixCharge\Dto\PixData;
use AstrotechLabs\Pay2MSdk\CreatePixCharge\Dto\GeneratorData;
// Crie uma instância de Pay2MGateway utilizando como parâmetros o seu ClientId e sua ClientSecret que podem ser adquiridos em seu painel PAY2M
$createPixChargeGateway = new Pay2MGateway(new Pay2MGatewayParams($_ENV['CLIENT_ID'], $_ENV['CLIENT_SECRET']));
// Gere o token manualmente e armazene-o
$token = $createPixChargeGateway->getAuthToken();
// Chame o método createCharge() para criar uma cobrança e passe o parâmetro token
$response = $createPixChargeGateway->createCharge(new PixData(
generator: new GeneratorData(
name: 'Dev Teste', // STRING | Deve ser o mesmo nome que está na sua conta Pay2M
document: '###########', // STRING | Deve ser o mesmo documento da sua conta Pay2M
manualToken: true, // BOOL | O parâmetro como true irá cobrar o token e utilizará o mesmo para gerar a cobrança
token: $token // STRING | Deve ser o token gerado pelo metodo getAuthToken() da classe Pay2MGateway
),
value: 1, // FLOAT | Valor mínimo 1;
));
print_r($response);