goSellSDK 2.3.38

goSellSDK 2.3.38

KholdunnTap Mobile DeveloperOSAMA RABIEOsama Rabie 维护。



goSellSDK 2.3.38

  • Tap Payments

goSell iOS SDK

iOS SDK 用于使用 goSell API

Platform Build Status CocoaPods Compatible Documentation

一个库,完全覆盖您在 iOS 应用程序内的支付/授权/卡存储过程。

目录


  1. 要求
  2. 安装
    1. CocoaPods 安装
    2. Carthage 安装
    3. M1 架构 Mac
    4. App Clip 安装
  3. 设置
    1. goSellSDK 类属性
    2. goSellSDK 类方法
    3. 设置步骤
  4. 用法
    1. SDK 模式
    2. 支付按钮
      1. 支付按钮位置
      2. 属性
      3. 方法
    3. 会话
      1. 属性
      2. 方法
    4. API 会话
      1. 属性
      2. 方法
    5. 会话数据源
      1. 结构
      2. 示例
    6. 会话代理
      1. 支付成功回调
      2. 支付失败回调
      3. 授权成功回调
      4. 授权失败回调
      5. 卡存储成功回调
      6. 卡存储失败回调
      7. 卡令牌化成功回调
      8. 卡令牌化失败回调
      9. 会话开始回调
      10. 会话开始回调
      11. 会话开始失败回调
      12. 会话取消回调
    7. 会话外观
  5. 示例

需求


要使用SDK,需满足以下要求:

  1. Xcode 10.0 或更高版本
  2. Swift 4.0 或更高版本(随Xcode预装)
  3. 应用的部署目标SDK:iOS 11.0 或更高
  4. 为了支持iOS 11以下的应用,请使用以下命令: pod "goSellSDK", '2.2.22'

安装


CocoaPods安装

CocoaPods 是一个依赖关系管理器,它自动化并简化了在项目中使用第三方库的过程。
您可以使用以下命令安装它:

$ gem install cocoapods

Podfile

要使用CocoaPods将goSellSDK集成到Xcode 12+项目中,请确保您使用的是版本 >= 2.2.33 的goSellSDK。

要将goSellSDK集成到iOS 11+ 的Xcode项目中使用CocoaPods,请在其 Podfile 中指定它。

platform :ios, '12.0'
use_frameworks!

source 'https://github.com/CocoaPods/Specs.git'

target 'MyApp' do
    
    pod 'goSellSDK'

end

然后,运行以下命令:

$ pod update

要将goSellSDK集成到低于iOS 11的Xcode项目使用CocoaPods,请在其 Podfile 中指定。

platform :ios, '11.0'
use_frameworks!

source 'https://github.com/CocoaPods/Specs.git'

target 'MyApp' do
    
    pod "goSellSDK", '2.2.22'

end

我们还建议您包含错误报告子模块,以便您的客户可以直接向Tap报告SDK的意外行为。

要包含错误报告,请将以下行添加到您的Podfile

target 'MyApp' do
    
    # Other pods
    ...
    
    # Error reporting submodule.
    pod 'goSellSDK/ErrorReporting' 

end

M1型Mac设备

使用基于M1的Mac设备编译时,您可能会遇到编译错误,请按照以下步骤解决:

  1. 关闭Xcode。

  2. 转到application文件夹。

  3. 找到Xcode图标。

  4. 右键单击Xcode图标。

  5. 选择获取信息

  6. 勾选使用Rosetta打开选项

img

安装到App Clip

苹果在iOS 14+中引入了一种按需安装方式,称之为“App Clip”,它给了商家在不要求顾客下载应用的情况下提供其服务的机会。

在我们的Tap平台中,我们追求最高标准并利用最新提供的技术,因此我们提供了一种兼容的SDK以嵌入到App Clip目标中。SDK的使用方式与SDK代码完全相同。

更多信息请参看:goSellAppClipSDK

配置


首先,需要配置goSellSDK。在本节中,仅需要设置密钥。

goSellSDK 类属性

以下是可以操作的 goSellSDK 类属性列表。在使用 SDK 之前,请确保已经进行了设置。

密钥

要设置它,在您的项目中的某个位置添加以下代码行,并确保在调用 goSellSDK 之前执行,否则将抛出异常。必需。 PS:此密钥只是与我们的 SDK 集成的应用程序的“轻触标识符”。请勿将其与用于加密和解密的公共/密钥混淆,这些密钥安全存储在我们的 PCI 认可的服务器上。

