如何捕获条带传输的错误和成功?
How do I catch error and success for stripe transfer?
我正在尝试启动传输,但如果有错误,我需要捕获错误,如果传输成功,我需要执行另一种方法。我如何赶上 success/error?
stripe.transfers.create({
amount: payoutAmount*100,
currency: "usd",
destination: "default_for_currency",
method: "instant"
},{stripe_account: String(accountId)}
);
Node.js Stripe 库是异步的,因此您需要包含一个带有 that API call or return it into a var
and handle it with promises 的回调。
使用回调,它会是这样的:
stripe.transfers.create({
amount: payoutAmount*100,
currency: "usd",
destination: "default_for_currency",
method: "instant"
}, {stripe_account: String(accountId)}, function(error, transfer) {
if (error) {
// Transfer failed, so do something with the error:
return doSomethingWithError(error);
}
// Transfer succeeded, so do something with the Transfer:
doSomethingWithTransfer(transfer);
});
我正在尝试启动传输,但如果有错误,我需要捕获错误,如果传输成功,我需要执行另一种方法。我如何赶上 success/error?
stripe.transfers.create({
amount: payoutAmount*100,
currency: "usd",
destination: "default_for_currency",
method: "instant"
},{stripe_account: String(accountId)}
);
Node.js Stripe 库是异步的,因此您需要包含一个带有 that API call or return it into a var
and handle it with promises 的回调。
使用回调,它会是这样的:
stripe.transfers.create({
amount: payoutAmount*100,
currency: "usd",
destination: "default_for_currency",
method: "instant"
}, {stripe_account: String(accountId)}, function(error, transfer) {
if (error) {
// Transfer failed, so do something with the error:
return doSomethingWithError(error);
}
// Transfer succeeded, so do something with the Transfer:
doSomethingWithTransfer(transfer);
});