PHP code example of codpay / php-sdk
1. Go to this page and download the library: Download codpay/php-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/ */
codpay / php-sdk example snippets
use CodPay\Api\Amount;
use CodPay\Api\Payer;
use CodPay\Api\Payment;
use CodPay\Api\RedirectUrls;
use CodPay\Api\Transaction;
$payer = new Payer();
$payer->setPaymentMethod('Pix');
$amountIns = new Amount($amount);
$amountIns->setTotal($amount)
->setCurrency('BRL')
->setReferencia($txid);
$trans = new Transaction();
$trans->setAmount($amountIns);
$urls = new RedirectUrls();
$urls->setSuccessUrl($dominio.'/notification/ipn.php')
->setCancelUrl ($dominio.'/cancel');
$payment = new Payment();
$payment->setCredentials(
['client_id' => $client_id,
'client_secret' => $client_secret,
])
->setRedirectUrls($urls)
->setPayer($payer)
->setTransaction($trans);
try {
$payment->create();
if ($payment->getApprovedUrl() == false) {
echo 'Metodo de pagamento indisponivel no momento.';
exit;
}
$jsonData = file_get_contents($payment->getApprovedUrl());
$arrayData = json_decode($jsonData, true);
//QrCode e code
$qrcode = $arrayData["data"]["qrcode"];
$copia_cola = $arrayData["data"]["qrcopy"];
} catch (\Exception $ex) {
print $ex; exit;
}