在我的应用程序中集成了Card.IO ios sdk但无法让它扫描卡片

时间:2016-06-15 18:58:24

标签: ios card.io

我正在使用CardIOPaymentViewController将card.io集成到我的应用程序中。但是,每当我启动并显示视图控制器时,它总是进入手动输入屏幕。相机屏幕从未启动。我在Xcode" NSScanner:nil string argument"。

中看到了这个日志

我还试图打印CardIOUtilities.canReadCardWithCamera()的输出,它总是返回false。

任何有关问题的线索都会受到赞赏吗?

以下是代码:

导入基金会 导入条纹

class PaymentAccountAddController:BaseController,STPPaymentCardTextFieldDelegate,CardIOPaymentViewControllerDelegate {

@IBOutlet weak var paymentTextField: STPPaymentCardTextField!
@IBOutlet weak var paymentHeadingLabel: UILabel!

@IBOutlet weak var addCardBtnOutlet: UIButton!

override func viewDidLoad() {
    super.viewDidLoad()
    paymentHeadingLabel.font = UIFont.boldSystemFontOfSize(16)
    paymentTextField.delegate = self
}

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    CardIOUtilities.preload()
}

@IBAction func payButtonTapped(sender: AnyObject) {
    print("purchase button clicked")

    let card = paymentTextField.cardParams
    //send card information to stripe to get back a token
    getStripeToken(card)
}

@IBAction func addCard(sender: AnyObject?) {
    // If you have your own form for getting credit card information, you can construct
    // your own STPCardParams from number, month, year, and CVV.

    let card = paymentTextField.cardParams
    if(paymentTextField.isValid == true){
        getStripeToken(card)
    }
}

func getStripeToken(card:STPCardParams) {
    // get stripe token for current card
    activityIndicator?.showActivityIndicator()

    dispatch_async(dispatch_get_main_queue(), {
        STPAPIClient.sharedClient().createTokenWithCard(card) { token, error in
            if let token = token {
                print(token)
                print("Stripe token successfully received: \(token)")
                self.activityIndicator?.hideActivityIndicator()
                self.postStripeToken(card,token: token)
            } else {
                self.activityIndicator?.hideActivityIndicator()
                print(error)
                //SVProgressHUD.showErrorWithStatus(error?.localizedDescription)
            }
        }
    })
}

// charge money from backend
func postStripeToken(card:STPCardParams, token: STPToken) {
    //Set up these params as your backend require
    let card = Card(name: "", expiryDate: "\( card.expMonth)/\( card.expYear)", last4: "\( card.last4()!)", cardToken: "\(token.tokenId)", defaultCard: false,brand:"\(token.card!.type)",type: "\(token.card!.funding.rawValue)")

    //TODO: Send params to your backend to process payment
    activityIndicator?.showActivityIndicator()
    CustomerService.sharedInstance.addCustomerAccount(GlobalService.getLoggedInCustomerId(), cardObj: card, onSuccess: { (response) in
        dispatch_async(dispatch_get_main_queue(), {
            self.activityIndicator?.hideActivityIndicator()
            self.performSegueWithIdentifier("unwindToPaymentAccountListScreenSegue", sender: nil)
        })
        }, onFailure: { (error) in
            dispatch_async(dispatch_get_main_queue(), {
                self.activityIndicator?.hideActivityIndicator()
                self.showError(Messages.ERROR, errors: [error.data["responseMsg"].stringValue])
            })
    })

}

//MARK: - CardIO Methods

@IBAction func scanCard(sender: AnyObject) {
    print("scanning card")
    let cardIOVC = CardIOPaymentViewController(paymentDelegate: self)
    cardIOVC.modalPresentationStyle = .FormSheet
    presentViewController(cardIOVC, animated: true, completion: nil)
}

//Allow user to cancel card scanning
func userDidCancelPaymentViewController(paymentViewController: CardIOPaymentViewController!) {
    print("user canceled")
    paymentViewController?.dismissViewControllerAnimated(true, completion: nil)
}

//Callback when card is scanned correctly
func userDidProvideCreditCardInfo(cardInfo: CardIOCreditCardInfo!, inPaymentViewController paymentViewController: CardIOPaymentViewController!) {
    if let info = cardInfo {
        let str = NSString(format: "Received card info.\n Number: %@\n expiry: %02lu/%lu\n cvv: %@.", info.redactedCardNumber, info.expiryMonth, info.expiryYear, info.cvv)
        print(str)

        //create Stripe card
        let card: STPCardParams = STPCardParams()
        card.number = info.cardNumber
        card.expMonth = info.expiryMonth
        card.expYear = info.expiryYear
        card.cvc = info.cvv

        //dismiss scanning controller
        paymentViewController?.dismissViewControllerAnimated(true, completion: nil)

        //Send to Stripe
        getStripeToken(card)


    }
}

}

0 个答案:

没有答案