gpt4 book ai didi

与 Parse Cloud 代码通信的 Swift/Stripe 错误

转载 作者:搜寻专家 更新时间:2023-11-01 05:40:51 24 4
gpt4 key购买 nike

我已经工作了好几天,试图弄清楚如何使用 Swift 以 Parse.com 云代码作为后端,通过 Stripe 对卡进行收费并将卡保存给客户。我成功地将 Stripe pod 与我的项目集成,并且我创建了一个 token ,并在控制台中打印出来以验证其存在。但是我不能用它做任何事情!我到处寻找答案,但无法弄清楚为什么我总是出错。我认为这与我尝试提供给 Cloud Code 的参数有关,但我不确定。我已经阅读了 Cloud Code 和 Stripe 的文档,但无济于事。这是我的 PaymentViewController.swift:

import UIKit
import Stripe
import PaymentKit
import Parse
import Bolts




class PaymentViewController: UIViewController, PTKViewDelegate {


@IBOutlet weak var saveBtn: UIButton!

var paymentView: PTKView = PTKView()

override func viewDidLoad() {
super.viewDidLoad()



var view : PTKView = PTKView(frame: CGRectMake(15,20,290,55))

paymentView = view
paymentView.delegate = self;
self.view.addSubview(self.paymentView)

saveBtn.enabled = false



}

func paymentView(view: PTKView!, withCard card: PTKCard!, isValid valid: Bool) {
if (valid) {
saveBtn.enabled = true
} else {
saveBtn.enabled = false
}
}



override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}





@IBAction func save(sender: AnyObject) {

var card: STPCard = STPCard()
card.number = self.paymentView.card.number
card.expMonth = self.paymentView.card.expMonth
card.expYear = self.paymentView.card.expYear
card.cvc = self.paymentView.card.cvc

STPAPIClient.sharedClient().createTokenWithCard(card, completion: { (tokenId: STPToken?, error: NSError?) -> Void in
if (error != nil) {
println(error)
println("what the..")
} else {
println(tokenId)


PFCloud.callFunctionInBackground("hello", withParameters: nil) {
(response: AnyObject?, error: NSError?) -> Void in
let responseString = response as? String
println(responseString)
}




PFCloud.callFunctionInBackground("createCharge", withParameters: nil, block: { (success: AnyObject?, error: NSError?) -> Void in
if error != nil {
println("error")
}
})








}
})



}







@IBAction func cancel(sender: AnyObject) {
self.dismissViewControllerAnimated(true, completion: nil)
}






}

我添加了“Hello World”示例以查看云代码是否设置正确,以及 callFunction 是否正常工作。我的云代码是:

var Stripe = require('stripe');
Stripe.initialize('My_Secret_Key');

Parse.Cloud.define("hello", function(request, response) {
response.success("Hello world!");
});

Parse.Cloud.define("createCharge", function(request, response) {
Stripe.Charges.create({
amount: 100 * 10, // $10 expressed in cents
currency: "usd",
card: "tok_3TnIVhEv9P24T0"
},{
success: function(httpResponse) {
response.success("Purchase made!");
},
error: function(httpResponse) {
response.error("Uh oh, something went wrong");
}
});


});

任何帮助将不胜感激!!我一直在不知疲倦地解决这个问题!控制台打印出来

Uh oh, something went wrong (Code: 141, Version: 1.7.2)

最佳答案

您看到的错误 Uh oh, something went wrong (Code: 141, Version: 1.7.2) 表示您的 createCharge Parse 函数返回了一个错误。您可能想要记录 httpResponse 的值以找到来自 Stripe 的确切错误。

查看您的代码,错误很可能是:无效请求错误:不能多次使用 token tok_3TnIVhEv9P24T0。您可以在 Stripe 控制面板的日志部分确认这一点。

我看到您打印了 token println(tokenId),您还想将其发送到您的 Parse 函数并将 card 设置为等于您刚刚创建的 token 的值.

关于与 Parse Cloud 代码通信的 Swift/Stripe 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30679007/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com