HEX
Server: LiteSpeed
System: Linux s917.lon1.mysecurecloudhost.com 4.18.0-477.21.1.lve.1.el8.x86_64 #1 SMP Tue Sep 5 23:08:35 UTC 2023 x86_64
User: assibfaf (3034)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: /home/assibfaf/assignmentghostwriter.com/prox-checkout.php
<?php
/**
 * @package    Proxim
 * @author     Davison Pro <davisonpro.coder@gmail.com | https://davisonpro.dev>
 * @copyright  2019 Proxim
 * @version    1.0.0
 * @since      File available since Release 1.0.0
 */

require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'prox-bootstrap.php';

use Proxim\Configuration;
use Proxim\Tools;
use Proxim\Validate;
use Proxim\Site\Site;
use Proxim\Currency;
use Proxim\User\Customer;
use Proxim\Order\Order;
use Proxim\Module\Module;
use Proxim\Order\PayPalPayment;
use Proxim\Order\AdditionalService;
use Proxim\Util\ArrayUtils;
use Proxim\Util\DateUtils;
use Proxim\Presenter\Order\OrderPresenter;

$paymentMethod = Tools::getValue('paymentMethod');
$paymentNodeType = Tools::getValue('paymentNodeType');

if (!$paymentMethod || !$paymentNodeType) {
	$app->setTemplate('404');
	$app->display(); 
}

$app->registerStylesheet('checkout-css', '/static/css/checkout.css', ['media' => 'all']);
$app->setVars([
    'page' => [
        'title' => 'Checkout',
        'description' => ''
    ]
]);

$smarty = $app->container->smarty;

$options = array();

$paymentModule = Module::getInstanceByName($paymentMethod);
if(!Validate::isLoadedObject($paymentModule)) {
    $app->setTemplate('404');
    $app->display();
}

if(!$paymentModule->isActive()) {
    $app->setTemplate('404');
    $app->display();
}

$smarty->assign('payment_method', $paymentModule->name);

$app->unregisterStylesheet('components-css');
$app->unregisterStylesheet('app-css');
$app->unregisterJavascript('components-js');
$app->unregisterJavascript('app-js');

$idempotency_key = Tools::randomGen(10);

