你是否想通过仅编写几行代码就接受来自不同国家和不同支付系统的移动用户的支付?Paymentwall SDK是一个全球移动支付网关,可以接受来自200多个国家以及100多个替代支付方式的支付。我们现在提供了iOS SDK,它将成为你应用的本地部分,它消除了支付时打开网页的需求。步骤更少,效率更高,你的转化率无疑会得到提升!你所要做的就是将库导入你的项目中,并配置它以开始接受应用内支付。这很简单!在此,我们将引导你完成整个流程。
XCode 8.0+, iOS 8.0+
SDK集成需要一个项目密钥。在你的商户账户的Paymentwall.com应用设置中获取这些Paymentwall API凭证。
我们的SDK作为静态库或公开存储库提供。
-ObjC
。bridging-header.h
文件,然后将以下文件导入到头文件中,例如#import <PWCoreSDK/PWCoreSDK.h>
更新:如果安装任何插件时CoreSDK发生了更新,你应该还检查更新其余插件。
PWCoreSDK.sharedInstance().setupPaymentwall(withProjectKey: "YOUR PUBLIC KEY", secretKey: "YOUR SECRET KEY", requestTimeout: 30)
可选:额外的设置可以在下面的“额外设置”部分找到
项目密钥:如果项目的密钥设置为nil,所有支付选项都会使用此项目密钥,您也可以指定它们自己的项目密钥
密钥:如果您在这里指定了它, PWLocal和本地支付选项插件将使用此密钥作为默认密钥
PWCoreSDKDelegate
协议以处理支付响应func paymentResponse(_ response: PWCoreSDKResponse?) {
guard let response = response else { return }
switch response.responseCode {
case .SUCCESSFUL:
case .FAILED:
case .CANCEL:
case .MERCHANT_PROCESSING:
//Example when you use Brick and `useNativeFinishDialog == true` can be found below
}
switch response.paymentType {
case .NONE:
case .MINT:
case .PWLOCAL:
case .BRICK:
case .MOBIAMO:
case .OTHERS:
}
}
PWCoreSDK.sharedInstance().addBrickPayment(withPublicKey: nil, useNativeFinishDialog: true, cardScannerPlugin: PWCardScannerPlugin.sharedInstance())
noPrice
来指定你是否想为每个国家使用默认的Mobiamo价格PWCoreSDK.sharedInstance().addMobiamoPayment(withAppID: nil, noPrice: true)
PWCoreSDK.sharedInstance().addMintPayment(withAppID: nil)
type
可以是VIRTUAL_CURRENCY / DIGITAL Goods_FLEXIBLE / DIGITAL Goods_DEFAULT / CARTPWCoreSDK.sharedInstance().addPWLocalPayment(with: .DIGITAL_GOODS_FLEXIBLE, secretKey: nil)
PWCoreSDK.sharedInstance().addCustomPaymentOptions([alipay, unionpay, ...])
注意:这些支付选项将连同PWLocal一起放置在
本地支付
中。
PaymentObject
类创建新的支付,并将其分配给CoreSDKlet payment = PaymentObject()
payment.name = choosenItem.name
payment.price = Double(choosenItem.price)!
payment.currency = "USD"
payment.image = choosenItem.image
payment.userID = "test_user"
payment.itemID = choosenItem.name+"id"
payment.signVersion = 3
let customSetting = ["widget":"pw",
"ag_type":"fixed"]
payment.pwLocalParams = customSetting
PWCoreSDK.sharedInstance().setPaymentObject(payment)
注意:pwLocalParams可以是字典或以下定义的任何类:
CartDefaultWidget
、DigitalGoodsDefaultWidget
、DigitalGoodsFlexibleWidget
、VirtualCurrency
,参考它们的头文件以获取所需的属性或PWLocal文档。键和值如价格、金额、货币代码、货币、ag_name、ag_external_id、uid将被忽略,并使用你在PaymentObject
中描述的值。
PWCoreSDK.showPaymentOptionsViewController(withParentViewcontroller: self, delegate: self, showCompletion: nil)
PWCoreSDK.sharedInstance().setUseGameUI(true)
PWCoreSDK.sharedInstance().setUseNativeFinishDialogForAllMethods(false)
response: PWCoreSDKResponse
将包含与它一起的token: BrickToken
如果将 useNativeFinishDialog
设置为 false
,则在获取令牌成功后,SDK 将会关闭,response.responseCode
也会是 .MERCHANT_PROCESSING
,您需要自己处理成功/失败/3D安全,且存储卡片功能将不可用。
如果将 useNativeFinishDialog
设置为 true
,载入弹出窗口将持续显示,您在服务器上处理令牌后,发布一个 Notification
来使用 SDK 成功或失败对话框,SDK 也会再次调用代理以返回 .SUCCESS
或 .FAILED
。
if response.paymentType == .BRICK {
if let returnedToken = response.token {
//Process the token with your server here asynchronous
//When done:
NotificationCenter.default.post(name: Notification.Name(BRICK_TOKEN_PROCESSED_FINISH), object: nil, userInfo: nil)
}
}
将通过 Dictionary 传递错误信息作为 ["error": errorMessage]
通过 userInfo
,SDK 将自动显示失败对话框而不是成功对话框。
如果发生3D安全,我们同样支持3D安全,通过 Dictionary 中的 ["secure": urlString]
通过 userInfo
传递URL,用户完成安全信息的输入后,SDK 将处理显示3D安全并将 SUCCESS/FAILED
返回给应用。
如果您想为用户启用存储卡片功能,请通过 userInfo
将 Charge 对象传递给我们 SDK,Charge 对象的格式可在我们的 Brick 文档 中找到。
如果您希望手动提供您的 PWLocal 签名
//Define all params in step 8., and extra custom settings, then get `stringToSign`:
let payment = PaymentObject()
payment.name = choosenItem.name
payment.price = Double(choosenItem.price)!
payment.currency = "USD"
payment.image = choosenItem.image
payment.userID = "test_user"
payment.itemID = choosenItem.name+"id"
payment.signVersion = 3
let customSetting = ["widget":"pw",
"ag_type":"fixed"]
let strToSign = PWCoreSDK.sharedInstance().getStringToSign(customSetting, paymentObject: payment)
//Calculate your sign and set it
customSetting["sign"] = sha256(text: "\(strToSign!)YOUR SECRET KEY")
payment.pwLocalParams = customSetting
Paymentwall SDK 支持外部支付系统注入(这些都在我们定义的支付系统(PS)列表中)。每次您想添加一个新支付系统时,您必须将其本地 SDK 和我们的插件框架一起包含到项目中,我们的框架将处理创建所有必要的参数,然后您可以使用它们来显示本地支付 SDK。
pod 'PW[Local payment method]Plugin'
通过 Cocoapods 添加插件,或手动将 PW[Local payment method]Plugin.a
及其头文件拖到您的项目中。bridging-headers.h
。注意:所有插件都支持您自己的签名字符串,如果您在 CoreSDK 和 PluginSDK 中均不指定密钥,请使用
plugin.getStringToSign()
获取签名字符串,然后将您的签名字符串添加到plugin.signString
。