goSellAppClipSDK 1.0.5

goSellAppClipSDK 1.0.5

Osama Rabie 维护。



  • 点击支付

goSell iOS SDK

用于 goSell API 的 iOS SDK。

Platform Build Status CocoaPods Compatible Documentation

一个完全覆盖您的 iOS 应用中支付/授权/卡片保存过程的库。

目录


  1. 要求
  2. 安装
    1. 使用 CocoaPods 进行安装
  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+ 项目中,请确保您正在使用 goSellSDK 版本 >= 2.2.33

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

platform :ios, '12.0'
use_frameworks!

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

target 'MyApp' do
    
    pod 'goSellSDK'

end

然后,运行以下命令

$ pod update

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

platform :ios, '11.0'
use_frameworks!

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

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

end

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

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

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

end

设置


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

goSellSDK 类属性

以下是 goSellSDK 类中您可以操作的属性列表。确保在使用 SDK 之前完成设置。

密钥

为了设置它,请将以下代码行添加到您的项目中的某个位置,并确保在调用 goSellSDK 之前这样做,否则将抛出异常。 必需

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正在运行的模式,可以是沙盒生产

使用此属性来测试您的沙盒交易集成。

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

语言

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 中的商家身份。您可以为多个原生动.IContainer Web 应用程序使用相同的商家标识符。它永不失效。

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

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

      2. 在“标识符”下,通过右上角的过滤器选择商家标识符。

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

        注意: 如果页面顶部出现提示您需要接受协议的横幅,请点击“审查协议”按钮并按照说明操作,然后再继续。

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

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

      6. 点击选择文件。

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

      8. 点击继续。

      9. 点击下载。

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

  3. 将您的 .cer 文件、商家标识符和应用捆绑 ID 发回 Tap 团队。

  4. 从 Xcode 中的项目中启用 Apple Pay 功能并选择商家标识符。img

    1. 您执行了所有前面的步骤时,会显示 Tap Apple Pay 按钮
    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 BOOLBool 指明按钮是否启用。
可能您需要用于内部逻辑。
dataSource id<SessionDataSource>SessionDataSource 会话数据源。所有输入的支付信息都会通过此协议传递。必需。
delegate id<SessionDelegate>SessionDelegate 会话代理。支付状态以及所有输出支付信息都会通过此协议传递。
appearance id<SessionAppearance>SessionAppearance 会话外观。只有在需要UI定制时才实现。更多信息请参阅“会话外观”部分。

方法

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

会话

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

属性

属性 类型 描述
Objective-CSwift Objective-CSwift
dataSource id<SessionDataSource>SessionDataSource 会话数据源。所有输入的支付信息都会通过此协议传递。必需。
delegate id<SessionDelegate>SessionDelegate 会话代理。支付状态以及所有输出支付信息都会通过此协议传递。
appearance id<SessionAppearance>SessionAppearance 会话外观。只有在需要UI定制时才实现。更多信息请参阅“会话外观”部分。
canStart BOOLBool 只读属性。定义是否可以使用提供的 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 购买授权卡储蓄
mode TransactionMode false 事务模式(购买授权卡储蓄卡令牌化)。如果此属性未实现,则使用 购买 模式。
customer Customer true 客户信息。有关创建客户的更多详细信息,请参阅 Customer 类参考。
currency Currency truefalse 交易货币。
amount NSDecimalDecimal false 支付/授权金额。
注意:为了有支付金额,应实现 amountitems 之一。如果两者都实现,则优先使用 items
items NSArray <PaymentItem *>[PaymentItem] false 要支付的项的列表。
注意:为了有支付金额,应实现 amountitems 之一。如果两者都实现,则优先使用 items
destinations NSArray <Destination *>[Destination] false 商户期望从支付/授权交易中收款的账户列表。
merchantID NSString字符串 false 如果您有多个商户账户,请通过此字段指定您想要使用哪个。
taxes NSArray <Tax *>[Tax] false 您可以在此处指定税务详情。默认情况下,没有税务。
注意:指定税务会影响支付/授权总额。
shipping 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 BOOLBool false 定义是否需要3D安全检查。如未实现,则被视为
注意: 如果您禁用3D安全检查,仍然可能会发生。最终决定由Tap做出。
receiptSettings 收据 false 收据接受者详细信息。
authorizeAction AuthorizeAction falsetruefalse 授权成功后要执行的操作。
allowsToSaveSameCardMoreThanOnce BOOLBool false 定义是否可以同一张卡保存多次。
注意: 同一张卡指的是完全相同的数据集。例如,如果客户指定相同的卡详细信息,但卡持有人姓名不同,我们将将其视为不同的卡。
applePayMerchantID NSString字符串 false 定义从Apple开发者账户获取的Apple Pay商户ID。
allowedCadTypes NSArray<\CardType *>[CardType] false 定义商户希望其客户使用的允许的卡类型(信用卡、借记卡、全部)。
isSaveCardSwitchOnByDefault BOOLBool false 定义是否默认启用保存卡开关。
注意: 如果此属性的值为,则开关将保持关闭状态,直到填写有效的卡信息。之后将自动开启。
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种货币的支付处理,允许您以客户的本币进行收费,同时收取自己的货币。如果您有全球业务,这将特别有帮助,因为使用客户的本币收费可以提高销售额。

支持货币
Currency 代码
阿联酋迪拉姆 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]
}

发布链接

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 是一个接口,您可能希望实现它以接收支付/授权/卡片保存状态更新,并在支付窗口关闭时相应地更新用户界面。

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

支付成功回调

通知接收者支付已成功。只能在 购买 模式下调用。

声明

Objective-C

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

Swift

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

参数

charge:成功的付款对象。

session:会话对象。如果您不使用PayButton,它可以是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或会话实例。

您可能假设至少有一个,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或会话实例。

权限失败回调

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

声明

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或会话实例。

可以假设至少有一个,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或会话实例。

卡保存失败回调

通知接收者客户未能保存卡。只能在卡保存模式下调用。

声明

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或会话实例。

卡令牌成功创建回调

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

声明

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,可以是PayButton或Session的实例。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或会话实例。

会话开始回调

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

声明

Objective-C

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

Swift

func sessionHasStarted(_ session: SessionProtocol)

参数

session:会话对象。如果您不使用PayButton,它可以是PayButton或会话实例。

会话启动失败回调

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

声明

Objective-C

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

Swift

func sessionHasFailedToStart(_ session: SessionProtocol)

参数

session:会话对象。如果您不使用PayButton,它可以是PayButton或会话实例。

会议取消回调

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

声明

Objective-C

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

Swift

func sessionCancelled(_ session: SessionProtocol)

参数

session:会话对象。如果您不使用PayButton,它可以是PayButton或会话实例。

会话外观

如果您需要一些用户界面定制以匹配您的界面并提供良好的用户体验,则可能希望实现 SessionAppearance 协议。

请参阅 SessionAppearance 类文档,查看当前可用的定制类型。

示例

示例应用程序集成可在 Example 文件夹中找到。


文档

文档可在 github-pages 上找到。
还附带了库的文档化源代码。