Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
90.91% |
10 / 11 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| AI_Launchpad_Memberships | |
90.91% |
10 / 11 |
|
50.00% |
1 / 2 |
7.04 | |
0.00% |
0 / 1 |
| has_override | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| is_task_complete | |
90.00% |
9 / 10 |
|
0.00% |
0 / 1 |
6.04 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * AI Launchpad memberships completion override. |
| 4 | * |
| 5 | * @package automattic/jetpack-mu-wpcom |
| 6 | * |
| 7 | * @phan-file-suppress PhanUndeclaredClassMethod -- Jetpack_Memberships ships in the Jetpack plugin, available at runtime on Atomic; calls are guarded by class_exists. |
| 8 | */ |
| 9 | |
| 10 | /** |
| 11 | * Recomputes the memberships task completion from Jetpack_Memberships' local signals. |
| 12 | * |
| 13 | * The catalog's own callbacks are always false on Atomic (their membership settings return null there), so the REST |
| 14 | * read path uses this instead. Jetpack_Memberships syncs the connected-account flag and membership plans down locally. |
| 15 | */ |
| 16 | class AI_Launchpad_Memberships { |
| 17 | |
| 18 | /** |
| 19 | * Membership tasks whose completion the AI Launchpad recomputes locally. |
| 20 | */ |
| 21 | const OVERRIDDEN_TASK_IDS = array( |
| 22 | 'stripe_connected', |
| 23 | 'set_up_payments', |
| 24 | 'paid_offer_created', |
| 25 | 'newsletter_plan_created', |
| 26 | ); |
| 27 | |
| 28 | /** |
| 29 | * Whether the AI Launchpad recomputes completion for the given task locally. |
| 30 | * |
| 31 | * @param string $task_id The catalog task ID. |
| 32 | * @return bool |
| 33 | */ |
| 34 | public static function has_override( $task_id ) { |
| 35 | return in_array( $task_id, self::OVERRIDDEN_TASK_IDS, true ); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Whether an overridden membership task is complete, from Jetpack_Memberships' |
| 40 | * local signals. Returns false for non-overridden tasks and when the memberships |
| 41 | * module is unavailable. |
| 42 | * |
| 43 | * @param string $task_id The catalog task ID. |
| 44 | * @return bool |
| 45 | */ |
| 46 | public static function is_task_complete( $task_id ) { |
| 47 | if ( ! class_exists( 'Jetpack_Memberships' ) ) { |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | switch ( $task_id ) { |
| 52 | case 'stripe_connected': |
| 53 | case 'set_up_payments': |
| 54 | // A connected account means a payment method is set up; wpcom completes both on Stripe-connect. |
| 55 | return (bool) Jetpack_Memberships::has_connected_account(); |
| 56 | case 'paid_offer_created': |
| 57 | return (bool) Jetpack_Memberships::has_configured_plans_jetpack_recurring_payments(); |
| 58 | case 'newsletter_plan_created': |
| 59 | return (bool) Jetpack_Memberships::has_configured_plans_jetpack_recurring_payments( 'newsletter' ); |
| 60 | } |
| 61 | |
| 62 | return false; |
| 63 | } |
| 64 | } |