66use Give \API \REST \V3 \Routes \Campaigns \Permissions \CampaignPermissions ;
77use Give \API \REST \V3 \Routes \Campaigns \ValueObjects \CampaignRoute ;
88use Give \Campaigns \Controllers \CampaignRequestController ;
9+ use Give \Campaigns \ValueObjects \CampaignGoalType ;
10+ use Give \Campaigns \ValueObjects \CampaignStatus ;
11+ use Give \Campaigns \ValueObjects \CampaignType ;
912use WP_REST_Request ;
1013use WP_REST_Server ;
1114
@@ -142,6 +145,7 @@ public function registerGetCampaigns()
142145 'default ' => '' ,
143146 ],
144147 ],
148+ 'schema ' => [$ this , 'getSchema ' ],
145149 ]
146150 );
147151 }
@@ -249,7 +253,7 @@ public function registerCreateCampaign()
249253 'required ' => false ,
250254 'validate_callback ' => 'rest_parse_date ' ,
251255 'sanitize_callback ' => function ($ value ) {
252- return new DateTime ($ value );
256+ return new DateTime ($ value, wp_timezone () );
253257 },
254258 ],
255259 'endDateTime ' => [
@@ -258,7 +262,7 @@ public function registerCreateCampaign()
258262 'required ' => false ,
259263 'validate_callback ' => 'rest_parse_date ' ,
260264 'sanitize_callback ' => function ($ value ) {
261- return new DateTime ($ value );
265+ return new DateTime ($ value, wp_timezone () );
262266 },
263267 ],
264268 ] ),
@@ -313,61 +317,126 @@ public function getSchema(): array
313317 'id ' => [
314318 'type ' => 'integer ' ,
315319 'description ' => esc_html__ ('Campaign ID ' , 'give ' ),
320+ 'readonly ' => true ,
321+ ],
322+ 'pagePermalink ' => [
323+ 'type ' => ['string ' , 'null ' ],
324+ 'description ' => esc_html__ ('Campaign page permalink ' , 'give ' ),
325+ 'readonly ' => true ,
316326 ],
317327 'title ' => [
318328 'type ' => 'string ' ,
319329 'description ' => esc_html__ ('Campaign title ' , 'give ' ),
320330 'minLength ' => 3 ,
321331 'maxLength ' => 128 ,
322- 'errorMessage ' => esc_html__ ( ' Campaign title is required ' , ' give ' ) ,
332+ 'required ' => true ,
323333 ],
324334 'status ' => [
325- 'enum ' => [' active ' , ' inactive ' , ' draft ' , ' pending ' , ' processing ' , ' failed ' , ' archived ' ],
335+ 'enum ' => [CampaignStatus:: ACTIVE ,CampaignStatus:: ARCHIVED ],
326336 'description ' => esc_html__ ('Campaign status ' , 'give ' ),
337+ 'default ' => CampaignStatus::ACTIVE ,
327338 ],
328339 'shortDescription ' => [
329- 'type ' => 'string ' ,
340+ 'type ' => [ 'string ' , ' null ' ] ,
330341 'description ' => esc_html__ ('Campaign short description ' , 'give ' ),
331342 'maxLength ' => 120 ,
332343 ],
344+ 'longDescription ' => [
345+ 'type ' => ['string ' , 'null ' ],
346+ 'description ' => esc_html__ ('Campaign long description ' , 'give ' ),
347+ ],
348+ 'logo ' => [
349+ 'type ' => ['string ' , 'null ' ],
350+ 'format ' => 'uri ' ,
351+ 'description ' => esc_html__ ('Campaign logo URL ' , 'give ' ),
352+ ],
353+ 'image ' => [
354+ 'type ' => ['string ' , 'null ' ],
355+ 'format ' => 'uri ' ,
356+ 'description ' => esc_html__ ('Campaign featured image URL ' , 'give ' ),
357+ ],
333358 'primaryColor ' => [
334- 'type ' => 'string ' ,
359+ 'type ' => [ 'string ' , ' null ' ] ,
335360 'description ' => esc_html__ ('Primary color for the campaign ' , 'give ' ),
336361 ],
337362 'secondaryColor ' => [
338- 'type ' => 'string ' ,
363+ 'type ' => [ 'string ' , ' null ' ] ,
339364 'description ' => esc_html__ ('Secondary color for the campaign ' , 'give ' ),
340365 ],
341366 'goal ' => [
342- 'type ' => 'number ' ,
367+ 'type ' => 'integer ' ,
343368 'description ' => esc_html__ ('Campaign goal ' , 'give ' ),
344369 'errorMessage ' => esc_html__ ('Must be a number ' , 'give ' ),
345- ],
346- 'goalProgress ' => [
347- 'type ' => 'number ' ,
348- 'description ' => esc_html__ ('Campaign goal progress ' , 'give ' ),
370+ 'required ' => true ,
349371 ],
350372 'goalType ' => [
351- 'enum ' => [
352- 'amount ' ,
353- 'donations ' ,
354- 'donors ' ,
355- 'amountFromSubscriptions ' ,
356- 'subscriptions ' ,
357- 'donorsFromSubscriptions ' ,
358- ],
373+ 'enum ' => array_values (CampaignGoalType::toArray ()),
359374 'description ' => esc_html__ ('Campaign goal type ' , 'give ' ),
375+ 'required ' => true ,
376+ ],
377+ 'goalStats ' => [
378+ 'type ' => 'object ' ,
379+ 'description ' => esc_html__ ('Campaign goal statistics ' , 'give ' ),
380+ 'readonly ' => true ,
381+ 'properties ' => [
382+ 'actual ' => [
383+ 'type ' => ['integer ' , 'number ' ],
384+ 'description ' => esc_html__ ('Actual progress value ' , 'give ' ),
385+ ],
386+ 'actualFormatted ' => [
387+ 'type ' => ['string ' , 'number ' ],
388+ 'description ' => esc_html__ ('Formatted actual progress ' , 'give ' ),
389+ ],
390+ 'percentage ' => [
391+ 'type ' => 'number ' ,
392+ 'description ' => esc_html__ ('Progress percentage ' , 'give ' ),
393+ ],
394+ 'goal ' => [
395+ 'type ' => ['integer ' , 'number ' ],
396+ 'description ' => esc_html__ ('Goal value ' , 'give ' ),
397+ ],
398+ 'goalFormatted ' => [
399+ 'type ' => ['string ' , 'number ' ],
400+ 'description ' => esc_html__ ('Formatted goal value ' , 'give ' ),
401+ ],
402+ ],
403+ ],
404+ 'type ' => [
405+ 'type ' => 'string ' ,
406+ 'enum ' => array_values (CampaignType::toArray ()),
407+ 'description ' => esc_html__ ('Campaign type ' , 'give ' ),
408+ 'default ' => CampaignType::CORE ,
360409 ],
361410 'defaultFormId ' => [
362411 'type ' => 'integer ' ,
363412 'description ' => esc_html__ ('Default campaign form ID ' , 'give ' ),
413+ 'readonly ' => true ,
414+ ],
415+ 'defaultFormTitle ' => [
416+ 'type ' => 'string ' ,
417+ 'description ' => esc_html__ ('Default campaign form title ' , 'give ' ),
418+ 'readonly ' => true ,
364419 ],
365420 'pageId ' => [
366- 'type ' => 'integer ' ,
421+ 'type ' => [ 'integer ' , ' null ' ] ,
367422 'description ' => esc_html__ ('Campaign page ID ' , 'give ' ),
368423 ],
424+ 'startDate ' => [
425+ 'type ' => ['string ' , 'null ' ],
426+ 'description ' => esc_html__ ('Campaign start date (Y-m-d H:i:s) ' , 'give ' ),
427+ 'format ' => 'date-time ' ,
428+ ],
429+ 'endDate ' => [
430+ 'type ' => ['string ' , 'null ' ],
431+ 'description ' => esc_html__ ('Campaign end date (Y-m-d H:i:s) or null ' , 'give ' ),
432+ 'format ' => 'date-time ' ,
433+ ],
434+ 'createdAt ' => [
435+ 'type ' => ['string ' , 'null ' ],
436+ 'description ' => esc_html__ ('Campaign creation date (Y-m-d H:i:s) ' , 'give ' ),
437+ 'format ' => 'date-time ' ,
438+ ],
369439 ],
370- 'required ' => ['id ' , 'title ' , 'goal ' , 'goalType ' ],
371440 'allOf ' => [
372441 [
373442 'if ' => [
@@ -381,7 +450,7 @@ public function getSchema(): array
381450 'properties ' => [
382451 'goal ' => [
383452 //'minimum' => 1,
384- 'type ' => 'number ' ,
453+ 'type ' => 'integer ' ,
385454 ],
386455 ],
387456 'errorMessage ' => [
@@ -403,7 +472,7 @@ public function getSchema(): array
403472 'properties ' => [
404473 'goal ' => [
405474 'minimum ' => 1 ,
406- 'type ' => 'number ' ,
475+ 'type ' => 'integer ' ,
407476 ],
408477 ],
409478 'errorMessage ' => [
@@ -425,7 +494,7 @@ public function getSchema(): array
425494 'properties ' => [
426495 'goal ' => [
427496 'minimum ' => 1 ,
428- 'type ' => 'number ' ,
497+ 'type ' => 'integer ' ,
429498 ],
430499 ],
431500 'errorMessage ' => [
@@ -447,7 +516,7 @@ public function getSchema(): array
447516 'properties ' => [
448517 'goal ' => [
449518 'minimum ' => 1 ,
450- 'type ' => 'number ' ,
519+ 'type ' => 'integer ' ,
451520 ],
452521 ],
453522 'errorMessage ' => [
@@ -469,7 +538,7 @@ public function getSchema(): array
469538 'properties ' => [
470539 'goal ' => [
471540 'minimum ' => 1 ,
472- 'type ' => 'number ' ,
541+ 'type ' => 'integer ' ,
473542 ],
474543 ],
475544 'errorMessage ' => [
0 commit comments