Home

Awesome

Laravel TbcPay

Latest Stable Version Total Downloads Downloads Month

This package allows you to use TBC payments in your Laravel application.

Laravel TbcPay

Table of Contents

Installation

composer require lotuashvili/laravel-tbcpay

For Laravel <= 5.4

If you're using Laravel 5.4 or lower, you have to manually add a service provider in your config/app.php file. Open config/app.php and add TbcPayServiceProvider to the providers array.

'providers' => [
    # Other providers
    Lotuashvili\LaravelTbcPay\TbcPayServiceProvider::class,
],

Then run:

php artisan vendor:publish --provider="Lotuashvili\LaravelTbcPay\TbcPayServiceProvider"

And run migrations:

php artisan migrate

Transaction types (SMS / DMS)

There are two types of transaction within this system: SMS and DMS.

SMS - is a direct payment method, money is charged in 1 event, as soon as customer enters the credit card details and clicks proceed.
DMS - is a two step method, first event blocks the money on the card (max 30 days), second event captures the money (second event can be carried out when product is shipped to the customer for example).

Every 24 hours, a merchant must close the business day.

Generating and placing a certificate

TBC provides SSL certificate in .p12 format, we need to transform it to .pem format. Use command below:

openssl pkcs12 -in *.p12 -out tbcpay.pem

After transformation, place certificate (.pem file) in storage/certificates folder. Name it whatever you want (tbcpay.pem in this example) and specify the name and password in .env.

TBCPAY_CERTIFICATE_NAME=tbcpay.pem
TBCPAY_CERTIFICATE_PASS=YourPassword123

After that, add storage/certificates folder in to your .gitignore.

Environment

Set your environment variables:

Note: Specify only certificate file name instead of full path. Certificates are placed in storage/certificates folder.

Set default currency with ISO 4217 standart. List of all currencies: http://en.wikipedia.org/wiki/ISO_4217 (Default is 981 - GEL).

TBCPAY_DEBUG=true
TBCPAY_CERTIFICATE_NAME=tbcpay.pem
TBCPAY_CERTIFICATE_PASS=YourPassword123
TBCPAY_DEFAULT_CURRENCY=981

Configuration

Amount unit

You can change default amount unit from configuration or .env file. Amount unit is used to multiply final amount before sending request to TBC. TBC bank requires amount in Cents (or Tetri) instead of USD (or GEL).

By default, unit is set to 100, so you can pass amount in GEL, for example $amount = 300 will redirect to the checkout page with 300GEL amount.

If you set unit to 1, then you will be redirected to the checkout page with 3GEL amount.

To change amount unit, set TBCPAY_AMOUNT_UNIT=1 in .env file or change amount_unit directly in config/tbc.php.

Merchant URLs

If one day TBC updates merchant and submit URLs, you can simply override old URLs from .env or config/tbc.php.

Set TBCPAY_MERCHANT_URL and TBCPAY_FORM_URL in .env or merchant_url and form_url directly in config/tbc.php.

Debug

Simply enable debug from .env by setting TBCPAY_DEBUG=true, all logs will be in tbc_logs table by default. You can access them with Lotuashvili\LaravelTbcPay\Models\TbcLog model.

Usage

Setting up routes and controller

After publishing files, app/Http/Controllers/TbcPayController will be created. Feel free to modify controller as you want.

Open routes/web.php and define routes (Remove variables to use default values).

<?php

use Lotuashvili\LaravelTbcPay\TbcPay;

// Other routes

TbcPay::routes(
    $controller, // Default: 'TbcPayController'
    $successMethod, // Default: 'success'
    $failMethod // Default: 'fail'
);

