@@ -7,45 +7,45 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | // The payment methods select title. |
13 | -if ( empty( $text ) ) { |
|
14 | - $text = __( 'Select Payment Method', 'invoicing' ); |
|
13 | +if (empty($text)) { |
|
14 | + $text = __('Select Payment Method', 'invoicing'); |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | // An array of active payment methods. |
18 | -$gateways = wpinv_get_enabled_payment_gateways( true ); |
|
18 | +$gateways = wpinv_get_enabled_payment_gateways(true); |
|
19 | 19 | |
20 | 20 | // The current invoice id. |
21 | 21 | $invoice_id = 0; |
22 | 22 | $chosen_gateway = wpinv_get_default_gateway(); |
23 | 23 | |
24 | -if ( ! empty( $form->invoice ) ) { |
|
24 | +if (!empty($form->invoice)) { |
|
25 | 25 | $invoice_id = $form->invoice->get_id(); |
26 | 26 | $chosen_gateway = $form->invoice->get_gateway(); |
27 | 27 | } |
28 | 28 | |
29 | 29 | ?> |
30 | 30 | |
31 | - <?php do_action( 'getpaid_before_payment_form_gateway_select', $form ); ?> |
|
31 | + <?php do_action('getpaid_before_payment_form_gateway_select', $form); ?> |
|
32 | 32 | <div class="mt-4 mb-4 getpaid-gateways"> |
33 | 33 | |
34 | - <?php do_action( 'wpinv_payment_mode_top', $invoice_id, $chosen_gateway, $gateways, $form ); ?> |
|
34 | + <?php do_action('wpinv_payment_mode_top', $invoice_id, $chosen_gateway, $gateways, $form); ?> |
|
35 | 35 | |
36 | 36 | <div class="getpaid-select-gateway-title-div"> |
37 | - <h6><?php echo sanitize_text_field( $text ); ?></h6> |
|
37 | + <h6><?php echo sanitize_text_field($text); ?></h6> |
|
38 | 38 | </div> |
39 | 39 | |
40 | 40 | <div class="getpaid-available-gateways-div"> |
41 | 41 | |
42 | - <?php foreach ( array_keys( $gateways ) as $gateway ) : ?> |
|
42 | + <?php foreach (array_keys($gateways) as $gateway) : ?> |
|
43 | 43 | |
44 | - <div class="pt-1 pb-1 getpaid-gateway getpaid-gateway-<?php echo sanitize_html_class( $gateway ) ;?>" data-checkout-label='<?php echo esc_attr( apply_filters( "getpaid_gateway_{$gateway}_checkout_button_label", '' ) ); ?>'> |
|
44 | + <div class="pt-1 pb-1 getpaid-gateway getpaid-gateway-<?php echo sanitize_html_class($gateway); ?>" data-checkout-label='<?php echo esc_attr(apply_filters("getpaid_gateway_{$gateway}_checkout_button_label", '')); ?>'> |
|
45 | 45 | |
46 | 46 | <label class="d-block w-100 getpaid-gateway-radio"> |
47 | - <input type="radio" value="<?php echo esc_attr( $gateway ) ;?>" <?php checked( $gateway, $chosen_gateway ) ;?> name="wpi-gateway"> |
|
48 | - <span><?php echo sanitize_text_field( wpinv_get_gateway_checkout_label( $gateway ) ); ?></span> |
|
47 | + <input type="radio" value="<?php echo esc_attr($gateway); ?>" <?php checked($gateway, $chosen_gateway); ?> name="wpi-gateway"> |
|
48 | + <span><?php echo sanitize_text_field(wpinv_get_gateway_checkout_label($gateway)); ?></span> |
|
49 | 49 | </label> |
50 | 50 | |
51 | 51 | </div> |
@@ -56,22 +56,22 @@ discard block |
||
56 | 56 | |
57 | 57 | <div class="getpaid-gateway-descriptions-div"> |
58 | 58 | |
59 | - <?php foreach ( array_keys( $gateways ) as $gateway ) : ?> |
|
59 | + <?php foreach (array_keys($gateways) as $gateway) : ?> |
|
60 | 60 | |
61 | - <div class="my-2 p-3 bg-light border getpaid-gateway-description getpaid-description-<?php echo sanitize_html_class( $gateway ) ;?>" style="display: none;"> |
|
61 | + <div class="my-2 p-3 bg-light border getpaid-gateway-description getpaid-description-<?php echo sanitize_html_class($gateway); ?>" style="display: none;"> |
|
62 | 62 | <?php |
63 | 63 | |
64 | - $description = wpinv_get_gateway_description( $gateway ); |
|
64 | + $description = wpinv_get_gateway_description($gateway); |
|
65 | 65 | |
66 | - if ( wpinv_is_test_mode( $gateway ) ) { |
|
67 | - $sandbox_notice = apply_filters( "getpaid_{$gateway}_sandbox_notice", __( 'SANDBOX ENABLED: No real payments will occur.', 'invoicing' ) ); |
|
66 | + if (wpinv_is_test_mode($gateway)) { |
|
67 | + $sandbox_notice = apply_filters("getpaid_{$gateway}_sandbox_notice", __('SANDBOX ENABLED: No real payments will occur.', 'invoicing')); |
|
68 | 68 | $description = "$description $sandbox_notice"; |
69 | 69 | } |
70 | 70 | |
71 | - echo wpautop( wp_kses_post( $description ) ); |
|
71 | + echo wpautop(wp_kses_post($description)); |
|
72 | 72 | |
73 | - do_action( 'wpinv_' . $gateway . '_checkout_fields', $invoice_id ) ; |
|
74 | - do_action( 'wpinv_' . $gateway . '_cc_form', $invoice_id, $form ) ; |
|
73 | + do_action('wpinv_' . $gateway . '_checkout_fields', $invoice_id); |
|
74 | + do_action('wpinv_' . $gateway . '_cc_form', $invoice_id, $form); |
|
75 | 75 | |
76 | 76 | ?> |
77 | 77 | </div> |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | <?php |
85 | 85 | echo aui()->alert( |
86 | 86 | array( |
87 | - 'content' => __( 'None of the available payment gateways support purchasing recurring items.', 'invoicing' ), |
|
87 | + 'content' => __('None of the available payment gateways support purchasing recurring items.', 'invoicing'), |
|
88 | 88 | 'type' => 'danger', |
89 | 89 | ) |
90 | 90 | ); |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | <?php |
96 | 96 | echo aui()->alert( |
97 | 97 | array( |
98 | - 'content' => __( 'None of the available payment gateways support purchasing multiple subscriptions in a single order.', 'invoicing' ), |
|
98 | + 'content' => __('None of the available payment gateways support purchasing multiple subscriptions in a single order.', 'invoicing'), |
|
99 | 99 | 'type' => 'danger', |
100 | 100 | ) |
101 | 101 | ); |
@@ -106,14 +106,14 @@ discard block |
||
106 | 106 | <?php |
107 | 107 | echo aui()->alert( |
108 | 108 | array( |
109 | - 'content' => __( 'There is no active payment gateway available to process your request.', 'invoicing' ), |
|
109 | + 'content' => __('There is no active payment gateway available to process your request.', 'invoicing'), |
|
110 | 110 | 'type' => 'danger', |
111 | 111 | ) |
112 | 112 | ); |
113 | 113 | ?> |
114 | 114 | </div> |
115 | 115 | |
116 | - <?php do_action( 'wpinv_payment_mode_bottom', $invoice_id, $chosen_gateway, $gateways, $form ); ?> |
|
116 | + <?php do_action('wpinv_payment_mode_bottom', $invoice_id, $chosen_gateway, $gateways, $form); ?> |
|
117 | 117 | |
118 | 118 | </div> |
119 | - <?php do_action( 'getpaid_after_payment_form_gateway_select', $form ); ?> |
|
119 | + <?php do_action('getpaid_after_payment_form_gateway_select', $form); ?> |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Payment form submission refresh prices class |
@@ -23,23 +23,23 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @param GetPaid_Payment_Form_Submission $submission |
25 | 25 | */ |
26 | - public function __construct( $submission ) { |
|
26 | + public function __construct($submission) { |
|
27 | 27 | |
28 | 28 | $this->response = array( |
29 | 29 | 'submission_id' => $submission->id, |
30 | 30 | 'has_recurring' => $submission->has_recurring, |
31 | - 'has_multiple_subscriptions' => $submission->has_recurring && 1 < count( getpaid_get_subscription_groups( $submission ) ), |
|
32 | - 'is_free' => ! $submission->should_collect_payment_details(), |
|
31 | + 'has_multiple_subscriptions' => $submission->has_recurring && 1 < count(getpaid_get_subscription_groups($submission)), |
|
32 | + 'is_free' => !$submission->should_collect_payment_details(), |
|
33 | 33 | ); |
34 | 34 | |
35 | - $this->add_totals( $submission ); |
|
36 | - $this->add_texts( $submission ); |
|
37 | - $this->add_items( $submission ); |
|
38 | - $this->add_fees( $submission ); |
|
39 | - $this->add_discounts( $submission ); |
|
40 | - $this->add_taxes( $submission ); |
|
41 | - $this->add_gateways( $submission ); |
|
42 | - $this->add_data( $submission ); |
|
35 | + $this->add_totals($submission); |
|
36 | + $this->add_texts($submission); |
|
37 | + $this->add_items($submission); |
|
38 | + $this->add_fees($submission); |
|
39 | + $this->add_discounts($submission); |
|
40 | + $this->add_taxes($submission); |
|
41 | + $this->add_gateways($submission); |
|
42 | + $this->add_data($submission); |
|
43 | 43 | |
44 | 44 | } |
45 | 45 | |
@@ -48,30 +48,30 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @param GetPaid_Payment_Form_Submission $submission |
50 | 50 | */ |
51 | - public function add_totals( $submission ) { |
|
51 | + public function add_totals($submission) { |
|
52 | 52 | |
53 | 53 | $this->response = array_merge( |
54 | 54 | $this->response, |
55 | 55 | array( |
56 | 56 | |
57 | 57 | 'totals' => array( |
58 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
59 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
60 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
61 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
62 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
63 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
58 | + 'subtotal' => $submission->format_amount($submission->get_subtotal()), |
|
59 | + 'discount' => $submission->format_amount($submission->get_discount()), |
|
60 | + 'fees' => $submission->format_amount($submission->get_fee()), |
|
61 | + 'tax' => $submission->format_amount($submission->get_tax()), |
|
62 | + 'total' => $submission->format_amount($submission->get_total()), |
|
63 | + 'raw_total' => html_entity_decode(sanitize_text_field($submission->format_amount($submission->get_total())), ENT_QUOTES), |
|
64 | 64 | ), |
65 | 65 | |
66 | 66 | 'recurring' => array( |
67 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
68 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
69 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
70 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
71 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
67 | + 'subtotal' => $submission->format_amount($submission->get_recurring_subtotal()), |
|
68 | + 'discount' => $submission->format_amount($submission->get_recurring_discount()), |
|
69 | + 'fees' => $submission->format_amount($submission->get_recurring_fee()), |
|
70 | + 'tax' => $submission->format_amount($submission->get_recurring_tax()), |
|
71 | + 'total' => $submission->format_amount($submission->get_recurring_total()), |
|
72 | 72 | ), |
73 | 73 | |
74 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
74 | + 'initial_amt' => wpinv_round_amount($submission->get_total(), null, true), |
|
75 | 75 | 'currency' => $submission->get_currency(), |
76 | 76 | |
77 | 77 | ) |
@@ -84,23 +84,23 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @param GetPaid_Payment_Form_Submission $submission |
86 | 86 | */ |
87 | - public function add_texts( $submission ) { |
|
87 | + public function add_texts($submission) { |
|
88 | 88 | |
89 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
90 | - $groups = getpaid_get_subscription_groups( $submission ); |
|
89 | + $payable = $submission->format_amount($submission->get_total()); |
|
90 | + $groups = getpaid_get_subscription_groups($submission); |
|
91 | 91 | |
92 | - if ( $submission->has_recurring != 0 && 2 > $groups ) { |
|
92 | + if ($submission->has_recurring != 0 && 2 > $groups) { |
|
93 | 93 | |
94 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
95 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
94 | + $recurring = new WPInv_Item($submission->has_recurring); |
|
95 | + $period = getpaid_get_subscription_period_label($recurring->get_recurring_period(true), $recurring->get_recurring_interval(), ''); |
|
96 | 96 | |
97 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
97 | + if ($submission->get_total() == $submission->get_recurring_total()) { |
|
98 | 98 | $payable = "$payable / $period"; |
99 | 99 | } else { |
100 | 100 | $payable = sprintf( |
101 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
102 | - $submission->format_amount( $submission->get_total() ), |
|
103 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
101 | + __('%1$s (renews at %2$s / %3$s)', 'invoicing'), |
|
102 | + $submission->format_amount($submission->get_total()), |
|
103 | + $submission->format_amount($submission->get_recurring_total()), |
|
104 | 104 | $period |
105 | 105 | ); |
106 | 106 | } |
@@ -111,14 +111,14 @@ discard block |
||
111 | 111 | '.getpaid-checkout-total-payable' => $payable, |
112 | 112 | ); |
113 | 113 | |
114 | - foreach ( $submission->get_items() as $item ) { |
|
114 | + foreach ($submission->get_items() as $item) { |
|
115 | 115 | $item_id = $item->get_id(); |
116 | - $initial_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) ); |
|
117 | - $recurring_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) ); |
|
118 | - $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
116 | + $initial_price = $submission->format_amount($this->standardize_price($item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false)); |
|
117 | + $recurring_price = $submission->format_amount($this->standardize_price($item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true)); |
|
118 | + $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text($item, $submission->get_currency(), $initial_price, $recurring_price); |
|
119 | 119 | } |
120 | 120 | |
121 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
121 | + $this->response = array_merge($this->response, array('texts' => $texts)); |
|
122 | 122 | |
123 | 123 | } |
124 | 124 | |
@@ -127,19 +127,19 @@ discard block |
||
127 | 127 | * |
128 | 128 | * @param GetPaid_Payment_Form_Submission $submission |
129 | 129 | */ |
130 | - public function add_items( $submission ) { |
|
130 | + public function add_items($submission) { |
|
131 | 131 | |
132 | 132 | // Add items. |
133 | 133 | $items = array(); |
134 | 134 | |
135 | - foreach ( $submission->get_items() as $item ) { |
|
135 | + foreach ($submission->get_items() as $item) { |
|
136 | 136 | $item_id = $item->get_id(); |
137 | - $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
137 | + $items["$item_id"] = $submission->format_amount($item->get_sub_total()); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | $this->response = array_merge( |
141 | 141 | $this->response, |
142 | - array( 'items' => $items ) |
|
142 | + array('items' => $items) |
|
143 | 143 | ); |
144 | 144 | |
145 | 145 | } |
@@ -149,17 +149,17 @@ discard block |
||
149 | 149 | * |
150 | 150 | * @param GetPaid_Payment_Form_Submission $submission |
151 | 151 | */ |
152 | - public function add_fees( $submission ) { |
|
152 | + public function add_fees($submission) { |
|
153 | 153 | |
154 | 154 | $fees = array(); |
155 | 155 | |
156 | - foreach ( $submission->get_fees() as $name => $data ) { |
|
157 | - $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
156 | + foreach ($submission->get_fees() as $name => $data) { |
|
157 | + $fees[$name] = $submission->format_amount($data['initial_fee']); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | $this->response = array_merge( |
161 | 161 | $this->response, |
162 | - array( 'fees' => $fees ) |
|
162 | + array('fees' => $fees) |
|
163 | 163 | ); |
164 | 164 | |
165 | 165 | } |
@@ -169,17 +169,17 @@ discard block |
||
169 | 169 | * |
170 | 170 | * @param GetPaid_Payment_Form_Submission $submission |
171 | 171 | */ |
172 | - public function add_discounts( $submission ) { |
|
172 | + public function add_discounts($submission) { |
|
173 | 173 | |
174 | 174 | $discounts = array(); |
175 | 175 | |
176 | - foreach ( $submission->get_discounts() as $name => $data ) { |
|
177 | - $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
176 | + foreach ($submission->get_discounts() as $name => $data) { |
|
177 | + $discounts[$name] = $submission->format_amount($data['initial_discount']); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | $this->response = array_merge( |
181 | 181 | $this->response, |
182 | - array( 'discounts' => $discounts ) |
|
182 | + array('discounts' => $discounts) |
|
183 | 183 | ); |
184 | 184 | |
185 | 185 | } |
@@ -189,24 +189,24 @@ discard block |
||
189 | 189 | * |
190 | 190 | * @param GetPaid_Payment_Form_Submission $submission |
191 | 191 | */ |
192 | - public function add_taxes( $submission ) { |
|
192 | + public function add_taxes($submission) { |
|
193 | 193 | |
194 | 194 | $taxes = array(); |
195 | 195 | $markup = ''; |
196 | - foreach ( $submission->get_taxes() as $name => $data ) { |
|
197 | - $name = sanitize_text_field( $name ); |
|
198 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
196 | + foreach ($submission->get_taxes() as $name => $data) { |
|
197 | + $name = sanitize_text_field($name); |
|
198 | + $amount = $submission->format_amount($data['initial_tax']); |
|
199 | 199 | $taxes[$name] = $amount; |
200 | 200 | $markup .= "<small class='form-text'>$name : $amount</small>"; |
201 | 201 | } |
202 | 202 | |
203 | - if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
203 | + if (wpinv_display_individual_tax_rates() && !empty($taxes)) { |
|
204 | 204 | $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
205 | 205 | } |
206 | 206 | |
207 | 207 | $this->response = array_merge( |
208 | 208 | $this->response, |
209 | - array( 'taxes' => $taxes ) |
|
209 | + array('taxes' => $taxes) |
|
210 | 210 | ); |
211 | 211 | |
212 | 212 | } |
@@ -216,26 +216,26 @@ discard block |
||
216 | 216 | * |
217 | 217 | * @param GetPaid_Payment_Form_Submission $submission |
218 | 218 | */ |
219 | - public function add_gateways( $submission ) { |
|
219 | + public function add_gateways($submission) { |
|
220 | 220 | |
221 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
221 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
222 | 222 | |
223 | - if ( $this->response['has_recurring'] ) { |
|
223 | + if ($this->response['has_recurring']) { |
|
224 | 224 | |
225 | - foreach ( $gateways as $i => $gateway ) { |
|
225 | + foreach ($gateways as $i => $gateway) { |
|
226 | 226 | |
227 | - if ( ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) || ( $this->response['has_multiple_subscriptions'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscriptions' ) ) ) { |
|
228 | - unset( $gateways[ $i ] ); |
|
227 | + if (!getpaid_payment_gateway_supports($gateway, 'subscription') || ($this->response['has_multiple_subscriptions'] && !getpaid_payment_gateway_supports($gateway, 'multiple_subscriptions'))) { |
|
228 | + unset($gateways[$i]); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | } |
232 | 232 | |
233 | 233 | } |
234 | 234 | |
235 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
235 | + $gateways = apply_filters('getpaid_submission_gateways', $gateways, $submission); |
|
236 | 236 | $this->response = array_merge( |
237 | 237 | $this->response, |
238 | - array( 'gateways' => $gateways ) |
|
238 | + array('gateways' => $gateways) |
|
239 | 239 | ); |
240 | 240 | |
241 | 241 | } |
@@ -248,22 +248,22 @@ discard block |
||
248 | 248 | * @param string $discount_code |
249 | 249 | * @param bool $recurring |
250 | 250 | */ |
251 | - public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) { |
|
251 | + public function standardize_price($item_id, $item_total, $discount_code, $recurring = false) { |
|
252 | 252 | |
253 | 253 | $standardadized_price = $item_total; |
254 | 254 | |
255 | 255 | // Do we have a $discount_code? |
256 | - if ( ! empty( $discount_code ) ) { |
|
256 | + if (!empty($discount_code)) { |
|
257 | 257 | |
258 | - $discount = new WPInv_Discount( $discount_code ); |
|
258 | + $discount = new WPInv_Discount($discount_code); |
|
259 | 259 | |
260 | - if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) { |
|
261 | - $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total ); |
|
260 | + if ($discount->exists() && $discount->is_valid_for_items($item_id) && (!$recurring || $discount->is_recurring())) { |
|
261 | + $standardadized_price = $item_total - $discount->get_discounted_amount($item_total); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | } |
265 | 265 | |
266 | - return max( 0, $standardadized_price ); |
|
266 | + return max(0, $standardadized_price); |
|
267 | 267 | |
268 | 268 | } |
269 | 269 | |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | * |
273 | 273 | * @param GetPaid_Payment_Form_Submission $submission |
274 | 274 | */ |
275 | - public function add_data( $submission ) { |
|
275 | + public function add_data($submission) { |
|
276 | 276 | |
277 | 277 | $this->response = array_merge( |
278 | 278 | $this->response, |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Contains gateway functions. |
4 | 4 | * |
5 | 5 | */ |
6 | -defined( 'ABSPATH' ) || exit; |
|
6 | +defined('ABSPATH') || exit; |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * Returns an array of payment gateways. |
@@ -11,82 +11,82 @@ discard block |
||
11 | 11 | * @return array |
12 | 12 | */ |
13 | 13 | function wpinv_get_payment_gateways() { |
14 | - return apply_filters( 'wpinv_payment_gateways', array() ); |
|
14 | + return apply_filters('wpinv_payment_gateways', array()); |
|
15 | 15 | } |
16 | 16 | |
17 | -function wpinv_payment_gateway_titles( $all_gateways ) { |
|
17 | +function wpinv_payment_gateway_titles($all_gateways) { |
|
18 | 18 | global $wpinv_options; |
19 | 19 | |
20 | 20 | $gateways = array(); |
21 | - foreach ( $all_gateways as $key => $gateway ) { |
|
22 | - if ( !empty( $wpinv_options[$key . '_title'] ) ) { |
|
23 | - $all_gateways[$key]['checkout_label'] = __( $wpinv_options[$key . '_title'], 'invoicing' ); |
|
21 | + foreach ($all_gateways as $key => $gateway) { |
|
22 | + if (!empty($wpinv_options[$key . '_title'])) { |
|
23 | + $all_gateways[$key]['checkout_label'] = __($wpinv_options[$key . '_title'], 'invoicing'); |
|
24 | 24 | } |
25 | 25 | |
26 | - $gateways[$key] = isset( $wpinv_options[$key . '_ordering'] ) ? $wpinv_options[$key . '_ordering'] : ( isset( $gateway['ordering'] ) ? $gateway['ordering'] : '' ); |
|
26 | + $gateways[$key] = isset($wpinv_options[$key . '_ordering']) ? $wpinv_options[$key . '_ordering'] : (isset($gateway['ordering']) ? $gateway['ordering'] : ''); |
|
27 | 27 | } |
28 | 28 | |
29 | - asort( $gateways ); |
|
29 | + asort($gateways); |
|
30 | 30 | |
31 | - foreach ( $gateways as $gateway => $key ) { |
|
31 | + foreach ($gateways as $gateway => $key) { |
|
32 | 32 | $gateways[$gateway] = $all_gateways[$gateway]; |
33 | 33 | } |
34 | 34 | |
35 | 35 | return $gateways; |
36 | 36 | } |
37 | -add_filter( 'wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1 ); |
|
37 | +add_filter('wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1); |
|
38 | 38 | |
39 | -function wpinv_get_enabled_payment_gateways( $sort = false ) { |
|
39 | +function wpinv_get_enabled_payment_gateways($sort = false) { |
|
40 | 40 | $gateways = wpinv_get_payment_gateways(); |
41 | - $enabled = wpinv_get_option( 'gateways', array( 'manual' => 1 ) ); |
|
41 | + $enabled = wpinv_get_option('gateways', array('manual' => 1)); |
|
42 | 42 | |
43 | 43 | $gateway_list = array(); |
44 | 44 | |
45 | - foreach ( $gateways as $key => $gateway ) { |
|
46 | - if ( isset( $enabled[ $key ] ) && $enabled[ $key ] == 1 ) { |
|
47 | - $gateway_list[ $key ] = $gateway; |
|
45 | + foreach ($gateways as $key => $gateway) { |
|
46 | + if (isset($enabled[$key]) && $enabled[$key] == 1) { |
|
47 | + $gateway_list[$key] = $gateway; |
|
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
51 | - if ( true === $sort ) { |
|
52 | - uasort( $gateway_list, 'wpinv_sort_gateway_order' ); |
|
51 | + if (true === $sort) { |
|
52 | + uasort($gateway_list, 'wpinv_sort_gateway_order'); |
|
53 | 53 | |
54 | 54 | // Reorder our gateways so the default is first |
55 | 55 | $default_gateway_id = wpinv_get_default_gateway(); |
56 | 56 | |
57 | - if ( wpinv_is_gateway_active( $default_gateway_id ) ) { |
|
58 | - $default_gateway = array( $default_gateway_id => $gateway_list[ $default_gateway_id ] ); |
|
59 | - unset( $gateway_list[ $default_gateway_id ] ); |
|
57 | + if (wpinv_is_gateway_active($default_gateway_id)) { |
|
58 | + $default_gateway = array($default_gateway_id => $gateway_list[$default_gateway_id]); |
|
59 | + unset($gateway_list[$default_gateway_id]); |
|
60 | 60 | |
61 | - $gateway_list = array_merge( $default_gateway, $gateway_list ); |
|
61 | + $gateway_list = array_merge($default_gateway, $gateway_list); |
|
62 | 62 | } |
63 | 63 | } |
64 | 64 | |
65 | - return apply_filters( 'wpinv_enabled_payment_gateways', $gateway_list ); |
|
65 | + return apply_filters('wpinv_enabled_payment_gateways', $gateway_list); |
|
66 | 66 | } |
67 | 67 | |
68 | -function wpinv_sort_gateway_order( $a, $b ) { |
|
68 | +function wpinv_sort_gateway_order($a, $b) { |
|
69 | 69 | return $a['ordering'] - $b['ordering']; |
70 | 70 | } |
71 | 71 | |
72 | -function wpinv_is_gateway_active( $gateway ) { |
|
72 | +function wpinv_is_gateway_active($gateway) { |
|
73 | 73 | $gateways = wpinv_get_enabled_payment_gateways(); |
74 | 74 | |
75 | - $ret = is_array($gateways) && $gateway ? array_key_exists( $gateway, $gateways ) : false; |
|
75 | + $ret = is_array($gateways) && $gateway ? array_key_exists($gateway, $gateways) : false; |
|
76 | 76 | |
77 | - return apply_filters( 'wpinv_is_gateway_active', $ret, $gateway, $gateways ); |
|
77 | + return apply_filters('wpinv_is_gateway_active', $ret, $gateway, $gateways); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | function wpinv_get_default_gateway() { |
81 | - $default = wpinv_get_option( 'default_gateway', 'paypal' ); |
|
81 | + $default = wpinv_get_option('default_gateway', 'paypal'); |
|
82 | 82 | |
83 | - if ( !wpinv_is_gateway_active( $default ) ) { |
|
83 | + if (!wpinv_is_gateway_active($default)) { |
|
84 | 84 | $gateways = wpinv_get_enabled_payment_gateways(); |
85 | - $gateways = array_keys( $gateways ); |
|
86 | - $default = reset( $gateways ); |
|
85 | + $gateways = array_keys($gateways); |
|
86 | + $default = reset($gateways); |
|
87 | 87 | } |
88 | 88 | |
89 | - return apply_filters( 'wpinv_default_gateway', $default ); |
|
89 | + return apply_filters('wpinv_default_gateway', $default); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -95,17 +95,17 @@ discard block |
||
95 | 95 | * @param string $gateway The gateway to key. |
96 | 96 | * @return string |
97 | 97 | */ |
98 | -function wpinv_get_gateway_admin_label( $gateway ) { |
|
98 | +function wpinv_get_gateway_admin_label($gateway) { |
|
99 | 99 | |
100 | - if ( empty( $gateway ) || 'none' == $gateway ) { |
|
101 | - return esc_html__( 'No Gateway', 'invoicing' ); |
|
100 | + if (empty($gateway) || 'none' == $gateway) { |
|
101 | + return esc_html__('No Gateway', 'invoicing'); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | $gateways = wpinv_get_payment_gateways(); |
105 | - $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway; |
|
106 | - $gateway = apply_filters( 'wpinv_gateway_admin_label', $label, $gateway ); |
|
105 | + $label = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway; |
|
106 | + $gateway = apply_filters('wpinv_gateway_admin_label', $label, $gateway); |
|
107 | 107 | |
108 | - return wpinv_clean( $gateway ); |
|
108 | + return wpinv_clean($gateway); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -113,49 +113,49 @@ discard block |
||
113 | 113 | * |
114 | 114 | * @param string $gateway |
115 | 115 | */ |
116 | -function wpinv_get_gateway_description( $gateway ) { |
|
116 | +function wpinv_get_gateway_description($gateway) { |
|
117 | 117 | global $wpinv_options; |
118 | 118 | |
119 | - $description = ! empty( $wpinv_options[$gateway . '_desc'] ) ? $wpinv_options[$gateway . '_desc'] : ''; |
|
119 | + $description = !empty($wpinv_options[$gateway . '_desc']) ? $wpinv_options[$gateway . '_desc'] : ''; |
|
120 | 120 | |
121 | - return apply_filters( 'wpinv_gateway_description', $description, $gateway ); |
|
121 | + return apply_filters('wpinv_gateway_description', $description, $gateway); |
|
122 | 122 | } |
123 | 123 | |
124 | -function wpinv_get_gateway_button_label( $gateway ) { |
|
125 | - return apply_filters( 'wpinv_gateway_' . $gateway . '_button_label', '' ); |
|
124 | +function wpinv_get_gateway_button_label($gateway) { |
|
125 | + return apply_filters('wpinv_gateway_' . $gateway . '_button_label', ''); |
|
126 | 126 | } |
127 | 127 | |
128 | -function wpinv_get_gateway_checkout_label( $gateway ) { |
|
128 | +function wpinv_get_gateway_checkout_label($gateway) { |
|
129 | 129 | $gateways = wpinv_get_payment_gateways(); |
130 | - $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway; |
|
130 | + $label = isset($gateways[$gateway]) ? $gateways[$gateway]['checkout_label'] : $gateway; |
|
131 | 131 | |
132 | - if ( $gateway == 'none' ) { |
|
133 | - $label = __( 'None', 'invoicing' ); |
|
132 | + if ($gateway == 'none') { |
|
133 | + $label = __('None', 'invoicing'); |
|
134 | 134 | } |
135 | 135 | |
136 | - return apply_filters( 'wpinv_gateway_checkout_label', ucfirst( $label ), $gateway ); |
|
136 | + return apply_filters('wpinv_gateway_checkout_label', ucfirst($label), $gateway); |
|
137 | 137 | } |
138 | 138 | |
139 | -function wpinv_settings_sections_gateways( $settings ) { |
|
139 | +function wpinv_settings_sections_gateways($settings) { |
|
140 | 140 | $gateways = wpinv_get_payment_gateways(); |
141 | 141 | |
142 | 142 | if (!empty($gateways)) { |
143 | - foreach ($gateways as $key => $gateway) { |
|
143 | + foreach ($gateways as $key => $gateway) { |
|
144 | 144 | $settings[$key] = $gateway['admin_label']; |
145 | 145 | } |
146 | 146 | } |
147 | 147 | |
148 | 148 | return $settings; |
149 | 149 | } |
150 | -add_filter( 'wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1 ); |
|
150 | +add_filter('wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1); |
|
151 | 151 | |
152 | 152 | /** |
153 | 153 | * Adds GateWay settings. |
154 | 154 | */ |
155 | -function wpinv_settings_gateways( $settings ) { |
|
155 | +function wpinv_settings_gateways($settings) { |
|
156 | 156 | |
157 | 157 | // Loop through each gateway. |
158 | - foreach ( wpinv_get_payment_gateways() as $key => $gateway ) { |
|
158 | + foreach (wpinv_get_payment_gateways() as $key => $gateway) { |
|
159 | 159 | |
160 | 160 | $gateway_settings = array( |
161 | 161 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | "{$key}_header" => array( |
164 | 164 | |
165 | 165 | 'id' => "{$key}_gateway_header", |
166 | - 'name' => '<h3>' . wp_sprintf( __( '%s Settings', 'invoicing' ), $gateway['admin_label'] ) . '</h3>', |
|
166 | + 'name' => '<h3>' . wp_sprintf(__('%s Settings', 'invoicing'), $gateway['admin_label']) . '</h3>', |
|
167 | 167 | 'custom' => $key, |
168 | 168 | 'type' => 'gateway_header', |
169 | 169 | |
@@ -172,16 +172,16 @@ discard block |
||
172 | 172 | // Activate/Deactivate a gateway. |
173 | 173 | "{$key}_active" => array( |
174 | 174 | 'id' => $key . '_active', |
175 | - 'name' => __( 'Activate', 'invoicing' ), |
|
176 | - 'desc' => wp_sprintf( __( 'Enable %s', 'invoicing' ), $gateway['admin_label'] ), |
|
175 | + 'name' => __('Activate', 'invoicing'), |
|
176 | + 'desc' => wp_sprintf(__('Enable %s', 'invoicing'), $gateway['admin_label']), |
|
177 | 177 | 'type' => 'checkbox', |
178 | 178 | ), |
179 | 179 | |
180 | 180 | // Activate/Deactivate sandbox. |
181 | 181 | "{$key}_sandbox" => array( |
182 | 182 | 'id' => $key . '_sandbox', |
183 | - 'name' => __( 'Sandbox', 'invoicing' ), |
|
184 | - 'desc' => __( 'Enable sandbox to test payments', 'invoicing' ), |
|
183 | + 'name' => __('Sandbox', 'invoicing'), |
|
184 | + 'desc' => __('Enable sandbox to test payments', 'invoicing'), |
|
185 | 185 | 'type' => 'checkbox', |
186 | 186 | 'std' => '1', |
187 | 187 | ), |
@@ -189,40 +189,40 @@ discard block |
||
189 | 189 | // Checkout title. |
190 | 190 | "{$key}_title" => array( |
191 | 191 | 'id' => $key . '_title', |
192 | - 'name' => __( 'Checkout Title', 'invoicing' ), |
|
193 | - 'std' => isset( $gateway['checkout_label'] ) ? $gateway['checkout_label'] : '', |
|
192 | + 'name' => __('Checkout Title', 'invoicing'), |
|
193 | + 'std' => isset($gateway['checkout_label']) ? $gateway['checkout_label'] : '', |
|
194 | 194 | 'type' => 'text', |
195 | 195 | ), |
196 | 196 | |
197 | 197 | // Checkout description. |
198 | 198 | "{$key}_desc" => array( |
199 | 199 | 'id' => $key . '_desc', |
200 | - 'name' => __( 'Checkout Description', 'invoicing' ), |
|
201 | - 'std' => apply_filters( "getpaid_default_{$key}_checkout_description", '' ), |
|
200 | + 'name' => __('Checkout Description', 'invoicing'), |
|
201 | + 'std' => apply_filters("getpaid_default_{$key}_checkout_description", ''), |
|
202 | 202 | 'type' => 'text', |
203 | 203 | ), |
204 | 204 | |
205 | 205 | // Checkout order. |
206 | 206 | "{$key}_ordering" => array( |
207 | 207 | 'id' => $key . '_ordering', |
208 | - 'name' => __( 'Priority', 'invoicing' ), |
|
209 | - 'std' => apply_filters( "getpaid_default_{$key}_checkout_description", '' ), |
|
208 | + 'name' => __('Priority', 'invoicing'), |
|
209 | + 'std' => apply_filters("getpaid_default_{$key}_checkout_description", ''), |
|
210 | 210 | 'type' => 'number', |
211 | 211 | 'step' => '1', |
212 | 212 | 'min' => '0', |
213 | 213 | 'max' => '100000', |
214 | - 'std' => isset( $gateway['ordering'] ) ? $gateway['ordering'] : '10', |
|
214 | + 'std' => isset($gateway['ordering']) ? $gateway['ordering'] : '10', |
|
215 | 215 | ), |
216 | 216 | |
217 | 217 | ); |
218 | 218 | |
219 | 219 | // Maybe remove the sandbox. |
220 | - if ( ! getpaid_payment_gateway_supports( $key, 'sandbox' ) ) { |
|
221 | - unset( $gateway_settings["{$key}_sandbox"] ); |
|
220 | + if (!getpaid_payment_gateway_supports($key, 'sandbox')) { |
|
221 | + unset($gateway_settings["{$key}_sandbox"]); |
|
222 | 222 | } |
223 | 223 | |
224 | - $gateway_settings = apply_filters( 'wpinv_gateway_settings', $gateway_settings, $key, $gateway ); |
|
225 | - $gateway_settings = apply_filters( 'wpinv_gateway_settings_' . $key, $gateway_settings, $gateway ); |
|
224 | + $gateway_settings = apply_filters('wpinv_gateway_settings', $gateway_settings, $key, $gateway); |
|
225 | + $gateway_settings = apply_filters('wpinv_gateway_settings_' . $key, $gateway_settings, $gateway); |
|
226 | 226 | |
227 | 227 | $settings[$key] = $gateway_settings; |
228 | 228 | } |
@@ -230,10 +230,10 @@ discard block |
||
230 | 230 | return $settings; |
231 | 231 | |
232 | 232 | } |
233 | -add_filter( 'wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1 ); |
|
233 | +add_filter('wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1); |
|
234 | 234 | |
235 | -function wpinv_gateway_header_callback( $args ) { |
|
236 | - echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr( $args['custom'] ) . '" />'; |
|
235 | +function wpinv_gateway_header_callback($args) { |
|
236 | + echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr($args['custom']) . '" />'; |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | /** |
@@ -244,64 +244,64 @@ discard block |
||
244 | 244 | * @return bool |
245 | 245 | * @since 2.3.0 |
246 | 246 | */ |
247 | -function getpaid_payment_gateway_supports( $gateway, $feature ) { |
|
247 | +function getpaid_payment_gateway_supports($gateway, $feature) { |
|
248 | 248 | |
249 | 249 | $supports = false; |
250 | 250 | |
251 | - if ( wpinv_is_gateway_active( $gateway ) ) { |
|
251 | + if (wpinv_is_gateway_active($gateway)) { |
|
252 | 252 | |
253 | - $supports = apply_filters( "getpaid_{$gateway}_supports_{$feature}", false ); |
|
253 | + $supports = apply_filters("getpaid_{$gateway}_supports_{$feature}", false); |
|
254 | 254 | |
255 | 255 | // Backwards compatibility. |
256 | - $supports = apply_filters( "wpinv_{$gateway}_supports_{$feature}", $supports ); |
|
257 | - $supports = apply_filters( "wpinv_{$gateway}_support_{$feature}", $supports ); |
|
256 | + $supports = apply_filters("wpinv_{$gateway}_supports_{$feature}", $supports); |
|
257 | + $supports = apply_filters("wpinv_{$gateway}_support_{$feature}", $supports); |
|
258 | 258 | |
259 | - $supports = apply_filters( "getpaid_gateway_supports_{$feature}", $supports, $gateway ); |
|
260 | - $supports = apply_filters( 'getpaid_payment_gateway_supports', $supports, $feature, $gateway ); |
|
259 | + $supports = apply_filters("getpaid_gateway_supports_{$feature}", $supports, $gateway); |
|
260 | + $supports = apply_filters('getpaid_payment_gateway_supports', $supports, $feature, $gateway); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | return $supports; |
264 | 264 | } |
265 | 265 | |
266 | -function wpinv_get_chosen_gateway( $invoice_id = 0 ) { |
|
267 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
266 | +function wpinv_get_chosen_gateway($invoice_id = 0) { |
|
267 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
268 | 268 | |
269 | 269 | $chosen = false; |
270 | - if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
270 | + if ($invoice_id > 0 && $invoice = wpinv_get_invoice($invoice_id)) { |
|
271 | 271 | $chosen = $invoice->get_gateway(); |
272 | 272 | } |
273 | 273 | |
274 | - $chosen = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen; |
|
274 | + $chosen = isset($_REQUEST['payment-mode']) ? sanitize_text_field($_REQUEST['payment-mode']) : $chosen; |
|
275 | 275 | |
276 | - if ( false !== $chosen ) { |
|
277 | - $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen ); |
|
276 | + if (false !== $chosen) { |
|
277 | + $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen); |
|
278 | 278 | } |
279 | 279 | |
280 | - if ( ! empty ( $chosen ) ) { |
|
281 | - $enabled_gateway = urldecode( $chosen ); |
|
282 | - } else if ( !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) { |
|
280 | + if (!empty ($chosen)) { |
|
281 | + $enabled_gateway = urldecode($chosen); |
|
282 | + } else if (!empty($invoice) && (float) $invoice->get_subtotal() <= 0) { |
|
283 | 283 | $enabled_gateway = 'manual'; |
284 | 284 | } else { |
285 | 285 | $enabled_gateway = wpinv_get_default_gateway(); |
286 | 286 | } |
287 | 287 | |
288 | - if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) { |
|
289 | - if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){ |
|
288 | + if (!wpinv_is_gateway_active($enabled_gateway) && !empty($gateways)) { |
|
289 | + if (wpinv_is_gateway_active(wpinv_get_default_gateway())) { |
|
290 | 290 | $enabled_gateway = wpinv_get_default_gateway(); |
291 | - }else{ |
|
291 | + } else { |
|
292 | 292 | $enabled_gateway = $gateways[0]; |
293 | 293 | } |
294 | 294 | |
295 | 295 | } |
296 | 296 | |
297 | - return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway ); |
|
297 | + return apply_filters('wpinv_chosen_gateway', $enabled_gateway); |
|
298 | 298 | } |
299 | 299 | |
300 | -function wpinv_record_gateway_error( $title = '', $message = '' ) { |
|
301 | - return wpinv_error_log( $message, $title ); |
|
300 | +function wpinv_record_gateway_error($title = '', $message = '') { |
|
301 | + return wpinv_error_log($message, $title); |
|
302 | 302 | } |
303 | 303 | |
304 | -function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) { |
|
304 | +function wpinv_count_sales_by_gateway($gateway_id = 'paypal', $status = 'publish') { |
|
305 | 305 | $ret = 0; |
306 | 306 | $args = array( |
307 | 307 | 'meta_key' => '_wpinv_gateway', |
@@ -312,48 +312,48 @@ discard block |
||
312 | 312 | 'fields' => 'ids' |
313 | 313 | ); |
314 | 314 | |
315 | - $payments = new WP_Query( $args ); |
|
315 | + $payments = new WP_Query($args); |
|
316 | 316 | |
317 | - if( $payments ) |
|
317 | + if ($payments) |
|
318 | 318 | $ret = $payments->post_count; |
319 | 319 | return $ret; |
320 | 320 | } |
321 | 321 | |
322 | -function wpinv_settings_update_gateways( $input ) { |
|
322 | +function wpinv_settings_update_gateways($input) { |
|
323 | 323 | global $wpinv_options; |
324 | 324 | |
325 | - if ( !empty( $input['save_gateway'] ) ) { |
|
326 | - $gateways = wpinv_get_option( 'gateways', array( 'manual' => 1 ) ); |
|
325 | + if (!empty($input['save_gateway'])) { |
|
326 | + $gateways = wpinv_get_option('gateways', array('manual' => 1)); |
|
327 | 327 | $gateways = !empty($gateways) ? $gateways : array(); |
328 | 328 | $gateway = $input['save_gateway']; |
329 | 329 | |
330 | - if ( !empty( $input[$gateway . '_active'] ) ) { |
|
330 | + if (!empty($input[$gateway . '_active'])) { |
|
331 | 331 | $gateways[$gateway] = 1; |
332 | 332 | } else { |
333 | - if ( isset( $gateways[$gateway] ) ) { |
|
334 | - unset( $gateways[$gateway] ); |
|
333 | + if (isset($gateways[$gateway])) { |
|
334 | + unset($gateways[$gateway]); |
|
335 | 335 | } |
336 | 336 | } |
337 | 337 | |
338 | 338 | $input['gateways'] = $gateways; |
339 | 339 | } |
340 | 340 | |
341 | - if ( !empty( $input['default_gateway'] ) ) { |
|
341 | + if (!empty($input['default_gateway'])) { |
|
342 | 342 | $gateways = wpinv_get_payment_gateways(); |
343 | 343 | |
344 | - foreach ( $gateways as $key => $gateway ) { |
|
345 | - $active = 0; |
|
346 | - if ( !empty( $input['gateways'] ) && !empty( $input['gateways'][$key] ) ) { |
|
344 | + foreach ($gateways as $key => $gateway) { |
|
345 | + $active = 0; |
|
346 | + if (!empty($input['gateways']) && !empty($input['gateways'][$key])) { |
|
347 | 347 | $active = 1; |
348 | 348 | } |
349 | 349 | |
350 | 350 | $input[$key . '_active'] = $active; |
351 | 351 | |
352 | - if ( empty( $wpinv_options[$key . '_title'] ) ) { |
|
352 | + if (empty($wpinv_options[$key . '_title'])) { |
|
353 | 353 | $input[$key . '_title'] = $gateway['checkout_label']; |
354 | 354 | } |
355 | 355 | |
356 | - if ( !isset( $wpinv_options[$key . '_ordering'] ) && isset( $gateway['ordering'] ) ) { |
|
356 | + if (!isset($wpinv_options[$key . '_ordering']) && isset($gateway['ordering'])) { |
|
357 | 357 | $input[$key . '_ordering'] = $gateway['ordering']; |
358 | 358 | } |
359 | 359 | } |
@@ -361,27 +361,27 @@ discard block |
||
361 | 361 | |
362 | 362 | return $input; |
363 | 363 | } |
364 | -add_filter( 'wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1 ); |
|
364 | +add_filter('wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1); |
|
365 | 365 | |
366 | 366 | // PayPal Standard settings |
367 | -function wpinv_gateway_settings_paypal( $setting ) { |
|
368 | - $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing' ); |
|
369 | - $setting['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
|
367 | +function wpinv_gateway_settings_paypal($setting) { |
|
368 | + $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __('( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing'); |
|
369 | + $setting['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing'); |
|
370 | 370 | |
371 | 371 | $setting['paypal_sandbox'] = array( |
372 | 372 | 'type' => 'checkbox', |
373 | 373 | 'id' => 'paypal_sandbox', |
374 | - 'name' => __( 'PayPal Sandbox', 'invoicing' ), |
|
375 | - 'desc' => __( 'PayPal sandbox can be used to test payments.', 'invoicing' ), |
|
374 | + 'name' => __('PayPal Sandbox', 'invoicing'), |
|
375 | + 'desc' => __('PayPal sandbox can be used to test payments.', 'invoicing'), |
|
376 | 376 | 'std' => 1 |
377 | 377 | ); |
378 | 378 | |
379 | 379 | $setting['paypal_email'] = array( |
380 | 380 | 'type' => 'text', |
381 | 381 | 'id' => 'paypal_email', |
382 | - 'name' => __( 'PayPal Email', 'invoicing' ), |
|
383 | - 'desc' => __( 'Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing' ), |
|
384 | - 'std' => __( '[email protected]', 'invoicing' ), |
|
382 | + 'name' => __('PayPal Email', 'invoicing'), |
|
383 | + 'desc' => __('Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing'), |
|
384 | + 'std' => __('[email protected]', 'invoicing'), |
|
385 | 385 | ); |
386 | 386 | /* |
387 | 387 | $setting['paypal_ipn_url'] = array( |
@@ -395,18 +395,18 @@ discard block |
||
395 | 395 | |
396 | 396 | return $setting; |
397 | 397 | } |
398 | -add_filter( 'wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1 ); |
|
398 | +add_filter('wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1); |
|
399 | 399 | |
400 | 400 | /** |
401 | 401 | * Displays the ipn url field. |
402 | 402 | */ |
403 | -function wpinv_ipn_url_callback( $args ) { |
|
404 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
403 | +function wpinv_ipn_url_callback($args) { |
|
404 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
405 | 405 | |
406 | 406 | $attrs = $args['readonly'] ? ' readonly' : ''; |
407 | 407 | |
408 | - $html = '<input class="regular-text" type="text" ' . $attrs . ' value="' . esc_attr( $args['std'] ) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" onClick="this.select()">'; |
|
409 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>'; |
|
408 | + $html = '<input class="regular-text" type="text" ' . $attrs . ' value="' . esc_attr($args['std']) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" onClick="this.select()">'; |
|
409 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>'; |
|
410 | 410 | |
411 | 411 | echo $html; |
412 | 412 | } |
@@ -418,10 +418,10 @@ discard block |
||
418 | 418 | * |
419 | 419 | * @return bool |
420 | 420 | */ |
421 | -function wpinv_is_test_mode( $gateway = '' ) { |
|
422 | - $sandbox = empty( $gateway ) ? false : wpinv_get_option( "{$gateway}_sandbox", true ); |
|
423 | - $supports = getpaid_payment_gateway_supports( $gateway, 'sandbox' ); |
|
424 | - return apply_filters( 'wpinv_is_test_mode', $sandbox && $supports, $gateway ); |
|
421 | +function wpinv_is_test_mode($gateway = '') { |
|
422 | + $sandbox = empty($gateway) ? false : wpinv_get_option("{$gateway}_sandbox", true); |
|
423 | + $supports = getpaid_payment_gateway_supports($gateway, 'sandbox'); |
|
424 | + return apply_filters('wpinv_is_test_mode', $sandbox && $supports, $gateway); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | * |
433 | 433 | * @return string |
434 | 434 | */ |
435 | -function wpinv_get_ipn_url( $gateway = false, $args = array() ) { |
|
435 | +function wpinv_get_ipn_url($gateway = false, $args = array()) { |
|
436 | 436 | $args = wp_parse_args( |
437 | 437 | array( |
438 | 438 | 'wpi-listener' => 'IPN', |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | $args |
442 | 442 | ); |
443 | 443 | |
444 | - return apply_filters( 'wpinv_ipn_url', add_query_arg( $args, home_url( 'index.php' ) ), $gateway, $args ); |
|
444 | + return apply_filters('wpinv_ipn_url', add_query_arg($args, home_url('index.php')), $gateway, $args); |
|
445 | 445 | |
446 | 446 | } |
447 | 447 | |
@@ -452,34 +452,34 @@ discard block |
||
452 | 452 | * |
453 | 453 | * @return string |
454 | 454 | */ |
455 | -function getpaid_get_non_query_string_ipn_url( $gateway ) { |
|
456 | - $gateway = wpinv_sanitize_key( $gateway ); |
|
457 | - return home_url( "getpaid-ipn/$gateway" ); |
|
455 | +function getpaid_get_non_query_string_ipn_url($gateway) { |
|
456 | + $gateway = wpinv_sanitize_key($gateway); |
|
457 | + return home_url("getpaid-ipn/$gateway"); |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | |
461 | 461 | /** |
462 | 462 | * Retrieves request data with slashes removed slashes. |
463 | 463 | */ |
464 | -function wpinv_get_post_data( $method = 'request' ) { |
|
464 | +function wpinv_get_post_data($method = 'request') { |
|
465 | 465 | |
466 | - if ( $method == 'post' ) { |
|
467 | - return wp_unslash( $_POST ); |
|
466 | + if ($method == 'post') { |
|
467 | + return wp_unslash($_POST); |
|
468 | 468 | } |
469 | 469 | |
470 | - if ( $method == 'get' ) { |
|
471 | - return wp_unslash( $_GET ); |
|
470 | + if ($method == 'get') { |
|
471 | + return wp_unslash($_GET); |
|
472 | 472 | } |
473 | 473 | |
474 | - return wp_unslash( $_REQUEST ); |
|
474 | + return wp_unslash($_REQUEST); |
|
475 | 475 | |
476 | 476 | } |
477 | 477 | |
478 | 478 | /** |
479 | 479 | * Checks if a given gateway supports subscription payments. |
480 | 480 | */ |
481 | -function wpinv_gateway_support_subscription( $gateway ) { |
|
482 | - return getpaid_payment_gateway_supports( $gateway, 'subscription' ); |
|
481 | +function wpinv_gateway_support_subscription($gateway) { |
|
482 | + return getpaid_payment_gateway_supports($gateway, 'subscription'); |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | /** |
@@ -488,14 +488,14 @@ discard block |
||
488 | 488 | * @param array $gateways an array of gateways. |
489 | 489 | * @param GetPaid_Payment_Form $form payment form. |
490 | 490 | */ |
491 | -function wpinv_payment_gateways_on_cart( $gateways, $form ) { |
|
491 | +function wpinv_payment_gateways_on_cart($gateways, $form) { |
|
492 | 492 | |
493 | - if ( $form->is_recurring() ) { |
|
493 | + if ($form->is_recurring()) { |
|
494 | 494 | |
495 | - foreach ( array_keys( $gateways ) as $gateway ) { |
|
495 | + foreach (array_keys($gateways) as $gateway) { |
|
496 | 496 | |
497 | - if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
498 | - unset( $gateways[$gateway] ); |
|
497 | + if (!wpinv_gateway_support_subscription($gateway)) { |
|
498 | + unset($gateways[$gateway]); |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | } |
@@ -504,4 +504,4 @@ discard block |
||
504 | 504 | |
505 | 505 | return $gateways; |
506 | 506 | } |
507 | -add_filter( 'getpaid_payment_form_gateways', 'wpinv_payment_gateways_on_cart', 10, 2 ); |
|
507 | +add_filter('getpaid_payment_form_gateways', 'wpinv_payment_gateways_on_cart', 10, 2); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Manual Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'addons', 'multiple_subscriptions' ); |
|
27 | + protected $supports = array('subscription', 'addons', 'multiple_subscriptions'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -39,10 +39,10 @@ discard block |
||
39 | 39 | public function __construct() { |
40 | 40 | parent::__construct(); |
41 | 41 | |
42 | - $this->title = __( 'Test Gateway', 'invoicing' ); |
|
43 | - $this->method_title = __( 'Test Gateway', 'invoicing' ); |
|
42 | + $this->title = __('Test Gateway', 'invoicing'); |
|
43 | + $this->method_title = __('Test Gateway', 'invoicing'); |
|
44 | 44 | |
45 | - add_filter( 'getpaid_daily_maintenance_should_expire_subscription', array( $this, 'maybe_renew_subscription' ), 10, 2 ); |
|
45 | + add_filter('getpaid_daily_maintenance_should_expire_subscription', array($this, 'maybe_renew_subscription'), 10, 2); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -54,16 +54,16 @@ discard block |
||
54 | 54 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
55 | 55 | * @return array |
56 | 56 | */ |
57 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
57 | + public function process_payment($invoice, $submission_data, $submission) { |
|
58 | 58 | |
59 | 59 | // Mark it as paid. |
60 | 60 | $invoice->mark_paid(); |
61 | 61 | |
62 | 62 | // (Maybe) activate subscription. |
63 | - getpaid_activate_invoice_subscription( $invoice ); |
|
63 | + getpaid_activate_invoice_subscription($invoice); |
|
64 | 64 | |
65 | 65 | // Send to the success page. |
66 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
66 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
67 | 67 | |
68 | 68 | } |
69 | 69 | |
@@ -74,15 +74,15 @@ discard block |
||
74 | 74 | * @param bool $should_expire |
75 | 75 | * @param WPInv_Subscription $subscription |
76 | 76 | */ |
77 | - public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
77 | + public function maybe_renew_subscription($should_expire, $subscription) { |
|
78 | 78 | |
79 | 79 | // Ensure its our subscription && it's active. |
80 | - if ( 'manual' != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) { |
|
80 | + if ('manual' != $subscription->get_gateway() || !$subscription->has_status('active trialling')) { |
|
81 | 81 | return $should_expire; |
82 | 82 | } |
83 | 83 | |
84 | 84 | // If this is the last renewal, complete the subscription. |
85 | - if ( $subscription->is_last_renewal() ) { |
|
85 | + if ($subscription->is_last_renewal()) { |
|
86 | 86 | $subscription->complete(); |
87 | 87 | return false; |
88 | 88 | } |
@@ -108,10 +108,10 @@ discard block |
||
108 | 108 | * @param GetPaid_Form_Item[] $items |
109 | 109 | * @return WPInv_Invoice |
110 | 110 | */ |
111 | - public function process_addons( $invoice, $items ) { |
|
111 | + public function process_addons($invoice, $items) { |
|
112 | 112 | |
113 | - foreach ( $items as $item ) { |
|
114 | - $invoice->add_item( $item ); |
|
113 | + foreach ($items as $item) { |
|
114 | + $invoice->add_item($item); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | $invoice->recalculate_total(); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Abstaract Payment Gateway class. |
@@ -139,49 +139,49 @@ discard block |
||
139 | 139 | public function __construct() { |
140 | 140 | |
141 | 141 | // Register gateway. |
142 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
142 | + add_filter('wpinv_payment_gateways', array($this, 'register_gateway')); |
|
143 | 143 | |
144 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
144 | + $this->enabled = wpinv_is_gateway_active($this->id); |
|
145 | 145 | |
146 | 146 | // Add support for various features. |
147 | - foreach ( $this->supports as $feature ) { |
|
148 | - add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
147 | + foreach ($this->supports as $feature) { |
|
148 | + add_filter("getpaid_{$this->id}_supports_{$feature}", '__return_true'); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | // Invoice addons. |
152 | - if ( $this->supports( 'addons' ) ) { |
|
153 | - add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
152 | + if ($this->supports('addons')) { |
|
153 | + add_action("getpaid_process_{$this->id}_invoice_addons", array($this, 'process_addons'), 10, 2); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | // Gateway settings. |
157 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
157 | + add_filter("wpinv_gateway_settings_{$this->id}", array($this, 'admin_settings')); |
|
158 | 158 | |
159 | 159 | |
160 | 160 | // Gateway checkout fiellds. |
161 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
161 | + add_action("wpinv_{$this->id}_cc_form", array($this, 'payment_fields'), 10, 2); |
|
162 | 162 | |
163 | 163 | // Process payment. |
164 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
164 | + add_action("getpaid_gateway_{$this->id}", array($this, 'process_payment'), 10, 3); |
|
165 | 165 | |
166 | 166 | // Change the checkout button text. |
167 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
168 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
167 | + if (!empty($this->checkout_button_text)) { |
|
168 | + add_filter("getpaid_gateway_{$this->id}_checkout_button_label", array($this, 'rename_checkout_button')); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | // Check if a gateway is valid for a given currency. |
172 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
172 | + add_filter("getpaid_gateway_{$this->id}_is_valid_for_currency", array($this, 'validate_currency'), 10, 2); |
|
173 | 173 | |
174 | 174 | // Generate the transaction url. |
175 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
175 | + add_filter("getpaid_gateway_{$this->id}_transaction_url", array($this, 'filter_transaction_url'), 10, 2); |
|
176 | 176 | |
177 | 177 | // Generate the subscription url. |
178 | - add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
178 | + add_filter('getpaid_remote_subscription_profile_url', array($this, 'generate_subscription_url'), 10, 2); |
|
179 | 179 | |
180 | 180 | // Confirm payments. |
181 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
181 | + add_filter("wpinv_payment_confirm_{$this->id}", array($this, 'confirm_payment'), 10, 2); |
|
182 | 182 | |
183 | 183 | // Verify IPNs. |
184 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
184 | + add_action("wpinv_verify_{$this->id}_ipn", array($this, 'verify_ipn')); |
|
185 | 185 | |
186 | 186 | } |
187 | 187 | |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | * @since 1.0.19 |
192 | 192 | * @return bool |
193 | 193 | */ |
194 | - public function is( $gateway ) { |
|
194 | + public function is($gateway) { |
|
195 | 195 | return $gateway == $this->id; |
196 | 196 | } |
197 | 197 | |
@@ -201,23 +201,23 @@ discard block |
||
201 | 201 | * @since 1.0.19 |
202 | 202 | * @return array |
203 | 203 | */ |
204 | - public function get_tokens( $sandbox = null ) { |
|
204 | + public function get_tokens($sandbox = null) { |
|
205 | 205 | |
206 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
207 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
206 | + if (is_user_logged_in() && $this->supports('tokens') && 0 == count($this->tokens)) { |
|
207 | + $tokens = get_user_meta(get_current_user_id(), "getpaid_{$this->id}_tokens", true); |
|
208 | 208 | |
209 | - if ( is_array( $tokens ) ) { |
|
209 | + if (is_array($tokens)) { |
|
210 | 210 | $this->tokens = $tokens; |
211 | 211 | } |
212 | 212 | |
213 | 213 | } |
214 | 214 | |
215 | - if ( ! is_bool( $sandbox ) ) { |
|
215 | + if (!is_bool($sandbox)) { |
|
216 | 216 | return $this->tokens; |
217 | 217 | } |
218 | 218 | |
219 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
220 | - return wp_list_filter( $this->tokens, $args ); |
|
219 | + $args = array('type' => $sandbox ? 'sandbox' : 'live'); |
|
220 | + return wp_list_filter($this->tokens, $args); |
|
221 | 221 | |
222 | 222 | } |
223 | 223 | |
@@ -226,12 +226,12 @@ discard block |
||
226 | 226 | * |
227 | 227 | * @since 1.0.19 |
228 | 228 | */ |
229 | - public function save_token( $token ) { |
|
229 | + public function save_token($token) { |
|
230 | 230 | |
231 | 231 | $tokens = $this->get_tokens(); |
232 | 232 | $tokens[] = $token; |
233 | 233 | |
234 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
234 | + update_user_meta(get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens); |
|
235 | 235 | |
236 | 236 | $this->tokens = $tokens; |
237 | 237 | |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | * @return string |
244 | 244 | */ |
245 | 245 | public function get_method_title() { |
246 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
246 | + return apply_filters('getpaid_gateway_method_title', $this->method_title, $this); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | /** |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | * @return string |
253 | 253 | */ |
254 | 254 | public function get_method_description() { |
255 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
255 | + return apply_filters('getpaid_gateway_method_description', $this->method_description, $this); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | * @param WPInv_Invoice $invoice Invoice object. |
262 | 262 | * @return string |
263 | 263 | */ |
264 | - public function get_return_url( $invoice ) { |
|
264 | + public function get_return_url($invoice) { |
|
265 | 265 | |
266 | 266 | // Payment success url |
267 | 267 | $return_url = add_query_arg( |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | wpinv_get_success_page_uri() |
274 | 274 | ); |
275 | 275 | |
276 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
276 | + return apply_filters('getpaid_gateway_success_url', $return_url, $invoice, $this); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | /** |
@@ -282,24 +282,24 @@ discard block |
||
282 | 282 | * @param string $content Success page content. |
283 | 283 | * @return string |
284 | 284 | */ |
285 | - public function confirm_payment( $content ) { |
|
285 | + public function confirm_payment($content) { |
|
286 | 286 | |
287 | 287 | // Retrieve the invoice. |
288 | 288 | $invoice_id = getpaid_get_current_invoice_id(); |
289 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
289 | + $invoice = wpinv_get_invoice($invoice_id); |
|
290 | 290 | |
291 | 291 | // Ensure that it exists and that it is pending payment. |
292 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
292 | + if (empty($invoice_id) || !$invoice->needs_payment()) { |
|
293 | 293 | return $content; |
294 | 294 | } |
295 | 295 | |
296 | 296 | // Can the user view this invoice?? |
297 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
297 | + if (!wpinv_user_can_view_invoice($invoice)) { |
|
298 | 298 | return $content; |
299 | 299 | } |
300 | 300 | |
301 | 301 | // Show payment processing indicator. |
302 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
302 | + return wpinv_get_template_html('wpinv-payment-processing.php', compact('invoice')); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | /** |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | * @param GetPaid_Form_Item[] $items |
317 | 317 | * @return WPInv_Invoice |
318 | 318 | */ |
319 | - public function process_addons( $invoice, $items ) { |
|
319 | + public function process_addons($invoice, $items) { |
|
320 | 320 | |
321 | 321 | } |
322 | 322 | |
@@ -327,14 +327,14 @@ discard block |
||
327 | 327 | * @param WPInv_Invoice $invoice Invoice object. |
328 | 328 | * @return string transaction URL, or empty string. |
329 | 329 | */ |
330 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
330 | + public function filter_transaction_url($transaction_url, $invoice) { |
|
331 | 331 | |
332 | - $transaction_id = $invoice->get_transaction_id(); |
|
332 | + $transaction_id = $invoice->get_transaction_id(); |
|
333 | 333 | |
334 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
335 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
336 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
337 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
334 | + if (!empty($this->view_transaction_url) && !empty($transaction_id)) { |
|
335 | + $transaction_url = sprintf($this->view_transaction_url, $transaction_id); |
|
336 | + $replace = $this->is_sandbox($invoice) ? 'sandbox' : ''; |
|
337 | + $transaction_url = str_replace('{sandbox}', $replace, $transaction_url); |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | return $transaction_url; |
@@ -347,15 +347,15 @@ discard block |
||
347 | 347 | * @param WPInv_Subscription $subscription Subscription objectt. |
348 | 348 | * @return string subscription URL, or empty string. |
349 | 349 | */ |
350 | - public function generate_subscription_url( $subscription_url, $subscription ) { |
|
350 | + public function generate_subscription_url($subscription_url, $subscription) { |
|
351 | 351 | |
352 | - $profile_id = $subscription->get_profile_id(); |
|
352 | + $profile_id = $subscription->get_profile_id(); |
|
353 | 353 | |
354 | - if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
354 | + if ($this->id == $subscription->get_gateway() && !empty($this->view_subscription_url) && !empty($profile_id)) { |
|
355 | 355 | |
356 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
357 | - $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
358 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
356 | + $subscription_url = sprintf($this->view_subscription_url, $profile_id); |
|
357 | + $replace = $this->is_sandbox($subscription->get_parent_invoice()) ? 'sandbox' : ''; |
|
358 | + $subscription_url = str_replace('{sandbox}', $replace, $subscription_url); |
|
359 | 359 | |
360 | 360 | } |
361 | 361 | |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | * @return bool |
369 | 369 | */ |
370 | 370 | public function is_available() { |
371 | - return ! empty( $this->enabled ); |
|
371 | + return !empty($this->enabled); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | /** |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | * @return string |
378 | 378 | */ |
379 | 379 | public function get_title() { |
380 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
380 | + return apply_filters('getpaid_gateway_title', $this->title, $this); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | /** |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | * @return string |
387 | 387 | */ |
388 | 388 | public function get_description() { |
389 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
389 | + return apply_filters('getpaid_gateway_description', $this->description, $this); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | /** |
@@ -398,9 +398,9 @@ discard block |
||
398 | 398 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
399 | 399 | * @return void |
400 | 400 | */ |
401 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
401 | + public function process_payment($invoice, $submission_data, $submission) { |
|
402 | 402 | // Process the payment then either redirect to the success page or the gateway. |
403 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
403 | + do_action('getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | /** |
@@ -414,8 +414,8 @@ discard block |
||
414 | 414 | * @param string $reason Refund reason. |
415 | 415 | * @return WP_Error|bool True or false based on success, or a WP_Error object. |
416 | 416 | */ |
417 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
418 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
417 | + public function process_refund($invoice, $amount = null, $reason = '') { |
|
418 | + return apply_filters('getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason); |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | /** |
@@ -424,8 +424,8 @@ discard block |
||
424 | 424 | * @param int $invoice_id 0 or invoice id. |
425 | 425 | * @param GetPaid_Payment_Form $form Current payment form. |
426 | 426 | */ |
427 | - public function payment_fields( $invoice_id, $form ) { |
|
428 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
427 | + public function payment_fields($invoice_id, $form) { |
|
428 | + do_action('getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form); |
|
429 | 429 | } |
430 | 430 | |
431 | 431 | /** |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | * |
434 | 434 | * @param array $admin_settings |
435 | 435 | */ |
436 | - public function admin_settings( $admin_settings ) { |
|
436 | + public function admin_settings($admin_settings) { |
|
437 | 437 | return $admin_settings; |
438 | 438 | } |
439 | 439 | |
@@ -442,8 +442,8 @@ discard block |
||
442 | 442 | * |
443 | 443 | * @param string $option |
444 | 444 | */ |
445 | - public function get_option( $option, $default = false ) { |
|
446 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
445 | + public function get_option($option, $default = false) { |
|
446 | + return wpinv_get_option($this->id . '_' . $option, $default); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -456,8 +456,8 @@ discard block |
||
456 | 456 | * @return bool True if the gateway supports the feature, false otherwise. |
457 | 457 | * @since 1.0.19 |
458 | 458 | */ |
459 | - public function supports( $feature ) { |
|
460 | - return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
459 | + public function supports($feature) { |
|
460 | + return getpaid_payment_gateway_supports($this->id, $feature); |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | /** |
@@ -465,36 +465,36 @@ discard block |
||
465 | 465 | * |
466 | 466 | * @param bool $save whether or not to display the save button. |
467 | 467 | */ |
468 | - public function get_cc_form( $save = false ) { |
|
468 | + public function get_cc_form($save = false) { |
|
469 | 469 | |
470 | 470 | ob_start(); |
471 | 471 | |
472 | - $id_prefix = esc_attr( uniqid( $this->id ) ); |
|
472 | + $id_prefix = esc_attr(uniqid($this->id)); |
|
473 | 473 | |
474 | 474 | $months = array( |
475 | - '01' => __( 'January', 'invoicing' ), |
|
476 | - '02' => __( 'February', 'invoicing' ), |
|
477 | - '03' => __( 'March', 'invoicing' ), |
|
478 | - '04' => __( 'April', 'invoicing' ), |
|
479 | - '05' => __( 'May', 'invoicing' ), |
|
480 | - '06' => __( 'June', 'invoicing' ), |
|
481 | - '07' => __( 'July', 'invoicing' ), |
|
482 | - '08' => __( 'August', 'invoicing' ), |
|
483 | - '09' => __( 'September', 'invoicing' ), |
|
484 | - '10' => __( 'October', 'invoicing' ), |
|
485 | - '11' => __( 'November', 'invoicing' ), |
|
486 | - '12' => __( 'December', 'invoicing' ), |
|
475 | + '01' => __('January', 'invoicing'), |
|
476 | + '02' => __('February', 'invoicing'), |
|
477 | + '03' => __('March', 'invoicing'), |
|
478 | + '04' => __('April', 'invoicing'), |
|
479 | + '05' => __('May', 'invoicing'), |
|
480 | + '06' => __('June', 'invoicing'), |
|
481 | + '07' => __('July', 'invoicing'), |
|
482 | + '08' => __('August', 'invoicing'), |
|
483 | + '09' => __('September', 'invoicing'), |
|
484 | + '10' => __('October', 'invoicing'), |
|
485 | + '11' => __('November', 'invoicing'), |
|
486 | + '12' => __('December', 'invoicing'), |
|
487 | 487 | ); |
488 | 488 | |
489 | - $year = (int) date( 'Y', current_time( 'timestamp' ) ); |
|
489 | + $year = (int) date('Y', current_time('timestamp')); |
|
490 | 490 | $years = array(); |
491 | 491 | |
492 | - for ( $i = 0; $i <= 10; $i++ ) { |
|
493 | - $years[ $year + $i ] = $year + $i; |
|
492 | + for ($i = 0; $i <= 10; $i++) { |
|
493 | + $years[$year + $i] = $year + $i; |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | ?> |
497 | - <div class="<?php echo esc_attr( $this->id );?>-cc-form getpaid-cc-form mt-1"> |
|
497 | + <div class="<?php echo esc_attr($this->id); ?>-cc-form getpaid-cc-form mt-1"> |
|
498 | 498 | |
499 | 499 | |
500 | 500 | <div class="getpaid-cc-card-inner"> |
@@ -503,14 +503,14 @@ discard block |
||
503 | 503 | <div class="col-12"> |
504 | 504 | |
505 | 505 | <div class="form-group"> |
506 | - <label for="<?php echo esc_attr( "$id_prefix-cc-number" ) ?>"><?php _e( 'Card number', 'invoicing' ); ?></label> |
|
506 | + <label for="<?php echo esc_attr("$id_prefix-cc-number") ?>"><?php _e('Card number', 'invoicing'); ?></label> |
|
507 | 507 | <div class="input-group input-group-sm"> |
508 | 508 | <div class="input-group-prepend "> |
509 | 509 | <span class="input-group-text"> |
510 | 510 | <i class="fa fa-credit-card"></i> |
511 | 511 | </span> |
512 | 512 | </div> |
513 | - <input type="text" name="<?php echo esc_attr( $this->id . '[cc_number]' ) ?>authorizenet[cc_number]" id="<?php echo esc_attr( "$id_prefix-cc-number" ) ?>" class="form-control form-control-sm" autocomplete="cc-number"> |
|
513 | + <input type="text" name="<?php echo esc_attr($this->id . '[cc_number]') ?>authorizenet[cc_number]" id="<?php echo esc_attr("$id_prefix-cc-number") ?>" class="form-control form-control-sm" autocomplete="cc-number"> |
|
514 | 514 | </div> |
515 | 515 | </div> |
516 | 516 | |
@@ -518,17 +518,17 @@ discard block |
||
518 | 518 | |
519 | 519 | <div class="col-12"> |
520 | 520 | <div class="form-group"> |
521 | - <label><?php _e( 'Expiration', 'invoicing' ); ?></label> |
|
521 | + <label><?php _e('Expiration', 'invoicing'); ?></label> |
|
522 | 522 | <div class="form-row"> |
523 | 523 | |
524 | 524 | <div class="col"> |
525 | - <select class="form-control form-control-sm" autocomplete="cc-exp-month" name="<?php echo esc_attr( $this->id );?>[cc_expire_month]"> |
|
526 | - <option disabled selected="selected"><?php _e( 'MM', 'invoicing' ); ?></option> |
|
525 | + <select class="form-control form-control-sm" autocomplete="cc-exp-month" name="<?php echo esc_attr($this->id); ?>[cc_expire_month]"> |
|
526 | + <option disabled selected="selected"><?php _e('MM', 'invoicing'); ?></option> |
|
527 | 527 | |
528 | 528 | <?php |
529 | - foreach ( $months as $key => $month ) { |
|
530 | - $key = esc_attr( $key ); |
|
531 | - $month = wpinv_clean( $month ); |
|
529 | + foreach ($months as $key => $month) { |
|
530 | + $key = esc_attr($key); |
|
531 | + $month = wpinv_clean($month); |
|
532 | 532 | echo "<option value='$key'>$month</option>" . PHP_EOL; |
533 | 533 | } |
534 | 534 | ?> |
@@ -537,13 +537,13 @@ discard block |
||
537 | 537 | </div> |
538 | 538 | |
539 | 539 | <div class="col"> |
540 | - <select class="form-control form-control-sm" autocomplete="cc-exp-year" name="<?php echo esc_attr( $this->id );?>[cc_expire_year]"> |
|
541 | - <option disabled selected="selected"><?php _e( 'YY', 'invoicing' ); ?></option> |
|
540 | + <select class="form-control form-control-sm" autocomplete="cc-exp-year" name="<?php echo esc_attr($this->id); ?>[cc_expire_year]"> |
|
541 | + <option disabled selected="selected"><?php _e('YY', 'invoicing'); ?></option> |
|
542 | 542 | |
543 | 543 | <?php |
544 | - foreach ( $years as $key => $year ) { |
|
545 | - $key = esc_attr( $key ); |
|
546 | - $year = wpinv_clean( $year ); |
|
544 | + foreach ($years as $key => $year) { |
|
545 | + $key = esc_attr($key); |
|
546 | + $year = wpinv_clean($year); |
|
547 | 547 | echo "<option value='$key'>$year</option>" . PHP_EOL; |
548 | 548 | } |
549 | 549 | ?> |
@@ -561,7 +561,7 @@ discard block |
||
561 | 561 | array( |
562 | 562 | 'name' => $this->id . '[cc_cvv2]', |
563 | 563 | 'id' => "$id_prefix-cc-cvv2", |
564 | - 'label' => __( 'CCV', 'invoicing' ), |
|
564 | + 'label' => __('CCV', 'invoicing'), |
|
565 | 565 | 'label_type' => 'vertical', |
566 | 566 | 'class' => 'form-control-sm', |
567 | 567 | 'extra_attributes' => array( |
@@ -576,7 +576,7 @@ discard block |
||
576 | 576 | |
577 | 577 | <?php |
578 | 578 | |
579 | - if ( $save ) { |
|
579 | + if ($save) { |
|
580 | 580 | echo $this->save_payment_method_checkbox(); |
581 | 581 | } |
582 | 582 | |
@@ -595,7 +595,7 @@ discard block |
||
595 | 595 | * |
596 | 596 | * @since 1.0.19 |
597 | 597 | */ |
598 | - public function new_payment_method_entry( $form ) { |
|
598 | + public function new_payment_method_entry($form) { |
|
599 | 599 | echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
600 | 600 | } |
601 | 601 | |
@@ -605,16 +605,16 @@ discard block |
||
605 | 605 | * @since 1.0.19 |
606 | 606 | */ |
607 | 607 | public function saved_payment_methods() { |
608 | - $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
608 | + $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr(count($this->get_tokens($this->is_sandbox()))) . '">'; |
|
609 | 609 | |
610 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
611 | - $html .= $this->get_saved_payment_method_option_html( $token ); |
|
610 | + foreach ($this->get_tokens($this->is_sandbox()) as $token) { |
|
611 | + $html .= $this->get_saved_payment_method_option_html($token); |
|
612 | 612 | } |
613 | 613 | |
614 | 614 | $html .= $this->get_new_payment_method_option_html(); |
615 | 615 | $html .= '</ul>'; |
616 | 616 | |
617 | - echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
617 | + echo apply_filters('getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this); |
|
618 | 618 | } |
619 | 619 | |
620 | 620 | /** |
@@ -624,7 +624,7 @@ discard block |
||
624 | 624 | * @param array $token Payment Token. |
625 | 625 | * @return string Generated payment method HTML |
626 | 626 | */ |
627 | - public function get_saved_payment_method_option_html( $token ) { |
|
627 | + public function get_saved_payment_method_option_html($token) { |
|
628 | 628 | |
629 | 629 | return sprintf( |
630 | 630 | '<li class="getpaid-payment-method form-group"> |
@@ -633,10 +633,10 @@ discard block |
||
633 | 633 | <span>%3$s</span> |
634 | 634 | </label> |
635 | 635 | </li>', |
636 | - esc_attr( $this->id ), |
|
637 | - esc_attr( $token['id'] ), |
|
638 | - esc_html( $token['name'] ), |
|
639 | - checked( empty( $token['default'] ), false, false ) |
|
636 | + esc_attr($this->id), |
|
637 | + esc_attr($token['id']), |
|
638 | + esc_html($token['name']), |
|
639 | + checked(empty($token['default']), false, false) |
|
640 | 640 | ); |
641 | 641 | |
642 | 642 | } |
@@ -648,7 +648,7 @@ discard block |
||
648 | 648 | */ |
649 | 649 | public function get_new_payment_method_option_html() { |
650 | 650 | |
651 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
651 | + $label = apply_filters('getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __('Use a new payment method', 'invoicing'), $this); |
|
652 | 652 | |
653 | 653 | return sprintf( |
654 | 654 | '<li class="getpaid-new-payment-method"> |
@@ -657,8 +657,8 @@ discard block |
||
657 | 657 | <span>%2$s</span> |
658 | 658 | </label> |
659 | 659 | </li>', |
660 | - esc_attr( $this->id ), |
|
661 | - esc_html( $label ) |
|
660 | + esc_attr($this->id), |
|
661 | + esc_html($label) |
|
662 | 662 | ); |
663 | 663 | |
664 | 664 | } |
@@ -673,10 +673,10 @@ discard block |
||
673 | 673 | return aui()->input( |
674 | 674 | array( |
675 | 675 | 'type' => 'checkbox', |
676 | - 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
677 | - 'id' => esc_attr( uniqid( $this->id ) ), |
|
676 | + 'name' => esc_attr("getpaid-$this->id-new-payment-method"), |
|
677 | + 'id' => esc_attr(uniqid($this->id)), |
|
678 | 678 | 'required' => false, |
679 | - 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
679 | + 'label' => esc_html__('Save payment method', 'invoicing'), |
|
680 | 680 | 'value' => 'true', |
681 | 681 | 'checked' => true, |
682 | 682 | 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
@@ -690,9 +690,9 @@ discard block |
||
690 | 690 | * |
691 | 691 | * @return array |
692 | 692 | */ |
693 | - public function register_gateway( $gateways ) { |
|
693 | + public function register_gateway($gateways) { |
|
694 | 694 | |
695 | - $gateways[ $this->id ] = array( |
|
695 | + $gateways[$this->id] = array( |
|
696 | 696 | |
697 | 697 | 'admin_label' => $this->method_title, |
698 | 698 | 'checkout_label' => $this->title, |
@@ -710,13 +710,13 @@ discard block |
||
710 | 710 | * @param WPInv_Invoice|null $invoice Invoice object or null. |
711 | 711 | * @return bool |
712 | 712 | */ |
713 | - public function is_sandbox( $invoice = null ) { |
|
713 | + public function is_sandbox($invoice = null) { |
|
714 | 714 | |
715 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
715 | + if (!empty($invoice) && !$invoice->needs_payment()) { |
|
716 | 716 | return $invoice->get_mode() == 'test'; |
717 | 717 | } |
718 | 718 | |
719 | - return wpinv_is_test_mode( $this->id ); |
|
719 | + return wpinv_is_test_mode($this->id); |
|
720 | 720 | |
721 | 721 | } |
722 | 722 | |
@@ -734,15 +734,15 @@ discard block |
||
734 | 734 | * |
735 | 735 | * @return bool |
736 | 736 | */ |
737 | - public function validate_currency( $validation, $currency ) { |
|
737 | + public function validate_currency($validation, $currency) { |
|
738 | 738 | |
739 | 739 | // Required currencies. |
740 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
740 | + if (!empty($this->currencies) && !in_array($currency, $this->currencies)) { |
|
741 | 741 | return false; |
742 | 742 | } |
743 | 743 | |
744 | 744 | // Excluded currencies. |
745 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
745 | + if (!empty($this->exclude_currencies) && in_array($currency, $this->exclude_currencies)) { |
|
746 | 746 | return false; |
747 | 747 | } |
748 | 748 | |
@@ -753,13 +753,13 @@ discard block |
||
753 | 753 | * Displays an error |
754 | 754 | * |
755 | 755 | */ |
756 | - public function show_error( $code, $message, $type ) { |
|
756 | + public function show_error($code, $message, $type) { |
|
757 | 757 | |
758 | - if ( is_admin() ) { |
|
759 | - getpaid_admin()->{"show_$type"}( $message ); |
|
758 | + if (is_admin()) { |
|
759 | + getpaid_admin()->{"show_$type"}($message); |
|
760 | 760 | } |
761 | 761 | |
762 | - wpinv_set_error( $code, $message, $type ); |
|
762 | + wpinv_set_error($code, $message, $type); |
|
763 | 763 | |
764 | 764 | } |
765 | 765 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | /** |
9 | 9 | * Main Subscriptions class. |
10 | 10 | * |
@@ -14,31 +14,31 @@ discard block |
||
14 | 14 | /** |
15 | 15 | * Class constructor. |
16 | 16 | */ |
17 | - public function __construct(){ |
|
17 | + public function __construct() { |
|
18 | 18 | |
19 | 19 | // Fire gateway specific hooks when a subscription changes. |
20 | - add_action( 'getpaid_subscription_status_changed', array( $this, 'process_subscription_status_change' ), 10, 3 ); |
|
20 | + add_action('getpaid_subscription_status_changed', array($this, 'process_subscription_status_change'), 10, 3); |
|
21 | 21 | |
22 | 22 | // De-activate a subscription whenever the invoice changes payment statuses. |
23 | - add_action( 'getpaid_invoice_status_wpi-refunded', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
24 | - add_action( 'getpaid_invoice_status_wpi-failed', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
25 | - add_action( 'getpaid_invoice_status_wpi-cancelled', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
26 | - add_action( 'getpaid_invoice_status_wpi-pending', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
23 | + add_action('getpaid_invoice_status_wpi-refunded', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
24 | + add_action('getpaid_invoice_status_wpi-failed', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
25 | + add_action('getpaid_invoice_status_wpi-cancelled', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
26 | + add_action('getpaid_invoice_status_wpi-pending', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
27 | 27 | |
28 | 28 | // Handles subscription cancelations. |
29 | - add_action( 'getpaid_authenticated_action_subscription_cancel', array( $this, 'user_cancel_single_subscription' ) ); |
|
29 | + add_action('getpaid_authenticated_action_subscription_cancel', array($this, 'user_cancel_single_subscription')); |
|
30 | 30 | |
31 | 31 | // Create a subscription whenever an invoice is created, (and update it when it is updated). |
32 | - add_action( 'getpaid_new_invoice', array( $this, 'maybe_create_invoice_subscription' ), 5 ); |
|
33 | - add_action( 'getpaid_update_invoice', array( $this, 'maybe_update_invoice_subscription' ), 5 ); |
|
32 | + add_action('getpaid_new_invoice', array($this, 'maybe_create_invoice_subscription'), 5); |
|
33 | + add_action('getpaid_update_invoice', array($this, 'maybe_update_invoice_subscription'), 5); |
|
34 | 34 | |
35 | 35 | // Handles admin subscription update actions. |
36 | - add_action( 'getpaid_authenticated_admin_action_update_single_subscription', array( $this, 'admin_update_single_subscription' ) ); |
|
37 | - add_action( 'getpaid_authenticated_admin_action_subscription_manual_renew', array( $this, 'admin_renew_single_subscription' ) ); |
|
38 | - add_action( 'getpaid_authenticated_admin_action_subscription_manual_delete', array( $this, 'admin_delete_single_subscription' ) ); |
|
36 | + add_action('getpaid_authenticated_admin_action_update_single_subscription', array($this, 'admin_update_single_subscription')); |
|
37 | + add_action('getpaid_authenticated_admin_action_subscription_manual_renew', array($this, 'admin_renew_single_subscription')); |
|
38 | + add_action('getpaid_authenticated_admin_action_subscription_manual_delete', array($this, 'admin_delete_single_subscription')); |
|
39 | 39 | |
40 | 40 | // Filter invoice item row actions. |
41 | - add_action( 'getpaid-invoice-page-line-item-actions', array( $this, 'filter_invoice_line_item_actions' ), 10, 3 ); |
|
41 | + add_action('getpaid-invoice-page-line-item-actions', array($this, 'filter_invoice_line_item_actions'), 10, 3); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -47,19 +47,19 @@ discard block |
||
47 | 47 | * @param WPInv_Invoice $invoice |
48 | 48 | * @return WPInv_Subscription|bool |
49 | 49 | */ |
50 | - public function get_invoice_subscription( $invoice ) { |
|
50 | + public function get_invoice_subscription($invoice) { |
|
51 | 51 | $subscription_id = $invoice->get_subscription_id(); |
52 | 52 | |
53 | 53 | // Fallback to the parent invoice if the child invoice has no subscription id. |
54 | - if ( empty( $subscription_id ) && $invoice->is_renewal() ) { |
|
54 | + if (empty($subscription_id) && $invoice->is_renewal()) { |
|
55 | 55 | $subscription_id = $invoice->get_parent_payment()->get_subscription_id(); |
56 | 56 | } |
57 | 57 | |
58 | 58 | // Fetch the subscription. |
59 | - $subscription = new WPInv_Subscription( $subscription_id ); |
|
59 | + $subscription = new WPInv_Subscription($subscription_id); |
|
60 | 60 | |
61 | 61 | // Return subscription or use a fallback for backwards compatibility. |
62 | - return $subscription->exists() ? $subscription : wpinv_get_invoice_subscription( $invoice ); |
|
62 | + return $subscription->exists() ? $subscription : wpinv_get_invoice_subscription($invoice); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -67,21 +67,21 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @param WPInv_Invoice $invoice |
69 | 69 | */ |
70 | - public function maybe_deactivate_invoice_subscription( $invoice ) { |
|
70 | + public function maybe_deactivate_invoice_subscription($invoice) { |
|
71 | 71 | |
72 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
72 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
73 | 73 | |
74 | - if ( empty( $subscriptions ) ) { |
|
74 | + if (empty($subscriptions)) { |
|
75 | 75 | return; |
76 | 76 | } |
77 | 77 | |
78 | - if ( ! is_array( $subscriptions ) ) { |
|
79 | - $subscriptions = array( $subscriptions ); |
|
78 | + if (!is_array($subscriptions)) { |
|
79 | + $subscriptions = array($subscriptions); |
|
80 | 80 | } |
81 | 81 | |
82 | - foreach ( $subscriptions as $subscription ) { |
|
83 | - if ( $subscription->is_active() ) { |
|
84 | - $subscription->set_status( 'pending' ); |
|
82 | + foreach ($subscriptions as $subscription) { |
|
83 | + if ($subscription->is_active()) { |
|
84 | + $subscription->set_status('pending'); |
|
85 | 85 | $subscription->save(); |
86 | 86 | } |
87 | 87 | } |
@@ -95,15 +95,15 @@ discard block |
||
95 | 95 | * @param string $from |
96 | 96 | * @param string $to |
97 | 97 | */ |
98 | - public function process_subscription_status_change( $subscription, $from, $to ) { |
|
98 | + public function process_subscription_status_change($subscription, $from, $to) { |
|
99 | 99 | |
100 | 100 | $gateway = $subscription->get_gateway(); |
101 | 101 | |
102 | - if ( ! empty( $gateway ) ) { |
|
103 | - $gateway = sanitize_key( $gateway ); |
|
104 | - $from = sanitize_key( $from ); |
|
105 | - $to = sanitize_key( $to ); |
|
106 | - do_action( "getpaid_{$gateway}_subscription_$to", $subscription, $from ); |
|
102 | + if (!empty($gateway)) { |
|
103 | + $gateway = sanitize_key($gateway); |
|
104 | + $from = sanitize_key($from); |
|
105 | + $to = sanitize_key($to); |
|
106 | + do_action("getpaid_{$gateway}_subscription_$to", $subscription, $from); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | } |
@@ -116,8 +116,8 @@ discard block |
||
116 | 116 | * @deprecated |
117 | 117 | * @return mixed|string|void |
118 | 118 | */ |
119 | - public static function wpinv_get_pretty_subscription_frequency( $period, $frequency_count = 1 ) { |
|
120 | - return getpaid_get_subscription_period_label( $period, $frequency_count ); |
|
119 | + public static function wpinv_get_pretty_subscription_frequency($period, $frequency_count = 1) { |
|
120 | + return getpaid_get_subscription_period_label($period, $frequency_count); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -127,33 +127,33 @@ discard block |
||
127 | 127 | * @since 1.0.0 |
128 | 128 | * @return void |
129 | 129 | */ |
130 | - public function user_cancel_single_subscription( $data ) { |
|
130 | + public function user_cancel_single_subscription($data) { |
|
131 | 131 | |
132 | 132 | // Ensure there is a subscription to cancel. |
133 | - if ( empty( $data['subscription'] ) ) { |
|
133 | + if (empty($data['subscription'])) { |
|
134 | 134 | return; |
135 | 135 | } |
136 | 136 | |
137 | - $subscription = new WPInv_Subscription( (int) $data['subscription'] ); |
|
137 | + $subscription = new WPInv_Subscription((int) $data['subscription']); |
|
138 | 138 | |
139 | 139 | // Ensure that it exists and that it belongs to the current user. |
140 | - if ( ! $subscription->exists() || $subscription->get_customer_id() != get_current_user_id() ) { |
|
141 | - wpinv_set_error( 'invalid_subscription', __( 'You do not have permission to cancel this subscription', 'invoicing' ) ); |
|
140 | + if (!$subscription->exists() || $subscription->get_customer_id() != get_current_user_id()) { |
|
141 | + wpinv_set_error('invalid_subscription', __('You do not have permission to cancel this subscription', 'invoicing')); |
|
142 | 142 | |
143 | 143 | // Can it be cancelled. |
144 | - } else if ( ! $subscription->can_cancel() ) { |
|
145 | - wpinv_set_error( 'cannot_cancel', __( 'This subscription cannot be cancelled as it is not active.', 'invoicing' ) ); |
|
144 | + } else if (!$subscription->can_cancel()) { |
|
145 | + wpinv_set_error('cannot_cancel', __('This subscription cannot be cancelled as it is not active.', 'invoicing')); |
|
146 | 146 | |
147 | 147 | // Cancel it. |
148 | 148 | } else { |
149 | 149 | |
150 | 150 | $subscription->cancel(); |
151 | - wpinv_set_error( 'cancelled', __( 'This subscription has been cancelled.', 'invoicing' ), 'info' ); |
|
151 | + wpinv_set_error('cancelled', __('This subscription has been cancelled.', 'invoicing'), 'info'); |
|
152 | 152 | } |
153 | 153 | |
154 | - $redirect = remove_query_arg( array( 'getpaid-action', 'getpaid-nonce' ) ); |
|
154 | + $redirect = remove_query_arg(array('getpaid-action', 'getpaid-nonce')); |
|
155 | 155 | |
156 | - wp_safe_redirect( $redirect ); |
|
156 | + wp_safe_redirect($redirect); |
|
157 | 157 | exit; |
158 | 158 | |
159 | 159 | } |
@@ -165,41 +165,41 @@ discard block |
||
165 | 165 | * @param WPInv_Invoice $invoice |
166 | 166 | * @since 1.0.0 |
167 | 167 | */ |
168 | - public function maybe_create_invoice_subscription( $invoice ) { |
|
168 | + public function maybe_create_invoice_subscription($invoice) { |
|
169 | 169 | global $getpaid_subscriptions_skip_invoice_update; |
170 | 170 | |
171 | 171 | // Abort if it is not recurring. |
172 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_free() || ! $invoice->is_recurring() || $invoice->is_renewal() ) { |
|
172 | + if (!$invoice->is_type('invoice') || $invoice->is_free() || !$invoice->is_recurring() || $invoice->is_renewal()) { |
|
173 | 173 | return; |
174 | 174 | } |
175 | 175 | |
176 | 176 | // Either group the subscriptions or only process a single suscription. |
177 | - if ( getpaid_should_group_subscriptions( $invoice ) ) { |
|
177 | + if (getpaid_should_group_subscriptions($invoice)) { |
|
178 | 178 | |
179 | 179 | $subscription_groups = array(); |
180 | 180 | $is_first = true; |
181 | 181 | |
182 | - foreach ( getpaid_calculate_subscription_totals( $invoice ) as $group_key => $totals ) { |
|
183 | - $subscription_groups[ $group_key ] = $this->create_invoice_subscription_group( $totals, $invoice, 0, $is_first ); |
|
182 | + foreach (getpaid_calculate_subscription_totals($invoice) as $group_key => $totals) { |
|
183 | + $subscription_groups[$group_key] = $this->create_invoice_subscription_group($totals, $invoice, 0, $is_first); |
|
184 | 184 | |
185 | - if ( $is_first ) { |
|
185 | + if ($is_first) { |
|
186 | 186 | $getpaid_subscriptions_skip_invoice_update = true; |
187 | - $invoice->set_subscription_id( $subscription_groups[ $group_key ]['subscription_id'] ); |
|
187 | + $invoice->set_subscription_id($subscription_groups[$group_key]['subscription_id']); |
|
188 | 188 | $invoice->save(); |
189 | 189 | $getpaid_subscriptions_skip_invoice_update = false; |
190 | 190 | } |
191 | 191 | |
192 | - $is_first = false; |
|
192 | + $is_first = false; |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | // Cache subscription groups. |
196 | - update_post_meta( $invoice->get_id(), 'getpaid_subscription_groups', $subscription_groups ); |
|
196 | + update_post_meta($invoice->get_id(), 'getpaid_subscription_groups', $subscription_groups); |
|
197 | 197 | return true; |
198 | 198 | |
199 | 199 | } |
200 | 200 | |
201 | 201 | $subscription = new WPInv_Subscription(); |
202 | - return $this->update_invoice_subscription( $subscription, $invoice ); |
|
202 | + return $this->update_invoice_subscription($subscription, $invoice); |
|
203 | 203 | |
204 | 204 | } |
205 | 205 | |
@@ -214,47 +214,47 @@ discard block |
||
214 | 214 | * |
215 | 215 | * @since 2.3.0 |
216 | 216 | */ |
217 | - public function create_invoice_subscription_group( $totals, $invoice, $subscription_id = 0, $is_first = false ) { |
|
217 | + public function create_invoice_subscription_group($totals, $invoice, $subscription_id = 0, $is_first = false) { |
|
218 | 218 | |
219 | - $subscription = new WPInv_Subscription( (int) $subscription_id ); |
|
219 | + $subscription = new WPInv_Subscription((int) $subscription_id); |
|
220 | 220 | $initial_amt = $totals['initial_total']; |
221 | 221 | $recurring_amt = $totals['recurring_total']; |
222 | 222 | $fees = array(); |
223 | 223 | |
224 | 224 | // Maybe add recurring fees. |
225 | - if ( $is_first ) { |
|
225 | + if ($is_first) { |
|
226 | 226 | |
227 | - foreach ( $invoice->get_fees() as $fee ) { |
|
228 | - if ( ! empty( $fee['recurring_fee'] ) ) { |
|
229 | - $initial_amt += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
230 | - $recurring_amt += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
227 | + foreach ($invoice->get_fees() as $fee) { |
|
228 | + if (!empty($fee['recurring_fee'])) { |
|
229 | + $initial_amt += wpinv_sanitize_amount($fee['initial_fee']); |
|
230 | + $recurring_amt += wpinv_sanitize_amount($fee['recurring_fee']); |
|
231 | 231 | $fees[] = $fee; |
232 | 232 | } |
233 | 233 | } |
234 | 234 | |
235 | 235 | } |
236 | 236 | |
237 | - $subscription->set_customer_id( $invoice->get_customer_id() ); |
|
238 | - $subscription->set_parent_invoice_id( $invoice->get_id() ); |
|
239 | - $subscription->set_initial_amount( $initial_amt ); |
|
240 | - $subscription->set_recurring_amount( $recurring_amt ); |
|
241 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
242 | - $subscription->set_status( $invoice->is_paid() ? 'active' : 'pending' ); |
|
243 | - $subscription->set_product_id( $totals['item_id'] ); |
|
244 | - $subscription->set_period( $totals['period'] ); |
|
245 | - $subscription->set_frequency( $totals['interval'] ); |
|
246 | - $subscription->set_bill_times( $totals['recurring_limit'] ); |
|
247 | - $subscription->set_next_renewal_date( $totals['renews_on'] ); |
|
237 | + $subscription->set_customer_id($invoice->get_customer_id()); |
|
238 | + $subscription->set_parent_invoice_id($invoice->get_id()); |
|
239 | + $subscription->set_initial_amount($initial_amt); |
|
240 | + $subscription->set_recurring_amount($recurring_amt); |
|
241 | + $subscription->set_date_created(current_time('mysql')); |
|
242 | + $subscription->set_status($invoice->is_paid() ? 'active' : 'pending'); |
|
243 | + $subscription->set_product_id($totals['item_id']); |
|
244 | + $subscription->set_period($totals['period']); |
|
245 | + $subscription->set_frequency($totals['interval']); |
|
246 | + $subscription->set_bill_times($totals['recurring_limit']); |
|
247 | + $subscription->set_next_renewal_date($totals['renews_on']); |
|
248 | 248 | |
249 | 249 | // Trial periods. |
250 | - if ( ! empty( $totals['trialling'] ) ) { |
|
251 | - $subscription->set_trial_period( $totals['trialling'] ); |
|
252 | - $subscription->set_status( 'trialling' ); |
|
250 | + if (!empty($totals['trialling'])) { |
|
251 | + $subscription->set_trial_period($totals['trialling']); |
|
252 | + $subscription->set_status('trialling'); |
|
253 | 253 | |
254 | 254 | // If initial amount is free, treat it as a free trial even if the subscription item does not have a free trial. |
255 | - } else if ( empty( $initial_amt ) ) { |
|
256 | - $subscription->set_trial_period( $totals['interval'] . ' ' . $totals['period'] ); |
|
257 | - $subscription->set_status( 'trialling' ); |
|
255 | + } else if (empty($initial_amt)) { |
|
256 | + $subscription->set_trial_period($totals['interval'] . ' ' . $totals['period']); |
|
257 | + $subscription->set_status('trialling'); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | $subscription->save(); |
@@ -272,87 +272,87 @@ discard block |
||
272 | 272 | * @param WPInv_Invoice $invoice |
273 | 273 | * @since 1.0.19 |
274 | 274 | */ |
275 | - public function maybe_update_invoice_subscription( $invoice ) { |
|
275 | + public function maybe_update_invoice_subscription($invoice) { |
|
276 | 276 | global $getpaid_subscriptions_skip_invoice_update; |
277 | 277 | |
278 | 278 | // Avoid infinite loops. |
279 | - if ( ! empty( $getpaid_subscriptions_skip_invoice_update ) ) { |
|
279 | + if (!empty($getpaid_subscriptions_skip_invoice_update)) { |
|
280 | 280 | return; |
281 | 281 | } |
282 | 282 | |
283 | 283 | // Do not process renewals. |
284 | - if ( $invoice->is_renewal() ) { |
|
284 | + if ($invoice->is_renewal()) { |
|
285 | 285 | return; |
286 | 286 | } |
287 | 287 | |
288 | 288 | // Delete existing subscriptions if available and the invoice is not recurring. |
289 | - if ( ! $invoice->is_recurring() ) { |
|
290 | - $this->delete_invoice_subscriptions( $invoice ); |
|
289 | + if (!$invoice->is_recurring()) { |
|
290 | + $this->delete_invoice_subscriptions($invoice); |
|
291 | 291 | return; |
292 | 292 | } |
293 | 293 | |
294 | 294 | // Fetch existing subscriptions. |
295 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
295 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
296 | 296 | |
297 | 297 | // Create new ones if no existing subscriptions. |
298 | - if ( empty( $subscriptions ) ) { |
|
299 | - return $this->maybe_create_invoice_subscription( $invoice ); |
|
298 | + if (empty($subscriptions)) { |
|
299 | + return $this->maybe_create_invoice_subscription($invoice); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | // Abort if an invoice is paid and already has a subscription. |
303 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
303 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
304 | 304 | return; |
305 | 305 | } |
306 | 306 | |
307 | - $is_grouped = is_array( $subscriptions ); |
|
308 | - $should_group = getpaid_should_group_subscriptions( $invoice ); |
|
307 | + $is_grouped = is_array($subscriptions); |
|
308 | + $should_group = getpaid_should_group_subscriptions($invoice); |
|
309 | 309 | |
310 | 310 | // Ensure that the subscriptions are only grouped if there are more than 1 recurring items. |
311 | - if ( $is_grouped != $should_group ) { |
|
312 | - $this->delete_invoice_subscriptions( $invoice ); |
|
313 | - delete_post_meta( $invoice->get_id(), 'getpaid_subscription_groups' ); |
|
314 | - return $this->maybe_create_invoice_subscription( $invoice ); |
|
311 | + if ($is_grouped != $should_group) { |
|
312 | + $this->delete_invoice_subscriptions($invoice); |
|
313 | + delete_post_meta($invoice->get_id(), 'getpaid_subscription_groups'); |
|
314 | + return $this->maybe_create_invoice_subscription($invoice); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | // If there is only one recurring item... |
318 | - if ( ! $is_grouped ) { |
|
319 | - return $this->update_invoice_subscription( $subscriptions, $invoice ); |
|
318 | + if (!$is_grouped) { |
|
319 | + return $this->update_invoice_subscription($subscriptions, $invoice); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | // Process subscription groups. |
323 | - $current_groups = getpaid_get_invoice_subscription_groups( $invoice->get_id() ); |
|
323 | + $current_groups = getpaid_get_invoice_subscription_groups($invoice->get_id()); |
|
324 | 324 | $subscription_groups = array(); |
325 | 325 | $is_first = true; |
326 | 326 | |
327 | 327 | // Create new subscription groups. |
328 | - foreach ( getpaid_calculate_subscription_totals( $invoice ) as $group_key => $totals ) { |
|
329 | - $subscription_id = isset( $current_groups[ $group_key ] ) ? $current_groups[ $group_key ]['subscription_id'] : 0; |
|
330 | - $subscription_groups[ $group_key ] = $this->create_invoice_subscription_group( $totals, $invoice, $subscription_id, $is_first ); |
|
328 | + foreach (getpaid_calculate_subscription_totals($invoice) as $group_key => $totals) { |
|
329 | + $subscription_id = isset($current_groups[$group_key]) ? $current_groups[$group_key]['subscription_id'] : 0; |
|
330 | + $subscription_groups[$group_key] = $this->create_invoice_subscription_group($totals, $invoice, $subscription_id, $is_first); |
|
331 | 331 | |
332 | - if ( $is_first && $invoice->get_subscription_id() !== $subscription_groups[ $group_key ]['subscription_id'] ) { |
|
332 | + if ($is_first && $invoice->get_subscription_id() !== $subscription_groups[$group_key]['subscription_id']) { |
|
333 | 333 | $getpaid_subscriptions_skip_invoice_update = true; |
334 | - $invoice->set_subscription_id( $subscription_groups[ $group_key ]['subscription_id'] ); |
|
334 | + $invoice->set_subscription_id($subscription_groups[$group_key]['subscription_id']); |
|
335 | 335 | $invoice->save(); |
336 | 336 | $getpaid_subscriptions_skip_invoice_update = false; |
337 | 337 | } |
338 | 338 | |
339 | - $is_first = false; |
|
339 | + $is_first = false; |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | // Delete non-existent subscription groups. |
343 | - foreach ( $current_groups as $group_key => $data ) { |
|
344 | - if ( ! isset( $subscription_groups[ $group_key ] ) ) { |
|
345 | - $subscription = new WPInv_Subscription( (int) $data['subscription_id'] ); |
|
343 | + foreach ($current_groups as $group_key => $data) { |
|
344 | + if (!isset($subscription_groups[$group_key])) { |
|
345 | + $subscription = new WPInv_Subscription((int) $data['subscription_id']); |
|
346 | 346 | |
347 | - if ( $subscription->exists() ) { |
|
348 | - $subscription->delete( true ); |
|
347 | + if ($subscription->exists()) { |
|
348 | + $subscription->delete(true); |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | } |
352 | 352 | } |
353 | 353 | |
354 | 354 | // Cache subscription groups. |
355 | - update_post_meta( $invoice->get_id(), 'getpaid_subscription_groups', $subscription_groups ); |
|
355 | + update_post_meta($invoice->get_id(), 'getpaid_subscription_groups', $subscription_groups); |
|
356 | 356 | return true; |
357 | 357 | |
358 | 358 | } |
@@ -362,20 +362,20 @@ discard block |
||
362 | 362 | * |
363 | 363 | * @param WPInv_Invoice $invoice |
364 | 364 | */ |
365 | - public function delete_invoice_subscriptions( $invoice ) { |
|
365 | + public function delete_invoice_subscriptions($invoice) { |
|
366 | 366 | |
367 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
367 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
368 | 368 | |
369 | - if ( empty( $subscriptions ) ) { |
|
369 | + if (empty($subscriptions)) { |
|
370 | 370 | return; |
371 | 371 | } |
372 | 372 | |
373 | - if ( ! is_array( $subscriptions ) ) { |
|
374 | - $subscriptions = array( $subscriptions ); |
|
373 | + if (!is_array($subscriptions)) { |
|
374 | + $subscriptions = array($subscriptions); |
|
375 | 375 | } |
376 | 376 | |
377 | - foreach ( $subscriptions as $subscription ) { |
|
378 | - $subscription->delete( true ); |
|
377 | + foreach ($subscriptions as $subscription) { |
|
378 | + $subscription->delete(true); |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | } |
@@ -388,57 +388,57 @@ discard block |
||
388 | 388 | * @param WPInv_Invoice $invoice |
389 | 389 | * @since 1.0.19 |
390 | 390 | */ |
391 | - public function update_invoice_subscription( $subscription, $invoice ) { |
|
391 | + public function update_invoice_subscription($subscription, $invoice) { |
|
392 | 392 | |
393 | 393 | // Delete the subscription if an invoice is free or nolonger recurring. |
394 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_free() || ! $invoice->is_recurring() ) { |
|
394 | + if (!$invoice->is_type('invoice') || $invoice->is_free() || !$invoice->is_recurring()) { |
|
395 | 395 | return $subscription->delete(); |
396 | 396 | } |
397 | 397 | |
398 | - $subscription->set_customer_id( $invoice->get_customer_id() ); |
|
399 | - $subscription->set_parent_invoice_id( $invoice->get_id() ); |
|
400 | - $subscription->set_initial_amount( $invoice->get_initial_total() ); |
|
401 | - $subscription->set_recurring_amount( $invoice->get_recurring_total() ); |
|
402 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
403 | - $subscription->set_status( $invoice->is_paid() ? 'active' : 'pending' ); |
|
398 | + $subscription->set_customer_id($invoice->get_customer_id()); |
|
399 | + $subscription->set_parent_invoice_id($invoice->get_id()); |
|
400 | + $subscription->set_initial_amount($invoice->get_initial_total()); |
|
401 | + $subscription->set_recurring_amount($invoice->get_recurring_total()); |
|
402 | + $subscription->set_date_created(current_time('mysql')); |
|
403 | + $subscription->set_status($invoice->is_paid() ? 'active' : 'pending'); |
|
404 | 404 | |
405 | 405 | // Get the recurring item and abort if it does not exist. |
406 | - $subscription_item = $invoice->get_recurring( true ); |
|
407 | - if ( ! $subscription_item->get_id() ) { |
|
406 | + $subscription_item = $invoice->get_recurring(true); |
|
407 | + if (!$subscription_item->get_id()) { |
|
408 | 408 | $invoice->set_subscription_id(0); |
409 | 409 | $invoice->save(); |
410 | 410 | return $subscription->delete(); |
411 | 411 | } |
412 | 412 | |
413 | - $subscription->set_product_id( $subscription_item->get_id() ); |
|
414 | - $subscription->set_period( $subscription_item->get_recurring_period( true ) ); |
|
415 | - $subscription->set_frequency( $subscription_item->get_recurring_interval() ); |
|
416 | - $subscription->set_bill_times( $subscription_item->get_recurring_limit() ); |
|
413 | + $subscription->set_product_id($subscription_item->get_id()); |
|
414 | + $subscription->set_period($subscription_item->get_recurring_period(true)); |
|
415 | + $subscription->set_frequency($subscription_item->get_recurring_interval()); |
|
416 | + $subscription->set_bill_times($subscription_item->get_recurring_limit()); |
|
417 | 417 | |
418 | 418 | // Calculate the next renewal date. |
419 | - $period = $subscription_item->get_recurring_period( true ); |
|
419 | + $period = $subscription_item->get_recurring_period(true); |
|
420 | 420 | $interval = $subscription_item->get_recurring_interval(); |
421 | 421 | |
422 | 422 | // If the subscription item has a trial period... |
423 | - if ( $subscription_item->has_free_trial() ) { |
|
424 | - $period = $subscription_item->get_trial_period( true ); |
|
423 | + if ($subscription_item->has_free_trial()) { |
|
424 | + $period = $subscription_item->get_trial_period(true); |
|
425 | 425 | $interval = $subscription_item->get_trial_interval(); |
426 | - $subscription->set_trial_period( $interval . ' ' . $period ); |
|
427 | - $subscription->set_status( 'trialling' ); |
|
426 | + $subscription->set_trial_period($interval . ' ' . $period); |
|
427 | + $subscription->set_status('trialling'); |
|
428 | 428 | } |
429 | 429 | |
430 | 430 | // If initial amount is free, treat it as a free trial even if the subscription item does not have a free trial. |
431 | - if ( $invoice->has_free_trial() ) { |
|
432 | - $subscription->set_trial_period( $interval . ' ' . $period ); |
|
433 | - $subscription->set_status( 'trialling' ); |
|
431 | + if ($invoice->has_free_trial()) { |
|
432 | + $subscription->set_trial_period($interval . ' ' . $period); |
|
433 | + $subscription->set_status('trialling'); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | // Calculate the next renewal date. |
437 | - $expiration = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", strtotime( $subscription->get_date_created() ) ) ); |
|
437 | + $expiration = date('Y-m-d H:i:s', strtotime("+$interval $period", strtotime($subscription->get_date_created()))); |
|
438 | 438 | |
439 | - $subscription->set_next_renewal_date( $expiration ); |
|
439 | + $subscription->set_next_renewal_date($expiration); |
|
440 | 440 | $subscription->save(); |
441 | - $invoice->set_subscription_id( $subscription->get_id() ); |
|
441 | + $invoice->set_subscription_id($subscription->get_id()); |
|
442 | 442 | return $subscription->get_id(); |
443 | 443 | |
444 | 444 | } |
@@ -449,27 +449,27 @@ discard block |
||
449 | 449 | * @param array $data |
450 | 450 | * @since 1.0.19 |
451 | 451 | */ |
452 | - public function admin_update_single_subscription( $args ) { |
|
452 | + public function admin_update_single_subscription($args) { |
|
453 | 453 | |
454 | 454 | // Ensure the subscription exists and that a status has been given. |
455 | - if ( empty( $args['subscription_id'] ) ) { |
|
455 | + if (empty($args['subscription_id'])) { |
|
456 | 456 | return; |
457 | 457 | } |
458 | 458 | |
459 | 459 | // Retrieve the subscriptions. |
460 | - $subscription = new WPInv_Subscription( $args['subscription_id'] ); |
|
460 | + $subscription = new WPInv_Subscription($args['subscription_id']); |
|
461 | 461 | |
462 | - if ( $subscription->get_id() ) { |
|
462 | + if ($subscription->get_id()) { |
|
463 | 463 | |
464 | 464 | $subscription->set_props( |
465 | 465 | array( |
466 | - 'status' => isset( $args['subscription_status'] ) ? $args['subscription_status'] : null, |
|
467 | - 'profile_id' => isset( $args['wpinv_subscription_profile_id'] ) ? $args['wpinv_subscription_profile_id'] : null, |
|
466 | + 'status' => isset($args['subscription_status']) ? $args['subscription_status'] : null, |
|
467 | + 'profile_id' => isset($args['wpinv_subscription_profile_id']) ? $args['wpinv_subscription_profile_id'] : null, |
|
468 | 468 | ) |
469 | 469 | ); |
470 | 470 | |
471 | 471 | $subscription->save(); |
472 | - getpaid_admin()->show_info( __( 'Subscription updated', 'invoicing' ) ); |
|
472 | + getpaid_admin()->show_info(__('Subscription updated', 'invoicing')); |
|
473 | 473 | |
474 | 474 | } |
475 | 475 | |
@@ -481,27 +481,27 @@ discard block |
||
481 | 481 | * @param array $data |
482 | 482 | * @since 1.0.19 |
483 | 483 | */ |
484 | - public function admin_renew_single_subscription( $args ) { |
|
484 | + public function admin_renew_single_subscription($args) { |
|
485 | 485 | |
486 | 486 | // Ensure the subscription exists and that a status has been given. |
487 | - if ( empty( $args['id'] ) ) { |
|
487 | + if (empty($args['id'])) { |
|
488 | 488 | return; |
489 | 489 | } |
490 | 490 | |
491 | 491 | // Retrieve the subscriptions. |
492 | - $subscription = new WPInv_Subscription( $args['id'] ); |
|
492 | + $subscription = new WPInv_Subscription($args['id']); |
|
493 | 493 | |
494 | - if ( $subscription->get_id() ) { |
|
494 | + if ($subscription->get_id()) { |
|
495 | 495 | |
496 | - do_action( 'getpaid_admin_renew_subscription', $subscription ); |
|
496 | + do_action('getpaid_admin_renew_subscription', $subscription); |
|
497 | 497 | |
498 | - $args = array( 'transaction_id', $subscription->get_parent_invoice()->generate_key( 'renewal_' ) ); |
|
498 | + $args = array('transaction_id', $subscription->get_parent_invoice()->generate_key('renewal_')); |
|
499 | 499 | |
500 | - if ( ! $subscription->add_payment( $args ) ) { |
|
501 | - getpaid_admin()->show_error( __( 'We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing' ) ); |
|
500 | + if (!$subscription->add_payment($args)) { |
|
501 | + getpaid_admin()->show_error(__('We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing')); |
|
502 | 502 | } else { |
503 | 503 | $subscription->renew(); |
504 | - getpaid_admin()->show_info( __( 'This subscription has been renewed and extended.', 'invoicing' ) ); |
|
504 | + getpaid_admin()->show_info(__('This subscription has been renewed and extended.', 'invoicing')); |
|
505 | 505 | } |
506 | 506 | |
507 | 507 | wp_safe_redirect( |
@@ -524,20 +524,20 @@ discard block |
||
524 | 524 | * @param array $data |
525 | 525 | * @since 1.0.19 |
526 | 526 | */ |
527 | - public function admin_delete_single_subscription( $args ) { |
|
527 | + public function admin_delete_single_subscription($args) { |
|
528 | 528 | |
529 | 529 | // Ensure the subscription exists and that a status has been given. |
530 | - if ( empty( $args['id'] ) ) { |
|
530 | + if (empty($args['id'])) { |
|
531 | 531 | return; |
532 | 532 | } |
533 | 533 | |
534 | 534 | // Retrieve the subscriptions. |
535 | - $subscription = new WPInv_Subscription( $args['id'] ); |
|
535 | + $subscription = new WPInv_Subscription($args['id']); |
|
536 | 536 | |
537 | - if ( $subscription->delete() ) { |
|
538 | - getpaid_admin()->show_info( __( 'This subscription has been deleted.', 'invoicing' ) ); |
|
537 | + if ($subscription->delete()) { |
|
538 | + getpaid_admin()->show_info(__('This subscription has been deleted.', 'invoicing')); |
|
539 | 539 | } else { |
540 | - getpaid_admin()->show_error( __( 'We are unable to delete this subscription. Please try again.', 'invoicing' ) ); |
|
540 | + getpaid_admin()->show_error(__('We are unable to delete this subscription. Please try again.', 'invoicing')); |
|
541 | 541 | } |
542 | 542 | |
543 | 543 | $redirected = wp_safe_redirect( |
@@ -550,7 +550,7 @@ discard block |
||
550 | 550 | ) |
551 | 551 | ); |
552 | 552 | |
553 | - if ( $redirected ) { |
|
553 | + if ($redirected) { |
|
554 | 554 | exit; |
555 | 555 | } |
556 | 556 | |
@@ -563,16 +563,16 @@ discard block |
||
563 | 563 | * @param WPInv_Item $item |
564 | 564 | * @param WPInv_Invoice $invoice |
565 | 565 | */ |
566 | - public function filter_invoice_line_item_actions( $actions, $item, $invoice ) { |
|
566 | + public function filter_invoice_line_item_actions($actions, $item, $invoice) { |
|
567 | 567 | |
568 | 568 | // Abort if this invoice uses subscription groups. |
569 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
570 | - if ( ! $invoice->is_recurring() || ! is_object( $subscriptions ) ) { |
|
569 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
570 | + if (!$invoice->is_recurring() || !is_object($subscriptions)) { |
|
571 | 571 | return $actions; |
572 | 572 | } |
573 | 573 | |
574 | 574 | // Fetch item subscription. |
575 | - $args = array( |
|
575 | + $args = array( |
|
576 | 576 | 'invoice_in' => $invoice->is_parent() ? $invoice->get_id() : $invoice->get_parent_id(), |
577 | 577 | 'product_in' => $item->get_id(), |
578 | 578 | 'number' => 1, |
@@ -580,13 +580,13 @@ discard block |
||
580 | 580 | 'fields' => 'id', |
581 | 581 | ); |
582 | 582 | |
583 | - $subscription = new GetPaid_Subscriptions_Query( $args ); |
|
583 | + $subscription = new GetPaid_Subscriptions_Query($args); |
|
584 | 584 | $subscription = $subscription->get_results(); |
585 | 585 | |
586 | 586 | // In case we found a match... |
587 | - if ( ! empty( $subscription ) ) { |
|
588 | - $url = esc_url( add_query_arg( 'subscription', (int) $subscription[0], get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); |
|
589 | - $actions['subscription'] = "<a href='$url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
587 | + if (!empty($subscription)) { |
|
588 | + $url = esc_url(add_query_arg('subscription', (int) $subscription[0], get_permalink((int) wpinv_get_option('invoice_subscription_page')))); |
|
589 | + $actions['subscription'] = "<a href='$url' class='text-decoration-none'>" . __('Manage Subscription', 'invoicing') . '</a>'; |
|
590 | 590 | } |
591 | 591 | |
592 | 592 | return $actions; |