From 3bfbe6d408b8d95aefa1ffb4997456dcca1b5bba Mon Sep 17 00:00:00 2001 From: Anand Chowdhary Date: Tue, 25 Jun 2019 14:44:50 +0200 Subject: [PATCH] :bug: Credit card fixes --- package.json | 2 +- src/controllers/organization.ts | 4 ++-- src/crud/billing.ts | 8 ++++---- src/rest/organization.ts | 5 +++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 66df3f4e6..611c50394 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "staart", - "version": "1.0.42", + "version": "1.0.43", "main": "index.js", "repository": "git@github.com:AnandChowdhary/staart.git", "author": "Anand Chowdhary ", diff --git a/src/controllers/organization.ts b/src/controllers/organization.ts index a18b8d822..163aa9d8a 100644 --- a/src/controllers/organization.ts +++ b/src/controllers/organization.ts @@ -388,7 +388,7 @@ export class OrganizationController { joiValidate( { organizationId: Joi.number().required(), - sourceId: Joi.number().required() + sourceId: Joi.string().required() }, { organizationId, sourceId } ); @@ -408,7 +408,7 @@ export class OrganizationController { joiValidate( { organizationId: Joi.number().required(), - sourceId: Joi.number().required() + sourceId: Joi.string().required() }, { organizationId, sourceId } ); diff --git a/src/crud/billing.ts b/src/crud/billing.ts index 079dd999c..443bcdf49 100644 --- a/src/crud/billing.ts +++ b/src/crud/billing.ts @@ -241,7 +241,7 @@ export const getStripeSources = async ( ) => { return cleanStripeResponse( await stripe.customers.listSources(id, { - object: "source", + object: "card", starting_after: start !== "0" ? start : undefined, limit: itemsPerPage }) @@ -269,8 +269,8 @@ export const deleteStripeSource = async (id: string, sourceId: string) => { * Get the details of a customer * @param id - Stripe customer ID */ -export const createStripeSource = async (id: string, card: any) => { - await stripe.customers.createCard(id, { card }); +export const createStripeSource = async (id: string, source: any) => { + await stripe.customers.createSource(id, { source }); return { success: true, message: "billing-source-created" }; }; @@ -283,6 +283,6 @@ export const updateStripeSource = async ( cardId: string, data: any ) => { - await stripe.customers.updateCard(id, cardId, data); + await stripe.customers.updateSource(id, cardId, data); return { success: true, message: "billing-source-updated" }; }; diff --git a/src/rest/organization.ts b/src/rest/organization.ts index 244a703cf..e5624c6cb 100644 --- a/src/rest/organization.ts +++ b/src/rest/organization.ts @@ -47,7 +47,8 @@ import { getStripeSubscription, updateStripeSubscription, getStripeInvoice, - createStripeSubscriptionSession + createStripeSubscriptionSession, + createStripeSubscription } from "../crud/billing"; import { getUser } from "../crud/user"; import { ApiKey } from "../interfaces/tables/user"; @@ -276,7 +277,7 @@ export const createOrganizationSubscriptionForUser = async ( if (await can(userId, Authorizations.READ, "organization", organizationId)) { const organization = await getOrganization(organizationId); if (organization.stripeCustomerId) - return await createStripeSubscriptionSession( + return await createStripeSubscription( organization.stripeCustomerId, params );