Swift:

let secretKey = SecretKey(sanbox: "YOUR_SANDBOX_SECRET_KEY", production: "YOUR_PRODUCTION_SECRET_KEY") // (format of the key: "sk_XXXXXXXXXXXXXXXXXXXXXXXX")
goSellSDK.secretKey = secretKey // Secret key (format: "sk_XXXXXXXXXXXXXXXXXXXXXXXX")

Objective-C:

SecretKey *secretKey = [[SecretKey alloc] initWithSandbox:@"YOUR_SANDBOX_SECRET_KEY" production:@"YOUR_PRODUCTION_SECRET_KEY"]; // (format of the key: "sk_XXXXXXXXXXXXXXXXXXXXXXXX")
[goSellSDK setSecretKey:secretKey];

别忘了在文件开头导入框架

Swift:

import goSellSDK

Objective-C:

@import goSellSDK;

或者

#import <goSellSDK/goSellSDK-Swift.h>

模式

SDK 模式是 SDK 操作的模式,可以是 沙盒生产

使用此属性测试您的沙盒事务集成。

警告:此属性的默认值为 生产,这意味着您的交易是真实交易。在开发过程中切换到 沙盒

语言

SDK UI 部分的语言本地化。这是一个区域标识符。

请确保它只由 2 个小写字母组成,并且显示在 goSellSDK 类的 availableLanguages 属性的列表中。

注意:iOS 9 SDK 开始,用户界面布局方向取决于您选择的语言,这意味着如果您想使用阿拉伯语,UI 将切换到从右到左(RTL)。

支持的脚本

此属性返回 SDK 当前本地化的地区标识符的列表。

目前我们支持以下脚本

脚本地区标识符
阿拉伯语ar
英语en
俄语ru

SDK 版本

此属性返回当前 SDK 版本。

goSellSDK 类方法

重置

重置所有设置并使 SDK 在下一次使用时重新初始化。
当您切换帐户时可能很有用。
当您注销用户时也有用,尽管这不是必需的。

设置步骤

含 PayButton

对于那些想使用 PayButton 的人来说。

  1. 放置 PayButton
  2. 为其分配 数据源代理
  3. 实现 数据源代理

不含 PayButton

对于那些想保留其设计并手动启动 SDK 进程的人来说。

  1. 创建 会话 对象。
  2. 为其分配 数据源代理
  3. 实现 数据源代理

Apple Pay

确保当前 goSellSDK 版本 >= 2.2.12-beta

  1. 从 Tap 团队获取 CSR。

  2. 从您的 Apple 开发者账户

    1. 创建商户标识符

      商户标识符 在 Apple Pay 中唯一标识您作为一个能够接受付款的商户。您可以使用相同的商户标识符为多个原生和网页应用。它永远不会过期。

      1. 证书、标识符和配置文件 中,从侧边栏选择“标识符”,然后在右上角点击添加按钮(+)。 img
      2. 选择商户ID,然后点击继续。 img
      3. 输入商户描述和标识名称,然后点击继续。 img
      4. 检查设置,然后点击注册。
    2. 创建支付处理证书:一个 支付处理证书 与您的商户标识相关联,用于加密支付信息。支付处理证书每25个月到期一次。如果证书被吊销,您可以重新创建它。

      1. 证书、标识符和配置文件 中,从侧边栏选择标识符。 img

      2. 在标识符下,使用右上角的过滤器选择商户ID。

      3. 在右侧,选择您的商户标识。

        注意: 如果页面顶部出现一个横幅 saying that you need to accept an agreement, 点击 the Review Agreement button 并遵循说明后继续。

      4. 在 Apple Pay 支付处理证书下,点击创建证书。

      5. 在您的 Mac 上创建证书签名请求,然后点击继续。

      6. 点击选择文件。

      7. 在出现的对话框中,选择证书请求文件(一个具有 .certSigningRequest 文件扩展名的文件),然后点击选择。

      8. 点击继续。

      9. 点击下载。

        证书文件(一个具有 .cer 文件扩展名的文件)出现在您的 下载 文件夹中。

  3. 将您的 .cer 文件、商户标识和应用程序包标识发送回 Tap 团队。

  4. 从 Xcode 将 Apple Pay 功能启用到您的项目中,并选择商户标识。 img

  5. 如果

    1. 您完成了所有前面的步骤。
    2. 客户正在使用我们启用了 Apple Pay 选项的货币进行支付。
    3. 付费客户已在其设备上激活Apple Pay。
    4. 付费客户已在 Apple Wallet 中添加了至少一张有效的卡片,并通过我们的 Apple Pay 支付网络。

