Sage Pay Form Integration In native IOS app.

Sage Pay did not have any mobile SDK. So i used data encryption method to achieve sage pay form integration in IOS. I followed the following steps to achieve sage pay form integration.

a) Create the string b) Apply PKCS5 Padding c)Encrypt using mcrypt_encrypt (using MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC and password as key and initialization) d)Convert to hex using bin2hex e)Convert to uppercase using strtoupper f) prepend @ to string.

OverFlow :

Sage Pay is Europe’s leading independent payment service provider (PSP) and is one of the most trusted payment brands. We offer our you 3 methods of integration to process your transactions through our system.  Each method of integration available to you allows for different levels of control, and communication between your website and our own platform.

  • Sage Pay Form: A simple encrypted form submission post from your website to the Sage Pay systems, the shopper is then transferred to our hosted payment pages  for the card details to be securely captured.  This is the most basic method of integration available on our platform with your site only requiring a single post for the transaction to be processed.
  • Sage Pay Sever: The Sage Pay Server method of integration allows you more control over the transactional process than the Form solution.  The Server integration still enables you to have the transactional process hosted on our platform. There is continuous channel of communication open between your site and our platform.  The Server method also enables our vendors the option to implement an “InFrame” into their site which embeds the Sage Pay payment pages on the vendors website.
  • Sage Pay Direct: This solution gives you complete control over the transactional process including the hosting of the card details capture pages.  You are required to undertake complete developmental work of the entire payment process including the security and safety of the details that are captured.

Now I am going to explain Sage Pay Form integration below:

Introduction:-

Sage Pay’s Form integration provides a straightforward hosted payment interface for the customer and takes complete responsibility for the online transaction, including the collection and encrypted storage of payment data. Eliminating the security implications of storing such sensitive information on your own servers and removing the need for you to maintain highly secure encrypted databases or obtain digital certificates. Follow below steps.

1.First you should take needed details and success & failure fallback URLs in string format.

Ex: VendorTxCode=TxCode-1310917599-223087284&Amount=36.95&Currency=GBP&
Description=description&CustomerName=Fname&Surname&CustomerEMail=
customer@example.com&BillingSurname=Surname&BillingFirstnames=Fname&
BillingAddress1=BillAddress Line 1&BillingCity=BillCity&BillingPostCode=W1A 1BL
&BillingCountry=GB&BillingPhone=447933000000&DeliveryFirstnames=Fname&
DeliverySurname=Surname&DeliveryAddress1=BillAddress Line 1&DeliveryCity=
BillCity&DeliveryPostCode=W1A 1BL&DeliveryCountry=GB&DeliveryPhone=447933000000
&SuccessURL=https://example.com/success&FailureURL=https://example.com/failure

2.Encrypt the above string using CCOperation = kCCEncrypt. Here you should take string as encoded data, base64 iv & base64 key values are from password(iv and key both are same) and apply CCOperation as kCCEncrypt. Now you will get encrypted data then convert into hexaDecimaString as uppercase. Just follow encryption and  hexaDecimalString methods.

- (NSData *)crypt:(NSData *)dataIn iv:(NSData *)iv key:(NSData *)symmetricKey context:(CCOperation)encryptOrDecrypt;

- (NSString *)hexaDecimalString;

