Skip to content

Unofficial Openpay API client for iOS written in Swift.

Notifications You must be signed in to change notification settings

Pacific3/SwiftyOpenPay

Repository files navigation

SwiftyOpenPay

Carthage compatible ![SwiftyOpenPay v0.2.1](https://img.shields.io/badge/Latest Version-v0.4-brightgreen.svg)

SwiftyOpenPay is an unofficial OpenPay API client for iOS written in Swift.

Use at your own risk.

Installation

SwiftyOpenPay can be installed using Carthage.

In your Cartfile, include SwiftyOpenPay:

github "Pacific3/SwiftyOpenPay" ~> 0.4

Then, update:

$ carthage update

Drag all the .framework files at Carthage/Build/iOS to your target's Linked Frameworks and Libraries section.

Usage

import SwiftyOpenPay

let myAddress = Address(
    line1: "1 Infinite Loop",
    city: "Cupertino",
    state: "California",
    countryCode: "US",
    postalCode: "95014"
)

let myCard = Card(
    holderName: "John Doe",
    expirationMonth: "12",
    expirationYear: "19",
    address: myAddress,
    number: "XXXXXXXXXXXX"
)

let configuration = SwiftyOpenPay.Configuration(
    merchantId: "MyMerchantId",
    apiKey: "MyAPIKey",
    sandboxMode: true,
    verboseMode: true
)

let openPay = SwiftyOpenPay(configuration: configuration)

do {
    try openPay.createTokenWithCard(myCard,
        completion: { token in
            print(token.id)
        },
        error: { error in
            print(error)
        }
    )
} catch {
    print(error)
}

You can either crate a SwiftyOpenPay instance using a SwiftyOpenPay.Configuration, or passing the values directly to the initializer.

sandboxMode and verboseMode default to false. Both of them can be omitted from the constructors.

Disclaimer

SwiftyOpenPay is not an oficial Openpay product. Openpay is not responsible for either this code or what you use it for. The use of SwiftyOpenPay is your and only your responsability.

Openpay does provide an officially supported version of their iOS API client, which can be found over at their GitHub page.

Refer to Openpay's Privacy Notice and Terms of Service.