使用说明


在配置goSellSDK之后,您实际上可以使用SDK。
我们努力使SDK集成尽可能简单,对您的需求尽可能少。

SDK模式

goSellSDK运行于4种模式

  1. 购书记录:默认模式。正常顾客收费。
  2. 授权:只进行授权。成功授权后您应指定操作:在指定时间段后捕获金额或取消费用。
  3. 卡信息保存:使用这种模式来保存顾客的卡信息以便以后使用。
  4. 卡信息令牌化:如果您愿意手动执行充电/授权,请使用此模式。此模式的目的仅限于在您没有PCI合规证书但愿意手动处理付款的情况下收集和令牌化顾客的卡信息详情。

通过SessionDataSource接口设置模式。

支付按钮

在Tap,我们设计了自己的支付按钮。您只需将其放在屏幕的某个位置,并通过其dataSource属性提供至少必要的支付详情。

支付按钮位置

支付按钮的高度限制为恰好44点。为了获得更好的体验,请确保其有足够的宽度来显示内容。

XIB/Storyboard

您可以在XIB/Storyboard文件中的视图中添加付款按钮。为此,请执行以下操作

  1. UIView的实例拖放到所需位置。
  2. 选择添加的视图并打开身份检查器
  3. 输入以下值
    1. 类: PayButton
    2. 模块: goSellSDK
  4. 为了方便起见,您还可以连接dataSourcedelegate出口。

代码

您也可以使用代码添加付款按钮

Swift:

import goSellSDK
...
func addPayButton() {

    let buttonFrame = CGRect(x: 8.0, y: UIScreen.main.bounds.height - 52.0, width: UIScreen.main.bounds.width - 16.0, height: 44.0)
    let button = PayButton(frame: buttonFrame)
    self.view.addSubview(button) // or where you want it
    
    button.dataSource = self // or whatever
    button.delegate = self // or whatever
}

Objective-C:

@import goSellSDK;
...
- (void)addPayButton {

    CGRect buttonFrame = CGRectMake(8.0, UIScreen.mainScreen.bounds.size.height - 52.0, UIScreen.mainScreen.bounds.size.width - 16.0, 44.0);
    PayButton *button = [[PayButton alloc] initWithFrame:buttonFrame];
    [self.view addSubview:button]; // or where you want it
    
    button.dataSource = self; // or whatever
    button.delegate = self; // or whatever
}

属性

以下是付款按钮的属性列表

属性 类型 描述
Objective-CSwift Objective-CSwift
enabledisEnabled BOOL布尔值 定义按钮是否启用。
您可能需要它来处理内部逻辑。
dataSource id<SessionDataSource>SessionDataSource Session数据源。所有输入付款信息都通过此协议传递。必需。
delegate id<SessionDelegate>SessionDelegate Session代理。通过此协议传递付款状态以及所有输出付款信息。
appearance id<SessionAppearance>SessionAppearance Session外观。如果需要UI自定义,请实现。有关更多信息,请参阅SessionAppearance部分。

方法

方法 描述
Objective-CSwift
-(void)updateDisplayedStatefunc updateDisplayedState() 调用此方法以更新按钮上显示的数量。
注意: 如果金额不是正数,则支付按钮会强制禁用。

会话

如果你不使用 PayButton,则希望使用 Session 对象。

属性

属性 类型 描述
Objective-CSwift Objective-CSwift
dataSource id<SessionDataSource>SessionDataSource Session数据源。所有输入付款信息都通过此协议传递。必需。
delegate id<SessionDelegate>SessionDelegate Session代理。通过此协议传递付款状态以及所有输出付款信息。
appearance id<SessionAppearance>SessionAppearance Session外观。如果需要UI自定义,请实现。有关更多信息,请参阅SessionAppearance部分。
canStart BOOL布尔值 只读。定义会话是否可以使用你通过 dataSource 提供的数据启动。

方法

