@@ -40,86 +40,86 @@ discard block |
||
40 | 40 | <tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>"> |
41 | 41 | <?php |
42 | 42 | |
43 | - foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : |
|
43 | + foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : |
|
44 | 44 | |
45 | - $column_id = sanitize_html_class( $column_id ); |
|
46 | - $class = empty( $column_name['class'] ) ? '' : sanitize_html_class( $column_name['class'] ); |
|
45 | + $column_id = sanitize_html_class( $column_id ); |
|
46 | + $class = empty( $column_name['class'] ) ? '' : sanitize_html_class( $column_name['class'] ); |
|
47 | 47 | |
48 | - echo "<td class='$column_id $class'>"; |
|
49 | - switch ( $column_id ) { |
|
48 | + echo "<td class='$column_id $class'>"; |
|
49 | + switch ( $column_id ) { |
|
50 | 50 | |
51 | - case 'invoice-number': |
|
52 | - echo wpinv_invoice_link( $invoice ); |
|
53 | - break; |
|
51 | + case 'invoice-number': |
|
52 | + echo wpinv_invoice_link( $invoice ); |
|
53 | + break; |
|
54 | 54 | |
55 | - case 'created-date': |
|
56 | - echo getpaid_format_date_value( $invoice->get_date_created() ); |
|
57 | - break; |
|
55 | + case 'created-date': |
|
56 | + echo getpaid_format_date_value( $invoice->get_date_created() ); |
|
57 | + break; |
|
58 | 58 | |
59 | - case 'payment-date': |
|
59 | + case 'payment-date': |
|
60 | 60 | |
61 | - if ( $invoice->needs_payment() ) { |
|
62 | - echo "—"; |
|
63 | - } else { |
|
64 | - echo getpaid_format_date_value( $invoice->get_date_completed() ); |
|
65 | - } |
|
61 | + if ( $invoice->needs_payment() ) { |
|
62 | + echo "—"; |
|
63 | + } else { |
|
64 | + echo getpaid_format_date_value( $invoice->get_date_completed() ); |
|
65 | + } |
|
66 | 66 | |
67 | - break; |
|
67 | + break; |
|
68 | 68 | |
69 | - case 'invoice-status': |
|
70 | - echo $invoice->get_status_label_html(); |
|
69 | + case 'invoice-status': |
|
70 | + echo $invoice->get_status_label_html(); |
|
71 | 71 | |
72 | - break; |
|
72 | + break; |
|
73 | 73 | |
74 | - case 'invoice-total': |
|
75 | - echo wpinv_price( wpinv_format_amount( $invoice->get_total() ) ); |
|
74 | + case 'invoice-total': |
|
75 | + echo wpinv_price( wpinv_format_amount( $invoice->get_total() ) ); |
|
76 | 76 | |
77 | - break; |
|
77 | + break; |
|
78 | 78 | |
79 | - case 'invoice-actions': |
|
79 | + case 'invoice-actions': |
|
80 | 80 | |
81 | - $actions = array( |
|
81 | + $actions = array( |
|
82 | 82 | |
83 | - 'pay' => array( |
|
84 | - 'url' => $invoice->get_checkout_payment_url(), |
|
85 | - 'name' => __( 'Pay Now', 'invoicing' ), |
|
83 | + 'pay' => array( |
|
84 | + 'url' => $invoice->get_checkout_payment_url(), |
|
85 | + 'name' => __( 'Pay Now', 'invoicing' ), |
|
86 | 86 | 'class' => 'btn-success' |
87 | - ), |
|
87 | + ), |
|
88 | 88 | |
89 | 89 | 'print' => array( |
90 | - 'url' => $invoice->get_view_url(), |
|
91 | - 'name' => __( 'View Invoice', 'invoicing' ), |
|
90 | + 'url' => $invoice->get_view_url(), |
|
91 | + 'name' => __( 'View Invoice', 'invoicing' ), |
|
92 | 92 | 'class' => 'btn-secondary', |
93 | 93 | 'attrs' => 'target="_blank"' |
94 | - ) |
|
95 | - ); |
|
94 | + ) |
|
95 | + ); |
|
96 | 96 | |
97 | - if ( ! $invoice->needs_payment() ) { |
|
98 | - unset( $actions['pay'] ); |
|
99 | - } |
|
97 | + if ( ! $invoice->needs_payment() ) { |
|
98 | + unset( $actions['pay'] ); |
|
99 | + } |
|
100 | 100 | |
101 | - $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ); |
|
101 | + $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ); |
|
102 | 102 | |
103 | - foreach ( $actions as $key => $action ) { |
|
104 | - $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; |
|
105 | - echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm btn-block ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>'; |
|
106 | - } |
|
103 | + foreach ( $actions as $key => $action ) { |
|
104 | + $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; |
|
105 | + echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm btn-block ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>'; |
|
106 | + } |
|
107 | 107 | |
108 | - break; |
|
108 | + break; |
|
109 | 109 | |
110 | - default: |
|
111 | - do_action( "wpinv_user_invoices_column_$column_id", $invoice ); |
|
112 | - break; |
|
110 | + default: |
|
111 | + do_action( "wpinv_user_invoices_column_$column_id", $invoice ); |
|
112 | + break; |
|
113 | 113 | |
114 | 114 | |
115 | - } |
|
115 | + } |
|
116 | 116 | |
117 | - do_action( "wpinv_user_invoices_column_after_$column_id", $invoice ); |
|
117 | + do_action( "wpinv_user_invoices_column_after_$column_id", $invoice ); |
|
118 | 118 | |
119 | - echo '</td>'; |
|
119 | + echo '</td>'; |
|
120 | 120 | |
121 | - endforeach; |
|
122 | - ?> |
|
121 | + endforeach; |
|
122 | + ?> |
|
123 | 123 | </tr> |
124 | 124 | |
125 | 125 | <?php endforeach; ?> |
@@ -132,14 +132,14 @@ discard block |
||
132 | 132 | <?php if ( 1 < $invoices->max_num_pages ) : ?> |
133 | 133 | <div class="invoicing-Pagination"> |
134 | 134 | <?php |
135 | - $big = 999999; |
|
136 | - |
|
137 | - echo paginate_links( array( |
|
138 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
139 | - 'format' => '?paged=%#%', |
|
140 | - 'total' => $invoices->max_num_pages, |
|
141 | - ) ); |
|
142 | - ?> |
|
135 | + $big = 999999; |
|
136 | + |
|
137 | + echo paginate_links( array( |
|
138 | + 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
139 | + 'format' => '?paged=%#%', |
|
140 | + 'total' => $invoices->max_num_pages, |
|
141 | + ) ); |
|
142 | + ?> |
|
143 | 143 | </div> |
144 | 144 | <?php endif; ?> |
145 | 145 |
@@ -12,186 +12,186 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Metaboxes { |
14 | 14 | |
15 | - /** |
|
16 | - * Only save metaboxes once. |
|
17 | - * |
|
18 | - * @var boolean |
|
19 | - */ |
|
20 | - private static $saved_meta_boxes = false; |
|
15 | + /** |
|
16 | + * Only save metaboxes once. |
|
17 | + * |
|
18 | + * @var boolean |
|
19 | + */ |
|
20 | + private static $saved_meta_boxes = false; |
|
21 | 21 | |
22 | 22 | /** |
23 | - * Hook in methods. |
|
24 | - */ |
|
25 | - public static function init() { |
|
26 | - |
|
27 | - // Register metaboxes. |
|
28 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
29 | - |
|
30 | - // Remove metaboxes. |
|
31 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
32 | - |
|
33 | - // Rename metaboxes. |
|
34 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
35 | - |
|
36 | - // Save metaboxes. |
|
37 | - add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * Register core metaboxes. |
|
42 | - */ |
|
43 | - public static function add_meta_boxes( $post_type, $post ) { |
|
44 | - global $wpinv_euvat; |
|
45 | - |
|
46 | - // For invoices... |
|
47 | - if ( $post_type == 'wpi_invoice' ) { |
|
48 | - $invoice = new WPInv_Invoice( $post ); |
|
49 | - |
|
50 | - // Resend invoice. |
|
51 | - if ( ! $invoice->is_draft() && ! $invoice->is_paid() ) { |
|
52 | - add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'GetPaid_Meta_Box_Resend_Invoice::output', 'wpi_invoice', 'side', 'low' ); |
|
53 | - } |
|
54 | - |
|
55 | - // Subscriptions. |
|
56 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
57 | - if ( ! empty( $subscription ) ) { |
|
58 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', 'wpi_invoice', 'advanced' ); |
|
59 | - add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', 'wpi_invoice', 'advanced' ); |
|
60 | - } |
|
61 | - |
|
62 | - // Invoice details. |
|
63 | - add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Details::output', 'wpi_invoice', 'side', 'default' ); |
|
23 | + * Hook in methods. |
|
24 | + */ |
|
25 | + public static function init() { |
|
26 | + |
|
27 | + // Register metaboxes. |
|
28 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
29 | + |
|
30 | + // Remove metaboxes. |
|
31 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
32 | + |
|
33 | + // Rename metaboxes. |
|
34 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
35 | + |
|
36 | + // Save metaboxes. |
|
37 | + add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * Register core metaboxes. |
|
42 | + */ |
|
43 | + public static function add_meta_boxes( $post_type, $post ) { |
|
44 | + global $wpinv_euvat; |
|
45 | + |
|
46 | + // For invoices... |
|
47 | + if ( $post_type == 'wpi_invoice' ) { |
|
48 | + $invoice = new WPInv_Invoice( $post ); |
|
49 | + |
|
50 | + // Resend invoice. |
|
51 | + if ( ! $invoice->is_draft() && ! $invoice->is_paid() ) { |
|
52 | + add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'GetPaid_Meta_Box_Resend_Invoice::output', 'wpi_invoice', 'side', 'low' ); |
|
53 | + } |
|
54 | + |
|
55 | + // Subscriptions. |
|
56 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
57 | + if ( ! empty( $subscription ) ) { |
|
58 | + add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', 'wpi_invoice', 'advanced' ); |
|
59 | + add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', 'wpi_invoice', 'advanced' ); |
|
60 | + } |
|
61 | + |
|
62 | + // Invoice details. |
|
63 | + add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Details::output', 'wpi_invoice', 'side', 'default' ); |
|
64 | 64 | |
65 | - // Payment details. |
|
66 | - if ( ! $invoice->is_draft() ) { |
|
67 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', 'wpi_invoice', 'side', 'default' ); |
|
68 | - } |
|
65 | + // Payment details. |
|
66 | + if ( ! $invoice->is_draft() ) { |
|
67 | + add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', 'wpi_invoice', 'side', 'default' ); |
|
68 | + } |
|
69 | 69 | |
70 | - // Billing details. |
|
71 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', 'wpi_invoice', 'normal', 'high' ); |
|
70 | + // Billing details. |
|
71 | + add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', 'wpi_invoice', 'normal', 'high' ); |
|
72 | 72 | |
73 | - // Invoice items. |
|
74 | - add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Items::output', 'wpi_invoice', 'normal', 'high' ); |
|
73 | + // Invoice items. |
|
74 | + add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Items::output', 'wpi_invoice', 'normal', 'high' ); |
|
75 | 75 | |
76 | - // Invoice notes. |
|
77 | - add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'side', 'low' ); |
|
76 | + // Invoice notes. |
|
77 | + add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'side', 'low' ); |
|
78 | 78 | |
79 | - // Payment form information. |
|
80 | - if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) { |
|
81 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high' ); |
|
82 | - } |
|
83 | - } |
|
79 | + // Payment form information. |
|
80 | + if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) { |
|
81 | + add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high' ); |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | - // For payment forms. |
|
86 | - if ( $post_type == 'wpi_payment_form' ) { |
|
85 | + // For payment forms. |
|
86 | + if ( $post_type == 'wpi_payment_form' ) { |
|
87 | 87 | |
88 | - // Design payment form. |
|
89 | - add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
88 | + // Design payment form. |
|
89 | + add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
90 | 90 | |
91 | - // Payment form information. |
|
92 | - add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
91 | + // Payment form information. |
|
92 | + add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
93 | 93 | |
94 | - } |
|
94 | + } |
|
95 | 95 | |
96 | - // For invoice items. |
|
97 | - if ( $post_type == 'wpi_item' ) { |
|
96 | + // For invoice items. |
|
97 | + if ( $post_type == 'wpi_item' ) { |
|
98 | 98 | |
99 | - // Item details. |
|
100 | - add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
99 | + // Item details. |
|
100 | + add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
101 | 101 | |
102 | - // If taxes are enabled, register the tax metabox. |
|
103 | - if ( $wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes() ) { |
|
104 | - add_meta_box( 'wpinv_item_vat', __( 'VAT / Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
105 | - } |
|
102 | + // If taxes are enabled, register the tax metabox. |
|
103 | + if ( $wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes() ) { |
|
104 | + add_meta_box( 'wpinv_item_vat', __( 'VAT / Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
105 | + } |
|
106 | 106 | |
107 | - // Item info. |
|
108 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
107 | + // Item info. |
|
108 | + add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
109 | 109 | |
110 | - } |
|
110 | + } |
|
111 | 111 | |
112 | - // For invoice discounts. |
|
113 | - if ( $post_type == 'wpi_discount' ) { |
|
114 | - add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
115 | - } |
|
112 | + // For invoice discounts. |
|
113 | + if ( $post_type == 'wpi_discount' ) { |
|
114 | + add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
115 | + } |
|
116 | 116 | |
117 | 117 | |
118 | - } |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Remove some metaboxes. |
|
122 | - */ |
|
123 | - public static function remove_meta_boxes() { |
|
124 | - remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
125 | - } |
|
120 | + /** |
|
121 | + * Remove some metaboxes. |
|
122 | + */ |
|
123 | + public static function remove_meta_boxes() { |
|
124 | + remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * Rename other metaboxes. |
|
129 | - */ |
|
130 | - public static function rename_meta_boxes() { |
|
127 | + /** |
|
128 | + * Rename other metaboxes. |
|
129 | + */ |
|
130 | + public static function rename_meta_boxes() { |
|
131 | 131 | |
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Check if we're saving, then trigger an action based on the post type. |
|
136 | - * |
|
137 | - * @param int $post_id Post ID. |
|
138 | - * @param object $post Post object. |
|
139 | - */ |
|
140 | - public static function save_meta_boxes( $post_id, $post ) { |
|
141 | - $post_id = absint( $post_id ); |
|
142 | - $data = wp_unslash( $_POST ); |
|
143 | - |
|
144 | - // Do not save for ajax requests. |
|
145 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
146 | - return; |
|
147 | - } |
|
148 | - |
|
149 | - // $post_id and $post are required |
|
150 | - if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
151 | - return; |
|
152 | - } |
|
153 | - |
|
154 | - // Dont' save meta boxes for revisions or autosaves. |
|
155 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
156 | - return; |
|
157 | - } |
|
158 | - |
|
159 | - // Check the nonce. |
|
160 | - if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
161 | - return; |
|
162 | - } |
|
163 | - |
|
164 | - // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
165 | - if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
166 | - return; |
|
167 | - } |
|
168 | - |
|
169 | - // Check user has permission to edit. |
|
170 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
171 | - return; |
|
172 | - } |
|
173 | - |
|
174 | - // Ensure this is our post type. |
|
175 | - $post_types_map = array( |
|
176 | - 'wpi_invoice' => 'GetPaid_Meta_Box_Invoice_Address', |
|
177 | - 'wpi_quote' => 'GetPaid_Meta_Box_Invoice_Address', |
|
178 | - 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
179 | - 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
180 | - 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
181 | - ); |
|
182 | - |
|
183 | - // Is this our post type? |
|
184 | - if ( empty( $post->post_type ) || ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
185 | - return; |
|
186 | - } |
|
187 | - |
|
188 | - // We need this save event to run once to avoid potential endless loops. |
|
189 | - self::$saved_meta_boxes = true; |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Check if we're saving, then trigger an action based on the post type. |
|
136 | + * |
|
137 | + * @param int $post_id Post ID. |
|
138 | + * @param object $post Post object. |
|
139 | + */ |
|
140 | + public static function save_meta_boxes( $post_id, $post ) { |
|
141 | + $post_id = absint( $post_id ); |
|
142 | + $data = wp_unslash( $_POST ); |
|
143 | + |
|
144 | + // Do not save for ajax requests. |
|
145 | + if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
146 | + return; |
|
147 | + } |
|
148 | + |
|
149 | + // $post_id and $post are required |
|
150 | + if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
151 | + return; |
|
152 | + } |
|
153 | + |
|
154 | + // Dont' save meta boxes for revisions or autosaves. |
|
155 | + if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
156 | + return; |
|
157 | + } |
|
158 | + |
|
159 | + // Check the nonce. |
|
160 | + if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
161 | + return; |
|
162 | + } |
|
163 | + |
|
164 | + // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
165 | + if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
166 | + return; |
|
167 | + } |
|
168 | + |
|
169 | + // Check user has permission to edit. |
|
170 | + if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
171 | + return; |
|
172 | + } |
|
173 | + |
|
174 | + // Ensure this is our post type. |
|
175 | + $post_types_map = array( |
|
176 | + 'wpi_invoice' => 'GetPaid_Meta_Box_Invoice_Address', |
|
177 | + 'wpi_quote' => 'GetPaid_Meta_Box_Invoice_Address', |
|
178 | + 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
179 | + 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
180 | + 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
181 | + ); |
|
182 | + |
|
183 | + // Is this our post type? |
|
184 | + if ( empty( $post->post_type ) || ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
185 | + return; |
|
186 | + } |
|
187 | + |
|
188 | + // We need this save event to run once to avoid potential endless loops. |
|
189 | + self::$saved_meta_boxes = true; |
|
190 | 190 | |
191 | - // Save the post. |
|
192 | - $class = $post_types_map[ $post->post_type ]; |
|
193 | - $class::save( $post_id, $_POST, $post ); |
|
191 | + // Save the post. |
|
192 | + $class = $post_types_map[ $post->post_type ]; |
|
193 | + $class::save( $post_id, $_POST, $post ); |
|
194 | 194 | |
195 | - } |
|
195 | + } |
|
196 | 196 | |
197 | 197 | } |
@@ -17,28 +17,28 @@ discard block |
||
17 | 17 | */ |
18 | 18 | function getpaid_get_subscriptions( $args = array(), $return = 'results' ) { |
19 | 19 | |
20 | - // Do not retrieve all fields if we just want the count. |
|
21 | - if ( 'count' == $return ) { |
|
22 | - $args['fields'] = 'id'; |
|
23 | - $args['number'] = 1; |
|
24 | - } |
|
20 | + // Do not retrieve all fields if we just want the count. |
|
21 | + if ( 'count' == $return ) { |
|
22 | + $args['fields'] = 'id'; |
|
23 | + $args['number'] = 1; |
|
24 | + } |
|
25 | 25 | |
26 | - // Do not count all matches if we just want the results. |
|
27 | - if ( 'results' == $return ) { |
|
28 | - $args['count_total'] = false; |
|
29 | - } |
|
26 | + // Do not count all matches if we just want the results. |
|
27 | + if ( 'results' == $return ) { |
|
28 | + $args['count_total'] = false; |
|
29 | + } |
|
30 | 30 | |
31 | - $query = new GetPaid_Subscriptions_Query( $args ); |
|
31 | + $query = new GetPaid_Subscriptions_Query( $args ); |
|
32 | 32 | |
33 | - if ( 'results' == $return ) { |
|
34 | - return $query->get_results(); |
|
35 | - } |
|
33 | + if ( 'results' == $return ) { |
|
34 | + return $query->get_results(); |
|
35 | + } |
|
36 | 36 | |
37 | - if ( 'count' == $return ) { |
|
38 | - return $query->get_total(); |
|
39 | - } |
|
37 | + if ( 'count' == $return ) { |
|
38 | + return $query->get_total(); |
|
39 | + } |
|
40 | 40 | |
41 | - return $query; |
|
41 | + return $query; |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -48,18 +48,18 @@ discard block |
||
48 | 48 | */ |
49 | 49 | function getpaid_get_subscription_statuses() { |
50 | 50 | |
51 | - return apply_filters( |
|
52 | - 'getpaid_get_subscription_statuses', |
|
53 | - array( |
|
54 | - 'pending' => __( 'Pending', 'invoicing' ), |
|
55 | - 'trialling' => __( 'Trialing', 'invoicing' ), |
|
56 | - 'active' => __( 'Active', 'invoicing' ), |
|
57 | - 'failing' => __( 'Failing', 'invoicing' ), |
|
58 | - 'expired' => __( 'Expired', 'invoicing' ), |
|
59 | - 'completed' => __( 'Complete', 'invoicing' ), |
|
60 | - 'cancelled' => __( 'Cancelled', 'invoicing' ), |
|
61 | - ) |
|
62 | - ); |
|
51 | + return apply_filters( |
|
52 | + 'getpaid_get_subscription_statuses', |
|
53 | + array( |
|
54 | + 'pending' => __( 'Pending', 'invoicing' ), |
|
55 | + 'trialling' => __( 'Trialing', 'invoicing' ), |
|
56 | + 'active' => __( 'Active', 'invoicing' ), |
|
57 | + 'failing' => __( 'Failing', 'invoicing' ), |
|
58 | + 'expired' => __( 'Expired', 'invoicing' ), |
|
59 | + 'completed' => __( 'Complete', 'invoicing' ), |
|
60 | + 'cancelled' => __( 'Cancelled', 'invoicing' ), |
|
61 | + ) |
|
62 | + ); |
|
63 | 63 | |
64 | 64 | } |
65 | 65 | |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | * @return string |
70 | 70 | */ |
71 | 71 | function getpaid_get_subscription_status_label( $status ) { |
72 | - $statuses = getpaid_get_subscription_statuses(); |
|
73 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) ); |
|
72 | + $statuses = getpaid_get_subscription_statuses(); |
|
73 | + return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) ); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -80,18 +80,18 @@ discard block |
||
80 | 80 | */ |
81 | 81 | function getpaid_get_subscription_status_classes() { |
82 | 82 | |
83 | - return apply_filters( |
|
84 | - 'getpaid_get_subscription_status_classes', |
|
85 | - array( |
|
86 | - 'pending' => 'getpaid-item-status-pending', |
|
87 | - 'trialling' => 'getpaid-item-status-trial', |
|
88 | - 'active' => 'getpaid-item-status-info', |
|
89 | - 'failing' => 'getpaid-item-status-failing', |
|
90 | - 'expired' => 'getpaid-item-status-expired', |
|
91 | - 'completed' => 'getpaid-item-status-success', |
|
92 | - 'cancelled' => 'getpaid-item-status-canceled', |
|
93 | - ) |
|
94 | - ); |
|
83 | + return apply_filters( |
|
84 | + 'getpaid_get_subscription_status_classes', |
|
85 | + array( |
|
86 | + 'pending' => 'getpaid-item-status-pending', |
|
87 | + 'trialling' => 'getpaid-item-status-trial', |
|
88 | + 'active' => 'getpaid-item-status-info', |
|
89 | + 'failing' => 'getpaid-item-status-failing', |
|
90 | + 'expired' => 'getpaid-item-status-expired', |
|
91 | + 'completed' => 'getpaid-item-status-success', |
|
92 | + 'cancelled' => 'getpaid-item-status-canceled', |
|
93 | + ) |
|
94 | + ); |
|
95 | 95 | |
96 | 96 | } |
97 | 97 | |
@@ -102,15 +102,15 @@ discard block |
||
102 | 102 | */ |
103 | 103 | function getpaid_get_subscription_status_counts( $args = array() ) { |
104 | 104 | |
105 | - $statuses = array_keys( getpaid_get_subscription_statuses() ); |
|
106 | - $counts = array(); |
|
105 | + $statuses = array_keys( getpaid_get_subscription_statuses() ); |
|
106 | + $counts = array(); |
|
107 | 107 | |
108 | - foreach ( $statuses as $status ) { |
|
109 | - $_args = wp_parse_args( "status=$status", $args ); |
|
110 | - $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' ); |
|
111 | - } |
|
108 | + foreach ( $statuses as $status ) { |
|
109 | + $_args = wp_parse_args( "status=$status", $args ); |
|
110 | + $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' ); |
|
111 | + } |
|
112 | 112 | |
113 | - return $counts; |
|
113 | + return $counts; |
|
114 | 114 | |
115 | 115 | } |
116 | 116 | |
@@ -121,32 +121,32 @@ discard block |
||
121 | 121 | */ |
122 | 122 | function getpaid_get_subscription_periods() { |
123 | 123 | |
124 | - return apply_filters( |
|
125 | - 'getpaid_get_subscription_periods', |
|
126 | - array( |
|
124 | + return apply_filters( |
|
125 | + 'getpaid_get_subscription_periods', |
|
126 | + array( |
|
127 | 127 | |
128 | - 'day' => array( |
|
129 | - 'singular' => __( '%s day', 'invoicing' ), |
|
130 | - 'plural' => __( '%d days', 'invoicing' ), |
|
131 | - ), |
|
128 | + 'day' => array( |
|
129 | + 'singular' => __( '%s day', 'invoicing' ), |
|
130 | + 'plural' => __( '%d days', 'invoicing' ), |
|
131 | + ), |
|
132 | 132 | |
133 | - 'week' => array( |
|
134 | - 'singular' => __( '%s week', 'invoicing' ), |
|
135 | - 'plural' => __( '%d weeks', 'invoicing' ), |
|
136 | - ), |
|
133 | + 'week' => array( |
|
134 | + 'singular' => __( '%s week', 'invoicing' ), |
|
135 | + 'plural' => __( '%d weeks', 'invoicing' ), |
|
136 | + ), |
|
137 | 137 | |
138 | - 'month' => array( |
|
139 | - 'singular' => __( '%s month', 'invoicing' ), |
|
140 | - 'plural' => __( '%d months', 'invoicing' ), |
|
141 | - ), |
|
138 | + 'month' => array( |
|
139 | + 'singular' => __( '%s month', 'invoicing' ), |
|
140 | + 'plural' => __( '%d months', 'invoicing' ), |
|
141 | + ), |
|
142 | 142 | |
143 | - 'year' => array( |
|
144 | - 'singular' => __( '%s year', 'invoicing' ), |
|
145 | - 'plural' => __( '%d years', 'invoicing' ), |
|
146 | - ), |
|
143 | + 'year' => array( |
|
144 | + 'singular' => __( '%s year', 'invoicing' ), |
|
145 | + 'plural' => __( '%d years', 'invoicing' ), |
|
146 | + ), |
|
147 | 147 | |
148 | - ) |
|
149 | - ); |
|
148 | + ) |
|
149 | + ); |
|
150 | 150 | |
151 | 151 | } |
152 | 152 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * @return int |
158 | 158 | */ |
159 | 159 | function getpaid_get_subscription_trial_period_interval( $trial_period ) { |
160 | - return (int) preg_replace( '/[^0-9]/', '', $trial_period ); |
|
160 | + return (int) preg_replace( '/[^0-9]/', '', $trial_period ); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | * @return string |
168 | 168 | */ |
169 | 169 | function getpaid_get_subscription_trial_period_period( $trial_period ) { |
170 | - return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) ); |
|
170 | + return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) ); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
@@ -178,8 +178,8 @@ discard block |
||
178 | 178 | * @return string |
179 | 179 | */ |
180 | 180 | function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) { |
181 | - $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label( $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix ); |
|
182 | - return strtolower( sanitize_text_field( $label ) ); |
|
181 | + $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label( $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix ); |
|
182 | + return strtolower( sanitize_text_field( $label ) ); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -190,22 +190,22 @@ discard block |
||
190 | 190 | */ |
191 | 191 | function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) { |
192 | 192 | |
193 | - $periods = getpaid_get_subscription_periods(); |
|
194 | - $period = strtolower( $period ); |
|
193 | + $periods = getpaid_get_subscription_periods(); |
|
194 | + $period = strtolower( $period ); |
|
195 | 195 | |
196 | - if ( isset( $periods[ $period ] ) ) { |
|
197 | - return sprintf( $periods[ $period ]['singular'], $singular_prefix ); |
|
198 | - } |
|
196 | + if ( isset( $periods[ $period ] ) ) { |
|
197 | + return sprintf( $periods[ $period ]['singular'], $singular_prefix ); |
|
198 | + } |
|
199 | 199 | |
200 | - // Backwards compatibility. |
|
201 | - foreach ( $periods as $key => $data ) { |
|
202 | - if ( strpos( $key, $period ) === 0 ) { |
|
203 | - return sprintf( $data['singular'], $singular_prefix ); |
|
204 | - } |
|
205 | - } |
|
200 | + // Backwards compatibility. |
|
201 | + foreach ( $periods as $key => $data ) { |
|
202 | + if ( strpos( $key, $period ) === 0 ) { |
|
203 | + return sprintf( $data['singular'], $singular_prefix ); |
|
204 | + } |
|
205 | + } |
|
206 | 206 | |
207 | - // Invalid string. |
|
208 | - return ''; |
|
207 | + // Invalid string. |
|
208 | + return ''; |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
@@ -217,22 +217,22 @@ discard block |
||
217 | 217 | */ |
218 | 218 | function getpaid_get_plural_subscription_period_label( $period, $interval ) { |
219 | 219 | |
220 | - $periods = getpaid_get_subscription_periods(); |
|
221 | - $period = strtolower( $period ); |
|
220 | + $periods = getpaid_get_subscription_periods(); |
|
221 | + $period = strtolower( $period ); |
|
222 | 222 | |
223 | - if ( isset( $periods[ $period ] ) ) { |
|
224 | - return sprintf( $periods[ $period ]['plural'], $interval ); |
|
225 | - } |
|
223 | + if ( isset( $periods[ $period ] ) ) { |
|
224 | + return sprintf( $periods[ $period ]['plural'], $interval ); |
|
225 | + } |
|
226 | 226 | |
227 | - // Backwards compatibility. |
|
228 | - foreach ( $periods as $key => $data ) { |
|
229 | - if ( strpos( $key, $period ) === 0 ) { |
|
230 | - return sprintf( $data['plural'], $interval ); |
|
231 | - } |
|
232 | - } |
|
227 | + // Backwards compatibility. |
|
228 | + foreach ( $periods as $key => $data ) { |
|
229 | + if ( strpos( $key, $period ) === 0 ) { |
|
230 | + return sprintf( $data['plural'], $interval ); |
|
231 | + } |
|
232 | + } |
|
233 | 233 | |
234 | - // Invalid string. |
|
235 | - return ''; |
|
234 | + // Invalid string. |
|
235 | + return ''; |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
@@ -243,50 +243,50 @@ discard block |
||
243 | 243 | */ |
244 | 244 | function getpaid_get_formatted_subscription_amount( $subscription ) { |
245 | 245 | |
246 | - $initial = wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
247 | - $recurring = wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
248 | - $period = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
246 | + $initial = wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
247 | + $recurring = wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
248 | + $period = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
249 | 249 | |
250 | - // Trial periods. |
|
251 | - if ( $subscription->has_trial_period() ) { |
|
250 | + // Trial periods. |
|
251 | + if ( $subscription->has_trial_period() ) { |
|
252 | 252 | |
253 | - $trial_period = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() ); |
|
254 | - $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() ); |
|
255 | - return sprintf( |
|
253 | + $trial_period = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() ); |
|
254 | + $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() ); |
|
255 | + return sprintf( |
|
256 | 256 | |
257 | - // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
|
258 | - _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
259 | - $initial, |
|
260 | - getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
261 | - $recurring, |
|
262 | - $period |
|
257 | + // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
|
258 | + _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
259 | + $initial, |
|
260 | + getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
261 | + $recurring, |
|
262 | + $period |
|
263 | 263 | |
264 | - ); |
|
264 | + ); |
|
265 | 265 | |
266 | - } |
|
266 | + } |
|
267 | 267 | |
268 | - if ( $initial != $recurring ) { |
|
268 | + if ( $initial != $recurring ) { |
|
269 | 269 | |
270 | - return sprintf( |
|
270 | + return sprintf( |
|
271 | 271 | |
272 | - // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period |
|
273 | - _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ), |
|
274 | - $initial, |
|
275 | - $recurring, |
|
276 | - $period |
|
272 | + // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period |
|
273 | + _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ), |
|
274 | + $initial, |
|
275 | + $recurring, |
|
276 | + $period |
|
277 | 277 | |
278 | - ); |
|
278 | + ); |
|
279 | 279 | |
280 | - } |
|
280 | + } |
|
281 | 281 | |
282 | - return sprintf( |
|
282 | + return sprintf( |
|
283 | 283 | |
284 | - // translators: $1: is the recurring amount, $2: is the recurring period |
|
285 | - _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
286 | - $initial, |
|
287 | - $period |
|
284 | + // translators: $1: is the recurring amount, $2: is the recurring period |
|
285 | + _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
286 | + $initial, |
|
287 | + $period |
|
288 | 288 | |
289 | - ); |
|
289 | + ); |
|
290 | 290 | |
291 | 291 | } |
292 | 292 | |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | * @return WPInv_Subscription|bool |
298 | 298 | */ |
299 | 299 | function getpaid_get_invoice_subscription( $invoice ) { |
300 | - return getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
300 | + return getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | /** |
@@ -306,10 +306,10 @@ discard block |
||
306 | 306 | * @param WPInv_Invoice $invoice |
307 | 307 | */ |
308 | 308 | function getpaid_activate_invoice_subscription( $invoice ) { |
309 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
310 | - if ( is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
311 | - $subscription->activate(); |
|
312 | - } |
|
309 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
310 | + if ( is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
311 | + $subscription->activate(); |
|
312 | + } |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | /** |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | * @return WPInv_Subscriptions |
319 | 319 | */ |
320 | 320 | function getpaid_subscriptions() { |
321 | - return getpaid()->get( 'subscriptions' ); |
|
321 | + return getpaid()->get( 'subscriptions' ); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | /** |
@@ -336,14 +336,14 @@ discard block |
||
336 | 336 | return false; |
337 | 337 | } |
338 | 338 | |
339 | - // Fetch the invoiec subscription. |
|
340 | - $subscription = getpaid_get_subscriptions( |
|
341 | - array( |
|
342 | - 'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(), |
|
343 | - 'number' => 1, |
|
344 | - ) |
|
345 | - ); |
|
339 | + // Fetch the invoiec subscription. |
|
340 | + $subscription = getpaid_get_subscriptions( |
|
341 | + array( |
|
342 | + 'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(), |
|
343 | + 'number' => 1, |
|
344 | + ) |
|
345 | + ); |
|
346 | 346 | |
347 | - return empty( $subscription ) ? false : $subscription[0]; |
|
347 | + return empty( $subscription ) ? false : $subscription[0]; |
|
348 | 348 | |
349 | 349 | } |
@@ -13,30 +13,30 @@ discard block |
||
13 | 13 | class GetPaid_Manual_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'manual'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
34 | - public $order = 11; |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | + public $order = 11; |
|
35 | 35 | |
36 | 36 | /** |
37 | - * Class constructor. |
|
38 | - */ |
|
39 | - public function __construct() { |
|
37 | + * Class constructor. |
|
38 | + */ |
|
39 | + public function __construct() { |
|
40 | 40 | parent::__construct(); |
41 | 41 | |
42 | 42 | $this->title = __( 'Manual Payment', 'invoicing' ); |
@@ -46,15 +46,15 @@ discard block |
||
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
49 | - * Process Payment. |
|
50 | - * |
|
51 | - * |
|
52 | - * @param WPInv_Invoice $invoice Invoice. |
|
53 | - * @param array $submission_data Posted checkout fields. |
|
54 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
55 | - * @return array |
|
56 | - */ |
|
57 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
49 | + * Process Payment. |
|
50 | + * |
|
51 | + * |
|
52 | + * @param WPInv_Invoice $invoice Invoice. |
|
53 | + * @param array $submission_data Posted checkout fields. |
|
54 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
55 | + * @return array |
|
56 | + */ |
|
57 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
58 | 58 | |
59 | 59 | // Mark it as paid. |
60 | 60 | $invoice->mark_paid(); |
@@ -68,13 +68,13 @@ discard block |
||
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
71 | - * (Maybe) renews a manual subscription profile. |
|
72 | - * |
|
73 | - * |
|
74 | - * @param bool $should_expire |
|
71 | + * (Maybe) renews a manual subscription profile. |
|
72 | + * |
|
73 | + * |
|
74 | + * @param bool $should_expire |
|
75 | 75 | * @param WPInv_Subscription $subscription |
76 | - */ |
|
77 | - public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
76 | + */ |
|
77 | + public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
78 | 78 | |
79 | 79 | // Ensure its our subscription && it's active. |
80 | 80 | if ( 'manual' != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) { |
@@ -13,36 +13,36 @@ discard block |
||
13 | 13 | class GetPaid_Notification_Email { |
14 | 14 | |
15 | 15 | /** |
16 | - * Contains the type of this notification email. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Contains the type of this notification email. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id; |
21 | 21 | |
22 | 22 | /** |
23 | - * Contains any object to use in filters. |
|
24 | - * |
|
25 | - * @var false|WPInv_Invoice|WPInv_Item|WPInv_Subscription |
|
26 | - */ |
|
23 | + * Contains any object to use in filters. |
|
24 | + * |
|
25 | + * @var false|WPInv_Invoice|WPInv_Item|WPInv_Subscription |
|
26 | + */ |
|
27 | 27 | public $object; |
28 | 28 | |
29 | 29 | /** |
30 | - * Class constructor. |
|
31 | - * |
|
30 | + * Class constructor. |
|
31 | + * |
|
32 | 32 | * @param string $id Email Type. |
33 | 33 | * @param mixed $object Optional. Associated object. |
34 | - */ |
|
35 | - public function __construct( $id, $object = false ) { |
|
34 | + */ |
|
35 | + public function __construct( $id, $object = false ) { |
|
36 | 36 | $this->id = $id; |
37 | 37 | $this->object = $object; |
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
41 | - * Retrieves an option |
|
42 | - * |
|
41 | + * Retrieves an option |
|
42 | + * |
|
43 | 43 | * @return mixed |
44 | - */ |
|
45 | - public function get_option( $key ) { |
|
44 | + */ |
|
45 | + public function get_option( $key ) { |
|
46 | 46 | |
47 | 47 | $key = "email_{$this->id}_$key"; |
48 | 48 | $value = wpinv_get_option( $key, null ); |
@@ -60,80 +60,80 @@ discard block |
||
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
63 | - * Retrieves the email body. |
|
64 | - * |
|
63 | + * Retrieves the email body. |
|
64 | + * |
|
65 | 65 | * @return string |
66 | - */ |
|
67 | - public function get_body() { |
|
66 | + */ |
|
67 | + public function get_body() { |
|
68 | 68 | $body = $this->get_option( 'body' ); |
69 | 69 | return apply_filters( 'getpaid_get_email_body', $body, $this->id, $this->object ); |
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
73 | - * Retrieves the email subject. |
|
74 | - * |
|
73 | + * Retrieves the email subject. |
|
74 | + * |
|
75 | 75 | * @return string |
76 | - */ |
|
77 | - public function get_subject() { |
|
76 | + */ |
|
77 | + public function get_subject() { |
|
78 | 78 | $subject = $this->get_option( 'subject' ); |
79 | 79 | return apply_filters( 'getpaid_get_email_subject', $subject, $this->id, $this->object ); |
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
83 | - * Retrieves the email heading. |
|
84 | - * |
|
83 | + * Retrieves the email heading. |
|
84 | + * |
|
85 | 85 | * @return string |
86 | - */ |
|
87 | - public function get_heading() { |
|
86 | + */ |
|
87 | + public function get_heading() { |
|
88 | 88 | $heading = $this->get_option( 'heading' ); |
89 | 89 | return apply_filters( 'getpaid_get_email_heading', $heading, $this->id, $this->object ); |
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
93 | - * Checks if an email is active. |
|
94 | - * |
|
93 | + * Checks if an email is active. |
|
94 | + * |
|
95 | 95 | * @return bool |
96 | - */ |
|
97 | - public function is_active() { |
|
96 | + */ |
|
97 | + public function is_active() { |
|
98 | 98 | $is_active = ! empty( $this->get_option( 'active' ) ); |
99 | 99 | return apply_filters( 'getpaid_email_type_is_active', $is_active, $this->id, $this->object ); |
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
103 | - * Checks if the site's admin should receive email notifications. |
|
104 | - * |
|
103 | + * Checks if the site's admin should receive email notifications. |
|
104 | + * |
|
105 | 105 | * @return bool |
106 | - */ |
|
107 | - public function include_admin_bcc() { |
|
106 | + */ |
|
107 | + public function include_admin_bcc() { |
|
108 | 108 | $include_admin_bcc = ! empty( $this->get_option( 'admin_bcc' ) ); |
109 | 109 | return apply_filters( 'getpaid_email_type_include_admin_bcc', $include_admin_bcc, $this->id, $this->object ); |
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
113 | - * Checks whether this email should be sent to the customer or admin. |
|
114 | - * |
|
113 | + * Checks whether this email should be sent to the customer or admin. |
|
114 | + * |
|
115 | 115 | * @return bool |
116 | - */ |
|
117 | - public function is_admin_email() { |
|
116 | + */ |
|
117 | + public function is_admin_email() { |
|
118 | 118 | $is_admin_email = in_array( $this->id, array( 'new_invoice', 'cancelled_invoice', 'failed_invoice' ) ); |
119 | 119 | return apply_filters( 'getpaid_email_type_is_admin_email', $is_admin_email, $this->id, $this->object ); |
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
123 | - * Returns email attachments. |
|
124 | - * |
|
123 | + * Returns email attachments. |
|
124 | + * |
|
125 | 125 | * @return array |
126 | - */ |
|
127 | - public function get_attachments() { |
|
126 | + */ |
|
127 | + public function get_attachments() { |
|
128 | 128 | return apply_filters( 'getpaid_get_email_attachments', array(), $this->id, $this->object ); |
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
132 | - * Returns an array of merge tags. |
|
133 | - * |
|
132 | + * Returns an array of merge tags. |
|
133 | + * |
|
134 | 134 | * @return array |
135 | - */ |
|
136 | - public function get_merge_tags() { |
|
135 | + */ |
|
136 | + public function get_merge_tags() { |
|
137 | 137 | |
138 | 138 | $merge_tags = array( |
139 | 139 | '{site_title}' => wpinv_get_blogname(), |
@@ -144,13 +144,13 @@ discard block |
||
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
147 | - * Adds merge tags to a text. |
|
148 | - * |
|
147 | + * Adds merge tags to a text. |
|
148 | + * |
|
149 | 149 | * @param string string $text |
150 | 150 | * @param array $merge_tags |
151 | 151 | * @return string |
152 | - */ |
|
153 | - public function add_merge_tags( $text, $merge_tags = array() ) { |
|
152 | + */ |
|
153 | + public function add_merge_tags( $text, $merge_tags = array() ) { |
|
154 | 154 | |
155 | 155 | foreach ( $merge_tags as $key => $value ) { |
156 | 156 | $text = str_replace( $key, $value, $text ); |
@@ -160,13 +160,13 @@ discard block |
||
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
163 | - * Returns the email content |
|
164 | - * |
|
163 | + * Returns the email content |
|
164 | + * |
|
165 | 165 | * @param array $merge_tags |
166 | 166 | * @param array $extra_args Extra template args |
167 | 167 | * @return string |
168 | - */ |
|
169 | - public function get_content( $merge_tags = array(), $extra_args = array() ) { |
|
168 | + */ |
|
169 | + public function get_content( $merge_tags = array(), $extra_args = array() ) { |
|
170 | 170 | |
171 | 171 | $content = wpinv_get_template_html( |
172 | 172 | "emails/wpinv-email-{$this->id}.php", |
@@ -13,282 +13,282 @@ |
||
13 | 13 | class GetPaid_Subscription_Notification_Emails { |
14 | 14 | |
15 | 15 | /** |
16 | - * The array of subscription email actions. |
|
17 | - * |
|
18 | - * @param array |
|
19 | - */ |
|
20 | - public $subscription_actions; |
|
16 | + * The array of subscription email actions. |
|
17 | + * |
|
18 | + * @param array |
|
19 | + */ |
|
20 | + public $subscription_actions; |
|
21 | 21 | |
22 | 22 | /** |
23 | - * Class constructor |
|
23 | + * Class constructor |
|
24 | 24 | * |
25 | - */ |
|
26 | - public function __construct() { |
|
27 | - |
|
28 | - $this->subscription_actions = apply_filters( |
|
29 | - 'getpaid_notification_email_subscription_triggers', |
|
30 | - array( |
|
31 | - 'getpaid_subscription_trialling' => 'subscription_trial', |
|
32 | - 'getpaid_subscription_cancelled' => 'subscription_cancelled', |
|
33 | - 'getpaid_subscription_expired' => 'subscription_expired', |
|
34 | - 'getpaid_subscription_completed' => 'subscription_complete', |
|
35 | - 'getpaid_daily_maintenance' => 'renewal_reminder', |
|
36 | - ) |
|
37 | - ); |
|
38 | - |
|
39 | - $this->init_hooks(); |
|
25 | + */ |
|
26 | + public function __construct() { |
|
27 | + |
|
28 | + $this->subscription_actions = apply_filters( |
|
29 | + 'getpaid_notification_email_subscription_triggers', |
|
30 | + array( |
|
31 | + 'getpaid_subscription_trialling' => 'subscription_trial', |
|
32 | + 'getpaid_subscription_cancelled' => 'subscription_cancelled', |
|
33 | + 'getpaid_subscription_expired' => 'subscription_expired', |
|
34 | + 'getpaid_subscription_completed' => 'subscription_complete', |
|
35 | + 'getpaid_daily_maintenance' => 'renewal_reminder', |
|
36 | + ) |
|
37 | + ); |
|
38 | + |
|
39 | + $this->init_hooks(); |
|
40 | 40 | |
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
44 | - * Registers email hooks. |
|
45 | - */ |
|
46 | - public function init_hooks() { |
|
47 | - |
|
48 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
49 | - foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
50 | - |
|
51 | - $email = new GetPaid_Notification_Email( $email_type ); |
|
52 | - |
|
53 | - if ( ! $email->is_active() ) { |
|
54 | - continue; |
|
55 | - } |
|
56 | - |
|
57 | - if ( method_exists( $this, $email_type ) ) { |
|
58 | - add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
59 | - continue; |
|
60 | - } |
|
61 | - |
|
62 | - do_action( 'getpaid_subscription_notification_email_register_hook', $email ); |
|
63 | - |
|
64 | - } |
|
65 | - |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Filters subscription merge tags. |
|
70 | - * |
|
71 | - * @param array $merge_tags |
|
72 | - * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
73 | - */ |
|
74 | - public function subscription_merge_tags( $merge_tags, $object ) { |
|
75 | - |
|
76 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
77 | - $merge_tags = array_merge( |
|
78 | - $merge_tags, |
|
79 | - $this->get_subscription_merge_tags( $object ) |
|
80 | - ); |
|
81 | - } |
|
82 | - |
|
83 | - return $merge_tags; |
|
84 | - |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Generates subscription merge tags. |
|
89 | - * |
|
90 | - * @param WPInv_Subscription $subscription |
|
91 | - * @return array |
|
92 | - */ |
|
93 | - public function get_subscription_merge_tags( $subscription ) { |
|
94 | - |
|
95 | - // Abort if it does not exist. |
|
96 | - if ( ! $subscription->get_id() ) { |
|
97 | - return array(); |
|
98 | - } |
|
99 | - |
|
100 | - $invoice = $subscription->get_parent_invoice(); |
|
101 | - return array( |
|
102 | - '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
103 | - '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
104 | - '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
105 | - '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
106 | - '{subscription_id}' => absint( $subscription->get_id() ), |
|
107 | - '{subscription_recurring_amount}' => wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $invoice->get_currency() ), |
|
108 | - '{subscription_initial_amount}' => wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $invoice->get_currency() ), |
|
109 | - '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
110 | - '{subscription_bill_times}' => $subscription->get_bill_times(), |
|
111 | - '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
112 | - ); |
|
113 | - |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Checks if we should send a notification for a subscription. |
|
118 | - * |
|
119 | - * @param WPInv_Invoice $invoice |
|
120 | - * @return bool |
|
121 | - */ |
|
122 | - public function should_send_notification( $invoice ) { |
|
123 | - return 0 != $invoice->get_id(); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Returns notification recipients. |
|
128 | - * |
|
129 | - * @param WPInv_Invoice $invoice |
|
130 | - * @return array |
|
131 | - */ |
|
132 | - public function get_recipients( $invoice ) { |
|
133 | - $recipients = array( $invoice->get_email() ); |
|
134 | - |
|
135 | - $cc = $invoice->get_email_cc(); |
|
136 | - |
|
137 | - if ( ! empty( $cc ) ) { |
|
138 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
139 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
140 | - } |
|
141 | - |
|
142 | - return $recipients; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Helper function to send an email. |
|
147 | - * |
|
148 | - * @param WPInv_Subscription $subscription |
|
149 | - * @param GetPaid_Notification_Email $email |
|
150 | - * @param string $type |
|
151 | - * @param array $extra_args Extra template args. |
|
152 | - */ |
|
153 | - public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
154 | - |
|
155 | - // Abort in case the parent invoice does not exist. |
|
156 | - $invoice = $subscription->get_parent_invoice(); |
|
157 | - if ( ! $this->should_send_notification( $invoice ) ) { |
|
158 | - return; |
|
159 | - } |
|
160 | - |
|
161 | - do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
162 | - |
|
163 | - $recipients = $this->get_recipients( $invoice ); |
|
164 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
165 | - $merge_tags = $email->get_merge_tags(); |
|
166 | - $content = $email->get_content( $merge_tags, $extra_args ); |
|
167 | - $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
168 | - $attachments = $email->get_attachments(); |
|
169 | - |
|
170 | - $result = $mailer->send( |
|
171 | - apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
172 | - $subject, |
|
173 | - $content, |
|
174 | - $attachments |
|
175 | - ); |
|
176 | - |
|
177 | - // Maybe send a copy to the admin. |
|
178 | - if ( $email->include_admin_bcc() ) { |
|
179 | - $mailer->send( |
|
180 | - wpinv_get_admin_email(), |
|
181 | - $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
182 | - $content, |
|
183 | - $attachments |
|
184 | - ); |
|
185 | - } |
|
186 | - |
|
187 | - if ( ! $result ) { |
|
188 | - $subscription->get_parent_invoice()->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
189 | - } |
|
190 | - |
|
191 | - do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
192 | - |
|
193 | - } |
|
44 | + * Registers email hooks. |
|
45 | + */ |
|
46 | + public function init_hooks() { |
|
47 | + |
|
48 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
49 | + foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
50 | + |
|
51 | + $email = new GetPaid_Notification_Email( $email_type ); |
|
52 | + |
|
53 | + if ( ! $email->is_active() ) { |
|
54 | + continue; |
|
55 | + } |
|
56 | + |
|
57 | + if ( method_exists( $this, $email_type ) ) { |
|
58 | + add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
59 | + continue; |
|
60 | + } |
|
61 | + |
|
62 | + do_action( 'getpaid_subscription_notification_email_register_hook', $email ); |
|
63 | + |
|
64 | + } |
|
65 | + |
|
66 | + } |
|
194 | 67 | |
195 | 68 | /** |
196 | - * Sends a new trial notification. |
|
197 | - * |
|
198 | - * @param WPInv_Subscription $subscription |
|
199 | - */ |
|
200 | - public function subscription_trial( $subscription ) { |
|
69 | + * Filters subscription merge tags. |
|
70 | + * |
|
71 | + * @param array $merge_tags |
|
72 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
73 | + */ |
|
74 | + public function subscription_merge_tags( $merge_tags, $object ) { |
|
201 | 75 | |
202 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
203 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
76 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
77 | + $merge_tags = array_merge( |
|
78 | + $merge_tags, |
|
79 | + $this->get_subscription_merge_tags( $object ) |
|
80 | + ); |
|
81 | + } |
|
204 | 82 | |
205 | - } |
|
83 | + return $merge_tags; |
|
206 | 84 | |
207 | - /** |
|
208 | - * Sends a cancelled subscription notification. |
|
209 | - * |
|
210 | - * @param WPInv_Subscription $subscription |
|
211 | - */ |
|
212 | - public function subscription_cancelled( $subscription ) { |
|
85 | + } |
|
213 | 86 | |
214 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
215 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
87 | + /** |
|
88 | + * Generates subscription merge tags. |
|
89 | + * |
|
90 | + * @param WPInv_Subscription $subscription |
|
91 | + * @return array |
|
92 | + */ |
|
93 | + public function get_subscription_merge_tags( $subscription ) { |
|
94 | + |
|
95 | + // Abort if it does not exist. |
|
96 | + if ( ! $subscription->get_id() ) { |
|
97 | + return array(); |
|
98 | + } |
|
99 | + |
|
100 | + $invoice = $subscription->get_parent_invoice(); |
|
101 | + return array( |
|
102 | + '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
103 | + '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
104 | + '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
105 | + '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
106 | + '{subscription_id}' => absint( $subscription->get_id() ), |
|
107 | + '{subscription_recurring_amount}' => wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $invoice->get_currency() ), |
|
108 | + '{subscription_initial_amount}' => wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $invoice->get_currency() ), |
|
109 | + '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
110 | + '{subscription_bill_times}' => $subscription->get_bill_times(), |
|
111 | + '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
112 | + ); |
|
216 | 113 | |
217 | - } |
|
114 | + } |
|
218 | 115 | |
219 | - /** |
|
220 | - * Sends a subscription expired notification. |
|
221 | - * |
|
222 | - * @param WPInv_Subscription $subscription |
|
223 | - */ |
|
224 | - public function subscription_expired( $subscription ) { |
|
116 | + /** |
|
117 | + * Checks if we should send a notification for a subscription. |
|
118 | + * |
|
119 | + * @param WPInv_Invoice $invoice |
|
120 | + * @return bool |
|
121 | + */ |
|
122 | + public function should_send_notification( $invoice ) { |
|
123 | + return 0 != $invoice->get_id(); |
|
124 | + } |
|
225 | 125 | |
226 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
227 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
126 | + /** |
|
127 | + * Returns notification recipients. |
|
128 | + * |
|
129 | + * @param WPInv_Invoice $invoice |
|
130 | + * @return array |
|
131 | + */ |
|
132 | + public function get_recipients( $invoice ) { |
|
133 | + $recipients = array( $invoice->get_email() ); |
|
228 | 134 | |
229 | - } |
|
135 | + $cc = $invoice->get_email_cc(); |
|
230 | 136 | |
231 | - /** |
|
232 | - * Sends a completed subscription notification. |
|
233 | - * |
|
234 | - * @param WPInv_Subscription $subscription |
|
235 | - */ |
|
236 | - public function subscription_complete( $subscription ) { |
|
137 | + if ( ! empty( $cc ) ) { |
|
138 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
139 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
140 | + } |
|
237 | 141 | |
238 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
239 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
142 | + return $recipients; |
|
143 | + } |
|
240 | 144 | |
241 | - } |
|
145 | + /** |
|
146 | + * Helper function to send an email. |
|
147 | + * |
|
148 | + * @param WPInv_Subscription $subscription |
|
149 | + * @param GetPaid_Notification_Email $email |
|
150 | + * @param string $type |
|
151 | + * @param array $extra_args Extra template args. |
|
152 | + */ |
|
153 | + public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
154 | + |
|
155 | + // Abort in case the parent invoice does not exist. |
|
156 | + $invoice = $subscription->get_parent_invoice(); |
|
157 | + if ( ! $this->should_send_notification( $invoice ) ) { |
|
158 | + return; |
|
159 | + } |
|
160 | + |
|
161 | + do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
162 | + |
|
163 | + $recipients = $this->get_recipients( $invoice ); |
|
164 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
165 | + $merge_tags = $email->get_merge_tags(); |
|
166 | + $content = $email->get_content( $merge_tags, $extra_args ); |
|
167 | + $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
168 | + $attachments = $email->get_attachments(); |
|
169 | + |
|
170 | + $result = $mailer->send( |
|
171 | + apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
172 | + $subject, |
|
173 | + $content, |
|
174 | + $attachments |
|
175 | + ); |
|
176 | + |
|
177 | + // Maybe send a copy to the admin. |
|
178 | + if ( $email->include_admin_bcc() ) { |
|
179 | + $mailer->send( |
|
180 | + wpinv_get_admin_email(), |
|
181 | + $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
182 | + $content, |
|
183 | + $attachments |
|
184 | + ); |
|
185 | + } |
|
186 | + |
|
187 | + if ( ! $result ) { |
|
188 | + $subscription->get_parent_invoice()->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
189 | + } |
|
190 | + |
|
191 | + do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
242 | 192 | |
243 | - /** |
|
244 | - * Sends a subscription renewal reminder notification. |
|
245 | - * |
|
246 | - */ |
|
247 | - public function renewal_reminder() { |
|
193 | + } |
|
248 | 194 | |
249 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
195 | + /** |
|
196 | + * Sends a new trial notification. |
|
197 | + * |
|
198 | + * @param WPInv_Subscription $subscription |
|
199 | + */ |
|
200 | + public function subscription_trial( $subscription ) { |
|
250 | 201 | |
251 | - // Fetch reminder days. |
|
252 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
202 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
203 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
253 | 204 | |
254 | - // Abort if non is set. |
|
255 | - if ( empty( $reminder_days ) ) { |
|
256 | - return; |
|
257 | - } |
|
205 | + } |
|
258 | 206 | |
259 | - // Fetch matching subscriptions. |
|
207 | + /** |
|
208 | + * Sends a cancelled subscription notification. |
|
209 | + * |
|
210 | + * @param WPInv_Subscription $subscription |
|
211 | + */ |
|
212 | + public function subscription_cancelled( $subscription ) { |
|
213 | + |
|
214 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
215 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
216 | + |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Sends a subscription expired notification. |
|
221 | + * |
|
222 | + * @param WPInv_Subscription $subscription |
|
223 | + */ |
|
224 | + public function subscription_expired( $subscription ) { |
|
225 | + |
|
226 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
227 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
228 | + |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * Sends a completed subscription notification. |
|
233 | + * |
|
234 | + * @param WPInv_Subscription $subscription |
|
235 | + */ |
|
236 | + public function subscription_complete( $subscription ) { |
|
237 | + |
|
238 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
239 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
240 | + |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * Sends a subscription renewal reminder notification. |
|
245 | + * |
|
246 | + */ |
|
247 | + public function renewal_reminder() { |
|
248 | + |
|
249 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
250 | + |
|
251 | + // Fetch reminder days. |
|
252 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
253 | + |
|
254 | + // Abort if non is set. |
|
255 | + if ( empty( $reminder_days ) ) { |
|
256 | + return; |
|
257 | + } |
|
258 | + |
|
259 | + // Fetch matching subscriptions. |
|
260 | 260 | $args = array( |
261 | 261 | 'number' => -1, |
262 | - 'count_total' => false, |
|
263 | - 'status' => 'trialling active', |
|
262 | + 'count_total' => false, |
|
263 | + 'status' => 'trialling active', |
|
264 | 264 | 'date_expires_query' => array( |
265 | - 'relation' => 'OR' |
|
265 | + 'relation' => 'OR' |
|
266 | 266 | ), |
267 | - ); |
|
267 | + ); |
|
268 | 268 | |
269 | - foreach ( $reminder_days as $days ) { |
|
270 | - $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
269 | + foreach ( $reminder_days as $days ) { |
|
270 | + $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
271 | 271 | |
272 | - $args['date_expires_query'][] = array( |
|
273 | - 'year' => $date['year'], |
|
274 | - 'month' => $date['month'], |
|
275 | - 'day' => $date['day'], |
|
276 | - ); |
|
272 | + $args['date_expires_query'][] = array( |
|
273 | + 'year' => $date['year'], |
|
274 | + 'month' => $date['month'], |
|
275 | + 'day' => $date['day'], |
|
276 | + ); |
|
277 | 277 | |
278 | - } |
|
278 | + } |
|
279 | 279 | |
280 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
280 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
281 | 281 | |
282 | 282 | foreach ( $subscriptions as $subscription ) { |
283 | 283 | |
284 | - // Skip packages. |
|
285 | - if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) { |
|
286 | - $email->object = $subscription; |
|
287 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
288 | - } |
|
284 | + // Skip packages. |
|
285 | + if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) { |
|
286 | + $email->object = $subscription; |
|
287 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
288 | + } |
|
289 | 289 | |
290 | - } |
|
290 | + } |
|
291 | 291 | |
292 | - } |
|
292 | + } |
|
293 | 293 | |
294 | 294 | } |
@@ -13,38 +13,38 @@ |
||
13 | 13 | |
14 | 14 | foreach ( array_keys( $widget->get_subscriptions_table_columns() ) as $column ) : |
15 | 15 | |
16 | - $class = sanitize_html_class( $column ); |
|
17 | - echo "<td class='getpaid-subscriptions-table-column-$class'>"; |
|
16 | + $class = sanitize_html_class( $column ); |
|
17 | + echo "<td class='getpaid-subscriptions-table-column-$class'>"; |
|
18 | 18 | |
19 | - do_action( "getpaid_subscriptions_before_frontend_subscription_table_$column", $subscription ); |
|
19 | + do_action( "getpaid_subscriptions_before_frontend_subscription_table_$column", $subscription ); |
|
20 | 20 | |
21 | - switch( $column ) : |
|
21 | + switch( $column ) : |
|
22 | 22 | |
23 | - case 'subscription': |
|
24 | - $subscription_id = (int) $subscription->get_id(); |
|
25 | - $url = esc_url( $subscription->get_view_url() ); |
|
26 | - echo $widget->add_row_actions( "<a href='$url' class='text-decoration-none'>#$subscription_id</a>", $subscription ); |
|
27 | - break; |
|
23 | + case 'subscription': |
|
24 | + $subscription_id = (int) $subscription->get_id(); |
|
25 | + $url = esc_url( $subscription->get_view_url() ); |
|
26 | + echo $widget->add_row_actions( "<a href='$url' class='text-decoration-none'>#$subscription_id</a>", $subscription ); |
|
27 | + break; |
|
28 | 28 | |
29 | - case 'status': |
|
30 | - echo $subscription->get_status_label(); |
|
31 | - break; |
|
29 | + case 'status': |
|
30 | + echo $subscription->get_status_label(); |
|
31 | + break; |
|
32 | 32 | |
33 | - case 'renewal-date': |
|
34 | - $renewal = getpaid_format_date_value( $subscription->get_next_renewal_date() ); |
|
35 | - echo $subscription->is_active() ? $renewal : "—"; |
|
36 | - break; |
|
33 | + case 'renewal-date': |
|
34 | + $renewal = getpaid_format_date_value( $subscription->get_next_renewal_date() ); |
|
35 | + echo $subscription->is_active() ? $renewal : "—"; |
|
36 | + break; |
|
37 | 37 | |
38 | - case 'amount': |
|
39 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
40 | - $amount = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_recurring_amount() ) ), $subscription->get_parent_payment()->get_currency() ); |
|
41 | - echo "<strong style='font-weight: 500;'>$amount</strong> / $frequency"; |
|
42 | - break; |
|
38 | + case 'amount': |
|
39 | + $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
40 | + $amount = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_recurring_amount() ) ), $subscription->get_parent_payment()->get_currency() ); |
|
41 | + echo "<strong style='font-weight: 500;'>$amount</strong> / $frequency"; |
|
42 | + break; |
|
43 | 43 | |
44 | - endswitch; |
|
44 | + endswitch; |
|
45 | 45 | |
46 | - do_action( "getpaid_subscriptions_frontend_subscription_table_$column", $subscription ); |
|
46 | + do_action( "getpaid_subscriptions_frontend_subscription_table_$column", $subscription ); |
|
47 | 47 | |
48 | - echo '</td>'; |
|
48 | + echo '</td>'; |
|
49 | 49 | |
50 | 50 | endforeach; |
@@ -15,31 +15,31 @@ discard block |
||
15 | 15 | abstract class GetPaid_Authorize_Net_Legacy_Gateway extends GetPaid_Payment_Gateway { |
16 | 16 | |
17 | 17 | /** |
18 | - * Class constructor. |
|
19 | - */ |
|
20 | - public function __construct() { |
|
18 | + * Class constructor. |
|
19 | + */ |
|
20 | + public function __construct() { |
|
21 | 21 | parent::__construct(); |
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
25 | - * Returns the API URL. |
|
26 | - * |
|
27 | - * |
|
28 | - * @param WPInv_Invoice $invoice Invoice. |
|
29 | - * @return string |
|
30 | - */ |
|
31 | - public function get_api_url( $invoice ) { |
|
25 | + * Returns the API URL. |
|
26 | + * |
|
27 | + * |
|
28 | + * @param WPInv_Invoice $invoice Invoice. |
|
29 | + * @return string |
|
30 | + */ |
|
31 | + public function get_api_url( $invoice ) { |
|
32 | 32 | return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
36 | - * Communicates with authorize.net |
|
37 | - * |
|
38 | - * |
|
39 | - * @param array $post Data to post. |
|
36 | + * Communicates with authorize.net |
|
37 | + * |
|
38 | + * |
|
39 | + * @param array $post Data to post. |
|
40 | 40 | * @param WPInv_Invoice $invoice Invoice. |
41 | - * @return stdClass|WP_Error |
|
42 | - */ |
|
41 | + * @return stdClass|WP_Error |
|
42 | + */ |
|
43 | 43 | public function post( $post, $invoice ){ |
44 | 44 | |
45 | 45 | $url = $this->get_api_url( $invoice ); |
@@ -81,12 +81,12 @@ discard block |
||
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
84 | - * Returns the API authentication params. |
|
85 | - * |
|
86 | - * |
|
87 | - * @return array |
|
88 | - */ |
|
89 | - public function get_auth_params() { |
|
84 | + * Returns the API authentication params. |
|
85 | + * |
|
86 | + * |
|
87 | + * @return array |
|
88 | + */ |
|
89 | + public function get_auth_params() { |
|
90 | 90 | |
91 | 91 | return array( |
92 | 92 | 'name' => $this->get_option( 'login_id' ), |
@@ -96,13 +96,13 @@ discard block |
||
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
99 | - * Cancels a subscription remotely |
|
100 | - * |
|
101 | - * |
|
102 | - * @param WPInv_Subscription $subscription Subscription. |
|
99 | + * Cancels a subscription remotely |
|
100 | + * |
|
101 | + * |
|
102 | + * @param WPInv_Subscription $subscription Subscription. |
|
103 | 103 | * @param WPInv_Invoice $invoice Invoice. |
104 | - */ |
|
105 | - public function cancel_subscription( $subscription, $invoice ) { |
|
104 | + */ |
|
105 | + public function cancel_subscription( $subscription, $invoice ) { |
|
106 | 106 | |
107 | 107 | // Backwards compatibility. New version do not use authorize.net subscriptions. |
108 | 108 | $this->post( |
@@ -118,17 +118,17 @@ discard block |
||
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
121 | - * Processes ipns. |
|
122 | - * |
|
123 | - * @return void |
|
124 | - */ |
|
125 | - public function verify_ipn() { |
|
121 | + * Processes ipns. |
|
122 | + * |
|
123 | + * @return void |
|
124 | + */ |
|
125 | + public function verify_ipn() { |
|
126 | 126 | |
127 | 127 | $this->maybe_process_old_ipn(); |
128 | 128 | |
129 | 129 | // Validate the IPN. |
130 | 130 | if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
131 | - wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 500 ) ); |
|
131 | + wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 500 ) ); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | // Event type. |
@@ -167,24 +167,24 @@ discard block |
||
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
170 | - * Validates IPN invoices. |
|
171 | - * |
|
170 | + * Validates IPN invoices. |
|
171 | + * |
|
172 | 172 | * @param WPInv_Invoice $invoice |
173 | 173 | * @param object $payload |
174 | - * @return void |
|
175 | - */ |
|
176 | - public function validate_ipn_invoice( $invoice, $payload ) { |
|
174 | + * @return void |
|
175 | + */ |
|
176 | + public function validate_ipn_invoice( $invoice, $payload ) { |
|
177 | 177 | if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) { |
178 | 178 | exit; |
179 | 179 | } |
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
183 | - * Process subscriptio IPNS. |
|
184 | - * |
|
185 | - * @return void |
|
186 | - */ |
|
187 | - public function maybe_process_old_ipn() { |
|
183 | + * Process subscriptio IPNS. |
|
184 | + * |
|
185 | + * @return void |
|
186 | + */ |
|
187 | + public function maybe_process_old_ipn() { |
|
188 | 188 | |
189 | 189 | $data = wp_unslash( $_POST ); |
190 | 190 | |
@@ -226,11 +226,11 @@ discard block |
||
226 | 226 | } |
227 | 227 | |
228 | 228 | /** |
229 | - * Validates the old IPN signature. |
|
229 | + * Validates the old IPN signature. |
|
230 | 230 | * |
231 | 231 | * @param array $posted |
232 | - */ |
|
233 | - public function validate_old_ipn_signature( $posted ) { |
|
232 | + */ |
|
233 | + public function validate_old_ipn_signature( $posted ) { |
|
234 | 234 | |
235 | 235 | $signature = $this->get_option( 'signature_key' ); |
236 | 236 | if ( ! empty( $signature ) ) { |
@@ -249,9 +249,9 @@ discard block |
||
249 | 249 | } |
250 | 250 | |
251 | 251 | /** |
252 | - * Check Authorize.NET IPN validity. |
|
253 | - */ |
|
254 | - public function validate_ipn() { |
|
252 | + * Check Authorize.NET IPN validity. |
|
253 | + */ |
|
254 | + public function validate_ipn() { |
|
255 | 255 | |
256 | 256 | wpinv_error_log( 'Validating Authorize.NET IPN response' ); |
257 | 257 |
@@ -13,23 +13,23 @@ discard block |
||
13 | 13 | class GetPaid_Bank_Transfer_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'bank_transfer'; |
21 | 21 | |
22 | 22 | /** |
23 | - * Payment method order. |
|
24 | - * |
|
25 | - * @var int |
|
26 | - */ |
|
27 | - public $order = 8; |
|
23 | + * Payment method order. |
|
24 | + * |
|
25 | + * @var int |
|
26 | + */ |
|
27 | + public $order = 8; |
|
28 | 28 | |
29 | 29 | /** |
30 | - * Class constructor. |
|
31 | - */ |
|
32 | - public function __construct() { |
|
30 | + * Class constructor. |
|
31 | + */ |
|
32 | + public function __construct() { |
|
33 | 33 | parent::__construct(); |
34 | 34 | |
35 | 35 | $this->title = __( 'Direct bank transfer', 'invoicing' ); |
@@ -37,22 +37,22 @@ discard block |
||
37 | 37 | $this->checkout_button_text = __( 'Proceed', 'invoicing' ); |
38 | 38 | $this->instructions = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) ); |
39 | 39 | |
40 | - add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
41 | - add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
42 | - add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
40 | + add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
41 | + add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
42 | + add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
43 | 43 | |
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
47 | - * Process Payment. |
|
48 | - * |
|
49 | - * |
|
50 | - * @param WPInv_Invoice $invoice Invoice. |
|
51 | - * @param array $submission_data Posted checkout fields. |
|
52 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
53 | - * @return array |
|
54 | - */ |
|
55 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
47 | + * Process Payment. |
|
48 | + * |
|
49 | + * |
|
50 | + * @param WPInv_Invoice $invoice Invoice. |
|
51 | + * @param array $submission_data Posted checkout fields. |
|
52 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
53 | + * @return array |
|
54 | + */ |
|
55 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
56 | 56 | |
57 | 57 | // Add a transaction id. |
58 | 58 | $invoice->set_transaction_id( $invoice->generate_key('trans_') ); |
@@ -73,66 +73,66 @@ discard block |
||
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
76 | - * Output for the order received page. |
|
77 | - * |
|
78 | - * @param WPInv_Invoice $invoice Invoice. |
|
79 | - */ |
|
80 | - public function thankyou_page( $invoice ) { |
|
76 | + * Output for the order received page. |
|
77 | + * |
|
78 | + * @param WPInv_Invoice $invoice Invoice. |
|
79 | + */ |
|
80 | + public function thankyou_page( $invoice ) { |
|
81 | 81 | |
82 | 82 | if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
83 | 83 | |
84 | - echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
|
84 | + echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
|
85 | 85 | |
86 | 86 | if ( ! empty( $this->instructions ) ) { |
87 | 87 | echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) ); |
88 | - } |
|
88 | + } |
|
89 | 89 | |
90 | - $this->bank_details( $invoice ); |
|
90 | + $this->bank_details( $invoice ); |
|
91 | 91 | |
92 | - echo '</div>'; |
|
92 | + echo '</div>'; |
|
93 | 93 | |
94 | 94 | } |
95 | 95 | |
96 | - } |
|
96 | + } |
|
97 | 97 | |
98 | 98 | /** |
99 | - * Add content to the WPI emails. |
|
100 | - * |
|
101 | - * @param WPInv_Invoice $invoice Invoice. |
|
102 | - * @param string $email_type Email format: plain text or HTML. |
|
103 | - * @param bool $sent_to_admin Sent to admin. |
|
104 | - */ |
|
105 | - public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
99 | + * Add content to the WPI emails. |
|
100 | + * |
|
101 | + * @param WPInv_Invoice $invoice Invoice. |
|
102 | + * @param string $email_type Email format: plain text or HTML. |
|
103 | + * @param bool $sent_to_admin Sent to admin. |
|
104 | + */ |
|
105 | + public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
106 | 106 | |
107 | - if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
107 | + if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
108 | 108 | |
109 | - echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
|
109 | + echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
|
110 | 110 | |
111 | - if ( $this->instructions ) { |
|
112 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
111 | + if ( $this->instructions ) { |
|
112 | + echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
113 | 113 | } |
114 | 114 | |
115 | - $this->bank_details( $invoice ); |
|
115 | + $this->bank_details( $invoice ); |
|
116 | 116 | |
117 | - echo '</div>'; |
|
117 | + echo '</div>'; |
|
118 | 118 | |
119 | - } |
|
119 | + } |
|
120 | 120 | |
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
124 | - * Get bank details and place into a list format. |
|
125 | - * |
|
126 | - * @param WPInv_Invoice $invoice Invoice. |
|
127 | - */ |
|
128 | - protected function bank_details( $invoice ) { |
|
124 | + * Get bank details and place into a list format. |
|
125 | + * |
|
126 | + * @param WPInv_Invoice $invoice Invoice. |
|
127 | + */ |
|
128 | + protected function bank_details( $invoice ) { |
|
129 | 129 | |
130 | - // Get the invoice country and country $locale. |
|
131 | - $country = $invoice->get_country(); |
|
132 | - $locale = $this->get_country_locale(); |
|
130 | + // Get the invoice country and country $locale. |
|
131 | + $country = $invoice->get_country(); |
|
132 | + $locale = $this->get_country_locale(); |
|
133 | 133 | |
134 | - // Get sortcode label in the $locale array and use appropriate one. |
|
135 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
134 | + // Get sortcode label in the $locale array and use appropriate one. |
|
135 | + $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
136 | 136 | |
137 | 137 | $bank_fields = array( |
138 | 138 | 'ac_name' => __( 'Account Name', 'invoicing' ), |
@@ -161,144 +161,144 @@ discard block |
||
161 | 161 | return; |
162 | 162 | } |
163 | 163 | |
164 | - echo '<h3 class="getpaid-bank-transfer-title"> ' . apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ) ) . '</h3>' . PHP_EOL; |
|
164 | + echo '<h3 class="getpaid-bank-transfer-title"> ' . apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ) ) . '</h3>' . PHP_EOL; |
|
165 | 165 | |
166 | - echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
|
166 | + echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
|
167 | 167 | |
168 | - foreach ( $bank_info as $key => $data ) { |
|
168 | + foreach ( $bank_info as $key => $data ) { |
|
169 | 169 | |
170 | - $key = sanitize_html_class( $key ); |
|
171 | - $label = wp_kses_post( $data['label'] ); |
|
172 | - $value = wp_kses_post( wptexturize( $data['value'] ) ); |
|
170 | + $key = sanitize_html_class( $key ); |
|
171 | + $label = wp_kses_post( $data['label'] ); |
|
172 | + $value = wp_kses_post( wptexturize( $data['value'] ) ); |
|
173 | 173 | |
174 | - echo "<tr class='getpaid-bank-transfer-$key'><th>$label</th><td>$value</td></tr>" . PHP_EOL; |
|
175 | - } |
|
174 | + echo "<tr class='getpaid-bank-transfer-$key'><th>$label</th><td>$value</td></tr>" . PHP_EOL; |
|
175 | + } |
|
176 | 176 | |
177 | - echo '</table>'; |
|
177 | + echo '</table>'; |
|
178 | 178 | |
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
182 | - * Get country locale if localized. |
|
183 | - * |
|
184 | - * @return array |
|
185 | - */ |
|
186 | - public function get_country_locale() { |
|
187 | - |
|
188 | - if ( empty( $this->locale ) ) { |
|
189 | - |
|
190 | - // Locale information to be used - only those that are not 'Sort Code'. |
|
191 | - $this->locale = apply_filters( |
|
192 | - 'getpaid_get_bank_transfer_locale', |
|
193 | - array( |
|
194 | - 'AU' => array( |
|
195 | - 'sortcode' => array( |
|
196 | - 'label' => __( 'BSB', 'invoicing' ), |
|
197 | - ), |
|
198 | - ), |
|
199 | - 'CA' => array( |
|
200 | - 'sortcode' => array( |
|
201 | - 'label' => __( 'Bank transit number', 'invoicing' ), |
|
202 | - ), |
|
203 | - ), |
|
204 | - 'IN' => array( |
|
205 | - 'sortcode' => array( |
|
206 | - 'label' => __( 'IFSC', 'invoicing' ), |
|
207 | - ), |
|
208 | - ), |
|
209 | - 'IT' => array( |
|
210 | - 'sortcode' => array( |
|
211 | - 'label' => __( 'Branch sort', 'invoicing' ), |
|
212 | - ), |
|
213 | - ), |
|
214 | - 'NZ' => array( |
|
215 | - 'sortcode' => array( |
|
216 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
217 | - ), |
|
218 | - ), |
|
219 | - 'SE' => array( |
|
220 | - 'sortcode' => array( |
|
221 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
222 | - ), |
|
223 | - ), |
|
224 | - 'US' => array( |
|
225 | - 'sortcode' => array( |
|
226 | - 'label' => __( 'Routing number', 'invoicing' ), |
|
227 | - ), |
|
228 | - ), |
|
229 | - 'ZA' => array( |
|
230 | - 'sortcode' => array( |
|
231 | - 'label' => __( 'Branch code', 'invoicing' ), |
|
232 | - ), |
|
233 | - ), |
|
234 | - ) |
|
235 | - ); |
|
236 | - |
|
237 | - } |
|
238 | - |
|
239 | - return $this->locale; |
|
240 | - |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * Filters the gateway settings. |
|
245 | - * |
|
246 | - * @param array $admin_settings |
|
247 | - */ |
|
248 | - public function admin_settings( $admin_settings ) { |
|
182 | + * Get country locale if localized. |
|
183 | + * |
|
184 | + * @return array |
|
185 | + */ |
|
186 | + public function get_country_locale() { |
|
187 | + |
|
188 | + if ( empty( $this->locale ) ) { |
|
189 | + |
|
190 | + // Locale information to be used - only those that are not 'Sort Code'. |
|
191 | + $this->locale = apply_filters( |
|
192 | + 'getpaid_get_bank_transfer_locale', |
|
193 | + array( |
|
194 | + 'AU' => array( |
|
195 | + 'sortcode' => array( |
|
196 | + 'label' => __( 'BSB', 'invoicing' ), |
|
197 | + ), |
|
198 | + ), |
|
199 | + 'CA' => array( |
|
200 | + 'sortcode' => array( |
|
201 | + 'label' => __( 'Bank transit number', 'invoicing' ), |
|
202 | + ), |
|
203 | + ), |
|
204 | + 'IN' => array( |
|
205 | + 'sortcode' => array( |
|
206 | + 'label' => __( 'IFSC', 'invoicing' ), |
|
207 | + ), |
|
208 | + ), |
|
209 | + 'IT' => array( |
|
210 | + 'sortcode' => array( |
|
211 | + 'label' => __( 'Branch sort', 'invoicing' ), |
|
212 | + ), |
|
213 | + ), |
|
214 | + 'NZ' => array( |
|
215 | + 'sortcode' => array( |
|
216 | + 'label' => __( 'Bank code', 'invoicing' ), |
|
217 | + ), |
|
218 | + ), |
|
219 | + 'SE' => array( |
|
220 | + 'sortcode' => array( |
|
221 | + 'label' => __( 'Bank code', 'invoicing' ), |
|
222 | + ), |
|
223 | + ), |
|
224 | + 'US' => array( |
|
225 | + 'sortcode' => array( |
|
226 | + 'label' => __( 'Routing number', 'invoicing' ), |
|
227 | + ), |
|
228 | + ), |
|
229 | + 'ZA' => array( |
|
230 | + 'sortcode' => array( |
|
231 | + 'label' => __( 'Branch code', 'invoicing' ), |
|
232 | + ), |
|
233 | + ), |
|
234 | + ) |
|
235 | + ); |
|
236 | + |
|
237 | + } |
|
238 | + |
|
239 | + return $this->locale; |
|
240 | + |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * Filters the gateway settings. |
|
245 | + * |
|
246 | + * @param array $admin_settings |
|
247 | + */ |
|
248 | + public function admin_settings( $admin_settings ) { |
|
249 | 249 | |
250 | 250 | $admin_settings['worldpay_desc']['std'] = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ); |
251 | - $admin_settings['worldpay_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
251 | + $admin_settings['worldpay_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
252 | 252 | |
253 | - $locale = $this->get_country_locale(); |
|
253 | + $locale = $this->get_country_locale(); |
|
254 | 254 | |
255 | - // Get sortcode label in the $locale array and use appropriate one. |
|
256 | - $country = wpinv_default_billing_country(); |
|
257 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
255 | + // Get sortcode label in the $locale array and use appropriate one. |
|
256 | + $country = wpinv_default_billing_country(); |
|
257 | + $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
258 | 258 | |
259 | - $admin_settings['bank_transfer_ac_name'] = array( |
|
259 | + $admin_settings['bank_transfer_ac_name'] = array( |
|
260 | 260 | 'type' => 'text', |
261 | 261 | 'id' => 'bank_transfer_ac_name', |
262 | 262 | 'name' => __( 'Account Name', 'invoicing' ), |
263 | - ); |
|
263 | + ); |
|
264 | 264 | |
265 | - $admin_settings['bank_transfer_ac_no'] = array( |
|
265 | + $admin_settings['bank_transfer_ac_no'] = array( |
|
266 | 266 | 'type' => 'text', |
267 | 267 | 'id' => 'bank_transfer_ac_no', |
268 | 268 | 'name' => __( 'Account Number', 'invoicing' ), |
269 | - ); |
|
269 | + ); |
|
270 | 270 | |
271 | - $admin_settings['bank_transfer_bank_name'] = array( |
|
271 | + $admin_settings['bank_transfer_bank_name'] = array( |
|
272 | 272 | 'type' => 'text', |
273 | 273 | 'id' => 'bank_transfer_bank_name', |
274 | 274 | 'name' => __( 'Bank Name', 'invoicing' ), |
275 | - ); |
|
275 | + ); |
|
276 | 276 | |
277 | - $admin_settings['bank_transfer_ifsc'] = array( |
|
277 | + $admin_settings['bank_transfer_ifsc'] = array( |
|
278 | 278 | 'type' => 'text', |
279 | 279 | 'id' => 'bank_transfer_ifsc', |
280 | 280 | 'name' => __( 'IFSC Code', 'invoicing' ), |
281 | - ); |
|
281 | + ); |
|
282 | 282 | |
283 | - $admin_settings['bank_transfer_iban'] = array( |
|
283 | + $admin_settings['bank_transfer_iban'] = array( |
|
284 | 284 | 'type' => 'text', |
285 | 285 | 'id' => 'bank_transfer_iban', |
286 | 286 | 'name' => __( 'IBAN', 'invoicing' ), |
287 | - ); |
|
287 | + ); |
|
288 | 288 | |
289 | - $admin_settings['bank_transfer_bic'] = array( |
|
289 | + $admin_settings['bank_transfer_bic'] = array( |
|
290 | 290 | 'type' => 'text', |
291 | 291 | 'id' => 'bank_transfer_bic', |
292 | 292 | 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
293 | - ); |
|
293 | + ); |
|
294 | 294 | |
295 | - $admin_settings['bank_transfer_sort_code'] = array( |
|
296 | - 'type' => 'text', |
|
297 | - 'id' => 'bank_transfer_sort_code', |
|
298 | - 'name' => $sortcode, |
|
299 | - ); |
|
295 | + $admin_settings['bank_transfer_sort_code'] = array( |
|
296 | + 'type' => 'text', |
|
297 | + 'id' => 'bank_transfer_sort_code', |
|
298 | + 'name' => $sortcode, |
|
299 | + ); |
|
300 | 300 | |
301 | - $admin_settings['bank_transfer_info'] = array( |
|
301 | + $admin_settings['bank_transfer_info'] = array( |
|
302 | 302 | 'id' => 'bank_transfer_info', |
303 | 303 | 'name' => __( 'Instructions', 'invoicing' ), |
304 | 304 | 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | 'rows' => 5 |
309 | 309 | ); |
310 | 310 | |
311 | - return $admin_settings; |
|
312 | - } |
|
311 | + return $admin_settings; |
|
312 | + } |
|
313 | 313 | |
314 | 314 | } |