@@ -12,12 +12,18 @@ import {
1212} from '../../plus/subscription' ;
1313import { logger } from '../../../logger' ;
1414import { OpportunityJob } from '../../../entity/opportunities/OpportunityJob' ;
15- import { recruiterPaddleCustomDataSchema } from './types' ;
15+ import {
16+ recruiterPaddleCustomDataSchema ,
17+ recruiterPaddlePricingCustomDataSchema ,
18+ } from './types' ;
1619import {
1720 ensureOpportunityPermissions ,
1821 OpportunityPermissions ,
1922} from '../../opportunity/accessControl' ;
20- import { updateRecruiterSubscriptionFlags } from '../../utils' ;
23+ import {
24+ updateFlagsStatement ,
25+ updateRecruiterSubscriptionFlags ,
26+ } from '../../utils' ;
2127import { OpportunityState } from '@dailydotdev/schema' ;
2228import { Organization } from '../../../entity/Organization' ;
2329
@@ -84,6 +90,24 @@ export const createOpportunitySubscription = async ({
8490 permission : OpportunityPermissions . Edit ,
8591 } ) ;
8692
93+ if ( event . data ?. items ?. length > 1 ) {
94+ throw new Error (
95+ 'Multiple recruiter subscription items not supported on creation, check payment manually' ,
96+ ) ;
97+ }
98+
99+ const price = event . data ?. items ?. [ 0 ] ?. price ;
100+
101+ if ( ! price ) {
102+ throw new Error (
103+ 'Price information missing from recruiter subscription data' ,
104+ ) ;
105+ }
106+
107+ const priceCustomData = recruiterPaddlePricingCustomDataSchema . parse (
108+ price . customData ,
109+ ) ;
110+
87111 await con . transaction ( async ( entityManager ) => {
88112 await entityManager . getRepository ( Organization ) . update (
89113 {
@@ -114,6 +138,10 @@ export const createOpportunitySubscription = async ({
114138 } ,
115139 {
116140 state : OpportunityState . IN_REVIEW ,
141+ flags : updateFlagsStatement < OpportunityJob > ( {
142+ batchSize : priceCustomData . batch_size ,
143+ plan : price . id ,
144+ } ) ,
117145 } ,
118146 ) ;
119147 } ) ;
0 commit comments