方法 描述
Objective-CSwift
calculateDisplayedAmount 根据通过 dataSource 提供的详细信息计算并返回一个金额。如果你不使用 SDK 提供的 PayButton,则在更新 dataSource 后希望每次都调用此方法以反映 UI 中的更改。
返回: 建议向客户显示的金额或以下情况下的 nil
  1. 会话无法使用提供的详细信息启动。
  2. 你处于卡片保存模式。
start 启动会话。
返回: 布尔值,表示是否满足启动会话的所有条件。
stop 停止会话。你可能希望在从你的应用程序外部关闭 SDK 的情况下使用此方法,例如执行深度链接时。
参数
completion:完成闭包将在所有打开的 SDK 用户界面关闭后调用。

API会话

APISession 是一个类,您在需要调用不带UI的普通API时可以使用。目前不是所有的API都可用。

属性

属性 类型 描述
Objective-CSwift Objective-CSwift
sharedInstance shared APISession 共享的单例APISession实例。

方法

请参阅 APISession 类文档以获取更多详细信息。

会话数据源

SessionDataSource 是一个接口,您应该在代码的某个地方实现此接口以传递支付信息,以便能够访问SDK中的支付流程。

结构

下表描述了其结构并指定了每种模式所需的字段。

成员 类型 必需的 描述
Objective-CSwift 购买授权卡保存
模式 TransactionMode false 交易的模式(购买、授权、卡保存或卡令牌化)。如果此属性未实现,则使用购买模式。
客户 客户 true 客户信息。有关如何创建客户的详细信息,请参阅客户类参考。
货币 货币 truefalse 交易货币。
金额 NSDecimal十进制 false 支付/授权金额。
注意:为了有支付金额,必须实现金额项目之一。如果两个都实现了,则优先使用项目
项目 NSArray <PaymentItem *>[PaymentItem] false 要支付的项列表。
注意:为了有支付金额,必须实现金额项目之一。如果两个都实现了,则优先使用项目
目的地 NSArray <Destination *>[Destination] false 从支付/授权交易中接收资金的可选目的地账户列表。
商户ID NSString字符串 false 如果您有多个商户账户,请通过此字段指定您想使用的哪个。
税率 NSArray <Tax *>[Tax] false 您可以在此处指定税收详细信息。默认情况下,没有税收。
注意:指定税收将影响总支付/授权金额。
配送 NSArray <Shipping *>[Shipping] false 您可以在此处指定配送详情。默认情况下,没有配送详情。
注意:指定配送将影响总支付/授权金额。
postURL NSURLURL false 在支付成功或失败时,由Tap系统调用的URL通知。
paymentDescription NSString字符串 false 支付描述。
paymentMetadata NSDictionary <NSString *, NSString *>[String: String] false 您希望随交易传递的附加信息。
paymentReference 参考 false 您可以使用此属性保留交易的引用。
paymentStatementDescriptor NSString字符串 false 账单描述符。
require3DSecure BOOL布尔值 false 定义是否需要3D安全检查。如果未实现,视为true
注意:如果您禁用3D安全检查,仍然可能发生。最终决定由Tap做出。
receiptSettings 收据 false 收据接收者的详细信息。
authorizeAction AuthorizeAction falsetruefalse 授权成功后要执行的操作。
allowsToSaveSameCardMoreThanOnce BOOL布尔值 false 定义相同的卡是否可以保存超过一次。
注意:相同的卡指的是完全相同的集合。例如,如果客户指定相同的卡详细信息,但不同的持卡人姓名,我们将将其视为不同的卡。
applePayMerchantID NSString字符串 false 定义从Apple开发者账户获取的Apple pay商户ID。
allowedCadTypes NSArray<\CardType *>[CardType] false 定义商户希望其客户使用的允许的卡类型(信用、借记、全部)。
isSaveCardSwitchOnByDefault BOOL布尔值 false 定义是否默认开启保存卡切换。
注意:如果此属性的值为true,则开关将保留关闭状态,直到卡信息填写有效,然后自动切换开启。
paymentType PaymentType false 定义要显示的支付类型。
cardHolderName NSString字符串 false 提供一个默认的持卡人姓名,在卡输入视图中编写。
paymentType PaymentType false 定义要显示的支付类型。

示例


模式

Objective-C

- (enum TransactionMode)mode {
    
    return Purchase;
}

Swift

var mode: TransactionMode {
        
    return .purchase
}

客户

Objective-C

