upgrade stripe to v7

This commit is contained in:
Matteo Pagliazzi
2019-09-10 15:02:02 +02:00
parent 2c881d4a3a
commit cb6fdd4a15
2 changed files with 8 additions and 10 deletions

View File

@@ -97,17 +97,17 @@ describe('edit subscription', () => {
beforeEach(() => { beforeEach(() => {
subscriptionId = 'subId'; subscriptionId = 'subId';
stripeListSubscriptionStub = sinon.stub(stripe.customers, 'listSubscriptions') stripeListSubscriptionStub = sinon.stub(stripe.subscriptions, 'list')
.resolves({ .resolves({
data: [{id: subscriptionId}], data: [{id: subscriptionId}],
}); });
stripeUpdateSubscriptionStub = sinon.stub(stripe.customers, 'updateSubscription').resolves({}); stripeUpdateSubscriptionStub = sinon.stub(stripe.subscriptions, 'update').resolves({});
}); });
afterEach(() => { afterEach(() => {
stripe.customers.listSubscriptions.restore(); stripe.subscriptions.list.restore();
stripe.customers.updateSubscription.restore(); stripe.subscriptions.update.restore();
}); });
it('edits a user subscription', async () => { it('edits a user subscription', async () => {
@@ -118,10 +118,9 @@ describe('edit subscription', () => {
}, stripe); }, stripe);
expect(stripeListSubscriptionStub).to.be.calledOnce; expect(stripeListSubscriptionStub).to.be.calledOnce;
expect(stripeListSubscriptionStub).to.be.calledWith(user.purchased.plan.customerId); expect(stripeListSubscriptionStub).to.be.calledWith({customer: user.purchased.plan.customerId});
expect(stripeUpdateSubscriptionStub).to.be.calledOnce; expect(stripeUpdateSubscriptionStub).to.be.calledOnce;
expect(stripeUpdateSubscriptionStub).to.be.calledWith( expect(stripeUpdateSubscriptionStub).to.be.calledWith(
user.purchased.plan.customerId,
subscriptionId, subscriptionId,
{ card: token } { card: token }
); );
@@ -135,10 +134,9 @@ describe('edit subscription', () => {
}, stripe); }, stripe);
expect(stripeListSubscriptionStub).to.be.calledOnce; expect(stripeListSubscriptionStub).to.be.calledOnce;
expect(stripeListSubscriptionStub).to.be.calledWith(group.purchased.plan.customerId); expect(stripeListSubscriptionStub).to.be.calledWith({customer: group.purchased.plan.customerId});
expect(stripeUpdateSubscriptionStub).to.be.calledOnce; expect(stripeUpdateSubscriptionStub).to.be.calledOnce;
expect(stripeUpdateSubscriptionStub).to.be.calledWith( expect(stripeUpdateSubscriptionStub).to.be.calledWith(
group.purchased.plan.customerId,
subscriptionId, subscriptionId,
{ card: token } { card: token }
); );

View File

@@ -79,9 +79,9 @@ api.editSubscription = async function editSubscription (options, stripeInc) {
if (!customerId) throw new NotAuthorized(i18n.t('missingSubscription')); if (!customerId) throw new NotAuthorized(i18n.t('missingSubscription'));
if (!token) throw new BadRequest('Missing req.body.id'); if (!token) throw new BadRequest('Missing req.body.id');
let subscriptions = await stripeApi.customers.listSubscriptions(customerId); // @TODO: Handle Stripe Error response let subscriptions = await stripeApi.subscriptions.list({customer: customerId}); // @TODO: Handle Stripe Error response
let subscriptionId = subscriptions.data[0].id; let subscriptionId = subscriptions.data[0].id;
await stripeApi.customers.updateSubscription(customerId, subscriptionId, { card: token }); await stripeApi.subscriptions.update(subscriptionId, { card: token });
}; };
/** /**