Skip to content

Instantly share code, notes, and snippets.

@snez
Last active June 30, 2021 18:35
Show Gist options
  • Save snez/ad9b91c0049f96f78fb6d409c396ba2c to your computer and use it in GitHub Desktop.
Save snez/ad9b91c0049f96f78fb6d409c396ba2c to your computer and use it in GitHub Desktop.
Stripe.js patch for Olegnax OneStepCheckout
diff --git a/js/olegnax_osc/osc_form.js b/js/olegnax_osc/osc_form.js
index 2030f11..e093e31 100644
--- a/js/olegnax_osc/osc_form.js
+++ b/js/olegnax_osc/osc_form.js
@@ -915,10 +915,22 @@ OnestepcheckoutForm.prototype = {
classThis.placeOrderButton.addClassName(classThis.disabledClassName);
classThis.placeOrderButton.disabled = true;
- new Ajax.Request(classThis.placeOrderUrl, {
- method: 'post',
- parameters: Form.serialize(classThis.form.form, true),
- onComplete: classThis.onComplete.bindAsEventListener(classThis)
+ createStripeToken(function(err)
+ {
+ if (err)
+ {
+ cryozonic.displayCardError(err);
+ classThis.turnOnPlaceOrderButton();
+ classThis.overlay.hide();
+ }
+ else
+ {
+ new Ajax.Request(classThis.placeOrderUrl, {
+ method: 'post',
+ parameters: Form.serialize(classThis.form.form, true),
+ onComplete: classThis.onComplete.bindAsEventListener(classThis)
+ });
+ }
});
}
});
@@ -1360,4 +1372,4 @@ OnestepcheckoutAddress.prototype = {
afterFinish: function(){ delete el.effect; complateFunctionFn(); }
});
}
-};
\ No newline at end of file
+};
@ishanchatterjee
Copy link

Hello, I am facing problem in OSC(olegnax) with stripe.
Can you please upload the exact modified osc_form.js? I do not understand the patch.diff

@LuizSantos22
Copy link

Hi there,
Where sould I apply this patch?
I have tried on js/olegnax_osc/osc_form.js but it did not work
Maybe I am applying it in a wrong way?

Regards

@snez
Copy link
Author

snez commented Jun 28, 2021

@LuizSantos22 this patch is outdated and cannot be used as-is. The idea is to first call the createStripeToken() method before submitting the order. If you send the example to Olegnax, they will be able to advise how to apply it to the latest version of their module.

@LuizSantos22
Copy link

LuizSantos22 commented Jun 28, 2021

@snex Hi there, how are you doing?
Olegnax does not provide support for M1 anymore.
I have the Olegnax OSC 1.0 and Stripe Official module here
I have noticed that your patch was intended to use with an old Stripe module made by Cryozonic, right?
Unfortunately it is deprecated by Stripe.

I'd thank you if you could take a look and see if it can be fixed
I really spent a lot of time to customize Olegnax OSC to Brazilian Market and I really
wanted to make it opensource to the community after all the tests.
It is one of a few modules that allows us to heavily customize its looks and easily disable
required fields with a simple click. Which by default, is a nightmare and is it something I was looking
for due to new privacy rules imposed by Google here in Brazil.

Here is the Google Drive link: https://drive.google.com/drive/folders/1Q2r_wO_06zE6yK60hWWgYJtc-rL4_NI4?usp=sharing
The link comes with Olegnax OSC 1.0 and Stripe latest module for M1
And yes, it is a incompability with the OSC as I have tested on Magento 1 (OpenMage 1.9.4.13) default checkout and it works fine.

I have installed it along with OpenMage 1.9.4.13 using PHP 7.3 which can be downloaded from here:
https://github.com/OpenMage/magento-lts/releases

If you or someone else here decide to take a look into it and need Stripe test keys, please let me know and I can provide mine.

@snez
Copy link
Author

snez commented Jun 28, 2021

It is better to just use an OSC module that is still actively supported. I think Amasty, Swisslabs and aheadWorks are still supporting their M1 OSC modules. These will also not need any integration work with the Stripe module.

@LuizSantos22
Copy link

LuizSantos22 commented Jun 28, 2021 via email

@snez
Copy link
Author

snez commented Jun 29, 2021

If you prefer to stay on Olegnax that is fine. The adjustment is really simple. Instead of submitting the order, you first call createStripeToken() which will tokenize the card details. When the tokenization is finished, you get into the callback method, where you just submit the order with new Ajax.Request(classThis.placeOrderUrl, {})

@LuizSantos22
Copy link

@snez
Would you mind telling me which files and where should I make theses changes? I am not an expert. Regards

@snez
Copy link
Author

snez commented Jun 30, 2021

js/olegnax_osc/osc_form.js b/js/olegnax_osc/osc_form.js line 920

@LuizSantos22
Copy link

Is there a way of making a "before" and "after"

At the original code on "js/olegnax_osc/osc_form.js" from lines 918 to 925 I have this code:

new Ajax.Request(classThis.placeOrderUrl, { method: 'post', parameters: Form.serialize(classThis.form.form, true), onComplete: classThis.onComplete.bindAsEventListener(classThis) }); } }); }

If I change to your lines it stays like this from lines 918 to 933:

`createStripeToken(function(err)

  •                        {
    
  •                            if (err)
    
  •                            {
    
  •                                cryozonic.displayCardError(err);
    
  •                                classThis.turnOnPlaceOrderButton();
    
  •                                classThis.overlay.hide();
    
  •                            }
    
  •                            else
    
  •                            {
    
  •                                new Ajax.Request(classThis.placeOrderUrl, {
    
  •                                    method: 'post',
    
  •                                    parameters: Form.serialize(classThis.form.form, true),
    
  •                                    onComplete: classThis.onComplete.bindAsEventListener(classThis)
    
  •                                });
    
  •                            }`
    

This will not work, because my module is Stripe's official module and your mod is made to
Cryozonic's module. I have tried to change "cryozonic.displayCardError(err);" to "stripe.displayCardError(err);"
but it did not work neither...

Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment