UGBPaymentSwiftSDK 0.2.0

UGBPaymentSwiftSDK 0.2.0

Bohdan Potorochyn 维护。



  • BohdanPotorochyn

UGBPaymentSwiftSDKSource

需求

iOS 11.0+ 需要

SDK 配置

初始化 UGBPaymentSwiftSDK 库。例如

private let ugbPaymentSDK = UGBPaymentSwiftSDK()

支持的 环境 服务器

public enum Environment {
    case sandbox
    case production
}

自定义

您可以轻松自定义支付界面的颜色和文本,只需实现代码ColorSettingsColorSettings并将其传递到您应用程序的变量中。

let customColors = ColorSettings()

// Colors for PayButton
customColors.buttonPayEnabledColor = UIColor.colorFromHex("#212529")
customColors.buttonPayDisabledColor = UIColor.colorFromHex("#cad4dd")
customColors.buttonPayTextColor = .white
customColors.buttonPayEnabledTextColor = .white
customColors.buttonPayDisabledTextColor = .white

// Colors and Fonts for InfoText
customColors.infoTextBackgroundColor = .clear
customColors.infoTextColor = .black

// Colors for PaymentSummary
customColors.summaryBackgroundColor = .white
customColors.summaryTextColor = UIColor.colorFromHex("#212529")
customColors.summarySeparatorColor = UIColor.colorFromHex("#E7F0F7")

// Colors for TextFields and Labels
customColors.textFieldColor = .black
customColors.textFieldPlaceholderColor = UIColor.colorFromHex("#9E9E9E")
customColors.textFieldActiveBorderColor = UIColor.colorFromHex("#212529")
customColors.textFieldInactiveBorderColor = UIColor.colorFromHex("#9E9E9E")
customColors.textFieldLabelTextColor = .black

// Colors for AlertText
customColors.alertGradientColors = [
    UIColor.colorFromHex("#DBC6B8").withAlphaComponent(0.6).cgColor,
    UIColor.colorFromHex("#FFA3A3").withAlphaComponent(0.6).cgColor,
    UIColor.colorFromHex("#FC8E8E").withAlphaComponent(0.6).cgColor,
    UIColor.colorFromHex("#1F1BE0").withAlphaComponent(0.6).cgColor,
    UIColor.colorFromHex("#2011D1").withAlphaComponent(0.6).cgColor,
    UIColor.colorFromHex("#3018C2").withAlphaComponent(0.6).cgColor,
    UIColor.colorFromHex("#3C16A8").withAlphaComponent(0.6).cgColor,
    UIColor.colorFromHex("#572FCA").withAlphaComponent(0.6).cgColor,
    UIColor.colorFromHex("#4512D5").withAlphaComponent(0.6).cgColor,
    UIColor.colorFromHex("#4A1DCA").withAlphaComponent(0.6).cgColor,
    UIColor.colorFromHex("#4718CF").withAlphaComponent(0.6).cgColor,
    UIColor.colorFromHex("#230A68").withAlphaComponent(0.6).cgColor
]

customColors.alertBackgroundColor = .white
customColors.alertEmojiLabelColor = .black
customColors.alertTextLabelColor = .black

// Colors for NavigationButton
customColors.navigationButtonColor = .black

// Colors for MyViewController
customColors.viewBackgroundColor = UIColor.colorFromHex("#E7F0F7")

// Colors for LoaderLongPollingManager
customColors.loaderDimmingBackgroundColor = UIColor.black.withAlphaComponent(0.4)
customColors.loaderStrokeColor = UIColor.colorFromHex("#E7F0F7")

// Colors for LongPollingManager's modals
customColors.modalViewSuccessBackgroundColor = UIColor.black.withAlphaComponent(0.4)
customColors.modalViewErrorBackgroundColor = UIColor.black.withAlphaComponent(0.4)

// Colors for ModalErrorViewController
customColors.errorResultViewBackgroundColor = UIColor.colorFromHex("#E7F0F7")
customColors.errorResultDefaultBackgroundColor = .white
customColors.errorResultShadowColor = .black
customColors.errorResultLabelColor = .black
customColors.errorResultButtonBorderColor = .black
customColors.errorResultButtonTitleColor = .black
customColors.errorResultButtonBackgrundColor = .clear

// Colors for ModalSuccessViewController
customColors.successResultViewBackgroundColor = UIColor.colorFromHex("#E7F0F7")
customColors.successResultDefaultBackgroundColor = .white
customColors.successResultShadowColor = .black
customColors.successResultLabelColor = .black
customColors.successResultButtonTitleColor = .black
customColors.successResultButtonBorderColor = .black
customColors.successResultButtonBackgroundColor = .clear

customColors.bottomPanelWithLogosColor = .white

// Apply these settings
ugbPaymentSDK.setColorSettings(customColors: customColors)

let customTextStrings = TextSettings()

// Texts for PayButton
customTextStrings.buttonPayEnabledTextString = "Сплатити"
customTextStrings.buttonPayDisabledTextString = "Сплатити"

// Texts for InfoText
customTextStrings.infoTextString = "Транзакція обробляється платіжною компанією ТОВ «ФК «Єдиний простір».Натискаючи «Сплатити», ви погоджуєтесь з умовами Публічної оферти. Виникли питання?"

