PAYONE-GmbH / magento-1

PAYONE Payment Extension for Magento 1
22 stars 41 forks source link

Custom Onepage-Checkout: ReferenceError: payment is not defined #191

Closed branb closed 5 years ago

branb commented 6 years ago

We've taken over an already running Magento 1.9.3.6 Shop, which has a custom onepage checkout solution. I'm still in the process of figuring out if the whole module is custom coded or just an adjustment of an existing module.

Right now, there seems to be no "payment" object in the DOM, which the payone module references at one point with this code:

<script type="text/javascript" src="https://secure.pay1.de/client-api/js/v1/payone_hosted_min.js"></script>
<script type="text/javascript">
    //<![CDATA[
    payone = new PAYONE.Service.CreditCardCheck(
            new PAYONE.Handler.CreditCardCheck.OnepageCheckout()
    );

    document.observe('dom:loaded', function () {
        payone.form = payment.form;
        payment.save = payment.save.wrap(
                function (origMethod) {
                    payone.exec(origMethod);
                }
        );
    });
    //]]>
</script>

which is found in the template file app/design/frontend/base/default/template/payone/core/checkout/onepage/init.phtml

Obviously, this expects a payment object to exist already, but this is not the case in our checkout module. Do you or anyone else reading this have any experience with that case?

We are offering other payments on checkout, e.g. BillPay, Bank Transfer, PayPal etc., and these don't seem to depend on the payment object to exist.

fjbender commented 6 years ago

In a stock Magento, I found this object to be created in opcheckout.js:

image

Our plugin needs to know when the customer has clicked the "Continue" button of some sort to start tokenization of the credit card, for instance.

Maybe you can work around that and trigger payone.exec somewhere else?

branb commented 6 years ago

Thanks for your reply.

Ok, that sounds doable.

Can you give me a simple outline of what the payone object needs to do it's job?

How do I tell it where the data from the form (input fields, there is no real form...) is located and how does it map / read the input fields?

Is payone.exec all that needs to be executed? How do I check if it succeeded?

As far as I've understood it, I'd have to do:

  1. somehow tell it where the form data is to be found
  2. trigger payone.exec and check for success / failure
  3. then continue with whatever the checkout process wants to do
fjbender commented 6 years ago

From what I see (I'm no JS expert), payone.exec handles everything, provided the environment is as it expects it to be (which might be the tricky part). It collects the credit card data from the iFrames and writes the token back.

Following https://github.com/PAYONE-GmbH/magento-1/blob/master/js/payone/core/creditcard.js#L40 we, however, somewhat rely on payment.save() from the classic one page checkout, so I'm not entirely sure what else is needed to emulate this environment.

branb commented 6 years ago

Allright. Thx so far, I'll give it a try