Browse Source

Add payeer processing and config values

master
Immanuel Onyeka 3 years ago
parent
commit
f57518c59d
3 changed files with 49 additions and 5 deletions
  1. +35
    -4
      app/Http/Controllers/BillingController.php
  2. +6
    -0
      config/services.php
  3. +8
    -1
      routes/web.php

+ 35
- 4
app/Http/Controllers/BillingController.php View File

@@ -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 ];
}
}

+ 6
- 0
config/services.php View File

@@ -35,4 +35,10 @@ return [
'secret' => env('STRIPE_SECRET'),
],

'payeer' => [
'secret' => env('PAYEER_SECRET'),
'param_key' => env('PAYEER_PARAM_KEY'),
'id' => env('PAYEER_ID'),
],

];

+ 8
- 1
routes/web.php View File

@@ -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']);

Loading…
Cancel
Save