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