iOS SDK

The iOS SDK is an SDK for integrating stera smart one into iOS apps.
This guide explains in detail how to integrate the SDK with your iOS app.

Supported versions

  • From iOS SDK 5.0, the SDK is split into ElepaySDK and independent plugins such as RPay / Checkout, which you add as needed. Starting with 5.0.5, SGP (ApplePay / CreditCard) processing is also supported.
  • From iOS SDK 4.0, iOS 11.0 is no longer supported. Bitcode support has also ended.
  • From iOS SDK 3.0, iOS 10.0 is no longer supported.
  • iOS SDK 2.x is compatible with iOS 10.0 and later.
  • Development environment: Use Xcode 11.0 or later.

Installation

1. Install with CocoaPods

From iOS SDK 5.0, use SPM (Swift Package Manager). If you have requests regarding other integration methods, contact the stera smart one team.

  1. Add ElepaySDK to your Podfile.
    Note: Use CocoaPods 1.10.0 or later.
# ElepaySDK versions earlier than 2.2 support only the dynamic frameworks format
# From 2.3, the static frameworks format is also supported
#use_frameworks!

# From 2.0.0, the SDK renamed from ElePay to ElepaySDK

pod 'ElepaySDK', '~> 3.0'
  1. Only if you use Chinese payment methods (Alipay, WeChat Pay, UnionPay), also add Elepay_ChinesePayments_Plugin.
# From 2.0.0, the SDK renamed from ElePay-ChinesePayments-Plugin to Elepay_ChinesePayments_Plugin

pod 'Elepay_ChinesePayments_Plugin', '~> 2.0'
  1. Only if you use Stripe and your SDK is 2.2.0 or later, add Stripe.
    Note: If you use SDK 2.x, add Stripe with pod 'Stripe', '~> 19.4.1'.
# Only ElepaySDK 3.0 and above supports Stripe 21.x
# Use "pod 'Stripe', '~> 19.4.1'" if you are using ElepaySDK 2.x

pod 'Stripe', '~> 22.0'

Because Stripe v23 dropped support for iOS 12, specify Stripe v22 or earlier for the SDK.

  1. Only if you use PayPal and your SDK is 1.7.0 or later, add Braintree.
    Note: SDK 4.0.0 and later no longer support Braintree. If you use PayPal, use SDK 3.x.
pod 'Braintree'
  1. Run pod install.

2. Install with Swift Package Manager (SPM)

From iOS SDK 5.0, SPM (Swift Package Manager) is the standard distribution method. If you have requests regarding other integration methods, contact the stera smart one team.

iOS SDK supports SPM from 3.1.1.
iOS SDK Chinese Payments Plugin supports SPM from 2.0.2.

  1. Add the SDK with SPM.
    Use this URL: https://github.com/elestyle/elepay-ios-sdk.git
    If you specify a version, specify 3.1.1 or later.

  2. Only if you use Chinese payment methods (Alipay, WeChat Pay, UnionPay), also add Elepay_ChinesePayments_Plugin.
    Use this URL: https://github.com/elestyle/elepay-ios-sdk-chinesepayments-plugin.git
    If you specify a version, specify 2.0.2 or later.

  3. If you use Stripe, add Stripe.
    Use this URL: https://github.com/stripe/stripe-ios.git
    If you specify a version, specify 21.8.1 or later.

  4. If you use PayPal, add Braintree.
    Note: The latest Braintree 5.x.x dropped support for iOS 11, so use 4.x.x. Because 4.x.x does not support SPM, install it with CocoaPods or manually.

3. Manual installation

You can add the SDK for iOS to your app in 7 steps.

  1. On Github.com, download ElePaySDK.zip and extract it.

  2. Add ElePay.framework to your Xcode project. Select "Copy items if needed" if necessary.

  3. In the target settings, add ElePay.framework to "Embedded Binaries".

  4. If you use Apple Pay in an Objective-C project, you also need to add PassKit.framework to "Embedded Binaries" in the target settings.

4. Using the SDK in an Objective-C project

When developing in Objective-C

To implement the SDK in an Objective-C project, use this
ElePayObjCBridge.swift file.

