Giter Club home page Giter Club logo

laravel-tigopesa-push's Introduction

Tigopesa (Tz) Push API - Laravel Package

Software License Travis Total Downloads

Install

composer require tumainimosha/laravel-tigopesa-push

Publish Configuration File

Publish config file to customize the default package config.

php artisan vendor:publish --provider="Tumainimosha\TigopesaPush\TigopesaPushServiceProvider" --tag="config"

Run migration

php artisan migrate

Configuration

Authentication

Configure your api parameters in .env file as follows. Substitute example values below with those provided to you at time of integration.

TZ_TIGOPESA_PUSH_USERNAME=<your-username>
TZ_TIGOPESA_PUSH_PASSWORD=<your-password>
TZ_TIGOPESA_PUSH_BILLER_MSISDN=<your-biller-msisdn> # Should start with country code 255 followed by 9 digits. eg: 25565000111
TZ_TIGOPESA_PUSH_GET_TOKEN_URL=<your-get-token-url>
TZ_TIGOPESA_PUSH_BILL_PAY_URL=<your-biller-pay-url>

Other configuration can be found in the config file published by this package. The options are well commented :)

Usage

Quick start

use Tumainimosha\TigopesaPush\TigopesaPush;

$customerMsisdn = '255652111222';
$amount = 1000;
$txnId = uniqid();

$tigopesaPushService = TigopesaPush::instance();
$response = $tigopesaPushService->postRequest($customerMsisdn, $amount, $txnId);

/** @var bool $success */
$success = $response['ResponseStatus'];

Handling callback

Out of the box, this package stores transactions in table tigopesa_push_transactions, and updates their status on receiving callback.

However, you may need to do further actions on your app after receiving callback, by listening to event TigopesaCallbackReceivedHandler::class fired at callback.

You need to implement your own event listener to listen for this event and do any additional steps after receiving callback.

The event has public attribute $transaction which contains the transaction parameters including status

// EventServiceProvider.php

protected $listen = [
    ...
    \Tumainimosha\TigopesaPush\Events\TigopesaCallbackReceived::class => [
        \App\Listeners\TigopesaCallbackReceivedHandler::class,
    ],
];

// TigopesaCallbackReceivedHandler.php

public function handle(TigopesaCallbackReceived $event)
{
    $transaction = $event->transaction;
    
    // do your custom logic here
}

Customize config values at runtime

The service offers fluent setters to change config values at runtime if your use case requires.

Such a use case could be when you have multiple accounts on the same project, and you fetch your config values from DB.

$tigopesaPushService = TigopesaPush::instance();

$tigopesaPushService->setUsername($account->username)
    ->setPassword($account->password)
    ->setBillerMsisdn($account->business_number)
    ->setTokenUrl(config('tigopesa-push.token_url'))
    ->setBillPayUrl(config('tigopesa-push.bill_pay_url'));

Testing

Run the tests with:

vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.

** Help needed with improving documentation and unit testing. Pull Requests are welcome.

Security

If you discover any security-related issues, please email instead of using the issue tracker.

License

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

laravel-tigopesa-push's People

Contributors

kea137 avatar tumainimosha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.