LukaBluesnapSDK 1.0.14

LukaBluesnapSDK 1.0.14

Jose Moran 维护。



 
依赖
BluesnapSDK>= 0
Alamofire>= 0
 

  • Jose Moran

Luka - BlueSnap iOS SDK

Latest Version Swift Platform

Luka的iOS SDK 为 BlueSnap提供了一种快速集成方法。需要注意的是,这个SDK目前仅支持通过BlueSnap SDK进行卡支付,不支持其他支付方式。

安装

要求

  • Luka API 凭据
  • iOS 15 或更高版本

CocoaPods

要将 Luka - BlueSnap SDK 集成到您的 Xcode 项目中,使用 CocoaPods,请在您的 Podfile 中指定它

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '15.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'LukaBluesnapSDK', '~> <latest version available>'
end

然后,运行以下命令

$ pod install --repo-update

用法

初始化

通过以下方式在您的 AppDelegate 类或 Swift 主 App 中设置配置来初始化 LukaBluesnapSDK

  LukaBluesnapSdk
    .setUpConfig(
      config: Config(env: .sandbox, creds: Config.SdkCredentials(username: "username", password: "password")),
      callbacks: ConfigCallbacksImpl()
    )

ConfigCallbacks 协议用于提供回调功能,如以下代码所述

  class ConfigCallbacksImpl: ConfigCallbacks {
      func onSuccess() {
        print("success")
      }
  
      func onError() {
        print("error")
      }
  }

向用户添加新卡

要在您的应用中向用户添加借记卡/信用卡,您可以使用 addNewCard() 方法

  LukaBluesnapSdk.addNewCard(email: "[email protected]")
    .onSuccess { result in
      print(result)
    }.onError { err in
      print(err)
    }
    .onLoading {
      print("loading")
    }
    .start()

onSuccess 回调函数提供了包含关于分配给给定电子邮件地址的 lukaId 以及作为 Card 对象提供的卡信息 AddCardResult 类

  public struct AddCardResult: Codable {
      public let lukaCustomerId: String
      public let card: LukaCard
  }
  public struct LukaCard: Codable {
    public let cardId: Int
    public let cardLast4: String
    public let cardProcessor: LukaCard.Processor
    public let cardSubType: LukaCard.SubType
    public let country: String
    public let expiryDate: String
  }

onError 回调提供类型为 Error 的错误参数,它可以被转换为 AddCardError 来区分每种错误类型

  public enum AddCardError: Error {
    case noAuth
    case noCustomerId
    case couldNotAddCard
    case cardAlreadyAdded
    case somethingWentWrong(msg: String)
  }

如果错误不是 AddCardError 类中先前可用选项中的错误,那么将提供一个描述错误的字符串作为错误参数。要访问错误的描述,可以使用 errorDescription 属性。

给用户添加新卡片

要在您的应用中向用户添加借记卡/信用卡,您可以使用 addNewCard() 方法

  LukaBluesnapSdk.addNewCard(email: "[email protected]")
    .onSuccess { result in
      print(result)
    }.onError { err in
      print(err)
    }
    .onLoading {
      print("loading")
    }
    .start()

此方法会将您重定向到 SDK 内部的一个内置屏幕,该屏幕提供了将新卡片与用户链接所需的所有输入。

onSuccess 回调函数提供了包含关于分配给给定电子邮件地址的 lukaId 以及作为 Card 对象提供的卡信息 AddCardResult 类

此逻辑与 SDK 中所有可用的方法保持一致。

列出用户的所有可用卡片

要列出您的应用程序中给定用户的所有借记/信用卡,您可以使用 getCards() 方法,如下所述

  LukaBluesnapSdk.getCards(clientId: "client uuid provided when a card is link to a user")
    .onSuccess { list : [LukaCard] in
      self.cards = list
    }.onLoading {}
    .start()

此方法提供了 LukaCard 类实例的列表。在处理与卡片的支付时,还可以使用此相同类。请注意,如果发生任何错误,则将返回空数组。

删除用户卡

要能够删除用户卡,您只需要用户 clientId 和要删除的 cardId。

  LukaBluesnapSdk.deleteCard(clientId: "client uuid provided when a card is link to a user", cardId: id)
    .onSuccess { isDeleted in
      if (isDeleted) {
        // remove from list
      }
    }.onError { err in

    }.start()

处理支付

要使用已链接到用户的卡片处理支付,您可以使用 processPayment() 方法

  LukaBluesnapSdk.processPayment(clientId: "client uuid provided when a card is link to a user", card: card, amount: 10.0, email: "[email protected]")
    .onSuccess { rst in
      print("Transaction successfull \(rst.id)")
    }.onError { err in
      print(err)
    }.start()

此方法需要先前提供的 LukaCard 类、金额(Double 类型)、客户端 ID 和与用户关联的电子邮件。成功回调返回 TransactionResult 类的实例,其中包含有关付款的相关信息。

  public struct TransactionResult {
    public let id: Int
    public let merchantTransactionId: Int
    public let traceId: String
    public let amount: Double
    public let lukaClientId: String
    public let paymentNetwork: String
  }