PHP code example of zrkb / bancard
1. Go to this page and download the library: Download zrkb/bancard 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/ */
zrkb / bancard example snippets
use Bancard\Bancard;
$bancard = new Bancard(
publicKey: 'YOUR_PUBLIC_KEY',
privateKey: 'YOUR_PRIVATE_KEY',
staging: true, // optional, defaults to false
);
use Bancard\Util\Currency;
$response = $bancard->singleBuy([
'shop_process_id' => '7777777',
'amount' => '10000.00',
'currency' => Currency::PYG->value,
'return_url' => 'https://app.test/return',
'cancel_url' => 'https://app.test/cancel',
]);
if ($response->isSuccessful()) {
$processId = $response->getProcessId();
}
$response = $bancard->singleBuyZimple([
'shop_process_id' => '7777777',
'amount' => '10000.00',
'currency' => Currency::PYG->value,
'return_url' => 'https://app.test/return',
'cancel_url' => 'https://app.test/cancel',
]);
$response = $bancard->singleBuyConfirm([
'shop_process_id' => '7777777',
'amount' => '10000.00',
'currency' => Currency::PYG->value,
]);
$token = $response->getToken();
$response = $bancard->singleBuyGetConfirmation([
'shop_process_id' => '7777777',
]);
if ($response->isApproved()) {
$code = $response->getResponseCode();
}
$response = $bancard->singleBuyRollback([
'shop_process_id' => '7777777',
]);
$response = $bancard->cardsNew([
'card_id' => '123',
'user_id' => '456',
'return_url' => 'https://app.test/return',
]);
$processId = $response->getProcessId();
$response = $bancard->usersCards([
'user_id' => '456',
]);
foreach ($response->getCards() as $card) {
echo $card->card_masked_number;
}
$response = $bancard->charge([
'shop_process_id' => '7777777',
'amount' => '10000.00',
'currency' => Currency::PYG->value,
'alias_token' => 'card_alias_token',
]);
if ($response->isApproved()) {
// Payment successful
}
if ($response->is3dsRedirect()) {
// 3DS authentication
$response = $bancard->deleteCard([
'user_id' => '456',
'alias_token' => 'card_alias_token',
]);
$response = $bancard->preauthorizationConfirm([
'shop_process_id' => '7777777',
]);
if ($response->isApproved()) {
// Preauthorization confirmed
}
$response = $bancard->billingClientInfo([
// billing client info fields
]);
$client = $response->getClient();
$response = $bancard->billingCancel([
'shop_process_id' => '7777777',
]);
use Bancard\Exception\ValidationException;
try {
$response = $bancard->singleBuy($payload);
} catch (ValidationException $e) {
// Missing
use Bancard\Util\Amount;
$formatted = Amount::format(10000); // "10000.00"