Friday, 24 July 2015

payUmoney Payment Gateway Integration in iOS App (Objective C)

We have many Payment Gateways available such as Paypal, CCAvenue, Zaakpay, etc.

payUmoney is the best Payment Gateway available in India now; according to me.
I am saying this with my personal experience with payUmoney Technical Support Team.

They offer 2.9% Transaction charges without any Enrolment, Setup, AMC or other Hidden charges.

payUmoney Home Page Link: Home_Page

payUmoney Contact Details:
 5th Floor, Pearl Towers Plot 51, Sector 32 Gurgaon, 122002



Steps to integrate payUmoney gateway:

1. Create a new iOS Objective C app in XCode.
2. Open Main.storyboard in you app.
3. Add UIWebView and set its Delegate. [Screenshot 1]
4. Set Frames & Constraints as per design requirements.
5. Link UIWebView by creating IBOutlet to either .h or .m file. [Screenshot 2]
6. Signup and create an account on payUmoney. Test Envirnment: or Production Environment:
7. Follow below mentioned procedure to complete the registration process:

 Test Environment:

 Recently, payUmoney has done some modifications in test environment due to which test key-JBZaLc and salt-GQs7yium will not work anymore.

 In order to test the gateway using a test key and salt, kindly follow these steps:

     1 - Go on
     2 - Sign up as a merchant - use any of your valid email ids - kindly do not use a random email id.
     3 - Use a valid Mobile Number and for Phone/Landline No use your valid mobile number with a preceeding 0. (e.g. Mobile No: 9762159571 so the Landline No: 09762159571)
     4 - Complete the "Business Details"  - you may use PAN no. ABCDE1234F and DOB - 01/04/1990
     5 - Complete "Bank Account Details" (You may use IFSC- ALLA0212632)
     6 - Please leave the bank verification part.
     7 - Go to below mentioned location to get the Test Merchant Id :
          Seller Dashboard -> Settings -> My account -> Profile Settings

 Once you provide your test merchant id, payUmoney will approve it so that you can find your test key and salt at :
 Seller Dashboard -> Settings -> My account -> Merchant Key - Salt

 Production Environment:

 kindly register to and follow above steps with all your Genuine Bank details, contact numbers & adresses.
 Please note that the Key and Salt for Production server are different from the one we get from Test server.

8. payUmoney requires some mandatory fields to make a web-call:
    txnidkey, amount, productinfo, firstname, email, phone, surl, furl, hash, service_provider.
9. We have to create a Transaction ID which must be unique SHA512 encrypted value.
10. Take all values from user except txnid, key, surl, furl,  hash & service_provider.
11. Create a NSString by appending all the values in sequence as below:
NSString *hashValue = [NSString stringWithFormat:@"%@|%@|%@|%@|%@|%@|||||||||||%@",key,txnid1,amount,productInfo,firstname,email,Salt];
12. Use SHA512 encryption to hash the hashValue.
13. Create a NSDictionary of with all the values we have.
14. Make a POST type NSMutableURLRequest and pass the required parameters.
15. Load the NSMutableURLRequest to WebView and we are done.

Download code from Github Repo: Code

Special Thanks to:

Friday, 3 July 2015

Variable declaration in Swift

Declaration of iVar:

Let's start with declaring iVars in Swift

In Swift we can declare an iVar using keyword:
1. let - it declares an immutable iVar
2. var - it declares a mutable iVar

let myLetObject = "My immutable iVar"
So now i cannot change the value of myLetObject after it is once assigned.

var myVarObject = "My mutable iVar"
myVarObject = "Changed the value of iVar"
I can change its value at any instance.

Some examples of declaring objects:
let luckyNumber = 9
let myAge = NSInteger(27)
var myHeight = 5.5
let myImage = UIIMage(named:"MyPhoto.png")
var myName: NSString = NSString"string:Suraj Ramjan Mirajkar"
var tableView: UITableView!

Wednesday, 3 June 2015

Youtube Video Player

To play Youtube video within the app we have 2 ways:

1. Open Youtube App (if installed) or launch Safari to play video:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@""]];

In this case we don't have a choice to bring back the user to our app.
So we better use the 2nd way.

2. Embed Youtube iOS Player Helper:
I have used youtube-ios-player-helper Version - 0.1.3
  1. Select YTPlayerView.hYTPlayerView.m, and the Assets folder from my Github repository CODE.
  2. Drag these files and folders into your project. Make sure the Copy items into destination group’s folder option is checked. When dragging the Assets folder, make sure that the Create Folder References for any added folders option is checked.
  3. Drag a UIView the desired size of your player onto your Storyboard.
  4. Change the UIView's class in the Identity Inspector tab to YTPlayerView
  5. Import "YTPlayerView.h" in your ViewController.
  6. Add the following property to your ViewController's header file:
    @interface ViewController : UIViewController <YTPlayerViewDelegate>
    @property(nonatomic, strong) IBOutlet YTPlayerView *playerView;
  7. In Implementation's viewDidLoad() add following code:[self.playerView setDelegate: self];
    [self.playerView loadWithVideoId:@"Xk1zfQOklJY"];
  8. We are done.
  9. In case you want to get all the controls to Play, Pause, Stop, Seek to Time do download my code and check it out.

        Download - CODE

Below links helped me:

Friday, 13 March 2015

Check Internet Connectivity Using AFNetworking 2.0

I have created NetworkRechabilityMonitor class to get the Internet Connection status in my app using AFNetworking 2.0 library.

1. Create an NSObject class naming NetworkRechabilityMonitor, add below code in respective Header & Implementation files.


#import <Foundation/Foundation.h>

@interface NetworkRechabilityMonitor : NSObject




#import "NetworkRechabilityMonitor.h"

@implementation NetworkRechabilityMonitor

#pragma mark - Start Monitoring Network Manager
+(void)startNetworkReachabilityMonitoring {
    [[AFNetworkReachabilityManager sharedManager] startMonitoring];

#pragma mark - Check Internet Network Status
+(BOOL)checkNetworkStatus {
    return [AFNetworkReachabilityManager sharedManager].reachable;


2. Import the NetworkRechabilityMonitor in your ViewController class where you want to check the internet status.

3. In viewDidLoad method of your ViewController add below line of code:

[NetworkRechabilityMonitor startNetworkReachabilityMonitoring];

4. Now in ViewController if i want to check internet status before making an API call add below code:
if ([NetworkRechabilityMonitor checkNetworkStatus]) {
          NSLog(@"Connected to Internet");
          // Add your code
} else {
         NSLog(@"Not Connected to Internet");
         // Notify user to connect to Internet