2021-06-20 08:24:37 +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-20 08:24:37 +02:00
|
|
|
*
|
2021-06-21 07:10:20 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2021-06-20 08:24:37 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\PaymentDrivers\WePay;
|
|
|
|
|
|
|
|
use App\Exceptions\PaymentFailed;
|
|
|
|
use App\Jobs\Util\SystemLogger;
|
2021-07-12 11:52:43 +02:00
|
|
|
use App\Models\GatewayType;
|
2021-06-20 08:24:37 +02:00
|
|
|
use App\Models\PaymentType;
|
|
|
|
use App\Models\SystemLog;
|
|
|
|
|
|
|
|
trait WePayCommon
|
|
|
|
{
|
2021-08-30 05:20:29 +02:00
|
|
|
private function processSuccessfulPayment($response, $payment_status, $gateway_type, $return_payment = false)
|
2021-06-20 08:24:37 +02:00
|
|
|
{
|
2022-06-21 11:57:17 +02:00
|
|
|
if ($gateway_type == GatewayType::BANK_TRANSFER) {
|
2021-06-25 00:38:15 +02:00
|
|
|
$payment_type = PaymentType::ACH;
|
2022-06-21 11:57:17 +02:00
|
|
|
} else {
|
2021-06-25 00:38:15 +02:00
|
|
|
$payment_type = PaymentType::CREDIT_CARD_OTHER;
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2021-06-25 00:38:15 +02:00
|
|
|
|
2021-06-20 08:24:37 +02:00
|
|
|
$data = [
|
2021-06-25 00:38:15 +02:00
|
|
|
'payment_type' => $payment_type,
|
2021-06-20 08:24:37 +02:00
|
|
|
'amount' => $response->amount,
|
|
|
|
'transaction_reference' => $response->checkout_id,
|
|
|
|
'gateway_type_id' => $gateway_type,
|
|
|
|
];
|
|
|
|
|
|
|
|
$payment = $this->wepay_payment_driver->createPayment($data, $payment_status);
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
SystemLogger::dispatch(
|
2021-06-20 08:24:37 +02:00
|
|
|
['response' => $this->wepay_payment_driver->payment_hash->data->server_response, 'data' => $data],
|
|
|
|
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
|
|
|
SystemLog::EVENT_GATEWAY_SUCCESS,
|
|
|
|
SystemLog::TYPE_WEPAY,
|
|
|
|
$this->wepay_payment_driver->client,
|
|
|
|
$this->wepay_payment_driver->client->company,
|
|
|
|
);
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if ($return_payment) {
|
2021-08-30 05:20:29 +02:00
|
|
|
return $payment;
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2021-08-30 05:20:29 +02:00
|
|
|
|
2021-06-20 08:24:37 +02:00
|
|
|
return redirect()->route('client.payments.show', ['payment' => $this->wepay_payment_driver->encodePrimaryKey($payment->id)]);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function processUnSuccessfulPayment($response, $payment_status)
|
|
|
|
{
|
2021-10-17 12:40:40 +02:00
|
|
|
$this->wepay_payment_driver->sendFailureMail($response->state);
|
2021-06-20 08:24:37 +02:00
|
|
|
|
|
|
|
$message = [
|
|
|
|
'server_response' => $response,
|
|
|
|
'data' => $this->wepay_payment_driver->payment_hash->data,
|
|
|
|
];
|
|
|
|
|
|
|
|
SystemLogger::dispatch(
|
|
|
|
$message,
|
|
|
|
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
|
|
|
SystemLog::EVENT_GATEWAY_FAILURE,
|
|
|
|
SystemLog::TYPE_WEPAY,
|
|
|
|
$this->wepay_payment_driver->client,
|
|
|
|
$this->wepay_payment_driver->client->company,
|
|
|
|
);
|
|
|
|
|
|
|
|
throw new PaymentFailed('Failed to process the payment.', 500);
|
|
|
|
}
|
|
|
|
}
|