1. Go to this page and download the library: Download jhernandes/ipag-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/ */
jhernandes / ipag-sdk-php example snippets
use Ipag\Ipag;
use Ipag\Classes\Authentication;
use Ipag\Classes\Endpoint;
$ipag = new Ipag(new Authentication('my_id_ipag', 'my_ipag_key'), Endpoint::SANDBOX);
$transaction = $ipag->transaction();
$transaction->getOrder()
->setOrderId($orderId)
->setCallbackUrl('https://minha_loja.com.br/ipag/callback')
->setAmount(10.00)
->setInstallments(1)
->setPayment($ipag->payment()
->setMethod(Method::PIX)
->setPixExpiresIn(60)
)->setCustomer($customer)
);
$response = $transaction->execute();
// PIX LINK DE PAGAMENTO (Usando o Checkout do iPag para finalizar)
$linkDePagamento = $response->pix->link;
// PIX Copia e Cola | QRCode (Utilizar a string retornada ou gerar um QrCode)
$qrCodeString = $response->pix->qrCode;
pag\Ipag;
use Ipag\Classes\Authentication;
use Ipag\Classes\Endpoint;
use Ipag\Classes\Enum\PaymentStatus;
try {
$ipag = new Ipag(new Authentication('my_id_ipag', 'my_ipag_key'), Endpoint::SANDBOX);
$customer = $ipag->customer()
->setName('Fulano da Silva')
->setTaxpayerId('799.993.388-01')
->setPhone('11', '98888-3333')
->setEmail('[email protected]')
->setAddress($ipag->address()
->setStreet('Rua Júlio Gonzalez')
->setNumber('1000')
->setNeighborhood('Barra Funda')
->setCity('São Paulo')
->setState('SP')
->setZipCode('01156-060')
);
$products = [
['Produto 1', 5.00, 1, 'ABDC1'],
['Produto 2', 2.50, 2, 'ABDC2']
];
$cart = $ipag->cart(...$products);
$transaction = $ipag->transaction();
$transaction->getOrder()
->setOrderId($orderId)
->setCallbackUrl('https://minha_loja.com.br/ipag/callback')
->setAmount(10.00)
->setInstallments(1)
->setExpiry('10/07/2021')
->setPayment($ipag->payment()
->setMethod(Method::BANKSLIP_ZOOP)
)->setCustomer($customer)
);
$response = $transaction->execute();
//Retornou algum erro?
if (!empty($response->error)) {
throw new \Exception($response->errorMessage);
}
//Pagamento de Boleto Criado (1) ou Boleto Impresso (2) ?
if (in_array($response->payment->status, [
PaymentStatus::CREATED,
PaymentStatus::PRINTED_BOLETO
])) {
// Boleto Link
//echo $response->urlAuthentication;
return $response;
}
} catch(\Exception $e) {
print_r($e->__toString());
}
pag\Classes\Services\CallbackService;
use Ipag\Classes\Enum\PaymentStatus;
$postContent = file_get_contents('php://input');
$callbackService = new CallbackService();
// $response conterá os dados de retorno do iPag
// $postContent deverá conter o XML enviado pelo iPag
$response = $callbackService->getResponse($postContent);
// Verificar se o retorno tem erro
if (!empty($response->error)) {
echo "Contem erro! {$response->error} - {$response->errorMessage}";
}
// Verificar se a transação foi aprovada e capturada:
if ($response->payment->status == PaymentStatus::CAPTURED) {
echo 'Transação Aprovada e Capturada';
// Atualize minha base de dados ...
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.