3.Next load Sage pay gateway with crypt as above hexa decimal string into your web view, then you can see sage pay login page with payment details. After payment success, fallback url loaded into web view. See below loaded URL format data and attached screens.

 
https://test.sagepay.com/gateway/service/vspform-register.vsp?VPSProtocol=3.
00&TxType=PAYMENT&Vendor=protxross&Crypt=@D73A09F9A3D3AFE9303613BD2AA2354C7D8
7D65125DC78079E2C964F9C48D2DA43F50B24E6F4A7A2E8F9FD6DEDD572E50F14EA25E565BD1F0
C7656B64D671BAC293A3C8D80ED9B43C20AF1EE1E40F96E3B9E0DB96003345A018F570C35F6994
E8427339F9E0528C68BB234EF1D4911289F01BAC4AC03EEE01646CEEBA4EF2AF85E8C85D6A5DE3
F1D025FBC6C991CD20AF0E7A3357841E0AB4B26112FAC514D9F4AADDED6C5203C1B8A0988BD0EB
705F4525A0DD48B1A0FF4237CA08A943E0A7DEA4DCFB5F2FFA0252C3CBA5D74D4C3D1DCD946442
8527D021EC8355BC42CCB92D450D51AD8CE52A1FBE20D7E0F6675D5AE63A4C545498406DA7FE36
A835834CD25A381C09E359E1F6ADEEE8218549E71B182B565E692F3670C6154795973FD5767F48
F4B9691BDE53A038C8C9744F559A177D8861132CB89FDB2E989EC7DDC36BFC30C24CDF2FF4AE66
97A852C5AED71380EE9EA323F6E5FBAD2E252A689BC31E4ABE9AF231744C42590EF4BBC501AB67
D2297E042E1865A27DA49F645D526E2C1DE5F0E32B6FA9A23DA4DB21B9F283DD05D9760189159A
AFB5C20F0D0D971921B4BA2762B1E412C35839D696AFFC2243F006DCE1BBC47D7D7ABBB128ABFE
F5DA18AAEFEF652E1A960A07DA95E5D37ADE1EF478E9B6C56BB794C619BC66FE20C0672ADEE295
06A4DE73996BFBCD837EEFF8D2286361250E3B3AE83F5D62B80AF78508E2F82128AE208371568D
A21E331FE242CE27E753D988FC413BCC5642E15B5DC95F2FE36879309B7E4DC3582B9B8DE57E2A
020AAD56D52CF6B83B00DEC00A9E6CEA16B4EECAA70342CAD12D12F5F2D415F2B647D213C78FCA
3B9B8CE5C035E035CD9CFB4410573149159C3601E56280B34DF44C0123F3B409EC3190B4D0728A
C68D45A640EF9BB08406A724A8E4273978C99057FF552F840949977A67C5E12A90E3DC68E1F3BE
FA74C88D2832862      

Mobile app development, iOS Development Mobile app development, iOS Development Mobile app development, iOS Development

4.After payment success you can get payment response from web view delegate method(didFinishLoaded).

Payment Response : http://192.168.2.19:8080/sagepay-php/?crypt=@d73a09f9a3d3
afe9303613bd2aa2354c62c29543cb0dea3cd9d2cd8da77b083efc6f2104840ac38cf4889a3d
152626421171647446ccf14858ce6988bbfd94f23a9270e01ed0fa08883cff683b482b59df4c1
394ad43ca19ca832063e5d9b327ca3c37956319f228ab1afc2aaa0a5f886ba56c809439b47c03
e6963a12aaa92a1965414bc3fe266f6d8485dffc8c7b71cbca31227993ff179fae8b93302b032
ac84cdd70ab1f4b166cb218dd6bb4074a358c4df6ef21634f19ce64fd8c1eb5404a738c805854
6602f8c1d0f0c82c1e6113ac0e4e77d974663f69aa9f1745d631afeedb0fefa6424aff4dcbfc3
8e94abd42acba3c00ba704801c6b5cfccb8f44aa7727ac85d8d9b121c7fecda9378e1a5368a37
47c0a4b713a8ef4ab16c9e15b6155604bf9ed0600d302ab00dfe77d050ff044eeb61750afc1ecb
46c3619674d20d88f0a1d886f39ae1ab084056f2ca04465fdc9d09138886df9ba6489ad224e12e
f239806ddeb330c431f2038fabda505c5ef313a8a1689a1a1ccf5edf216c541d74034ba6f13e8c
5ecd3d5c83d3dd0ed4cdaf9d78ad7a32722780c95518b682e85c098d95eff20577001ff067f0a7
50

5.Apply NSURLSession with GET method to see payment details in JSON format like below.

6.If transaction is successful then vendor & customer will receive mails otherwise vendor only will receive mail.

7.Source code is available in GitHub

About the Author

       

Gopal.E,

IOS Application Developer at Colors Software Pvt Ltd.

Gopal Reddy

Author: Gopal Reddy