1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00
invoiceninja/app/Http/Requests/CreateOnlinePaymentRequest.php

55 lines
1.3 KiB
PHP
Raw Normal View History

2017-01-30 20:40:43 +01:00
<?php
namespace App\Http\Requests;
2016-06-20 16:14:43 +02:00
use App\Models\Invitation;
2017-11-27 15:50:06 +01:00
use App\Models\GatewayType;
2016-06-20 16:14:43 +02:00
class CreateOnlinePaymentRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$account = $this->invitation->account;
$paymentDriver = $account->paymentDriver($this->invitation, $this->gateway_type);
2017-11-27 15:50:06 +01:00
2016-06-20 16:14:43 +02:00
return $paymentDriver->rules();
}
public function sanitize()
{
$input = $this->all();
$invitation = Invitation::with('invoice.invoice_items', 'invoice.client.currency', 'invoice.client.account.currency', 'invoice.client.account.account_gateways.gateway')
->where('invitation_key', '=', $this->invitation_key)
->firstOrFail();
$input['invitation'] = $invitation;
2017-11-27 15:50:06 +01:00
if ($gatewayTypeAlias = request()->gateway_type) {
$input['gateway_type'] = GatewayType::getIdFromAlias($gatewayTypeAlias);
} else {
$input['gateway_type'] = session($invitation->id . 'gateway_type');
}
2016-06-20 16:14:43 +02:00
$this->replace($input);
return $this->all();
}
}