Archive for the 'Tech Stuff' Category

Is DeadlineExceededError a thing of the past?

 

The new version (1.4.0) of the google app engine was announced yesterday, details can be found here:

 

http://googleappengine.blogspot.com/

 

There are some interesting changes and additions, however the one change that really caught my attention is that the time limit for tasks has been increased from 15 seconds to 10 minutes!!

 

The 15 second limit was a real pain when trying to do any sort of even light to medium weight background processing in the GAE – any task that ran to 15s would be killed and the very annoyong DeadlineExceededError would be reported. This sometimes made life really difficult for software developers, forcing them to restructure their code into multiple smaller chained tasks etc. So this is big news!

 

I have run some quick tests this morning and have happily run background tasks for many minutes, so things are looking good so far!

Software Developers know their away around SQL – it is a tool of the trade (as it were!), however today I had to revert to google to find the SQL to swap the values of 2 columns within a table. Luckily I found this interesting (and very handy) article that explains just how to do it:

 

http://beerpla.net/2009/02/17/swapping-column-values-in-mysql/

 

I had to reverse the relationships between drupal taxonomy terms, this was to be done by reversing the values of the tid1 and tid2 columns of the term_relation table, this code did the trick for me:

 

UPDATE term_relation SET tid1=tid2, tid2=@temp WHERE (@temp:=tid1) IS NOT NULL;

 

If I had to manually reverse all of the taxonomy relationships via the drupal admin interface it would have taken _forever_!

 

PS. If, for a given taxonomy term id, you need to get a list of the related taxonomy terms, just call:

taxonomy_get_related()

although be warned that the concept of related terms is to be removed in drupal 7!

Yesterday I was doing some web and eCommerce development for a client in Kildare, I was working to link Expression Engine and FoxEE up to foxycart. When testing transactions everything seemed to work ok, except that after very transaction I received the following error:

 

DataFeed Failed: (2134029) 2010-09-30 05:50:28 No data returned for http://www.blahblahblah.com/index.php?ACT=24 [500]

 

Every time the error occurred foxycart would send me an email.

 

The XML datafeed sends transaction data back to the expression engine website and FoxEE so that FoxEE can display the transaction details in the admin interface. Despite the error the transactions were being properly displayed by FoxEE and everything else seemed to work well!

 

Any script that consumes the foxycart XML datafeed must return the text ‘foxy’, if not this error will occur. It turns out that if your expression engine site is offline (Admin / System preferences / General Preferences / Is system on? == No), FoxEE will return some testing text instead of ‘foxee’ and so the error will occur. The funny thing was that my website was not ‘offline’ it was completely live and so FoxEE should not have been in test mode at all…… strange…. Then I remembered that I did have the site offline a few days ago but not now….

 

Well I cleared all of the Expression Engine caches and the error went away!!

 

Hope this helps somebody with a similar quandary – If you get this error, try:

(a) Check that your site us ‘On’
(b) Clear the Expression Engine Cache (Admin / Utilities / Clear Cached Data)

….

Q: I want so setup my Paypal business account to accept credit card transactions and not just paypal payments, but my customers are not offered the ‘pay by credit card’ option and when I look for the “Paypal Account Optional” setting in Profile / Website Payments Preferences I can’t find it! What do I do?

 

A: Make sure that the email account associated with you paypal business account has been verified (also check that you bank account has been verified too.) if it is not verified the option to pay by credit card will not be available. Once everything is verified the Profile / Website Payments Preferences / Paypal Account Optional should be visible -make sure that this option is ‘On’ and your customers should now be given the option to pay by credit card!

Ok, I am going to post this here so that I know where to find it the next time I desperately looking! I am developing for GAE on windows with eclipse and on windows the google launcher doesn’t have the nice option to delete the datastore before launch that it has on the Mac??!!

 

So, to clear out or delete your GAE application’s local datastore, open a console cd to your application’s directory (i.e the one that has your app.yaml file), and run the following command:

 

dev_appserver.py -c .

 

This will launch the app server but first empty the local datastore.

We have been slaving away in the cloud working on integrating paypal with a google app engine application for one our clients in Dublin. There really isn’t much information ‘out there’ on the subject of connecting to paypal from the GAE, so I have decided to write up some notes in the hope that they prove useful to others (and me when I forget all about it!)

 