Implementation

1. Add a URL Scheme

In Xcode, open URL Types on the Info tab under PROJECT > TARGETS, and add the dedicated URL Scheme.

Common settings for stera smart one

For how to obtain the stera smart one URL Scheme, see "Get the URL Scheme for the iOS / Android SDK".

Test the URL Scheme

You can test whether the URL Scheme above (e.g., ep1a2b3c4d5e://) correctly launches the app by entering it in the address bar of Mobile Safari or Chrome.

Important

If you have multiple TARGETS, add the URL Scheme above to the URL Type of every target.

2. Settings for each payment method

See the Payment methods page.

3. Initialize stera smart one

Add the following initialization code to your project's application(_:didFinishLaunchingWithOptions:) function.

Elepay.initApp(key: "ELEPAY_APP_PUBLIC_KEY")

About the Public Key

Replace ELEPAY_APP_PUBLIC_KEY with the key issued on the stera smart one dashboard.

4. Configure the callback

Add the following code to the application(_:open:options:) -> Bool function.

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    // Let elepay Handle Result Callback from 3rd party payment Apps first.
    if (Elepay.handleOpenURL(url)) {
        // When ELEPay has already handled the URL, make sure your code returns here.
        return true;
    }

    // for no payment URL handle it in your own code here.
    return false;
}

5. Payment processing (one-time payments)

Your server-side processing

Start a one-time payment with the API charge endpoint /api/charges.
Because this API requires authentication, store the security key used for authentication on a server that you manage, and send requests from that server.

Security

For security, never store the security key in the app or transmit it to the app.

Native app processing

Pass the payload obtained from the API charge endpoint to the SDK as shown in the code below, and add the code that runs after the payment completes (or fails) to the callback from the SDK.

Use whichever of the following three methods is most convenient.

1. Charge with a JSON String

_ = Elepay.handlePayment(
  chargeJSON: jsonString, 
  cardParams: elepayCardParams, /* <- Optinal parameter, can be removed */
  viewController: viewController) { result in
    switch (result) {
    case let .succeeded(paymentId):
        // your code for handling successful situation
    case let .canceled(paymentId):
        // your code for handling canceled by user
    case let .failed(paymentId, error):
        // your code for handling failure situation
    }
}
Parameter nameDescription
chargeJSONA JSON object of type String that contains the payment data. It is created on the server side, and the iOS SDK processes the payment with this data.
cardParamsAn optional parameter that controls the credit card UI. The default is nil. When nil, the SDK's built-in credit card UI is used.
viewControllerThe UIViewController instance used to display the UI during payment.
completionA callback that reports the payment result.

2. Charge with JSON Data

_ = Elepay.handlePayment(
  chargeData: jsonData, 
  cardParams: elepayCardParams, /* <- Optinal parameter, can be removed */
  viewController: viewController) { result in
    switch (result) {
    case let .succeeded(paymentId):
        // your code for handling successful situation
    case let .canceled(paymentId):
        // your code for handling canceled by user
    case let .failed(paymentId, error):
        // your code for handling failure situation
    }
}
Parameter nameDescription
chargeDataA JSON object of type Data that contains the payment data. It is created on the server side, and the iOS SDK processes the payment with this data.
cardParamsAn optional parameter that controls the credit card UI. The default is nil. When nil, the SDK's built-in credit card UI is used.
viewControllerThe UIViewController instance used to display the UI during payment.
completionA callback that reports the payment result.

3. Charge with a JSON Dictionary

_ = Elepay.handlePayment(
  charge: jsonDictionary, 
  cardParams: elepayCardParams, /* <- Optinal parameter, can be removed */
  viewController: viewController) { result in
    switch (result) {
    case let .succeeded(paymentId):
        // your code for handling successful situation
    case let .canceled(paymentId):
        // your code for handling canceled by user
    case let .failed(paymentId, error):
        // your code for handling failure situation
    }
}
Parameter nameDescription
chargeA JSON object of type Dictionary that contains the payment data. It is created on the server side, and the iOS SDK processes the payment with this data.
cardParamsAn optional parameter that controls the credit card UI. The default is nil. When nil, the SDK's built-in credit card UI is used.
viewControllerThe UIViewController instance used to display the UI during payment.
completionA callback that reports the payment result.

