Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
Premium_Pricing
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 1
 get_yearly_pricing
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3namespace Automattic\Jetpack_Boost\Lib;
4
5use Automattic\Jetpack\My_Jetpack\Products\Boost;
6use Automattic\Jetpack\My_Jetpack\Wpcom_Products;
7use Automattic\Jetpack\Status;
8
9class Premium_Pricing {
10    /**
11     * Get an object containing the yearly pricing information for Jetpack Boost.
12     *
13     * Used by Jetpack_Boost js constants and data sync.
14     */
15    public static function get_yearly_pricing() {
16        $yearly_pricing = Wpcom_Products::get_product_pricing( Boost::UPGRADED_TIER_PRODUCT_SLUG );
17
18        if ( empty( $yearly_pricing ) ) {
19            // In offline mode, we don't have access to the pricing data and it's not an error.
20            if ( ! ( new Status() )->is_offline_mode() ) {
21                Analytics::record_user_event( 'upgrade_price_missing', array( 'error_message' => 'Missing pricing information on benefits interstitial page.' ) );
22            }
23            return null;
24        }
25
26        return array(
27            'priceBefore'         => $yearly_pricing['full_price'],
28            'priceAfter'          => $yearly_pricing['discount_price'],
29            'currencyCode'        => $yearly_pricing['currency_code'],
30            'isIntroductoryOffer' => $yearly_pricing['is_introductory_offer'] === true,
31        );
32    }
33}