Card-SDK-iOS
在 Tap Payments,我们努力让您的支付过程变得前所未有的简单。作为一个符合 PCI 标准的公司,我们为您提供从自构建解决方案到在您的 iOS 应用程序中处理卡支付的自助服务。
要求
- 我们支持 iOS 13.0 及以上版本
- Swift 版本 5.0 及以上
- Objective-C
获取您的 Tap 密钥
您可以使用我们示例应用程序中的示例密钥,但我们强烈建议您前往我们的 注册页面。您需要注册您的 bundle id
以获取激活我们 Card SDK
所需的 Tap Key
。
安装
我们为您提供了所有的技术支持,`TapCardSDK` 可以使用所有可能的技术进行安装。
CocoaPods
target 'MyApp' do
pod 'Card-SDK-iOS'
end
然后在您的终端中运行
pod install
pod update
Swift 包管理器
在 Xcode 中,将 `TapCardSDK
` 添加为 包依赖 到您的 Xcode 项目中。将 https://github.com/Tap-Payments/Card-SDK-iOS.git 作为包 URL。勾选 `Tap-Card-SD
` 复选框将 `TapCardSDK
` 库添加到您的应用中。
准备输入
文档
为了使我们的 SDK 尽可能动态,我们接受许多配置作为输入。让我们先声明它们并解释每个配置的结构和用法。
/**
Creates a configuration model to be passed to the SDK
- Parameters:
- publicKey: The Tap public key
- scope: The scope of the card sdk. Default is generating a tap token
- purpose: The intended purpose of using the generated token afterwards.
- merchant: The Tap merchant details
- transaction: The transaction details
- order: The tap order id
- invoice: Link this token to an invoice
- customer: The Tap customer details
- acceptance: The acceptance details for the transaction
- fields: Defines the fields visibility
- addons: Defines some UI/UX addons enablement
- interface: Defines some UI related configurations
*/
配置 | 描述 | 必需 | 类型 | 示例 |
---|---|---|---|---|
publicKey | 这是在注册您的 bundle id 后获得的 `Tap Key `。 |
是 | 字符串 | let publicKey: String = "pk_test_YhUjg9PNT8oDlKJ1aE2fMRz7" |
scope | 定义使用 `TapCardSDK ` 的意图。 |
是 | 字符串 | let scope: String = "Token" // 这意味着您将获得用于后续使用的 Tap 令牌 |
purpose | 定义生成令牌后的用途。 | 是 | 字符串 | let purpose: String = "PAYMENT_TRANSACTION" // 使用令牌进行单次扣款。 |
transaction | 如果您生成的是认证令牌,则需要定义交易元数据和引用。 | 否 | 字典 |
let transaction: [String:Any] = ["metadata":["example":"value"], "reference":"A reference to this transaciton in your system"] |
order | 这是您之前创建的 按订单 编号、所需金额和货币,如果有的话,您希望将此令牌附加到它上。 |
否 | 词汇表 |
let order:[String:String] = ["id":"", "amount":1, "currency":"SAR", "description": "身份验证描述"] |
发票 | 这是您希望链接此令牌的 发票 id ,如果有的话。 |
否 | 词汇表 |
let invoice:[String:String] = ["id":""] |
商家 | 在注册您的包标识符后,您将获得的 商家 id 。 |
是 | 词汇表 |
let merchant:[String:String] = ["id":""] |
客户 | 您希望附加到此令牌化过程的客户详细信息。 | 是 | 词汇表 |
let customer:[String:Any] = ["id":"", "name":[["lang":"en","first":"TAP","middle":"","last":"PAYMENTS"]], "nameOnCard":"TAP PAYMENTS", "editable":true, "contact":["email":"[email protected]", "phone":["countryCode":"+965","number":"88888888"]]] |
接受 | 交易的事宜详情。包括,您希望允许客户进行令牌化的哪些卡品牌和类型。 | 否 | 词汇表 |
let acceptance:[String:Any] = ["supportedBrands": ["AMERICAN_EXPRESS","VISA","MASTERCARD","OMANNET","MADA"], "supportedCards":["CREDIT","DEBIT"] |
字段 | 需要定义卡表单中可选字段的可见性。 | 否 | 词汇表 |
let fields:[String:Bool] = ["cardHolder":true] |
附加功能 | 需要在基本的卡表单上定义启用一些额外功能。 | 否 | 词汇表 |
let addons:[String:Bool] = ["displayPaymentBrands": true, "loader": true,"scanner": false] /**- displayPaymentBrands: 定义是否显示支持的卡品牌标志 - loader: 定义是否在卡处于处理状态时在卡上方显示载入器 - scanner: 定义是否启用卡扫描功能*/ |
界面 | 需要定义外观和感受相关的配置。 | 否 | 词汇表 |
let interface:[String:String] = ["locale": "en", "theme": "light", "edges": "curved", "direction": "dynamic"] // 主题的允许值:light/dark。locale:en/ar,edges:curved/flat,direction:ltr/dynaimc |
上传 | 这是您的服务器上的 webhook ,如果您希望我们更新服务器到服务器。 |
否 | 词汇表 |
let post:[String:String] = ["url":""] |
输入的初始设置
初始化为字典
您可以创建一个字典来将数据传递给我们的 sdooter。关于这一点的好处是,您可以从一个 API 中生成数据。每当我们对配置进行更新时,您都可以更新您的 API。这将确保您不需要在 App Store 上更新您的应用程序。
var dictConfig: [String: Any] = [
"publicKey": "pk_test_YhUjg9PNT8oDlKJ1aE2fMRz7",
"scope": "Authenticate",
"purpose": "PAYMENT_TRANSACTION",
"transaction": [
"metadata": ["example": "value"],
"reference": "",
],
"order": ["id": "",
"amount": 1,
"currency": "SAR",
"description": "Authentication description"],
"invoice": ["id": ""],
"merchant": ["id": ""],
"customer": [
"id": "",
"name": [["lang": "en", "first": "TAP", "middle": "", "last": "PAYMENTS"]],
"nameOnCard": "TAP PAYMENTS",
"editble": true,
"contact": [
"email": "[email protected]",
"phone": ["countryCode": "+965", "number": "88888888"],
],
],
"acceptance": [
"supportedBrands": ["AMERICAN_EXPRESS", "VISA", "MASTERCARD", "OMANNET", "MADA"],
"supportedCards": ["CREDIT", "DEBIT"],
],
"fields": ["cardHolder": true],
"addons": ["displayPaymentBrands": true, "loader": true, "saveCard": false, "scanner": false],
"interface": [
"locale": "en",
"theme": "light",
"edges": "curved", "direction": "dynamic",
],
"post": ["url": ""],
]
TapCardSDK 表单的初始化
您可以用不同方式初始化 TapCardView
。
- Storyboard。
- 代码。
- SwiftUI
Storyboard
代码
/// A class level variable
var tapCardView:TapCardView = .init()
/// The configuration dictionary
var dictConfig:[String:Any] = ["publicKey":"pk_test_YhUjg9PNT8oDlKJ1aE2fMRz7",
"scope":"Authenticate",
"purpose":"PAYMENT_TRANSACTION",
"transaction":["metadata":["example":"value"],
"reference":""],
"order":["id":"",
"amount":1,
"currency":"SAR",
"description": "Authentication description"],
"invoice":["id":""],
"merchant":["id":""],
"customer":["id":"",
"name":[["lang":"en","first":"TAP","middle":"","last":"PAYMENTS"]],
"nameOnCard":"TAP PAYMENTS",
"editble":true,
"contact":["email":"[email protected]",
"phone":["countryCode":"+965","number":"88888888"]]],
"acceptance":["supportedBrands":["AMERICAN_EXPRESS","VISA","MASTERCARD","OMANNET","MADA"],
"supportedCards":["CREDIT","DEBIT"]],
"fields":["cardHolder":true],
"addons":["displayPaymentBrands": true, "loader": true, "saveCard": false, "scanner": false],
"interface":["locale": "en", "theme": UIView().traitCollection.userInterfaceStyle == .dark ? "dark": "light", "edges": "curved", "direction": "dynamic"],
"post":["url":""]]
/// Add the needed constraints to show and put the card view within your layout
func addCardView() {
view.addSubview(tapCardView)
tapCardView.translatesAutoresizingMaskIntoConstraints = false
let constraints = [
tapCardView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
tapCardView.topAnchor.constraint(equalTo: view.topAnchor, constant: 100),
tapCardView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20),
tapCardView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 20),
view.heightAnchor.constraint(equalToConstant: 95)
]
NSLayoutConstraint.activate(constraints)
tapCardView.setNeedsLayout()
tapCardView.updateConstraints()
view.updateConstraints()
}
/// Pass the required configuration data to the tap card view sdk
func configureTheSDK() {
tapCardView.initTapCardSDK(configDict: dictConfig, delegate: self, presentScannerIn: self)
}
SwiftUI
TapCardViewDelegate
一个协议,允许集成商从 TapCardSDK
触发的事件中获得通知。
@objc public protocol TapCardViewDelegate {
/// Will be fired whenever the card is rendered and loaded
@objc optional func onReady()
/// Will be fired once the user focuses any of the card fields
@objc optional func onFocus()
/// Will be fired once we detect the brand and related issuer data for the entered card data
/** - Parameter data: will include the data in JSON format. example :
*{
"bin": "424242",
"bank": "",
"card_brand": "VISA",
"card_type": "CREDIT",
"card_category": "",
"card_scheme": "VISA",
"country": "GB",
"address_required": false,
"api_version": "V2",
"issuer_id": "bnk_TS02A5720231337s3YN0809429",
"brand": "VISA"
}* */
@objc optional func onBinIdentification(data: String)
/// Will be fired whenever the validity of the card data changes.
/// - Parameter invalid: Will be true if the card data is invalid and false otherwise.
@objc optional func onInvalidInput(invalid: Bool)
/**
Will be fired whenever the card sdk finishes successfully the task assigned to it. Whether `TapToken` or `AuthenticatedToken`
- Parameter data: will include the data in JSON format. For `TapToken`:
{
"id": "tok_MrL97231045SOom8cF8G939",
"created": 1694169907939,
"object": "token",
"live_mode": false,
"type": "CARD",
"source": "CARD-ENCRYPTED",
"used": false,
"card": {
"id": "card_d9Vj7231045akVT80B8n944",
"object": "card",
"address": {},
"funding": "CREDIT",
"fingerprint": "gRkNTnMrJPtVYkFDVU485Gc%2FQtEo%2BsV44sfBLiSPM1w%3D",
"brand": "VISA",
"scheme": "VISA",
"category": "",
"exp_month": 4,
"exp_year": 24,
"last_four": "4242",
"first_six": "424242",
"name": "AHMED",
"issuer": {
"bank": "",
"country": "GB",
"id": "bnk_TS07A0720231345Qx1e0809820"
}
},
"url": ""
}
*/
@objc optional func onSuccess(data: String)
/// Will be fired whenever there is an error related to the card connectivity or apis
/// - Parameter data: includes a JSON format for the error description and error
@objc optional func onError(data: String)
/// Will be fired whenever the card element changes its height for your convience
/// - Parameter height: The new needed height
@objc optional func onHeightChange(height: Double)
}
卡令牌化
一旦您通过委托通知,TapCardView
现在有有效的输入。您可以通过调用公共接口开始令牌化过程。
/// Wil start the process of generating a `TapToken` with the current card data
tapCardView.generateTapToken()