The first payment gateway I dealed with was PayPal. At that moment, I found it sucks, very tedious to integrate into iOS platform. Until now, I need to work with iPay88, which has no native iOS SDK, and the process even more tedious than PayPal. I share this because of the toughness & not easy to find any resources on web. Hope you enjoy.
1. Register a merchant account with iPay88
You will get Merchant Code and Merchant Key.
After that, submit a request URL to iPay88 support. Where the request URL is the page that you submit to iPay88 site, you will know later.
2. Create a page that support submit payment info to iPay88
But wait a minute, during the development, the URL should be localhost. Don’t worry, we can use virtual host here, you can refer this in my other blog post section 3. Make sure you put the real url to /etc/hosts
1
127.0.0.1 mysite.com
So when you access http://mysite.com, you are not refering to the live site, but the development site in your local machine, now you can test with iPay88.
This cannot be done in cURL
I have tried using cURL as well, in fact it need to be a POST request in a webpage form.
3. Create a response handler
response.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
<?php if (isset($_REQUEST['ErrDesc'])) { redirect('failure.php'); } if (isset($_REQUEST['Signature']) && $_REQUEST['Signature'] != $my_signature) { // NOTE that $my_signature you can store it in session before submit the form to iPay88 redirect('failure.php'); // for security purpose }
// store the info returned by iPay88, you will get this in the document provided by iPay88
// after process everything, redirect to success page redirect('success.php');
The file above will be a POST request, if you don’t want to use $_REQUEST, you can use $_POST
Bare in mind (Updated: May 12, 2015)
Please take note on the backend.php
Sometime, there are some weird issue that may caused the response.php not working correctly. Thus, backend.php is needed here (I have faced the issue with CIMB click).
The backend.php will not work if you check for login session. e.g.
1 2 3 4 5
<?php if (is_loggedin()) exit; // will exit here
// code won't execute ...
That means you cannot deal with any session here (backend.php)
See com.mysite.myapp? Is this weird to you? If you have use Waze API you will see waze://?q=<address search term> this, waze:// is the custom scheme that only use in Waze app. Same to this, com.mysite.myapp:// is only use in this app
5. Show the page above in your app using UIWebView
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { // Update: May 12, 2015 // a hack to solve the Maybank2u TAC popup window issue if ([request.URL.path containsString:@"m2uTACProcess.do"]) {
// init a new webview (as a popup) _popupWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 280, 400)]; [_popupWebView loadRequest:request]; // show it in a popup, I tested with https://github.com/rnystrom/RNBlurModalView
returnNO; }
if ([[request.URL scheme] isEqual:@"com.mysite.myapp"]) { NSArray *component = [request.URL.description componentsSeparatedByString:@"://"]; if ([component[1] isEqual:@"closeClicked"]) { // com.mysite.myapp://closeClicked // action to perform after payment failed } if ([component[1] isEqual:@"successClicked"]) { // com.mysite.myapp://successClicked // action to perform after success } returnNO; } returnYES; } @end
See com.mysite.myapp again? We detect if the URL scheme is com.mysite.myapp, then perform some action.
When the time your app open this web view, you will see iPay88 page. The whole integration is done.