Translation disclaimer

Documentation is written in English and subsequently translated. This page, therefore, might not have the most up-to-date content. If any questions arise relating to the accuracy of the translated content, please refer to the English version of the page.

Menu

CVC 验证

在处理客户的 CVC 之前对其进行验证。

警告:该验证并不会检查客户的 CVC 是否正确。验证器只会检查所输入的 CVC 格式。

开始

  • 您已将 AccessCheckoutSDK 作为 Cocoapods 依赖项添加到您的项目中
  • 您在 swift 文件的顶部添加了一个 import AccessCheckoutSDK

该集成的四个基本组件如下:

  • 您的 CVC 的 UITextField
  • AccessCheckoutCvcOnlyValidationDelegate 旨在接收与验证有关的事件
  • CvcOnlyValidationConfig 的实例包含验证流初始化所需的所有信息,包括对要启用验证所用的视图组件的引用
  • AccessCheckoutValidationInitialiser 负责初始化验证流

完整示例集成:您可以在此处查看 CVC 验证集成的示例。

创建和引用 UI 组件

若要显示您的结账表,则必须首先使用故事板来创建您的布局。

以下是如何利用独特的识别码来引用您的 UI 组件的示例。

Copied!
import AccessCheckoutSDK

class ViewController: UIViewController {

  @IBOutlet weak var cvcTextField: UITextField!
  ...

实施 AccessCheckoutCvcOnlyValidationDelegate 协议

这样将确保您收到验证事件的通知。

以下为示例。

Copied!
extension ViewController: AccessCheckoutCvcOnlyValidationDelegate {

    // This event handler is notified when the CVC becomes valid or invalid
    func cvcValidChanged(isValid: Bool) {
        // You might want to change the text colour
        cvcTextField.textColor = isValid ? nil : UIColor.red

        if !valid {
            // You might want to disable a submit button which would normally be clicked on when all fields are valid
            submitButton.isEnabled = false
        }
    }

    // This is complimentary to cvcValidChanged() and is notified only when the CVC is valid
    func validationSuccess() {
        // You might want to enable a submit button
        submitButton.isEnabled = true
    }
}

CvcOnlyValidationConfig 实例化并初始化验证

我们建议在 UIViewController 的 viewDidLoad() 处理器中这样做。

Copied!
override func viewDidLoad() {
    ...
    let validationConfig = try! CvcOnlyValidationConfig.builder()
                                    .cvc(cvcTextField)
                                    .validationDelegate(self)
                                    .build()
    AccessCheckoutValidationInitialiser().initialise(validationConfig)
}

创建 CVC 会话

一旦验证就位,您就可以请求 sessions 来实施您的支付流。


后续步骤


创建 CVC 会话