У меня проблемы с предварительной авторизацией, описанной здесь https://stripe.com/docs/charges#auth-capture.
Авторизация прошла успешно (capture
params to false), я могу сохранить идентификатор машины на моей базе данных, и яс моей панели Stripe Dashboard можно увидеть незафиксированный заряд .
Проблема возникает, когда я пытаюсь захватить заряд, потому что он не срабатывает при Error: No such charge: <CHARGE_ID>
.Вот код:
constructor(){
this.stripe = require('stripe')('<sk_test_mysecretkey>');
}
async captureCharge(chargeId) {
try {
/**
* https://stripe.com/docs/api/charges/capture
*/
return this.stripe.charges.capture(chargeId)
.then((charge) => {
return {
error: false,
success: true,
message: 'ChargeSuccesful',
code: 200,
charge: charge,
};
},
(err) => {
console.log("CAPTURE CHARGE ERROR: ", err);
return {
success: false,
error: err.type,
code: err.statusCode,
};
}
);
} catch (e) {
console.log('ERROR CAPTURE', e);
}
}
Даже если я пытаюсь с POST на https://api.stripe.com/v1/charges/<CHARGE_ID>/capture
с auth: Bearer <sk_test_mysecretkey>
, я получаю ту же ошибку:
{
"error": {
"code": "resource_missing",
"doc_url": "https://stripe.com/docs/error-codes/resource-missing",
"message": "No such charge: <CHARGE_ID>",
"param": "charge",
"type": "invalid_request_error"
}
}
Захваченный заряд все еще существует наStripe.
Заранее спасибо.
ОБНОВЛЕНИЕ
Я забыл сказать, что заряд не простой заряд, но это расколоплата с общего клиента .Stripe поддерживает три подхода для обработки раздельного платежа, я выбрал прямые сборы :
async authorizationCharge(amount, merchantStripeId, billId, customerId) {
try {
var fee = 0.25;
/** Pre-Authorization Charge using a shared customer
* https://stripe.com/docs/charges#auth-capture
* https://stripe.com/docs/connect/shared-customers
*/
return this.stripe.tokens
.create(
{ customer: customerId },
{ stripe_account: merchantStripeId }
)
.then((oneTimeToken) => {
return this.stripe.charges
.create(
{
amount: Math.round(amount),
currency: 'eur',
application_fee: fee,
description: 'Bill ID: ' + billId,
source: oneTimeToken.id,
capture: false,
},
{ stripe_account: merchantStripeId }
)
.then((charge) => {
console.log('CHARGE: ', charge);
return {
error: false,
success: true,
code: 200,
charge: charge,
fee: fee,
};
},
(err) => {
// ERROR INFO:
// https://stripe.com/docs/api#error_handling
console.log('ERROR', err);
return {
success: false,
error: err.type,
code: err.statusCode,
};
}
);
},
(err) => {
// ERROR INFO:
// https://stripe.com/docs/api#error_handling
console.log('ERROR', err);
return { success: false, error: err.type, code: err.statusCode };
}
);
} catch (e) {
console.log(e);
}
}