1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/PaymentDrivers/WePay/WePayCommon.php

76 lines
2.4 KiB
PHP
Raw Normal View History

2021-06-20 08:24:37 +02:00
<?php
/**
* 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)
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
{
if ($gateway_type == GatewayType::BANK_TRANSFER) {
2021-06-25 00:38:15 +02:00
$payment_type = PaymentType::ACH;
} else {
2021-06-25 00:38:15 +02:00
$payment_type = PaymentType::CREDIT_CARD_OTHER;
}
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);
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,
);
if ($return_payment) {
2021-08-30 05:20:29 +02:00
return $payment;
}
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);
}
}