@@ -1,196 +1,196 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | function wpinv_is_subscription_payment( $invoice = '' ) { |
3 | - if ( empty( $invoice ) ) { |
|
4 | - return false; |
|
5 | - } |
|
3 | + if ( empty( $invoice ) ) { |
|
4 | + return false; |
|
5 | + } |
|
6 | 6 | |
7 | - if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
8 | - $invoice = wpinv_get_invoice( $invoice ); |
|
9 | - } |
|
7 | + if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
8 | + $invoice = wpinv_get_invoice( $invoice ); |
|
9 | + } |
|
10 | 10 | |
11 | - if ( empty( $invoice ) ) { |
|
12 | - return false; |
|
13 | - } |
|
11 | + if ( empty( $invoice ) ) { |
|
12 | + return false; |
|
13 | + } |
|
14 | 14 | |
15 | - if ( $invoice->is_renewal() ) { |
|
16 | - return true; |
|
17 | - } |
|
15 | + if ( $invoice->is_renewal() ) { |
|
16 | + return true; |
|
17 | + } |
|
18 | 18 | |
19 | - return false; |
|
19 | + return false; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | function wpinv_payment_link_transaction_id( $invoice = '' ) { |
23 | - if ( empty( $invoice ) ) { |
|
24 | - return false; |
|
25 | - } |
|
23 | + if ( empty( $invoice ) ) { |
|
24 | + return false; |
|
25 | + } |
|
26 | 26 | |
27 | - if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
28 | - $invoice = wpinv_get_invoice( $invoice ); |
|
29 | - } |
|
27 | + if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
28 | + $invoice = wpinv_get_invoice( $invoice ); |
|
29 | + } |
|
30 | 30 | |
31 | - if ( empty( $invoice ) ) { |
|
32 | - return false; |
|
33 | - } |
|
31 | + if ( empty( $invoice ) ) { |
|
32 | + return false; |
|
33 | + } |
|
34 | 34 | |
35 | - return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice ); |
|
35 | + return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice ); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) { |
39 | - $interval = (int)$interval > 0 ? (int)$interval : 1; |
|
40 | - |
|
41 | - if ( $trial_interval > 0 && ! empty( $trial_period ) ) { |
|
42 | - $amount = __( 'Free', 'invoicing' ); |
|
43 | - $interval = $trial_interval; |
|
44 | - $period = $trial_period; |
|
45 | - } |
|
46 | - |
|
47 | - $description = ''; |
|
48 | - switch ( $period ) { |
|
49 | - case 'D': |
|
50 | - case 'day': |
|
51 | - $description = wp_sprintf( _n( '%s for the first day.', '%1$s for the first %2$d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
52 | - break; |
|
53 | - case 'W': |
|
54 | - case 'week': |
|
55 | - $description = wp_sprintf( _n( '%s for the first week.', '%1$s for the first %2$d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
56 | - break; |
|
57 | - case 'M': |
|
58 | - case 'month': |
|
59 | - $description = wp_sprintf( _n( '%s for the first month.', '%1$s for the first %2$d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
60 | - break; |
|
61 | - case 'Y': |
|
62 | - case 'year': |
|
63 | - $description = wp_sprintf( _n( '%s for the first year.', '%1$s for the first %2$d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
64 | - break; |
|
65 | - } |
|
66 | - |
|
67 | - return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval ); |
|
39 | + $interval = (int)$interval > 0 ? (int)$interval : 1; |
|
40 | + |
|
41 | + if ( $trial_interval > 0 && ! empty( $trial_period ) ) { |
|
42 | + $amount = __( 'Free', 'invoicing' ); |
|
43 | + $interval = $trial_interval; |
|
44 | + $period = $trial_period; |
|
45 | + } |
|
46 | + |
|
47 | + $description = ''; |
|
48 | + switch ( $period ) { |
|
49 | + case 'D': |
|
50 | + case 'day': |
|
51 | + $description = wp_sprintf( _n( '%s for the first day.', '%1$s for the first %2$d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
52 | + break; |
|
53 | + case 'W': |
|
54 | + case 'week': |
|
55 | + $description = wp_sprintf( _n( '%s for the first week.', '%1$s for the first %2$d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
56 | + break; |
|
57 | + case 'M': |
|
58 | + case 'month': |
|
59 | + $description = wp_sprintf( _n( '%s for the first month.', '%1$s for the first %2$d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
60 | + break; |
|
61 | + case 'Y': |
|
62 | + case 'year': |
|
63 | + $description = wp_sprintf( _n( '%s for the first year.', '%1$s for the first %2$d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
64 | + break; |
|
65 | + } |
|
66 | + |
|
67 | + return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval ); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) { |
71 | - $interval = (int)$interval > 0 ? (int)$interval : 1; |
|
72 | - $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0; |
|
73 | - |
|
74 | - $description = ''; |
|
75 | - switch ( $period ) { |
|
76 | - case 'D': |
|
77 | - case 'day': |
|
78 | - if ( (int)$bill_times > 0 ) { |
|
79 | - if ( $interval > 1 ) { |
|
80 | - if ( $bill_times > 1 ) { |
|
81 | - $description = wp_sprintf( __( '%1$s for each %2$d days, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
82 | - } else { |
|
83 | - $description = wp_sprintf( __( '%1$s for %2$d days.', 'invoicing' ), $amount, $interval ); |
|
84 | - } |
|
85 | - } else { |
|
86 | - $description = wp_sprintf( _n( '%s for one day.', '%1$s for each day, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
87 | - } |
|
88 | - } else { |
|
89 | - $description = wp_sprintf( _n( '%s for each day.', '%1$s for each %2$d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
90 | - } |
|
91 | - break; |
|
92 | - case 'W': |
|
93 | - case 'week': |
|
94 | - if ( (int)$bill_times > 0 ) { |
|
95 | - if ( $interval > 1 ) { |
|
96 | - if ( $bill_times > 1 ) { |
|
97 | - $description = wp_sprintf( __( '%1$s for each %2$d weeks, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
98 | - } else { |
|
99 | - $description = wp_sprintf( __( '%1$s for %2$d weeks.', 'invoicing' ), $amount, $interval ); |
|
100 | - } |
|
101 | - } else { |
|
102 | - $description = wp_sprintf( _n( '%s for one week.', '%1$s for each week, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
103 | - } |
|
104 | - } else { |
|
105 | - $description = wp_sprintf( _n( '%s for each week.', '%1$s for each %2$d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
106 | - } |
|
107 | - break; |
|
108 | - case 'M': |
|
109 | - case 'month': |
|
110 | - if ( (int)$bill_times > 0 ) { |
|
111 | - if ( $interval > 1 ) { |
|
112 | - if ( $bill_times > 1 ) { |
|
113 | - $description = wp_sprintf( __( '%1$s for each %2$d months, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
114 | - } else { |
|
115 | - $description = wp_sprintf( __( '%1$s for %2$d months.', 'invoicing' ), $amount, $interval ); |
|
116 | - } |
|
117 | - } else { |
|
118 | - $description = wp_sprintf( _n( '%s for one month.', '%1$s for each month, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
119 | - } |
|
120 | - } else { |
|
121 | - $description = wp_sprintf( _n( '%s for each month.', '%1$s for each %2$d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
122 | - } |
|
123 | - break; |
|
124 | - case 'Y': |
|
125 | - case 'year': |
|
126 | - if ( (int)$bill_times > 0 ) { |
|
127 | - if ( $interval > 1 ) { |
|
128 | - if ( $bill_times > 1 ) { |
|
129 | - $description = wp_sprintf( __( '%1$s for each %2$d years, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
130 | - } else { |
|
131 | - $description = wp_sprintf( __( '%1$s for %2$d years.', 'invoicing' ), $amount, $interval ); |
|
132 | - } |
|
133 | - } else { |
|
134 | - $description = wp_sprintf( _n( '%s for one year.', '%1$s for each year, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
135 | - } |
|
136 | - } else { |
|
137 | - $description = wp_sprintf( _n( '%s for each year.', '%1$s for each %2$d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
138 | - } |
|
139 | - break; |
|
140 | - } |
|
141 | - |
|
142 | - return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
71 | + $interval = (int)$interval > 0 ? (int)$interval : 1; |
|
72 | + $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0; |
|
73 | + |
|
74 | + $description = ''; |
|
75 | + switch ( $period ) { |
|
76 | + case 'D': |
|
77 | + case 'day': |
|
78 | + if ( (int)$bill_times > 0 ) { |
|
79 | + if ( $interval > 1 ) { |
|
80 | + if ( $bill_times > 1 ) { |
|
81 | + $description = wp_sprintf( __( '%1$s for each %2$d days, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
82 | + } else { |
|
83 | + $description = wp_sprintf( __( '%1$s for %2$d days.', 'invoicing' ), $amount, $interval ); |
|
84 | + } |
|
85 | + } else { |
|
86 | + $description = wp_sprintf( _n( '%s for one day.', '%1$s for each day, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
87 | + } |
|
88 | + } else { |
|
89 | + $description = wp_sprintf( _n( '%s for each day.', '%1$s for each %2$d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
90 | + } |
|
91 | + break; |
|
92 | + case 'W': |
|
93 | + case 'week': |
|
94 | + if ( (int)$bill_times > 0 ) { |
|
95 | + if ( $interval > 1 ) { |
|
96 | + if ( $bill_times > 1 ) { |
|
97 | + $description = wp_sprintf( __( '%1$s for each %2$d weeks, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
98 | + } else { |
|
99 | + $description = wp_sprintf( __( '%1$s for %2$d weeks.', 'invoicing' ), $amount, $interval ); |
|
100 | + } |
|
101 | + } else { |
|
102 | + $description = wp_sprintf( _n( '%s for one week.', '%1$s for each week, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
103 | + } |
|
104 | + } else { |
|
105 | + $description = wp_sprintf( _n( '%s for each week.', '%1$s for each %2$d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
106 | + } |
|
107 | + break; |
|
108 | + case 'M': |
|
109 | + case 'month': |
|
110 | + if ( (int)$bill_times > 0 ) { |
|
111 | + if ( $interval > 1 ) { |
|
112 | + if ( $bill_times > 1 ) { |
|
113 | + $description = wp_sprintf( __( '%1$s for each %2$d months, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
114 | + } else { |
|
115 | + $description = wp_sprintf( __( '%1$s for %2$d months.', 'invoicing' ), $amount, $interval ); |
|
116 | + } |
|
117 | + } else { |
|
118 | + $description = wp_sprintf( _n( '%s for one month.', '%1$s for each month, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
119 | + } |
|
120 | + } else { |
|
121 | + $description = wp_sprintf( _n( '%s for each month.', '%1$s for each %2$d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
122 | + } |
|
123 | + break; |
|
124 | + case 'Y': |
|
125 | + case 'year': |
|
126 | + if ( (int)$bill_times > 0 ) { |
|
127 | + if ( $interval > 1 ) { |
|
128 | + if ( $bill_times > 1 ) { |
|
129 | + $description = wp_sprintf( __( '%1$s for each %2$d years, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
130 | + } else { |
|
131 | + $description = wp_sprintf( __( '%1$s for %2$d years.', 'invoicing' ), $amount, $interval ); |
|
132 | + } |
|
133 | + } else { |
|
134 | + $description = wp_sprintf( _n( '%s for one year.', '%1$s for each year, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
135 | + } |
|
136 | + } else { |
|
137 | + $description = wp_sprintf( _n( '%s for each year.', '%1$s for each %2$d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
138 | + } |
|
139 | + break; |
|
140 | + } |
|
141 | + |
|
142 | + return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | function wpinv_subscription_payment_desc( $invoice ) { |
146 | - if ( empty( $invoice ) ) { |
|
147 | - return null; |
|
148 | - } |
|
149 | - |
|
150 | - $description = ''; |
|
151 | - if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) { |
|
152 | - if ( $item->has_free_trial() ) { |
|
153 | - $trial_period = $item->get_trial_period(); |
|
154 | - $trial_interval = $item->get_trial_interval(); |
|
155 | - } else { |
|
156 | - $trial_period = ''; |
|
157 | - $trial_interval = 0; |
|
158 | - } |
|
159 | - |
|
160 | - $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() ); |
|
161 | - } |
|
162 | - |
|
163 | - return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice ); |
|
146 | + if ( empty( $invoice ) ) { |
|
147 | + return null; |
|
148 | + } |
|
149 | + |
|
150 | + $description = ''; |
|
151 | + if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) { |
|
152 | + if ( $item->has_free_trial() ) { |
|
153 | + $trial_period = $item->get_trial_period(); |
|
154 | + $trial_interval = $item->get_trial_interval(); |
|
155 | + } else { |
|
156 | + $trial_period = ''; |
|
157 | + $trial_interval = 0; |
|
158 | + } |
|
159 | + |
|
160 | + $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() ); |
|
161 | + } |
|
162 | + |
|
163 | + return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice ); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) { |
167 | - $initial_total = wpinv_round_amount( $initial ); |
|
168 | - $recurring_total = wpinv_round_amount( $recurring ); |
|
167 | + $initial_total = wpinv_round_amount( $initial ); |
|
168 | + $recurring_total = wpinv_round_amount( $recurring ); |
|
169 | 169 | |
170 | - if ( $trial_interval > 0 && ! empty( $trial_period ) ) { |
|
171 | - // Free trial |
|
172 | - } else { |
|
173 | - if ( $bill_times == 1 ) { |
|
174 | - $recurring_total = $initial_total; |
|
175 | - } elseif ( $bill_times > 1 && $initial_total != $recurring_total ) { |
|
176 | - $bill_times--; |
|
177 | - } |
|
178 | - } |
|
170 | + if ( $trial_interval > 0 && ! empty( $trial_period ) ) { |
|
171 | + // Free trial |
|
172 | + } else { |
|
173 | + if ( $bill_times == 1 ) { |
|
174 | + $recurring_total = $initial_total; |
|
175 | + } elseif ( $bill_times > 1 && $initial_total != $recurring_total ) { |
|
176 | + $bill_times--; |
|
177 | + } |
|
178 | + } |
|
179 | 179 | |
180 | - $initial_amount = wpinv_price( $initial_total, $currency ); |
|
181 | - $recurring_amount = wpinv_price( $recurring_total, $currency ); |
|
180 | + $initial_amount = wpinv_price( $initial_total, $currency ); |
|
181 | + $recurring_amount = wpinv_price( $recurring_total, $currency ); |
|
182 | 182 | |
183 | - $recurring = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
183 | + $recurring = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
184 | 184 | |
185 | - if ( $initial_total != $recurring_total ) { |
|
186 | - $initial = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval ); |
|
185 | + if ( $initial_total != $recurring_total ) { |
|
186 | + $initial = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval ); |
|
187 | 187 | |
188 | - $description = wp_sprintf( __( '%1$s Then %2$s', 'invoicing' ), $initial, $recurring ); |
|
189 | - } else { |
|
190 | - $description = $recurring; |
|
191 | - } |
|
188 | + $description = wp_sprintf( __( '%1$s Then %2$s', 'invoicing' ), $initial, $recurring ); |
|
189 | + } else { |
|
190 | + $description = $recurring; |
|
191 | + } |
|
192 | 192 | |
193 | - return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency ); |
|
193 | + return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency ); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
@@ -202,25 +202,25 @@ discard block |
||
202 | 202 | */ |
203 | 203 | function getpaid_get_card_name( $card_number ) { |
204 | 204 | |
205 | - // Known regexes. |
|
206 | - $regexes = array( |
|
207 | - '/^4/' => __( 'Visa', 'invoicing' ), |
|
208 | - '/^5[1-5]/' => __( 'Mastercard', 'invoicing' ), |
|
209 | - '/^3[47]/' => __( 'Amex', 'invoicing' ), |
|
210 | - '/^3(?:0[0-5]|[68])/' => __( 'Diners Club', 'invoicing' ), |
|
211 | - '/^6(?:011|5)/' => __( 'Discover', 'invoicing' ), |
|
212 | - '/^(?:2131|1800|35\d{3})/' => __( 'JCB', 'invoicing' ), |
|
213 | - ); |
|
214 | - |
|
215 | - // Confirm if one matches. |
|
216 | - foreach ( $regexes as $regex => $card ) { |
|
217 | - if ( preg_match( $regex, $card_number ) >= 1 ) { |
|
218 | - return $card; |
|
219 | - } |
|
220 | - } |
|
221 | - |
|
222 | - // None matched. |
|
223 | - return __( 'Card', 'invoicing' ); |
|
205 | + // Known regexes. |
|
206 | + $regexes = array( |
|
207 | + '/^4/' => __( 'Visa', 'invoicing' ), |
|
208 | + '/^5[1-5]/' => __( 'Mastercard', 'invoicing' ), |
|
209 | + '/^3[47]/' => __( 'Amex', 'invoicing' ), |
|
210 | + '/^3(?:0[0-5]|[68])/' => __( 'Diners Club', 'invoicing' ), |
|
211 | + '/^6(?:011|5)/' => __( 'Discover', 'invoicing' ), |
|
212 | + '/^(?:2131|1800|35\d{3})/' => __( 'JCB', 'invoicing' ), |
|
213 | + ); |
|
214 | + |
|
215 | + // Confirm if one matches. |
|
216 | + foreach ( $regexes as $regex => $card ) { |
|
217 | + if ( preg_match( $regex, $card_number ) >= 1 ) { |
|
218 | + return $card; |
|
219 | + } |
|
220 | + } |
|
221 | + |
|
222 | + // None matched. |
|
223 | + return __( 'Card', 'invoicing' ); |
|
224 | 224 | |
225 | 225 | } |
226 | 226 | |
@@ -230,24 +230,24 @@ discard block |
||
230 | 230 | * @param WPInv_Invoice|int|null $invoice |
231 | 231 | */ |
232 | 232 | function wpinv_send_back_to_checkout( $invoice = null ) { |
233 | - $response = array( 'success' => false ); |
|
234 | - $invoice = wpinv_get_invoice( $invoice ); |
|
235 | - |
|
236 | - // Was an invoice created? |
|
237 | - if ( ! empty( $invoice ) ) { |
|
238 | - $invoice = is_scalar( $invoice ) ? new WPInv_Invoice( $invoice ) : $invoice; |
|
239 | - $response['invoice'] = $invoice->get_id(); |
|
240 | - do_action( 'getpaid_checkout_invoice_exception', $invoice ); |
|
241 | - } |
|
242 | - |
|
243 | - // Do we have any errors? |
|
244 | - if ( wpinv_get_errors() ) { |
|
245 | - $response['data'] = getpaid_get_errors_html( true, false ); |
|
246 | - } else { |
|
247 | - $response['data'] = __( 'An error occured while processing your payment. Please try again.', 'invoicing' ); |
|
248 | - } |
|
249 | - |
|
250 | - wp_send_json( $response ); |
|
233 | + $response = array( 'success' => false ); |
|
234 | + $invoice = wpinv_get_invoice( $invoice ); |
|
235 | + |
|
236 | + // Was an invoice created? |
|
237 | + if ( ! empty( $invoice ) ) { |
|
238 | + $invoice = is_scalar( $invoice ) ? new WPInv_Invoice( $invoice ) : $invoice; |
|
239 | + $response['invoice'] = $invoice->get_id(); |
|
240 | + do_action( 'getpaid_checkout_invoice_exception', $invoice ); |
|
241 | + } |
|
242 | + |
|
243 | + // Do we have any errors? |
|
244 | + if ( wpinv_get_errors() ) { |
|
245 | + $response['data'] = getpaid_get_errors_html( true, false ); |
|
246 | + } else { |
|
247 | + $response['data'] = __( 'An error occured while processing your payment. Please try again.', 'invoicing' ); |
|
248 | + } |
|
249 | + |
|
250 | + wp_send_json( $response ); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | * @return string |
257 | 257 | */ |
258 | 258 | function getpaid_get_recaptcha_site_key() { |
259 | - return apply_filters( 'getpaid_recaptcha_site_key', wpinv_get_option( 'recaptcha_site_key', '' ) ); |
|
259 | + return apply_filters( 'getpaid_recaptcha_site_key', wpinv_get_option( 'recaptcha_site_key', '' ) ); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | * @return string |
266 | 266 | */ |
267 | 267 | function getpaid_get_recaptcha_secret_key() { |
268 | - return apply_filters( 'getpaid_recaptcha_secret_key', wpinv_get_option( 'recaptcha_secret_key', '' ) ); |
|
268 | + return apply_filters( 'getpaid_recaptcha_secret_key', wpinv_get_option( 'recaptcha_secret_key', '' ) ); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | * @return bool |
275 | 275 | */ |
276 | 276 | function getpaid_is_recaptcha_enabled() { |
277 | - return wpinv_get_option( 'enable_recaptcha', false ) && getpaid_get_recaptcha_site_key() && getpaid_get_recaptcha_secret_key(); |
|
277 | + return wpinv_get_option( 'enable_recaptcha', false ) && getpaid_get_recaptcha_site_key() && getpaid_get_recaptcha_secret_key(); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | /** |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * @return string |
284 | 284 | */ |
285 | 285 | function getpaid_get_recaptcha_version() { |
286 | - return apply_filters( 'getpaid_recaptcha_version', wpinv_get_option( 'recaptcha_version', 'v2' ) ); |
|
286 | + return apply_filters( 'getpaid_recaptcha_version', wpinv_get_option( 'recaptcha_version', 'v2' ) ); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | /** |
@@ -292,42 +292,42 @@ discard block |
||
292 | 292 | * @return array |
293 | 293 | */ |
294 | 294 | function getpaid_get_recaptcha_settings() { |
295 | - $settings = array( |
|
296 | - 'enabled' => getpaid_is_recaptcha_enabled(), |
|
297 | - 'version' => getpaid_get_recaptcha_version(), |
|
298 | - ); |
|
299 | - |
|
300 | - if ( ! getpaid_is_recaptcha_enabled() ) { |
|
301 | - return $settings; |
|
302 | - } |
|
303 | - |
|
304 | - $settings['sitekey'] = getpaid_get_recaptcha_site_key(); |
|
305 | - |
|
306 | - // Version 2 render params. |
|
307 | - if ( 'v2' === getpaid_get_recaptcha_version() ) { |
|
308 | - $settings['render_params'] = array( |
|
309 | - 'sitekey' => getpaid_get_recaptcha_site_key(), |
|
310 | - 'theme' => 'light', |
|
311 | - 'size' => 'normal', |
|
312 | - 'tabindex' => 0, |
|
313 | - ); |
|
314 | - } |
|
315 | - |
|
316 | - return apply_filters( 'getpaid_recaptcha_settings', $settings ); |
|
295 | + $settings = array( |
|
296 | + 'enabled' => getpaid_is_recaptcha_enabled(), |
|
297 | + 'version' => getpaid_get_recaptcha_version(), |
|
298 | + ); |
|
299 | + |
|
300 | + if ( ! getpaid_is_recaptcha_enabled() ) { |
|
301 | + return $settings; |
|
302 | + } |
|
303 | + |
|
304 | + $settings['sitekey'] = getpaid_get_recaptcha_site_key(); |
|
305 | + |
|
306 | + // Version 2 render params. |
|
307 | + if ( 'v2' === getpaid_get_recaptcha_version() ) { |
|
308 | + $settings['render_params'] = array( |
|
309 | + 'sitekey' => getpaid_get_recaptcha_site_key(), |
|
310 | + 'theme' => 'light', |
|
311 | + 'size' => 'normal', |
|
312 | + 'tabindex' => 0, |
|
313 | + ); |
|
314 | + } |
|
315 | + |
|
316 | + return apply_filters( 'getpaid_recaptcha_settings', $settings ); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
320 | 320 | * Displays reCAPTCHA before payment button. |
321 | 321 | */ |
322 | 322 | function getpaid_display_recaptcha_before_payment_button() { |
323 | - if ( ! getpaid_is_recaptcha_enabled() || 'v2' !== getpaid_get_recaptcha_version() ) { |
|
324 | - return; |
|
325 | - } |
|
326 | - |
|
327 | - printf( |
|
328 | - '<div class="getpaid-recaptcha-wrapper"><div class="g-recaptcha mw-100 overflow-hidden my-2" id="getpaid-recaptcha-%s"></div></div>', |
|
329 | - esc_attr( wp_unique_id() ) |
|
330 | - ); |
|
323 | + if ( ! getpaid_is_recaptcha_enabled() || 'v2' !== getpaid_get_recaptcha_version() ) { |
|
324 | + return; |
|
325 | + } |
|
326 | + |
|
327 | + printf( |
|
328 | + '<div class="getpaid-recaptcha-wrapper"><div class="g-recaptcha mw-100 overflow-hidden my-2" id="getpaid-recaptcha-%s"></div></div>', |
|
329 | + esc_attr( wp_unique_id() ) |
|
330 | + ); |
|
331 | 331 | } |
332 | 332 | add_action( 'getpaid_before_payment_form_pay_button', 'getpaid_display_recaptcha_before_payment_button' ); |
333 | 333 | |
@@ -338,43 +338,43 @@ discard block |
||
338 | 338 | */ |
339 | 339 | function getpaid_validate_recaptcha_response( $submission ) { |
340 | 340 | |
341 | - // Check if reCAPTCHA is enabled. |
|
342 | - if ( ! getpaid_is_recaptcha_enabled() ) { |
|
343 | - return; |
|
344 | - } |
|
345 | - |
|
346 | - $token = $submission->get_field( 'g-recaptcha-response' ); |
|
347 | - |
|
348 | - // Abort if no token was provided. |
|
349 | - if ( empty( $token ) ) { |
|
350 | - wp_send_json_error( 'v2' === getpaid_get_recaptcha_version() ? __( 'Please confirm that you are not a robot.', 'invoicing' ) : __( "Unable to verify that you're not a robot. Please try again.", 'invoicing' ) ); |
|
351 | - } |
|
352 | - |
|
353 | - $result = wp_remote_post( |
|
354 | - 'https://www.google.com/recaptcha/api/siteverify', |
|
355 | - array( |
|
356 | - 'body' => array( |
|
357 | - 'secret' => getpaid_get_recaptcha_secret_key(), |
|
358 | - 'response' => $token, |
|
359 | - ), |
|
360 | - ) |
|
361 | - ); |
|
362 | - |
|
363 | - // Site not reachable, give benefit of doubt. |
|
364 | - if ( is_wp_error( $result ) ) { |
|
365 | - return; |
|
366 | - } |
|
367 | - |
|
368 | - $result = json_decode( wp_remote_retrieve_body( $result ), true ); |
|
369 | - |
|
370 | - if ( empty( $result['success'] ) && ! in_array( 'missing-input-secret', $result['error-codes'], true ) && ! in_array( 'invalid-input-secret', $result['error-codes'], true ) ) { |
|
371 | - wp_send_json_error( __( "Unable to verify that you're not a robot. Please try again.", 'invoicing' ) ); |
|
372 | - } |
|
373 | - |
|
374 | - // For v3, check the score. |
|
375 | - $minimum_score = apply_filters( 'getpaid_recaptcha_minimum_score', 0.4 ); |
|
376 | - if ( 'v3' === getpaid_get_recaptcha_version() && ( empty( $result['score'] ) || $result['score'] < $minimum_score ) ) { |
|
377 | - wp_send_json_error( __( "Unable to verify that you're not a robot. Please try again.", 'invoicing' ) ); |
|
378 | - } |
|
341 | + // Check if reCAPTCHA is enabled. |
|
342 | + if ( ! getpaid_is_recaptcha_enabled() ) { |
|
343 | + return; |
|
344 | + } |
|
345 | + |
|
346 | + $token = $submission->get_field( 'g-recaptcha-response' ); |
|
347 | + |
|
348 | + // Abort if no token was provided. |
|
349 | + if ( empty( $token ) ) { |
|
350 | + wp_send_json_error( 'v2' === getpaid_get_recaptcha_version() ? __( 'Please confirm that you are not a robot.', 'invoicing' ) : __( "Unable to verify that you're not a robot. Please try again.", 'invoicing' ) ); |
|
351 | + } |
|
352 | + |
|
353 | + $result = wp_remote_post( |
|
354 | + 'https://www.google.com/recaptcha/api/siteverify', |
|
355 | + array( |
|
356 | + 'body' => array( |
|
357 | + 'secret' => getpaid_get_recaptcha_secret_key(), |
|
358 | + 'response' => $token, |
|
359 | + ), |
|
360 | + ) |
|
361 | + ); |
|
362 | + |
|
363 | + // Site not reachable, give benefit of doubt. |
|
364 | + if ( is_wp_error( $result ) ) { |
|
365 | + return; |
|
366 | + } |
|
367 | + |
|
368 | + $result = json_decode( wp_remote_retrieve_body( $result ), true ); |
|
369 | + |
|
370 | + if ( empty( $result['success'] ) && ! in_array( 'missing-input-secret', $result['error-codes'], true ) && ! in_array( 'invalid-input-secret', $result['error-codes'], true ) ) { |
|
371 | + wp_send_json_error( __( "Unable to verify that you're not a robot. Please try again.", 'invoicing' ) ); |
|
372 | + } |
|
373 | + |
|
374 | + // For v3, check the score. |
|
375 | + $minimum_score = apply_filters( 'getpaid_recaptcha_minimum_score', 0.4 ); |
|
376 | + if ( 'v3' === getpaid_get_recaptcha_version() && ( empty( $result['score'] ) || $result['score'] < $minimum_score ) ) { |
|
377 | + wp_send_json_error( __( "Unable to verify that you're not a robot. Please try again.", 'invoicing' ) ); |
|
378 | + } |
|
379 | 379 | } |
380 | 380 | add_action( 'getpaid_checkout_error_checks', 'getpaid_validate_recaptcha_response' ); |
@@ -1,155 +1,155 @@ discard block |
||
1 | 1 | <?php |
2 | -function wpinv_is_subscription_payment( $invoice = '' ) { |
|
3 | - if ( empty( $invoice ) ) { |
|
2 | +function wpinv_is_subscription_payment($invoice = '') { |
|
3 | + if (empty($invoice)) { |
|
4 | 4 | return false; |
5 | 5 | } |
6 | 6 | |
7 | - if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
8 | - $invoice = wpinv_get_invoice( $invoice ); |
|
7 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
8 | + $invoice = wpinv_get_invoice($invoice); |
|
9 | 9 | } |
10 | 10 | |
11 | - if ( empty( $invoice ) ) { |
|
11 | + if (empty($invoice)) { |
|
12 | 12 | return false; |
13 | 13 | } |
14 | 14 | |
15 | - if ( $invoice->is_renewal() ) { |
|
15 | + if ($invoice->is_renewal()) { |
|
16 | 16 | return true; |
17 | 17 | } |
18 | 18 | |
19 | 19 | return false; |
20 | 20 | } |
21 | 21 | |
22 | -function wpinv_payment_link_transaction_id( $invoice = '' ) { |
|
23 | - if ( empty( $invoice ) ) { |
|
22 | +function wpinv_payment_link_transaction_id($invoice = '') { |
|
23 | + if (empty($invoice)) { |
|
24 | 24 | return false; |
25 | 25 | } |
26 | 26 | |
27 | - if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
28 | - $invoice = wpinv_get_invoice( $invoice ); |
|
27 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
28 | + $invoice = wpinv_get_invoice($invoice); |
|
29 | 29 | } |
30 | 30 | |
31 | - if ( empty( $invoice ) ) { |
|
31 | + if (empty($invoice)) { |
|
32 | 32 | return false; |
33 | 33 | } |
34 | 34 | |
35 | - return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice ); |
|
35 | + return apply_filters('wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice); |
|
36 | 36 | } |
37 | 37 | |
38 | -function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) { |
|
39 | - $interval = (int)$interval > 0 ? (int)$interval : 1; |
|
38 | +function wpinv_subscription_initial_payment_desc($amount, $period, $interval, $trial_period = '', $trial_interval = 0) { |
|
39 | + $interval = (int) $interval > 0 ? (int) $interval : 1; |
|
40 | 40 | |
41 | - if ( $trial_interval > 0 && ! empty( $trial_period ) ) { |
|
42 | - $amount = __( 'Free', 'invoicing' ); |
|
41 | + if ($trial_interval > 0 && !empty($trial_period)) { |
|
42 | + $amount = __('Free', 'invoicing'); |
|
43 | 43 | $interval = $trial_interval; |
44 | 44 | $period = $trial_period; |
45 | 45 | } |
46 | 46 | |
47 | 47 | $description = ''; |
48 | - switch ( $period ) { |
|
48 | + switch ($period) { |
|
49 | 49 | case 'D': |
50 | 50 | case 'day': |
51 | - $description = wp_sprintf( _n( '%s for the first day.', '%1$s for the first %2$d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
51 | + $description = wp_sprintf(_n('%s for the first day.', '%1$s for the first %2$d days.', $interval, 'invoicing'), $amount, $interval); |
|
52 | 52 | break; |
53 | 53 | case 'W': |
54 | 54 | case 'week': |
55 | - $description = wp_sprintf( _n( '%s for the first week.', '%1$s for the first %2$d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
55 | + $description = wp_sprintf(_n('%s for the first week.', '%1$s for the first %2$d weeks.', $interval, 'invoicing'), $amount, $interval); |
|
56 | 56 | break; |
57 | 57 | case 'M': |
58 | 58 | case 'month': |
59 | - $description = wp_sprintf( _n( '%s for the first month.', '%1$s for the first %2$d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
59 | + $description = wp_sprintf(_n('%s for the first month.', '%1$s for the first %2$d months.', $interval, 'invoicing'), $amount, $interval); |
|
60 | 60 | break; |
61 | 61 | case 'Y': |
62 | 62 | case 'year': |
63 | - $description = wp_sprintf( _n( '%s for the first year.', '%1$s for the first %2$d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
63 | + $description = wp_sprintf(_n('%s for the first year.', '%1$s for the first %2$d years.', $interval, 'invoicing'), $amount, $interval); |
|
64 | 64 | break; |
65 | 65 | } |
66 | 66 | |
67 | - return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval ); |
|
67 | + return apply_filters('wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval); |
|
68 | 68 | } |
69 | 69 | |
70 | -function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) { |
|
71 | - $interval = (int)$interval > 0 ? (int)$interval : 1; |
|
72 | - $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0; |
|
70 | +function wpinv_subscription_recurring_payment_desc($amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0) { |
|
71 | + $interval = (int) $interval > 0 ? (int) $interval : 1; |
|
72 | + $bill_times = (int) $bill_times > 0 ? (int) $bill_times : 0; |
|
73 | 73 | |
74 | 74 | $description = ''; |
75 | - switch ( $period ) { |
|
75 | + switch ($period) { |
|
76 | 76 | case 'D': |
77 | 77 | case 'day': |
78 | - if ( (int)$bill_times > 0 ) { |
|
79 | - if ( $interval > 1 ) { |
|
80 | - if ( $bill_times > 1 ) { |
|
81 | - $description = wp_sprintf( __( '%1$s for each %2$d days, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
78 | + if ((int) $bill_times > 0) { |
|
79 | + if ($interval > 1) { |
|
80 | + if ($bill_times > 1) { |
|
81 | + $description = wp_sprintf(__('%1$s for each %2$d days, for %3$d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
82 | 82 | } else { |
83 | - $description = wp_sprintf( __( '%1$s for %2$d days.', 'invoicing' ), $amount, $interval ); |
|
83 | + $description = wp_sprintf(__('%1$s for %2$d days.', 'invoicing'), $amount, $interval); |
|
84 | 84 | } |
85 | 85 | } else { |
86 | - $description = wp_sprintf( _n( '%s for one day.', '%1$s for each day, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
86 | + $description = wp_sprintf(_n('%s for one day.', '%1$s for each day, for %2$d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
87 | 87 | } |
88 | 88 | } else { |
89 | - $description = wp_sprintf( _n( '%s for each day.', '%1$s for each %2$d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
89 | + $description = wp_sprintf(_n('%s for each day.', '%1$s for each %2$d days.', $interval, 'invoicing'), $amount, $interval); |
|
90 | 90 | } |
91 | 91 | break; |
92 | 92 | case 'W': |
93 | 93 | case 'week': |
94 | - if ( (int)$bill_times > 0 ) { |
|
95 | - if ( $interval > 1 ) { |
|
96 | - if ( $bill_times > 1 ) { |
|
97 | - $description = wp_sprintf( __( '%1$s for each %2$d weeks, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
94 | + if ((int) $bill_times > 0) { |
|
95 | + if ($interval > 1) { |
|
96 | + if ($bill_times > 1) { |
|
97 | + $description = wp_sprintf(__('%1$s for each %2$d weeks, for %3$d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
98 | 98 | } else { |
99 | - $description = wp_sprintf( __( '%1$s for %2$d weeks.', 'invoicing' ), $amount, $interval ); |
|
99 | + $description = wp_sprintf(__('%1$s for %2$d weeks.', 'invoicing'), $amount, $interval); |
|
100 | 100 | } |
101 | 101 | } else { |
102 | - $description = wp_sprintf( _n( '%s for one week.', '%1$s for each week, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
102 | + $description = wp_sprintf(_n('%s for one week.', '%1$s for each week, for %2$d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
103 | 103 | } |
104 | 104 | } else { |
105 | - $description = wp_sprintf( _n( '%s for each week.', '%1$s for each %2$d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
105 | + $description = wp_sprintf(_n('%s for each week.', '%1$s for each %2$d weeks.', $interval, 'invoicing'), $amount, $interval); |
|
106 | 106 | } |
107 | 107 | break; |
108 | 108 | case 'M': |
109 | 109 | case 'month': |
110 | - if ( (int)$bill_times > 0 ) { |
|
111 | - if ( $interval > 1 ) { |
|
112 | - if ( $bill_times > 1 ) { |
|
113 | - $description = wp_sprintf( __( '%1$s for each %2$d months, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
110 | + if ((int) $bill_times > 0) { |
|
111 | + if ($interval > 1) { |
|
112 | + if ($bill_times > 1) { |
|
113 | + $description = wp_sprintf(__('%1$s for each %2$d months, for %3$d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
114 | 114 | } else { |
115 | - $description = wp_sprintf( __( '%1$s for %2$d months.', 'invoicing' ), $amount, $interval ); |
|
115 | + $description = wp_sprintf(__('%1$s for %2$d months.', 'invoicing'), $amount, $interval); |
|
116 | 116 | } |
117 | 117 | } else { |
118 | - $description = wp_sprintf( _n( '%s for one month.', '%1$s for each month, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
118 | + $description = wp_sprintf(_n('%s for one month.', '%1$s for each month, for %2$d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
119 | 119 | } |
120 | 120 | } else { |
121 | - $description = wp_sprintf( _n( '%s for each month.', '%1$s for each %2$d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
121 | + $description = wp_sprintf(_n('%s for each month.', '%1$s for each %2$d months.', $interval, 'invoicing'), $amount, $interval); |
|
122 | 122 | } |
123 | 123 | break; |
124 | 124 | case 'Y': |
125 | 125 | case 'year': |
126 | - if ( (int)$bill_times > 0 ) { |
|
127 | - if ( $interval > 1 ) { |
|
128 | - if ( $bill_times > 1 ) { |
|
129 | - $description = wp_sprintf( __( '%1$s for each %2$d years, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
126 | + if ((int) $bill_times > 0) { |
|
127 | + if ($interval > 1) { |
|
128 | + if ($bill_times > 1) { |
|
129 | + $description = wp_sprintf(__('%1$s for each %2$d years, for %3$d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
130 | 130 | } else { |
131 | - $description = wp_sprintf( __( '%1$s for %2$d years.', 'invoicing' ), $amount, $interval ); |
|
131 | + $description = wp_sprintf(__('%1$s for %2$d years.', 'invoicing'), $amount, $interval); |
|
132 | 132 | } |
133 | 133 | } else { |
134 | - $description = wp_sprintf( _n( '%s for one year.', '%1$s for each year, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
134 | + $description = wp_sprintf(_n('%s for one year.', '%1$s for each year, for %2$d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
135 | 135 | } |
136 | 136 | } else { |
137 | - $description = wp_sprintf( _n( '%s for each year.', '%1$s for each %2$d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
137 | + $description = wp_sprintf(_n('%s for each year.', '%1$s for each %2$d years.', $interval, 'invoicing'), $amount, $interval); |
|
138 | 138 | } |
139 | 139 | break; |
140 | 140 | } |
141 | 141 | |
142 | - return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
142 | + return apply_filters('wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval); |
|
143 | 143 | } |
144 | 144 | |
145 | -function wpinv_subscription_payment_desc( $invoice ) { |
|
146 | - if ( empty( $invoice ) ) { |
|
145 | +function wpinv_subscription_payment_desc($invoice) { |
|
146 | + if (empty($invoice)) { |
|
147 | 147 | return null; |
148 | 148 | } |
149 | 149 | |
150 | 150 | $description = ''; |
151 | - if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) { |
|
152 | - if ( $item->has_free_trial() ) { |
|
151 | + if ($invoice->is_parent() && $item = $invoice->get_recurring(true)) { |
|
152 | + if ($item->has_free_trial()) { |
|
153 | 153 | $trial_period = $item->get_trial_period(); |
154 | 154 | $trial_interval = $item->get_trial_interval(); |
155 | 155 | } else { |
@@ -157,40 +157,40 @@ discard block |
||
157 | 157 | $trial_interval = 0; |
158 | 158 | } |
159 | 159 | |
160 | - $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() ); |
|
160 | + $description = wpinv_get_billing_cycle($invoice->get_total(), $invoice->get_recurring_details('total'), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency()); |
|
161 | 161 | } |
162 | 162 | |
163 | - return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice ); |
|
163 | + return apply_filters('wpinv_subscription_payment_desc', $description, $invoice); |
|
164 | 164 | } |
165 | 165 | |
166 | -function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) { |
|
167 | - $initial_total = wpinv_round_amount( $initial ); |
|
168 | - $recurring_total = wpinv_round_amount( $recurring ); |
|
166 | +function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') { |
|
167 | + $initial_total = wpinv_round_amount($initial); |
|
168 | + $recurring_total = wpinv_round_amount($recurring); |
|
169 | 169 | |
170 | - if ( $trial_interval > 0 && ! empty( $trial_period ) ) { |
|
170 | + if ($trial_interval > 0 && !empty($trial_period)) { |
|
171 | 171 | // Free trial |
172 | 172 | } else { |
173 | - if ( $bill_times == 1 ) { |
|
173 | + if ($bill_times == 1) { |
|
174 | 174 | $recurring_total = $initial_total; |
175 | - } elseif ( $bill_times > 1 && $initial_total != $recurring_total ) { |
|
175 | + } elseif ($bill_times > 1 && $initial_total != $recurring_total) { |
|
176 | 176 | $bill_times--; |
177 | 177 | } |
178 | 178 | } |
179 | 179 | |
180 | - $initial_amount = wpinv_price( $initial_total, $currency ); |
|
181 | - $recurring_amount = wpinv_price( $recurring_total, $currency ); |
|
180 | + $initial_amount = wpinv_price($initial_total, $currency); |
|
181 | + $recurring_amount = wpinv_price($recurring_total, $currency); |
|
182 | 182 | |
183 | - $recurring = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
183 | + $recurring = wpinv_subscription_recurring_payment_desc($recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval); |
|
184 | 184 | |
185 | - if ( $initial_total != $recurring_total ) { |
|
186 | - $initial = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval ); |
|
185 | + if ($initial_total != $recurring_total) { |
|
186 | + $initial = wpinv_subscription_initial_payment_desc($initial_amount, $period, $interval, $trial_period, $trial_interval); |
|
187 | 187 | |
188 | - $description = wp_sprintf( __( '%1$s Then %2$s', 'invoicing' ), $initial, $recurring ); |
|
188 | + $description = wp_sprintf(__('%1$s Then %2$s', 'invoicing'), $initial, $recurring); |
|
189 | 189 | } else { |
190 | 190 | $description = $recurring; |
191 | 191 | } |
192 | 192 | |
193 | - return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency ); |
|
193 | + return apply_filters('wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
@@ -200,27 +200,27 @@ discard block |
||
200 | 200 | * @param string $card_number Card number. |
201 | 201 | * @return string |
202 | 202 | */ |
203 | -function getpaid_get_card_name( $card_number ) { |
|
203 | +function getpaid_get_card_name($card_number) { |
|
204 | 204 | |
205 | 205 | // Known regexes. |
206 | 206 | $regexes = array( |
207 | - '/^4/' => __( 'Visa', 'invoicing' ), |
|
208 | - '/^5[1-5]/' => __( 'Mastercard', 'invoicing' ), |
|
209 | - '/^3[47]/' => __( 'Amex', 'invoicing' ), |
|
210 | - '/^3(?:0[0-5]|[68])/' => __( 'Diners Club', 'invoicing' ), |
|
211 | - '/^6(?:011|5)/' => __( 'Discover', 'invoicing' ), |
|
212 | - '/^(?:2131|1800|35\d{3})/' => __( 'JCB', 'invoicing' ), |
|
207 | + '/^4/' => __('Visa', 'invoicing'), |
|
208 | + '/^5[1-5]/' => __('Mastercard', 'invoicing'), |
|
209 | + '/^3[47]/' => __('Amex', 'invoicing'), |
|
210 | + '/^3(?:0[0-5]|[68])/' => __('Diners Club', 'invoicing'), |
|
211 | + '/^6(?:011|5)/' => __('Discover', 'invoicing'), |
|
212 | + '/^(?:2131|1800|35\d{3})/' => __('JCB', 'invoicing'), |
|
213 | 213 | ); |
214 | 214 | |
215 | 215 | // Confirm if one matches. |
216 | - foreach ( $regexes as $regex => $card ) { |
|
217 | - if ( preg_match( $regex, $card_number ) >= 1 ) { |
|
216 | + foreach ($regexes as $regex => $card) { |
|
217 | + if (preg_match($regex, $card_number) >= 1) { |
|
218 | 218 | return $card; |
219 | 219 | } |
220 | 220 | } |
221 | 221 | |
222 | 222 | // None matched. |
223 | - return __( 'Card', 'invoicing' ); |
|
223 | + return __('Card', 'invoicing'); |
|
224 | 224 | |
225 | 225 | } |
226 | 226 | |
@@ -229,25 +229,25 @@ discard block |
||
229 | 229 | * |
230 | 230 | * @param WPInv_Invoice|int|null $invoice |
231 | 231 | */ |
232 | -function wpinv_send_back_to_checkout( $invoice = null ) { |
|
233 | - $response = array( 'success' => false ); |
|
234 | - $invoice = wpinv_get_invoice( $invoice ); |
|
232 | +function wpinv_send_back_to_checkout($invoice = null) { |
|
233 | + $response = array('success' => false); |
|
234 | + $invoice = wpinv_get_invoice($invoice); |
|
235 | 235 | |
236 | 236 | // Was an invoice created? |
237 | - if ( ! empty( $invoice ) ) { |
|
238 | - $invoice = is_scalar( $invoice ) ? new WPInv_Invoice( $invoice ) : $invoice; |
|
237 | + if (!empty($invoice)) { |
|
238 | + $invoice = is_scalar($invoice) ? new WPInv_Invoice($invoice) : $invoice; |
|
239 | 239 | $response['invoice'] = $invoice->get_id(); |
240 | - do_action( 'getpaid_checkout_invoice_exception', $invoice ); |
|
240 | + do_action('getpaid_checkout_invoice_exception', $invoice); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | // Do we have any errors? |
244 | - if ( wpinv_get_errors() ) { |
|
245 | - $response['data'] = getpaid_get_errors_html( true, false ); |
|
244 | + if (wpinv_get_errors()) { |
|
245 | + $response['data'] = getpaid_get_errors_html(true, false); |
|
246 | 246 | } else { |
247 | - $response['data'] = __( 'An error occured while processing your payment. Please try again.', 'invoicing' ); |
|
247 | + $response['data'] = __('An error occured while processing your payment. Please try again.', 'invoicing'); |
|
248 | 248 | } |
249 | 249 | |
250 | - wp_send_json( $response ); |
|
250 | + wp_send_json($response); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | * @return string |
257 | 257 | */ |
258 | 258 | function getpaid_get_recaptcha_site_key() { |
259 | - return apply_filters( 'getpaid_recaptcha_site_key', wpinv_get_option( 'recaptcha_site_key', '' ) ); |
|
259 | + return apply_filters('getpaid_recaptcha_site_key', wpinv_get_option('recaptcha_site_key', '')); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | * @return string |
266 | 266 | */ |
267 | 267 | function getpaid_get_recaptcha_secret_key() { |
268 | - return apply_filters( 'getpaid_recaptcha_secret_key', wpinv_get_option( 'recaptcha_secret_key', '' ) ); |
|
268 | + return apply_filters('getpaid_recaptcha_secret_key', wpinv_get_option('recaptcha_secret_key', '')); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | * @return bool |
275 | 275 | */ |
276 | 276 | function getpaid_is_recaptcha_enabled() { |
277 | - return wpinv_get_option( 'enable_recaptcha', false ) && getpaid_get_recaptcha_site_key() && getpaid_get_recaptcha_secret_key(); |
|
277 | + return wpinv_get_option('enable_recaptcha', false) && getpaid_get_recaptcha_site_key() && getpaid_get_recaptcha_secret_key(); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | /** |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * @return string |
284 | 284 | */ |
285 | 285 | function getpaid_get_recaptcha_version() { |
286 | - return apply_filters( 'getpaid_recaptcha_version', wpinv_get_option( 'recaptcha_version', 'v2' ) ); |
|
286 | + return apply_filters('getpaid_recaptcha_version', wpinv_get_option('recaptcha_version', 'v2')); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | /** |
@@ -297,14 +297,14 @@ discard block |
||
297 | 297 | 'version' => getpaid_get_recaptcha_version(), |
298 | 298 | ); |
299 | 299 | |
300 | - if ( ! getpaid_is_recaptcha_enabled() ) { |
|
300 | + if (!getpaid_is_recaptcha_enabled()) { |
|
301 | 301 | return $settings; |
302 | 302 | } |
303 | 303 | |
304 | 304 | $settings['sitekey'] = getpaid_get_recaptcha_site_key(); |
305 | 305 | |
306 | 306 | // Version 2 render params. |
307 | - if ( 'v2' === getpaid_get_recaptcha_version() ) { |
|
307 | + if ('v2' === getpaid_get_recaptcha_version()) { |
|
308 | 308 | $settings['render_params'] = array( |
309 | 309 | 'sitekey' => getpaid_get_recaptcha_site_key(), |
310 | 310 | 'theme' => 'light', |
@@ -313,41 +313,41 @@ discard block |
||
313 | 313 | ); |
314 | 314 | } |
315 | 315 | |
316 | - return apply_filters( 'getpaid_recaptcha_settings', $settings ); |
|
316 | + return apply_filters('getpaid_recaptcha_settings', $settings); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
320 | 320 | * Displays reCAPTCHA before payment button. |
321 | 321 | */ |
322 | 322 | function getpaid_display_recaptcha_before_payment_button() { |
323 | - if ( ! getpaid_is_recaptcha_enabled() || 'v2' !== getpaid_get_recaptcha_version() ) { |
|
323 | + if (!getpaid_is_recaptcha_enabled() || 'v2' !== getpaid_get_recaptcha_version()) { |
|
324 | 324 | return; |
325 | 325 | } |
326 | 326 | |
327 | 327 | printf( |
328 | 328 | '<div class="getpaid-recaptcha-wrapper"><div class="g-recaptcha mw-100 overflow-hidden my-2" id="getpaid-recaptcha-%s"></div></div>', |
329 | - esc_attr( wp_unique_id() ) |
|
329 | + esc_attr(wp_unique_id()) |
|
330 | 330 | ); |
331 | 331 | } |
332 | -add_action( 'getpaid_before_payment_form_pay_button', 'getpaid_display_recaptcha_before_payment_button' ); |
|
332 | +add_action('getpaid_before_payment_form_pay_button', 'getpaid_display_recaptcha_before_payment_button'); |
|
333 | 333 | |
334 | 334 | /** |
335 | 335 | * Validates the reCAPTCHA response. |
336 | 336 | * |
337 | 337 | * @param GetPaid_Payment_Form_Submission $submission |
338 | 338 | */ |
339 | -function getpaid_validate_recaptcha_response( $submission ) { |
|
339 | +function getpaid_validate_recaptcha_response($submission) { |
|
340 | 340 | |
341 | 341 | // Check if reCAPTCHA is enabled. |
342 | - if ( ! getpaid_is_recaptcha_enabled() ) { |
|
342 | + if (!getpaid_is_recaptcha_enabled()) { |
|
343 | 343 | return; |
344 | 344 | } |
345 | 345 | |
346 | - $token = $submission->get_field( 'g-recaptcha-response' ); |
|
346 | + $token = $submission->get_field('g-recaptcha-response'); |
|
347 | 347 | |
348 | 348 | // Abort if no token was provided. |
349 | - if ( empty( $token ) ) { |
|
350 | - wp_send_json_error( 'v2' === getpaid_get_recaptcha_version() ? __( 'Please confirm that you are not a robot.', 'invoicing' ) : __( "Unable to verify that you're not a robot. Please try again.", 'invoicing' ) ); |
|
349 | + if (empty($token)) { |
|
350 | + wp_send_json_error('v2' === getpaid_get_recaptcha_version() ? __('Please confirm that you are not a robot.', 'invoicing') : __("Unable to verify that you're not a robot. Please try again.", 'invoicing')); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | $result = wp_remote_post( |
@@ -361,20 +361,20 @@ discard block |
||
361 | 361 | ); |
362 | 362 | |
363 | 363 | // Site not reachable, give benefit of doubt. |
364 | - if ( is_wp_error( $result ) ) { |
|
364 | + if (is_wp_error($result)) { |
|
365 | 365 | return; |
366 | 366 | } |
367 | 367 | |
368 | - $result = json_decode( wp_remote_retrieve_body( $result ), true ); |
|
368 | + $result = json_decode(wp_remote_retrieve_body($result), true); |
|
369 | 369 | |
370 | - if ( empty( $result['success'] ) && ! in_array( 'missing-input-secret', $result['error-codes'], true ) && ! in_array( 'invalid-input-secret', $result['error-codes'], true ) ) { |
|
371 | - wp_send_json_error( __( "Unable to verify that you're not a robot. Please try again.", 'invoicing' ) ); |
|
370 | + if (empty($result['success']) && !in_array('missing-input-secret', $result['error-codes'], true) && !in_array('invalid-input-secret', $result['error-codes'], true)) { |
|
371 | + wp_send_json_error(__("Unable to verify that you're not a robot. Please try again.", 'invoicing')); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | // For v3, check the score. |
375 | - $minimum_score = apply_filters( 'getpaid_recaptcha_minimum_score', 0.4 ); |
|
376 | - if ( 'v3' === getpaid_get_recaptcha_version() && ( empty( $result['score'] ) || $result['score'] < $minimum_score ) ) { |
|
377 | - wp_send_json_error( __( "Unable to verify that you're not a robot. Please try again.", 'invoicing' ) ); |
|
375 | + $minimum_score = apply_filters('getpaid_recaptcha_minimum_score', 0.4); |
|
376 | + if ('v3' === getpaid_get_recaptcha_version() && (empty($result['score']) || $result['score'] < $minimum_score)) { |
|
377 | + wp_send_json_error(__("Unable to verify that you're not a robot. Please try again.", 'invoicing')); |
|
378 | 378 | } |
379 | 379 | } |
380 | -add_action( 'getpaid_checkout_error_checks', 'getpaid_validate_recaptcha_response' ); |
|
380 | +add_action('getpaid_checkout_error_checks', 'getpaid_validate_recaptcha_response'); |