1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-16 08:02:40 +01:00
invoiceninja/app/Http/Requests/Payments/PaymentWebhookRequest.php

79 lines
1.7 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
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
*/
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\Libraries\MultiDB;
2020-06-27 15:53:12 +02:00
use App\Models\Company;
use App\Models\CompanyGateway;
use App\Models\Payment;
use App\Models\PaymentHash;
use App\Utils\Traits\MakesHash;
2020-06-27 15:53:12 +02:00
class PaymentWebhookRequest extends Request
2020-06-27 15:53:12 +02:00
{
use MakesHash;
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
*
* @return null|\App\Models\CompanyGateway
*/
2021-05-21 07:47:05 +02:00
public function getCompanyGateway()
{
MultiDB::findAndSetDbByCompanyKey($this->company_key);
return CompanyGateway::withTrashed()->find($this->decodePrimaryKey($this->company_gateway_id));
}
/**
* Resolve payment hash.
2020-12-07 14:56:23 +01:00
*
2020-12-16 15:25:42 +01:00
* @return null|\App\Models\PaymentHash
*/
2021-05-21 07:47:05 +02:00
public function getPaymentHash()
2020-06-27 15:53:12 +02:00
{
if ($this->query('hash')) {
MultiDB::findAndSetDbByCompanyKey($this->company_key);
return PaymentHash::where('hash', $this->query('hash'))->firstOrFail();
2020-06-27 17:39:28 +02:00
}
2021-05-21 07:47:05 +02:00
return false;
}
2020-06-27 17:39:28 +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
{
MultiDB::findAndSetDbByCompanyKey($this->company_key);
return Company::where('company_key', $this->company_key)->firstOrFail();
2020-06-27 15:53:12 +02:00
}
}