Skip to content

Commit b97e532

Browse files
committed
Squash commits
1 parent 379e022 commit b97e532

14 files changed

+119
-49
lines changed

.github/workflows/run-tests.yml

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
php: [7.4, 8.0, 8.1, 8.2, 8.3]
12+
php: [7.4, "8.0", 8.1, 8.2, 8.3]
1313
laravel: ["7.*", 8.*', "9.*", "10.*", "11.*"]
1414
stability: [prefer-stable]
1515
include:
@@ -20,23 +20,40 @@ jobs:
2020
- laravel: 9.*
2121
testbench: 7.*
2222
- laravel: 8.*
23-
testbench: 6.*
23+
testbench: ^6.23
24+
carbon: ^2.63
2425
- laravel: 7.*
2526
testbench: 5.*
26-
# Skip laravel 7.* with php ^8.0
27+
carbon: ^2.63
2728
exclude:
2829
- php: 8.1
2930
laravel: 7.*
3031
- php: 8.2
3132
laravel: 7.*
3233
- php: 8.3
3334
laravel: 7.*
35+
- php: "8.0"
36+
laravel: 7.*
37+
- php: 8.1
38+
laravel: 8.*
39+
- php: 8.2
40+
laravel: 8.*
41+
- php: 8.3
42+
laravel: 8.*
43+
- php: 7.4
44+
laravel: 9.*
45+
- php: 7.4
46+
laravel: 10.*
47+
- php: "8.0"
48+
laravel: 10.*
3449
- php: 7.4
3550
laravel: 11.*
51+
- php: "8.0"
52+
laravel: 11.*
3653
- php: 8.1
3754
laravel: 11.*
3855

39-
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }}
56+
name: PHP${{ matrix.php }} - Laravel_${{ matrix.laravel }} - ${{ matrix.stability }}
4057

4158
services:
4259
mysql:
@@ -70,14 +87,23 @@ jobs:
7087
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
7188
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
7289
73-
- name: Install dependencies
90+
- name: Install Laravel 9+ dependencies
7491
run: |
7592
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
7693
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
94+
if: (matrix.laravel == '9.*' || matrix.laravel == '10.*' || matrix.laravel == '11.*') && matrix.php != ''
95+
96+
- name: Install Laravel 7/8 dependencies
97+
run: |
98+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" --no-interaction --no-update
99+
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
100+
if: matrix.laravel == '7.*' || matrix.laravel == '8.*' && matrix.php != ''
101+
77102
- name: Execute tests
78103
run: vendor/bin/pest
79104
env:
80105
DB_USERNAME: user
81106
DB_PASSWORD: secret
82107
DB_PORT: ${{ job.services.mysql.ports[3306] }}
83108
REDIS_PORT: 6379
109+
if: matrix.testbench != '' && matrix.php != ''

