.net - STRIPE .NET/REACT-NATIVE:出现错误但 API 调用仍然通过
问题描述
我正在尝试在服务器端使用 .NET 将 Stripe 集成到我的 React-Native 应用程序中。
我的问题是,当我尝试创建客户并向其附加 paymentMethod 时,我收到 SyntaxError: JSON Parse error: Unexpected identifier: "Success",但在 Stripe 仪表板中,客户和 paymentMethod 已创建。
我需要访问我的日志,以便我可以检索 customerId 以附加到 paymentIntents 但由于我收到此错误,它就像它没有通过,即使它确实通过了。
public static async Task<dynamic> CreateClientAsync(string email, string name, string cardNumber, int month, int year, string cvv)
{
var optionstoken = new TokenCreateOptions
{
Card = new CreditCardOptions
{
Number = cardNumber,
ExpMonth = month,
ExpYear = year,
Cvc = cvv
}
};
var servicetoken = new TokenService();
Token stripetoken = await servicetoken.CreateAsync(optionstoken);
var customer = new CustomerCreateOptions
{
Email = email,
Name = name,
Source = stripetoken.Id,
};
Console.WriteLine(" stripetoken attributes :" + stripetoken);
var services = new CustomerService();
var created = services.Create(customer);
var option = new PaymentMethodCreateOptions
{
Type = "card",
Card = new PaymentMethodCardCreateOptions
{
Number = cardNumber,
ExpMonth = month,
ExpYear = year,
Cvc = cvv,
},
};
var service = new PaymentMethodService();
var result = service.Create(option);
Console.WriteLine(" PaymentMethodService attributes :" + result);
var options = new PaymentMethodAttachOptions
{
Customer = created.Id,
};
var method = new PaymentMethodService();
method.Attach(
result.Id,
options
);
if (created.Id == null)
{
return "Failed";
}
else
{
return "Success";
}
}
}
然后我在我的控制器中调用它
[HttpPost("stripecustomer")]
public async Task<dynamic> Client(Models.StripeClientModel sc)
{
return await CreateStripeClient.CreateClientAsync(sc.email, sc.name, sc.cardNumber, sc.month, sc.year, sc.cvv);
}
这是我的 React-Native 代码
let collection ={}
collection.email = this.state.email,
collection.name = this.state.name,
collection.cardNumber = this.state.cardNumber,
collection.month = 10,
collection.year = 2025,
collection.cvv = this.state.CVV
console.warn(collection);
await fetch("https://api/stripecustomer", {
method: 'POST', // or 'PUT'
headers: new Headers({
'Content-Type': 'application/json',
}),
body: JSON.stringify(collection),
})
.then((response) => response.json())
.then((collection) => {
console.log('Success stripe customer created:', collection);
})
.catch((error) => {
console.error('Error:', error);
});
我也尝试使用 axios,但 axios 根本没有发布到 Stripe,也没有创建任何客户。
如果您需要更多信息,请告诉我!谢谢!
解决方案
推荐阅读
- powershell - “InputObject”如何为空?
- java - 是否有用于侦听音频命令的 Kotlin 或 Java 库?(想要在孩子们大喊“TRICK OR TREAT”时触发万圣节展示)
- sql - 使用 SQL 从匹配的 meta_key 中检索所有帖子
- json - 预期解码 Int 但找到了一个数组
- javascript - 在数据列表中创建间距
- javascript - 打字稿意外令牌
- python - 切换到“gcloud app deploy”后无法部署 GAE 更改
- android - 将多种样式应用于单个文本 - Jetpack Compose
- javascript - 为什么我的 javascript 类在 .cshtml 文件中不可见?
- javascript - 创建一个在一行上显示 Y 位置的工具提示 (d3.js)