I have a shop set up and the payment mehod is always set as "1" in the javascript. I now have the requirement, that some users, based on a user property will not have to pay, so I need to by pass the payment provider screen or set the payment to account.
I am not sure where to do this? I have tried setting the price to zero in the "on orderline changed" but it still goes to paypal and wont let me past as the cost must be greater than zero!
I also tried changing the payment method in the event BeforePaymentFormGenerated but that didn't work either.
I don't want to do and if/else in the javascript based on a page property because someone my twig this and try changing it somehow.
What is the best way of doing what I am trying to accomplish?
In addition to the explanation in the other post: You would have to throw the error in the BeforePaymentFormGenerated event and then catch it in your javascript.
Sorry I completely missed that post! Was thinking bypassing rather than zero orders so didnt notice it!
Would that not also be obvious in JS and a security risk if it's still the javascript handling the changing of the payment provider? I need the order to finalize and go through the rest of the process as the other event's on the order need to still happen.
Jeps. And as the security check you hook into BeforePaymentFormGenerated and throw an error if your conditions are not met. That will only happen if people are trying to cheat anyways. But your error will make sure that no form is returned and that the user cannot go to payment.
You could then catch the error in the javascript and either do nothing OR change the payment method and then go to payment again.
My initial thought was to to add Logic at the payment stage, so as a step in the payment process , most likely in the BeforePaymentFormGenerated , to intercept and use that to bypass the payment, or set the payment values.
That way we aren't doing to much in the javascript which is more vulnerable.
We haven't got to the integration point yet so let you know when we start banging our head against the wall
There should be an option to get an error callback. I have changed that in the javascript, which will be available in the next release. I any of you guys want the javascript file now just write me at [email protected] and I will mail it back to you.
Simple just added a settings object in which you can add your own errorfn, which will be called if the server throws an error.
Will sticking a try catch round it for now work? I am running 1.4.1.1 so rather an old version (just realised) and there have been quite a few changes since then and I don't want to have to upgrade this project at the moment if I don't really have to as its very customised and it may break it.
No a try catch won't do anything as the javascript will not fail. As to your 1.4.1.1 version, it won't be a problem, nothing big has changed in the javascript since the 1.4.0.0 version. So just backup your old javascript file and try out my new one.
Your second setup is the correct one. The below code works for me getting the "error" alert when destroying my WebshopEvents_BeforePaymentFormGenerated with a NotImplementedException.
Ok, I have replaced my js with your example so it's like this:
TeaCommerce.goToPayment({ errorfn: function () {
TeaCommerce.setPaymentMethod(3, false);
TeaCommerce.goToPayment();
}
});
This does call my WebshopEvents_BeforePaymentFormGenerated function and it throws the error and it catches it and then calls the gotopayment again after going:
TeaCommerce.setPaymentMethod(3, false);
TeaCommerce.goToPayment();
but then when it runs WebshopEvents_BeforePaymentFormGenerated again the paymentmethodId is still 1.
When I tried debugging it with break points it did change to 3 once, but I can't get it to do it again, it's kind of as if it's too quick for it?
Aah, sorry, did'nt see that. The setPaymentMethod takes an id and a settings object as parameters. Like this:
TeaCommerce.setPaymentMethod(3, {async:false});
That should do the trick! What happened before was that the setPaymentMethodcall was made asyncronously and thereby letting the gotToPayment being called at the same time.
by-pass payment for certain users
Hi
I have a shop set up and the payment mehod is always set as "1" in the javascript.
I now have the requirement, that some users, based on a user property will not have to pay, so I need to by pass the payment provider screen or set the payment to account.
I am not sure where to do this? I have tried setting the price to zero in the "on orderline changed" but it still goes to paypal and wont let me past as the cost must be greater than zero!
I also tried changing the payment method in the event BeforePaymentFormGenerated but that didn't work either.
I don't want to do and if/else in the javascript based on a page property because someone my twig this and try changing it somehow.
What is the best way of doing what I am trying to accomplish?
Becky
Hi Bex,
We actually just discussed this here:
http://our.umbraco.org/projects/website-utilities/tea-commerce/tea-commerce-support/33352-Items-with-zero-value
In addition to the explanation in the other post: You would have to throw the error in the BeforePaymentFormGenerated event and then catch it in your javascript.
/Rune
Thanks Rune
Sorry I completely missed that post! Was thinking bypassing rather than zero orders so didnt notice it!
Would that not also be obvious in JS and a security risk if it's still the javascript handling the changing of the payment provider?
I need the order to finalize and go through the rest of the process as the other event's on the order need to still happen.
Becky
Jeps. And as the security check you hook into BeforePaymentFormGenerated and throw an error if your conditions are not met. That will only happen if people are trying to cheat anyways. But your error will make sure that no form is returned and that the user cannot go to payment.
You could then catch the error in the javascript and either do nothing OR change the payment method and then go to payment again.
/Rune
My initial thought was to to add Logic at the payment stage, so as a step in the payment process , most likely in the BeforePaymentFormGenerated , to intercept and use that to bypass the payment, or set the payment values.
That way we aren't doing to much in the javascript which is more vulnerable.
We haven't got to the integration point yet so let you know when we start banging our head against the wall
Rune, probably my last question then is, how do I catch the error in my javascript?
The gotopayment doesn't seem to have an error return?
No, actually you are quite right. Good point.
There should be an option to get an error callback. I have changed that in the javascript, which will be available in the next release. I any of you guys want the javascript file now just write me at [email protected] and I will mail it back to you.
Simple just added a settings object in which you can add your own errorfn, which will be called if the server throws an error.
/Rune
Will sticking a try catch round it for now work? I am running 1.4.1.1 so rather an old version (just realised) and there have been quite a few changes since then and I don't want to have to upgrade this project at the moment if I don't really have to as its very customised and it may break it.
Bex
No a try catch won't do anything as the javascript will not fail. As to your 1.4.1.1 version, it won't be a problem, nothing big has changed in the javascript since the 1.4.0.0 version. So just backup your old javascript file and try out my new one.
/Rune
Thanks.. I have emailed you.
Hi Rune
I am just trying to catch the error with the new bit of code and am unsure if I am adding the error handling code correctly.
I have tried both this:
and
but neither work and I can't find an example of javascript setting objects so what should it be?
My event in c# is:
Hi Bex,
Your second setup is the correct one. The below code works for me getting the "error" alert when destroying my WebshopEvents_BeforePaymentFormGenerated with a NotImplementedException.
TeaCommerce.goToPayment({errorfn:function(){alert('error');}})
What kind of error/problem are you experiencing?
/Rune
Ok, I have replaced my js with your example so it's like this:
This does call my WebshopEvents_BeforePaymentFormGenerated function and it throws the error and it catches it and then calls the gotopayment again after going:
but then when it runs WebshopEvents_BeforePaymentFormGenerated again the paymentmethodId is still 1.
When I tried debugging it with break points it did change to 3 once, but I can't get it to do it again, it's kind of as if it's too quick for it?
Bex
Aah, sorry, did'nt see that. The setPaymentMethod takes an id and a settings object as parameters. Like this:
That should do the trick! What happened before was that the setPaymentMethodcall was made asyncronously and thereby letting the gotToPayment being called at the same time.
/Rune
Thanks. That works!
is working on a reply...