Skip to content

Commit

Permalink
Merge pull request #874 from stripe/remi/codegen-824d494
Browse files Browse the repository at this point in the history
Add support for `billingPortal` namespace and `session` resource and APIs
  • Loading branch information
remi-stripe committed Apr 22, 2020
2 parents e7d859a + e5ac920 commit e125e0a
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 6 deletions.
3 changes: 3 additions & 0 deletions lib/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ module.exports = {
Topups: require('./resources/Topups'),
Transfers: require('./resources/Transfers'),
WebhookEndpoints: require('./resources/WebhookEndpoints'),
BillingPortal: resourceNamespace('billingPortal', {
Sessions: require('./resources/BillingPortal/Sessions'),
}),
Checkout: resourceNamespace('checkout', {
Sessions: require('./resources/Checkout/Sessions'),
}),
Expand Down
9 changes: 9 additions & 0 deletions lib/resources/BillingPortal/Sessions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

const StripeResource = require('../../StripeResource');

module.exports = StripeResource.extend({
path: 'billing_portal/sessions',

includeBasic: ['create'],
});
27 changes: 27 additions & 0 deletions test/resources/BillingPortal/Sessions.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

const stripe = require('../../../testUtils').getSpyableStripe();

const expect = require('chai').expect;

describe('BillingPortal', () => {
describe('Sessions Resource', () => {
describe('create', () => {
it('Sends the correct request', () => {
const params = {
customer: 'cus_123',
return_url: 'https://stripe.com/return',
};
stripe.billingPortal.sessions.create(params);

expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/billing_portal/sessions',
headers: {},
data: params,
settings: {},
});
});
});
});
});
72 changes: 72 additions & 0 deletions types/2020-03-02/BillingPortal/Sessions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
declare module 'stripe' {
namespace Stripe {
namespace BillingPortal {
/**
* The Session object.
*/
interface Session {
/**
* Unique identifier for the object.
*/
id: string;

/**
* String representing the object's type. Objects of the same type share the same value.
*/
object: 'billing_portal.session';

/**
* Time at which the object was created. Measured in seconds since the Unix epoch.
*/
created: number;

/**
* The ID of the customer for this session.
*/
customer: string;

/**
* Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
*/
livemode: boolean;

/**
* The URL to which Stripe should send customers when they click on the link to return to your website.
*/
return_url: string;

/**
* The short-lived URL of the session giving customers access to the self-serve portal.
*/
url: string;
}

interface SessionCreateParams {
/**
* The ID of an existing customer.
*/
customer: string;

/**
* Specifies which fields in the response should be expanded.
*/
expand?: Array<string>;

/**
* The URL to which Stripe should send customers when they click on the link to return to your website. This field is required if a default return URL has not been configured for the portal.
*/
return_url?: string;
}

class SessionsResource {
/**
* Creates a session of the Self-service Portal.
*/
create(
params: SessionCreateParams,
options?: RequestOptions
): Promise<Stripe.BillingPortal.Session>;
}
}
}
}
4 changes: 2 additions & 2 deletions types/2020-03-02/Checkout/Sessions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ declare module 'stripe' {

/**
* Plans define the base price, currency, and billing cycle for subscriptions.
* For example, you might have a 5/month plan
* For example, you might have a $5/month plan
* that provides limited access to your products, and a
* 15/month plan that allows full access.
* $15/month plan that allows full access.
*
* Related guides: [Set up a subscription](https://stripe.com/docs/billing/subscriptions/set-up-subscription) and more about [products and plans](https://stripe.com/docs/billing/subscriptions/products-and-plans).
*/
Expand Down
4 changes: 2 additions & 2 deletions types/2020-03-02/Plans.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ declare module 'stripe' {
object: 'plan';

/**
* Whether the price can be used for new purchases.
* Whether the plan can be used for new purchases.
*/
active: boolean;

Expand All @@ -35,7 +35,7 @@ declare module 'stripe' {
amount_decimal: string | null;

/**
* Describes how to compute the price per period. Either `per_unit` or `tiered`. `per_unit` indicates that the fixed amount (specified in `unit_amount` or `unit_amount_decimal`) will be charged per unit in `quantity` (for prices with `usage_type=licensed`), or per unit of total usage (for prices with `usage_type=metered`). `tiered` indicates that the unit pricing will be computed using a tiering strategy as defined using the `tiers` and `tiers_mode` attributes.
* Describes how to compute the price per period. Either `per_unit` or `tiered`. `per_unit` indicates that the fixed amount (specified in `amount`) will be charged per unit in `quantity` (for plans with `usage_type=licensed`), or per unit of total usage (for plans with `usage_type=metered`). `tiered` indicates that the unit pricing will be computed using a tiering strategy as defined using the `tiers` and `tiers_mode` attributes.
*/
billing_scheme: Plan.BillingScheme;

Expand Down
4 changes: 2 additions & 2 deletions types/2020-03-02/SubscriptionItems.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ declare module 'stripe' {

/**
* Plans define the base price, currency, and billing cycle for subscriptions.
* For example, you might have a 5/month plan
* For example, you might have a $5/month plan
* that provides limited access to your products, and a
* 15/month plan that allows full access.
* $15/month plan that allows full access.
*
* Related guides: [Set up a subscription](https://stripe.com/docs/billing/subscriptions/set-up-subscription) and more about [products and plans](https://stripe.com/docs/billing/subscriptions/products-and-plans).
*/
Expand Down
2 changes: 2 additions & 0 deletions types/2020-03-02/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
///<reference path='./Balance.d.ts' />
///<reference path='./BalanceTransactions.d.ts' />
///<reference path='./BankAccounts.d.ts' />
///<reference path='./BillingPortal/Sessions.d.ts' />
///<reference path='./BitcoinReceivers.d.ts' />
///<reference path='./BitcoinTransactions.d.ts' />
///<reference path='./Capabilities.d.ts' />
Expand Down Expand Up @@ -150,6 +151,7 @@ declare module 'stripe' {
/**
* Namespaced Resources
*/
billingPortal: {sessions: Stripe.BillingPortal.SessionsResource};
checkout: {sessions: Stripe.Checkout.SessionsResource};
issuing: {
authorizations: Stripe.Issuing.AuthorizationsResource;
Expand Down

0 comments on commit e125e0a

Please sign in to comment.