id, 'eazign' ) || false !== strpos( $screen->id, 'eazign-plan' ) || ! Eazign_Client::is_connected() ) {
return;
}
$data = self::overview();
if ( is_wp_error( $data ) || ! empty( $data['current'] ) ) {
return;
}
printf(
'
',
esc_html__( 'Your Eazign trial has ended. The designer is hidden in your shop until you choose a plan; paid orders still get their print files.', 'eazign' ),
esc_url( admin_url( 'admin.php?page=eazign-plan' ) ),
esc_html__( 'Choose a plan', 'eazign' )
);
}
/**
* Amount with currency.
*
* @param float $amount Amount.
* @param string $currency ISO code.
* @return string
*/
private static function money( $amount, $currency ) {
return wc_price( $amount, array( 'currency' => $currency ) );
}
/**
* Limit value or "unlimited".
*
* @param int|null $limit Limit.
* @return string
*/
private static function limit( $limit ) {
return null === $limit ? __( 'unlimited', 'eazign' ) : number_format_i18n( $limit );
}
/**
* Date in the site's format.
*
* @param string $iso ISO date.
* @return string
*/
private static function date( $iso ) {
return wp_date( get_option( 'date_format' ), strtotime( $iso ) );
}
/**
* The page.
*/
public static function page() {
echo '' . esc_html__( 'Plan & billing', 'eazign' ) . '
';
if ( ! Eazign_Client::is_connected() ) {
echo '
' . wp_kses_post( sprintf( /* translators: %s: URL */ __( 'Please connect your shop first.', 'eazign' ), esc_url( admin_url( 'admin.php?page=eazign' ) ) ) ) . '
';
return;
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display only.
$paid = ! empty( $_GET['paid'] );
$data = self::overview( true );
if ( is_wp_error( $data ) ) {
printf( '', esc_html( $data->get_error_message() ) );
return;
}
$current = $data['current'];
$currency = $data['currency'];
$names = array(
'designerProducts' => __( 'Designer products', 'eazign' ),
'generatedPerMonth' => __( 'Generated products per month', 'eazign' ),
'ordersPerMonth' => __( 'Orders with print files per month', 'eazign' ),
);
if ( $paid ) {
echo '' . esc_html__( 'Thank you! Your subscription is being activated – this can take a minute. Reload the page if the plan does not show yet.', 'eazign' ) . '
';
}
if ( $current && 'past_due' === $current['status'] ) {
echo '' . esc_html__( 'The last payment failed. Please update your payment method under "Manage subscription".', 'eazign' ) . '
';
}
?>
' . esc_html( $current['name'] ) . '', esc_html( self::date( $current['trialEndsAt'] ) ) );
} elseif ( 'free' === $current['source'] ) {
/* translators: %s: plan name */
printf( esc_html__( '%s – free of charge.', 'eazign' ), '' . esc_html( $current['name'] ) . '' );
} else {
$interval = 'yearly' === $current['interval'] ? __( 'yearly', 'eazign' ) : __( 'monthly', 'eazign' );
/* translators: 1: plan name, 2: billing interval */
printf( esc_html__( '%1$s, billed %2$s.', 'eazign' ), '' . esc_html( $current['name'] ) . '', esc_html( $interval ) );
if ( ! empty( $current['periodEndsAt'] ) ) {
echo ' ';
if ( 'trialing' === $current['status'] ) {
/* translators: %s: date */
printf( esc_html__( 'Trial period until %s, then billed.', 'eazign' ), esc_html( self::date( $current['periodEndsAt'] ) ) );
} elseif ( 'canceled' === $current['status'] ) {
/* translators: %s: date */
printf( esc_html__( 'Canceled, active until %s.', 'eazign' ), esc_html( self::date( $current['periodEndsAt'] ) ) );
} else {
/* translators: %s: date */
printf( esc_html__( 'Next renewal on %s.', 'eazign' ), esc_html( self::date( $current['periodEndsAt'] ) ) );
}
}
}
?>
isset( $_POST['plan'] ) ? sanitize_key( wp_unslash( $_POST['plan'] ) ) : '',
'interval' => isset( $_POST['interval'] ) && 'yearly' === $_POST['interval'] ? 'yearly' : 'monthly',
)
);
delete_transient( self::CACHE );
if ( is_wp_error( $result ) ) {
Eazign_Admin::notice( 'error', $result->get_error_message() );
} elseif ( ! empty( $result['url'] ) && 0 === strpos( $result['url'], Eazign_Client::server_url() . '/woo/v1/pay/' ) ) {
// Checkout page of the Eazign service, which opens Paddle's checkout.
wp_redirect( $result['url'] ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- checked to be the service's own page.
exit;
} elseif ( ! empty( $result['changed'] ) ) {
Eazign_Admin::notice( 'success', __( 'Your plan was changed.', 'eazign' ) );
}
wp_safe_redirect( $back );
exit;
}
/**
* Paddle customer portal (temporary, authenticated link).
*/
public static function portal() {
if ( ! current_user_can( 'manage_woocommerce' ) ) {
wp_die( esc_html__( 'Sorry, you are not allowed to do this.', 'eazign' ) );
}
check_admin_referer( 'eazign_portal' );
$result = Eazign_Client::post( 'billing/portal' );
if ( ! is_wp_error( $result ) && ! empty( $result['url'] ) && 'https' === wp_parse_url( $result['url'], PHP_URL_SCHEME ) ) {
wp_redirect( $result['url'] ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- Paddle's customer portal.
exit;
}
Eazign_Admin::notice( 'error', is_wp_error( $result ) ? $result->get_error_message() : __( 'The subscription portal is not available.', 'eazign' ) );
wp_safe_redirect( admin_url( 'admin.php?page=eazign-plan' ) );
exit;
}
}