TillhubPointOfSaleSDK 0.0.3

TillhubPointOfSaleSDK 0.0.3

Andreas Hilbert 维护。



  • TillhubGmbH

TillhubPointOfSaleSDK-iOS

Build Status Version License Platform Swift Version

使用 Tillhub 创建销售和处理支付

要求

  • 请联系 [email protected] 注册您的应用程序
  • iOS 10 或更高版本
  • Xcode 10.2 或更高版本
  • Swift 5.x

入门

将 SDK 添加到您的项目中

CocoaPods

platform :ios, '10.0'
pod 'TillhubPointOfSaleSDK', :git => 'https://github.com/tillhub/TillhubPointOfSaleSDK-iOS.git'

请确保运行 pod update 并使用 pod install --repo-update 来确保您安装了 SDK 的最新版本。


更新您的Info.plist

要开始使用Tillhub销售点SDK,您需要根据以下步骤更改Info.plist文件。

首先,导航到Xcode中的项目设置,点击“Info”选项卡。在“自定义iOS目标属性”下

  1. 添加一个新条目,键为LSApplicationQueriesSchemes
  2. 将“类型”设置为数组
  3. 将值tillhub添加到数组中。

接下来,创建一个URL方案,以便Tillhub销售点在客户完成交易后可以重新打开您的应用。如果您的应用已经有URL方案,您可以直接使用。

最后,打开“URL类型”部分,点击“+”按钮添加新的URL类型。将值设置为以下内容

属性
标识符 TillhubPointOfSaleSDK
URL方案 您的URL方案
角色 编辑器

在Tillhub中注册您的应用

请通过[email protected]联系Tillhub,以便注册您的应用。这样,Tillhub应用可以使用包含所有相关结果的正确响应调用回调您的应用。

示例项目

示例项目展示了最常见的用法。

请联系Tillhub以获取另一个测试帐户的设置帮助,或为[email protected]请求密码。


Swift

导入声明: import TillhubPointOfSaleSDK

- 创建一个带有完整的购物车详情的TPOSRequest

// common header
let header = TPOSRequestHeader(clientID: "Your client's Tillhub account ID",
                               actionPath: TPOSRequestActionPath.checkout,
                               payloadType: TPOSRequestPayloadType.cart,
                               callbackUrlScheme: "Your Url scheme",
                               autoReturn: true, // Tillhub will automatically return to your application
                               comment: "Testing a checkout with cart details")

// Minimal cart item example
let cartItem1 = try TPOSCartItem(productId: "A Tillhub product ID",
                                 currency: "EUR",
                                 pricePerUnit: 99.95,
                                 vatRate: 0.19)

// Extended cart item example
let discount = try TPOSCartItemDiscount(type: TPOSCartItemDiscountType.relative,
                                        value: 0.15,
                                        comment: "A 15% discount.") 
                                                
let cartItem2 = try TPOSCartItem(type: TPOSCartItemType.item,
                                 quantity: 2.0,
                                 productId: "A Tillhub product ID",
                                 currency: "EUR",
                                 pricePerUnit: 99.95,
                                 vatRate: 0.19,
                                 title: "Another test product",
                                 comment: "Yet another fancy product",
                                 salesPerson: TPOSStaff(name: "Hubert Cumberdale", customId: "0089"),
                                 discounts: [discount])
        
// set up the cart
let paymentIntent = TPOSPaymentIntent(allowedTypes: [TKPOSPaymentType.cash],
                                      automaticType: TKPOSPaymentAutomaticType.automaticCash)

let cart = try TPOSCart(taxType: TPOSTaxType.inclusive,
                        items: [cartItem1, cartItem2],
                        paymentIntent: paymentIntent,
                        customId: "My custom reference",
                        title: "My test cart's title",
                        comment: "My test cart's comment",
                        customer: TPOSCustomer(name: "Marjory Stewart Baxter", customId: "000432001"),
                        cashier: TPOSStaff(name: "Jeremy Fisher", customId: "c_sdj_234"))
                        
// create the request
let cartRequest = TPOSRequest(header: header, payload: cart)

// perform request
TPOS.perform(request: cartRequest) { (error) in
    if let error = error { 
    	print("An error occured: \(error.localizedDescription)") 
    }
	...
}

- 创建一个引用现有购物车的TPOSRequest

// common header
let header = TPOSRequestHeader(clientID: "Your client's Tillhub account ID",
                               actionPath: TPOSRequestActionPath.load,
                               payloadType: TPOSRequestPayloadType.cartReference,
                               callbackUrlScheme: "Your Url scheme",
                               autoReturn: true, // Tillhub will automatically return to your application
                               comment: "Testing a checkout with a cart reference")

        
// set up cart reference
let cartReference = try TPOSCartReference(cartId: "A Tillhub cart ID")
                        
// create the request
let cartReferenceRequest = TPOSRequest(header: header, payload: cartReference)

// perform request
TPOS.perform(request: cartReferenceRequest) { (error) in
    if let error = error { 
    	print("An error occured: \(error.localizedDescription)") 
    }
	...
}

- 解析通过UIApplication代理方法从Tillhub收到的响应

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
	let response = try TPOSResponse(url: url)
	switch response.header.status {
	case .success:
		print("success, response: \(response)")
	case .failure:
		print("failure, error: \(response.header.localizedErrorDescription ?? "- no reason given -")")
	}
}

支持

如果在项目中使用此SDK遇到困难,请创建一个带有 tillhub-sdk 标签的问题 Stack Overflow。我们的团队会监控该标签,并能为您提供帮助。如果您认为SDK本身存在问题,请创建一个问题。

许可证

版权所有 2019 Tillhub

许可协议:MIT。

除非适用法律要求或书面同意,在许可证下分发的软件按“原样”基础分发,不提供任何明示或暗示的保证或条件。有关许可证的特定语言规范权限和限制,请参阅许可证。