Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actualización a Swift 3 #12

Open
wants to merge 3 commits into
base: swift
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0830"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A7010C2F1BD583FA002FC7C1"
BuildableName = "ConektaCardToken-ObjectiveC.app"
BlueprintName = "ConektaCardToken-ObjectiveC"
ReferencedContainer = "container:ConektaCardToken-ObjectiveC.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A7010C481BD583FA002FC7C1"
BuildableName = "ConektaCardToken-ObjectiveCTests.xctest"
BlueprintName = "ConektaCardToken-ObjectiveCTests"
ReferencedContainer = "container:ConektaCardToken-ObjectiveC.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A7010C531BD583FA002FC7C1"
BuildableName = "ConektaCardToken-ObjectiveCUITests.xctest"
BlueprintName = "ConektaCardToken-ObjectiveCUITests"
ReferencedContainer = "container:ConektaCardToken-ObjectiveC.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A7010C2F1BD583FA002FC7C1"
BuildableName = "ConektaCardToken-ObjectiveC.app"
BlueprintName = "ConektaCardToken-ObjectiveC"
ReferencedContainer = "container:ConektaCardToken-ObjectiveC.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A7010C2F1BD583FA002FC7C1"
BuildableName = "ConektaCardToken-ObjectiveC.app"
BlueprintName = "ConektaCardToken-ObjectiveC"
ReferencedContainer = "container:ConektaCardToken-ObjectiveC.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A7010C2F1BD583FA002FC7C1"
BuildableName = "ConektaCardToken-ObjectiveC.app"
BlueprintName = "ConektaCardToken-ObjectiveC"
ReferencedContainer = "container:ConektaCardToken-ObjectiveC.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>ConektaCardToken-ObjectiveC.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>A7010C2F1BD583FA002FC7C1</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>A7010C481BD583FA002FC7C1</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>A7010C531BD583FA002FC7C1</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
112 changes: 112 additions & 0 deletions Examples/ConektaCardToken-Swift/Conekta.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
//
// Conekta.swift
// ConektaSwift
//
// Created by Eduardo Pacheco on 27/06/17.
// Copyright © 2017 Eduardo Pacheco. All rights reserved.
//

import Foundation
import UIKit

