github.com/JudoPay/Judo-Swift

Judo Swift SDK for Swift 2.2/Xcode 7.3


License
MIT

Documentation

Stories in Ready CocoaPods Compatible Carthage Compatible License Platform Twitter Build Status

judoNative SDK for Swift

This is the new judoNative Swift SDK. It contains base work to easily access the REST API with all the validation and helper methods needed to make simple payments with a fully custom UI. If you are interested in a simple integration of payments without having to implement a full custom UI, fraud prevention, 3DS, AVS, etc as well as PCI compliance yourself, have a look at the judoKit project which contains this as a base module.

If you still would like to implement everything yourself, we strongly recommend you to use the judoSecure Framework and send device related information along with transaction requests to ensure safety and fraud security for all your payments.

***Due to industry-wide security updates, versions below 1.5.1 of this SDK will no longer be supported after 1st Oct 2016. For more information regarding these updates, please read our blog here.***

What is this project for?

The judoNative Swift SDK is a framework for accessing the judoPay backend API for making and accepting payments inside your app as easy and frictionless as possible.

Integration

Sign up judo's platform

  • To use judo SDKs, you'll need to sign up and get your app token.
  • the SDK has to be integrated into your project using one of the following methods:

CocoaPods

CocoaPods is a dependency manager for Cocoa projects.

CocoaPods 0.39 supports Swift and embedded frameworks. You can install it with the following command:

$ gem install cocoapods

add judo to your Podfile to integrate it into your Xcode project:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'Judo', '~> 2.0'

Then, run the following command:

$ pod install

Carthage

Carthage - decentralized dependency management.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage
  • To integrate judo into your Xcode project using Carthage, specify it in your Cartfile:
github "JudoPay/Judo-Swift" >= 2.0
  • On your application targets’ “General” settings tab, in the “Linked Frameworks and Libraries” section, drag and drop each framework you want to use from the Carthage/Build folder on disk.
  • On your application targets’ “Build Phases” settings tab, click the “+” icon and choose “New Run Script Phase”. Create a Run Script with the following contents:
/usr/local/bin/carthage copy-frameworks

And add the paths to the frameworks you want to use under “Input Files”, e.g.:

$(SRCROOT)/Carthage/Build/iOS/Judo.framework

Manual integration

You can integrate judo into your project manually if you prefer not to use dependency management.

Adding the framework

  • Add judo as a submodule by opening the Terminal, changing into your project directory, and entering the following command:
$ git submodule add https://github.com/JudoPay/Judo-Swift

To initiate the submodule you have to execute the following command

$ git submodule update --init
  • Open the new Judo folder, and drag the Judo.xcodeproj into the Project Navigator of your application's Xcode project.
  • Select the Judo.xcodeproj in the Project Navigator and verify the deployment target matches that of your application target.
  • Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the "Targets" heading in the sidebar.
  • In the tab bar at the top of that window, open the "General" panel.
  • Click on the + button under the "Embedded Binaries" section.
  • Select Judo.framework nested inside the Products folder on the top.

Further setup

  • Add import Judo to the top of the file where you want to use the SDK.

  • To instruct the SDK to communicate with the sandbox, include the following line myJudoSession.sandboxed = true. When you are ready to go live you can remove this line. We would recommend you to put this in your Root ViewController implementation and pass it as a parameter to every subsequent class that uses Judo.

  • You can also set your key and secret here if you do not wish to include it in all subsequent calls myJudoSession.setToken(token:, secret:).

Examples

Token and Secret

The token and secret are accessible from your judo account here. After you have created an app you can either generate sandbox or live tokens. We recommend you to set this in your AppDelegate in the didFinishLaunchingWithOptions method.

let token = "a3xQdxP6iHdWg1zy"
let secret = "2094c2f5484ba42557917aad2b2c2d294a35dddadb93de3c35d6910e6c461bfb"

...
let myJudoSession = Judo()

// myJudoSession.didSetTokenAndSecret() returns false

...
let myJudoSession = Judo(token, secret: secret)

// myJudoSession.didSetTokenAndSecret() returns true

Make a simple payment

The judoNative Swift SDK takes a reactive approach.

Card payment
let myJudoSession = Judo("your token", secret: "your secret")
...

let judoID = "100111222"
let references = Reference(yourConsumerReference: "consumer0053252")
let card = Card(number: "4976000000003436", expiryDate: "12/20", cv2: "452")
let amount = Amount(amountString: "30", currency: .GBP)
let emailAddress = "hans@email.com"
let mobileNumber = "07100000000"

let judoShield = JudoShield()

self.judoShield.locationWithCompletion { (coordinate, error) -> Void in
    if let error = error {
        self.delegate?.payViewController(self, didEncounterError: error)
    } else {
        self.currentLocation = coordinate
    }
}

let deviceSignal = judoShield.deviceSignal()

do {
    let makePayment = try myJudoSession.payment(correctJudoID, amount: amount, reference: references)
                                       .card(card)
                                       .location(location)
                                       .deviceSignal(deviceSignal)
                                       .contact(mobileNumber, emailAddress)
                                       .completion({ (data, error) -> () in
                                           if let _ = error {
                                               // failure
                                           } else {
                                               // success
                                           }
                                       })
} catch {
    // error creating a Transaction e.g. the judoID could be in a wrong format
}
Token payment
let myJudoSession = Judo("your token", secret: "your secret")
...
myJudoSession.payment(correctJudoID, amount: amount, reference: references)
             .paymentToken(payToken)
             .location(location)
             .deviceSignal(deviceSignal)
             .contact(mobileNumber, emailAddress)
             .completion({ (data, error) -> () in
                 if let _ = error {
                     // failure
                 } else {
                     // success
                 }
             })

Notice that the only difference is calling .paymentToken(payToken) with a valid PaymentToken instead of .card(card) for making a token payment instead of a card payment. This process is the same for pre-authorizations and token pre-authorizations.

Card pre-authorization
let myJudoSession = Judo("your token", secret: "your secret")
...
myJudoSession.preAuth(correctJudoID, amount: amount, reference: references)
             .card(card)
             .location(location)
             .deviceSignal(deviceSignal)
             .contact(mobileNumber, emailAddress)
             .completion({ (data, error) -> () in
                 if let _ = error {
                     // error
                 } else {
                     // success
                 }
             })
Token pre-authorization
let myJudoSession = Judo("your token", secret: "your secret")
...
myJudoSession.preAuth(correctJudoID, amount: amount, reference: references)
             .paymentToken(payToken)
             .location(location)
             .deviceSignal(deviceSignal)
             .contact(mobileNumber, emailAddress)
             .completion({ (data, error) -> () in
                 if let _ = error {
                     // error
                 } else {
                     // success
                 }
             })

License

Judo-Swift is released under the MIT license. See LICENSE for details.

Contact

  • Ben Riazy
  • Ben King