gpt4 book ai didi

ios - 在 Parse 后端保存 Stripe customerId

转载 作者:行者123 更新时间:2023-11-29 02:29:41 25 4
gpt4 key购买 nike

我正在尝试为我的应用程序的用户在 Parse 后端保存一个 customerId。

以下代码可能有什么问题:

    var Stripe = require("stripe");
Stripe.initialize('sk_test_----------');

Parse.Cloud.define("saveStripeCustomerId", function (request, response) {
Stripe.Customers.create(
{ card: request.params.token
}, {
success: function(httpResponse) {
response.success("Purchase made!");


var Usr = Parse.User.current();
Usr.set("StripeCustomerId",request.params.objectId );
Usr.save(null, {
success: function(newUsr) {
// Execute any logic that should take place after the object is saved.
alert('New object created with objectId: ' + newUsr.id);

},
error: function(newUsr, error) {
// Execute any logic that should take place if the save fails.
// error is a Parse.Error with an error code and message.
alert('Failed to create new customer , with error code: ' + error.message);
}

});

},
error: function(httpResponse) {
response.error("Error ...oh no");
}
});
});

IOS代码:

- (IBAction)save:(id)sender
{
PTKCard* card = self.paymentView.card;

NSLog(@"Card last4: %@", card.last4);
NSLog(@"Card expiry: %lu/%lu", (unsigned long)card.expMonth, (unsigned long)card.expYear);
NSLog(@"Card cvc: %@", card.cvc);

[[NSUserDefaults standardUserDefaults] setValue:card.last4 forKey:@"card.last4"];
[self.navigationController popViewControllerAnimated:YES];

STPCard* stpcard = [[STPCard alloc] init];
stpcard.number = card.number;
stpcard.expMonth = card.expMonth;
stpcard.expYear = card.expYear;
stpcard.cvc = card.cvc;


[Stripe createTokenWithCard:stpcard completion:^(STPToken *token, NSError *error) {
if (error) {

//[self handleError:error];


} else {
//[self createBackendChargeWithToken:token];


[PFCloud callFunctionInBackground:@"saveStripeCustomerId"
withParameters:[NSDictionary dictionaryWithObjectsAndKeys:token.tokenId, @"token", nil]
block:^(id object, NSError *error) {

if(error == nil)
{
[[[UIAlertView alloc] initWithTitle:@"Stripe Customer Id saved!"
message:@"Your stripe cust id has been saved!"
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil, nil] show];
}
}];

}
}];
}

@end

使用这段代码,我可以在 Stripe 中创建一个客户。但是,它不会将其保存在解析用户表中。

Parse Cloud Log:
I2014-11-21T15:55:10.887Z] v46: Ran cloud function saveStripeCustomerId for user GBkeqCcOcU with:
Input: {"token":"tok_-----------"}
Result: Purchase made!

可能出了什么问题?我将不胜感激任何帮助,谢谢!

最佳答案

它适用于以下代码。解析功能不正确,我不得不注销并登录用户,因为我在创建 StripeCustomerId 列后没有注销用户。

Parse.Cloud.define("saveStripeCustomerId", function (request, response) {
Stripe.Customers.create(
{ card: request.params.token
}, {
success: function(customer) {

//response.success("Purchase made!");


var Usr = request.user;
Usr.set("StripeCustomerId",customer.id );
Usr.save(null, {
success: function(customer) {
// Execute any logic that should take place after the object is saved.
//alert('New object created with objectId: ' + newUsr.id);

response.success("customer saved to parse = " + Usr.get("username"));
},
error: function(customer, error) {
// Execute any logic that should take place if the save fails.
// error is a Parse.Error with an error code and message.
//alert('Failed to create new customer , with error code: ' + error.message);
response.error("oh uh non oooo failed to saved customer id to parse");
}

});

},
error: function(httpResponse) {
response.error("Error ...oh no");
}
});
});

关于ios - 在 Parse 后端保存 Stripe customerId,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27062738/

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