Menu

Integrating with Stripe (iOS)


First, follow the steps in Parts I and II of our General Integration Guide.The DyScan output can then be converted into an STPCardParams object that can be passed to a STPPaymentCardTextField or a custom Stripe class by editing the extension functions in the following manner.



extension ExampleViewController: DyScanViewControllerDelegate{
    func userDidCancel(_ paymentViewController: DyScanViewController!) {
        dismiss(animated: true, completion: nil)
        
        let viewController = CardFieldViewController()
        let navigationController = UINavigationController(rootViewController: viewController)
        present(navigationController, animated: true, completion: nil)
    }
    
    func userDidProvide(_ cardInfo: DyScanCreditCardInfo!, in paymentViewController: DyScanViewController!) {
        dismiss(animated: true, completion: nil)
        
        let viewController = CardFieldViewController()
        
        if let info = cardInfo {
            let card: STPCardParams = STPCardParams()
            card.number = info.cardNumber
            if let month = info.expiryMonth{
                card.expMonth = month
            }
            if let year = info.expiryYear{
                card.expYear = year
            }
            viewController.cardField.cardParams = card
        }
        
        let navigationController = UINavigationController(rootViewController: viewController)
        present(navigationController, animated: true, completion: nil)
    }
}

        

Here, CardFieldViewController is a UIViewController containing an STPPaymentCardTextField object called cardField, which can be set to the DyScan results.

Get Started