6. Payment processing (recurring payments / wallet payments)

Your server-side processing

Start source registration with the API source endpoint customers/<_customerId_>/sources.
Because this API requires authentication, store the security key used for authentication on a server that you manage, and send requests from that server.

Native app processing

Pass the payload obtained from the API source endpoint to the SDK as shown in the code below, and add the code that runs after the payment completes (or fails) to the callback from the SDK.

Use whichever of the following three methods is most convenient.

1. When you obtain the source as a JSON String

_ = Elepay.handleSource(
  sourceJSON: jsonString, 
  cardParams: elepayCardParams, /* <- Optinal parameter, can be removed */
  viewController: viewController) { (result) in
    switch (result) {
    case let .succeeded(sourceId):
        // your code for handling successful situation
    case let .canceled(sourceId):
        // your code for handling canceled by user
    case let .failed(sourceId, error):
        // your code for handling failure situation
    }
 }
Parameter nameDescription
sourceJSONA JSON object of type String that contains the source data. It is created on the server side, and the iOS SDK processes the payment with this data.
cardParamsAn optional parameter that controls the credit card UI. The default is nil. When nil, the SDK's built-in credit card UI is used.
viewControllerThe UIViewController instance used to display the UI during payment.
completionA callback that reports the payment result.

2. When you obtain the source as JSON Data

_ = Elepay.handleSource(
  chargeData: jsonData, 
  cardParams: elepayCardParams, /* <- Optinal parameter, can be removed */
  viewController: viewController) { (result) in
    switch (result) {
    case let .succeeded(sourceId):
        // your code for handling successful situation
    case let .canceled(sourceId):
        // your code for handling canceled by user
    case let .failed(sourceId, error):
        // your code for handling failure situation
    }
 }
Parameter nameDescription
sourceDataA JSON object of type Data that contains the source data. It is created on the server side, and the iOS SDK processes the payment with this data.
cardParamsAn optional parameter that controls the credit card UI. The default is nil. When nil, the SDK's built-in credit card UI is used.
viewControllerThe UIViewController instance used to display the UI during payment.
completionA callback that reports the payment result.

3. When you obtain the source as a JSON Dictionary

_ = Elepay.handleSource(
  source: jsonDictionary, 
  cardParams: elepayCardParams, /* <- Optinal parameter, can be removed */
  viewController: viewController) { (result) in
    switch (result) {
    case let .succeeded(sourceId):
        // your code for handling successful situation
    case let .canceled(sourceId):
        // your code for handling canceled by user
    case let .failed(sourceId, error):
        // your code for handling failure situation
    }
 }
Parameter nameDescription
sourceA JSON object of type Dictionary that contains the source data. It is created on the server side, and the iOS SDK processes the payment with this data.
cardParamsAn optional parameter that controls the credit card UI. The default is nil. When nil, the SDK's built-in credit card UI is used.
viewControllerThe UIViewController instance used to display the UI during payment.
completionA callback that reports the payment result.

Checkout feature

With the Checkout feature, you can skip developing a payment method selection screen and use the payment method selection screen and other screens provided by the SDK.

You can see what the payment method screens look like in the screenshot below. Dark mode is also supported.

Server-side processing

Create a checkout payload with the API code endpoint.
For details, see the API reference.

Native app processing

Pass the payload obtained from the API code endpoint to the SDK, and let the SDK complete the checkout process.

Three methods are provided to match the payload type.
Sample code and method descriptions are shown below.

1. Check out with a JSON String

Elepay.checkout(
  checkoutJSONString: checkoutJSONString, 
  from: viewController
) { result in
   switch (result) {
   case .succeeded(let codeId):
     // checkout is succeeded.
   case .cancelled(let codeId):
     // checkout is canceled.
   case let .failed(let codeId, let error):
     // checkout is failed.
   }
}
Parameter nameDescription
checkoutJSONStringA JSON object of type String that contains the checkout data. It is created on the server side, and the iOS SDK processes the payment with this data.
fromThe UIViewController instance used to display the UI during payment.
resultHandlerA callback that reports the payment result.

