Download the PHP package zrkb/bancard without Composer
On this page you can find all versions of the php package zrkb/bancard. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package bancard
Bancard
PHP SDK for the Bancard vPOS 2.0 payment gateway API
Installation
Requirements: PHP >= 8.1
Configuration
Requests time out after 30 seconds (10 seconds to connect) by default. Override with the timeout and connect_timeout Guzzle options.
The private key is hidden from var_dump()/print_r() and stack traces.
Usage
All operations return typed response objects with convenience methods.
Single Buy
Single Buy (Zimple)
Single Buy Confirm
Generates the confirm token for the iframe callback (no HTTP request is made).
Payment Form (bancard-checkout.js)
singleBuy(), singleBuyZimple() and cardsNew() return a process_id. Bancard's iframe collects the card data with it:
Use Bancard.Zimple.createForm for Zimple, Bancard.Cards.createForm for card registration and Bancard.Charge3DS.createForm for 3DS. The URL follows the staging flag (bancard-checkout-4.0.0.js, Bancard::CHECKOUT_JS_VERSION).
The payment form also offers QR and PIX when they are enabled in the application profile of the commerce portal. They need no extra integration: the result arrives at the same confirmation callback.
Confirmation Callback
Bancard POSTs the payment result to your confirmation URL. parseConfirmation() verifies its token (constant-time comparison) and returns a typed object:
In Laravel: $bancard->parseConfirmation($request->getContent()) and return response()->json(ConfirmationCallback::ACKNOWLEDGEMENT);.
With electronic invoicing (billing), getInvoiceNumber() and getCdc() return the generated invoice number and control code.
Bancard expects HTTP 200 within 30 seconds. If it does not get one, the payment is not necessarily denied: check it with singleBuyGetConfirmation().
To check an already decoded operation array, use $bancard->verifyConfirmation($operation) (returns bool).
Single Buy Get Confirmation
While the customer has not paid yet, this throws ApiException with key PaymentNotFoundError.
singleBuyGetConfirmation(), preauthorizationConfirm() and charge() responses have the same getters as the confirmation callback (getResponseCode(), getAuthorizationNumber(), getTicketNumber(), getCardSource(), getRiskIndex(), ...).
Single Buy Rollback
Register a New Card
Mount Bancard.Cards.createForm with the process_id (Payment Form). Bancard then redirects to return_url with ?status=add_new_card_success, or ?status=add_new_card_fail&description=.... Check the result with usersCards(). A user can have at most 5 registered cards. On staging, use cédula 9661000.
List User Cards
Charge (Token-Based Payment)
charge() sends number_of_payments: 1, additional_data: "" and extra_response_attributes: ["confirmation.process_id"] (which enables 3DS detection) unless you pass other values. Pass null to omit one.
Charge a Saved Card (Recurring Payments)
Alias tokens are single-use and expire within minutes, so don't store them. Store user_id + card_id and use chargeCard(): it fetches a fresh alias token with usersCards() and then charges.
To pick the alias token yourself, use $bancard->usersCards([...])->findCard($cardId).
Delete Card
Preauthorization Confirm
Billing Client Info
Billing Cancel
Response Objects
All responses extend Bancard\Response\Response and provide:
isSuccessful(): bool-- checks ifstatus === 'success'getStatus(): ?stringgetMessage(): ?string-- first message descriptiongetErrorKey(): ?string-- error key from messagesraw(): \stdClass-- access the raw response data
Specialized responses add operation-specific methods (e.g., getProcessId(), isApproved(), getCards()).
Error Handling
Every exception extends BancardException, so one catch (BancardException $e) covers them all.
After a NetworkException on a payment the outcome is unknown: Bancard may have processed it. Check with singleBuyGetConfirmation() before retrying with the same shop_process_id.
Error keys worth handling:
| Key | Meaning |
|---|---|
DuplicatePaymentError |
Same card and amount charged in the last 5 minutes. |
PaymentNotFoundError |
The customer has not paid this shop_process_id yet. |
BuyNotFoundError |
No payment with that shop_process_id. |
InvalidOperationError |
A field is missing or invalid (see getMessage()). |
Bancard blocks a card at the commerce for 30 days after 7 rejected payments in 24 hours or 35 in 30 days ("MANDATO MC MAC 03 y 21"). Don't retry rejected payments automatically.
Field Validation
Fields are checked against the vPOS spec before sending, so mistakes fail locally with the field names instead of as InvalidOperationError:
- Integers:
shop_process_id(max 15 digits; rollback and billing cancel accept any string),card_idanduser_id(max 19 digits) - Strings:
description(20 chars),currency(3),client_ruc(32), URLs,additional_data,alias_token,user_cell_phoneanduser_mail(255) - Amounts: at most 13 integer digits and 2 decimals
- Required fields set to
nullor""count as missing.charge()andchargeCard()requiredescription: the spec omits it, but Bancard rejects charges without it.
Amounts and Currency
amount and iva_amount accept ints, floats or numeric strings and are sent and signed as "10000.00". Strings with more than two decimals, separators like "10,000" or negative values throw ValidationException.
currency accepts the Currency enum or its string value:
Upgrading from 1.0
See UPGRADE.md for the migration guide.
Development
Staging Smoke Test
tests/Smoke runs real requests against Bancard staging. It is not part of the default suite or CI, and skips itself without credentials:
| Variable | Purpose |
|---|---|
BANCARD_STAGING_PUBLIC_KEY, BANCARD_STAGING_PRIVATE_KEY |
Required. Staging keys from the Bancard commerce portal. |
BANCARD_STAGING_USER_ID |
Runs users_cards, and is used for cards_new. |
BANCARD_STAGING_CARD_ID |
card_id of a card registered for that user. Runs chargeCard() (with and without the 3DS attribute) and singleBuyGetConfirmation() with extra attributes, then rolls back. |
BANCARD_STAGING_RETURN_URL |
Return/cancel URL sent to Bancard (default https://example.com/bancard/return). |
BANCARD_SMOKE_TEST_CLIENT=1 |
Sends test_client so the runs don't count toward Bancard's staging test list. |
Keep the variables in .env.smoke (gitignored) and load them with set -a; . ./.env.smoke; set +a.
To get a BANCARD_STAGING_CARD_ID, serve tests/Smoke/register-card.php, for example with php -S localhost:8000 tests/Smoke/register-card.php or through Valet. It reads .env.smoke, opens Bancard's card form, and after registration shows the card_id to use. On staging, the card 5418630110000014 (expiry 08/21, CVV 258) with cédula 9661000 works.
Each request and response is written to build/smoke/<run>/ with keys, tokens and alias tokens redacted, so real response shapes can be compared with what the SDK expects.
Security
If you discover any security related issues, please use the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.