SDK UI & Core for iOS

Overview

Introduction

Mobile SDK UI & Core for iOS is a software development kit that can be used to integrate iOS applications with the ecommpay payment platform.

SDK UI & Core for iOS provides the functionality for interaction of customers with the user interface and for interaction of a mobile application with the payment platform which allows sending and receiving necessary information during payment processing.

This article describes how to work with SDK UI & Core for iOS and provides code examples in Swift and Objective-C.

SDK UI & Core for iOS can be embedded in mobile applications developed for iOS version 14 or later. The SDK UI & Core for iOS libraries and code examples are available on GitHub. To access, use the following URLs:

Capabilities

The following functional capabilities are supported by SDK UI & Core for iOS:

  • Processing purchases with immediate debiting of funds, made with payment cards and alternative payment methods available for the merchant's project.
  • Registering COF purchases.
  • Saving payment data for subsequent payment processing.
  • Submitting additional payment information.
  • Cascade payment processing.
  • Collecting customer data.
  • Checking current payment information.
  • Sending email notifications with the list of purchased items to customers after the payment has been processed.
  • Customising the colour of the payment interface.
  • Adding the logo of the merchant.

In case of card and Apple Pay payments, the payment interface described in this article is used. With other payment methods, Payment Page is used during payment processing.

Workflow

Generally, the following workflow is relevant when purchases are processed with the use of SDK UI & Core for iOS.

  1. In the user interface of a mobile application, the customer initiates a purchase by clicking the payment button or in a different fashion set up on the merchant side.
  2. In the mobile application, a set of parameters for creating a payment session is generated. Then, with the help of SDK UI & Core for iOS, this set is converted into a string for signing, and the string is sent to the server side of the merchant web service.
  3. On the server side of the merchant web service, the parameters can be checked and supplemented if necessary, and the signature to the final parameter set is generated, following which the prepared data is sent back to SDK UI & Core for iOS.
  4. With the help of SDK UI & Core for iOS, a payment session is initiated in the payment platform.
  5. On the payment platform side, the payment interface is prepared in accordance with the invocation parameters, and the data for opening the interface is passed to the customer's device.
  6. In the mobile application, the payment form is displayed to the customer.
  7. The customer selects a payment method (if no method was selected when the payment session was initiated), specifies the necessary information, and confirms the purchase.
  8. SDK UI & Core for iOS sends a purchase request to the payment platform.
  9. On the payment platform side, the payment is registered and all necessary technical actions are performed; these actions include sending the required data to the payment environment—to the providers and payment systems.
  10. The payment is processed in the payment environment. Then the payment result information is received in the payment platform.
  11. In the payment platform, the information about the payment result is processed and a callback is sent to the server side of the web service.
  12. The information about the purchase result is sent from the payment platform to SDK UI & Core for iOS.
  13. The notification with the result information is displayed to the customer in the user interface.

Interface

When card and Apple Pay payments are processed, the customer interacts with the user interface designed by the ecommpay specialists. This user interface can be customised: you can change its colour and add your company's logo.

Setup

Integration steps

To integrate the web service with the ecommpay payment platform by using SDK UI & Core for iOS:

  1. Address the following organisational issues of interaction with ecommpay:
    1. If your company has not obtained a project identifier and a secret key for interacting with ecommpay, submit the application for connecting to the ecommpay payment platform.
    2. If your company has obtained a project identifier and a secret key for interacting with ecommpay, inform the technical support specialists about the company's intention to integrate by using SDK UI & Core for iOS and coordinate the procedure of testing and launching the functionality.
  2. Complete the following preliminary technical steps:
    1. Download and link the SDK UI & Core for iOS libraries.
    2. Ensure the collection of data necessary for opening the payment form. The minimum data set needed in order to open the payment form consists of the project, payment, and customer identifiers as well as of the payment amount and currency.
    3. Ensure signature generation for the data on the server side of the mobile application.
    4. Ensure the receipt of and the response to the notifications from SDK UI & Core for iOS as well as the receipt of and the response to the callbacks from the payment platform on the web service side.
  3. With the technical support specialists, coordinate the timeline and the main steps of integrating, testing (including testing available payment methods), and launching the solution.
    1. For testing, use the test project identifier and the details of test cards.
    2. For switching to the production mode, change the value of the test project identifier to the value of the production project identifier received from ecommpay.

If you have any questions about working with SDK UI & Core for iOS, contact the ecommpay technical support specialists (support@ecommpay.com).

Importing libraries in Swift

To add a library into your iOS app:

  1. Copy the ecommpaySDK.xcframework file in the project folder of you iOS app.
  2. Add the library into your project. When using Xcode 12, you need to do the following:
    1. Open the target of your project.
    2. Select General > Embedded Binaries.
    3. Click +.
    4. Click Add Other.
    5. Select the ecommpaySDK.xcframework file and click Add.
  3. Add key NSCameraUsageDescription with value permission is needed in order to scan card to the Info.plist file.
  4. If your iOS app does not use user location information, add the NSLocationWhenInUseUsageDescription key with the fraud prevention value in the Info.plist file.

    The ecommpay libraries code does not request user location if the request is not initiated by the host app, but the App Store requires that the NSLocationWhenInUseUsageDescription key value is not empty.

    If your iOS app requests user location information, you can skip this step.

  5. If the iOS app does not have permission to save data on the mobile device, add Privacy - Photo Library Usage Description and Privacy - Photo Library Additions Usage Description keys with values to the Info.plist file. The values specified are shown to the customer in the permission request message.

Importing libraries in Objective-C

To add a library into your iOS app:

  1. Copy the ecommpaySDK.xcframework file in the project folder of you iOS app.
  2. Add the library into your project. When using Xcode 12, you need to do the following:
    1. Open the target of your project.
    2. Select General > Embedded Binaries.
    3. Click +.
    4. Click Add Other.
    5. Select the ecommpaySDK.xcframework file and click Add.
    6. Select Build Settings.
    7. Set Always embed swift embedded libraries to Yes.
  3. Add key NSCameraUsageDescription with value permission is needed in order to scan card to the Info.plist file.
  4. If your iOS app does not use user location information, add the NSLocationWhenInUseUsageDescription key with the fraud prevention value in the Info.plist file.

    The ecommpay libraries code does not request user location if the request is not initiated by the host app, but the App Store requires that the NSLocationWhenInUseUsageDescription key value is not empty.

    If your iOS app requests user location information, you can skip this step.

  5. If the iOS app does not have permission to save data on the mobile device, add Privacy - Photo Library Usage Description and Privacy - Photo Library Additions Usage Description keys with values to the Info.plist file. The values specified are shown to the customer in the permission request message.

Importing libraries via Cocoapods

To add a library into your iOS app:

  1. Open the Podfile file and add the following strings:
    target 'App' do
      # Pods for App
      pod 'EcommpaySDK_UI', '2.0.0'
    end
  2. Add key NSCameraUsageDescription with value permission is needed in order to scan card to the Info.plist file.
  3. If your iOS app does not use user location information, add the NSLocationWhenInUseUsageDescription key with the fraud prevention value in the Info.plist file.

    The ecommpay libraries code does not request user location if the request is not initiated by the host app, but the App Store requires that the NSLocationWhenInUseUsageDescription key value is not empty.

    If your iOS app requests user location information, you can skip this step.

  4. If the iOS app does not have permission to save data on the mobile device, add Privacy - Photo Library Usage Description and Privacy - Photo Library Additions Usage Description keys with values to the Info.plist file. The values specified are shown to the customer in the permission request message.

Signature generation

Make sure that the data is signed on the server side of the web service with the use of the secret key received from ecommpay. To work with the signature, you can use ready-to-use components, such as language-specific SDKs for web services (details), or your own in-house solutions. The procedure of working with the signature is described in Signature generation and verification.

Testing

If necessary, you can open the payment form in the test mode in order to get information about errors if there were any when payment parameters were specified or to test processing payments with a certain payment result. When creating the request to open the payment form, in the PaymentOptions object specify the following values for the mockModeType parameter (the values are listed for Swift and Objective-C respectively):

  • MockModeType.success / MockModeTypeSuccess—if you need to receive Success payment result.
  • MockModeType.decline / MockModeTypeDecline—if you need to receive Decline payment result.

If you need to switch to the production mode, pass MockModeType.disabled / MockModeTypeDisabled as a value for the mockModeType parameter.

You can also test payment processing in the test environment of the ecommpay payment platform. In this case, you should get access to the ecommpay test environment (it can be done via the company's website) and use the identifier and the secret key of the test project as values of the required parameters passed in the request to open the payment form.

The code samples that are provided on Github contain constants for these parameters

Figure: Swift

 let secret = "your_secret" // secret key of the test project
    let project_id: Int32 = 10 // identifier of the test project

Figure: Objective-C

#define SECRET @"your_secret" // secret key of the test project
#define PROJECT_ID 10 // identifier of the test project

To switch to the production mode, change the test values (the identifier and the secret key of the test project) to the production ones.

Use

Opening payment form

SDK UI & Core for iOS supports such actions as performing one-time purchases and registering COF purchases. To initiate these actions, you need a certain parameter set. The required minimum of parameters is passed in the PaymentOptions object. Optional parameters can be passed in the same object. In addition, they can also be requested from the customer or received from the payment platform.

Opening the payment form in Swift

To open the payment form:

  1. Import the library:
    import ecommpaySDK
  2. Declare the EcommpaySDK library in you app (for example, inside the viewDidLoad method):
    let ecommpaySDK = EcommpaySDK()
  3. Create an object named PaymentOptions. This object must contain the following required parameters:
    • projectId (integer)—a project identifier assigned by ecommpay
    • paymentId (string)—a payment identifier unique within the project
    • paymentCurrency (string)—the payment currency code in the ISO 4217 alpha-3 format
    • paymentAmount (integer)—the payment amount in the smallest currency units
    • customerId (string)—a customer's identifier within the project

    You can also add any other parameters listed in the following section.

    The following is an example of the PaymentOptions object that includes optional parameters (description of the payment and the customer's country)

    let paymentOptions = PaymentOptions(projectID: 10,
                                paymentID: "internal_payment_id_1",
                                paymentAmount: 1999,
                                paymentCurrency: "USD",
                                paymentDescription: "T-shirt with dog print",
                                customerID: "10",
                                regionCode: "US")
  4. Pack all payment parameters into a string for signing:
    paymentOptions.paramsForSignature();
  5. Send the string to the server side of your web service.
  6. Have your web service generate the signature on the basis of the string and your secret key.
  7. Add signature in your PaymentOptions object:
    paymentOptions.signature = signature;
  8. Open the payment form by using the following code:
    ecommpaySDK.presentPayment(at: self, paymentOptions: paymentOptions) { result in
             print("ecommpaySDK finished with status \(result.status.rawValue)")
       ...
     }

    Before opening the payment form, the library checks for any errors and opens the payment form only if no errors occur. Otherwise, the payment form is not opened and the presentPayment method returns the error code.

Opening the payment form in Objective-C

To open the payment form:

  1. Import the library:
    #import <EcommpaySDK/EcommpaySDK.h>
  2. Declare the EcommpaySDK library in you app (for example, inside the viewDidLoad method):
    EcommpaySDK *self.ecommpaySDK = [[EcommpaySDK alloc] init];
  3. Create an object named PaymentOptions. This object must contain the following required parameters:
    • projectId (integer)—a project identifier assigned by ecommpay
    • paymentId (string)—a payment identifier unique within the project
    • paymentCurrency (string)—the payment currency code in the ISO 4217 alpha-3 format
    • paymentAmount (integer)—the payment amount in the smallest currency units
    • customerId (string)—a customer's identifier within the project

    You can also add any other parameters listed in the following section.

    The following is an example of the PaymentOptions object that includes optional parameters (description of the payment and the customer's country)

    PaymentOptions *paymentOptions = [[PaymentOptions alloc] initWithProjectID:10
                                paymentID:@"internal_payment_id_1"
                            paymentAmount:1999
                          paymentCurrency:@"USD"
                       paymentDescription:@"T-shirt with dog print"
                               customerID:@"10"
                               regionCode:@"US"];
  4. Pack all payment parameters into a string for signing:
    paymentOptions.paramsForSignature();
  5. Send the string to the server side of your web service.
  6. Have your web service generate the signature on the basis of the string and your secret key.
  7. Add signature in your PaymentOptions object:
    [paymentOptions setSignature:signature]
  8. Open the payment form by using the following code:
    [self.ecommpaySDK presentPaymentAt:self paymentOptions:paymentOptions 
         completionHandler:^(PaymentResult *result) {
         NSLog(@"ECommPay SDK finished with status %ld", (long)result.status);
         ...
     }];

    Before opening the payment form, the library checks for any errors and opens the payment form only if no errors occur. Otherwise, the payment form is not opened and the presentPayment method returns the error code.

Payment status information

To receive payment result notifications, use requests with the following code included:

Figure: Receiving payment information in Swift

ecommpaySDK.presentPayment(at: self, paymentOptions: paymentOptions) { result in
         print("ecommpaySDK finished with status \(result.status.rawValue)")
   if let error = result.error {      // if an error occurred
      print("ErrorCode: \(error.code) message: \(error.message)")
   }
 }

Figure: Receving payment information in Objective-C

[self.ecommpaySDK presentPaymentAt:self paymentOptions:paymentOptions 
     completionHandler:^(PaymentResult *result) {
     NSLog(@"ECommPay SDK finished with status %ld", (long)result.status);
        if(result.error != NULL) {    // if an error occurred
            NSLog(@"Error code: %@ with message: %@", error.codeString, error.message);
        }
 }];

Possible payment result codes passed in the PaymentResult.status parameter:

Result code Message Description
0 Success Payment has been completed
100 Decline Payment has been declined
200 Cancelled Payment has been cancelled by the customer
500 Error An error occurred when the payment was being processed

Processing payments made with Apple Pay

In order to implement payment processing which involves the Apple Pay payment method, it is necessary to do the following:

  1. Register the merchant's identifier (Merchant ID) with Apple. Merchant ID allows the merchant to accept payments made with the Apple Pay method. This identifier never expires and can be used in multiple websites and iOS applications. For more information see Apple documentation: Create a merchant identifier.
  2. Create Payment Processing Certificate. This certificate is associated with the Merchant ID and is used to secure transaction data when processing Apple Pay payments. For more information see Apple documentation: Create a payment processing certificate.
  3. Send Payment Processing Certificate to the ecommpay technical support. Use the agreed upon security methods.
  4. Enable the Apple Pay capability for the mobile application in the programming environment. For information about enabling Apple Pay capability in Xcode environment, see Apple documentation: Enable Apple Pay

Once these steps are completed, you can process Apple Pay payments. The main steps such as opening the payment form and processing the responses are performed according to the general procedure, which is the same for all payment methods. In addition, you need to pass the following data in the applePayOptions object

Figure: Swift

setupApplePayparams(paymentOptions: PaymentOptions) {
        let applePayOptions = PaymentOptions.ApplePayOptions(applePayMerchantID: "merchant.example.com",
                                                             applePayDescription: "Shop",
                                                             countryCode: "US")
        paymentOptions.applePayOptions = applePayOptions
}

Figure: Objective-C

setApplePaySettings:(PaymentOptions *)paymentOptions {
    PaymentOptionsForApplePay *applePayOptions = [[PaymentOptionsForApplePay alloc]
                                                  initWithApplePayMerchantID:@"merchant.example.com"
                                                  applePayDescription:@"Shop"
                                                  countryCode:@"US"];
}

All parameters passed in the applePayOptions object are mandatory and are necessary for the Apple Pay session to start correctly.

Additional capabilities

Saving payment data

SDK UI & Core for iOS allows saving payment data of the customer for subsequent processing of payments without the need for the said customer to re-enter such data. This capability is set up individually for each project. The merchant has to let the technical support know which of the two options is preferable: always save payment data or ask the customer to select the option. For more information about this capability, refer to article Saving customer payment data.

As a result of saving payment data, a separate identifier is generated for each payment instrument. This identifier is associated with the identifier of a certain customer (customerId). To display saved payment data to the customer, pass false in the hideSavedWallets parameter of the PaymentOptions object.

Cascade payment processing

In case of a payment attempt failure, the capability of cascade payment processing can be used (details). This capability implies executing a sequence of payment attempts via alternative providers without the payment method change and can be set up upon coordination with the ecommpay specialists.

If this capability is set up for the project in use, then after the first unsuccessful attempt, a notification is received from SDK UI & Core for iOS. This notification contains the cascading_with_redirect = trueattribute-value pair. Along with that, the error page with the button to retry making the payment is shown to the customer. If the 3‑D Secure authentication is not required as part of the additional attempt, then the attempt is executed without any further interaction with the customer. Otherwise, a separate page opens for repeating the authentication process.

Submitting additional payment information

Generally, for processing a payment, it is enough to send a set of parameters that are mandatory for its initiation. However, in some cases, a payment system or a provider can require additional data necessary for processing a particular payment. This can be due to region-specific requirements, the need for an additional anti-fraud check, or other factors. The information about submitting additional payment data is provided in the following article.

The final set of required parameters can vary depending on a specific provider or a payment system. The list of parameters relevant for a particular payment is displayed to the customer on the payment form. The customer fills in the required data, confirms the payment, and receives the payment result information.

Collecting customer data

In some cases, alongside the mandatory parameters, it can be relevant to require the additional ones (such as phone numbers and email addresses) from the customers. To have this capability set up, the merchant should decide which data has to be mandatory to be specified by the customers and communicate data collection preferences to the technical support specialists. For more information about using the capability, see the separate article.

Payment form opening parameters

When working with SDK UI & Core for iOS, you can pass the following optional parameters in the PaymentOptions object.

Table 1.
Parameter Description

paymentDescription
string

Description of the payment. A string that contains between 1 and 255 characters.

Example: Cosmoshop purchase

receiptData
string

Data to be included in the notification with the list of the purchased items, passed as a JSON object encoded using the Base64 scheme.

Example: eyAgCiAgICAgICJwb3NpdGlvbnMiOlsgIAogICAgICAgICB7ICAKICAgICAgI CAgICAgInF1YW50aXR5IjozLAogICAgICAgICAgICAiYW1vdW50IjoxMDAwMC wKICAgICAgICAgICAgInRheCI6MTgsCiAgICAg

hideSavedWallets
boolean

Parameter to enable hiding or displaying saved payment instruments in the payment form.

Possible values:

  • true—saved payment data is hidden
  • false—saved payment data is displayed.

forcePaymentMethod
string

The identifier of the preselected payment method according to the table.

Example: card

threeDSecureInfo
object

Object that contains additional objects and parameters necessary for the 3‑D Secure 2 authentication (learn more).

regionCode

string

Code of the customer's country in the ISO 3166-1 alpha-2 format.

Example: GB

applePayMerchantID
string

The Apple Pay identifier of the merchant.

applePayDescription
string

The description of the merchant in the Apple Pay service.

countryCode
string

Code of the customer's country in the ISO 3166-1 alpha-2 format. Passed when Apple Pay payments are processed.

Example: GB

logoImage
object

A PNG or SVG file that contains the logo of the merchant.

brandColor
string

Payment interface colour passed as a UIColor object.

Example: UIColor.green

additionalFields
list

Additional fields that contain information about the customer. Includes a list of parameters with specified values.

Example: AdditionalField(type: .customer_first_name, value: "Arthur")

SDK UI & Core for iOS

To work with COF purchases, you should pass relevant parameters in the recurrentInfo object of the PaymentOptions object.

Table 2.
Parameter Description

type
string

COF purchase type:

  • .OneClick
  • .Autopayment
  • .Regular

period
string

Debiting period for a regular purchase.

Possible values:

  • .Day— daily
  • .Week—weekly
  • .Month—monthly
  • .Quarter— quarterly
  • .Year—yearly

expiryDay
string

Expiration day of the COF purchase.

expiryMonth
string

Expiration month of the COF purchase.

expiryYear
integer

Expiration year of the COF purchase.

scheduledPaymentID
string

Identifier to assign to the COF purchase (for automatic debiting).

Parameter must be passed together with the startDate parameter.

startDate
string

Date to perform the first debit in the dd-mm-yyyy format. Parameter must be passed together with the scheduledpaymentId parameter.

time
string

Time when to perform a scheduled debit (for regular purchases) in the hh:mm:ss format, passed if the period parameter is specified as well.

schedule
object—schedule of debits performed as part of the COF purchase (can be specified by the merchant). Should contain parameters amount and date.

amount
integer

The amount to debit in the smallest units of currency.

date
string

Date to perform the debit in the dd-mm-yyyy format.