PHPackages                             njoguamos/laravel-jenga - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. njoguamos/laravel-jenga

ActiveLibrary[Payment Processing](/categories/payments)

njoguamos/laravel-jenga
=======================

A Laravel package for setting up and interacting with Jenga V3 API.

v2.0.4(5mo ago)985↓100%3MITPHPPHP ^8.2 | ^8.3 | 8.4CI passing

Since Feb 13Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/njoguamos/laravel-jenga)[ Packagist](https://packagist.org/packages/njoguamos/laravel-jenga)[ Docs](https://github.com/njoguamos/laravel-jenga)[ GitHub Sponsors](https://github.com/njoguamos)[ RSS](/packages/njoguamos-laravel-jenga/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (13)Versions (24)Used By (0)

[![Cover](art/cover.png)](art/cover.png)

Jenga API wrapper for Laravel 11+
=================================

[](#jenga-api-wrapper-for-laravel-11)

[![run-tests](https://github.com/njoguamos/laravel-jenga/actions/workflows/run-test.yml/badge.svg)](https://github.com/njoguamos/laravel-jenga/actions/workflows/run-test.yml)[![License](https://camo.githubusercontent.com/a64b0316c3dce28b163b8fbdd3747ccee4d88b3692ded275b8564ad2402143b5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6e6a6f6775616d6f732f6c61726176656c2d6a656e67612e737667)](https://github.com/njoguamos/laravel-jenga)[![Latest Stable Version](https://camo.githubusercontent.com/103a69d0ddc8abb95ee4b90b79db323737f8b33db7fbb08c8e962a83e28254f7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6a6f6775616d6f732f6c61726176656c2d6a656e67612e737667)](https://packagist.org/packages/njoguamos/laravel-jenga)[![Issues](https://camo.githubusercontent.com/d28bb5f4bf7810772d8d54e5779d5d1a56c140e7dd2bbadf154476516c7fabd8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6e6a6f6775616d6f732f6c61726176656c2d6a656e6761)](https://camo.githubusercontent.com/d28bb5f4bf7810772d8d54e5779d5d1a56c140e7dd2bbadf154476516c7fabd8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6e6a6f6775616d6f732f6c61726176656c2d6a656e6761)[![Total Downloads](https://camo.githubusercontent.com/6b107e39f4bbf0bf17f4ab835947dd779f66d2f0a03cc4a9b3aab9cd85888e7b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e6a6f6775616d6f732f6c61726176656c2d6a656e67612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/njoguamos/laravel-jenga)

1. Why use this package
-----------------------

[](#1-why-use-this-package)

1. To provide a way of generating jenga api `access_token` after a give period e.g every 15 minutes
2. To provide a fluent way of generating jenga api key pair of `private key` and `public key`
3. To automate generation of jenga api `Bearer Token`
4. Offer a seamless gateway to interacting with Jenga API

> **Info**Ready to get started? I have prepared a [playground which you can clone](https://github.com/njoguamos/laravel-jenga-playground) and get started. It will help you test your crendentials while showinf you how to integrate this package with your laravel application.

2. Documentation
----------------

[](#2-documentation)

### 2.1 Installation

[](#21-installation)

VersionSupported Laravel1.x9.x, 10.x, 11.x2.x11.x, 12.xUse the Composer package manager to install this package into your Laravel project

```
composer require njoguamos/laravel-jenga
```

### 2.2 Update your `.env` variables

[](#22-update-your-env-variables)

This package assumes that you have a JengaHQ account, and that you have `Api Key`, `Merchant Code` and `Consumer Secret` (from Jenga)().

Copy the respective keys and place them in the `.env` as show in the example below.

```
JENGA_LIVE_MODE=false
JENGA_MERCHANT_CODE=
JENGA_API_KEY=
JENGA_CONSUMER_SECRET=

# Optional
JENGA_DEFAULT_ACC=
JENGA_DEFAULT_WALLET=
JENGA_COUNTRY_CODE=
```

> **Note**For `JENGA_LIVE_MODE` use `false` when testing and `true` when running live transactions

### 2.3 Initialising the Package

[](#23-initialising-the-package)

You must run install command that will publish the `jenga.php` config file and `create_jenga_tokens` migration

```
php artisan jenga:install
```

> **Note**For security reasons, `access_token` and `refresh_token` will be encrypted using you `application key`. You can learn more about encryption from [Laravel documentation](https://laravel.com/docs/9.x/encryption)

You can go ahead and migrate the database.

```
php artisan migrate
```

### 2.4 Generating `Bearer Token`

[](#24-generating-bearer-token)

Once you have valid credentials, run the following command.

```
php artisan jenga:auth
```

This command will get an `access_token` token from Jenga API and add them into a new record on `jenga` table.

This command may fail:

- When you are not connected to the internet
- When `Api Key` or `Consumer Secret` or `Merchant` is/are invalid
- There is a problem with jenga api endpoint

### 2.5 Generate `Bearer Token` Frequently

[](#25-generate-bearer-token-frequently)

The generated `access_token` expires after a particular period usually after `one hour`. To generate a new `access_token` automatically, schedule the `jenga:auth` command in the console kernel. The schedule time should be less than 15 minutes.

```
// app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
    # ...
    $schedule->command(command: 'jenga:auth')->everyThirtyMinutes();
}
```

### 2.6 Clearing Expired Token

[](#26-clearing-expired-token)

To periodically deleted expired `Bearer Token`, schedule `model:prune` command in the console kernel.

```
// app/Console/Kernel.php

use NjoguAmos\Jenga\Models\JengaToken;

protected function schedule(Schedule $schedule)
{
    # ...
     $schedule->command(command: 'model:prune', parameters: [
        '--model' => [JengaToken::class],
    ])->everyFiveMinutes();
}
```

### 2.7 Generate Private and Public Keys

[](#27-generate-private-and-public-keys)

To generate a key pair of private and public key, run the following command.

```
php artisan jenga:keys
```

This command will create a `jenga.key` and `jenga.pub.key` file in your laravel application storage folder. You can customise the directory using `JENGA_KEYS_PATH` variable.

```
# ./yourapplication/storage/jenga.key

-----BEGIN PRIVATE KEY-----

-----END RSA PRIVATE KEY-----

```

```
# ./yourapplication/storage/jenga.pub.key

-----BEGIN PUBLIC KEY-----

-----END PUBLIC KEY-----

```

You may use `--force` flag to replace existing keys. The default key size is `4096`

> **Warning**The generated keys files **SHOULD NEVER** be kept in source control. Make sure you add them to you gitignore file.

> **Note**Extensions like `bcmath`, `gmp`, `libsodium` and `openssl` are required when generating they keys.

### 2.8 Ensure that you are subscribed to the API services

[](#28-ensure-that-you-are-subscribed-to-the-api-services)

If you attempt to access the API and you get `Not Authorized to access the API`, confirm that your account has subscribed to the respective service you are trying to access. You can do so by going to the JengaAPI Settings -&gt; Subscriptions, then `subscribe` or `unsubscribe`.

3. Usage
--------

[](#3-usage)

### 3.1 Generating signature

[](#31-generating-signature)

To generate a signature manually, call `getSignature` method in `JengaSignature` class using the data you want to sign.> **Info**The data is signed in the order it is passed.

```
use NjoguAmos\Jenga\JengaSignature;

$data = [
    "accountId"   => "0011547896523",
    "countryCode" => "KE",
    "date"        => "2022-01-01"
];

$signature = (new JengaSignature(data: $data))->getSignature();
// This will return signature for "0011547896523KE2022-01-01'
// "NCgbapJwPIt+203eyADfPSvPX6uWPPVwMbFdrW+3XoT7oQC2+IaS6srFIGGdMrwrTH ..."
```

### 3.2 Payment Gateway Checkout

[](#32-payment-gateway-checkout)

To use the payment gateway, prepare the data using the backend and pass to the browser form.```