- (Customer *)customer {
    
    if ( customerIDIsKnown ) {
        
        return [self identifiedCustomer];
    }
    else {
        
        return [self newCustomer];
    }
}

/// Creating a customer with known identifier received from Tap before.
- (Customer *)identifiedCustomer {
    
    return [[Customer alloc] initWithIdentifier:@"cus_tomer_id"];
}

/// Creating a customer with raw information.
- (Customer *)newCustomer {
    
    EmailAddress *email = [EmailAddress withEmailAddressString:@"[email protected]"];
    PhoneNumber *phoneNumber = [[PhoneNumber alloc] initWithISDNumber:@"965" phoneNumber:@"96512345"];
    
    Customer *newCustomer = [[Customer alloc] initWithEmailAddress:email
                                                       phoneNumber:phoneNumber
                                                         firstName:@"Steve"
                                                        middleName:nil
                                                          lastName:@"Jobs"];
    
    return newCustomer;
}

Swift

var customer: Customer? {
        
    if customerIDIsKnown {
            
        return self.identifiedCustomer
    }
    else {
            
        return self.newCustomer
    }
}

/// Creating a customer with known identifier received from Tap before.
var identifiedCustomer: Customer? {
        
    return try? Customer(identifier: "cus_to_mer")
}

/// Creating a customer with raw information. 
var newCustomer: Customer? {
        
    let emailAddress = try! EmailAddress(emailAddressString: "[email protected]")
    let phoneNumber = try! PhoneNumber(isdNumber: "965", phoneNumber: "96512345")
        
    return try? Customer(emailAddress:  emailAddress,
                         phoneNumber:   phoneNumber,
                         firstName:     "Steve",
                         middleName:    nil,
                         lastName:      "Jobs")
}

货币

Tap 支持处理 10 多种货币的支付,允许您用客户的原货币收费,同时您将收到自己的货币资金。这对于您在国际上有业务来说尤其有帮助,因为以客户的原货币收费可以增加销售额。

支持的货币
货币 代码
阿联酋迪拉姆 AED
巴林第纳尔 BHD
埃及镑 EGP
欧元 EUR
英国英镑 GBP
科威特第纳尔 KWD
阿曼里亚尔 OMR
卡塔尔里亚尔 QAR
沙特里亚尔 SAR
美国美元 USD

Objective-C

- (Currency *)currency {
    
    return [Currency withISOCode:@"KWD"];
}

Swift

var currency: Currency? {
        
    return .with(isoCode: "KWD")
}

金额

Objective-C

- (NSDecimal)amount {
    
    return [NSDecimalNumber one].decimalValue;
}

Swift

var amount: Decimal {
        
    return 1.0
}

项目

Objective-C

- (NSArray<PaymentItem *> *)items {
    
    Quantity *oneUnit = [[Quantity alloc] initWithValue:[NSDecimalNumber one].decimalValue
                                      unitOfMeasurement:[Measurement units]];
    NSDecimal ten = [[NSDecimalNumber one] decimalNumberByMultiplyingByPowerOf10:1].decimalValue;
    
    PaymentItem *firstItem = [[PaymentItem alloc] initWithTitle:@"Test item #1"
                                                       quantity:oneUnit
                                                  amountPerUnit:ten];
    
    
    NSDecimal oneHundred = [[NSDecimalNumber one] decimalNumberByMultiplyingByPowerOf10:2].decimalValue;
    Quantity *oneHundredSquareMeters = [[Quantity alloc] initWithValue:oneHundred unitOfMeasurement:[Measurement area:SquareMeters]];
    
    NSDecimal seventeen = [NSDecimalNumber numberWithDouble:17.0].decimalValue;
    
    AmountModificator *tenPercents = [[AmountModificator alloc] initWithPercents:ten];
    
    NSDecimal oneThousand = [[NSDecimalNumber one] decimalNumberByMultiplyingByPowerOf10:3].decimalValue;
    
    AmountModificator *thousandMoney = [[AmountModificator alloc] initWithFixedAmount:oneThousand];
    Tax *thousandKD = [[Tax alloc] initWithTitle:@"KD 1,000.000" descriptionText:@"This is an example of a tax." amount:thousandMoney];
    
    PaymentItem *secondItem = [[PaymentItem alloc] initWithTitle:@"Test item #2"
                                                 descriptionText:@"Test item #2 awesome description"
                                                        quantity:oneHundredSquareMeters
                                                   amountPerUnit:seventeen
                                                        discount:tenPercents
                                                           taxes:@[thousandKD]];
    
    return @[firstItem, secondItem];
}

