DyScan
Search…
Integrating with Stripe (iOS)
If you haven't already, follow the "Importing DyScan" and "Interfacing DyScan" steps in the General Integration Guide.
Stripe 16.0.3 and higher
Stripe 16.0.2 and lower
The DyScan output can then be converted into an STPPaymentMethodCardParams object that can be passed to a STPPaymentCardTextField or a custom Stripe class by editing the extension functions in the following manner.
1
extension ExampleViewController: DyScanViewControllerDelegate{
2
func onFailure(_ paymentViewController: DyScanViewController!, reason: DyScanExitReason) {
3
paymentViewController.dismiss(animated: true){
4
5
// CardFieldViewController is a view controller containing an
6
// STPPaymentCardTextField called cardField
7
let viewController = CardFieldViewController()
8
let navigationController = UINavigationController(rootViewController: viewController)
9
self.present(navigationController, animated: true, completion: nil)
10
}
11
}
12
13
func onSuccess(_ cardInfo: DyScanCreditCardInfo!, in paymentViewController: DyScanViewController!) {
14
15
// CardFieldViewController is a view controller containing an
16
// STPPaymentCardTextField called cardField
17
let viewController = CardFieldViewController()
18
let navigationController = UINavigationController(rootViewController: viewController)
19
20
paymentViewController.dismiss(animated: true){
21
22
if let info = cardInfo {
23
let card = STPPaymentMethodCardParams()
24
card.number = info.cardNumber
25
if(info.expiryMonth > 0){
26
card.expMonth = NSNumber(value: info.expiryMonth)
27
card.expYear = NSNumber(value: info.expiryYear)
28
}
29
viewController.cardField.cardParams = card
30
}
31
self.present(navigationController, animated: true, completion: nil)
32
}
33
}
Copied!
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.
1
extension ExampleViewController: DyScanViewControllerDelegate{
2
func onFailure(_ paymentViewController: DyScanViewController!, reason: DyScanExitReason) {
3
paymentViewController.dismiss(animated: true){
4
5
// CardFieldViewController is a view controller containing an
6
// STPPaymentCardTextField called cardField
7
let viewController = CardFieldViewController()
8
let navigationController = UINavigationController(rootViewController: viewController)
9
self.present(navigationController, animated: true, completion: nil)
10
}
11
}
12
13
func onSuccess(_ cardInfo: DyScanCreditCardInfo!, in paymentViewController: DyScanViewController!) {
14
15
// CardFieldViewController is a view controller containing an
16
// STPPaymentCardTextField called cardField
17
let viewController = CardFieldViewController()
18
let navigationController = UINavigationController(rootViewController: viewController)
19
20
paymentViewController.dismiss(animated: true){
21
22
if let info = cardInfo {
23
let card = STPCardParams()
24
card.number = info.cardNumber
25
if(info.expiryMonth > 0){
26
card.expMonth = info.expiryMonth
27
card.expYear = info.expiryYear
28
}
29
viewController.cardField.cardParams = card
30
}
31
self.present(navigationController, animated: true, completion: nil)
32
}
33
}
Copied!
Copy link