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
+};
@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