我试图将Stripe付款整合到我的iOS应用中,而我似乎无法解决这些错误。我不确定他们是否与我的桥接头有任何关系,但是如果有人可以查看代码。 提前谢谢了。 这是我的ViewControllerClass中的代码:
class PaymentInfoViewController: UIViewController, UITextFieldDelegate {
**var stripeView: STPView = STPView()**
@IBOutlet var cardNumber: UITextField!
@IBOutlet var expiryDate: UITextField!
@IBOutlet var cvc: UITextField!
@IBOutlet var sendPaymentInfo: UIButton!
@IBAction func getStripeToken(sender: AnyObject) {
let creditCard = STPCard() //creating a stripe card object
creditCard.number = cardNumber.text
creditCard.cvc = cvc.text
//extracting month and year values from expiry date
if (!expiryDate.text.isEmpty){
let expArr = expiryDate.text.componentsSeparatedByString("/")
if (expArr.count > 1)
{
var expMonth: NSNumber = expArr[0].toInt()!
var expYear: NSNumber = expArr[1].toInt()!
creditCard.expMonth = expMonth.unsignedLongValue
creditCard.expYear = expYear.unsignedLongValue
}
}
var error: NSError?
if (creditCard.validateCardReturningError(&error)){
var stripeError: NSError!
**Stripe.createTokenWithCard(creditCard, completion: { (token, stripeError) -> Void in**
if (stripeError != nil){
println("there is error");
}
else{
self.cardNumber.text = ""
self.expiryDate.text = ""
self.cvc.text = ""
//shows your stripe token
var alert = UIAlertController(title: "Your stripe token is: " + token.tokenId, message: "", preferredStyle: UIAlertControllerStyle.Alert)
var defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
alert.addAction(defaultAction)
self.presentViewController(alert, animated: true, completion: nil)
}
})
}else{
//shows alert if information is not correct
var alert = UIAlertController(title: "Please enter valid credit card details", message: "", preferredStyle: UIAlertControllerStyle.Alert)
var defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
alert.addAction(defaultAction)
self.presentViewController(alert, animated: true, completion: nil)
}
}
用双星号括起来的部分是编译错误的地方。
来自桥接标题的代码:
#import "Stripe.h"
@import Foundation;
答案 0 :(得分:0)
如果您使用的是高于3.0的SDK版本,则应该查看github上的迁移指南:https://github.com/stripe/stripe-ios#migration-guides。
具体 - “在3.0版之前,大多数令牌创建方法都是Stripe类的类方法。现在这些是STPAPIClient类上的所有实例方法。”
你可能想要更好的运气(从你的getStripeToken函数开始): ```@IBAction func getStripeToken(sender:AnyObject){ 让creditCard = STPCard() 让StripePublicKey =“your_key_here” 让stpClient = STPAPIClient(publishableKey:StripePublicKey)
creditCard.number = cardNum.text
creditCard.cvc = cvc.text
if (!exp.text.isEmpty) {
let expArr = exp.text.componentsSeparatedByString("/")
if (expArr.count > 1) {
var expMonth: NSNumber = expArr[0].toInt()!
var expYear: NSNumber = expArr[1].toInt()!
creditCard.expMonth = expMonth.unsignedLongValue
creditCard.expYear = expYear.unsignedLongValue
}
}
var error: NSError?
if (creditCard.validateCardReturningError(&error)){
var stripeError: NSError!
stpClient.createTokenWithCard(creditCard, completion: { (token, stripeError) -> Void in
if (stripeError != nil){
println("there is error");
}
else{
self.cardNum.text = ""
self.exp.text = ""
self.cvc.text = ""
self.email.text = ""
var alert = UIAlertController(title: "Your stripe token is: " + token!.tokenId, message: "", preferredStyle: UIAlertControllerStyle.Alert)
var defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
alert.addAction(defaultAction)
self.presentViewController(alert, animated: true, completion: nil)
}
})
}```