PHP code example of krugerdavid / laravel-bancard

1. Go to this page and download the library: Download krugerdavid/laravel-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/ */

    

krugerdavid / laravel-bancard example snippets


use KrugerDavid\Bancard\Facades\Bancard;

$result = Bancard::singleBuy(
    shopProcessId: 54322,
    amount: '10330.00',
    description: 'Ejemplo de pago',
    returnUrl: 'https://tusitio.com/finish'
);

// $result['process_id'] → usar en Bancard.Checkout.createForm()
// $result['status'] → 'success'

Bancard::singleBuy(54322, '10330.00', 'Pago', 'https://x.com/finish', [
    'cancel_url' => 'https://x.com/cancel',
    'additional_data' => '099VS ORO000045',  // promociones
    'iva_amount' => '1033.00',
    'preauthorization' => 'S',
    'extra_response_attributes' => ['payment_card_type'],
]);

$result = Bancard::singleBuyZimple(
    shopProcessId: 54322,
    amount: '10330.00',
    description: 'Pago Zimple',
    returnUrl: 'https://tusitio.com/finish',
    userPhone: '0981123456'
);

$result = Bancard::rollback(12313);
// $result['status'] === 'success'

$result = Bancard::getConfirmation(12313);
// $result['confirmation']['response'] → 'S' (aprobado) o 'N'
// $result['confirmation']['response_code'] → '00' (aprobada)

$result = Bancard::cardsNew(
    cardId: 1,
    userId: 966389,
    userCellPhone: '0919876543',
    userMail: '[email protected]',
    returnUrl: 'https://tusitio.com/cards/result'
);
// Usar $result['process_id'] con Bancard.Cards.createForm()

$result = Bancard::usersCards(966389);
// $result['cards'] → array de tarjetas con alias_token

$result = Bancard::charge(
    60361,
    '723215.00',
    $aliasToken,  // de usersCards
    [
        'return_url' => 'https://tusitio.com/result',
        'number_of_payments' => 1,
    ]
);

$result = Bancard::deleteCard(966389, $aliasToken);

$isValid = Bancard::verifyConfirmToken(
    $shopProcessId,
    $amount,
    $receivedToken
);

use KrugerDavid\Bancard\BancardManager;

class PaymentController
{
    public function __construct(
        private BancardManager $bancard
    ) {}

    public function checkout()
    {
        $result = $this->bancard->singleBuy(...);
    }
}

use KrugerDavid\Bancard\DTOs\Billing;
use KrugerDavid\Bancard\DTOs\BillingDetail;

$billing = new Billing(
    clientRuc: '123456-1',
    clientName: 'JUAN GONZALEZ',
    clientEmail: '[email protected]',
    commerceStamp: '12559969',
    commerceExpeditionPoint: '001',
    commerceEstablishment: '002',
    details: [
        new BillingDetail('Item 1', '10000.00', 10, 1),
        new BillingDetail('Item 2', '330.00', 10, 1),
    ]
);

Bancard::singleBuy(54322, '10330.00', 'Pago', 'https://x.com', [
    'billing' => $billing,
]);
bash
php artisan vendor:publish --tag=bancard-config