NOTE: Exclude tbcpay/* routes from CSRF Token verification to avoid TokenMismatchException on success/fail URLs.

Add urls in your app/Http/Middleware/VerifyCsrtToken.php:

<?php

class VerifyCsrfToken extends Middleware
{
    // Other variables

    protected $except = [
        'tbcpay/*',
    ];
}

Send success and fail URLs to TBC:

Success: http://website.ge/tbcpay/success

Fail: http://website.ge/tbcpay/fail

Payment

In your controller, inject \Lotuashvili\LaravelTbcPay\TbcPay class to use payments.

<?php

class PaymentController
{
    // Other methods
    
    public function pay(\Lotuashvili\LaravelTbcPay\TbcPay $tbcPay)
    {
        // OPTIONAL: Load model and start transaction by model
        // Model relation will be used in tbc_transactions table
        $model = User::first();

        return $tbcPay->init(
            100, // Amount
            981, // Currency (Optional)
            'Biller name', // Name of biller (Optional)
            'Website payment', // Message to be displayed on a payment page (Optional)
            'ge' // Language of the payment page (Optional)
        )->start($model) // Model parameter is optional
         ->sms() // Optional: Specify transaction type (Supported: sms and dms)
         ->view(); // Return final view of TBC payment to redirect to a payment page
    }
}

After returning view, website will be redirected to the payment page. After filling card details, you will be redirected to the success or fail url, that you've specified previously to TBC.

Using other methods

If you have started DMS authorization (blocked money on account), then you have to actually bill blocked amount after some period of time. You will need makeDms() function for that.

You can directly access core processor's methods by calling for example $tbcPay->reverse_transaction() (Using magic __call function). For all methods, please check PlugAndPay TBC Processor's documentation

Closing day with cron

If you don't have cron jobs running in your application, please check out Laravel's documentation.

Register command in your app/Console/Kernel.php.

protected $commands = [
    // Other commands
    \Lotuashvili\LaravelTbcPay\Commands\CloseDay::class,
];

Then add command to schedule (for example use daily(), it will run command everyday at 00:00).

protected function schedule(Schedule $schedule)
{
    // Other commands
    $schedule->command('tbcpay:close-day')
             ->daily();
}

Transactions history

All transactions will be available in tbc_transactions table by default. You can access them with Lotuashvili\LaravelTbcPay\Models\TbcTransaction model.

If you have enabled debug, then all records will be available in tbc_logs table and can access them with Lotuashvili\LaravelTbcPay\Models\TbcLog model.

Result Codes

KeyValueDescription
000ApprovedApproved
001Approved with IDApproved, honour with identification
002ApprovedApproved for partial amount
003ApprovedApproved for VIP
004ApprovedApproved, update track 3
005ApprovedApproved, account type specified by card issuer
006ApprovedApproved for partial amount, account type specified by card issuer
007ApprovedApproved, update ICC
100DeclineDecline (general, no comments)
101DeclineDecline, expired card
102DeclineDecline, suspected fraud
103DeclineDecline, card acceptor contact acquirer
104DeclineDecline, restricted card
105DeclineDecline, card acceptor call acquirer's security department
106DeclineDecline, allowable PIN tries exceeded
107DeclineDecline, refer to card issuer
108DeclineDecline, refer to card issuer's special conditions
109DeclineDecline, invalid merchant
110DeclineDecline, invalid amount
111DeclineDecline, invalid card number
112DeclineDecline, PIN data required
113DeclineDecline, unacceptable fee
114DeclineDecline, no account of type requested
115DeclineDecline, requested function not supported
116Decline, no fundsDecline, not sufficient funds
117DeclineDecline, incorrect PIN
118DeclineDecline, no card record
119DeclineDecline, transaction not permitted to cardholder
120DeclineDecline, transaction not permitted to terminal
121DeclineDecline, exceeds withdrawal amount limit
122DeclineDecline, security violation
123DeclineDecline, exceeds withdrawal frequency limit
124DeclineDecline, violation of law
125DeclineDecline, card not effective
126DeclineDecline, invalid PIN block
127DeclineDecline, PIN length error
128DeclineDecline, PIN kay synch error
129DeclineDecline, suspected counterfeit card
180DeclineDecline, by cardholders wish
200Pick-upPick-up (general, no comments)
201Pick-upPick-up, expired card
202Pick-upPick-up, suspected fraud
203Pick-upPick-up, card acceptor contact card acquirer
204Pick-upPick-up, restricted card
205Pick-upPick-up, card acceptor call acquirer's security department
206Pick-upPick-up, allowable PIN tries exceeded
207Pick-upPick-up, special conditions
208Pick-upPick-up, lost card
209Pick-upPick-up, stolen card
210Pick-upPick-up, suspected counterfeit card
300Call acquirerStatus message: file action successful
301Call acquirerStatus message: file action not supported by receiver
302Call acquirerStatus message: unable to locate record on file
303Call acquirerStatus message: duplicate record, old record replaced
304Call acquirerStatus message: file record field edit error
305Call acquirerStatus message: file locked out
306Call acquirerStatus message: file action not successful
307Call acquirerStatus message: file data format error
308Call acquirerStatus message: duplicate record, new record rejected
309Call acquirerStatus message: unknown file
400AcceptedAccepted (for reversal)
499ApprovedApproved, no original message data
500Call acquirerStatus message: reconciled, in balance
501Call acquirerStatus message: reconciled, out of balance
502Call acquirerStatus message: amount not reconciled, totals provided
503Call acquirerStatus message: totals for reconciliation not available
504Call acquirerStatus message: not reconciled, totals provided
600AcceptedAccepted (for administrative info)
601Call acquirerStatus message: impossible to trace back original transaction
602Call acquirerStatus message: invalid transaction reference number
603Call acquirerStatus message: reference number/PAN incompatible
604Call acquirerStatus message: POS photograph is not available
605Call acquirerStatus message: requested item supplied
606Call acquirerStatus message: request cannot be fulfilled - required documentation is not available
680List readyList ready
681List not readyList not ready
700AcceptedAccepted (for fee collection)
800AcceptedAccepted (for network management)
900AcceptedAdvice acknowledged, no financial liability accepted
901AcceptedAdvice acknowledged, finansial liability accepted
902Call acquirerDecline reason message: invalid transaction
903Call acquirerStatus message: re-enter transaction
904Call acquirerDecline reason message: format error
905Call acquirerDecline reason message: acqiurer not supported by switch
906Call acquirerDecline reason message: cutover in process
907Call acquirerDecline reason message: card issuer or switch inoperative
908Call acquirerDecline reason message: transaction destination cannot be found for routing
909Call acquirerDecline reason message: system malfunction
910Call acquirerDecline reason message: card issuer signed off
911Call acquirerDecline reason message: card issuer timed out
912Call acquirerDecline reason message: card issuer unavailable
913Call acquirerDecline reason message: duplicate transmission
914Call acquirerDecline reason message: not able to trace back to original transaction
915Call acquirerDecline reason message: reconciliation cutover or checkpoint error
916Call acquirerDecline reason message: MAC incorrect
917Call acquirerDecline reason message: MAC key sync error
918Call acquirerDecline reason message: no communication keys available for use
919Call acquirerDecline reason message: encryption key sync error
920Call acquirerDecline reason message: security software/hardware error - try again
921Call acquirerDecline reason message: security software/hardware error - no action
922Call acquirerDecline reason message: message number out of sequence
923Call acquirerStatus message: request in progress
950Not acceptedDecline reason message: violation of business arrangement
XXXUndefinedCode to be replaced by card status code or stoplist insertion reason code

Credits