点击TapApplePayKit-iOS 1.0.23

TapApplePayKit-iOS 1.0.23

Osama Rabie维护。



 
依赖
CommonDataModelsKit-iOS>= 0
TapNetworkKit-iOS>= 0
TapApplicationV2>= 0
 

  • Tap Payments

TapApplePayKit-iOS

这是一个SDK,它可以提供在您的应用程序中显示、处理和授权Pay的接口。

Platform CocoaPods Compatible

Tap Apple Pay Kit Demo

要求

要使用SDK,必须满足以下要求

  1. Xcode 11.0或更高版本
  2. Swift 4.2或更高版本(Xcode中预装)
  3. 应用程序的部署目标框架版本:iOS 12.0或更高

安装


CocoaPods 安装

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

$ gem install cocoapods

Podfile

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

platform :ios, '12.0'
use_frameworks!

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

target 'MyApp' do
    
    pod 'TapApplePayKit-iOS'

end

然后,运行以下命令

$ pod update

功能


TapApplePayKit 提供了广泛的方法,用于轻松地在您的应用程序中使用 Pay

  • 使用 Tap Apple Pay 按钮

    • 可定制的 Apple pay 按钮
    • 处理 Apple 支付授权和处理
    • 主题和标题可自定义。
    • Simulator-Screen-Shot-i-Phone-11-2020-04-15-at-09-50-17
  • 使用您的 UI

    • 您可以在方便的时刻从自己的 UI 开始 TapApplePayKit

    • 将处理 Apple pay 授权。

    • 将 Apple Pay 处理结果委托回。

    使其成为市场上最具包容性的 pod 之一,同时也是最容易集成的之一。

模型

本节将介绍 kit 中使用的模型。这是了解如何利用和使用该套件的重要介绍。

TapApplePayPaymentNetwork

这是一个用于封装PKPaymentNetwork的表达性枚举。以下列出了支持的情况,并指出任何情况是否需要最低iOS版本。

Swift:

case Amex
case CartesBancaires
case Discover
case Eftpos
case Electron
@available(iOS 12.1.1, *)
case Elo
case idCredit
case Interac
case JCB
@available(iOS 12.1.1, *)
case Mada
case Maestro
case MasterCard
case PrivateLabel
case QuicPay
case Suica
case Visa
case VPay

TapApplePayStatus

该枚举用于封装当前设备/用户状态,以便处理Apple Pay。

Swift:

 /// This means the current device/user has Apple pay activated and a card belongs to the given payment networks
    case Eligible
    /// This means the current device/user has Apple pay activated but has no card belongs to the given payment networks
    case NeedSetup
    /// This means the current device/user cannot use Apple pay from Apple
    case NotEligible

TapApplePayButtonType

该枚举是PKPaymentButtonType的封装,用于定义TapApplePayButton的类型/上下文,这将影响按钮的标题。

Swift:

 /// Title : Pay
    case AppleLogoOnly
 /// Title : Buy with Pay
    case BuyWithApplePay
 /// Title : Setup Pay
    case SetupApplePay
 /// Title : Pay with Pay
    case PayWithApplePay
 /// Title : Donate with Pay
    case DonateWithApplePay
 /// Title : Checkout with Pay
    case CheckoutWithApplePay
 /// Title : Book with Pay
    case BookWithApplePay
 /// Title : Subscribe with Pay
    case SubscribeWithApplePay

TapApplePayButtonType

该枚举是PKPaymentButtonStyle的封装,用于定义TapApplePayButton的样式。

Swift:

 /// Full black with white title
    case Black
/// Full white with black title
    case White
/// Full white with black border and black title
    case WhiteOutline

TapApplePayToken

表示 TapApplePayToken 模型的类。它包装 PKPaymentToken,并用于 TapApplePayKit 的 DataSource。

此外,它将原始 PKPaymentToken 数据转换为字符串和 JSON,并公开访问。

Swift:

 /**
     Create TapApplePayToken object with an apple payment token
     - Parameter rawAppleToken: This is the raw apple token you want to wrap. All other representations will be converted automatically
     */
    public init(with rawAppleToken:PKPaymentToken)

TapApplePayRequest

表示标识事务的请求细节,由 TapApplePayKit 的数据源填写。应用必须传递必要的信息以满足 Pay 的要求。

Swift:

/**
     Creates a Tap Apple Pay request that can be used afterards to make an apple pay request
     - Parameter countryCode: The country code where the user transacts default .US
     - Parameter currencyCode: The currency code the transaction has default .USD
     - Parameter paymentNetworks:  The payment networks you  want to limit the payment to default [.Amex,.Visa,.Mada,.MasterCard]
     - Parameter var paymentItems: What are the items you want to show in the apple pay sheet default  []
     - Parameter paymentAmount: The total amount you want to collect
     - Parameter merchantID: The apple pay merchant identefier default ""
     **/
    public func build(with countryCode:TapCountryCode = .US, paymentNetworks:[TapApplePayPaymentNetwork] = [.Amex,.Visa,.MasterCard], paymentItems:[PKPaymentSummaryItem] = [], paymentAmount:Double,currencyCode:TapCurrencyCode = .USD,merchantID:String)

Controllers

本节描述您应用将处理的实际控制器。控制器取决于应用使用的集成模式。无论使用我们的 TapApplePayButton 还是启动自家的 UI 的套件。

TapApplePayButton

TapApplePayKit 提供了一个现成的 UIView,用于向用户显示 Apple Pay 按钮。按钮会自动处理并在点击时启动和过程 Apple 支付。

