1. Home
  2. Library
  3. Tokenization
  4. iOS Tokenization

iOS Tokenization

Pre-requisites

Before starting the development it is intended to register the application in Sr Pago’s platforms

Process

Install Cocoapods, to achieve this type the following command in Mac OS’ terminal

sudo gem install cocoapods

Using the terminal navigate to the applications path where you will install the library and type the following command

pod init

Put the Framework folder in the application folder and add a reference to the Podfile that is located in the application’s folder. Be careful put the correct path.

# Uncomment the next line to define a global platform for your project
 platform :ios, '9.0'

target 'SrPago' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!
  pod 'SrPago', :path=>'./SrPagoFramework'
  # Pods for SrPago

  target 'SrPagoTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'SrPagoUITests' do
    inherit! :search_paths
    # Pods for testing
  end

end

In the application directory execute the following command in order to install the references that were just added

pod install

From now on open your workspace using the file xcworkspace, avoid using xcodeproj since this file won’t have the installed elements

Implementación

In the .m controller file in which you will execute the tokenization process, import Sr. Pago’s Framework using the following line

#import <SrPago/SrPago.h>

Instantiate an object in your preferred method, as a recommendation you can use viewDidLoad  so it will be executed by default

srPago  = [SrPago sharedInstance];
    [srPago setPublisableKey:(@"<Put here your public key >")];
    [srPago setLiveMode:NO];

Once the instance is created and after you have retrieve all the required data you can create a model and request the tokenization

SPCard *card = [[SPCard alloc] init];
card.name = 'Nombre tarjetahabiente';
card.number = <Numero tarjeta de crédito>;
card.expMonth= '02';
card.expYear = '22';
card.cvv = '000';
@try{
    [srPago.token createTokenWithCard:card onSuccess:^(SPToken *response){
        NSLog(@"El Token es: %@",response.token);
    }onFail:^(SPError *error) {
        NSLog(@"Error: %@", error.message);
    }];
}@catch(NSException *e){
    NSLog(@"Hubo un error: %@", e.reason);
}

 

Additional Resources

 

As an option you can download our Demo.

 

Was this article helpful to you? Yes No