Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bex 444 posts 555 karma points
    Jul 23, 2012 @ 12:03
    Bex
    0

    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

     

     

  • Rune Grønkjær 1372 posts 3103 karma points
    Jul 23, 2012 @ 12:09
    Rune Grønkjær
    0

    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

  • Bex 444 posts 555 karma points
    Jul 23, 2012 @ 12:18
    Bex
    0

    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

     

  • Rune Grønkjær 1372 posts 3103 karma points
    Jul 23, 2012 @ 12:22
    Rune Grønkjær
    0

    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

  • Ravi Motha 290 posts 500 karma points MVP 8x c-trib
    Jul 23, 2012 @ 12:40
    Ravi Motha
    0

    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

  • Bex 444 posts 555 karma points
    Jul 23, 2012 @ 12:50
    Bex
    0

    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?

  • Rune Grønkjær 1372 posts 3103 karma points
    Jul 23, 2012 @ 13:02
    Rune Grønkjær
    0

    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

  • Bex 444 posts 555 karma points
    Jul 23, 2012 @ 13:08
    Bex
    0

    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

  • Rune Grønkjær 1372 posts 3103 karma points
    Jul 23, 2012 @ 13:12
    Rune Grønkjær
    0

    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

  • Bex 444 posts 555 karma points
    Jul 23, 2012 @ 13:16
    Bex
    0

    Thanks.. I have emailed you.

  • Bex 444 posts 555 karma points
    Jul 23, 2012 @ 14:26
    Bex
    0

    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:

      TeaCommerce.goToPayment(function (error) {
                TeaCommerce.setPaymentMethod(3, false);
                TeaCommerce.goToPayment();
            });

    and 

      var settings = {
                "errorfn": function(error) {
                    TeaCommerce.setPaymentMethod(3, false);
                    TeaCommerce.goToPayment();
                }
            };
            TeaCommerce.goToPayment(settings);

     but neither work and I can't find an example of javascript setting objects so what should it be?

    My event in c# is:

    void WebshopEvents_BeforePaymentFormGenerated(Order order, Dictionary<string, string> paymentProviderSettings, string paymentProviderAlias)
            {
                Member member = new Member((int)Membership.GetUser().ProviderUserKey);
                if (member.getProperty("freePurchase") != null)
                {
                    bool free = false;
                    if (member.getProperty("freePurchase").Value.ToString() != string.Empty)
                    {
                        free = member.getProperty("freePurchase").Value.ToString() == "1" ? true : false;
                    }
                    if (free)
                    {
                        if (order.PaymentMethodId != 3)
                            throw new Exception("cc exception -- payment method");
                    }
                }
    
            }
  • Rune Grønkjær 1372 posts 3103 karma points
    Jul 23, 2012 @ 14:47
    Rune Grønkjær
    0

    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

  • Bex 444 posts 555 karma points
    Jul 23, 2012 @ 15:04
    Bex
    0

    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?

    Bex

  • Rune Grønkjær 1372 posts 3103 karma points
    Jul 23, 2012 @ 15:41
    Rune Grønkjær
    0

    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.

    /Rune

     

  • Bex 444 posts 555 karma points
    Jul 23, 2012 @ 15:59
    Bex
    0

    Thanks. That works!

Please Sign in or register to post replies

Write your reply to:

Draft