该按钮提供了自定义外观的方法以及数据源协议,用于填充启动Apple Pay过程所需的数据。此外,它还提供了一个代理协议,当用户授权支付时,可以将解析后的Apple支付令牌返回到您的应用程序中。

数据源,Swift:

/// Data source to provide needed data for the apple pay button to start the apple authorization process
@objc public protocol TapApplePayButtonDataSource {
    /// This s the Tap wrapper of Apple pay request and it is a must to be correctly filled before firing Apple pay request
    var tapApplePayRequest:TapApplePayRequest { get }
}

代理,Swift:

/// Delegate of methods Tap Apple Pay will use to pass back the results of the authorization process
@objc public protocol TapApplePayButtonDelegate {
    /**
     This method will be called once the authprization happened
     - Parameter appleToken: The correctly and authorized tokenized payment data from Apple Pay kit
     */
    func tapApplePayFinished(with tapAppleToken:TapApplePayToken)->()
}

将视图框架设置为任何正常的UIView后,您可以按照以下步骤设置它以提供所需的个性化外观:

Swift:

/**
     Method to configure the tap apple pay button
     - Parameter tapApplePayButtonClicked: Inform when the apple pay button is clicked so you can do any logic if you want
     - Parameter buttonType: The type/title to show for the Apple pay button
		 - Parameter buttonStyle: The UI style you want to apply to the button
     */
    public func setup(tapApplePayButtonClicked:((TapApplePayButton)->())? = nil,buttonType:TapApplePayButtonType = .AppleLogoOnly, buttonStyle:TapApplePayButtonStyleOutline = .Black)

TapApplePay

TapApplePayKit 提供了一个基于您自定义UI内的事件启动Apple Pay授权过程的接口。

当您想要在自己的UI中使用并希望在应用程序流程的某个特定点启动Apple Pay过程时,请使用该功能。使用block based development,无需实现任意数据源或代理,即可尽可能简单地做到这一点。

以下是一行调用来开始支付过程:

Swift:

/**
     Public interface to be used to start Apple pay athprization process without the need to include out Tap APple Pay button
     - Parameter presenter: The UIViewcontroller you want to show the native Apple Pay sheet in
     - Parameter tapApplePayRequest: The Tap apple request wrapper that has the valid data of your transaction
     - Parameter tokenized: The block to be called once the user successfully authorize the payment
     */
    public func authorizePayment(in presenter:UIViewController, for tapApplePayRequest:TapApplePayRequest, tokenized:@escaping ((TapApplePayToken)->()))

示例

从您的UI内部启动KIT

Swift:

import TapApplePayKit_iOS
import enum CommonDataModelsKit_iOS.TapCountryCode
import enum CommonDataModelsKit_iOS.TapCurrencyCode

// Prepare the needed parameters, to adjust them once you need to start the process
let myTapApplePayRequest:TapApplePayRequest = .init()
let tapApplePay:TapApplePay = .init()
// Set your tap keys if you need to generate TAP token for apple pay raw token
TapApplePay.secretKey = .init(sandbox: "sk_test_cvSHaplrPNkJO7dhoUxDYjqA", production: "sk_live_QglH8V7Fw6NPAom4qRcynDK2")
// Set your sdk environment if you need to generate TAP token for apple pay raw token
TapApplePay.sdkMode = .sandbox
	
// Fill in the required data for your transaction to the TapApplePayRequest object
myTapApplePayRequest.build(with: .US, paymentNetworks: [.Amex,.Visa,.MasterCard], paymentItems: [PKPaymentSummaryItem(label: "My Best Seller", amount: 10)], paymentAmount: 10, currencyCode: .USD, merchantID:"merchant.tap.gosell")
// PS : you can use the default parameters and just pass the amount and merchant id as follows:
myTapApplePayRequest.build(paymentAmount: 10, merchantID: "merchant.tap.gosell")


// Then you can start the payment authorization process with one call whenever you. want as follows
tapApplePay.authorizePayment(in: self, for: myTapApplePayRequest) { [weak self] (token) in
	print("I can do whatever i want with the result token")
}

使用TapApplePayButton

Swift:

import TapApplePayKit_iOS
import enum CommonDataModelsKit_iOS.TapCountryCode
import enum CommonDataModelsKit_iOS.TapCurrencyCode

// Prepare the needed parameters, to adjust them once you need to start the process
let myTapApplePayRequest:TapApplePayRequest = .init()
let tapApplePay:TapApplePay = .init()
// Create the TapApplePayButton by providing the bounds if the uiview holder inside your layoutu
let tapApplePayButton = TapApplePayButton.init(frame: tapApplePayButtonHolder.bounds)

// Then we need to setup the button to provide the needed UI customisation, you can use the default or provide yours.

tapApplePayButton.setup(tapApplePayButtonClicked: { (clickedTapApplePayButton:TapApplePayButton) in
            print("A Tap apple pay button was clicked !")
        }, buttonType: .PayWithApplePay, buttonStyle: .Black)
// PS : You can use the default values and just call:
tapApplePayButton.setup()
// Add the Button to your UI
tapApplePayButtonHolder.addSubview(tapApplePayButton)

// Provide the data source and the delegate protocols
tapApplePayButton.dataSource = self
tapApplePayButton.delegate   = self


// Implement the delegates and the data sources needed methods
extension ViewController:TapApplePayButtonDataSource,TapApplePayButtonDelegate {
  // You have to return the TapApplePayRequest which we defined up, to start the apple pay process
    var tapApplePayRequest: TapApplePayRequest {
        return myTapApplePayRequest
    }
    
    func tapApplePayFinished(with tapAppleToken: TapApplePayToken) {
        print("I can do whatever i want with the result token")
    }
}