Swift

var items: [PaymentItem]? {
        
    let oneUnit = Quantity(value: 1, unitOfMeasurement: .units)
    let firstItem = PaymentItem(title:          "Test item #1",
                                quantity:       oneUnit,
                                amountPerUnit:  10)
        
    let oneHundredSquareMeters = Quantity(value:                100,
                                          unitOfMeasurement:    .area(.squareMeters))
    let tenPercents = AmountModificator(percents: 10)
    let thousandMoney = AmountModificator(fixedAmount: 1000)
    let thousandKD = Tax(title:             "KD 1,000.000",
                         descriptionText:   "This is an example of a tax.",
                         amount: thousandMoney)
        
    let secondItem = PaymentItem(title:             "Test item #2",
                                 descriptionText:   "Test item #2 awesome description.",
                                 quantity:          oneHundredSquareMeters,
                                 amountPerUnit:     17,
                                 discount:          tenPercents,
                                 taxes:             [thousandKD])
        
    return [firstItem, secondItem]
}

税金

Objective-C

- (NSArray<Tax *> *)taxes {
    
    NSDecimal fifteen = [NSDecimalNumber numberWithDouble:15.0].decimalValue;
    AmountModificator *fifteenPercents = [[AmountModificator alloc] initWithPercents:fifteen];
    
    Tax *fifteenPercentsTax = [[Tax alloc] initWithTitle:@"15 percents"
                                         descriptionText:@"Just another fifteen percents."
                                                  amount:fifteenPercents];
    
    return @[fifteenPercentsTax];
}

Swift

var taxes: [Tax]? {
        
    let fifteenPercents = AmountModificator(percents: 15)
    
    let fifteenPercentsTax = Tax(title:             "15 percents",
                                 descriptionText:   "Just another fifteen percents",
                                 amount:            fifteenPercents)
        
    return [fifteenPercentsTax]
}

运费

Objective-C

- (NSArray<Shipping *> *)shipping {
    
    NSDecimal fiveHundred = [NSDecimalNumber numberWithDouble:500.0].decimalValue;
    Shipping *deliveryToHome = [[Shipping alloc] initWithName:@"Delivery"
                                              descriptionText:@"Delivery to Home"
                                                       amount:fiveHundred];
    
    return @[deliveryToHome];
}

Swift

var shipping: [Shipping]? {
        
    let deliveryToHome = Shipping(name:             "Delivery",
                                  descriptionText:  "Delivery to Home",
                                  amount:           500)
    return [deliveryToHome]
}

发布URL

Objective-C

- (NSURL *)postURL {
    
    return [NSURL URLWithString:@"https://tap.company/post"];
}

Swift

var postURL: URL? {
        
    return URL(string: "https://tap.company/post")
}

付款描述

Objective-C

- (NSString *)paymentDescription {
    
    return @"Awesome payment description will be here.";
}

Swift

var paymentDescription: String? {
        
    return "Awesome payment description will be here.";
}

付款元数据

Objective-C

- (NSDictionary<NSString *,NSString *> *)paymentMetadata {
    
    return @{@"note": @"some note",
             @"internal_linking_id": @"id3424141414"};
}

Swift

var paymentMetadata: [String : String]? {
        
    return [
        
        "note": "some note",
        "internal_linking_id": "id3424141414"
    ]
}

付款引用

Objective-C

- (Reference *)paymentReference {
    
    return [[Reference alloc] initWithTransactionNumber:@"tr_2352358020f"
                                            orderNumber:@"ord_2352094823"];
}

Swift

var paymentReference: Reference? {
        
    return Reference(transactionNumber: "tr_2352358020f",
                     orderNumber:       "ord_2352094823")
}

付款声明描述符

Objective-C

- (NSString *)paymentStatementDescriptor {
    
    return @"Payment statement descriptor will be here";
}

Swift

var paymentStatementDescriptor: String? {
        
    return "Payment statement descriptor will be here"
}

要求3D Secure

Objective-C

- (BOOL)require3DSecure {
    
    return YES;
}

Swift

var require3DSecure: Bool {
        
    return true
}

收据设置

Objective-C

