Taking screenshots on iPhone and iPad

It's the little things that you learn that make life easier. I wanted to screenshot the RushCrowds iPhone app this morning, turns out is easy:

  1. Open the screen you want to copy
  2. Hold down the power and the home button at the same time for a second then release, the screen flashes white and you hear a camera click. (The power button, which might be officially called the sleep button I suspect, is the one at the top right, the home button is the round button at the bottom middle).

It saves the screenshots to your Photos, so you can email them, or just sync over to iPhoto.

 

CyberSource Payment Gateway – Authorize and Capture

I've been implementing a credit card payment gateway recently using the Cybersource system and their SIMPLE API features – it's a COM object based system.

Everything seemed to go swimmingly well until I struck a snag processing Refunds using the follow-on service, which is where you can refund a previous payment by referencing its unique identifiers. As opposed to a stand alone refund credit.

Cybersource steadfastly refused to allow the credit, giving me errors saying that I was missing a data field, which, after spending a bunch of time carefully checking the fields against their SDK documentation, I was convinced was not correct.

Finally I worked it out – and it had been staring at me in the face. Credit card systems generally have two modes:

  1. Authorization – where you check that the card number etc is valid, and that the customer has the bucks available
  2. Capture – where you then 'capture' the payment based on the Authorization

Virtually every credit card gateway I've used wraps Authorization and Capture into a single function for cases where you just want a straightforward payment. EG you just want to get the customer's money in a single transaction.

Cybersource is different, first you have to Authorize the payment, then Capture it, which of course you have to do as a single set of calls all as part of processing the customer's payment. On the surface of course it makes complete sense, you are replicating the actual process going on behind the scenes.

But in practice it means making two separate calls to the Cybersource API, all while the customer is sitting watching the spinning 'loading' icon in your shopping cart page.

Matters are not assisted by Cybersource's documentation not clearly describing this (a flow chart or diagram would be helpful), and their samples are woefully deficient – they don't actually have a sample that shows a combined Authorize and Capture scenario – which would surely have to be the single most common activity undetaken by developers implementing their API.

 

Sending JMail email with SQL stored procedure

I really must share more interesting stuff as a I come across it.

I've been having fun recently using sp_OACreate in SQL stored procedures to use COM objects. For example, I came across this link that shows how to send email using the JMail COM object in a stored procedure.

A couple of helpful hints:

  1. You need to  'OLE Automation Procedures are enabled' as true, in SQL Surface Area Configuration
  2. You'll need a user with rights on the Master db. I created a separate user just for calling these stored procedures, and gave the them the following rights:

USE [master]
GRANT EXECUTE ON dbo.sp_OACreate TO [user]
GO
GRANT EXECUTE ON dbo.sp_OASetProperty TO [user]
GO
GRANT EXECUTE ON dbo.sp_OAMethod TO [user]
GO
GRANT EXECUTE ON dbo.sp_OAGetErrorInfo TO [user]
GO

My only problem so far is JMail won't send an attachment. I've tried messing with permissions on the file to be attached but that didn't help.

The Disappearing Google Toolbar

My Google Toolbar (on Mac FireFox) went AWOL overnight – the bar was there at the top of the browser window but completely blank, no buttons. I tried the usual right click on the bar and Google Toolbar was ticked. I went to Google and downloaded and installed the Toolbar again, still nothing.

Then tried clicking Tools > Add Ons > Google Toolbar > Preferences and the Preference window was slightly bizarre with a number of buttons duplicated:

Screen shot 2010-02-15 at 9.40.13 AM

A quick Google Search found this page, and this piece of advice:

I removed everything in ~/Library/Application Support/Firefox/Profiles/<profile dir>/GoogleToolbarData

I followed the instructions, restarted Firefox and my Google Toolbar reappeared.

Firebug 1.5

Having problems with the latest version of Firebug, it doesn't like the SACK ajax library that I use a great deal (it's the same AJAX library included in WordPress).

The issue only just started, basically Firebug doesn't like the way the SACK script prepares for an AJAX call.

I found something about this in another blog post that appears to explain the issue. Firebug And The Mysterious “Components Is Not Defined”.

A commenter named Svan seems to have found the issue and a simple workaround that I'm going to try.

It seems that every plugin that wants to use the “sack” function of wordpress (for fetching ajax data), will trigger a firebug bug, due to the attempt to create ActiveXObject.

But as Firebug only is made for Firefox, I tried to switch the logic of the createAJAX inner function.
So normally, the javascript function would try to make the xmlhttp object with ActiveXObject (MS Stuff), and when that doesn’t succeed it does it the Mozilla way with XMLHttpRequest.

I changed the order:

if (typeof XMLHttpRequest != “undefined”)
this.xmlhttp = new XMLHttpRequest();

if (! this.xmlhttp) {
try {
this.xmlhttp = new ActiveXObject(“Msxml2.XMLHTTP”);
} catch (e1) {
try {
this.xmlhttp = new ActiveXObject(“Microsoft.XMLHTTP”);
} catch (e2) {
this.xmlhttp = null;
this.failed = true;
}
}
}

Entries in iCal not syncing to Google Calendar

I have iCal set up attached to my Google Calendar, and thus events entered into iCal, Google Calendar or my iPhone all happily sync up. Except today new events entered into iCal stopped appearing in Google or iPhone.

Found a quick and easy solution.

1. Exit iCal

2. Find the file [youruser]/library/calendars/calendar cache and delete it

3. Restart iCal

And hey presto entries added to iCal are syncing again.

Missing Formula Bar in Excel (for Mac)

My Formula bar was missing in Excel (Mac). Click on View > Formula Bar and the option was ticked. Tried on untick – but stayed ticked.

Closed all other tool bars, no help.

Found solution: hold down CONTROL and SHIFT keys and start Excel. Resets the tool bars and the Formula bar magically reappeared.

Javascript Frustration – Spaces in Window Names

It's the little things that drive us to an early grave. Was working on a page this morning, it had a Javascript call along the lines of:

function openPage(myPage,myTitle,settings) {

win = window.open(myPage,myTitle, settings);

}

Then I had a link on the page:

<a href="javascript:openPage('demo.asp','document view','width=600,height=400,scrollbars=yes');">Click This</a>

Works in FireFox. Get error in Internet Explorer.

Of course took me 30 minutes of messing around to realise the problem – the space in the window title. Has to be 'documentview' with no space. You'd think I'd know better after all these years, but it's the little typos that cause us the most grief most often I reckon. FireFox is more adaptable and figured out that a space didn't make the blindest difference and let it through to the keeper. IE, of course, gave a useless indefinite error and wouldn't work.

Check dates are valid in sql

Tearing my hair out over a query that involves manipulating and querying dates from SQL. Amongst various stuff I came across was this useful little snippet, if you have stored dates in a text field (eg nvarchar) it can tell you if the dates are valid:

set dateformat mdy

select *
from t
where isdate(startdate) = 1
    and convert(datetime, startdate) not between '19000101' and '20790606'

Keeping this one in the toolbox for another day.

Blocking Spammy IPs

A few months ago I found our little web server at home was being constantly wacked by people trying to find a way in. As is now unfortunately the case, the vast majority of the IPs were Chinese or Korean.

I found a neat little utility called IISIP – a free download, that enables you to load a big bunch of IP numbers into IIS to block. You could add them one by one in IIS of course. But they give you block lists for most China and Korean ranges and it adds up to 50,000 IPs. Not a list you want to manually add.

Am reminded because a VPS box for one of my clients seems to be attracting an inordinate amount of interest from those two countries, and given the client does no business there, I'm going to ask their OK to load IISIP and just turn off access from those countries.