Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The payment process will be switched from SPP to Modal format. #1

Open
BeycanDeveloper opened this issue May 7, 2024 · 0 comments
Open
Assignees
Labels
enhancement New feature or request

Comments

@BeycanDeveloper
Copy link
Member

The payment process will be switched from SPP to Modal format.

Sample code to help with this process.

class PaystckHandler {
    constructor($form, instance) {
        let formId = instance.settings.id;
        this.$form = $form;
        this.formInstance = instance;
        this.formId = formId;
    }

    init() {
        this.$form.on('fluentform_next_action_paystack', (event, data) => {
            const response = data.response;
            this.$form.parent().find('.ff_paystack_text').remove();

            jQuery('<div/>', {
                'id': 'form_success',
                'class': 'ff-message-success ff_paystck_text'
            })
                .html(response.data.message)
                .insertAfter(this.$form);

            if(response.data.actionName === 'initPaystackModal') {
                this.initPaystackModal(response.data);
            } else {
                alert('No method found');
            }
        });
    }

    initPaystackModal(res) {
        var that = this;
        const options = res.modal_data;
        options.callback = function (response) {
            that.formInstance.hideFormSubmissionProgress(that.$form);
            const data = {
                action: 'fluentform_paystack_confirm_payment',
                form_id: that.formId,
                ...response
            }

            that.$form.parent().find('.ff_paystck_text').remove();

            jQuery('<div/>', {
                'id': that.formId + '_success',
                'class': 'ff-message-success ff_msg_temp ff_razorpay_text'
            })
                .html(res.confirming_text)
                .insertAfter(that.$form);

            that.formInstance.showFormSubmissionProgress(that.$form);
            that.formInstance.sendData(that.$form, data);
        }

        options.onClose = function (error) {
            that.$form.parent().find('.ff_paystck_text').remove();
        }

        let handler = PaystackPop.setup(options);
        handler.openIframe();
    }
}

(function ($) {
    $.each($('form.fluentform_has_payment'), function () {
        const $form = $(this);
        $form.on('fluentform_init_single', function (event, instance) {
            (new PaystckHandler($form, instance)).init();
        });
    });
}(jQuery));
@BeycanDeveloper BeycanDeveloper self-assigned this May 7, 2024
@BeycanDeveloper BeycanDeveloper added the enhancement New feature or request label May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant