Skip to main content
Skip table of contents

Initialize Pay-me SDK iOS

The following are the steps to initialize the SDK.

You need the data of the step Pay-me SDK iOS Input and Output Parameters and the Key provided by Pay-me.

Import the SDK

We place ourselves at the top of the class that will be in charge of invoking the SDK. At this point, the SDK must be imported so that its methods and entities can be recognized.

import Payme

Invoke the SDK

The SDK is invoked with the input data.

The function authorizeTransaction of the PaymeClient class is in charge of initializing the authorization process, this function receives the following parameters:

  • controller: is the controller where the SDK invocation will start.

  • usePresent: the value true indicates that a presentController will be used to invoke the main SDK controller, otherwise pushViewController will be used.

  • paymeRequest: the input object containing all the transaction information.

setEnvironment: this function will allow us to select the environment:

  • Development

  • Production

let paymePersonData = PaymePersonData(
  firstName: "Levis Antonio",
  lastName: "Silvestre Maylle",
  email: "",
  addrLine1: "Av casimiro Ulloa 333",
  addrLine2: "Av casimiro Ulloa 333",
  countryCode: "PE",
  countryNumber: "604",
  zip: "18",
  city: "Lima",
  state: "Lima",
  mobilePhone: "51-958435685"

var reserved = [String:String]() 
reserved["reserved1"] = "1"
reserved["reserved2"] = "1"
reserved["reserved3"] = "3"
let paymeRequest = PaymeRequest(
  merchant: PaymeMerchantData(
    operation: PaymeOperationData(
      operationNumber: "000001",
      operationDescription: "Televisor",
      amount: "10.55",
      currency: PaymeCurrencyData(
        code: "604",
        symbol: "S/"
    addrMatch: true,
    billing: paymePersonData,
    shipping: paymePersonData
  feature: PaymeFeatureData(
    reserved: reserved,
    wallet: PaymeWalletData(enable: true, userID: "COMMERCE_USER"),
    installments: PaymeInstallmentsData(enable: true),
    authentication: PaymeAuthenticationData(tdsChallengeInd: "01")
  setting: PaymeSettingData(
    locale: "es_PE",
    brands: ["VISA","MSCD","AMEX","DINC"]
let paymeClient = PaymeClient(delegate: self, key: "COMMERCE_KEY")
paymeClient.setEnvironment(environment: PaymeEnviroment.production)
paymeClient.authorizeTransaction(controller: self.navigationController!, usePresent: false, paymeRequest: paymeRequest)

The Delegate for the methods to be used is added, which is the PaymeClientDelegate.

The PaymeInternalAction object will return notifications from the SDK for each internal action:

  • Cardholder presses the pay button.

  • RBA process starts and ends.

  • 3DS process starts and ends.

  • Authorization with the Charges component starts.

The PaymeResponse object will return the final response from the SDK, once the whole process is finished.

extension MainController: PaymeClientDelegate {
    func onNotificate(action: PaymeInternalAction) {
        print("========================================= INTERNAL ACTION SDK =======================================")
        switch action {
            case .PRESS_PAY_BUTTON: print("El usuario presionó el boton pagar exitosamente.")
            case .START_SCORING: print("Inicia el proceso de evaluación de riesgo.")
            case .END_SCORING: print("Termina el proceso de evaluación de riesgo.")
            case .START_TDS: print("Inicia el proceso de autenticación.")
            case .END_TDS: print("Termina el proceso de autenticación.")
            case .START_AUTHORIZATION: print("Se inicia la autorización.")
            default: print("Action no reconocida.")
        print("========================================= INTERNAL ACTION SDK =======================================")
    func onRespondsPayme(response: PaymeResponse) {
        print("========================================= PAYMENT_RESPONSE =======================================")
        print("success: ", response.success)
        print("messageCode: ", response.resultCode ?? "-")
        print("message: ", response.resultMessage ?? "-")
        print("detail: ", response.resultDetail ?? "-")
        if let payment = response.payment {
            print("payment.accepted: ", payment.accepted)
            print("payment.operationNumber: ", payment.operationNumber ?? "-")
            print(" ", payment.operationDate ?? "-")
            print("payment.authorizationCode: ", payment.authorizationCode ?? "-")
        print("========================================= PAYMENT_RESPONSE =======================================")
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.