function email_notification( $blog_id, $action, $email = false, $args = array() ) { global $wpdb; if ( ! $email ) { $email = get_blog_option( $blog_id, 'admin_email' ); } // used in all emails $search_replace = array( 'LEVEL' => $this->get_level_setting( $this->get_level( $blog_id ), 'name' ), 'SITEURL' => get_home_url( $blog_id ), 'SITENAME' => get_blog_option( $blog_id, 'blogname' ), 'CHECKOUTURL' => $this->checkout_url( $blog_id ) ); // send emails as html (fixes some formatting issues with currencies) $mail_headers = array( 'Content-Type: text/html' ); switch ( $action ) { case 'success': $e = array( 'msg' => $this->get_setting( 'success_msg' ), 'subject' => $this->get_setting( 'success_subject' ) ); $e = str_replace( array_keys( $search_replace ), $search_replace, $e ); wp_mail( $email, $e['subject'], nl2br( $e['msg'] ), implode( "\r\n", $mail_headers ) ); $this->log_action( $blog_id, sprintf( __( 'Signup success email sent to %s', 'psts' ), $email ) ); break; case 'receipt': // NOTE: Stripe no longer uses this //grab default payment info $result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->base_prefix}pro_sites WHERE blog_ID = %d", $blog_id ) ); if ( $result->term == 1 || $result->term == 3 || $result->term == 12 ) { $term = sprintf( __( 'Every %s Month(s)', 'psts' ), $result->term ); } else { $term = $result->term; } $level = $result->level; $payment_info = ''; // Get current plan $level_list = get_site_option( 'psts_levels' ); $level_name = $level_list[ $level ]['name']; $payment_info .= sprintf( __( 'Current Plan: %s', 'psts' ), $level_name ) . "\n\n"; if ( $result->gateway ) { $nicename = ProSites_Helper_Gateway::get_nice_name( $result->gateway ); $payment_info .= sprintf( __( 'Payment Method: %s', 'psts' ), $nicename ) . "\n"; } if ( $term ) { $payment_info .= sprintf( __( 'Payment Term: %s', 'psts' ), $term ) . "\n"; } $trialing = ProSites_Helper_Registration::is_trial( $blog_id ); $amount = $trialing ? 0.0 : $result->amount; $payment_info .= sprintf( __( 'Payment Amount: %s', 'psts' ), $this->format_currency( false, $amount ) . ' ' . $this->get_setting( 'currency' ) ) . "\n"; if( ! empty( $args ) ) { if( isset( $args['items'] ) ) { $items = $args['items']; $items_total = ProSites_Model_Receipt::get_items_total( $items ); foreach( $items as $item ) { $symbol = $item['amount'] > 0 ? '' : '-'; $payment_info .= sprintf( '%s: %s%s', $item['description'], $symbol, $this->format_currency( false, abs( $item['amount'] ) ) . ' ' . $this->get_setting( 'currency' ) ) . "\n"; } $payment_info .= '<hr />'; $items_total = $items_total > 0 ? $items_total : 0; $symbol = $items_total >= 0 ? '' : '-'; $payment_info .= sprintf( __( 'Total Paid: %s%s', 'psts' ), $symbol, $this->format_currency( false, $items_total ) . ' ' . $this->get_setting( 'currency' ) ) . "\n"; } else { /** * @todo Remove prior to release */ if( isset( $args['setup_amount'] ) ) { $payment_info .= sprintf( __( 'One-Time Setup Fee: %s', 'psts' ), $this->format_currency( false, $args['setup_amount'] ) . ' ' . $this->get_setting( 'currency' ) ) . "\n"; } else { $args['setup_amount'] = 0; } if( isset( $args['discount_amount'] ) ) { $payment_info .= sprintf( __( 'Discount: -%s', 'psts' ), $this->format_currency( false, abs( $args['discount_amount'] ) ) . ' ' . $this->get_setting( 'currency' ) ) . "\n"; } else { $args['discount_amount'] = 0; } $zero_cost_change = false; if( isset( $args['plan_change_amount'] ) ) { switch( $args['plan_change_mode'] ) { case 'upgrade': $payment_info .= sprintf( __( 'Plan Modified: %s', 'psts' ), $this->format_currency( false, abs( $args['plan_change_amount'] ) ) . ' ' . $this->get_setting( 'currency' ) ) . "\n"; break; case 'downgrade': $payment_info .= sprintf( __( 'Plan Modified: -%s', 'psts' ), $this->format_currency( false, abs( $args['plan_change_amount'] ) ) . ' ' . $this->get_setting( 'currency' ) ) . "\n"; break; } $zero_cost_change = 0 > ( $amount + $args['setup_amount'] + $args['plan_change_amount'] - $args['discount_amount'] ); } else { $args['plan_change_amount'] = 0; } $payment_info .= sprintf( '<hr />' ); if( $zero_cost_change ) { // No cost to upgrade $payment_info .= sprintf( __( 'Total Paid: %s', 'psts' ), $this->format_currency( false, 0 ) . ' ' . $this->get_setting( 'currency' ) ) . "\n"; } else { $payment_info .= sprintf( __( 'Total Paid: %s', 'psts' ), $this->format_currency( false, ( $amount + $args['setup_amount'] + $args['plan_change_amount'] - $args['discount_amount'] ) ) . ' ' . $this->get_setting( 'currency' ) ) . "\n"; } } } if ( $result->gateway == 'Trial' || ! empty( $trialing ) ) { $trial_info = "\n" . __( '*** PLEASE NOTE ***', 'psts' ) . "\n"; $trial_info .= sprintf( __( 'You will not be charged for your subscription until your trial ends on %s. If applicable, this does not apply to setup fees and other upfront costs.', 'psts' ), date_i18n( get_option( 'date_format' ), $result->expire ) ); $payment_info .= apply_filters( 'psts_trial_info', $trial_info, $blog_id ); } $search_replace['PAYMENTINFO'] = apply_filters( 'psts_payment_info', $payment_info, $blog_id ); $e = array( 'msg' => $this->get_setting( 'receipt_msg' ), 'subject' => $this->get_setting( 'receipt_subject' ) ); $e = str_replace( array_keys( $search_replace ), $search_replace, $e ); wp_mail( $email, $e['subject'], nl2br( $e['msg'] ), implode( "\r\n", $mail_headers ), $this->pdf_receipt( $e['msg'] ) ); $this->log_action( $blog_id, sprintf( __( 'Payment receipt email sent to %s', 'psts' ), $email ) ); break; case 'canceled': //get end date from expiration $end_date = date_i18n( get_blog_option( $blog_id, 'date_format' ), $this->get_expire( $blog_id ) ); $search_replace['ENDDATE'] = $end_date; $e = array( 'msg' => $this->get_setting( 'canceled_msg' ), 'subject' => $this->get_setting( 'canceled_subject' ) ); $e = str_replace( array_keys( $search_replace ), $search_replace, $e ); wp_mail( $email, $e['subject'], nl2br( $e['msg'] ), implode( "\r\n", $mail_headers ) ); $this->log_action( $blog_id, sprintf( __( 'Subscription canceled email sent to %s', 'psts' ), $email ) ); break; case 'expired': $e = array( 'msg' => $this->get_setting( 'expired_msg' ), 'subject' => $this->get_setting( 'expired_subject' ) ); $e = str_replace( array_keys( $search_replace ), $search_replace, $e ); wp_mail( $email, $e['subject'], nl2br( $e['msg'] ), implode( "\r\n", $mail_headers ) ); $this->log_action( $blog_id, sprintf( __( 'Expired email sent to %s', 'psts' ), $email ) ); break; case 'failed': $e = array( 'msg' => $this->get_setting( 'failed_msg' ), 'subject' => $this->get_setting( 'failed_subject' ) ); $e = str_replace( array_keys( $search_replace ), $search_replace, $e ); wp_mail( $email, $e['subject'], nl2br( $e['msg'] ), implode( "\r\n", $mail_headers ) ); $this->log_action( $blog_id, sprintf( __( 'Payment failed email sent to %s', 'psts' ), $email ) ); break; case 'extension': //get end date from expiration $end_date = date_i18n( get_blog_option( $blog_id, 'date_format' ), $this->get_expire( $blog_id ) ); if( ! empty( $args ) && isset( $args['indefinite'] ) ) { $end_date = __( 'Indefinitely', 'psts' ); } $search_replace['ENDDATE'] = $end_date; $e = array( 'msg' => $this->get_setting( 'extension_msg' ), 'subject' => $this->get_setting( 'extension_subject' ) ); $e = str_replace( array_keys( $search_replace ), $search_replace, $e ); wp_mail( $email, $e['subject'], nl2br( $e['msg'] ), implode( "\r\n", $mail_headers ) ); $this->log_action( $blog_id, sprintf( __( 'Manual extension email sent to %s', 'psts' ), $email ) ); break; } }
public function get_total() { return ProSites_Model_Receipt::get_items_total($this->items); }