I am going to start at the ‘end’ while the information is fresh in my head, when using ‘Paypal Payments Standard’ you can choose to get Paypal to pass you back transaction outcome information when it redirects back to your website after a transaction – they call this PDT. You can use this information to update the transaction/order status on your website (once you verify it).

 

Here is some more information on PDT:

 

https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/howto_html_paymentdatatransfer

 

With PDT enabled paypal adds some arguments to the return url, these arguments contain information about the transaction, however you shouldn’t really trust this info as the HTTP POST could have been spoofed by somebody else. So to check the transaction information you pull out the ‘tx’ argument and pass it back to paypal which will return a verification message that contains the transaction details.

 

So to verify a PDT transaction we must:

 

(a) Get the ‘txt’ argument from the paypal return request.
(b) Perform a HTTP POST back to paypal specifying ‘tx’
(c) Check the response from Paypal, check for ‘SUCCESS’, check ‘payment_status’ and possibly other transaction details.

 

In Python on the Google App Engine the python code could look like this:

 

import urllib
from google.appengine.api import urlfetch
import re
#
class paypal_pdt_handler(RequestHandler):
    def get(self):
        # Get the transaction id, tx=blahblahblah
        trans_id = self.request.get(‘tx’)
       
        # Confgure POST args
        args = {}
        # Specify the paypal command
        args[‘cmd’] =‘_notify-synch’
        args[‘tx’] = trans_id
        args[‘at’] = _identity_token
       
        args = urllib.urlencode(args)
       
        try:
            # Do a post back to validate
            # the transaction data
            status = urlfetch.fetch(url = _paypal_url,
                                    method = urlfetch.POST,
                                    payload = args).content
        except:
            self.response.out.write(‘POST Failed’)
           
        # Check for SUCCESS at the start of the response
        if re.search(‘^SUCCESS’, status):
            # Check other transaction details here like
            # payment_status etc..
            # Update order status
            self.response.out.write(‘OK’)
        else:
            self.response.out.write(‘Failed’)

 

This is a slightly cut down example, in a real application you would need to do a bit more error handling etc. In this example the following variables need to be given values:

 

_paypal_url – The url to paypal, either sandbox or live.
_identity_token – Your “Identity Token”, see this post for info on how to find this in your paypal account:

 

NOTE: Another way to get information on transaction status is to handle Paypal IPN. I tend to use both methods as if you only use PDT and for some reason the user does not redirect back to your site, then your site won’t b able to check the transaction status whereas IPN messages will be delivered in all cases.

August 12, 2010

There are a few reasons that could cause paypal to send back:

 

FAIL ERROR: 4020

 

When you attempt to verify PDT transaction data by posting a _notify-synch command.  However, in 9 times out of 10 the cause is due to the request containing an incorrect ‘at’ or authorisation token argument.

 

The ‘authorisation token’, or ‘Identity Token’ is a big long alphanumeric string, to find yours log into your paypal account, click on ‘Profile’, then click on ‘Website Payment Preferences’, scroll down to the ‘Payment Data Transfer’ section – you will see your ‘Identity Token’ at the end of this section.

 

This token must be included in your _notify-synch command as an argument named ‘at’.

 

Some more information on Paypal’s PTD can be found here:
https://www.paypal.com/us/cgi-bin/webscr?cmd=p/xcl/rec/pdt-techview-outside

Software Engineering can be a bit challenging on the Google App Engine, and so I am always on the lookout for a helping hand!  I came across this article on using reCaptcha on the Google App Engine using python:

http://daily.profeth.de/2008/04/using-recaptcha-with-google-app-engine.html

Just what I needed, a step by step guide!

There are some interesting aspects to doing Software Enginering from within the Google App Engine sandbox – I came across this interesting article on how to play with things so that you can make XML-RPC calls from within the google app engine sandbox.  By default such calls will be blocked but the article shows who to provide your own ‘Transport’ object to break out of the sandbox.


http://brizzled.clapper.org/id/80


I haven’t tried the technique yet as there are a few changes to make but I hope to try it soon and report back!


In the mean time if anybody has tried the technique please let us know how you got on!

Just came across a bit of a time-waster in the PHP SimpleXMLElement lib.  Usually if you’re accessing an element called, say ‘username’ you use the follwoing syntax:

$username = $element->username;

However if the element has a minus sign in its name, like ‘user-name’ you have to use the following syntax instead:

$username = $element->{‘user-name’};

If you use the original syntax no data will be returned, mad stuff, I would have wasted much more time on this if it wasn’t for this post – Thanks for the dig-out!