Fix GET /methods request

This commit is contained in:
Djery-Tom 2022-10-09 01:00:12 +01:00
parent d0e69790b3
commit 6540a42d0d
4 changed files with 59 additions and 11 deletions

View File

@ -49,7 +49,7 @@ class CinetpayController extends Controller
*/ */
public function getMethods() public function getMethods()
{ {
return $this->successResponse(['ALL', 'MOBILE_MONEY','CREDIT_CARD','WALLET']); return $this->successResponse(['ALL', 'MOBILE_MONEY','CREDIT_CARD']);
} }
// //

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Models\PaymentAggregator; use App\Models\PaymentAggregator;
use GuzzleHttp\Client;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
@ -10,19 +11,30 @@ class PaymentController extends Controller
{ {
public function getMethods(Request $request) public function getMethods(Request $request)
{ {
$this->validate($request, [ $aggregator = PaymentAggregator::where('status', 1)->first();
'aggregator_id' => 'required|integer|exists:payment_aggregators,id', if (!$aggregator) {
]); return $this->errorResponse(trans('errors.model_not_found', ['model' => 'methods']));
}
$aggregator = PaymentAggregator::findOrFail($request->input('aggregator_id')); Log::info($aggregator->name);
switch (strtolower($aggregator->name)) { switch (strtolower($aggregator->name)) {
case 'yoomee': case 'yoomee':
return redirect()->route('yoomee.methods', $request->all()); $client = new Client([
'base_uri' => config('variables.yoomee_api_url'),
'timeout' => 60,
]);
$response = $client->get('operators');
return $this->successResponse(json_decode($response->getBody()->getContents()));
case 'yoomeev2': case 'yoomeev2':
return redirect()->route('yoomee.v2.methods', $request->all()); $client = new Client([
'base_uri' => config('variables.yoomee_api_v2_url'),
'timeout' => 60,
]);
$response = $client->get('providers/v1');
return $this->successResponse(json_decode($response->getBody()->getContents()));
case 'cinetpay': case 'cinetpay':
return redirect()->route('cinetpay.methods', $request->all()); return $this->successResponse(['ALL', 'MOBILE_MONEY', 'CREDIT_CARD']);
default: default:
return $this->errorResponse(__('errors.unexpected_error')); return $this->errorResponse(__('errors.unexpected_error'));
} }

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePaymentAggregatorsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('payment_aggregators', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email');
$table->string('address');
$table->string('phone');
$table->boolean('status')->default(0);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('payment_aggregators');
}
}

View File

@ -24,7 +24,7 @@ $router->group(['prefix' => '', 'middleware' => 'auth'], function () use ($route
/** /**
* Entry Endpoints * Entry Endpoints
*/ */
$router->post('methods','PaymentController@getMethods'); $router->get('methods','PaymentController@getMethods');
$router->post('pay','PaymentController@pay'); $router->post('pay','PaymentController@pay');