Search by

sextanet / laravel-oneclick

sextanet

Laravel Oneclick

Package info

github.com/sextanet/laravel-oneclick

pkg:composer/sextanet/laravel-oneclick

Fund package maintenance!

SextaNet

Statistics

Installs: 12

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

2.1.1 2026-04-11 02:19 UTC

This package is auto-updated.

Last update: 2026-10-16 17:18:16 UTC


README

Laravel oneclick

Laravel, Transbank, Webpay and SextaNet products and logos are property of their respective companies.

The easiest way to use Oneclick in your projects

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Installation

You can install the package via composer:

composer require sextanet/laravel-oneclick

Publish and run migrations

php artisan vendor:publish --tag="oneclick-migrations"
php artisan migrate

Copy these keys in your .env file

ONECLICK_IN_PRODUCTION=false
ONECLICK_API_KEY=
ONECLICK_COMMERCE_CODE=
ONECLICK_MALL_CODE=
ONECLICK_DEBUG=true

Usage

Registering a card

Import the trait in your User or equivalent model

use SextaNet\LaravelOneclick\Traits\HasOneclick;

class User // extends ...
{
    use HasOneclick;
}

Now, you can do that:

$user = User::find(2);

return $user->registerCardOneclick();

Pay with registered card

Import the trait in your Order or equivalent model

use SextaNet\LaravelOneclick\Traits\PayWithOneclick;

class Order extends Model
{
    use PayWithOneclick;
}

Now, you can do that:

$oneclick_card = User::find(2)->oneclick_cards()->first();

$order = Order::findById(1);

$order->payWithOneclick($oneclick_card);

Also, you can add installments by passing a second parameter:

$order->payWithOneclick($oneclick_card, 3);

For convenience, you can set custom pages for each status before calling payWithOneclick() method

Cancelled

LaravelOneclick::setCancelledUrl('/cancelled-page');

Rejected

LaravelOneclick::setRejectedUrl('/rejected-page');

Testing cards

Type Numbers Result
VISA 4051 8856 0044 6623 Approved
Mastercard 5186 0595 5959 0568 Rejected
Redcompra 4051 8842 3993 7763 Approved
VISA Prepaid 4051 8860 0005 6590 Approved
  • Expire date: (Any valid date)
  • RUT: 11111111-1
  • Password: 123

Source: Official Transbank Developers website

Testing

To test Oneclick flows without hitting the real Transbank API, call LaravelOneclick::enableTests(). It returns a fluent builder to queue stub responses, and always reset the fake in afterEach.

use SextaNet\LaravelOneclick\LaravelOneclick;

afterEach(fn () => LaravelOneclick::disableTests());

Registering a card (approved)

LaravelOneclick::enableTests()
    ->withInscriptionStart()
    ->withInscriptionFinishApproved();

$start = LaravelOneclick::instance()
    ->start($username, $email, $responseUrl);

$finish = LaravelOneclick::instance()
    ->finish($start->getToken());

$finish->isApproved(); // true
$finish->getTbkUser(); // 'b6bd6ba3-e718-4107-9386-d2b099a8dd42'
$finish->getCardType(); // 'Visa'
$finish->getCardNumber(); // 'XXXXXXXXXXXX6623'

You can also stub a rejected or cancelled registration:

LaravelOneclick::enableTests()->withInscriptionFinishRejected();  // response_code -1
LaravelOneclick::enableTests()->withInscriptionFinishCancelled(); // response_code -96

Authorizing a payment (approved)

LaravelOneclick::enableTests()->withTransactionAuthorizeApproved();

$response = LaravelOneclick::pay($username, $tbkUser, $parentBuyOrder, $details);

$response->isApproved();           // true
$response->getDetails()[0]->status; // 'AUTHORIZED'

Stub a rejected payment:

LaravelOneclick::enableTests()->withTransactionAuthorizeRejected();

Overriding stub data

Any stub method accepts an array of overrides merged into the response:

LaravelOneclick::enableTests()->withTransactionAuthorizeApproved([
    'details' => [['amount' => 9999]],
]);

Asserting all queued stubs were consumed

$fake = LaravelOneclick::enableTests()
    ->withInscriptionStart()
    ->withInscriptionFinishApproved();

// ... run code ...

$fake->assertAllResponsesConsumed();

Integration

Official Laravel integration project

Production mode

When you are ready to be in production, you need to set WEBPAY_IN_PRODUCTION to true, and specify WEBPAY_COMMERCE_CODE and WEBPAY_API_KEY.

License

The MIT License (MIT). Please see License File for more information.