@@ -3,6 +3,7 @@ import * as functions from 'firebase-functions'
33import { CallableContext , Request } from 'firebase-functions/lib/providers/https'
44import { ChargebeeSubscriptionAPIClient , CustomClaimsSetter , refreshUserSubscriptionStatus } from "./subscriptions" ;
55import { helpTesting , notAuthenticatedResponse , getUser , resultFormatter } from '../utils' ;
6+ import * as express from "express" ;
67
78const chargebee = require ( 'chargebee' )
89
@@ -33,6 +34,11 @@ export const getCheckoutLink = functions.https.onCall(
3334 const checkoutOptions = {
3435 subscription : { plan_id : data . planId } ,
3536 customer : getUser ( context ) ,
37+ "redirect_url" : undefined ,
38+ }
39+
40+ if ( data [ "redirect_url" ] ) {
41+ checkoutOptions [ "redirect_url" ] = data [ "redirect_url" ]
3642 }
3743
3844 const result = await chargebee . hosted_page
@@ -60,6 +66,16 @@ export const getManageLink = functions.https.onCall(
6066
6167 const portalOptions = {
6268 customer : getUser ( context ) ,
69+ "redirect_url" : undefined ,
70+ "access_url" : undefined ,
71+ }
72+
73+ if ( data [ "redirect_url" ] ) {
74+ portalOptions [ "redirect_url" ] = data [ "redirect_url" ]
75+ }
76+
77+ if ( data [ "access_url" ] ) {
78+ portalOptions [ "access_url" ] = data [ "access_url" ]
6379 }
6480
6581 const result = await chargebee . portal_session
@@ -105,17 +121,15 @@ export const refreshUserClaims = functions.https.onCall(
105121 *
106122 */
107123export const userSubscriptionChanged = functions . https . onRequest (
108- async ( req : Request , resp : any ) => {
124+ async ( req : Request , resp : express . Response ) => {
109125 // TODO: Verify secret or host
110126 // TODO: Filter types of subscription change
111127
112- // @ts -ignore (Some issues with peer dep of Express https://github.com/DefinitelyTyped/DefinitelyTyped/issues/40905)
113- if ( req . is ( 'json' ) && req . body != null && req . body . content != null && req . body . content . customer != null ) {
114- // @ts -ignore
115- const userId = req . body . content . customer . id
116- await _refreshUserSubscriptionStatus ( userId )
117- }
118-
128+ resp . send ( ) ;
119129
130+ // if (req.is('json') && req.body != null && req.body.content != null && req.body.content.customer != null) {
131+ // const userId = req.body.content.customer.id
132+ // await _refreshUserSubscriptionStatus(userId)
133+ // }
120134 } ,
121135)
0 commit comments