Copied to clipboard

Flag this post as spam?

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


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Gary Elmes 2 posts 22 karma points
    Jan 06, 2012 @ 01:36
    Gary Elmes
    0

    Strange behaviour with XSLT RequestPayment(s) function calls

    Full disclosure: I'm a complete newbie at this. I've been on a steep learning curve, starting with zero knowledge, with XSLT, Umbraco, uCommerce, javascript, etc. over the last month, trying to put together a new website for a not-for-profit that I'm associated with.

    Which means that I'm probably making a Really Dumb Mistake(tm) somewhere. That said...

    I've got 99% of the way to where I want to be with implementing ecommerce on the website. All I need to do is integrate with Paypal for credit card orders.

    Based on my original cut of the code (which I've now reverted to), I made a call to CreatePayment() with requestPayment set to true() when the user selects their payment type. This seems to work fine for the "manual" payment methods that have service set to "(default)" and pipeline set to "none".

    The problem comes when I create a payment type with service set to "paypal". Of course, the hand-off to the paypal site happens as soon as the call to CreatePayment() is made, because of the requestPayment parameter being set to true(). I don't want this to happen, I want the user to see a confirmation page, complete with all the payment method related charges, before confirming and being taken off to paypal. So I changed the requestPayment parameter in the original CreatePayment() call to false() and added a RequestPayments() call in the XSLT macro that is invoked after the user finally confirms the order.

    And then things started to get weird.

    The invocation of RequestPayments() failed with the following error (from the umbraco log):

    Collection was modified; enumeration operation may not execute. Boolean MoveNext() at System.Collections.Generic.Dictionary`2.KeyCollection.Enumerator.MoveNext() at UCommerce.Xslt.TransactionLibrary.RequestPayments() at UCommerce.Xslt.Library.HandledCall[T](Func`1 method)

    If I look at the basket as returned by GetBasket() at this point, I see that a second payment node has been added - the same as the first but with a new paymentId and a later creation date.

    If I instead invoke RequestPayment(Id) for the specific payment node that I know is there, the function call completes OK, but it still creates a second payment node.

    Then, just to make things even more weird:

    If I change the "pipeline" value of a payment method to "checkout", then an invocation of RequestPayment() for that payment method fails with the following error:

    Cannot find template for e-mail type 'OrderConfirmation' and culture 'en-GB'. Make sure that a template is configured for e-mail type OrderConfirmation on profile Default. System.String Send(UCommerce.EntitiesV2.EmailProfile, System.String, System.Net.Mail.MailAddress, System.Collections.Generic.IDictionary`2[System.String,System.String]) at UCommerce.Transactions.EmailService.Send(EmailProfile profile, String emailTypeName, MailAddress to, IDictionary`2 templateParameters) at UCommerce.Pipelines.Common.SendEmailTask.Execute(PurchaseOrder purchaseOrder) at UCommerce.Pipelines.Pipeline`1.Execute(T subject)

    Some things to note about this error:

    - There is a properly configured template defined for OrderConfirmation on profile default.

    - The system uses only one country/culture - New Zealand, en-nz. There is no reference to en-GB anywhere.

    - The error occurs even if I try to kludge my way around it by changing the "culture" value of the country to en-GB.

    - A call to Checkout() works perfectly, sending the configured OrderConfirmation email.

    The uCommerce version is 2.1.0.0, which I believe is the most current. The Umbraco version is 4.7.1.

    Help!

    If it helps, the shop site is at http://test.pistolnz.org.nz/shop.aspx - it's not live, so don't expect to be sent any shirts if you order anything :-)

     

  • Søren Spelling Lund 1797 posts 2786 karma points
    Jan 09, 2012 @ 11:04
    Søren Spelling Lund
    0

    Hi Gary,

    It's probably the order, which is created with en-gb for its culture. When new baskets are created uCommerce will give them a locale based on the language Umbraco is currently using.

    If you don't have a language configure for the hostname Umbraco/ASP.NET will use the browser language. This is where the en-gb is coming from. If you modify your hostname to include en-nz it will work as expected.

    I'll test the Create/Request issue you mention.

     

  • Søren Spelling Lund 1797 posts 2786 karma points
    Jan 09, 2012 @ 11:21
    Søren Spelling Lund
    0

    Hi Gary,

    Just tried out the scenario locally, which worked fine. Then tried your site to see if I could recreate it, which, surprisingly, also worked: I get to the PayPal sandbox as expected.

    Could you provide me with the steps to repro?

    Thanks.

  • Gary Elmes 2 posts 22 karma points
    Jan 09, 2012 @ 23:29
    Gary Elmes
    0

    Hi,

    Thanks for looking into this for me, Søren. What's the weather like in Pipitea? ;-)

    Yes, I fixed (or maybe kludged) my site to work ok.

    I can see some orders in the uCommerce_PurchaseOrder table with CultureCode set to en-GB. These are from around the time I was implementing the paypal integration. Orders from before this time, though, were being set up correctly with a CultureCode of en-NZ. I'm guessing that there is something odd happening with the paypal integration, with the implementation of RequestPayment(), or with CreatePayment() when requestPayment is set to false().

    I think the issue came down to values in the umbracoLanguage table. I only have one country set up in uCommerce - New Zealand - which I defined with a Culture Code of en-NZ.I stumbled across the umbracoLanguage table and found that it had only one row in it, with a value of en-NZ in the languageISOCode field and a blank in the languageCultureName field. I changed the languageCultureName field to also have a value of en-NZ - which, as I say, may have fixed the problem (it didn't appear to straight away, but maybe that was because I was using a basket that had been defined with a CultureCode of en-GB before I made the change).

    I thought about going back and resetting the umbracoLanguage table to the way I found it, to see if the problem reappears, but I'm concerned that this may have unintended consequences.

    The other change I made was to replace the call to RequestPayment() in the XSLT script processing the order confirmation with a call to CreatePayment() - reapplying the existing payment and setting both requestPayment and overwriteExisting equal to true(). This seems to me to be more-or-less functionally equivalent to a call to RequestPayment(), except that it changes the paymentId (which I don't really care about) and - for me - it works.

    Maybe your code uses Culture from uCommerce_Country in some places and languageCultureName from umbracoLanguage in others?

    In any case, my site now works OK. Thanks again.

     

  • Søren Spelling Lund 1797 posts 2786 karma points
    Jan 16, 2012 @ 10:40
    Søren Spelling Lund
    0

    Wonderful.

    The locales stored with the country are never used for language purposes. We leave the selection of the proper language up to Umbraco and do indeed store that value on the order. The reason for this is that you might need to send e-mails after the order is placed in a different language from what the admin user is using, e.g. a Danish user looking at an order placed in the UK.

  • Christian Wendler 46 posts 155 karma points
    Feb 03, 2012 @ 17:55
    Christian Wendler
    0

    I have the same issue since updating an existing site to uCommerce 2.1. I don't use email confirmation, I am just getting the error:

    Collection was modified; enumeration operation may not execute. Boolean MoveNext() at System.Collections.Generic.Dictionary`2.KeyCollection.Enumerator.MoveNext() at UCommerce.Xslt.TransactionLibrary.RequestPayments() at UCommerce.Xslt.Library.HandledCall[T](Func`1 method)

    It happens when calling RequestPayments() in XSLT with default payment service (used for cash on delivery). No PayPal etc. involved.

    Have no clue what's going on.

    I can confirm that every purchaseOrder has two payment records in uCommerce_Payment, both are also displayed in backend.

  • Christian Wendler 46 posts 155 karma points
    Feb 03, 2012 @ 21:44
    Christian Wendler
    0

    If anyone else ran into this issue, this is my workaround:

           public static string RequestFirstPayment() {
    
                try {
                    if(!SiteContext.Current.OrderContext.HasBasket) {
                        return "No basket found";
                    }
    
                    var purchaseOrder = SiteContext.Current.OrderContext.GetBasket().PurchaseOrder;
                    Payment payment = purchaseOrder.Payments.First();
                    UCommerce.Xslt.TransactionLibrary.RequestPayment(payment.Id);
                    return "";
                }
                catch(Exception ex) {
                    return ex.Message;
                }
    
            }

    Put this into your xslt extension lib and replace RequestPayments() with RequestFirstPayment(). Did the trick for me, but I still wonder why there are two payments since updating to uCommerce 2.1, hmmm...

  • Søren Spelling Lund 1797 posts 2786 karma points
    Feb 08, 2012 @ 16:35
    Søren Spelling Lund
    0

    There's a fix included for this in uCommerce 2.5.

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Jul 25, 2012 @ 09:24
    Simon Dingley
    0

    FWIW I've just experienced similar issues in v2.6.1, the site had no hostnames added and so therefore as you mentioned takes the culture from my browser (en-GB) and as a result throws exceptions when attempting to send the order confirmation. The only way to get around it was to add a hostname to the root node with a culture of en-US. This is quite confusing and also not sure if it is necessary to kill the checkout process as a result of there being no hostname.

  • Søren Spelling Lund 1797 posts 2786 karma points
    Aug 07, 2012 @ 11:01
    Søren Spelling Lund
    0

    You could add en-GB as well. I'll look into what the actually error is and see if uCommerce can fallback gracefully to a supported language.

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Aug 07, 2012 @ 11:03
    Simon Dingley
    0

    I don't think that adding en-GB is really a solution because whilst it might work for me it wouldn't for you if your browser is using another cutlture?

  • Søren Spelling Lund 1797 posts 2786 karma points
    Aug 29, 2012 @ 10:56
    Søren Spelling Lund
    0

    Agreed. I have created a work item to add a graceful fallback option if the language in play isn't configured in Umbraco.

Please Sign in or register to post replies

Write your reply to:

Draft