Git Product home page Git Product logo

tokenex-ios's Introduction

TokenEx iOS SDK

CocoaPods Carthage compatible License Platform

The TokenEx iOS SDK makes it simple to access the TokenEx Mobile API from any Swift or Objective-C project.

Getting started

Add the framework

Add the framework to your project:

  • Swift Package Manager (SPM, SwiftPM): Add the URL of this repository as Package Dependency

    1. Select your XCode project in the Project navigator.
    2. Make sure the Project is selected in the Editor and switch to the tab "Package Dependencies".
    3. Click "+" and enter https://github.com/ixopay/tokenex-ios.git in the top right.
    4. Click "Add Package"
  • CocoaPods:

    1. Create a Podfile: pod init
    2. Edit the Podfile to add a dependency:
    target 'MyExampleProject' do
      use_frameworks!
    
      pod 'TokenExMobileAPI', '~> 1.0.0'
    end
    1. Install your project dependencies:
    pod install
    1. Re-open your XCode project:
    open ./MyExampleProject.xcworkspace
  • Carthage:

    1. Create a Cartfile in your project directory:
    github "ixopay/tokenex-ios.git" ~> 1.0.0
    
    1. Run:
    carthage update --use-xcframeworks
    1. Add the built package in ./Carthage/Build/TokenExMobileAPI.xcframework as framework dependency to your app.

Integration

  1. Provide your TokenEx ID:

    // Make sure the environment matches your TokenEx ID
    // i.e. for test IDs use the test environment, the default is the production environment
    TokenExMobileAPI.defaultEnvironment = TokenExMobileAPIEnvironment.production
    TokenExMobileAPI.defaultTokenExID = "YourTokenExID"
  2. Implement the protocol TXAuthenticationKeyProvider. The implementation should call your backend server to get an authentication key.

    internal class MyMerchantBackendAuthenticationKeyProvider : TXAuthenticationKeyProvider {
      internal func fetchAuthenticationKey(tokenExID: String, tokenSchemeOrToken: String) throws -> TXAuthentication {
        // Call your backend server with the tokenSchemeOrToken (and optionally your TokenEx ID to help you identify the client secret key)
        // For example code for your backend see https://docs.tokenex.com/docs/generating-the-authentication-key-1
    
        return TXAuthentication(key: "HMAC_RETURNED_BY_YOUR_SERVER", timestamp: TIMESTAMP_RETURNED_BY_YOUR_SERVER)
      }
    }

    Then configure the API client to use it:

    TokenExMobileAPI.defaultAuthenticationKeyProvider = MyMerchantBackendAuthenticationKeyProvider()
    1. Use the TXMobileAPIClient:
    let tokenResponse = try await TXMobileAPIClient.shared.tokenizeWithCVV(
      TXTokenizeCVVRequest(
        data: "5454545454545454",
        tokenScheme: TXTokenScheme.PCI,
        cvv: "123"
      )
    )
    
    print(tokenResponse.token)

Optionally, you can also provide a TokenExMobileAPI.defaultTokenHMACProvider that implements TXTokenHMACProvider and uses your backend to generate HMACs to validate TokenEx responses. See Validating the Token HMAC for more details.

Note: It's also possible to instantiate a TXMobileAPIClient without using the default values in TokenExMobileAPI.

Example

This project contains an example iOS app in TokenExMobileSample.

To use the demo app you need to provide your TokenEx ID and customer secret key in one of two ways:

  1. Edit your XCode build scheme to include the environment variables:
    APP_ENVIRONMENT="local"
    TOKENEX_ID="YourTokenExID"
    TOKENEX_ENVIRONMENT="test" # or production
    TOKENEX_CUSTOMER_SECRET="Customer secret from portal"
  2. Enter your login credentials in the Settings tab inside the app.

Code style

  • We use swiftlint to enforce code style.
  • Install switflint with brew install swiftlint
  • Install just

License

MIT

tokenex-ios's People

Watchers

Patrick avatar Stefan Schlesinger avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.