-
Notifications
You must be signed in to change notification settings - Fork 5
feat(billing): add billing endpoints #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Sourav-kashyap
wants to merge
6
commits into
master
Choose a base branch
from
GH-120
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9e24f4e
feat(billing): add billing endpoints
Sourav-kashyap f70215e
feat(billing): fix sonar issue
Sourav-kashyap 6baedad
feat(billing): fix sonar
Sourav-kashyap 5673f13
feat(billing): fix comments
Sourav-kashyap 9a123de
feat(billing): fix comments
Sourav-kashyap 9285d61
feat(billing): align codebase with existing project structure
Sourav-kashyap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
177 changes: 177 additions & 0 deletions
177
services/subscription-service/src/controllers/billing-service.controller.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| import {inject} from '@loopback/core'; | ||
| import {get, param} from '@loopback/rest'; | ||
| import {authorize} from 'loopback4-authorization'; | ||
| import {authenticate, STRATEGY} from 'loopback4-authentication'; | ||
| import { | ||
| BillingComponentBindings, | ||
| IService, | ||
| TInvoicePdf, | ||
| TInvoicePaymentDetails, | ||
| TPaymentIntent, | ||
| } from 'loopback4-billing'; | ||
| import { | ||
| getModelSchemaRefSF, | ||
| STATUS_CODE, | ||
| OPERATION_SECURITY_SPEC, | ||
| } from '@sourceloop/core'; | ||
| import {BillingPaymentStatusResponse, BillingErrorResponse} from '../models'; | ||
| import { | ||
| InvoicePdfDto, | ||
| InvoicePaymentDetailsDto, | ||
| PaymentIntentDto, | ||
| } from '../models/dto'; | ||
| import {PermissionKey} from '../permissions'; | ||
|
|
||
| const BASE = '/billing'; | ||
|
|
||
| export class BillingServiceController { | ||
| constructor( | ||
| @inject(BillingComponentBindings.SDKProvider) | ||
| private readonly billingService: IService, | ||
| ) {} | ||
|
|
||
| /** | ||
| * Check whether an invoice has been paid. | ||
| */ | ||
| @authorize({permissions: [PermissionKey.ViewInvoice]}) | ||
| @authenticate(STRATEGY.BEARER, {passReqToCallback: true}) | ||
| @get(`${BASE}/invoices/{invoiceId}/payment-status`, { | ||
| security: OPERATION_SECURITY_SPEC, | ||
| summary: 'Check if an invoice is paid', | ||
| responses: { | ||
| [STATUS_CODE.OK]: { | ||
| description: 'Payment status', | ||
| content: { | ||
| 'application/json': { | ||
| schema: {...getModelSchemaRefSF(BillingPaymentStatusResponse)}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| async getPaymentStatus( | ||
| @param.path.string('invoiceId') invoiceId: string, | ||
| ): Promise<BillingPaymentStatusResponse> { | ||
| const paid = await this.billingService.getPaymentStatus(invoiceId); | ||
| return {paid}; | ||
| } | ||
|
|
||
| @authorize({permissions: [PermissionKey.ViewInvoice]}) | ||
| @authenticate(STRATEGY.BEARER, {passReqToCallback: true}) | ||
| @get(`${BASE}/invoices/{invoiceId}/pdf`, { | ||
| security: OPERATION_SECURITY_SPEC, | ||
| summary: 'Get PDF download URL for an invoice', | ||
| description: | ||
| 'Retrieves a temporary URL to download the invoice PDF. ' + | ||
| 'For Stripe, only finalized invoices have PDF URLs available. ' + | ||
| 'For ChargeBee, most invoice states support PDF generation.', | ||
| responses: { | ||
| [STATUS_CODE.OK]: { | ||
| description: 'PDF information retrieved successfully', | ||
| content: { | ||
| 'application/json': { | ||
| schema: getModelSchemaRefSF(InvoicePdfDto), | ||
| }, | ||
| }, | ||
| }, | ||
| [STATUS_CODE.NOT_FOUND]: { | ||
| description: 'Invoice not found', | ||
| content: { | ||
| 'application/json': { | ||
| schema: getModelSchemaRefSF(BillingErrorResponse), | ||
| }, | ||
| }, | ||
| }, | ||
| [STATUS_CODE.BAD_REQUEST]: { | ||
| description: 'PDF URL not available', | ||
| content: { | ||
| 'application/json': { | ||
| schema: getModelSchemaRefSF(BillingErrorResponse), | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| async getInvoicePdf( | ||
| @param.path.string('invoiceId') invoiceId: string, | ||
| ): Promise<TInvoicePdf> { | ||
| const pdfInfo: TInvoicePdf = | ||
| await this.billingService.getInvoicePdf(invoiceId); | ||
| return pdfInfo; | ||
| } | ||
|
|
||
| @authorize({permissions: [PermissionKey.ViewInvoice]}) | ||
| @authenticate(STRATEGY.BEARER, {passReqToCallback: true}) | ||
| @get(`${BASE}/invoices/{invoiceId}/payment-details`, { | ||
| security: OPERATION_SECURITY_SPEC, | ||
| summary: 'Get payment details for an invoice', | ||
| description: | ||
| 'Retrieves payment method details, payment amount, status, and ' + | ||
| 'transaction information for a specific invoice.', | ||
| responses: { | ||
| [STATUS_CODE.OK]: { | ||
| description: 'Payment details retrieved successfully', | ||
| content: { | ||
| 'application/json': { | ||
| schema: getModelSchemaRefSF(InvoicePaymentDetailsDto), | ||
| }, | ||
| }, | ||
| }, | ||
| [STATUS_CODE.NOT_FOUND]: { | ||
| description: 'Invoice not found', | ||
| content: { | ||
| 'application/json': { | ||
| schema: getModelSchemaRefSF(BillingErrorResponse), | ||
| }, | ||
| }, | ||
| }, | ||
| [STATUS_CODE.BAD_REQUEST]: { | ||
| description: 'No payment details available', | ||
| content: { | ||
| 'application/json': { | ||
| schema: getModelSchemaRefSF(BillingErrorResponse), | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| async getInvoicePaymentDetails( | ||
| @param.path.string('invoiceId') invoiceId: string, | ||
| ): Promise<TInvoicePaymentDetails> { | ||
| return this.billingService.getInvoicePaymentDetails(invoiceId); | ||
| } | ||
|
|
||
| @authorize({permissions: [PermissionKey.ViewInvoice]}) | ||
| @authenticate(STRATEGY.BEARER, {passReqToCallback: true}) | ||
| @get(`${BASE}/payment-intents/{paymentIntentId}`, { | ||
| security: OPERATION_SECURITY_SPEC, | ||
| summary: 'Get payment intent details', | ||
| description: | ||
| 'Retrieves detailed information about a payment intent including ' + | ||
| 'status, payment method, amount, and transaction metadata. ' + | ||
| 'Useful for payment tracking and webhook handling.', | ||
| responses: { | ||
| [STATUS_CODE.OK]: { | ||
| description: 'Payment intent retrieved successfully', | ||
| content: { | ||
| 'application/json': { | ||
| schema: getModelSchemaRefSF(PaymentIntentDto), | ||
| }, | ||
| }, | ||
| }, | ||
| [STATUS_CODE.NOT_FOUND]: { | ||
| description: 'Payment intent not found', | ||
| content: { | ||
| 'application/json': { | ||
| schema: getModelSchemaRefSF(BillingErrorResponse), | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| async getPaymentIntent( | ||
| @param.path.string('paymentIntentId') paymentIntentId: string, | ||
| ): Promise<TPaymentIntent> { | ||
| return this.billingService.getPaymentIntent(paymentIntentId); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there was a webhook component right ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes ma'am
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is it not added there then ?