From f57518c59d4d9cdd6106e592176ed766c3547b7f Mon Sep 17 00:00:00 2001 From: Immanuel Onyeka Date: Sat, 19 Jun 2021 13:30:28 -0400 Subject: [PATCH] Add payeer processing and config values --- app/Http/Controllers/BillingController.php | 39 +++++++++++++++++++--- config/services.php | 6 ++++ routes/web.php | 9 ++++- 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/BillingController.php b/app/Http/Controllers/BillingController.php index 62e4ad0..56c2c55 100644 --- a/app/Http/Controllers/BillingController.php +++ b/app/Http/Controllers/BillingController.php @@ -23,9 +23,7 @@ class BillingController extends Controller $this->user = Auth::user(); } - //Expects an array 'packs' representing the amount of each multiple of credits. - //Should validate that all amounts are positive integers in a reasonable range - public function secret(Request $request) { + protected function attempt(Request $request) { $user = Auth::user(); $amount = $request->packs[ 'credits10' ]*1099 + $request->packs[ 'credits50' ]*5499 + $request->packs[ 'credits100' ]*10999 @@ -45,7 +43,15 @@ class BillingController extends Controller $transaction->charge = $amount; $transaction->status = 'processing'; $transaction->completed = false; - $total_credits = $transaction->credits + $transaction->credits_extra; + $transaction->save(); + return $transaction; + } + + //Expects an array 'packs' representing the amount of each multiple of credits. + //Should validate that all amounts are positive integers in a reasonable range + public function stripeSecret(Request $request) { + $user = Auth::user(); + $transaction = $this->attempt($request); $intent = PaymentIntent::create([ 'amount' => $amount, @@ -115,4 +121,29 @@ class BillingController extends Controller } return ($this->getCards()); } + + //Receives a request with a packs. It is an array of each type of credit + //amount to be bought + public function payeer(Request $request) { + $transaction = $this->attempt($request); + $shopid = config('services.payeer.id'); + $secret = config('services.payeer.secret'); + $param_key = config('services.payeer.param_key'); + $total = $transaction->credits + $transaction->credits_extra; + + $arHash = [$shopid, $transaction->id, $transaction->charge, 'USD', "You + will receive $total credits."]; + + $params = ['reference' => ['transaction_id' => $transaction->id]]; + $key = md5($param_key.$transaction->id); + $encodedParams = urlencode(base64_encode(openssl_encrypt( + json_encode($params), 'AES-256-CBC', $key, OPENSSL_RAW_DATA + ))); + $arHash[] = $encodedParams; + $arHash[] = $secret; + + $signature = strtoupper(hash('sha256', implode(':', $arHash))); + return [ 'signature' => $signature, 'params' => $encodedParams, 'shop' + => $shopid, 'transaction' => $transaction->id ]; + } } diff --git a/config/services.php b/config/services.php index cada514..d054620 100644 --- a/config/services.php +++ b/config/services.php @@ -35,4 +35,10 @@ return [ 'secret' => env('STRIPE_SECRET'), ], + 'payeer' => [ + 'secret' => env('PAYEER_SECRET'), + 'param_key' => env('PAYEER_PARAM_KEY'), + 'id' => env('PAYEER_ID'), + ], + ]; diff --git a/routes/web.php b/routes/web.php index 75d5403..cc30c70 100644 --- a/routes/web.php +++ b/routes/web.php @@ -110,7 +110,10 @@ Route::post('/panel/orders', [OrderController::class, 'newOrder'])->middleware([ 'auth', 'verified' ]); Route::post('/panel/secret', [BillingController::class, - 'secret'])->middleware([ 'auth', 'verified' ]); + 'stripeSecret'])->middleware([ 'auth', 'verified' ]); + +Route::post('/panel/payeer', [BillingController::class, + 'payeer'])->middleware([ 'auth', 'verified' ]); Route::get('/panel/cards', [BillingController::class, 'getCards'])->middleware([ 'auth', 'verified' ]); @@ -118,3 +121,7 @@ Route::get('/panel/cards', [BillingController::class, //Stripe webhooks Route::post('/hooks/charge', [BillingController::class, 'chargeEvent']); + +//Payeer handler function +Route::post('/hooks/payeer-transaction', + [BillingController::class, 'payeer']);