Skip to content

Commit 6706d8a

Browse files
committed
Refactor Vodacom Mobile Money package: clean up code, remove unused routes and files, and improve formatting
1 parent c030711 commit 6706d8a

File tree

12 files changed

+34
-292
lines changed

12 files changed

+34
-292
lines changed

src/backend/app/Http/Controllers/VodacomTransactionController.php

-140
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace App\Http\Controllers;
44

5-
use App\Http\Resources\VodacomResource;
65
use App\Models\Transaction\VodacomTransaction;
7-
use App\Services\VodacomService;
86
use Illuminate\Http\Request;
97

108
/**
@@ -13,8 +11,6 @@
1311
* API endpoints for integrating with Vodacom's M-Pesa payment services
1412
*/
1513
class VodacomTransactionController extends Controller {
16-
public function __construct(private VodacomService $vodacomService) {}
17-
1814
/**
1915
* Store a newly created resource in storage.
2016
*
@@ -41,140 +37,4 @@ public function store(Request $request): void {
4137
'message' => $transactionData->accountReference,
4238
]);
4339
}
44-
45-
/**
46-
* Validate Transaction.
47-
*
48-
* Validates a transaction before processing. Use this endpoint to verify if a transaction
49-
* can proceed based on the provided information. This is typically the first step in the payment flow.
50-
*
51-
* @bodyParam serialNumber string required Unique identifier for the product/service being purchased pattern: ^[A-Z0-9]{8,12}$ Example: ABC123456789
52-
* @bodyParam amount number required Transaction amount in the local currency Example: 15000
53-
* @bodyParam payerPhoneNumber string required Customer's phone number in international format pattern: ^258[0-9]{9}$ Example: 258712345678
54-
* @bodyParam referenceId string required Unique reference identifier for this transaction pattern: ^[A-Za-z0-9\-]{5,20}$ Example: ORD-12345-ABC
55-
*
56-
* @response scenario="Success" {
57-
* "data": {
58-
* "transactionId": "VOD-TXN-123456",
59-
* "status": "validated",
60-
* "details": {
61-
* "product": "Internet Bundle",
62-
* "validAmount": true
63-
* },
64-
* "success": true
65-
* }
66-
* }
67-
* @response 400 scenario="Validation Error" {
68-
* "data": {
69-
* "message": "Invalid amount specified for this product",
70-
* "success": false
71-
* }
72-
* }
73-
*
74-
* @param Request $request
75-
*
76-
* @return VodacomResource
77-
*/
78-
public function validateTransaction(Request $request): VodacomResource {
79-
$validatedData = $request->validate([
80-
'serialNumber' => 'required|string|regex:/^[A-Z0-9]{8,12}$/',
81-
'amount' => 'required|numeric|min:100|max:5000000',
82-
'payerPhoneNumber' => 'required|string|regex:/^258[0-9]{9}$/',
83-
'referenceId' => 'required|string|regex:/^[A-Za-z0-9\-]{5,20}$/',
84-
]);
85-
86-
try {
87-
$result = $this->vodacomService->validateTransaction($validatedData);
88-
89-
return VodacomResource::make($result);
90-
} catch (\Exception $e) {
91-
return VodacomResource::error($e->getMessage());
92-
}
93-
}
94-
95-
/**
96-
* Process Transaction.
97-
*
98-
* Processes a previously validated transaction. This endpoint should be called after successful
99-
* validation to initiate the payment process with Vodacom M-Pesa.
100-
*
101-
* @bodyParam referenceId string required The reference ID used during validation pattern: ^[A-Za-z0-9\-]{5,20}$ Example: ORD-12345-ABC
102-
* @bodyParam transactionId string required The transaction ID returned from the validation step pattern: ^VOD-TXN-[0-9]{6}$ Example: VOD-TXN-123456
103-
*
104-
* @response scenario="Success" {
105-
* "data": {
106-
* "transactionId": "VOD-TXN-123456",
107-
* "status": "processing",
108-
* "providerReference": "MPESA-TX-987654321",
109-
* "success": true
110-
* }
111-
* }
112-
* @response 400 scenario="Processing Error" {
113-
* "data": {
114-
* "message": "Transaction processing failed: Insufficient funds",
115-
* "success": false
116-
* }
117-
* }
118-
*
119-
* @param Request $request
120-
*
121-
* @return VodacomResource
122-
*/
123-
public function processTransaction(Request $request): VodacomResource {
124-
$validatedData = $request->validate([
125-
'referenceId' => 'required|string|regex:/^[A-Za-z0-9\-]{5,20}$/',
126-
'transactionId' => 'required|string|regex:/^VOD-TXN-[0-9]{6}$/',
127-
]);
128-
129-
try {
130-
$result = $this->vodacomService->processTransaction($validatedData);
131-
132-
return VodacomResource::make($result);
133-
} catch (\Exception $e) {
134-
return VodacomResource::error($e->getMessage());
135-
}
136-
}
137-
138-
/**
139-
* Check Transaction Status.
140-
*
141-
* Checks the current status of a transaction that has been submitted for processing.
142-
* Use this to verify if a payment has been completed, is still pending, or has failed.
143-
*
144-
* @bodyParam referenceId string required The reference ID of the transaction to check pattern: ^[A-Za-z0-9\-]{5,20}$ Example: ORD-12345-ABC
145-
*
146-
* @response scenario="Success" {
147-
* "data": {
148-
* "referenceId": "ORD-12345-ABC",
149-
* "transactionId": "VOD-TXN-123456",
150-
* "status": "completed",
151-
* "mpesaReceipt": "QCL4521XYZ",
152-
* "completedAt": "2023-06-15T12:45:32Z",
153-
* "success": true
154-
* }
155-
* }
156-
* @response 400 scenario="Enquiry Error" {
157-
* "data": {
158-
* "message": "Transaction not found or reference ID is invalid",
159-
* "success": false
160-
* }
161-
* }
162-
*
163-
* @param Request $request
164-
*
165-
* @return VodacomResource
166-
*/
167-
public function transactionEnquiryStatus(Request $request): VodacomResource {
168-
$validatedData = $request->validate([
169-
'referenceId' => 'required|string|regex:/^[A-Za-z0-9\-]{5,20}$/',
170-
]);
171-
172-
try {
173-
$result = $this->vodacomService->transactionEnquiryStatus($validatedData);
174-
175-
return VodacomResource::make($result);
176-
} catch (\Exception $e) {
177-
return VodacomResource::error($e->getMessage());
178-
}
179-
}
18040
}