// Texts for PaymentSummary
customTextStrings.sumLabelTextString = "Сума до сплати:"
customTextStrings.commissionLabelTextString = "Комісія платіжної компанії:"
customTextStrings.totalLabelTextString = "Загалом:"

// Texts for TextFields and Labels
customTextStrings.cardNumberPlaceholderString = "0000 0000 0000 0000"
customTextStrings.expiryDatePlaceholderString = "Місяць/Рік"
customTextStrings.cvvPlaceholderString = "XXX"
customTextStrings.cardNumberLabelString = "Номер картки"
customTextStrings.expiryDateLabelString = "Строк дії"
customTextStrings.cvvLabelString = "Код CVV"
customTextStrings.toolbarDoneButtonString = "Done"

// Texts for AlertText
customTextStrings.alertTextString = "Дія не зберігає ваші платіжні дані."
customTextStrings.alertEmojiString = "☝️"

// Texts for NavigationButton
customTextStrings.navigationButtonString = "Разовий платіж карткою"

// Texts for ModalSuccessViewController
customTextStrings.successEmojiString = "👍"
customTextStrings.successMessageString = "Дякуємо, кошти зараховно"
customTextStrings.successHintString = "Кошти успішно зараховано на рахунок Національного банку України"
customTextStrings.continueButtonTitleString = "Продовжити"

// Texts for ModalErrorViewController
customTextStrings.errorEmojiString = "😟"
customTextStrings.errorMessageString = "Платіж не виконано"
customTextStrings.errorHintString = "Зверніться до банку, що видав картку"
customTextStrings.errorButtonTitleString = "Продовжити"



ugbPaymentSDK.setTextSettings(customTexts: customTextStrings)

您可以使用标准的 SWIFT UIColors 来选择颜色,例如 .white,或者使用 UIColor.colorWithHex("#FFFFFF")

为发送准备支付数据

a) 创建包含商家数据设置的 MerchantConfig 对象。

let merchantConfig = MerchantConfig(
        apiKey: "653s06d1-218f-447a-9025-a2e653f18b8d",
        merchantName: "your_merchant_name",
        sessionToken: "h.b.s"  // in format JWT
    )

b) 创建包含金额数据设置的 AmountConfig 对象。

let amountConfig = AmountConfig(
        amount: "1.00",
        currency: "UAH",
        commission: "0.00"
    )

请使用示例中显示的格式金额以保证正确无误的工作!

c) 创建包含交易数据设置的 TransactionConfig 对象。

let transactionConfig = TransactionConfig(
    orderID: UUID().uuidString,
    action: PaymentAction.purchase
)

d) 创建包含您支付所有设置的 PaymentData 对象。

let paymentData = PaymentData(
    merchantConfig: merchantConfig,
    amountConfig: amountConfig,
    transactionConfig: transactionConfig
)

为支付处理发起请求

ugbPaymentSDK.presentLibraryViewController(
    from: self,
    toSuccess:   navigationControllerSuccess,
    toError:     navigationControllerError,
    environment: .development,
    paymentData: paymentData
)

from - 用于显示支付视图的 UIViewController

toSuccess - 支付成功后重定向用户的 UIViewController

toError - 支付出错后重定向用户的 UIViewController

environment - 您想要使用的环境

paymentData - 包含设置您的支付的对象


处理支付状态

ugbPaymentSDK.paymentCompletion = { paymentData in
            
    print("paymentData.status: \(paymentData.status)")
    
    if let description = paymentData.description {
        print("paymentData.description: \(description)")
    } else {
        print("paymentData.description is nil")
    }
    
    if let rrn = paymentData.rrn {
        print("paymentData.rrn: \(rrn)")
    } else {
        print("paymentData.rrn is nil")
    }
    
    if let errorCode = paymentData.errorCode {
        print("paymentData.errorCode: \(errorCode)")
    } else {
        print("paymentData.errorCode is nil")
    }
    
    if let orderID = paymentData.orderID {
        print("paymentData.orderID: \(orderID)")
    } else {
        print("paymentData.orderID is nil")
    }
    
    if let currency = paymentData.currency {
        print("paymentData.currency: \(currency)")
    } else {
        print("paymentData.currency is nil")
    }
    
    if let termID = paymentData.termID {
        print("paymentData.termID: \(termID)")
    } else {
        print("paymentData.termID is nil")
    }
    
    if let amount = paymentData.amount {
        print("paymentData.amount: \(amount)")
    } else {
        print("paymentData.amount is nil")
    }

    if let timestamp = paymentData.timestamp {
        print("paymentData.timestamp: \(timestamp)")
    } else {
        print("paymentData.timestamp is nil")
    }
    
    if let transactionReference = paymentData.transactionReference {
        print("paymentData.transactionReference: \(transactionReference)")
    } else {
        print("paymentData.transactionReference is nil")
    }
}

当支付最终状态到来时,您将获得数据。

PaymentInfoResponse :

参数 描述
status 交易状态
description 支付描述
rrn 处理中的唯一标识符
errorCode SDK 支付状态代码
order_id 您设定的订单唯一标识符
currency 交易货币(ISO_4217)
termID 操作执行的支付终端
amount 交易金额
timestamp 交易获取最终状态的时间戳
transactionReference 您的交易参考