Tuesday, November 10, 2009

SagePay Payment Gateway Configuration in OFBiz

I was required to implement SagePay payment gateway for my client, as I had never implemented a payment gateway in Ofbiz before, I went through the test processor's method in PaymentGatewayServices and authorizedotnet payment gateway implementation code, and it helped me in implementing one myself.

When I started implementing, because of time constraint, I did it in an adhoc manner, and once it was working fine, I thought of contributing the code, for this again I had to properly structure the code and clean it up, anyways next time onwards I am planning of putting a bit more time and doing it correct at first time itself, so that I dont have to work again :)

If somebody wants to use SagePay as the payment gateway and if the code still isn't commited in Ofbiz, you can download the patch from


Anyways let's get to the point, the implementation lets you configure all the usual parameters like the vendor name, version, payment gateway urls, but apart from this as SagePay has different transaction types, they too are configurable.

Now anybody using SagePay or planning to do so, may be aware of different transaction types available in SagePay.

Below are the transaction types available in SagePay :

1) PAYMENT - This is basically an authcapture.

2) AUTHENTICATE/AUTHORISE - This one is a normal auth/capture.
3) DEFERRED/RELEASE - This is same as auth/capture, but deferred transaction are not sent to the bank until you send a RELEASE request, ideally all deferred transacton should be released within 6 days.

So instead of hardcoding the transaction type in ccAuth & ccCapture service, the transaction type is take from the configuration, so it's easy to switch between the desired transactin types by just setting the config parameter. This should be clear by the screen shots below.

Once you have downloaded the code or applied the patch, you need to follow the steps below :

1) Run run-install-seed, this will build, create a new entity PaymentGatewaySagePay which stores the payment gateway configuration and insert seed configuration data.
2) Start ofbiz
3) Go to Accounting - Payment Gateway Config - select SagePay Payment Gateway from Payment Gateway Config Type Id from the dropdown and click LOOKUP
4) Click on SagePay Config from Search Results
5) Put your vendor name in Vendor Name field, I guess result all configuration will do, anyways check it out, and also notice the dropdown's for transaction types.
6) Click Update

We are done with payment gateway configuration, next is to configure payment services for store.

7) Go to Catalog - Stores - your store (am using ecommerce) - Payments
8) Configure the payment services, services are sagepayCCAuth, sagepayCCCapture, sagepayCCRefund & sagepayCCRelease, don't forget to set Payment Gateway Config Id to SagePay Config

That's it and you are ready to GO !!

Screen Shots