2020-06-27 15:53:12 +02:00
|
|
|
<?php
|
2020-12-07 14:49:30 +01:00
|
|
|
|
2020-10-22 08:46:02 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2022-04-27 05:20:41 +02:00
|
|
|
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-10-22 08:46:02 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-10-22 08:46:02 +02:00
|
|
|
*/
|
|
|
|
|
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;
|
2020-12-21 12:19:48 +01:00
|
|
|
use App\Libraries\MultiDB;
|
2020-12-07 14:49:30 +01:00
|
|
|
use App\Models\Client;
|
2020-06-27 15:53:12 +02:00
|
|
|
use App\Models\Company;
|
|
|
|
use App\Models\CompanyGateway;
|
2020-12-07 14:49:30 +01:00
|
|
|
use App\Models\Payment;
|
|
|
|
use App\Models\PaymentHash;
|
2020-12-16 13:47:10 +01:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2020-06-27 15:53:12 +02:00
|
|
|
|
2020-10-22 08:46:02 +02:00
|
|
|
class PaymentWebhookRequest extends Request
|
2020-06-27 15:53:12 +02:00
|
|
|
{
|
2020-12-16 13:47:10 +01:00
|
|
|
use MakesHash;
|
|
|
|
|
2020-06-27 15:53:12 +02:00
|
|
|
public function authorize()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function rules()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
//
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-12-07 14:49:30 +01:00
|
|
|
/**
|
|
|
|
* Resolve company gateway.
|
2020-12-07 14:56:23 +01:00
|
|
|
*
|
|
|
|
* @param mixed $id
|
|
|
|
* @return null|\App\Models\CompanyGateway
|
2020-12-07 14:49:30 +01:00
|
|
|
*/
|
2021-05-21 07:47:05 +02:00
|
|
|
public function getCompanyGateway()
|
2020-12-07 14:49:30 +01:00
|
|
|
{
|
2022-01-09 03:34:23 +01:00
|
|
|
MultiDB::findAndSetDbByCompanyKey($this->company_key);
|
|
|
|
|
2021-12-14 21:42:20 +01:00
|
|
|
return CompanyGateway::withTrashed()->findOrFail($this->decodePrimaryKey($this->company_gateway_id));
|
2020-12-07 14:49:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolve payment hash.
|
2020-12-07 14:56:23 +01:00
|
|
|
*
|
|
|
|
* @param string $hash
|
2020-12-16 15:25:42 +01:00
|
|
|
* @return null|\App\Models\PaymentHash
|
2020-12-07 14:49:30 +01:00
|
|
|
*/
|
2021-05-21 07:47:05 +02:00
|
|
|
public function getPaymentHash()
|
2020-06-27 15:53:12 +02:00
|
|
|
{
|
2020-12-07 14:49:30 +01:00
|
|
|
if ($this->query('hash')) {
|
2022-01-09 03:34:23 +01:00
|
|
|
|
|
|
|
MultiDB::findAndSetDbByCompanyKey($this->company_key);
|
|
|
|
|
2020-12-07 14:49:30 +01:00
|
|
|
return PaymentHash::where('hash', $this->query('hash'))->firstOrFail();
|
2020-06-27 17:39:28 +02:00
|
|
|
}
|
2020-12-16 13:47:10 +01:00
|
|
|
|
2021-05-21 07:47:05 +02:00
|
|
|
return false;
|
2020-12-07 14:49:30 +01:00
|
|
|
}
|
2020-06-27 17:39:28 +02:00
|
|
|
|
2020-12-07 14:49:30 +01:00
|
|
|
/**
|
|
|
|
* Resolve company from company_key parameter.
|
2020-12-07 14:56:23 +01:00
|
|
|
*
|
|
|
|
* @return null|\App\Models\Company
|
2020-12-07 14:49:30 +01:00
|
|
|
*/
|
|
|
|
public function getCompany(): ?Company
|
|
|
|
{
|
2022-01-09 03:34:23 +01:00
|
|
|
MultiDB::findAndSetDbByCompanyKey($this->company_key);
|
|
|
|
|
2020-12-07 14:49:30 +01:00
|
|
|
return Company::where('company_key', $this->company_key)->firstOrFail();
|
2020-06-27 15:53:12 +02:00
|
|
|
}
|
|
|
|
}
|