Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/inventory.corals.io/Corals/modules/Payment/Cheque/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/inventory.corals.io/Corals/modules/Payment/Cheque/Gateway.php
<?php

namespace Corals\Modules\Payment\Cheque;


use Corals\Modules\Payment\Cheque\Exception\ChequeWebhookFailed;
use Corals\Modules\Payment\Cheque\Message\CreateChargeRequest;
use Corals\Modules\Payment\Common\AbstractGateway;
use Corals\Modules\Payment\Common\Models\WebhookCall;
use Corals\Modules\Payment\Payment;
use Corals\User\Models\User;
use Illuminate\Http\Request;

/**
 * Authorize.Net AIM Class
 */
class Gateway extends AbstractGateway
{
    public function getName()
    {
        return 'Cheque';
    }

    public function getDefaultParameters()
    {
        return array(
            'apiLoginId' => '',
            'transactionKey' => '',
            'clientKey' => '',
            'testMode' => false,
            'developerMode' => false,
            'hashSecret' => '',
            'signature' => '',
            'liveEndpoint' => 'https://api2.authorize.net',
            'developerEndpoint' => 'https://apitest.authorize.net',
        );
    }

    public function setAuthentication()
    {
        $cheque_info = \Settings::get('payment_cheque_cheque_notes');
        $this->setChequeNotes($cheque_info);
    }

    public function getPaymentViewName($type = null)
    {
        switch ($type) {
            case 'fields-only':
                return "Cheque::cheque-details-fields";
            default:
                return "Cheque::cheque-details";
        }
    }

    public function getChequeNotes()
    {
        return $this->getParameter('ChequeNotes');
    }

    public function setChequeNotes($value)
    {
        return $this->setParameter('ChequeNotes', $value);
    }

    function userRequirePayment(User $user)
    {
        return true;
    }

    public static function webhookHandler(Request $request)
    {
        try {
            $webhookCall = null;


            $eventPayload = $request->getContent();

            if (!static::validate($eventPayload, $request->header('X-Anet-Signature'))) {
                throw ChequeWebhookFailed::invalidSignature($request->header('X-Anet-Signature'));
            }

            $eventPayload = json_decode($eventPayload, true);

            $data = [
                'event_name' => 'cheque.' . $eventPayload['eventType'],
                'payload' => $eventPayload['payload'],
                'gateway' => 'Cheque'
            ];
            $webhookCall = WebhookCall::create($data);

            $webhookCall->process();
            die();
        } catch (\Exception $exception) {
            if ($webhookCall) {
                $webhookCall->saveException($exception);
            }
            log_exception($exception, 'Webhooks', 'cheque');
        }
    }


    public static function validate($payload, $AnetSignature)
    {
        $gateway = Payment::create('Cheque');
        $gateway->setAuthentication();
        $accepted_algos = array('sha512' => true);
        $parts = explode('=', $AnetSignature);
        $algorithm = $parts[0];
        if (empty($accepted_algos[$algorithm])) {
            return false;
        }
        $inSig = $parts[1];
        $vSig = strtoupper(hash_hmac($algorithm, $payload, $gateway->getSignature()));

        return hash_equals($inSig, $vSig);
    }

    public function renewSubscription($subscription)
    {
        return true;
    }

    public function prepareCreateChargeParameters($checkoutDetails)
    {
        return [
            'details' => $checkoutDetails
        ];
    }

    public function createCharge(array $parameters = array())
    {
        return $this->createRequest(CreateChargeRequest::class, $parameters);
    }

    public function paymentValidation(array $remaining_amount): array
    {
        $remaining_amount = data_get($remaining_amount, 'remaining_amount');
        $paid_amount_rule = ['required', 'numeric'];

        if (!is_null($remaining_amount)) {
            $paid_amount_rule[] = "max:$remaining_amount";
        }

        return [
            'payment_details.paid_amount' => $paid_amount_rule,
            'payment_details.bank_name' => 'required',
            'payment_details.cheque_date' => 'required',
            'payment_details.cheque_number' => 'required',
            'payment_details.cheque_owner' => 'required',
            'payment_details.cheque_name' => 'required',
            'payment_details.bank_account_number' => '',
        ];
    }
}

Spamworldpro Mini