Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

feat: stripe changes

Nevo David2d9adb840acb
diff --git a/apps/backend/src/api/api.module.ts b/apps/backend/src/api/api.module.ts
index 54787f590..ba1e687e7 100644
--- a/apps/backend/src/api/api.module.ts
+++ b/apps/backend/src/api/api.module.ts
@@ -50,6 +50,7 @@ import { AppleProvider } from '@gitroom/backend/services/auth/providers/apple.pr
import { FarcasterProvider } from '@gitroom/backend/services/auth/providers/farcaster.provider';
import { WalletProvider } from '@gitroom/backend/services/auth/providers/wallet.provider';
import { OauthProvider } from '@gitroom/backend/services/auth/providers/oauth.provider';
+import { StripeController } from '@gitroom/backend/api/routes/stripe.controller';
const authenticatedController = [
UsersController,
@@ -79,6 +80,7 @@ const authenticatedController = [
: [
RootController,
PaymentController,
+ StripeController,
AuthController,
PublicController,
MonitorController,
diff --git a/apps/backend/src/api/routes/stripe.controller.ts b/apps/backend/src/api/routes/stripe.controller.ts
new file mode 100644
index 000000000..793b1d00a
--- /dev/null
+++ b/apps/backend/src/api/routes/stripe.controller.ts
@@ -0,0 +1,24 @@
+import {
+ Controller,
+ Post,
+ RawBodyRequest,
+ Req,
+} from '@nestjs/common';
+import { ApiTags } from '@nestjs/swagger';
+import { PaymentService } from '@gitroom/nestjs-libraries/services/payment/payment.service';
+
+@ApiTags('Stripe')
+@Controller('/stripe')
+export class StripeController {
+ constructor(private readonly _paymentService: PaymentService) {}
+
+ @Post('/')
+ async stripe(@Req() req: RawBodyRequest<Request>) {
+ return await this._paymentService.webhook(
+ 'stripe',
+ req.rawBody,
+ // @ts-ignore
+ req.headers
+ );
+ }
+}
diff --git a/libraries/nestjs-libraries/src/services/stripe.service.ts b/libraries/nestjs-libraries/src/services/stripe.service.ts
index 1858277e9..e465ce3d3 100644
--- a/libraries/nestjs-libraries/src/services/stripe.service.ts
+++ b/libraries/nestjs-libraries/src/services/stripe.service.ts
@@ -330,8 +330,6 @@ export class StripeService extends PaymentProviderAbstract {
},
}));
- const proration_date = Math.floor(Date.now() / 1000);
-
const currentUserSubscription = {
data: (
await stripe.subscriptions.list({
@@ -346,8 +344,7 @@ export class StripeService extends PaymentProviderAbstract {
customer,
subscription: currentUserSubscription?.data?.[0]?.id,
subscription_details: {
- proration_behavior: 'create_prorations',
- billing_cycle_anchor: 'now',
+ proration_behavior: 'always_invoice',
items: [
{
id: currentUserSubscription?.data?.[0]?.items?.data?.[0]?.id,
@@ -355,14 +352,14 @@ export class StripeService extends PaymentProviderAbstract {
quantity: 1,
},
],
- proration_date: proration_date,
},
});
return {
- price: price?.amount_remaining ? price?.amount_remaining / 100 : 0,
+ price: price?.amount_due ? price?.amount_due / 100 : 0,
};
} catch (err) {
+ console.error('Error calculating proration:', err);
return { price: 0 };
}
}