0

我正在尝试将付款集成到我的应用程序中。

这是 Back4app 的云代码:

var Stripe = require("stripe")(
  "TestSecretKeyOk"
);

Parse.Cloud.define("purchaseItem", function(request, response) {
  var item, order;
  Parse.Promise.as().then(function() {

    var itemQuery = new Parse.Query('Item');
    itemQuery.equalTo('ItemName', request.params.itemName);
    return itemQuery.first(null,{useMasterKey: true}).then(null, function(error) {
      return Parse.Promise.error('Sorry, this item is no longer available.');
    });

  },{useMasterKey: true}).then(function(result) {
    if (!result) {
      return Parse.Promise.error('Sorry, this item is no longer available.');
    } else if (result.get('quantityAvailable') <= 0) { 
      return Parse.Promise.error('Sorry, this item is out of stock.');
    }
    item = result;
    item.increment('quantityAvailable', -1);
    return item.save(null,{useMasterKey: true}).then(null, function(error) {
      console.log('Decrementing quantity failed. Error: ' + error);
      return Parse.Promise.error('An error has occurred. Your credit card was not charged.');
    });

  },{useMasterKey: true}).then(function(result) {
    if (item.get('quantityAvailable') < 0) { // can be 0 if we took the last
      return Parse.Promise.error('Sorry, this item is out of stock.');}
  	order = new Parse.Object("Order");
  	order.set('name', "azeaze"); //You can pass the client data from request.params at the begining
    order.set('email', "a@gmail.com");
    order.set('address', "NA");
    order.set('zip', "99999");
    order.set('city_state', "CA");
    order.set('item', item.get('ItemName'));
    order.set('fulfilled', false);
    order.set('charged', false);
	return order.save(null,{useMasterKey:true}).then(null, function(error) {
      return Parse.Promise.error('An error has occurred. Your credit card was not charged.');
    });

  },{useMasterKey:true}).then(function(order) {
	return Stripe.charges.create({
	  amount: item.get('price')*100, // It needs to convert to cents
	  currency: "usd",
	  source: request.params.cardToken,
	  description: "Charge for dominwong4@gmail.com"
	}, function(err, charge) {
	  // asynchronously called
	  console.log(charge.id);
	});

  },{useMasterKey:true}).then(function(purchase) {
    order.set('stripePaymentId', purchase.id);
    order.set('charged', true);
    order.save(null,{useMasterKey:true});
	
	
  },{useMasterKey:true}).then(function() { 
  	//your email logic
  },{useMasterKey:true}).then(function() {
    response.success('Success');
  }, function(error) {
    response.error('erreur trouvé ' + error);
  });
});

一切似乎都很好:

-Stripe 告诉我他们的后端付款正常且没有错误。

但是,即使 Parse Dashboard 实现了
StripePaymentID 订单仍然为空,并且此错误引发:

TypeError:无法读取未定义的属性“id”

所以我不明白什么不起作用,如果您能提供帮助,我将不胜感激。

4

1 回答 1

0

我建议您更新您的 Stripe 版本。只需上传一个文件,名称为:“package.json”并插入如下结构的内容:

{
    "dependencies": {
        "stripe": "^5.8.0"
}
于 2018-04-27T12:10:47.913 回答