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j '  'P$a ( `D$Na L?u80e J,K˷NI'0eݷ(NI'؀ 2ipIIKp`:O'`ʤxB8Ѥx Ѥx $ $P6 :vRNb 'p,>NB 'P]-->P T+*^h& p '‰a ‰ (ĵt#u33;Nt̵'ޯ; [3W ~]0KH1q@8]O2]3*̧7# *p>us p _6]/}-4|t'|Smx= DoʾM×M_8!)6lq':l7!|4} '\ne t!=hnLn (~Dn\+‰_4k)0e@OhZ`F `.m1} 'vp{F`ON7Srx 'D˸nV`><;yMx!IS钦OM)Ե٥x 'DSD6bS8!" ODz#R >S8!7ّxEh0m$MIPHi$IvS8IN$I p$O8I,sk&I)$IN$Hi$I^Ah.p$MIN$IR8I·N "IF9Ah0m$MIN$IR8IN$I 3jIU;kO$ɳN$+ q.x* tEXtComment

Viewing File: /home/u456810272/domains/globalsoftech.org.in/public_html/crm2/modules/ideal/controllers/Ideal.php

<?php

use Stripe\Checkout\Session;
use Stripe\Exception\ApiErrorException;
use Stripe\Exception\SignatureVerificationException;
use Stripe\PaymentIntent;

/**
 * @property-read Ideal_gateway $ideal_gateway
 * @property-read Invoices_model $invoices_model
 * @property-read CI_Session $session
 */
class Ideal extends App_Controller
{
    public function make_payment($id, $hash)
    {
        check_invoice_restrictions($id, $hash);
        $this->load->model('invoices_model');
        $invoice = $this->invoices_model->get($id);
        load_client_language($invoice->clientid);


        $data['invoice'] = $invoice;
        $data['description'] = $this->ideal_gateway->getDescription($id);
        $data['total'] = $this->session->userdata('total_amount');
        $data['client_secret'] = $this->session->userdata('ideal_client_secret');
        if ($this->ideal_gateway->processingFees) {
            $data['attempt_amount'] = $this->session->userdata('attempt_amount');
            $data['attempt_fee'] = $this->session->userdata('attempt_fee');
        }

        if (!$data['client_secret']) {
            redirect(site_url("invoice/{$id}/{$hash}"));
        }
        echo $this->getHtml($data);
    }

    private function getHtml($data): string
    {
        ob_start();
        echo payment_gateway_head(); ?>
        <script src="https://js.stripe.com/v3/"></script>

        <body class="gateway-stripe-ideal">
        <div class="container">
            <div class="col-md-8 col-md-offset-2 mtop30">
                <div class="mbot30 text-center">
                    <?php echo payment_gateway_logo(); ?>
                </div>
                <div class="row">
                    <div class="panel_s">
                        <div class="panel-heading">
                            <h4 class="panel-title">
                                <?php echo _l('payment_for_invoice'); ?>
                                <a
                                        href="<?php echo site_url('invoice/' . $data['invoice']->id . '/' . $data['invoice']->hash); ?>">
                                    <?php echo e(format_invoice_number($data['invoice']->id)); ?>
                                </a>
                            </h4>
                        </div>
                        <div class="panel-body">
                            <?php if (isset($data['attempt_amount']) && isset($data['attempt_fee'])) { ?>
                                <div>
                                    <h5><?php echo _l('payment_attempt_amount') . ": " . e(app_format_money($data['attempt_amount'], $data['invoice']->currency_name)); ?></h5>
                                    <h5><?php echo _l('payment_attempt_fee') . ": " . e(app_format_money($data['attempt_fee'], $data['invoice']->currency_name)); ?></h5>
                                </div>
                            <?php } ?>
                        </div>
                        <div class="panel-footer">

                            <div id="checkout">
                                <!-- Checkout will insert the payment form here -->
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <script>
            // Initialize Stripe.js
            const stripe = Stripe('<?= $this->ideal_gateway->getPublishableKey() ?>');

            const initialize = async () => {
                const fetchClientSecret = () => '<?= $data['client_secret'] ?>';

                // Initialize Checkout
                const checkout = await stripe.initEmbeddedCheckout({
                    fetchClientSecret,
                });
                // Mount Checkout
                checkout.mount('#checkout');
            }
            try {
                initialize();
            } catch (e) {
                alert_float('warning', 'please try again');
                window.location.replace('<?= site_url('invoice/' . $data['invoice']->id . '/' . $data['invoice']->hash); ?>')
            }
        </script>
        </body>

        <?php
        echo payment_gateway_footer();
        $contents = ob_get_contents();
        ob_end_clean();
        return $contents;
    }

    public function callback($id, $hash)
    {
        $this->load->model('invoices_model');
        check_invoice_restrictions($id, $hash);

        $invoice = $this->invoices_model->get($id);
        load_client_language($invoice->clientid);
        $redirectURL = site_url('invoice/' . $id . '/' . $hash);

        $sessionId = $this->input->get('session_id');
        $this->session->unset_userdata(['total_amount', 'ideal_client_secret']);
        if ($sessionId === null || $sessionId === '') {
            redirect($redirectURL);
        }

        try {
            $session = $this->ideal_gateway->retrieveSession($sessionId);
            if ($session->status !== Session::STATUS_COMPLETE) {
                set_alert('danger', _l('ideal_payment_failure_message'));
                redirect($redirectURL);
            }

            if (total_rows('invoicepaymentrecords', ['transactionid' => $session->payment_intent]) !== 0) {
                redirect($redirectURL);
            }

            $metaData = $this->ideal_gateway->retrievePaymentIntent($session->payment_intent)->metadata->toArray();
            $success = $this->ideal_gateway->addPayment([
                'amount' => $session->amount_total / 100,
                'invoiceid' => $metaData['invoice_id'],
                'transactionid' => $session->payment_intent,
                'paymentmethod' => 'IDEAL',
                'payment_attempt_reference' => $metaData['attempt_reference'],
            ]);

            if ($success) {
                set_alert('success', _l('online_payment_recorded_success'));
            } else {
                set_alert('danger', _l('online_payment_recorded_success_fail_database'));
            }
            redirect($redirectURL);
        } catch (ApiErrorException $e) {
            set_alert('danger', _l('ideal_payment_failure_message'));
            redirect($redirectURL);
        }
    }

    public function create_webhook()
    {
        try {
            foreach ($this->ideal_gateway->getAllWebhookObjects() as $webhook) {
                if ($webhook->metadata?->identification_key === $this->ideal_gateway->getIdentificationKey()
                    || $webhook->url == $this->ideal_gateway->getWebhookEndPoint()
                ) {
                    $this->ideal_gateway->deleteWebhook($webhook);
                }
            }

            if ($this->input->get('recreate')) {
                update_option('ideal_module_stripe_webhook_id', '');
                update_option('ideal_module_stripe_webhook_signing_secret', '');
            }
        } catch (Exception $e) {
        }

        try {
            $this->ideal_gateway->createWebhook();
            set_alert('success', _l('webhook_created'));
        } catch (Exception $e) {
            $this->session->set_flashdata('stripe-webhook-failure', $e->getMessage());
        }

        redirect(admin_url('settings/?group=payment_gateways&tab=online_payments_Ideal_gateway_tab'));
    }

    /**
     * @throws ApiErrorException
     */
    public function enable_webhook(): void
    {
        if (staff_can('edit', 'settings')) {
            $this->ideal_gateway->enableCurrentWebhookEndpoint();
        }
        redirect(admin_url('settings/?group=payment_gateways&tab=online_payments_Ideal_gateway_tab'));
    }

    public function webhook(): void
    {
        $payload = @file_get_contents('php://input');
        try {
            $event = $this->ideal_gateway->validateAndReturnWebhookEvent($payload);
        } catch (UnexpectedValueException|SignatureVerificationException $e) {
            echo '⚠️  Webhook error while validating signature.';
            http_response_code(400);
            exit();
        }

        switch ($event->type) {
            case \Stripe\Event::TYPE_PAYMENT_INTENT_SUCCEEDED:
                /** @var PaymentIntent $paymentIntent */
                $paymentIntent = $event->data->object;
                if (total_rows('invoicepaymentrecords', ['transactionid' => $paymentIntent->id]) !== 0) {
                    http_response_code(200);
                    exit();
                }
                $this->ideal_gateway->addPayment([
                    'amount' => $paymentIntent->amount / 100,
                    'invoiceid' => $paymentIntent->metadata->invoice_id,
                    'transactionid' => $paymentIntent->id,
                    'paymentmethod' => 'IDEAL - ' . $paymentIntent->source,
                    'payment_attempt_reference' => $paymentIntent->metadata->attempt_reference,
                ]);
                http_response_code(200);
                exit();
            default:
                exit();
        }
    }
}
Back to Directory=ceiIENDB`