1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-05 18:52:44 +01:00
invoiceninja/app/Http/Requests/Payments/PaymentWebhookRequest.php

94 lines
2.0 KiB
PHP
Raw Normal View History

2020-06-27 15:53:12 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
2020-06-27 15:53:12 +02:00
namespace App\Http\Requests\Payments;
2020-11-25 15:19:52 +01:00
use App\Http\Requests\Request;
use App\Models\Client;
2020-06-27 15:53:12 +02:00
use App\Models\Company;
use App\Models\CompanyGateway;
use App\Models\Payment;
use App\Models\PaymentHash;
2020-06-27 15:53:12 +02:00
class PaymentWebhookRequest extends Request
2020-06-27 15:53:12 +02:00
{
public function authorize()
{
return true;
}
public function rules()
{
return [
//
];
}
/**
* Resolve company gateway.
2020-12-07 14:56:23 +01:00
*
* @param mixed $id
* @return null|\App\Models\CompanyGateway
*/
public function getCompanyGateway(): ?CompanyGateway
{
return CompanyGateway::where('gateway_key', $this->gateway_key)->firstOrFail();
}
/**
* Resolve payment hash.
2020-12-07 14:56:23 +01:00
*
* @param string $hash
* @return null|\App\Http\Requests\Payments\PaymentHash
*/
public function getPaymentHash(): ?PaymentHash
2020-06-27 15:53:12 +02:00
{
if ($this->query('hash')) {
return PaymentHash::where('hash', $this->query('hash'))->firstOrFail();
2020-06-27 17:39:28 +02:00
}
}
2020-06-27 17:39:28 +02:00
/**
* Resolve possible payment in the request.
2020-12-07 14:56:23 +01:00
*
* @return null|\App\Models\Payment
*/
public function getPayment(): ?Payment
{
$hash = $this->getPaymentHash();
return $hash->payment;
2020-06-27 15:53:12 +02:00
}
/**
* Resolve client from payment hash.
2020-12-07 14:56:23 +01:00
*
* @return null|\App\Models\Client
*/
public function getClient(): ?Client
2020-06-27 15:53:12 +02:00
{
$hash = $this->getPaymentHash();
2020-06-27 17:39:28 +02:00
return Client::find($hash->data->client_id)->firstOrFail();
}
2020-06-27 15:53:12 +02:00
/**
* Resolve company from company_key parameter.
2020-12-07 14:56:23 +01:00
*
* @return null|\App\Models\Company
*/
public function getCompany(): ?Company
{
return Company::where('company_key', $this->company_key)->firstOrFail();
2020-06-27 15:53:12 +02:00
}
}