A comprehensive PHP SDK for integrating Bancard vPOS and Bancard VentasQR payment solutions into your applications.
- Installation
- Configuration
- vPOS Integration
- VentasQR Integration
- Advanced Usage
- API Reference
- Contributing
- License
- PHP >= 8.0
composer require hds-solutions/bancard-sdk
use HDSSolutions\Bancard\Bancard;
// Set your vPOS API credentials
Bancard::credentials(
publicKey: 'YOUR_PUBLIC_KEY',
privateKey: 'YOUR_PRIVATE_KEY',
);
The SDK uses the staging environment by default for vPOS. Switch to production when ready:
use HDSSolutions\Bancard\Bancard;
// Switch to production
Bancard::useProduction();
// Or dynamically based on your application environment
Bancard::useProduction(config('app.env') === 'production');
- Single payments
- Single payments through Zimple
- Card management
- Charge payments to registered cards
- Pre-authorization
- Transaction management (get confirmation and rollback payments)
Endpoint used to generate a process ID to call the Bancard <iframe>
for a one-time payment.
use HDSSolutions\Bancard\Bancard;
use HDSSolutions\Bancard\Models\Currency;
$response = Bancard::single_buy(
shop_process_id: $shop_process_id,
amount: $amount,
description: 'Premium Subscription',
currency: Currency::Guarani,
return_url: 'https://your-domain.com/payment/success',
cancel_url: 'https://your-domain.com/payment/cancel',
);
if ($singleBuyResponse->wasSuccess()) {
// access the generated process ID to call the Bancard <iframe>
$process_id = $singleBuyResponse->getProcessId();
}
Same as above, but for Zimple
payments.
use HDSSolutions\Bancard\Bancard;
use HDSSolutions\Bancard\Models\Currency;
$singleBuyResponse = Bancard::single_buy_zimple(
shop_process_id: $shop_process_id,
amount: $amount,
description: 'Premium Subscription',
currency: Currency::Guarani,
phone_no: $phone_no, // this field is automatically send on the `additional_data` property of the request
return_url: 'https://localhost/your-success-callback-path',
cancel_url: 'https://localhost/your-cancelled-callback-path',
);
- Register a New Card
use HDSSolutions\Bancard\Bancard;
$response = Bancard::card_new(
user_id: $user_id,
card_id: $card_id,
phone_no: '+595991234567',
email: '[email protected]',
return_url: 'https://your-domain.com/cards/callback',
);
if ($response->wasSuccess()) {
// access the generated process ID to call the Bancard <iframe>
$processId = $response->getProcessId();
}
- List User's Cards
use HDSSolutions\Bancard\Bancard;
use HDSSolutions\Bancard\Models\Card;
$response = Bancard::users_cards(
user_id: $user_id,
);
if ($response->wasSuccess()) {
foreach ($response->getCards() as $card) {
echo "Card: {$card->card_masked_number}\n";
echo "Brand: {$card->card_brand}\n";
echo "Expiration: {$card->expiration_date}\n";
}
}
- Charge a Registered Card
use HDSSolutions\Bancard\Bancard;
use HDSSolutions\Bancard\Models\Card;
use HDSSolutions\Bancard\Models\Currency;
use HDSSolutions\Bancard\Models\Confirmation;
use HDSSolutions\Bancard\Models\SecurityInformation;
$response = Bancard::charge(
card: $card,
shop_process_id: $shop_process_id,
amount: $amount,
currency: Currency::Guarani,
description: 'Monthly Subscription',
);
if ($response->wasSuccess()) {
// access to change Confirmation data
$confirmation = $chargeResponse->getConfirmation();
echo sprintf('Ticket No: %u, Authorization ID: %u',
$confirmation->ticket_number,
$confirmation->authorization_number);
// also access to the security information data
$securityInformation = $confirmation->getSecurityInformation();
echo sprintf('Country: %s, Risk Index: %.2F',
$securityInformation->card_country,
$securityInformation->risk_index);
}
- Get the confirmation of a Payment
Endpoint to get the confirmation of a payment. Example, in case the above charge request stayed as a pending of confirmation payment.
use HDSSolutions\Bancard\Bancard;
use HDSSolutions\Bancard\Models\Confirmation;
$confirmationResponse = Bancard::confirmation(
shop_process_id: $chargeResponse->getRequest()->getShopProcessId(),
);
- Rollback a Payment
use HDSSolutions\Bancard\Bancard;
$rollbackResponse = Bancard::rollback(
shop_process_id: $chargeResponse->getRequest()->getShopProcessId(),
);
- Remove a Registered Card
use HDSSolutions\Bancard\Bancard;
use HDSSolutions\Bancard\Models\Card;
$response = Bancard::card_delete(
card: $card, // must be an instance of Card, obtained from Bancard::users_cards()
);
The SDK provides comprehensive error handling for various scenarios:
$response = Bancard::single_buy(/* ... */);
if (! $response->wasSuccess()) {
foreach ($response->getMessages() as $message) {
echo sprintf(
"Error: [%s] %s (Level: %s)\n",
$message->key,
$message->description,
$message->level
);
}
}
$response = Bancard::charge(/* ... */);
if ($response->wasSuccess()) {
$confirmation = $response->getConfirmation();
// Access confirmation details
echo "Response: {$confirmation->response}\n";
echo "Response Details: {$confirmation->response_details}\n";
echo "Response Description: {$confirmation->response_description}\n";
// Access security information
$security = $confirmation->getSecurityInformation();
echo "Customer IP: {$security->customer_ip}\n";
echo "Card Country: {$security->card_country}\n";
echo "Risk Index: {$security->risk_index}\n";
}
if (! $response->wasSuccess()) {
// Get request details
$request = $response->getRequest();
echo "Request Body: {$request->getBody()->getContents()}\n";
// Get response details
echo "Response Status: {$response->getStatusCode()}\n";
echo "Response Body: {$response->getBody()->getContents()}\n";
// Log for debugging
error_log(sprintf(
"Bancard API Error: %s, Status: %d, Body: %s",
$response->getMessages()[0]->description ?? 'Unknown error',
$response->getStatusCode(),
$response->getBody()->getContents()
));
}
⚠ Important: VentasQR is not scoped by Bancard::useProduction()
, since your assigned domain will define your testing/production environment.
use HDSSolutions\Bancard\Bancard;
Bancard::qr_credentials(
serviceUrl: 'YOUR_QR_ASSIGNED_DOMAIN',
publicKey: 'YOUR_QR_PUBLIC_KEY',
privateKey: 'YOUR_QR_PRIVATE_KEY',
qrCommerceCode: 1234,
qrBranchCode: 123,
);
- Generate QR codes for payments
- Revert QR payments
- Generate QR Code
$response = Bancard::qr_generate(
amount: $amount,
description: 'Product Purchase',
);
if ($response->wasSuccess()) {
// access the generated QR data
$qrExpress = $qrGenerateResponse->getQRExpress();
echo sprintf('QR Payment ID: %s, QR Image url: %s, QR Data: %s',
$qrExpress->hook_alias,
$qrExpress->url,
$qrExpress->qr_data);
// access the list of supported clients
$supportedClients = $qrGenerateResponse->getSupportedClients();
foreach ($supportedClients as $supportedClient) {
echo sprintf('Client name: %s, Client Logo url: %s',
$supportedClient->name,
$supportedClient->logo_url);
}
}
- Revert QR Payment
$response = Bancard::qr_revert(
hook_alias: $qrExpress->hook_alias,
);
if ($response->wasSuccess()) {
echo "Payment successfully reverted\n";
}
Access request and response details for debugging:
// From response to request
$request = $response->getRequest();
echo "Request Body: " . $request->getBody()->getContents() . "\n";
// From request to response
$response = $request->getResponse();
echo "Response Body: " . $response->getBody()->getContents() . "\n";
If you need, you can create a pending request and change the values on runtime. This applies to all available requests.
use HDSSolutions\Bancard\Bancard;
use HDSSolutions\Bancard\Models\Currency;
$singleBuyRequest = Bancard::newSingleBuyRequest(
shop_process_id: $shop_process_id,
amount: $amount,
description: 'Premium Subscription',
currency: Currency::Guarani,
return_url: 'https://your-domain.com/payment/success-callback-path',
cancel_url: 'https://your-domain.com/payment/cancel-callback-path',
);
// for example, enable Zimple flag for this request
$singleBuyRequest->enableZimple();
// for Zimple, you need to specify the user's phone number on the additional data property
$singleBuyRequest->setAdditionalData($phone_no);
// after building the request, you can call the execute() method to send the request to Bancard
if (! $singleBuyRequest->execute()) {
// if failed, you can access the response, and the messages
$singleBuyRequest->getResponse()->getMessages();
}
Bancard::single_buy()
- Process a one-time paymentBancard::single_buy_zimple()
- Process a Zimple paymentBancard::card_new()
- Register a new cardBancard::users_cards()
- List user's registered cardsBancard::card_delete()
- Remove a registered cardBancard::charge()
- Charge a registered cardBancard::confirmation()
- Check payment statusBancard::preauthorizationConfirm()
- Confirm a pre-authorized paymentBancard::rollback()
- Cancel a pending transaction
Bancard::qr_generate()
- Generate a QR code for paymentBancard::qr_revert()
- Cancel a QR payment
The SDK supports multiple currencies through the Currency
class:
Currency::Guarani
- Paraguayan Guarani (PYG)Currency::Dollar
- US Dollar (USD)
For detailed API documentation, visit:
Contributions are welcome! If you find any issues or would like to add new features or improvements, please feel free to submit a pull request.
If you encounter any security-related issues, please feel free to raise a ticket on the issue tracker.
This library is open-source software licensed under the MIT License. Please see the License File for more information.