composer.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"php": "^7.4|^8.0",
3232
"ext-json": "*",
3333
"ext-openssl": "*",
34-
"guzzlehttp/guzzle": "^6.0|^7.0",
34+
"guzzlehttp/guzzle": "^7.3",
35+
"guzzlehttp/promises": "^2.0",
3536
"illuminate/contracts": "^7.0|^8.0|^9.0|^10.0|^11.0",
3637
"illuminate/support": "^7.0|8.0|^9.0|^10.0|^11.0",
3738
"spatie/laravel-package-tools": "^1.0"
@@ -45,7 +46,10 @@
4546
"autoload": {
4647
"psr-4": {
4748
"Ghostscypher\\Mpesa\\": "src/"
48-
}
49+
},
50+
"files": [
51+
"src/GuzzlePromisePolyfill.php"
52+
]
4953
},
5054
"autoload-dev": {
5155
"psr-4": {

composer.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

database/migrations/create_mpesa_callbacks_table.php.stub renamed to database/migrations/2024_08_01_000000_create_mpesa_callbacks_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
return new class extends Migration
88
{
99
public function up()
10-
{
10+
{
1111
// Stores mpesa callbacks in a table
1212
Schema::create('mpesa_callbacks', function (Blueprint $table) {
1313
$table->id();

database/migrations/create_mpesa_logs_table.php.stub renamed to database/migrations/2024_08_27_000000_create_mpesa_logs_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
return new class extends Migration
88
{
99
public function up()
10-
{
10+
{
1111
Schema::create('mpesa_logs', function (Blueprint $table) {
1212
$table->id();
1313
$table->string('app_id')->index(); // Hashed consumer_key + secret
1414
$table->string('x_reference_id')->unique(); // This is the unique reference id that is generated by the system and can be used to track the transaction
15-
15+
1616
// Before calling the endpoint
1717
$table->string('endpoint')->default('');
1818
$table->string('environment')->default('');

database/migrations/create_mpesa_tokens_table.php.stub renamed to database/migrations/2024_08_27_000000_create_mpesa_tokens_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
return new class extends Migration
88
{
99
public function up()
10-
{
10+
{
1111
Schema::create('mpesa_tokens', function (Blueprint $table) {
1212
$table->id();
1313
$table->string('app_id')->index(); // Hashed consumer_key + secret
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Ghostscypher\Mpesa\Commands;
4+
5+
use Illuminate\Console\Command;
6+
7+
class InstallMpesaPackageCommand extends Command
8+
{
9+
protected $signature = 'mpesa:install';
10+
11+
public function handle(): int
12+
{
13+
$this->info('Installing Mpesa package...');
14+
15+
$this->call('vendor:publish', [
16+
'--provider' => 'Ghostscypher\Mpesa\MpesaServiceProvider',
17+
'--tag' => 'controllers',
18+
]);
19+
20+
$this->call('vendor:publish', [
21+
'--provider' => 'Ghostscypher\Mpesa\MpesaServiceProvider',
22+
'--tag' => 'config',
23+
]);
24+
25+
$this->call('vendor:publish', [
26+
'--provider' => 'Ghostscypher\Mpesa\MpesaServiceProvider',
27+
'--tag' => 'migrations',
28+
]);
29+
30+
// Ask the user to run the migrations
31+
if ($this->confirm('Do you want to run the migrations now?')) {
32+
$this->call('migrate');
33+
}
34+
35+
$this->info('Mpesa package installed successfully!');
36+
37+
return 0;
38+
}
39+
}

src/Concerns/MpesaGlobalConfig.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,8 @@ public function __construct()
3030
// Update the HTTP client with the required headers
3131
protected function updateHttpClient(array $headers = [], array $options = []): PendingRequest
3232
{
33-
// Get the original headers
34-
$original_headers = $this->http_client->getOptions()['headers'] ?? [];
35-
3633
// Merge the headers
3734
$headers = array_merge(
38-
$original_headers,
3935
$headers,
4036
[
4137
// Add the request ID and timestamp, this is for tracking requests
@@ -44,12 +40,15 @@ protected function updateHttpClient(array $headers = [], array $options = []): P
4440
]
4541
);
4642

47-
// Update the headers
48-
$this->http_client->withHeaders($headers);
43+
// Merge data
44+
$options = array_merge(
45+
$options,
46+
[
47+
'headers' => $headers,
48+
]
49+
);
4950

50-
// Update the options
51-
$original_options = $this->http_client->getOptions();
52-
$this->http_client->withOptions(array_merge($original_options, $options));
51+
$this->http_client->withOptions($options);
5352

5453
return $this->http_client;
5554
}

src/GuzzlePromisePolyfill.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace GuzzleHttp\Promise;
4+
5+
require_once __DIR__.'/../vendor/autoload.php';
6+
7+
// Polyfill for GuzzleHttp\Promise\Create::promiseFor for Laravel 7
8+
if (! function_exists('\GuzzleHttp\Promise\promise_for')) {
9+
function promise_for($response)
10+
{
11+
return class_exists(\GuzzleHttp\Promise\Create::class)
12+
? \GuzzleHttp\Promise\Create::promiseFor($response)
13+
: \GuzzleHttp\Promise\promise_for($response);
14+
}
15+
}

src/Models/MpesaCallback.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
namespace Ghostscypher\Mpesa\Models;
44

55
use Ghostscypher\Mpesa\Concerns\UsesMpesaEnv;
6-
use Illuminate\Database\Eloquent\Factories\HasFactory;
76
use Illuminate\Database\Eloquent\Model;
87

98
class MpesaCallback extends Model
109
{
11-
use HasFactory;
1210
use UsesMpesaEnv;
1311

1412
protected $table = 'mpesa_callbacks';

0 commit comments

Comments
 (0)