- (Receipt *)receiptSettings {
    
    return [[Receipt alloc] initWithEmail:YES sms:YES];
}

Swift

var receiptSettings: Receipt? {
        
    return Receipt(email: true, sms: true)
}

授权操作

Objective-C

- (AuthorizeAction *)authorizeAction {
    
    AuthorizeAction *captureAfterTwoHours = [AuthorizeAction captureAfterTimeInHours:2];
    return captureAfterTwoHours;
}

Swift

var authorizeAction: AuthorizeAction {
        
    return .capture(after: 2)
}

可多次保存相同的卡

Objective-C

- (BOOL)allowsToSaveSameCardMoreThanOnce {
    
    return NO;
}

Swift

var allowsToSaveSameCardMoreThanOnce: Bool {
        
    return false
}

Apple Pay 商户 ID

Objective-C

-(NSString *)applePayMerchantID
{
    return @"merchant.com.example";
}

Swift

var applePayMerchantID: String
{
	return "merchant.com.example"
}

定义可接受的卡片类型

Objective-C

- (NSArray<CardType *> *)allowedCadTypes {
    CardType* credit = [[CardType alloc]initWithCardType:Credit];
    CardType* debit = [[CardType alloc]initWithCardType:Debit];
    return @[credit,debit];
}

Swift

var allowedCadTypes: [CardType]? {
	return [CardType(cardType: .Debit), CardType(cardType: .Credit)]
}

会话代表

SessionDelegate是一个接口,你可以选择实现它来接收支付/授权/卡保存状态更新,并在支付窗口关闭时相应地更新用户界面。

以下列出了所有可用的回调函数

支付成功回调

通知接收者支付成功。只能在没有使用PayButton的情况下在购买模式下调用。

声明

Objective-C

- (void)paymentSucceed:(Charge * _Nonnull)charge onSession:(id <SessionProtocol> _Nonnull)session;

Swift

func paymentSucceed(_ charge: Charge, on session: SessionProtocol)

参数

charge:成功的费用对象。

session:会话对象。如果你没有使用PayButton,它可以是PayButton或者Session的一个实例。

支付失败回调

通知接收者支付失败。只能在没有使用PayButton的情况下在购买模式下调用。

声明

Objective-C

- (void)paymentFailedWithCharge:(Charge * _Nullable)charge error:(TapSDKError * _Nullable)error onSession:(id <SessionProtocol> _Nonnull)session;

Swift

func paymentFailed(with charge: Charge?, error: TapSDKError?, on session: SessionProtocol)

参数

charge:失败(达到充电阶段)的充电对象。

error:已发生(如果有)的错误。

session:会话对象。如果你没有使用PayButton,它可以是PayButton或者Session的一个实例。

您可以假设至少有一个,chargeerror 不是 nil

授权成功回调

通知接收者授权成功。只能在 授权 模式下调用。

声明

Objective-C

- (void)authorizationSucceed:(Authorize * _Nonnull)authorize onSession:(id <SessionProtocol> _Nonnull)session;

Swift

func authorizationSucceed(_ authorize: Authorize, on session: SessionProtocol)

参数

authorize:成功的授权对象。

session:会话对象。如果你没有使用PayButton,它可以是PayButton或者Session的一个实例。

授权失败回调

通知接收者授权失败。只能在授权模式下调用。

声明

Objective-C

- (void)authorizationFailedWithAuthorize:(Authorize * _Nullable)authorize error:(TapSDKError * _Nullable)error onSession:(id <SessionProtocol> _Nonnull)session;

Swift

func authorizationFailed(with authorize: Authorize?, error: TapSDKError?, on session: SessionProtocol)

参数

authorize:失败的授权对象(如果达到授权阶段)。

error:已发生(如果有)的错误。

session:会话对象。如果你没有使用PayButton,它可以是PayButton或者Session的一个实例。

可以假设至少有一个,authorizeerror 不是 nil

卡片保存成功回调

通知接收者客户已成功保存卡片。只能在保存卡片模式下调用。

声明

Objective-C

- (void)cardSaved:(CardVerification * _Nonnull)cardVerification onSession:(id <SessionProtocol> _Nonnull)session;

Swift

func cardSaved(_ cardVerification: CardVerification, on session: SessionProtocol)

参数

cardVerification:带有详细信息的卡片验证对象。

session:会话对象。如果你没有使用PayButton,它可以是PayButton或者Session的一个实例。

