Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/backend/app/Models/MpmPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class MpmPlugin extends BaseModelCentral {
public const AFRICAS_TALKING = 18;
public const VODACOM_MOBILE_MONEY = 19;
public const CHINT_METER = 20;
public const SAFARICOM_MOBILE_MONEY = 21;

protected $table = 'mpm_plugins';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use MPM\TenantResolver\ApiResolvers\AndroidGatewayCallbackApiResolver;
use MPM\TenantResolver\ApiResolvers\DataExportResolver;
use MPM\TenantResolver\ApiResolvers\DownloadingReportsResolver;
use MPM\TenantResolver\ApiResolvers\SafaricomMobileMoneyApiResolver;
use MPM\TenantResolver\ApiResolvers\SwiftaPaymentApiResolver;
use MPM\TenantResolver\ApiResolvers\TestApiResolver;
use MPM\TenantResolver\ApiResolvers\ViberMessagingApiResolver;
Expand All @@ -24,6 +25,7 @@ class ApiResolverMap {
public const DATA_EXPORTING_API = 'api/export';
public const AFRICAS_TALKING_API = 'api/africas-talking/callback';
public const VODACOM_MOBILE_MONEY = 'api/vodacom/';
public const SAFARICOM_MOBILE_MONEY = 'api/safaricom/';

public const RESOLVABLE_APIS = [
self::TEST_API,
Expand All @@ -35,6 +37,7 @@ class ApiResolverMap {
self::DATA_EXPORTING_API,
self::AFRICAS_TALKING_API,
self::VODACOM_MOBILE_MONEY,
self::SAFARICOM_MOBILE_MONEY,
];

private const API_RESOLVER = [
Expand All @@ -47,6 +50,7 @@ class ApiResolverMap {
self::DATA_EXPORTING_API => DataExportResolver::class,
self::AFRICAS_TALKING_API => AfricasTalkingApiResolver::class,
self::VODACOM_MOBILE_MONEY => VodacomMobileMoneyApiResolver::class,
self::SAFARICOM_MOBILE_MONEY => SafaricomMobileMoneyApiResolver::class,
];

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace MPM\TenantResolver\ApiResolvers;

use App\Exceptions\ValidationException;
use Illuminate\Http\Request;

class SafaricomMobileMoneyApiResolver implements ApiResolverInterface {
public function resolveCompanyId(Request $request): int {
/** @var \Tymon\JWTAuth\JWTGuard $guard */
$guard = auth('api');
$payload = $guard->check() ? $guard->payload() : null;

$companyId = $payload?->get('companyId');

if (!$companyId) {
throw new ValidationException('Failed to parse company identifier from the request');
}

return (int) $companyId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace MPM\Transaction\Provider;

use App\Models\Transaction\AgentTransaction;
use Inensus\SafaricomMobileMoney\Models\SafaricomTransaction;
use Inensus\SafaricomMobileMoney\Providers\SafaricomMobileMoneyTransactionProvider;
use Inensus\SwiftaPaymentProvider\Models\SwiftaTransaction;
use Inensus\SwiftaPaymentProvider\Providers\SwiftaTransactionProvider;
use Inensus\WavecomPaymentProvider\Models\WaveComTransaction;
Expand Down Expand Up @@ -36,6 +38,11 @@ public static function getTransaction($transactionProvider): ?ITransactionProvid
$baseTransaction = resolve(WaveComTransactionProvider::class);
$baseTransaction->init($transactionProvider);

return $baseTransaction;
} elseif ($transactionProvider instanceof SafaricomTransaction) {
$baseTransaction = resolve(SafaricomMobileMoneyTransactionProvider::class);
$baseTransaction->init($transactionProvider);

return $baseTransaction;
}

Expand Down
1 change: 1 addition & 0 deletions src/backend/bootstrap/providers.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
Inensus\VodacomMobileMoney\Providers\VodacomMobileMoneyServiceProvider::class,
Inensus\WaveMoneyPaymentProvider\Providers\WaveMoneyPaymentProviderServiceProvider::class,
Inensus\WavecomPaymentProvider\Providers\WavecomPaymentProviderServiceProvider::class,
Inensus\SafaricomMobileMoney\Providers\SafaricomMobileMoneyServiceProvider::class,
];
3 changes: 2 additions & 1 deletion src/backend/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
"Inensus\\AngazaSHS\\": "packages/inensus/angaza-shs/src",
"Inensus\\AfricasTalking\\": "packages/inensus/africas-talking/src",
"Inensus\\VodacomMobileMoney\\": "packages/inensus/vodacom-mobile-money/src",
"Inensus\\ChintMeter\\": "packages/inensus/chint-meter/src"
"Inensus\\ChintMeter\\": "packages/inensus/chint-meter/src",
"Inensus\\SafaricomMobileMoney\\": "packages/inensus/safaricom-mobile-money/src"
}
},
"autoload-dev": {
Expand Down
2 changes: 1 addition & 1 deletion src/backend/config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@
'key' => env('APP_KEY'),

'cipher' => 'AES-256-CBC',
];
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use App\Models\MpmPlugin;
use Carbon\Carbon;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class extends Migration {
public function up() {
DB::table('mpm_plugins')->insert([
[
'id' => MpmPlugin::SAFARICOM_MOBILE_MONEY,
'name' => 'SafaricomMobileMoney',
'description' => 'Safaricom M-PESA integration for MicroPowerManager.',
'tail_tag' => 'Safaricom M-PESA',
'installation_command' => 'safaricom-mobile-money:install',
'root_class' => 'SafaricomMobileMoney',
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
],
]);
}

public function down() {
DB::table('mpm_plugins')
->where('id', MpmPlugin::SAFARICOM_MOBILE_MONEY)
->delete();
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up() {
DB::table('protected_pages')->insert([
'name' => '/safaricom-mobile-money-overview',
'created_at' => now(),
'updated_at' => now(),
]);
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down() {
DB::table('protected_pages')
->where('name', '/safaricom-mobile-money-overview')
->delete();
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
public function up() {
Schema::connection('tenant')->create('safaricom_settings', function (Blueprint $table) {
$table->id();
$table->string('consumer_key');
$table->string('consumer_secret');
$table->string('passkey');
$table->string('shortcode');
$table->string('environment')->default('sandbox');
$table->string('validation_url')->nullable();
$table->string('confirmation_url')->nullable();
$table->string('timeout_url')->nullable();
$table->string('result_url')->nullable();
$table->timestamps();
});

Schema::connection('tenant')->create('safaricom_transactions', function (Blueprint $table) {
$table->id();
$table->string('reference_id')->unique();
$table->decimal('amount', 10, 2);
$table->string('phone_number');
$table->string('account_reference')->nullable();
$table->string('transaction_desc')->nullable();
$table->string('status');
$table->string('mpesa_receipt_number')->nullable();
$table->timestamp('transaction_date')->nullable();
$table->json('response_data')->nullable();
$table->timestamps();

$table->index('reference_id');
$table->index('status');
$table->index('phone_number');
});
}

public function down() {
Schema::connection('tenant')->dropIfExists('safaricom_transactions');
Schema::connection('tenant')->dropIfExists('safaricom_settings');
}
};
21 changes: 21 additions & 0 deletions src/backend/packages/inensus/safaricom-mobile-money/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Inensus

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
13 changes: 13 additions & 0 deletions src/backend/packages/inensus/safaricom-mobile-money/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Package-Development-Starter-Pack

Check failure on line 2 in src/backend/packages/inensus/safaricom-mobile-money/README.md

View workflow job for this annotation

GitHub Actions / Run markdownlint

Trailing spaces

src/backend/packages/inensus/safaricom-mobile-money/README.md:2:1 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md009.md
#### Starter pack for package development to MicroPowerManager.

Check failure on line 3 in src/backend/packages/inensus/safaricom-mobile-money/README.md

View workflow job for this annotation

GitHub Actions / Run markdownlint

Trailing punctuation in heading

src/backend/packages/inensus/safaricom-mobile-money/README.md:3:64 MD026/no-trailing-punctuation Trailing punctuation in heading [Punctuation: '.'] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md026.md

Check failure on line 3 in src/backend/packages/inensus/safaricom-mobile-money/README.md

View workflow job for this annotation

GitHub Actions / Run markdownlint

Headings must start at the beginning of the line

src/backend/packages/inensus/safaricom-mobile-money/README.md:3:1 MD023/heading-start-left Headings must start at the beginning of the line [Context: " #### Starter pack for package..."] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md023.md

Check failure on line 3 in src/backend/packages/inensus/safaricom-mobile-money/README.md

View workflow job for this annotation

GitHub Actions / Run markdownlint

Heading levels should only increment by one level at a time

src/backend/packages/inensus/safaricom-mobile-money/README.md:3 MD001/heading-increment Heading levels should only increment by one level at a time [Expected: h3; Actual: h4] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md001.md

- This repo has created by the MicroPowerManager development team for developers who will develop a new package for MicroPowerManager.

Check failure on line 5 in src/backend/packages/inensus/safaricom-mobile-money/README.md

View workflow job for this annotation

GitHub Actions / Run markdownlint

Unordered list indentation

src/backend/packages/inensus/safaricom-mobile-money/README.md:5:1 MD007/ul-indent Unordered list indentation [Expected: 0; Actual: 1] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md007.md
- The team suggests developers use this repo when they decide to develop new packages to MicroPowerManager.

Check failure on line 6 in src/backend/packages/inensus/safaricom-mobile-money/README.md

View workflow job for this annotation

GitHub Actions / Run markdownlint

Unordered list indentation

src/backend/packages/inensus/safaricom-mobile-money/README.md:6:1 MD007/ul-indent Unordered list indentation [Expected: 0; Actual: 1] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md007.md
- Developers should clone our `Core` project with this url `https://github.com/inensus/MPManager` first. After cloning and running the core project, They have to go into laravel container and navigate to mpmanager & run `php artisan micropowermanager:new-package {{package-name}}` command to clone `this repo` into packages folder in MicroPowerManager core project.

Check failure on line 7 in src/backend/packages/inensus/safaricom-mobile-money/README.md

View workflow job for this annotation

GitHub Actions / Run markdownlint

Unordered list indentation

src/backend/packages/inensus/safaricom-mobile-money/README.md:7:1 MD007/ul-indent Unordered list indentation [Expected: 0; Actual: 1] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md007.md
- After cloning Package-Development-Starter-Pack, developers can keep developing the package inside of core project.

Check failure on line 8 in src/backend/packages/inensus/safaricom-mobile-money/README.md

View workflow job for this annotation

GitHub Actions / Run markdownlint

Unordered list indentation

src/backend/packages/inensus/safaricom-mobile-money/README.md:8:1 MD007/ul-indent Unordered list indentation [Expected: 0; Actual: 1] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md007.md
- When the developing will have been finished they can upload their packages to `https://packagist.org/` for the other developers usage

Check failure on line 9 in src/backend/packages/inensus/safaricom-mobile-money/README.md

View workflow job for this annotation

GitHub Actions / Run markdownlint

Unordered list indentation

src/backend/packages/inensus/safaricom-mobile-money/README.md:9:1 MD007/ul-indent Unordered list indentation [Expected: 0; Actual: 1] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md007.md


Check failure on line 11 in src/backend/packages/inensus/safaricom-mobile-money/README.md

View workflow job for this annotation

GitHub Actions / Run markdownlint

Trailing spaces

src/backend/packages/inensus/safaricom-mobile-money/README.md:11:1 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md009.md


27 changes: 27 additions & 0 deletions src/backend/packages/inensus/safaricom-mobile-money/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "inensus/safaricom-mobile-money",
"description": "Package description",
"type": "package",
"require": {},
"license": "MIT",
"authors": [
{
"name": "author",
"email": "email",
"role": "role"
}
],
"minimum-stability": "dev",
"autoload": {
"psr-4": {
"Inensus\\SafaricomMobileMoney\\": "src"
}
},
"extra": {
"laravel": {
"providers": [
"Inensus\\SafaricomMobileMoney\\Providers\\ServiceProvider"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

return [
/*
|--------------------------------------------------------------------------
| Safaricom M-PESA API Configuration
|--------------------------------------------------------------------------
|
| This file contains the configuration settings for the Safaricom M-PESA API
| integration. These settings are used to authenticate and interact with
| the Safaricom M-PESA API.
|
*/

'api' => [
'base_url' => env('SAFARICOM_API_BASE_URL', 'https://sandbox.safaricom.co.ke'),
'consumer_key' => env('SAFARICOM_CONSUMER_KEY', ''),
'consumer_secret' => env('SAFARICOM_CONSUMER_SECRET', ''),
'passkey' => env('SAFARICOM_PASSKEY', ''),
'shortcode' => env('SAFARICOM_SHORTCODE', ''),
'env' => env('SAFARICOM_ENV', 'sandbox'), // sandbox or production
],

'webhook' => [
'validation_url' => env('SAFARICOM_VALIDATION_URL', ''),
'confirmation_url' => env('SAFARICOM_CONFIRMATION_URL', ''),
'timeout_url' => env('SAFARICOM_TIMEOUT_URL', ''),
'result_url' => env('SAFARICOM_RESULT_URL', ''),
],

'transaction' => [
'timeout' => env('SAFARICOM_TRANSACTION_TIMEOUT', 60), // in seconds
'max_amount' => env('SAFARICOM_MAX_AMOUNT', 150000), // in KES
'min_amount' => env('SAFARICOM_MIN_AMOUNT', 1), // in KES
],
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
public function up() {
if (!Schema::connection('tenant')->hasTable('safaricom_settings')) {
Schema::connection('tenant')->create('safaricom_settings', function (Blueprint $table) {
$table->id();
$table->string('consumer_key');
$table->string('consumer_secret');
$table->string('passkey');
$table->string('shortcode');
$table->string('environment')->default('sandbox');
$table->string('validation_url')->nullable();
$table->string('confirmation_url')->nullable();
$table->string('timeout_url')->nullable();
$table->string('result_url')->nullable();
$table->timestamps();
});
}

if (!Schema::connection('tenant')->hasTable('safaricom_transactions')) {
Schema::connection('tenant')->create('safaricom_transactions', function (Blueprint $table) {
$table->id();
$table->string('reference_id')->unique();
$table->decimal('amount', 10, 2);
$table->string('phone_number');
$table->string('account_reference')->nullable();
$table->string('transaction_desc')->nullable();
$table->string('status');
$table->string('mpesa_receipt_number')->nullable();
$table->timestamp('transaction_date')->nullable();
$table->json('response_data')->nullable();
$table->timestamps();

$table->index('reference_id');
$table->index('status');
$table->index('phone_number');
});
}
}

public function down() {
Schema::connection('tenant')->dropIfExists('safaricom_transactions');
Schema::connection('tenant')->dropIfExists('safaricom_settings');
}
};
Loading
Loading