Coder Social home page Coder Social logo

omise-ios's Introduction

Omise iOS SDK

Carthage compatible

See v1 branch for the previous version.

Omise is a payment service provider currently operating in Thailand. Omise provides a set of clean APIs that helps merchants of any size accept credit cards online.

Omise iOS SDK provides bindings for the Omise Tokenization API so you do not need to pass credit card data to your server as well as components for entering credit card information.

Hop into the Gitter chat (click the badge above) or email our support team if you have any question regarding this SDK and the functionality it provides.

Requirements

Merchant Compliance

Card data should never transit through your server. We recommend that you follow our guide on how to safely collect credit information.

To be authorized to create tokens server-side you must have a currently valid PCI-DSS Attestation of Compliance (AoC) delivered by a certified QSA Auditor.

This SDK provides means to tokenize card data on end-user mobile phone without the data having to go through your server.

Installation

Add the following line to your Cartfile:

github "omise/omise-ios" ~> 2.1

And run carthage bootstrap or carthage build Or run this copy-pastable script for a quick start:

echo 'github "omise/omise-ios" ~> 2.0' >> Cartfile
carthage bootstrap

Usage

If you clone this project to your local hard drive, you can also checkout the QuickStart playground. Otherwise if you'd like all the details, read on:

Credit Card Popover

The fastest way to get started with this SDK is to display the provided CreditCardFormController as popover from your application. The CreditCardFormController provides a pre-made credit card form and will automatically tokenize credit card information for you. You only need to implement two delegate methods and a way to display the form.

To use the controller in popover mode, modify your view controller with the following additions:

import OmiseSDK // at the top of the file

class ViewController: UIViewController {
  private let publicKey = "pkey_test_123"

  @IBAction func displayCreditCardForm() {
    let closeButton = UIBarButtonItem(title: "Close", style: .Done, target: self, action: #selector(dismissCreditCardPopover))

    let creditCardView = CreditCardFormController(publicKey: publicKey)
    creditCardView.delegate = self
    creditCardView.handleErrors = true
    creditCardView.navigationItem.rightBarButtonItem = closeButton

    let navigation = UINavigationController(rootViewController: creditCardView)
    presentViewController(navigation, animated: true, completion: nil)
  }

  @objc func dismissCreditCardPopover() {
    presentedViewController?.dismissViewControllerAnimated(true, completion: nil)
  }
}

Then implement the delegate to receive the OmiseToken object after user has entered the credit card data:

extension ViewController: CreditCardFormDelegate {
  func creditCardPopover(creditCardPopover: CreditCardPopoverController, didSucceededWithToken token: OmiseToken) {
    dismissCreditCardPopover()

    // Sends `OmiseToken` to your server for creating a charge, or a customer object.
  }

  func creditCardPopover(creditCardPopover: CreditCardPopoverController, didFailWithError error: ErrorType) {
    dismissCreditCardPopover()

    // Only important if we set `handleErrors = false`.
    // You can send errors to a logging service, or display them to the user here.
  }
}

Alternatively you can also push the view controller onto a UINavigationController stack like so:

@IBAction func displayCreditCardForm() {
  let creditCardView = CreditCardFormController(publicKey: publicKey)
  creditCardView.delegate = self
  creditCardView.handleErrors = true

  navigationController?.pushViewController(creditCardView, animated: true)
}

Custom Credit Card Form

You can make use of the SDK's text field components to build your own forms:

  • CardNumberTextField - Provides basic number grouping as the user types.
  • CardNameTextField
  • CardExpiryDatePicker - UIPickerView implementation that have a month and year column.
  • CardCVVTextField - Masked number field.

Additionally fields also turns red automatically if their content fails basic validation (e.g. alphabets in number field, or content with wrong length)

Manual Tokenization

If you build your own credit card form, you will need to use OmiseSDKClient to manually tokenize the contents. You can do so by first creating and initializing an OmiseTokenRequest like so:

let request = OmiseTokenRequest(
  name: "John Smith",
  number: "4242424242424242",
  expirationMonth: 10,
  expirationYear: 2019,
  securityCode: "123"
)

Then initialize an OmiseSDKClient with your public key and send the request:

let client = OmiseSDKClient(publicKey: publicKey)
client.send(request) { [weak self] (token, error) in
  guard let s = self else { return }

  // check `error` or send `token` to your server.
}

Alternatively, delegate style is also supported:

client.send(request, Handler())

class Handler: OmiseTokenRequestDelegate {
  func tokenRequest(request: OmiseTokenRequest, didSucceedWithToken token: OmiseToken) {
    // handles token
  }

  func tokenRequest(request: OmiseTokenRequest, didFailWithError error: ErrorType) {
    // handle errors
  }
}

Contributing

Pull requests and bugfixes are welcome. For larger scope of work, please pop on to our chatroom to discuss first.

LICENSE

MIT (See the (full license text)[https://github.com/omise/omise-ios/blob/master/LICENSE])

omise-ios's People

Watchers

 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.