public class Conekta: NSObject, URLSessionDelegate {

// MARK: - Properties
private let baseURI = "https://api.conekta.io"
private lazy var deviceFingerprint: String = {
let uuid = UIDevice.current.identifierForVendor!.uuidString
return uuid.replacingOccurrences(of: "-", with: "")
}()

public var publicKey: String!
public var number: String!
public var name: String!
public var cvc: String!
public var expMonth: String!
public var expYear: String!
public var delegate: UIViewController?

// MARK: - Init
required public convenience init(withNumber number: String, name: String, cvc: String, expMonth: String, expYear: String) {
self.init()
self.number = number
self.name = name
self.cvc = cvc
self.expMonth = expMonth
self.expYear = expYear
}

// MARK: - Public Methods
public func collectDevice() {
let html = "<html style=\"background: blue;\"><head></head><body><script type=\"text/javascript\" src=\"https://conektaapi.s3.amazonaws.com/v0.5.0/js/conekta.js\" data-conekta-public-key=\"\(publicKey)\" data-conekta-session-id=\"\(deviceFingerprint)\"></script></body></html>"
let web = UIWebView(frame: CGRect.zero)
web.loadHTMLString(html, baseURL: nil)
web.scalesPageToFit = true
self.delegate?.view.addSubview(web)
}

public func createToken(onSuccess successHandler: @escaping (String) -> (), onError errorHandler: @escaping (Error) -> ()) {
guard let apiBase64 = apiKeyBase64() else { errorHandler(createError(message: "Wrong API Key")); return }
if let req = createRequest(apiKey: apiBase64) {
let defaultSession = URLSession(configuration: .default, delegate: self, delegateQueue: .main)
let dataTask = defaultSession.dataTask(with: req) { [weak self] (data, response, error) in
guard let this = self else { return }
if error != nil { errorHandler(error!) }
if let data = data {
do {
let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as! Dictionary<AnyHashable, AnyObject>
if let id = json["id"] {
successHandler(id as! String)
} else {
if json["object"] as! String == "error" {
let msg = json["message_to_purchaser"] as! String
errorHandler(this.createError(message: msg))
} else {
errorHandler(this.createError(message: "Token Creation Error"))
}
}
} catch {
errorHandler(this.createError(message: "Token Creation Error"))
}
} else {
errorHandler(this.createError(message: "Connection Error"))
}
}
dataTask.resume()
}
}

// MARK: - Private Methods
private func apiKeyBase64() -> String? {
if let plainData = publicKey.data(using: .utf8) {
let base64Data = plainData.base64EncodedData(options: .lineLength64Characters)
return String(data: base64Data, encoding: .utf8)
} else {
return nil
}
}

private func cardJSONData() -> Data {
let json: String = "{\"card\":{\"name\": \"\(name!)\", \"number\": \"\(number!)\", \"cvc\": \"\(cvc!)\", \"exp_month\": \"\(expMonth!)\", \"exp_year\": \"\(expYear!)\", \"device_fingerprint\": \"\(deviceFingerprint)\" } }"
return json.data(using: .utf8, allowLossyConversion: true)!
}

private func createError(message: String) -> NSError {
return NSError(domain: "Request Error", code: 500, userInfo: [NSLocalizedDescriptionKey: message])
}

private func createRequest(apiKey: String) -> URLRequest? {
if let tokenURL = URL(string: baseURI + "/tokens") {
var urlRequest = URLRequest(url: tokenURL)
urlRequest.httpMethod = "POST"
urlRequest.addValue("Basic " + apiKey, forHTTPHeaderField: "Authorization")
urlRequest.addValue("application/json", forHTTPHeaderField: "Content-type")
urlRequest.addValue("application/vnd.conekta-v0.3.0+json", forHTTPHeaderField: "Accept")
urlRequest.addValue("{\"agent\":\"Conekta Conekta iOS SDK\"}", forHTTPHeaderField: "Conekta-Client-User-Agent")
urlRequest.httpBody = cardJSONData()
return urlRequest
} else {
return nil
}
}
}
55 changes: 0 additions & 55 deletions Examples/ConektaCardToken-Swift/Conekta/Connection.swift

This file was deleted.

64 changes: 0 additions & 64 deletions Examples/ConektaCardToken-Swift/Conekta/Token.swift

This file was deleted.

