Skip to content

Commit c58fe44

Browse files
feat(billing): fix comments
1 parent 5673f13 commit c58fe44

2 files changed

Lines changed: 3 additions & 145 deletions

File tree

services/subscription-service/src/controllers/billing-service.controller.ts

Lines changed: 1 addition & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@ import {
1515
TInvoicePdf,
1616
TInvoicePaymentDetails,
1717
TPaymentIntent,
18-
TCustomer,
1918
TPaymentSource,
2019
TInvoice,
2120
Transaction,
2221
} from 'loopback4-billing';
2322
import {getModelSchemaRefSF, STATUS_CODE} from '@sourceloop/core';
2423
import {
25-
BillingCustomerBody,
2624
BillingPaymentSourceBody,
2725
BillingPaymentMethodBody,
2826
BillingInvoiceBody,
@@ -44,117 +42,7 @@ export class BillingServiceController {
4442
private readonly billingService: IService,
4543
) {}
4644

47-
// -------------------------------------------------------------------------
48-
// CUSTOMER
49-
// -------------------------------------------------------------------------
50-
51-
/**
52-
* Create a new customer in Stripe.
53-
*
54-
* Example body:
55-
* ```json
56-
* {
57-
* "firstName": "John",
58-
* "lastName": "Doe",
59-
* "email": "john.doe@example.com",
60-
* "phone": "+1234567890"
61-
* }
62-
* ```
63-
*/
64-
@authorize({permissions: ['*']})
65-
@post(`${BASE}/customers`, {
66-
summary: 'Create a new customer',
67-
responses: {
68-
[STATUS_CODE.OK]: {
69-
description: 'Created customer object',
70-
content: {'application/json': {schema: {type: 'object'}}},
71-
},
72-
},
73-
})
74-
async createCustomer(
75-
@requestBody({
76-
content: {
77-
'application/json': {
78-
schema: {...getModelSchemaRefSF(BillingCustomerBody)},
79-
},
80-
},
81-
})
82-
customerDto: BillingCustomerBody,
83-
): Promise<TCustomer> {
84-
return this.billingService.createCustomer(customerDto as TCustomer);
85-
}
86-
87-
/**
88-
* Get a customer by external ID (Stripe customer ID, e.g. cus_XXXXX).
89-
*/
90-
@authorize({permissions: ['*']})
91-
@get(`${BASE}/customers/{customerId}`, {
92-
summary: 'Get a customer by ID',
93-
responses: {
94-
[STATUS_CODE.OK]: {
95-
description: 'Customer object',
96-
content: {'application/json': {schema: {type: 'object'}}},
97-
},
98-
},
99-
})
100-
async getCustomer(
101-
@param.path.string('customerId') customerId: string,
102-
): Promise<TCustomer> {
103-
return this.billingService.getCustomers(customerId);
104-
}
105-
106-
/**
107-
* Update an existing customer (email, phone, billing address, etc.).
108-
*
109-
* Example body:
110-
* ```json
111-
* {
112-
* "email": "new.email@example.com",
113-
* "billingAddress": { "city": "New York", "country": "US" }
114-
* }
115-
* ```
116-
*/
117-
@authorize({permissions: ['*']})
118-
@put(`${BASE}/customers/{customerId}`, {
119-
summary: 'Update a customer',
120-
responses: {
121-
[STATUS_CODE.NO_CONTENT]: {description: 'Customer updated'},
122-
},
123-
})
124-
async updateCustomer(
125-
@param.path.string('customerId') customerId: string,
126-
@requestBody({
127-
content: {
128-
'application/json': {
129-
schema: {...getModelSchemaRefSF(BillingCustomerBody)},
130-
},
131-
},
132-
})
133-
customerDto: Partial<BillingCustomerBody>,
134-
): Promise<void> {
135-
await this.billingService.updateCustomerById(
136-
customerId,
137-
customerDto as Partial<TCustomer>,
138-
);
139-
}
140-
141-
/**
142-
* Delete (permanently remove) a customer from Stripe.
143-
*/
144-
@authorize({permissions: ['*']})
145-
@del(`${BASE}/customers/{customerId}`, {
146-
summary: 'Delete a customer',
147-
responses: {
148-
[STATUS_CODE.NO_CONTENT]: {description: 'Customer deleted'},
149-
},
150-
})
151-
async deleteCustomer(
152-
@param.path.string('customerId') customerId: string,
153-
): Promise<void> {
154-
await this.billingService.deleteCustomer(customerId);
155-
}
156-
157-
// -------------------------------------------------------------------------
45+
// ------------------------------------------------------------------------
15846
// PAYMENT SOURCE
15947
// -------------------------------------------------------------------------
16048

services/subscription-service/src/controllers/billing-webhook.controller.ts

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ import {
66
ISubscriptionService,
77
TSubscriptionResult,
88
} from 'loopback4-billing';
9-
import {repository} from '@loopback/repository';
109
import {WEBHOOK_VERIFIER} from '../keys';
11-
import {InvoiceRepository} from '../repositories';
12-
import {IContent, IPayload, IWebhookPayload, IWebhookContent} from '../types';
10+
import {IWebhookPayload, IWebhookContent} from '../types';
1311

1412
/**
1513
* Chargebee webhook event types handled by this controller.
@@ -43,13 +41,11 @@ export class BillingWebhookController {
4341
constructor(
4442
@inject(BillingComponentBindings.SDKProvider)
4543
private readonly billingService: ISubscriptionService,
46-
@repository(InvoiceRepository)
47-
public invoiceRepository: InvoiceRepository,
4844
) {}
4945

5046
@authorize({permissions: ['*']})
5147
@intercept(WEBHOOK_VERIFIER)
52-
@post('/webhooks/billing-payment', {
48+
@post('/webhooks/chargebee', {
5349
summary: 'Chargebee webhook receiver',
5450
description:
5551
'Register this URL in Chargebee Settings → API Keys → Webhooks. ' +
@@ -119,20 +115,6 @@ export class BillingWebhookController {
119115
return {received: true, event: eventType};
120116
}
121117

122-
/**
123-
* Legacy webhook handler for backward compatibility.
124-
* Handles payment status updates.
125-
*/
126-
@authorize({
127-
permissions: ['*'],
128-
})
129-
@intercept(WEBHOOK_VERIFIER)
130-
@post('/webhooks/billing-payment/legacy')
131-
async handleWebhookLegacy(@requestBody() payload: IPayload): Promise<void> {
132-
const content = payload.content;
133-
await this.handlePayment(content);
134-
}
135-
136118
/**
137119
* Fired when a subscription is first created in Chargebee.
138120
* The subscription may be in `in_trial` or `active` state.
@@ -253,16 +235,4 @@ export class BillingWebhookController {
253235
cancelAtPeriodEnd: raw?.cancel_at_period_end ?? false,
254236
};
255237
}
256-
257-
/**
258-
* Legacy payment handler for backward compatibility.
259-
*/
260-
private async handlePayment(content: IContent): Promise<void> {
261-
const invoice = await this.invoiceRepository.find({
262-
where: {invoiceId: content.invoice.id},
263-
});
264-
await this.invoiceRepository.updateById(invoice[0].id, {
265-
invoiceStatus: content.invoice.status,
266-
});
267-
}
268238
}

0 commit comments

Comments
 (0)