卡片保存失败回调

通知接收者,客户保存卡片失败。只能在卡片保存模式下调用。

声明

Objective-C:

- (void)cardSavingFailedWithCardVerification:(CardVerification * _Nullable)cardVerification error:(TapSDKError * _Nullable)error onSession:(id <SessionProtocol> _Nonnull)session;

Swift

func cardSavingFailed(with cardVerification: CardVerification?, error: TapSDKError?, on session: SessionProtocol)

参数

cardVerification:带有详细信息的卡片验证对象(如果达到卡片保存阶段)。

error:发生的错误。如果为 nil,请参阅 cardVerification 对象以获取错误详细信息。

session:会话对象。如果你没有使用PayButton,它可以是PayButton或者Session的一个实例。

卡令牌化成功回调

通知接收者卡令牌已成功创建。只能在卡令牌化模式下调用。

声明

Objective-C:

- (void)cardTokenized:(Token * _Nonnull)token onSession:(id <SessionProtocol> _Nonnull)session customerRequestedToSaveTheCard:(BOOL)saveCard;

Swift:

func cardTokenized(_ token: Token, on session: SessionProtocol, customerRequestedToSaveTheCard saveCard: Bool)

参数

token:由您的客户提供得卡令牌。 session:会话对象。它可以是PayButton或Session实例,如果你不使用PayButton。 saveCard:布尔标志,表示客户是否想要保存卡。实际上并没有执行保存卡的过程。

卡令牌化失败回调

通知接收者卡令牌创建失败。只能在卡令牌化模式下调用。

声明

Objective-C:

- (void)cardTokenizationFailedWithError:(TapSDKError * _Nonnull)error onSession:(id <SessionProtocol> _Nonnull)session;

Swift:

func cardTokenizationFailed(with error: TapSDKError, on session: SessionProtocol)

参数

error: 已发生的错误。 session: 会话对象。它可以是PayButton或Session的一个实例,如果你没有使用PayButton。

会话开始回调

通知接收器会话即将开始,但尚未显示SDK UI。如果您在应用程序中没有使用PayButton,并且想在SDK UI显示在屏幕上之前显示一个加载器,则可能想要使用此方法。将在所有模式下调用。

声明

Objective-C

- (void)sessionIsStarting:(id <SessionProtocol> _Nonnull)session;

Swift

func sessionIsStarting(_ session: SessionProtocol)

参数

session:会话对象。如果你没有使用PayButton,它可以是PayButton或者Session的一个实例。

会话已开始回调

通知接收者会话已成功开始并在屏幕上显示了SDK UI。如果您在应用程序中不使用 PayButton 并希望在SDK UI显示在屏幕上后隐藏加载器,则可能希望使用此方法。将在所有模式下被调用。

声明

Objective-C

- (void)sessionHasStarted:(id <SessionProtocol> _Nonnull)session;

Swift

func sessionHasStarted(_ session: SessionProtocol)

参数

session:会话对象。如果你没有使用PayButton,它可以是PayButton或者Session的一个实例。

会话启动失败回调

通知接收者会话启动失败,将不会在屏幕上显示SDK UI。如果您在应用程序中不使用 PayButton 并希望在会话失败时隐藏加载器,则可能希望使用此方法。有关实际失败原因,请实现此协议中的其他方法并监听回调。将在所有模式下被调用。

声明

Objective-C

- (void)sessionHasFailedToStart:(id <SessionProtocol> _Nonnull)session;

Swift

func sessionHasFailedToStart(_ session: SessionProtocol)

参数

session:会话对象。如果你没有使用PayButton,它可以是PayButton或者Session的一个实例。

会话取消回调

通知接收者用户已取消支付/授权。在所有模式下都将调用。

声明

Objective-C

- (void)sessionCancelled:(id <SessionProtocol> _Nonnull)session;

Swift

func sessionCancelled(_ session: SessionProtocol)

参数

session:会话对象。如果你没有使用PayButton,它可以是PayButton或者Session的一个实例。

会话外观

如果您需要一些UI定制以匹配您的用户界面并提供出色的用户体验,则可能希望实现会话外观协议。

请参阅会话外观类的文档,以了解当前可用的自定义类型。

示例

示例应用程序集成可在示例文件夹中获得。


文档

文档可在GitHub页面找到。
库中还附带了已文档化的源代码。