Continuous Authority and repeated transactions using SagePay Gateway
SagePay allows us to process repeated capture transactions against a successful payment authorization. You can get more information about the introduction and instructions for obtaining a Continuous Authority Internet Merchant Number here.
This example makes use of a forked version of ActiveMerchant and SagePay Simulator environment. Please refer to the previous article for setup instructions.
Setup:
Make sure to check ‘Continuous Authority’ in the simulator account settings.
Case 1: A non 3D Authorized Transaction
response.authorization shows a value simiar to:
00001;{E5AC4385-06F8-40DD-8486-22EFB23768AE};9030;03FQG5AJA6;authorization
Capture the Payment
Repeat the transaction using previous authorization reference.
Case 2: 3D Authorized transaction
Follow the steps 1-3 for 3D Secure Payment Transaction as shown in the previous article. You’ll notice that the authorization returned by a three_d_complete process is incomplete and it looks something like “;{FB448BBF-CB72-414A-B293-316004162EEB};6598;OUWEBUCWL3;three_d_complete”
Prepend the order_id used in step 1 to this authorization reference so that it matches following format:
three_d_auth_reference = “00003;{FB448BBF-CB72-414A-B293-316004162EEB};6598;OUWEBUCWL3;three_d_complete”
Where “00003″ is the order_id used for authorization in step 1.
Capture this 3D Authorized payment for the first time by calling:
This transaction can be repeated by using the previous successful authorization (three_d_auth_reference) with a new order_id.
Html to plain text using webrat and nokogiri
Here is a snippet to parse a given http response into plain text. Basically it removes html tags, css blocks, script tags and yield visible text elements as seen in browser.
Gives:
Using AutoComplete with ActiveScaffold forms
This is a quick guide to set up auto_complete text fields in forms rendered by ActiveScaffold plugin.
I am not a huge fan of ActiveScaffold, but found these steps worth publishing after doing this for one typical project requirement.
1. Models
2. Install ActiveScaffold and AutoComplete Plugins
3. Controller Configuration
This renders a drop down list for country field, instead of the default create/replace form. However, we need to render an auto completing text box for which we need to replace the form column.
4. Form column override
Next step is to override the form column. Create a file named _country_form_column.html.erb in app/views/cities folder.
The second option :method => :get is needed to avoid the InvalidAuthenticityToken error generated by the ajax post request.
5. Since the form now returns country[name] instead of record[country_id] in params, we need to assign country object before creating city record. The CitiesController finally looks like:
Mass Image Processing
I ran into a requirement to create thumbs of all images in my content folder. This shell script can be used to create thumbs of all images or for mass conversion of file formats. The script scans for images with the specified format in all subdirectories and puts the processed file in same path.
The constants can be modified to define the source directory, resolution, source and target filetypes. You need to have ImageMagick installed and configured to get this script working.
The script will create thumbs for each image file in same directory with ‘.thumb’ before the extension.
For ex: my_cool_pic.jpg will have a thumbnail named as my_cool_pic.thumb.png.
Add Google Custom Search to your Rails Application (Business Edition)
Here are the steps to set up a Google CSE for your rails application. In order to use the xml api, first of all you need to have a business account. You can get the xml query format url or more precisely the cx parameter (unique ID of the CSE) from the control panel.
Setup:
Identify your resource to be searched with the help of url patterns. For ex, if the application is RESTful, it is easy to index something like http://someshop.com/products. Configure your CSE for the above url pattern so that http://someshop.com/products/1, http://someshop.com/products/2.. etc get indexed by the search engine.
Code:
The GoogleSearch class sends a GET request to fetch the results xml, which is parsed using the Hpricot parser.
Output:
Now you could get the urls of search results as an array. Likewise, you can fetch other parameters from resultant xml by referring the this doc..