src/backend/app/Http/Resources/VodacomResource.php

-39
This file was deleted.

src/backend/app/Services/VodacomService.php

-44
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
## Package-Development-Starter-Pack
2-
3-
#### Starter pack for package development to MicroPowerManager.
42

5-
- This repo has created by the MicroPowerManager development team for developers who will develop a new package for MicroPowerManager.
6-
- The team suggests developers use this repo when they decide to develop new packages to MicroPowerManager.
7-
- 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.
8-
- After cloning Package-Development-Starter-Pack, developers can keep developing the package inside of core project.
9-
- When the developing will have been finished they can upload their packages to `https://packagist.org/` for the other developers usage
10-
11-
3+
#### Starter pack for package development to MicroPowerManager
124

13-
5+
- This repo has created by the MicroPowerManager development team for developers who will develop a new package for MicroPowerManager.
6+
- The team suggests developers use this repo when they decide to develop new packages to MicroPowerManager.
7+
- 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.
8+
- After cloning Package-Development-Starter-Pack, developers can keep developing the package inside of core project.
9+
- When the developing will have been finished they can upload their packages to `https://packagist.org/` for the other developers usage
10+
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
22

33
return [
4-
5-
];
4+
];

src/backend/packages/inensus/vodacom-mobile-money/src/Models/VodacomMobileMoneyTransaction.php

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Inensus\VodacomMobileMoney\Models;
44

5-
65
use App\Models\Base\BaseModel;
76

87
class VodacomMobileMoneyTransaction extends BaseModel {

src/backend/packages/inensus/vodacom-mobile-money/src/Providers/EventServiceProvider.php

+3-8
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,16 @@
44

55
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
66

7-
class EventServiceProvider extends ServiceProvider
8-
{
7+
class EventServiceProvider extends ServiceProvider {
98
protected $subscribe = [
10-
119
];
1210

1311
/**
1412
* Register any events for your application.
1513
*
1614
* @return void
1715
*/
18-
public function boot()
19-
{
16+
public function boot() {
2017
parent::boot();
21-
22-
//
2318
}
24-
}
19+
}

src/backend/packages/inensus/vodacom-mobile-money/src/Providers/ObserverServiceProvider.php

+3-7
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@
44

55
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
66

7-
class ObserverServiceProvider extends ServiceProvider
8-
{
7+
class ObserverServiceProvider extends ServiceProvider {
98
/**
109
* Register any events for your application.
1110
*
1211
* @return void
1312
*/
14-
public function boot()
15-
{
13+
public function boot() {
1614
parent::boot();
17-
18-
1915
}
20-
}
16+
}

src/backend/packages/inensus/vodacom-mobile-money/src/Providers/RouteServiceProvider.php

+7-11
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,24 @@
22

33
namespace Inensus\VodacomMobileMoney\Providers;
44

5-
use Illuminate\Support\Facades\Route;
65
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
6+
use Illuminate\Support\Facades\Route;
77

8-
class RouteServiceProvider extends ServiceProvider
9-
{
8+
class RouteServiceProvider extends ServiceProvider {
109
protected $namespace = 'Inensus\VodacomMobileMoney\Http\Controllers';
1110

12-
public function boot()
13-
{
11+
public function boot() {
1412
parent::boot();
1513
}
1614

17-
public function map()
18-
{
15+
public function map() {
1916
$this->mapApiRoutes();
2017
}
2118

22-
protected function mapApiRoutes()
23-
{
19+
protected function mapApiRoutes() {
2420
Route::prefix('api')
2521
->middleware('api')
2622
->namespace($this->namespace)
27-
->group(__DIR__ . '/../routes/api.php');
23+
->group(__DIR__.'/../routes/api.php');
2824
}
29-
}
25+
}

src/backend/routes/api.php

-6
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,3 @@ static function () {
332332
Route::group(['prefix' => 'usage-types'], static function () {
333333
Route::get('/', 'UsageTypeController@index');
334334
});
335-
336-
Route::group(['prefix' => 'vodacom'], static function () {
337-
Route::post('/transactions/validation', 'VodacomTransactionController@validateTransaction');
338-
Route::post('/transactions/process', 'VodacomTransactionController@processTransaction');
339-
Route::post('/transactions/enquiry', 'VodacomTransactionController@transactionEnquiryStatus');
340-
});
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
2-
Vue.component('Component', require('./components/Component.vue'))
3-
window.packageNameEvent = new Vue()
1+
Vue.component("Component", require("./components/Component.vue"))
2+
window.packageNameEvent = new Vue()

0 commit comments

Comments
 (0)