Genesis iOS SDK
目录
要求
- iOS 9.0+
- Xcode 9.2
安装
GenesisSwift 需要 Swift 4,因此请确保您有 Xcode 9。
CocoaPods
在您的Podfile
中:
pod 'GenesisSwift'
Carthage
在您的Cartfile
中:
git "https://github.com/GenesisGateway/ios_sdk"
Git Submodule
-
将GenesisSwift作为子模块克隆到您选择的目录中,例如Libraries/GenesisSwift。
git submodule add https://github.com/GenesisGateway/ios_sdk Libraries/GenesisSwift git submodule update --init
-
将
GenesisSwift.xcodeproj
拖到您的项目树中作为子项目。 -
在您的项目构建阶段下,展开目标依赖关系。点击+按钮并添加GenesisSwift。
-
展开链接二进制库阶段。点击+按钮并添加GenesisSwift。
-
在左上角点击+按钮添加复制文件构建阶段。设置目录为Frameworks。点击+按钮并添加GenesisSwift。
基本用法
import GenesisSwift
...
//PaymentAddress for Genesis
let paymentAddress = PaymentAddress(firstName: firstName,
lastName: lastName,
address1: address1,
address2: address2,
zipCode: zipCode,
city: city,
state: state,
country: IsoCountryCodes.search(byName: "United States"))
//PaymentTransactionType for Genesis
let paymentTransactionType = PaymentTransactionType(name: .sale)
//PaymentRequest for Genesis
let paymentRequest = PaymentRequest(transactionId: transactionId,
amount: amount.explicitConvertionToDecimal()!,
currency: Currencies().USD,
customerEmail: customerEmail,
customerPhone: customerPhone,
billingAddress: paymentAddress,
transactionTypes: [paymentTransactionType],
notificationUrl: notificationUrl)
//Credentials for Genesis
let credentials = Credentials(withUsername: "YOUR_USERNAME", andPassword: "YOUR_PASSWORD")
//Configuration for Genesis
let configuration = Configuration(credentials: credentials, language: .en, environment: .staging, endpoint: .emerchantpay)
//Init Genesis with Configuration and WPFPaymentRequest
let genesis = Genesis(withConfiguration: configuration, paymentRequest: paymentRequest, forDelegate: self)
//show Genesis payment form
//Push to navigation controller
genesis.push(toNavigationController: navigationController!, animated: true)
//Present to modal view
genesis.present(toViewController: self, animated: true)
//Use genesis.genesisViewController() and show how you want
guard let genesisViewController = genesis.genesisViewController() else {
return
}
show(genesisViewController, sender: nil)
...
// MARK: - GenesisDelegate
extension YourViewController: GenesisDelegate {
func genesisDidFinishLoading() {
...
}
func genesisDidEndWithSuccess() {
...
}
func genesisDidEndWithFailure(errorCode: GenesisErrorCode) {
...
}
func genesisDidEndWithCancel() {
...
}
func genesisValidationError(error: GenesisValidationError) {
print(error.errorUserInfo)
...
}
}
其他用途
设置交易类型必需的参数
let paymentTransactionType = PaymentTransactionType(name: .idebitPayin)
paymentTransactionType.customerAccountId = "customerAccountId"
paymentRequest.transactionTypes = [paymentTransactionType]
设置用途或描述
paymentRequest.usage = "Usage"
paymentRequest.paymentDescription = "Description"
设置邮寄地址
let shippingAddress = PaymentAddress(firstName: "firstName",
lastName: "lastName",
address1: "address1",
address2: "address2",
zipCode: "zipCode",
city: "city",
state: nil,
country: IsoCountryCodes.search(byName: "Country"))
paymentRequest.shippingAddress = shippingAddress
设置风险参数
let riskParams = RiskParams()
riskParams.userId = "userId"
riskParams.sessionId = "sessionId"
riskParams.ssn = "ssn"
riskParams.macAddress = "macAddress"
riskParams.userLevel = "userLevel"
riskParams.email = "email"
riskParams.phone = "phone"
riskParams.remoteIp = "remoteIp"
riskParams.serialNumber = "serialNumber"
riskParams.panTail = "panTail"
riskParams.bin = "bin"
riskParams.firstName = "firstName"
riskParams.lastName = "lastName"
riskParams.country = IsoCountryCodes.search(byName: "Country")
riskParams.pan = "pan"
riskParams.forwardedIp = "forwardedIp"
riskParams.username = "username"
riskParams.password = "password"
riskParams.binName = "binName"
riskParams.binPhone = "binPhone"
paymentRequest.riskParams = riskParams
如何在WPF API中使用管理重复
let firstDate = Date().dateByAdding(1, to: .month)
let automaticManagedRecurrring = ManagedRecurringParams.Automatic(period: 22, interval: .days, firstDate: firstDate,
timeOfDay: 5, amount: 500, maxCount: 10)
let managedRecurring = ManagedRecurringParams(mode: .automatic(automaticManagedRecurrring))
let transactionType = PaymentTransactionType(name: .initRecurringSale3d)
transactionType.managedRecurring = managedRecurring
paymentRequest.transactionTypes = [transactionType]
如何在WPF API中使用管理重复为印度卡片(提供数据仅为示例,根据协议填写您的具体数据)
let manualManagedRecurrring = ManagedRecurringParams.Manual(paymentType: .subsequent, amountType: .fixed, frequency: .weekly, registrationReferenceNumber: "123434",
maxAmount: 200, maxCount: 99, validated: true)
let managedRecurring = ManagedRecurringParams(mode: .manual(manualManagedRecurrring))
let transactionType = PaymentTransactionType(name: .initRecurringSale)
transactionType.managedRecurring = managedRecurring
paymentRequest.transactionTypes = [transactionType]
为了强制执行3DSecure v2身份验证协议,为以下交易类型设置3DSv2参数:Authorize3d、Sale3d和InitRecurringSale3d。
// depending on the context, dates can be current, in the past, and in the future
var threeDSV2Params = ThreeDSV2Params()
threeDSV2Params.controlParams.challengeWindowSize = .fullScreen
threeDSV2Params.purchaseParams = ThreeDSV2Params.PurchaseParams(category: .service)
threeDSV2Params.recurringParams = ThreeDSV2Params.RecurringParams(expirationDate: Date(), frequency: 30)
threeDSV2Params.merchantRiskParams =
ThreeDSV2Params.MerchantRiskParams(shippingIndicator: .verifiedAddress,
deliveryTimeframe: .electronic,
reorderItemsIndicator: .reordered,
preOrderPurchaseIndicator: .merchandiseAvailable,
preOrderDate: Date(),
giftCard: true,
giftCardCount: 2)
threeDSV2Params.cardHolderAccountParams =
ThreeDSV2Params.CardHolderAccountParams(creationDate: Date(),
updateIndicator: .moreThan60Days,
lastChangeDate: Date(),
passwordChangeIndicator: .noChange,
passwordChangeDate: Date(),
shippingAddressUsageIndicator: .currentTransaction,
shippingAddressDateFirstUsed: Date(),
transactionsActivityLast24Hours: 2,
transactionsActivityPreviousYear: 20,
provisionAttemptsLast24Hours: 1,
purchasesCountLast6Months: 5,
suspiciousActivityIndicator: .noSuspiciousObserved,
registrationIndicator: .between30To60Days,
registrationDate: Date())
paymentRequest.threeDSV2Params = threeDSV2Params
检查输入数据
//This will check all setted data
do {
try paymentRequest.isValidData()
} catch {
print(error)
}
//Check address
do {
try paymentAddress.isValidData()
} catch {
print(error)
}
//Check transaction type
do {
try paymentTransactionType.isValidData()
} catch {
print(error)
}
交易类型必需参数
- ApplePay
let paymentTransactionTypes = [PaymentTransactionType(name: .applePay)]
let paymentSubtype = PaymentSubtype(type: .authorize)
paymentRequest.transactionTypes = paymentTransactionTypes
// paymentSubtype is required for ApplePay transactions
paymentRequest.paymentSubtype = paymentSubtype
- Authorize、Authorize3d、Sale、Sale3d
let paymentTransactionTypes = [PaymentTransactionType(name: .authorize), PaymentTransactionType(name: .sale), ...]
let recurringType = RecurringType(type: .subsequent)
paymentRequest.transactionTypes = paymentTransactionTypes
// recurringType is required for Authorize, Authorize3d, Sale, Sale3d transactions
paymentRequest.recurringType = recurringType
- Init Recurring Sale、Init Recurring Sale3d
let paymentTransactionTypes = [PaymentTransactionType(name: .initRecurringSale), PaymentTransactionType(name: .initRecurringSale3d)]
let recurringCategory = RecurringCategory(category: .subscription)
paymentRequest.transactionTypes = paymentTransactionTypes
// recurringCategory is required for Init Recurring Sale, Init Recurring Sale3d
paymentRequest.recurringCategory = recurringCategory
- 提醒
// Reminders (up to 3) are required when Pay Later property is set to true
paymentRequest.payLater = true
paymentRequest.reminders = [Reminder(channel: .email, after: 30), Reminder(channel: .sms, after: 60)]