Skip to content

Commit

Permalink
Billing: Add createSetupIntent function
Browse files Browse the repository at this point in the history
Change-type: minor
  • Loading branch information
joshbwlng committed Nov 22, 2024
1 parent a61d66e commit 72df2f5
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/models/billing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export interface BankAccountBillingInfo extends BillingInfo {
export interface TokenBillingSubmitInfo {
token_id: string;
'g-recaptcha-response'?: string;
token_type?: 'payment_method' | 'setup_intent';
}

export interface BillingPlanInfo {
Expand Down Expand Up @@ -268,6 +269,39 @@ const getBillingModel = function (
return body;
},

/**
* @summary Create a Stripe setup intent required for setting billing information
* @name createSetupIntent
* @public
* @function
* @memberof balena.models.billing
*
* @param {(String|Number)} organization - handle (string) or id (number) of the target organization.
*
* @fulfil {Object} - partial stripe setup intent object
* @returns {Promise}
*
* @example
* balena.models.billing.createSetupIntent(orgId).then(function(setupIntent) {
* console.log(setupIntent);
* });
*/
createSetupIntent: async (
organization: string | number,
): Promise<{
id: string;
client_secret: string;
}> => {
const orgId = await getOrgId(organization);

const { body } = await request.send({
method: 'POST',
url: `/billing/v1/account/${orgId}/setup-intent`,
baseUrl: apiUrl,
});
return body;
},

/**
* @summary Update the current billing information
* @name updateBillingInfo
Expand All @@ -280,6 +314,7 @@ const getBillingModel = function (
*
* @param {String} billingInfo.token_id - the token id generated for the billing info form
* @param {(String|undefined)} [billingInfo.'g-recaptcha-response'] - the captcha response
* @param {(String|undefined)} [billingInfo.token_type] - token type
* @fulfil {Object} - billing information
* @returns {Promise}
*
Expand Down

0 comments on commit 72df2f5

Please sign in to comment.