【问题标题】:Parse + Stripe iOS Swift 2 main.js解析 + 条纹 iOS Swift 2 main.js
【发布时间】:2016-07-26 06:19:12
【问题描述】:

我正在使用 Parse + Stripe。我的 Parse Cloud Code 版本是 1.5.0 这是我在应用程序端的源代码。

func performStripeOperation() {

    STPAPIClient.sharedClient().createTokenWithCard(stripCard, completion: { (token: STPToken?, error: NSError?) -> Void in

        if error == nil {
            // credit card details are correct
            print(token!.tokenId)
            var myVal: String = token!.tokenId
            NSLog("%@", token!)
            PFCloud.callFunctionInBackground("pay", withParameters: ["token": myVal], block: {(result: AnyObject?, error: NSError?) -> Void in
                if (error == nil) {
                    NSLog("from Cloud Code Res: %@", result as! String )
                }
                else {
                    NSLog("from Cloud Code: %@", error!)
                }
            })


        } else {
            print("Token error.")
            // Handle Error here
            NSLog("ERRRRR = %@", error!)
            let alert = UIAlertController(title: "Please try again", message: "\(error!.localizedDescription)", preferredStyle: .Alert)
            let actionOk = UIAlertAction(title: "Ok", style: .Default, handler: nil)
            alert.addAction(actionOk)
            self.presentViewController(alert, animated: true, completion: nil)
            //let alert: UIAlertView = UIAlertView(title: "Please try again", message: "\(error!.localizedDescription)", delegate: nil, cancelButtonTitle: "OK", otherButtonTitles: "")
            //alert.show()

        }


    })
}

对于 main.js,我遵循了来自 here 的源代码

var Stripe = require('stripe');
Stripe.initialize('sk_test_******************'); 
Parse.Cloud.define("pay", function(request, response) {
var stripeToken = request.params.token;
var charge = Stripe.Charges.create({
    amount: 1000, // in cents 
    currency: 'usd',
    card: stripeToken
}).then(null, function(error) {
    console.log('Charging with stripe failed. Error: ' + error);
}).then(function() {
    // And we're done!
   response.success('Success');
});
});

现在,我收到了这个错误

[Error]: TypeError: Object [object Object] has no method 'isString'
    at request (stripe.js:49:25)
    at post (stripe.js:117:12)
    at Object.module.exports.Charges.create (stripe.js:157:16)
    at main.js:27:29 (Code: 141, Version: 1.12.0)
2016-04-05 22:56:35.886 Muzicue[39049:832833] from Cloud Code: Error Domain=Parse Code=141 "TypeError: Object [object Object] has no method 'isString'
    at request (stripe.js:49:25)
    at post (stripe.js:117:12)
    at Object.module.exports.Charges.create (stripe.js:157:16)
    at main.js:27:29" UserInfo={code=141, temporary=0, error=TypeError: Object [object Object] has no method 'isString'
    at request (stripe.js:49:25)
    at post (stripe.js:117:12)
    at Object.module.exports.Charges.create (stripe.js:157:16)
    at main.js:27:29, NSLocalizedDescription=TypeError: Object [object Object] has no method 'isString'
    at request (stripe.js:49:25)
    at post (stripe.js:117:12)
    at Object.module.exports.Charges.create (stripe.js:157:16)
    at main.js:27:29}

知道我哪里做错了吗?谢谢...

【问题讨论】:

    标签: parse-platform swift2


    【解决方案1】:

    在我将 main.js 更改为此之后,它起作用了。 response.success 和 response.error 都需要实现。

    var Stripe = require('stripe');
    
    Stripe.initialize('sk_test_**********************');
    
    Parse.Cloud.define("pay", function(request, response) {
    
    Stripe.Charges.create({
    
    //  amount: request.params.amount,
    
    amount: 1000,
    
    currency: "usd",
    
    card: request.params.token
    
    }).then(
    
    function(param) {
    
        console.log('Made successful card charge with Stripe!');
    
        response.success("Stripe charge succeeded.");
    
    },
    
    function(error) {
    
        console.log('Charging with stripe failed. Error: ' + error);
    
        response.error(error.message);
    
    }
    
    )
    
    });
    

    【讨论】:

      猜你喜欢
      • 2015-12-09
      • 2017-03-14
      • 1970-01-01
      • 2019-01-08
      • 2016-05-10
      • 1970-01-01
      • 1970-01-01
      • 2017-01-26
      • 1970-01-01
      相关资源
      最近更新 更多