购买商 2.3.0

购买商 2.3.0

Tulio TroncosoThomas Vidas维护。



购买商 2.3.0

  • 购买商

购买商iOS SDK

购买商iOS SDK通过提供支付方式的标记化,为iOS应用提供了一种简单的方式来接受支付。通过使用这些标记而不是卡和银行信息,您就无需再将敏感的卡信息发送到您的服务器。

iOS刷卡支付指南

移动读卡器支付

通过使用Omni Mobile SDK,您可以通过快速添加移动读卡器支付来全面提升您的移动应用程序。这些支付将在Stax平台上创建发票、客户和交易对象。您还可以选择将支付方式存储在Stax中,以便您可以从Stax API中使用它。

工作原理

  1. 首先,您需要创建一个临时密钥来初始化Omni对象。
  2. 然后,您将创建一个TransactionRequest对象,它包含进行支付所必需的所有数据。
  3. 最后,通过调用takeMobileReaderPayment()方法,您将要求Omni执行支付,并将TransactionRequest和一个在支付完成后要执行的代码块作为参数传入。

要求

  • Xcode 8+
  • iOS 9+
  • 短暂的Stax API密钥

安装

使用CocoaPods来安装Fattmerchant iOS SDK。

  1. 安装CocoaPods{:target="_blank" rel="noreferrer"}
  2. pod 'Fattmerchant'添加到您的Podfile
  3. 运行pod install

入门

设置Info.plist

为了构建和运行带有Card-present功能的程序,您必须在项目文件的Info.plist中包含以下内容

  • NSBluetoothAlwaysUsageDescription:在这里提供一个值,以告知用户为什么需要启用蓝牙访问

初始化

创建一个InitParams实例。

var initParams = Omni.InitParams(appId: "fmiossample", apiKey: apiKey, environment: Environment.DEV)

将initParams传递给Omni.initialize(...),同时传递一个完成lambda和一个错误lambda。

omni = Omni()

log("Attempting initalization...")

// Initialize Omni
omni?.initialize(params: initParams, completion: {
  // Initialized!
}) { (error) in

}

联接移动读卡器

为了联接移动读卡器,您首先需要搜索可用的读卡器列表

omni.getAvailableReaders { readers ->

}

一旦您有了可用列表,就可以选择您想联接的读卡器

omni?.getAvailableReaders(completion: { readers in
  guard !readers.isEmpty else {
    self.log("No readers found")
    return
  }

  var chosenReader = ... // Choose a reader

  omni.connect(reader: chosenReader, completion: { connectedReader in
    self.log("Connected reader: \(connectedReader)")
  }) { (error) in
    // Something went wrong
  }
}) {
  self.log("Couldn't connect to the mobile reader")
}

收银

要收银,只需创建一个 TransactionRequest 并将它传递给 omni.takeMobileReaderTransaction(...)

// Create an Amount
let amount = Amount(cents: 50)

// Create the TransactionRequest
let request = TransactionRequest(amount: amount)

// Take the payment
omni.takeMobileReaderTransaction(request, { completedTransaction in
    // Payment successful!
}) {
    // Error
}

默认情况下,在交易中使用的 PaymentMethod 被标记为可重复使用。这允许在 Stax 虚拟终端和 Stax API 中使用 PaymentMethod。要退出标记化,可以将 TransactionRequesttokenize 字段设置为 false

// Create a TransactionRequest with no tokenization
let request = TransactionRequest(amount: amount, tokenize: false)

退款

您可以使用 [Stax API]({{ site.api_ref_url }}#reference/0/transactions){:target="_blank" rel="noreferrer"} 来退款。获取交易后,您可以使用 refundMobileReaderTransaction 方法尝试退款。

// Attain a transaction
var transaction = Transaction()

// Perform refund
omni.refundMobileReaderTransaction(transaction: transaction, completion: { (refundedTransaction) in
  // Refund successful!
}, error: { error in
  // Error
})