switch( $paymentNodeType ) {
    case 'order':
        $paymentNodeId = Tools::getValue('paymentNodeId');

        $order = new Order( (int) $paymentNodeId );
        if (!Validate::isLoadedObject($order)) {
            $app->setTemplate('404');
            $app->display();
        }

        $currency = $order->currency;

        $options['currency'] = array(
            'symbol' => $currency->symbol,
            'rate' => $currency->conversion_rate
        );

        $amount = ($order->total*$currency->conversion_rate);
        $redirectUri = $app->base_uri . '/dashboard/order/' . $order->id;
        $order_presenter = new OrderPresenter();

        $smarty->assign([
            'idempotency_key' => $idempotency_key,
            'title' => "Payment of " . formatPrice($order->total, $options),
            'currency' => $currency->iso_code,
            'amount' => toFixed($amount),
            'price_formatted' => formatPrice($order->total, $options),
            'order' => $order_presenter->present($order),
            'success_url' => $app->base_uri . '/payment/'.$paymentModule->name.'/success?handle=order&redirectUri=' . $redirectUri,
            'decline_url' => $app->base_uri . '/payment/'.$paymentModule->name.'/failed?handle=order&redirectUri=' . $redirectUri,
            'callback_url' => $app->base_uri . '/api/payment/'.$paymentModule->name.'/callback?handle=order'
        ]);

        if(!method_exists($paymentMethod, 'processOrderCheckout')) {
            $app->setTemplate('404');
            $app->display();
        }

        $output = $paymentModule->processOrderCheckout( $order, $currency );
        $smarty->assign('module_content', $output);
        $app->setTemplate('payment/payment.module');
        return $app->display();
        break;

    case 'paper':
        if(!Module::getInstanceByName('prepapers')) {
            $app->setTemplate('404');
            $app->display();
        }

        $paymentNodeId = Tools::getValue('paymentNodeId');

        $prepaper = new PrePaper( (int) $paymentNodeId );
        if (!Validate::isLoadedObject($prepaper)) {
            $app->setTemplate('404');
            $app->display();
        }

        $redirectUri = $app->base_uri . '/dashboard/paper/' . $prepaper->id;
        $prepaperPresenter = new PrePaperPresenter();

        $currency_id = Currency::getIdByIsoCode('USD');
        $currency = new Currency( (int) $currency_id );

        $smarty->assign([
            'idempotency_key' => $idempotency_key,
            'title' => "Payment of " . formatPrice($prepaper->price),
            'currency' => 'USD',
            'amount' => toFixed($prepaper->price),
            'price_formatted' => formatPrice($prepaper->price),
            'paper' => $prepaperPresenter->present($prepaper),
            'success_url' => $app->base_uri . '/payment/'.$paymentModule->name.'/success?handle=paper&redirectUri=' . $redirectUri,
            'decline_url' => $app->base_uri . '/payment/'.$paymentModule->name.'/failed?handle=paper&redirectUri=' . $redirectUri,
            'callback_url' => $app->base_uri . '/api/payment/'.$paymentModule->name.'/callback?handle=paper'
        ]);

        if(!method_exists($paymentMethod, 'processPaperCheckout')) {
            $app->setTemplate('404');
            $app->display();
        }

        $output = $paymentModule->processPaperCheckout( $prepaper, $currency );
        $smarty->assign('module_content', $output);
        $app->setTemplate('payment/payment.module');
        return $app->display();
        break;

    case 'add-payment':
        $paymentNodeId = Tools::getValue('paymentNodeId');

        $addPayment = new AdditionalService( (int) $paymentNodeId );
        if (!Validate::isLoadedObject($addPayment)) {
            $app->setTemplate('404');
            $app->display();
        }

        if ( $addPayment->is_paid ) {
            $app->redirect('/dashboard');
        }

        $order = new Order( (int) $addPayment->order_id );
        if (!Validate::isLoadedObject($order)) {
            $app->setTemplate('404');
            $app->display();
        }

        $currency = $order->currency;

        $options['currency'] = array(
            'symbol' => $currency->symbol,
            'rate' => $currency->conversion_rate
        );

        $amount = $addPayment->total*$currency->conversion_rate;
        $redirectUri = $app->base_uri . '/dashboard/order/' . $order->id;

        $smarty->assign([
            'idempotency_key' => $idempotency_key,
            'title' => "Additional Payment of " . formatPrice($addPayment->total, $options),
            'currency' => $currency->iso_code,
            'amount' => toFixed($amount),
            'price_formatted' => formatPrice($addPayment->total, $options),
            'add_payment' => (array) $addPayment,
            'success_url' => $app->base_uri . '/payment/'.$paymentModule->name.'/success?handle=add-payment&redirectUri=' . $redirectUri,
            'decline_url' => $app->base_uri . '/payment/'.$paymentModule->name.'/failed?handle=add-payment&redirectUri=' . $redirectUri,
            'callback_url' => $app->base_uri . '/api/payment/'.$paymentModule->name.'/callback?handle=add-payment',
        ]);

        if(!method_exists($paymentMethod, 'processAddPaymentCheckout')) {
            $app->setTemplate('404');
            $app->display();
        }

        $output = $paymentModule->processAddPaymentCheckout($addPayment, $currency);
        $smarty->assign('module_content', $output);
        $app->setTemplate('payment/payment.module');
        return $app->display();
        break;

    case 'wallet':
        $amount = Tools::getValue('paymentNodeId');

        if ( !$user->isLogged() ) {
            $app->redirect('/dashboard');
        }

        $defaultCurrency = Configuration::get('CURRENCY_DEFAULT');
        $currency = new Currency( (int) $defaultCurrency );
        if(!Validate::isLoadedObject($currency)) {
            $app->showError('ERROR', 'Default Currency not set');
        }

        $options['currency'] = array(
            'symbol' => $currency->symbol,
            'rate' => $currency->conversion_rate
        );

        $redirectUri = $app->base_uri . '/dashboard/wallet';

        $smarty->assign([
            'idempotency_key' => $idempotency_key,
            'title' => formatPrice($amount, $options) . " Wallet Deposit",
            'currency' => $currency->iso_code,
            'amount' => toFixed($amount),
            'price_formatted' => formatPrice($amount, $options),
            'success_url' => $app->base_uri . '/payment/'.$paymentModule->name.'/success?handle=wallet&redirectUri=' . $redirectUri,
            'decline_url' => $app->base_uri . '/payment/'.$paymentModule->name.'/failed?handle=wallet&redirectUri=' . $redirectUri,
            'callback_url' => $app->base_uri . '/api/payment/'.$paymentModule->name.'/callback?handle=wallet'
        ]);

        if(!method_exists($paymentMethod, 'processWalletCheckout')) {
            $app->setTemplate('404');
            $app->display();
        }

        $output = $paymentModule->processWalletCheckout($user->id, $amount, $currency);
        $smarty->assign('module_content', $output);
        $app->setTemplate('payment/payment.module');
        return $app->display();

        break;

    case 'tip':
        $orderId = Tools::getValue('paymentNodeId');
        $amount = Tools::getValue('amount');

        if ( !$user->isLogged() ) {
            $app->redirect('/dashboard');
        }

        $order = new Order( (int) $orderId );
        if(!Validate::isLoadedObject($order)) {
            $app->setTemplate('404');
            $app->display();
        }

        $defaultCurrency = Configuration::get('CURRENCY_DEFAULT');
        $currency = new Currency( (int) $defaultCurrency );
        if(!Validate::isLoadedObject($currency)) {
            $app->showError('ERROR', 'Default Currency not set');
        }

        $options['currency'] = array(
            'symbol' => $currency->symbol,
            'rate' => $currency->conversion_rate
        );

        $redirectUri = $app->base_uri . '/dashboard/order/' . $order->id;
        $order_presenter = new OrderPresenter();

        $smarty->assign([
            'idempotency_key' => $idempotency_key,
            'title' => formatPrice($amount, $options) . " Writer Tip",
            'order' => $order_presenter->present($order),
            'currency' => $currency->iso_code,
            'amount' => toFixed($amount),
            'price_formatted' => formatPrice($amount, $options),
            'success_url' => $app->base_uri . '/payment/'.$paymentModule->name.'/success?handle=tip&redirectUri=' . $redirectUri,
            'decline_url' => $app->base_uri . '/payment/'.$paymentModule->name.'/failed?handle=tip&redirectUri=' . $redirectUri,
            'callback_url' => $app->base_uri . '/api/payment/'.$paymentModule->name.'/callback?handle=tip'
        ]);

        if(!method_exists($paymentMethod, 'processTipCheckout')) {
            $app->setTemplate('404');
            $app->display();
        }

        $output = $paymentModule->processTipCheckout($order->id, $amount, $currency);

        $smarty->assign('module_content', $output);
        $app->setTemplate('payment/payment.module');
        return $app->display();

        break;

    default:
        $app->setTemplate('404');
        $app->display();
        break;
}