amazon: directly cancel subscription when already closed by amazon

This commit is contained in:
Matteo Pagliazzi
2016-10-11 15:54:48 +02:00
parent 8db6b7c6cb
commit 528abf77af

View File

@@ -235,10 +235,16 @@ api.subscribeCancel = {
if (!billingAgreementId) throw new NotAuthorized(res.t('missingSubscription'));
await amzLib.closeBillingAgreement({
let details = await amzLib.getBillingAgreementDetails({
AmazonBillingAgreementId: billingAgreementId,
});
if (details.BillingAgreementDetails.BillingAgreementStatus.status !== 'Closed') {
await amzLib.closeBillingAgreement({
AmazonBillingAgreementId: billingAgreementId,
});
}
let subscriptionBlock = shared.content.subscriptionBlocks[user.purchased.plan.planId];
let subscriptionLength = subscriptionBlock.months * 30;