2. Check out with JSON Data

Elepay.checkout(
  checkoutJSONData: checkoutJSONData, 
  from: viewController
) { result in
   switch (result) {
   case .succeeded(let codeId):
     // checkout is succeeded.
   case .cancelled(let codeId):
     // checkout is canceled.
   case let .failed(let codeId, let error):
     // checkout is failed.
   }
}
Parameter nameDescription
checkoutJSONDataA JSON object of type Data that contains the checkout data. It is created on the server side, and the iOS SDK processes the payment with this data.
fromThe UIViewController instance used to display the UI during payment.
resultHandlerA callback that reports the payment result.

3. Check out with a JSON Dictionary

Elepay.checkout(
  checkoutJSON: checkoutJSON, 
  from: viewController
) { result in
   switch (result) {
   case .succeeded(let codeId):
     // checkout is succeeded.
   case .cancelled(let codeId):
     // checkout is canceled.
   case let .failed(let codeId, let error):
     // checkout is failed.
   }
}
Parameter nameDescription
checkoutJSONA JSON object of type Dictionary that contains the checkout data. It is created on the server side, and the iOS SDK processes the payment with this data.
fromThe UIViewController instance used to display the UI during payment.
resultHandlerA callback that reports the payment result.

Error handling

The SDK returns various types of errors (Error) through the callback.

For a better user experience, we recommend showing users the error information of case unsupportedPaymentMethod(errorCode: String, paymentMethod: String).

Sample code

switch (result) {
case .succeeded(let codeId):
    // checkout is succeeded.
case .cancelled(let codeId):
    // checkout is canceled.
case let .failed(let codeId, let error):
    switch error {
    case let .unsupportedPaymentMethod(errorCode, method):
        if errorCode == "10110" {   // 3rd party App not installed error
            print("The \(method) App is not installed for payment processing. Please install the app first or selected another payment method.")
        } if errorCode == "10100" {   // The device or the iOS system is too old to use this payment method
            print("Your device is too old to use \(method)")
        } else {    // Other error codes. Such as: a new payment method not supported by current SDK. The App using elepay SDK need to be updated
            print("Your App need to be updated to use \(method)")
        }
    default:
        // other error handling code
    }
}

See Error codes for the list of error codes.

Notes

Handling payment results

Use the payment result in the app only to show the result to the user. Always confirm the actual charge result through the callback API on your server, using the data sent from the stera smart one server. See the API guide for details.

1. Apple Pay

  1. When implementing Apple Pay, click the Capabilities tab under PROJECT → TARGETS in Xcode and set Apple Pay to "ON".

  1. Upload your Apple Pay certificate in "stera smart one dashboard" - "開発設定" (Developer settings) - "Apple Pay".
    For how to create the certificate, see this document.

2. LSApplicationQueriesSchemes (iOS 9 and later)

To switch to each payment app, add the LSApplicationQueriesSchemes key on the Info tab (or in Info.plist) under PROJECT → TARGETS in Xcode.

<key>LSApplicationQueriesSchemes</key>
	<array>
	    <string>**Add the scheme of each app**</string>
	</array>

Settings for each payment method

See the Payment methods page.

Localization

The iOS SDK supports multiple languages (currently English, Japanese, Simplified Chinese, and Traditional Chinese).

By default, the SDK displays the language that matches the iOS system setting.

Specify the display language

To display a language different from the system setting, specify the language with the following code.

ElepayLocalization.shared.switchLanguage(code: .ja)	// Use Japanese

ElepayLocalization.shared.switchLanguage(code: .en)	// Use English

ElepayLocalization.shared.switchLanguage(code: .cn)	// Use Simplified Chinese

ElepayLocalization.shared.switchLanguage(code: .tw)	// Use Traditional Chinese

You can call this switchLanguage function any number of times. Screens displayed after the function is called are shown in the specified language.

The display language cannot be specified for some screens

Some payment methods may transition to third-party screens. Because those screens are outside the SDK's control, they may be displayed in a language different from the one you specified.

Last updated on

On this page