Original file line number Diff line number Diff line change
@@ -7,18 +7,14 @@
objects = {

/* Begin PBXBuildFile section */
8CBEFF021D418EF800705729 /* Token.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CBEFF011D418EF800705729 /* Token.swift */; };
8CFD48971D41831B001AB13C /* Card.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CFD48961D41831B001AB13C /* Card.swift */; };
8CFD48991D4183A8001AB13C /* Conekta.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CFD48981D4183A7001AB13C /* Conekta.swift */; };
8CFD489B1D4187F1001AB13C /* Connection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CFD489A1D4187F1001AB13C /* Connection.swift */; };
A74C8EE41BE0777700DF0A17 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A74C8EE31BE0777700DF0A17 /* Foundation.framework */; };
A753AE9F1BD588D800D269C7 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A753AE9E1BD588D800D269C7 /* AppDelegate.swift */; };
A753AEA11BD588D800D269C7 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A753AEA01BD588D800D269C7 /* ViewController.swift */; };
A753AEA41BD588D800D269C7 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A753AEA21BD588D800D269C7 /* Main.storyboard */; };
A753AEA61BD588D800D269C7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A753AEA51BD588D800D269C7 /* Assets.xcassets */; };
A753AEA91BD588D800D269C7 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A753AEA71BD588D800D269C7 /* LaunchScreen.storyboard */; };
A753AEB41BD588D800D269C7 /* ConektaCardToken_SwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A753AEB31BD588D800D269C7 /* ConektaCardToken_SwiftTests.swift */; };
A753AEBF1BD588D900D269C7 /* ConektaCardToken_SwiftUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A753AEBE1BD588D900D269C7 /* ConektaCardToken_SwiftUITests.swift */; };
BA72B8B91F04412600F18079 /* Conekta.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA72B8B81F04412600F18079 /* Conekta.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
@@ -39,11 +35,6 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
8CBEFF011D418EF800705729 /* Token.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Token.swift; path = Conekta/Token.swift; sourceTree = "<group>"; };
8CFD48961D41831B001AB13C /* Card.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Card.swift; path = Conekta/Card.swift; sourceTree = "<group>"; };
8CFD48981D4183A7001AB13C /* Conekta.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Conekta.swift; path = Conekta/Conekta.swift; sourceTree = "<group>"; };
8CFD489A1D4187F1001AB13C /* Connection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Connection.swift; path = Conekta/Connection.swift; sourceTree = "<group>"; };
A74C8EE31BE0777700DF0A17 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
A753AE9B1BD588D800D269C7 /* ConektaCardToken-Swift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "ConektaCardToken-Swift.app"; sourceTree = BUILT_PRODUCTS_DIR; };
A753AE9E1BD588D800D269C7 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
A753AEA01BD588D800D269C7 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
@@ -57,14 +48,14 @@
A753AEBA1BD588D900D269C7 /* ConektaCardToken-SwiftUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "ConektaCardToken-SwiftUITests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
A753AEBE1BD588D900D269C7 /* ConektaCardToken_SwiftUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConektaCardToken_SwiftUITests.swift; sourceTree = "<group>"; };
A753AEC01BD588D900D269C7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
BA72B8B81F04412600F18079 /* Conekta.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Conekta.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
A753AE981BD588D800D269C7 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
A74C8EE41BE0777700DF0A17 /* Foundation.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -88,8 +79,7 @@
A753AE921BD588D800D269C7 = {
isa = PBXGroup;
children = (
A74C8EE31BE0777700DF0A17 /* Foundation.framework */,
A753AECC1BD5897900D269C7 /* Conekta */,
A753AECC1BD5897900D269C7 /* Conekta-Swift */,
A753AE9D1BD588D800D269C7 /* ConektaCardToken-Swift */,
A753AEB21BD588D800D269C7 /* ConektaCardToken-SwiftTests */,
A753AEBD1BD588D900D269C7 /* ConektaCardToken-SwiftUITests */,
@@ -138,15 +128,12 @@
path = "ConektaCardToken-SwiftUITests";
sourceTree = "<group>";
};
A753AECC1BD5897900D269C7 /* Conekta */ = {
A753AECC1BD5897900D269C7 /* Conekta-Swift */ = {
isa = PBXGroup;
children = (
8CFD48961D41831B001AB13C /* Card.swift */,
8CFD48981D4183A7001AB13C /* Conekta.swift */,
8CFD489A1D4187F1001AB13C /* Connection.swift */,
8CBEFF011D418EF800705729 /* Token.swift */,
BA72B8B81F04412600F18079 /* Conekta.swift */,
);
name = Conekta;
name = "Conekta-Swift";
sourceTree = "<group>";
};
/* End PBXGroup section */
@@ -217,15 +204,18 @@
TargetAttributes = {
A753AE9A1BD588D800D269C7 = {
CreatedOnToolsVersion = 7.0.1;
LastSwiftMigration = 0830;
};
A753AEAE1BD588D800D269C7 = {
CreatedOnToolsVersion = 7.0.1;
DevelopmentTeam = 3C6QZ8FN6B;
LastSwiftMigration = 0830;
TestTargetID = A753AE9A1BD588D800D269C7;
};
A753AEB91BD588D900D269C7 = {
CreatedOnToolsVersion = 7.0.1;
DevelopmentTeam = 3C6QZ8FN6B;
LastSwiftMigration = 0830;
TestTargetID = A753AE9A1BD588D800D269C7;
};
};
@@ -283,11 +273,8 @@
buildActionMask = 2147483647;
files = (
A753AEA11BD588D800D269C7 /* ViewController.swift in Sources */,
8CFD48991D4183A8001AB13C /* Conekta.swift in Sources */,
8CFD489B1D4187F1001AB13C /* Connection.swift in Sources */,
8CBEFF021D418EF800705729 /* Token.swift in Sources */,
8CFD48971D41831B001AB13C /* Card.swift in Sources */,
A753AE9F1BD588D800D269C7 /* AppDelegate.swift in Sources */,
BA72B8B91F04412600F18079 /* Conekta.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -443,6 +430,7 @@
PROVISIONING_PROFILE = "";
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
@@ -463,6 +451,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_VERSION = 3.0;
};
name = Release;
};
@@ -474,6 +463,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "Conekta.ConektaCardToken-SwiftTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ConektaCardToken-Swift.app/ConektaCardToken-Swift";
};
name = Debug;
@@ -486,6 +476,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "Conekta.ConektaCardToken-SwiftTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ConektaCardToken-Swift.app/ConektaCardToken-Swift";
};
name = Release;
@@ -497,6 +488,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "Conekta.ConektaCardToken-SwiftUITests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_TARGET_NAME = "ConektaCardToken-Swift";
USES_XCTRUNNER = YES;
};
@@ -509,6 +501,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "Conekta.ConektaCardToken-SwiftUITests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_TARGET_NAME = "ConektaCardToken-Swift";
USES_XCTRUNNER = YES;
};
Original file line number Diff line number Diff line change
@@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(application: UIApplication) {
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

Original file line number Diff line number Diff line change
@@ -1,22 +1,44 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6211" systemVersion="14A298i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6204"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="ConektaCardToken_Swift" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Token..." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="HKr-xJ-mfw">
<rect key="frame" x="16" y="323" width="343" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="trailingMargin" secondItem="HKr-xJ-mfw" secondAttribute="trailing" id="4Hf-Lv-RHC"/>
<constraint firstItem="HKr-xJ-mfw" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="cSW-3h-ceg"/>
<constraint firstItem="HKr-xJ-mfw" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" id="k3q-ar-TUy"/>
<constraint firstItem="HKr-xJ-mfw" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="wr6-mX-Tqn"/>
</constraints>
</view>
<connections>
<outlet property="tokenLabel" destination="HKr-xJ-mfw" id="jaV-29-p1d"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
Original file line number Diff line number Diff line change
@@ -10,34 +10,38 @@ import UIKit

class ViewController: UIViewController {

// MARK: - Outlets
@IBOutlet weak var tokenLabel: UILabel!

// MARK: - View Lifecycle
override func viewDidLoad() {
super.viewDidLoad()

let conekta = Conekta()

conekta.viewController = self

// 1: - Create the conekta object with the credit card info...
let conekta = Conekta(withNumber: "4242424242424242", name: "Pancho Conekta", cvc: "123", expMonth: "10", expYear: "2018")

// 2: - Add your public key (remember to use the specific key for the environment you are developing for (test - production)
conekta.publicKey = "key_KJysdbf6PotS2ut2"

//conekta.collectDevice()

let card = conekta.card("4242424242424242", name: "Julian Ceballos", cvc: "123", expMonth: "10", expYear: "2018")

let token = conekta.token(card)

token.create({ (response) in
print("Token response: \(response)")

// 3: - Set the conekta delegate...
conekta.delegate = self

// 4: - Collect the device session id...
conekta.collectDevice()

// 5: - Create the token for the card info...
conekta.createToken(onSuccess: { [weak self] token in
print("Success! Card Token: " + token)
self?.tokenLabel.text = token
}, onError: { [weak self] error in
print("Error: " + error.localizedDescription)
self?.tokenLabel.text = "Error: " + error.localizedDescription
})
{ (error) in
print("Token error: \(error)")
}
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


}

Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@
//

import XCTest
@testable import ConektaCardToken_Swift

class ConektaCardToken_SwiftTests: XCTestCase {

@@ -28,7 +27,7 @@ class ConektaCardToken_SwiftTests: XCTestCase {

func testPerformanceExample() {
// This is an example of a performance test case.
self.measureBlock {
self.measure {
// Put the code you want to measure the time of here.
}
}