Passed
Push — master ( 555549...6eb161 )
by Brian
05:12
created
includes/wpinv-payment-functions.php 1 patch
Spacing   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -1,155 +1,155 @@  discard block
 block discarded – undo
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.', '%s for the first %d days.', $interval, 'invoicing' ), $amount, $interval );
51
+            $description = wp_sprintf(_n('%s for the first day.', '%s for the first %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.', '%s for the first %d weeks.', $interval, 'invoicing' ), $amount, $interval );
55
+            $description = wp_sprintf(_n('%s for the first week.', '%s for the first %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.', '%s for the first %d months.', $interval, 'invoicing' ), $amount, $interval );
59
+            $description = wp_sprintf(_n('%s for the first month.', '%s for the first %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.', '%s for the first %d years.', $interval, 'invoicing' ), $amount, $interval );
63
+            $description = wp_sprintf(_n('%s for the first year.', '%s for the first %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( __( '%s for each %d days, for %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(__('%s for each %d days, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
82 82
                     } else {
83
-                        $description = wp_sprintf( __( '%s for %d days.', 'invoicing' ), $amount, $interval );
83
+                        $description = wp_sprintf(__('%s for %d days.', 'invoicing'), $amount, $interval);
84 84
                     }
85 85
                 } else {
86
-                    $description = wp_sprintf( _n( '%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
86
+                    $description = wp_sprintf(_n('%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
87 87
                 }
88 88
             } else {
89
-                $description = wp_sprintf( _n( '%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval );
89
+                $description = wp_sprintf(_n('%s for each day.', '%s for each %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( __( '%s for each %d weeks, for %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(__('%s for each %d weeks, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
98 98
                     } else {
99
-                        $description = wp_sprintf( __( '%s for %d weeks.', 'invoicing' ), $amount, $interval );
99
+                        $description = wp_sprintf(__('%s for %d weeks.', 'invoicing'), $amount, $interval);
100 100
                     }
101 101
                 } else {
102
-                    $description = wp_sprintf( _n( '%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
102
+                    $description = wp_sprintf(_n('%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
103 103
                 }
104 104
             } else {
105
-                $description = wp_sprintf( _n( '%s for each week.', '%s for each %d weeks.', $interval, 'invoicing' ), $amount, $interval );
105
+                $description = wp_sprintf(_n('%s for each week.', '%s for each %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( __( '%s for each %d months, for %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(__('%s for each %d months, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
114 114
                     } else {
115
-                        $description = wp_sprintf( __( '%s for %d months.', 'invoicing' ), $amount, $interval );
115
+                        $description = wp_sprintf(__('%s for %d months.', 'invoicing'), $amount, $interval);
116 116
                     }
117 117
                 } else {
118
-                    $description = wp_sprintf( _n( '%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
118
+                    $description = wp_sprintf(_n('%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
119 119
                 }
120 120
             } else {
121
-                $description = wp_sprintf( _n( '%s for each month.', '%s for each %d months.', $interval, 'invoicing' ), $amount, $interval );
121
+                $description = wp_sprintf(_n('%s for each month.', '%s for each %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( __( '%s for each %d years, for %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(__('%s for each %d years, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
130 130
                     } else {
131
-                        $description = wp_sprintf( __( '%s for %d years.', 'invoicing'), $amount, $interval );
131
+                        $description = wp_sprintf(__('%s for %d years.', 'invoicing'), $amount, $interval);
132 132
                     }
133 133
                 } else {
134
-                    $description = wp_sprintf( _n( '%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
134
+                    $description = wp_sprintf(_n('%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
135 135
                 }
136 136
             } else {
137
-                $description = wp_sprintf( _n( '%s for each year.', '%s for each %d years.', $interval, 'invoicing' ), $amount, $interval );
137
+                $description = wp_sprintf(_n('%s for each year.', '%s for each %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
 block discarded – undo
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
-        } else if ( $bill_times > 1 && $initial_total != $recurring_total ) {
175
+        } else if ($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( __( '%s Then %s', 'invoicing' ), $initial, $recurring );
188
+        $description    = wp_sprintf(__('%s Then %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
 block discarded – undo
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,23 +229,23 @@  discard block
 block discarded – undo
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
 }
Please login to merge, or discard this patch.