@@ -13,30 +13,30 @@ discard block |
||
13 | 13 | class GetPaid_Bank_Transfer_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'bank_transfer'; |
21 | 21 | |
22 | - /** |
|
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - protected $supports = array( 'addons' ); |
|
22 | + /** |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + protected $supports = array( 'addons' ); |
|
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
34 | - public $order = 8; |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | + public $order = 8; |
|
35 | 35 | |
36 | 36 | /** |
37 | - * Class constructor. |
|
38 | - */ |
|
39 | - public function __construct() { |
|
37 | + * Class constructor. |
|
38 | + */ |
|
39 | + public function __construct() { |
|
40 | 40 | parent::__construct(); |
41 | 41 | |
42 | 42 | $this->title = __( 'Direct bank transfer', 'invoicing' ); |
@@ -44,22 +44,22 @@ discard block |
||
44 | 44 | $this->checkout_button_text = __( 'Proceed', 'invoicing' ); |
45 | 45 | $this->instructions = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) ); |
46 | 46 | |
47 | - add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
48 | - add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
49 | - add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
47 | + add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
48 | + add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
49 | + add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
50 | 50 | |
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
54 | - * Process Payment. |
|
55 | - * |
|
56 | - * |
|
57 | - * @param WPInv_Invoice $invoice Invoice. |
|
58 | - * @param array $submission_data Posted checkout fields. |
|
59 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
60 | - * @return array |
|
61 | - */ |
|
62 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
54 | + * Process Payment. |
|
55 | + * |
|
56 | + * |
|
57 | + * @param WPInv_Invoice $invoice Invoice. |
|
58 | + * @param array $submission_data Posted checkout fields. |
|
59 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
60 | + * @return array |
|
61 | + */ |
|
62 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
63 | 63 | |
64 | 64 | // Add a transaction id. |
65 | 65 | $invoice->set_transaction_id( $invoice->generate_key('trans_') ); |
@@ -80,66 +80,66 @@ discard block |
||
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
83 | - * Output for the order received page. |
|
84 | - * |
|
85 | - * @param WPInv_Invoice $invoice Invoice. |
|
86 | - */ |
|
87 | - public function thankyou_page( $invoice ) { |
|
83 | + * Output for the order received page. |
|
84 | + * |
|
85 | + * @param WPInv_Invoice $invoice Invoice. |
|
86 | + */ |
|
87 | + public function thankyou_page( $invoice ) { |
|
88 | 88 | |
89 | 89 | if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
90 | 90 | |
91 | - echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
|
91 | + echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
|
92 | 92 | |
93 | 93 | if ( ! empty( $this->instructions ) ) { |
94 | 94 | echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) ); |
95 | - } |
|
95 | + } |
|
96 | 96 | |
97 | - $this->bank_details( $invoice ); |
|
97 | + $this->bank_details( $invoice ); |
|
98 | 98 | |
99 | - echo '</div>'; |
|
99 | + echo '</div>'; |
|
100 | 100 | |
101 | 101 | } |
102 | 102 | |
103 | - } |
|
103 | + } |
|
104 | 104 | |
105 | 105 | /** |
106 | - * Add content to the WPI emails. |
|
107 | - * |
|
108 | - * @param WPInv_Invoice $invoice Invoice. |
|
109 | - * @param string $email_type Email format: plain text or HTML. |
|
110 | - * @param bool $sent_to_admin Sent to admin. |
|
111 | - */ |
|
112 | - public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
106 | + * Add content to the WPI emails. |
|
107 | + * |
|
108 | + * @param WPInv_Invoice $invoice Invoice. |
|
109 | + * @param string $email_type Email format: plain text or HTML. |
|
110 | + * @param bool $sent_to_admin Sent to admin. |
|
111 | + */ |
|
112 | + public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
113 | 113 | |
114 | - if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
114 | + if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
115 | 115 | |
116 | - echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
|
116 | + echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
|
117 | 117 | |
118 | - if ( $this->instructions ) { |
|
119 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
118 | + if ( $this->instructions ) { |
|
119 | + echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
120 | 120 | } |
121 | 121 | |
122 | - $this->bank_details( $invoice ); |
|
122 | + $this->bank_details( $invoice ); |
|
123 | 123 | |
124 | - echo '</div>'; |
|
124 | + echo '</div>'; |
|
125 | 125 | |
126 | - } |
|
126 | + } |
|
127 | 127 | |
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
131 | - * Get bank details and place into a list format. |
|
132 | - * |
|
133 | - * @param WPInv_Invoice $invoice Invoice. |
|
134 | - */ |
|
135 | - protected function bank_details( $invoice ) { |
|
131 | + * Get bank details and place into a list format. |
|
132 | + * |
|
133 | + * @param WPInv_Invoice $invoice Invoice. |
|
134 | + */ |
|
135 | + protected function bank_details( $invoice ) { |
|
136 | 136 | |
137 | - // Get the invoice country and country $locale. |
|
138 | - $country = $invoice->get_country(); |
|
139 | - $locale = $this->get_country_locale(); |
|
137 | + // Get the invoice country and country $locale. |
|
138 | + $country = $invoice->get_country(); |
|
139 | + $locale = $this->get_country_locale(); |
|
140 | 140 | |
141 | - // Get sortcode label in the $locale array and use appropriate one. |
|
142 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
141 | + // Get sortcode label in the $locale array and use appropriate one. |
|
142 | + $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
143 | 143 | |
144 | 144 | $bank_fields = array( |
145 | 145 | 'ac_name' => __( 'Account Name', 'invoicing' ), |
@@ -168,144 +168,144 @@ discard block |
||
168 | 168 | return; |
169 | 169 | } |
170 | 170 | |
171 | - echo '<h3 class="getpaid-bank-transfer-title"> ' . apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ) ) . '</h3>' . PHP_EOL; |
|
171 | + echo '<h3 class="getpaid-bank-transfer-title"> ' . apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ) ) . '</h3>' . PHP_EOL; |
|
172 | 172 | |
173 | - echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
|
173 | + echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
|
174 | 174 | |
175 | - foreach ( $bank_info as $key => $data ) { |
|
175 | + foreach ( $bank_info as $key => $data ) { |
|
176 | 176 | |
177 | - $key = sanitize_html_class( $key ); |
|
178 | - $label = wp_kses_post( $data['label'] ); |
|
179 | - $value = wp_kses_post( wptexturize( $data['value'] ) ); |
|
177 | + $key = sanitize_html_class( $key ); |
|
178 | + $label = wp_kses_post( $data['label'] ); |
|
179 | + $value = wp_kses_post( wptexturize( $data['value'] ) ); |
|
180 | 180 | |
181 | - echo "<tr class='getpaid-bank-transfer-$key'><th>$label</th><td>$value</td></tr>" . PHP_EOL; |
|
182 | - } |
|
181 | + echo "<tr class='getpaid-bank-transfer-$key'><th>$label</th><td>$value</td></tr>" . PHP_EOL; |
|
182 | + } |
|
183 | 183 | |
184 | - echo '</table>'; |
|
184 | + echo '</table>'; |
|
185 | 185 | |
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
189 | - * Get country locale if localized. |
|
190 | - * |
|
191 | - * @return array |
|
192 | - */ |
|
193 | - public function get_country_locale() { |
|
194 | - |
|
195 | - if ( empty( $this->locale ) ) { |
|
196 | - |
|
197 | - // Locale information to be used - only those that are not 'Sort Code'. |
|
198 | - $this->locale = apply_filters( |
|
199 | - 'getpaid_get_bank_transfer_locale', |
|
200 | - array( |
|
201 | - 'AU' => array( |
|
202 | - 'sortcode' => array( |
|
203 | - 'label' => __( 'BSB', 'invoicing' ), |
|
204 | - ), |
|
205 | - ), |
|
206 | - 'CA' => array( |
|
207 | - 'sortcode' => array( |
|
208 | - 'label' => __( 'Bank transit number', 'invoicing' ), |
|
209 | - ), |
|
210 | - ), |
|
211 | - 'IN' => array( |
|
212 | - 'sortcode' => array( |
|
213 | - 'label' => __( 'IFSC', 'invoicing' ), |
|
214 | - ), |
|
215 | - ), |
|
216 | - 'IT' => array( |
|
217 | - 'sortcode' => array( |
|
218 | - 'label' => __( 'Branch sort', 'invoicing' ), |
|
219 | - ), |
|
220 | - ), |
|
221 | - 'NZ' => array( |
|
222 | - 'sortcode' => array( |
|
223 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
224 | - ), |
|
225 | - ), |
|
226 | - 'SE' => array( |
|
227 | - 'sortcode' => array( |
|
228 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
229 | - ), |
|
230 | - ), |
|
231 | - 'US' => array( |
|
232 | - 'sortcode' => array( |
|
233 | - 'label' => __( 'Routing number', 'invoicing' ), |
|
234 | - ), |
|
235 | - ), |
|
236 | - 'ZA' => array( |
|
237 | - 'sortcode' => array( |
|
238 | - 'label' => __( 'Branch code', 'invoicing' ), |
|
239 | - ), |
|
240 | - ), |
|
241 | - ) |
|
242 | - ); |
|
243 | - |
|
244 | - } |
|
245 | - |
|
246 | - return $this->locale; |
|
247 | - |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Filters the gateway settings. |
|
252 | - * |
|
253 | - * @param array $admin_settings |
|
254 | - */ |
|
255 | - public function admin_settings( $admin_settings ) { |
|
189 | + * Get country locale if localized. |
|
190 | + * |
|
191 | + * @return array |
|
192 | + */ |
|
193 | + public function get_country_locale() { |
|
194 | + |
|
195 | + if ( empty( $this->locale ) ) { |
|
196 | + |
|
197 | + // Locale information to be used - only those that are not 'Sort Code'. |
|
198 | + $this->locale = apply_filters( |
|
199 | + 'getpaid_get_bank_transfer_locale', |
|
200 | + array( |
|
201 | + 'AU' => array( |
|
202 | + 'sortcode' => array( |
|
203 | + 'label' => __( 'BSB', 'invoicing' ), |
|
204 | + ), |
|
205 | + ), |
|
206 | + 'CA' => array( |
|
207 | + 'sortcode' => array( |
|
208 | + 'label' => __( 'Bank transit number', 'invoicing' ), |
|
209 | + ), |
|
210 | + ), |
|
211 | + 'IN' => array( |
|
212 | + 'sortcode' => array( |
|
213 | + 'label' => __( 'IFSC', 'invoicing' ), |
|
214 | + ), |
|
215 | + ), |
|
216 | + 'IT' => array( |
|
217 | + 'sortcode' => array( |
|
218 | + 'label' => __( 'Branch sort', 'invoicing' ), |
|
219 | + ), |
|
220 | + ), |
|
221 | + 'NZ' => array( |
|
222 | + 'sortcode' => array( |
|
223 | + 'label' => __( 'Bank code', 'invoicing' ), |
|
224 | + ), |
|
225 | + ), |
|
226 | + 'SE' => array( |
|
227 | + 'sortcode' => array( |
|
228 | + 'label' => __( 'Bank code', 'invoicing' ), |
|
229 | + ), |
|
230 | + ), |
|
231 | + 'US' => array( |
|
232 | + 'sortcode' => array( |
|
233 | + 'label' => __( 'Routing number', 'invoicing' ), |
|
234 | + ), |
|
235 | + ), |
|
236 | + 'ZA' => array( |
|
237 | + 'sortcode' => array( |
|
238 | + 'label' => __( 'Branch code', 'invoicing' ), |
|
239 | + ), |
|
240 | + ), |
|
241 | + ) |
|
242 | + ); |
|
243 | + |
|
244 | + } |
|
245 | + |
|
246 | + return $this->locale; |
|
247 | + |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Filters the gateway settings. |
|
252 | + * |
|
253 | + * @param array $admin_settings |
|
254 | + */ |
|
255 | + public function admin_settings( $admin_settings ) { |
|
256 | 256 | |
257 | 257 | $admin_settings['worldpay_desc']['std'] = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ); |
258 | - $admin_settings['worldpay_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
258 | + $admin_settings['worldpay_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
259 | 259 | |
260 | - $locale = $this->get_country_locale(); |
|
260 | + $locale = $this->get_country_locale(); |
|
261 | 261 | |
262 | - // Get sortcode label in the $locale array and use appropriate one. |
|
263 | - $country = wpinv_default_billing_country(); |
|
264 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
262 | + // Get sortcode label in the $locale array and use appropriate one. |
|
263 | + $country = wpinv_default_billing_country(); |
|
264 | + $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
265 | 265 | |
266 | - $admin_settings['bank_transfer_ac_name'] = array( |
|
266 | + $admin_settings['bank_transfer_ac_name'] = array( |
|
267 | 267 | 'type' => 'text', |
268 | 268 | 'id' => 'bank_transfer_ac_name', |
269 | 269 | 'name' => __( 'Account Name', 'invoicing' ), |
270 | - ); |
|
270 | + ); |
|
271 | 271 | |
272 | - $admin_settings['bank_transfer_ac_no'] = array( |
|
272 | + $admin_settings['bank_transfer_ac_no'] = array( |
|
273 | 273 | 'type' => 'text', |
274 | 274 | 'id' => 'bank_transfer_ac_no', |
275 | 275 | 'name' => __( 'Account Number', 'invoicing' ), |
276 | - ); |
|
276 | + ); |
|
277 | 277 | |
278 | - $admin_settings['bank_transfer_bank_name'] = array( |
|
278 | + $admin_settings['bank_transfer_bank_name'] = array( |
|
279 | 279 | 'type' => 'text', |
280 | 280 | 'id' => 'bank_transfer_bank_name', |
281 | 281 | 'name' => __( 'Bank Name', 'invoicing' ), |
282 | - ); |
|
282 | + ); |
|
283 | 283 | |
284 | - $admin_settings['bank_transfer_ifsc'] = array( |
|
284 | + $admin_settings['bank_transfer_ifsc'] = array( |
|
285 | 285 | 'type' => 'text', |
286 | 286 | 'id' => 'bank_transfer_ifsc', |
287 | 287 | 'name' => __( 'IFSC Code', 'invoicing' ), |
288 | - ); |
|
288 | + ); |
|
289 | 289 | |
290 | - $admin_settings['bank_transfer_iban'] = array( |
|
290 | + $admin_settings['bank_transfer_iban'] = array( |
|
291 | 291 | 'type' => 'text', |
292 | 292 | 'id' => 'bank_transfer_iban', |
293 | 293 | 'name' => __( 'IBAN', 'invoicing' ), |
294 | - ); |
|
294 | + ); |
|
295 | 295 | |
296 | - $admin_settings['bank_transfer_bic'] = array( |
|
296 | + $admin_settings['bank_transfer_bic'] = array( |
|
297 | 297 | 'type' => 'text', |
298 | 298 | 'id' => 'bank_transfer_bic', |
299 | 299 | 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
300 | - ); |
|
300 | + ); |
|
301 | 301 | |
302 | - $admin_settings['bank_transfer_sort_code'] = array( |
|
303 | - 'type' => 'text', |
|
304 | - 'id' => 'bank_transfer_sort_code', |
|
305 | - 'name' => $sortcode, |
|
306 | - ); |
|
302 | + $admin_settings['bank_transfer_sort_code'] = array( |
|
303 | + 'type' => 'text', |
|
304 | + 'id' => 'bank_transfer_sort_code', |
|
305 | + 'name' => $sortcode, |
|
306 | + ); |
|
307 | 307 | |
308 | - $admin_settings['bank_transfer_info'] = array( |
|
308 | + $admin_settings['bank_transfer_info'] = array( |
|
309 | 309 | 'id' => 'bank_transfer_info', |
310 | 310 | 'name' => __( 'Instructions', 'invoicing' ), |
311 | 311 | 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | 'rows' => 5 |
316 | 316 | ); |
317 | 317 | |
318 | - return $admin_settings; |
|
319 | - } |
|
318 | + return $admin_settings; |
|
319 | + } |
|
320 | 320 | |
321 | 321 | } |
@@ -13,30 +13,30 @@ discard block |
||
13 | 13 | class GetPaid_Manual_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'manual'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription', 'addons' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
34 | - public $order = 11; |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | + public $order = 11; |
|
35 | 35 | |
36 | 36 | /** |
37 | - * Class constructor. |
|
38 | - */ |
|
39 | - public function __construct() { |
|
37 | + * Class constructor. |
|
38 | + */ |
|
39 | + public function __construct() { |
|
40 | 40 | parent::__construct(); |
41 | 41 | |
42 | 42 | $this->title = __( 'Manual Payment', 'invoicing' ); |
@@ -46,15 +46,15 @@ discard block |
||
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
49 | - * Process Payment. |
|
50 | - * |
|
51 | - * |
|
52 | - * @param WPInv_Invoice $invoice Invoice. |
|
53 | - * @param array $submission_data Posted checkout fields. |
|
54 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
55 | - * @return array |
|
56 | - */ |
|
57 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
49 | + * Process Payment. |
|
50 | + * |
|
51 | + * |
|
52 | + * @param WPInv_Invoice $invoice Invoice. |
|
53 | + * @param array $submission_data Posted checkout fields. |
|
54 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
55 | + * @return array |
|
56 | + */ |
|
57 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
58 | 58 | |
59 | 59 | // Mark it as paid. |
60 | 60 | $invoice->mark_paid(); |
@@ -68,13 +68,13 @@ discard block |
||
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
71 | - * (Maybe) renews a manual subscription profile. |
|
72 | - * |
|
73 | - * |
|
74 | - * @param bool $should_expire |
|
71 | + * (Maybe) renews a manual subscription profile. |
|
72 | + * |
|
73 | + * |
|
74 | + * @param bool $should_expire |
|
75 | 75 | * @param WPInv_Subscription $subscription |
76 | - */ |
|
77 | - public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
76 | + */ |
|
77 | + public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
78 | 78 | |
79 | 79 | // Ensure its our subscription && it's active. |
80 | 80 | if ( 'manual' != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) { |
@@ -13,467 +13,467 @@ discard block |
||
13 | 13 | */ |
14 | 14 | abstract class GetPaid_Payment_Gateway { |
15 | 15 | |
16 | - /** |
|
17 | - * Set if the place checkout button should be renamed on selection. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $checkout_button_text; |
|
22 | - |
|
23 | - /** |
|
24 | - * Boolean whether the method is enabled. |
|
25 | - * |
|
26 | - * @var bool |
|
27 | - */ |
|
28 | - public $enabled = true; |
|
29 | - |
|
30 | - /** |
|
31 | - * Payment method id. |
|
32 | - * |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - public $id; |
|
36 | - |
|
37 | - /** |
|
38 | - * Payment method order. |
|
39 | - * |
|
40 | - * @var int |
|
41 | - */ |
|
42 | - public $order = 10; |
|
43 | - |
|
44 | - /** |
|
45 | - * Payment method title for the frontend. |
|
46 | - * |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - public $title; |
|
50 | - |
|
51 | - /** |
|
52 | - * Payment method description for the frontend. |
|
53 | - * |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - public $description; |
|
57 | - |
|
58 | - /** |
|
59 | - * Gateway title. |
|
60 | - * |
|
61 | - * @var string |
|
62 | - */ |
|
63 | - public $method_title = ''; |
|
64 | - |
|
65 | - /** |
|
66 | - * Gateway description. |
|
67 | - * |
|
68 | - * @var string |
|
69 | - */ |
|
70 | - public $method_description = ''; |
|
71 | - |
|
72 | - /** |
|
73 | - * Countries this gateway is allowed for. |
|
74 | - * |
|
75 | - * @var array |
|
76 | - */ |
|
77 | - public $countries; |
|
78 | - |
|
79 | - /** |
|
80 | - * Currencies this gateway is allowed for. |
|
81 | - * |
|
82 | - * @var array |
|
83 | - */ |
|
84 | - public $currencies; |
|
85 | - |
|
86 | - /** |
|
87 | - * Currencies this gateway is not allowed for. |
|
88 | - * |
|
89 | - * @var array |
|
90 | - */ |
|
91 | - public $exclude_currencies; |
|
92 | - |
|
93 | - /** |
|
94 | - * Maximum transaction amount, zero does not define a maximum. |
|
95 | - * |
|
96 | - * @var int |
|
97 | - */ |
|
98 | - public $max_amount = 0; |
|
99 | - |
|
100 | - /** |
|
101 | - * Optional URL to view a transaction. |
|
102 | - * |
|
103 | - * @var string |
|
104 | - */ |
|
105 | - public $view_transaction_url = ''; |
|
106 | - |
|
107 | - /** |
|
108 | - * Optional URL to view a subscription. |
|
109 | - * |
|
110 | - * @var string |
|
111 | - */ |
|
112 | - public $view_subscription_url = ''; |
|
113 | - |
|
114 | - /** |
|
115 | - * Optional label to show for "new payment method" in the payment |
|
116 | - * method/token selection radio selection. |
|
117 | - * |
|
118 | - * @var string |
|
119 | - */ |
|
120 | - public $new_method_label = ''; |
|
121 | - |
|
122 | - /** |
|
123 | - * Contains a user's saved tokens for this gateway. |
|
124 | - * |
|
125 | - * @var array |
|
126 | - */ |
|
127 | - protected $tokens = array(); |
|
128 | - |
|
129 | - /** |
|
130 | - * An array of features that this gateway supports. |
|
131 | - * |
|
132 | - * @var array |
|
133 | - */ |
|
134 | - protected $supports = array(); |
|
135 | - |
|
136 | - /** |
|
137 | - * Class constructor. |
|
138 | - */ |
|
139 | - public function __construct() { |
|
140 | - |
|
141 | - // Register gateway. |
|
142 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
143 | - |
|
144 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
145 | - |
|
146 | - // Enable Subscriptions. |
|
147 | - if ( $this->supports( 'subscription' ) ) { |
|
148 | - add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' ); |
|
149 | - } |
|
150 | - |
|
151 | - // Enable sandbox. |
|
152 | - if ( $this->supports( 'sandbox' ) ) { |
|
153 | - add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' ); |
|
154 | - } |
|
155 | - |
|
156 | - // Invoice addons. |
|
157 | - if ( $this->supports( 'addons' ) ) { |
|
158 | - add_filter( "getpaid_{$this->id}_supports_addons", '__return_true' ); |
|
159 | - add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ) ); |
|
160 | - } |
|
161 | - |
|
162 | - // Gateway settings. |
|
163 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
16 | + /** |
|
17 | + * Set if the place checkout button should be renamed on selection. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $checkout_button_text; |
|
22 | + |
|
23 | + /** |
|
24 | + * Boolean whether the method is enabled. |
|
25 | + * |
|
26 | + * @var bool |
|
27 | + */ |
|
28 | + public $enabled = true; |
|
29 | + |
|
30 | + /** |
|
31 | + * Payment method id. |
|
32 | + * |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + public $id; |
|
36 | + |
|
37 | + /** |
|
38 | + * Payment method order. |
|
39 | + * |
|
40 | + * @var int |
|
41 | + */ |
|
42 | + public $order = 10; |
|
43 | + |
|
44 | + /** |
|
45 | + * Payment method title for the frontend. |
|
46 | + * |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + public $title; |
|
50 | + |
|
51 | + /** |
|
52 | + * Payment method description for the frontend. |
|
53 | + * |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + public $description; |
|
57 | + |
|
58 | + /** |
|
59 | + * Gateway title. |
|
60 | + * |
|
61 | + * @var string |
|
62 | + */ |
|
63 | + public $method_title = ''; |
|
64 | + |
|
65 | + /** |
|
66 | + * Gateway description. |
|
67 | + * |
|
68 | + * @var string |
|
69 | + */ |
|
70 | + public $method_description = ''; |
|
71 | + |
|
72 | + /** |
|
73 | + * Countries this gateway is allowed for. |
|
74 | + * |
|
75 | + * @var array |
|
76 | + */ |
|
77 | + public $countries; |
|
78 | + |
|
79 | + /** |
|
80 | + * Currencies this gateway is allowed for. |
|
81 | + * |
|
82 | + * @var array |
|
83 | + */ |
|
84 | + public $currencies; |
|
85 | + |
|
86 | + /** |
|
87 | + * Currencies this gateway is not allowed for. |
|
88 | + * |
|
89 | + * @var array |
|
90 | + */ |
|
91 | + public $exclude_currencies; |
|
92 | + |
|
93 | + /** |
|
94 | + * Maximum transaction amount, zero does not define a maximum. |
|
95 | + * |
|
96 | + * @var int |
|
97 | + */ |
|
98 | + public $max_amount = 0; |
|
99 | + |
|
100 | + /** |
|
101 | + * Optional URL to view a transaction. |
|
102 | + * |
|
103 | + * @var string |
|
104 | + */ |
|
105 | + public $view_transaction_url = ''; |
|
106 | + |
|
107 | + /** |
|
108 | + * Optional URL to view a subscription. |
|
109 | + * |
|
110 | + * @var string |
|
111 | + */ |
|
112 | + public $view_subscription_url = ''; |
|
113 | + |
|
114 | + /** |
|
115 | + * Optional label to show for "new payment method" in the payment |
|
116 | + * method/token selection radio selection. |
|
117 | + * |
|
118 | + * @var string |
|
119 | + */ |
|
120 | + public $new_method_label = ''; |
|
121 | + |
|
122 | + /** |
|
123 | + * Contains a user's saved tokens for this gateway. |
|
124 | + * |
|
125 | + * @var array |
|
126 | + */ |
|
127 | + protected $tokens = array(); |
|
128 | + |
|
129 | + /** |
|
130 | + * An array of features that this gateway supports. |
|
131 | + * |
|
132 | + * @var array |
|
133 | + */ |
|
134 | + protected $supports = array(); |
|
135 | + |
|
136 | + /** |
|
137 | + * Class constructor. |
|
138 | + */ |
|
139 | + public function __construct() { |
|
140 | + |
|
141 | + // Register gateway. |
|
142 | + add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
143 | + |
|
144 | + $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
145 | + |
|
146 | + // Enable Subscriptions. |
|
147 | + if ( $this->supports( 'subscription' ) ) { |
|
148 | + add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' ); |
|
149 | + } |
|
150 | + |
|
151 | + // Enable sandbox. |
|
152 | + if ( $this->supports( 'sandbox' ) ) { |
|
153 | + add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' ); |
|
154 | + } |
|
155 | + |
|
156 | + // Invoice addons. |
|
157 | + if ( $this->supports( 'addons' ) ) { |
|
158 | + add_filter( "getpaid_{$this->id}_supports_addons", '__return_true' ); |
|
159 | + add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ) ); |
|
160 | + } |
|
161 | + |
|
162 | + // Gateway settings. |
|
163 | + add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
164 | 164 | |
165 | 165 | |
166 | - // Gateway checkout fiellds. |
|
167 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
168 | - |
|
169 | - // Process payment. |
|
170 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
166 | + // Gateway checkout fiellds. |
|
167 | + add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
168 | + |
|
169 | + // Process payment. |
|
170 | + add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
171 | + |
|
172 | + // Change the checkout button text. |
|
173 | + if ( ! empty( $this->checkout_button_text ) ) { |
|
174 | + add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
175 | + } |
|
176 | + |
|
177 | + // Check if a gateway is valid for a given currency. |
|
178 | + add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
179 | + |
|
180 | + // Generate the transaction url. |
|
181 | + add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
182 | + |
|
183 | + // Generate the subscription url. |
|
184 | + add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 ); |
|
185 | + |
|
186 | + // Confirm payments. |
|
187 | + add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
188 | + |
|
189 | + // Verify IPNs. |
|
190 | + add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
191 | + |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Checks if this gateway is a given gateway. |
|
196 | + * |
|
197 | + * @since 1.0.19 |
|
198 | + * @return bool |
|
199 | + */ |
|
200 | + public function is( $gateway ) { |
|
201 | + return $gateway == $this->id; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Returns a users saved tokens for this gateway. |
|
206 | + * |
|
207 | + * @since 1.0.19 |
|
208 | + * @return array |
|
209 | + */ |
|
210 | + public function get_tokens( $sandbox = null ) { |
|
211 | + |
|
212 | + if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
213 | + $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
214 | + |
|
215 | + if ( is_array( $tokens ) ) { |
|
216 | + $this->tokens = $tokens; |
|
217 | + } |
|
218 | + |
|
219 | + } |
|
220 | + |
|
221 | + if ( ! is_bool( $sandbox ) ) { |
|
222 | + return $this->tokens; |
|
223 | + } |
|
224 | + |
|
225 | + $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
226 | + return wp_list_filter( $this->tokens, $args ); |
|
227 | + |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Saves a token for this gateway. |
|
232 | + * |
|
233 | + * @since 1.0.19 |
|
234 | + */ |
|
235 | + public function save_token( $token ) { |
|
236 | + |
|
237 | + $tokens = $this->get_tokens(); |
|
238 | + $tokens[] = $token; |
|
239 | + |
|
240 | + update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
241 | + |
|
242 | + $this->tokens = $tokens; |
|
243 | + |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * Return the title for admin screens. |
|
248 | + * |
|
249 | + * @return string |
|
250 | + */ |
|
251 | + public function get_method_title() { |
|
252 | + return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * Return the description for admin screens. |
|
257 | + * |
|
258 | + * @return string |
|
259 | + */ |
|
260 | + public function get_method_description() { |
|
261 | + return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Get the success url. |
|
266 | + * |
|
267 | + * @param WPInv_Invoice $invoice Invoice object. |
|
268 | + * @return string |
|
269 | + */ |
|
270 | + public function get_return_url( $invoice ) { |
|
271 | + |
|
272 | + // Payment success url |
|
273 | + $return_url = add_query_arg( |
|
274 | + array( |
|
275 | + 'payment-confirm' => $this->id, |
|
276 | + 'invoice_key' => $invoice->get_key(), |
|
277 | + 'utm_nooverride' => 1 |
|
278 | + ), |
|
279 | + wpinv_get_success_page_uri() |
|
280 | + ); |
|
281 | + |
|
282 | + return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * Confirms payments when rendering the success page. |
|
287 | + * |
|
288 | + * @param string $content Success page content. |
|
289 | + * @return string |
|
290 | + */ |
|
291 | + public function confirm_payment( $content ) { |
|
292 | + |
|
293 | + // Retrieve the invoice. |
|
294 | + $invoice_id = getpaid_get_current_invoice_id(); |
|
295 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
296 | + |
|
297 | + // Ensure that it exists and that it is pending payment. |
|
298 | + if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
299 | + return $content; |
|
300 | + } |
|
301 | + |
|
302 | + // Can the user view this invoice?? |
|
303 | + if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
304 | + return $content; |
|
305 | + } |
|
306 | + |
|
307 | + // Show payment processing indicator. |
|
308 | + return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * Processes ipns and marks payments as complete. |
|
313 | + * |
|
314 | + * @return void |
|
315 | + */ |
|
316 | + public function verify_ipn() {} |
|
317 | + |
|
318 | + /** |
|
319 | + * Processes invoice addons. |
|
320 | + * |
|
321 | + * @param WPInv_Invoice $invoice |
|
322 | + * @param GetPaid_Form_Item[] $items |
|
323 | + * @return WPInv_Invoice |
|
324 | + */ |
|
325 | + public function process_addons( $invoice, $items ) { |
|
326 | + |
|
327 | + } |
|
328 | + |
|
329 | + /** |
|
330 | + * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
331 | + * |
|
332 | + * @param string $transaction_url transaction url. |
|
333 | + * @param WPInv_Invoice $invoice Invoice object. |
|
334 | + * @return string transaction URL, or empty string. |
|
335 | + */ |
|
336 | + public function filter_transaction_url( $transaction_url, $invoice ) { |
|
337 | + |
|
338 | + $transaction_id = $invoice->get_transaction_id(); |
|
339 | + |
|
340 | + if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
341 | + $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
342 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
343 | + $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
344 | + } |
|
345 | + |
|
346 | + return $transaction_url; |
|
347 | + } |
|
348 | + |
|
349 | + /** |
|
350 | + * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
351 | + * |
|
352 | + * @param string $subscription_url transaction url. |
|
353 | + * @param WPInv_Invoice $invoice Invoice object. |
|
354 | + * @return string subscription URL, or empty string. |
|
355 | + */ |
|
356 | + public function filter_subscription_url( $subscription_url, $invoice ) { |
|
357 | + |
|
358 | + $profile_id = $invoice->get_subscription_id(); |
|
359 | + |
|
360 | + if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
171 | 361 | |
172 | - // Change the checkout button text. |
|
173 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
174 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
175 | - } |
|
176 | - |
|
177 | - // Check if a gateway is valid for a given currency. |
|
178 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
179 | - |
|
180 | - // Generate the transaction url. |
|
181 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
182 | - |
|
183 | - // Generate the subscription url. |
|
184 | - add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 ); |
|
185 | - |
|
186 | - // Confirm payments. |
|
187 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
188 | - |
|
189 | - // Verify IPNs. |
|
190 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
191 | - |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Checks if this gateway is a given gateway. |
|
196 | - * |
|
197 | - * @since 1.0.19 |
|
198 | - * @return bool |
|
199 | - */ |
|
200 | - public function is( $gateway ) { |
|
201 | - return $gateway == $this->id; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Returns a users saved tokens for this gateway. |
|
206 | - * |
|
207 | - * @since 1.0.19 |
|
208 | - * @return array |
|
209 | - */ |
|
210 | - public function get_tokens( $sandbox = null ) { |
|
211 | - |
|
212 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
213 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
214 | - |
|
215 | - if ( is_array( $tokens ) ) { |
|
216 | - $this->tokens = $tokens; |
|
217 | - } |
|
218 | - |
|
219 | - } |
|
220 | - |
|
221 | - if ( ! is_bool( $sandbox ) ) { |
|
222 | - return $this->tokens; |
|
223 | - } |
|
224 | - |
|
225 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
226 | - return wp_list_filter( $this->tokens, $args ); |
|
227 | - |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Saves a token for this gateway. |
|
232 | - * |
|
233 | - * @since 1.0.19 |
|
234 | - */ |
|
235 | - public function save_token( $token ) { |
|
236 | - |
|
237 | - $tokens = $this->get_tokens(); |
|
238 | - $tokens[] = $token; |
|
239 | - |
|
240 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
241 | - |
|
242 | - $this->tokens = $tokens; |
|
243 | - |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * Return the title for admin screens. |
|
248 | - * |
|
249 | - * @return string |
|
250 | - */ |
|
251 | - public function get_method_title() { |
|
252 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * Return the description for admin screens. |
|
257 | - * |
|
258 | - * @return string |
|
259 | - */ |
|
260 | - public function get_method_description() { |
|
261 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Get the success url. |
|
266 | - * |
|
267 | - * @param WPInv_Invoice $invoice Invoice object. |
|
268 | - * @return string |
|
269 | - */ |
|
270 | - public function get_return_url( $invoice ) { |
|
271 | - |
|
272 | - // Payment success url |
|
273 | - $return_url = add_query_arg( |
|
274 | - array( |
|
275 | - 'payment-confirm' => $this->id, |
|
276 | - 'invoice_key' => $invoice->get_key(), |
|
277 | - 'utm_nooverride' => 1 |
|
278 | - ), |
|
279 | - wpinv_get_success_page_uri() |
|
280 | - ); |
|
281 | - |
|
282 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * Confirms payments when rendering the success page. |
|
287 | - * |
|
288 | - * @param string $content Success page content. |
|
289 | - * @return string |
|
290 | - */ |
|
291 | - public function confirm_payment( $content ) { |
|
292 | - |
|
293 | - // Retrieve the invoice. |
|
294 | - $invoice_id = getpaid_get_current_invoice_id(); |
|
295 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
296 | - |
|
297 | - // Ensure that it exists and that it is pending payment. |
|
298 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
299 | - return $content; |
|
300 | - } |
|
301 | - |
|
302 | - // Can the user view this invoice?? |
|
303 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
304 | - return $content; |
|
305 | - } |
|
306 | - |
|
307 | - // Show payment processing indicator. |
|
308 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * Processes ipns and marks payments as complete. |
|
313 | - * |
|
314 | - * @return void |
|
315 | - */ |
|
316 | - public function verify_ipn() {} |
|
317 | - |
|
318 | - /** |
|
319 | - * Processes invoice addons. |
|
320 | - * |
|
321 | - * @param WPInv_Invoice $invoice |
|
322 | - * @param GetPaid_Form_Item[] $items |
|
323 | - * @return WPInv_Invoice |
|
324 | - */ |
|
325 | - public function process_addons( $invoice, $items ) { |
|
326 | - |
|
327 | - } |
|
328 | - |
|
329 | - /** |
|
330 | - * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
331 | - * |
|
332 | - * @param string $transaction_url transaction url. |
|
333 | - * @param WPInv_Invoice $invoice Invoice object. |
|
334 | - * @return string transaction URL, or empty string. |
|
335 | - */ |
|
336 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
337 | - |
|
338 | - $transaction_id = $invoice->get_transaction_id(); |
|
339 | - |
|
340 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
341 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
342 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
343 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
344 | - } |
|
345 | - |
|
346 | - return $transaction_url; |
|
347 | - } |
|
348 | - |
|
349 | - /** |
|
350 | - * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
351 | - * |
|
352 | - * @param string $subscription_url transaction url. |
|
353 | - * @param WPInv_Invoice $invoice Invoice object. |
|
354 | - * @return string subscription URL, or empty string. |
|
355 | - */ |
|
356 | - public function filter_subscription_url( $subscription_url, $invoice ) { |
|
357 | - |
|
358 | - $profile_id = $invoice->get_subscription_id(); |
|
359 | - |
|
360 | - if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
361 | - |
|
362 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
363 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
364 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
365 | - |
|
366 | - } |
|
367 | - |
|
368 | - return $subscription_url; |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Check if the gateway is available for use. |
|
373 | - * |
|
374 | - * @return bool |
|
375 | - */ |
|
376 | - public function is_available() { |
|
377 | - return ! empty( $this->enabled ); |
|
378 | - } |
|
379 | - |
|
380 | - /** |
|
381 | - * Return the gateway's title. |
|
382 | - * |
|
383 | - * @return string |
|
384 | - */ |
|
385 | - public function get_title() { |
|
386 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Return the gateway's description. |
|
391 | - * |
|
392 | - * @return string |
|
393 | - */ |
|
394 | - public function get_description() { |
|
395 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
396 | - } |
|
397 | - |
|
398 | - /** |
|
399 | - * Process Payment. |
|
400 | - * |
|
401 | - * |
|
402 | - * @param WPInv_Invoice $invoice Invoice. |
|
403 | - * @param array $submission_data Posted checkout fields. |
|
404 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
405 | - * @return void |
|
406 | - */ |
|
407 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
408 | - // Process the payment then either redirect to the success page or the gateway. |
|
409 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
410 | - } |
|
411 | - |
|
412 | - /** |
|
413 | - * Process refund. |
|
414 | - * |
|
415 | - * If the gateway declares 'refunds' support, this will allow it to refund. |
|
416 | - * a passed in amount. |
|
417 | - * |
|
418 | - * @param WPInv_Invoice $invoice Invoice. |
|
419 | - * @param float $amount Refund amount. |
|
420 | - * @param string $reason Refund reason. |
|
421 | - * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
422 | - */ |
|
423 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
424 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
425 | - } |
|
426 | - |
|
427 | - /** |
|
428 | - * Displays the payment fields, credit cards etc. |
|
429 | - * |
|
430 | - * @param int $invoice_id 0 or invoice id. |
|
431 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
432 | - */ |
|
433 | - public function payment_fields( $invoice_id, $form ) { |
|
434 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
435 | - } |
|
436 | - |
|
437 | - /** |
|
438 | - * Filters the gateway settings. |
|
439 | - * |
|
440 | - * @param array $admin_settings |
|
441 | - */ |
|
442 | - public function admin_settings( $admin_settings ) { |
|
443 | - return $admin_settings; |
|
444 | - } |
|
445 | - |
|
446 | - /** |
|
447 | - * Retrieves the value of a gateway setting. |
|
448 | - * |
|
449 | - * @param string $option |
|
450 | - */ |
|
451 | - public function get_option( $option, $default = false ) { |
|
452 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
453 | - } |
|
454 | - |
|
455 | - /** |
|
456 | - * Check if a gateway supports a given feature. |
|
457 | - * |
|
458 | - * Gateways should override this to declare support (or lack of support) for a feature. |
|
459 | - * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
460 | - * |
|
461 | - * @param string $feature string The name of a feature to test support for. |
|
462 | - * @return bool True if the gateway supports the feature, false otherwise. |
|
463 | - * @since 1.0.19 |
|
464 | - */ |
|
465 | - public function supports( $feature ) { |
|
466 | - return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this ); |
|
467 | - } |
|
468 | - |
|
469 | - /** |
|
470 | - * Returns the credit card form html. |
|
471 | - * |
|
472 | - * @param bool $save whether or not to display the save button. |
|
473 | - */ |
|
362 | + $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
363 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
364 | + $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
365 | + |
|
366 | + } |
|
367 | + |
|
368 | + return $subscription_url; |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Check if the gateway is available for use. |
|
373 | + * |
|
374 | + * @return bool |
|
375 | + */ |
|
376 | + public function is_available() { |
|
377 | + return ! empty( $this->enabled ); |
|
378 | + } |
|
379 | + |
|
380 | + /** |
|
381 | + * Return the gateway's title. |
|
382 | + * |
|
383 | + * @return string |
|
384 | + */ |
|
385 | + public function get_title() { |
|
386 | + return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * Return the gateway's description. |
|
391 | + * |
|
392 | + * @return string |
|
393 | + */ |
|
394 | + public function get_description() { |
|
395 | + return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
396 | + } |
|
397 | + |
|
398 | + /** |
|
399 | + * Process Payment. |
|
400 | + * |
|
401 | + * |
|
402 | + * @param WPInv_Invoice $invoice Invoice. |
|
403 | + * @param array $submission_data Posted checkout fields. |
|
404 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
405 | + * @return void |
|
406 | + */ |
|
407 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
408 | + // Process the payment then either redirect to the success page or the gateway. |
|
409 | + do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * Process refund. |
|
414 | + * |
|
415 | + * If the gateway declares 'refunds' support, this will allow it to refund. |
|
416 | + * a passed in amount. |
|
417 | + * |
|
418 | + * @param WPInv_Invoice $invoice Invoice. |
|
419 | + * @param float $amount Refund amount. |
|
420 | + * @param string $reason Refund reason. |
|
421 | + * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
422 | + */ |
|
423 | + public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
424 | + return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
425 | + } |
|
426 | + |
|
427 | + /** |
|
428 | + * Displays the payment fields, credit cards etc. |
|
429 | + * |
|
430 | + * @param int $invoice_id 0 or invoice id. |
|
431 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
432 | + */ |
|
433 | + public function payment_fields( $invoice_id, $form ) { |
|
434 | + do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
435 | + } |
|
436 | + |
|
437 | + /** |
|
438 | + * Filters the gateway settings. |
|
439 | + * |
|
440 | + * @param array $admin_settings |
|
441 | + */ |
|
442 | + public function admin_settings( $admin_settings ) { |
|
443 | + return $admin_settings; |
|
444 | + } |
|
445 | + |
|
446 | + /** |
|
447 | + * Retrieves the value of a gateway setting. |
|
448 | + * |
|
449 | + * @param string $option |
|
450 | + */ |
|
451 | + public function get_option( $option, $default = false ) { |
|
452 | + return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
453 | + } |
|
454 | + |
|
455 | + /** |
|
456 | + * Check if a gateway supports a given feature. |
|
457 | + * |
|
458 | + * Gateways should override this to declare support (or lack of support) for a feature. |
|
459 | + * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
460 | + * |
|
461 | + * @param string $feature string The name of a feature to test support for. |
|
462 | + * @return bool True if the gateway supports the feature, false otherwise. |
|
463 | + * @since 1.0.19 |
|
464 | + */ |
|
465 | + public function supports( $feature ) { |
|
466 | + return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this ); |
|
467 | + } |
|
468 | + |
|
469 | + /** |
|
470 | + * Returns the credit card form html. |
|
471 | + * |
|
472 | + * @param bool $save whether or not to display the save button. |
|
473 | + */ |
|
474 | 474 | public function get_cc_form( $save = false ) { |
475 | 475 | |
476 | - ob_start(); |
|
476 | + ob_start(); |
|
477 | 477 | |
478 | 478 | $id_prefix = esc_attr( uniqid( $this->id ) ); |
479 | 479 | |
@@ -568,8 +568,8 @@ discard block |
||
568 | 568 | 'name' => $this->id . '[cc_cvv2]', |
569 | 569 | 'id' => "$id_prefix-cc-cvv2", |
570 | 570 | 'label' => __( 'CCV', 'invoicing' ), |
571 | - 'label_type' => 'vertical', |
|
572 | - 'class' => 'form-control-sm', |
|
571 | + 'label_type' => 'vertical', |
|
572 | + 'class' => 'form-control-sm', |
|
573 | 573 | ) |
574 | 574 | ); |
575 | 575 | ?> |
@@ -579,175 +579,175 @@ discard block |
||
579 | 579 | |
580 | 580 | <?php |
581 | 581 | |
582 | - if ( $save ) { |
|
583 | - echo $this->save_payment_method_checkbox(); |
|
584 | - } |
|
582 | + if ( $save ) { |
|
583 | + echo $this->save_payment_method_checkbox(); |
|
584 | + } |
|
585 | 585 | |
586 | - ?> |
|
586 | + ?> |
|
587 | 587 | </div> |
588 | 588 | |
589 | 589 | </div> |
590 | 590 | <?php |
591 | 591 | |
592 | - return ob_get_clean(); |
|
592 | + return ob_get_clean(); |
|
593 | + |
|
594 | + } |
|
593 | 595 | |
596 | + /** |
|
597 | + * Displays a new payment method entry form. |
|
598 | + * |
|
599 | + * @since 1.0.19 |
|
600 | + */ |
|
601 | + public function new_payment_method_entry( $form ) { |
|
602 | + echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
594 | 603 | } |
595 | 604 | |
596 | - /** |
|
597 | - * Displays a new payment method entry form. |
|
598 | - * |
|
599 | - * @since 1.0.19 |
|
600 | - */ |
|
601 | - public function new_payment_method_entry( $form ) { |
|
602 | - echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
603 | - } |
|
604 | - |
|
605 | - /** |
|
606 | - * Grab and display our saved payment methods. |
|
607 | - * |
|
608 | - * @since 1.0.19 |
|
609 | - */ |
|
610 | - public function saved_payment_methods() { |
|
611 | - $html = '<ul class="getpaid-saved-payment-methods m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
612 | - |
|
613 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
614 | - $html .= $this->get_saved_payment_method_option_html( $token ); |
|
615 | - } |
|
616 | - |
|
617 | - $html .= $this->get_new_payment_method_option_html(); |
|
618 | - $html .= '</ul>'; |
|
619 | - |
|
620 | - echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
621 | - } |
|
622 | - |
|
623 | - /** |
|
624 | - * Gets saved payment method HTML from a token. |
|
625 | - * |
|
626 | - * @since 1.0.19 |
|
627 | - * @param array $token Payment Token. |
|
628 | - * @return string Generated payment method HTML |
|
629 | - */ |
|
630 | - public function get_saved_payment_method_option_html( $token ) { |
|
631 | - |
|
632 | - return sprintf( |
|
633 | - '<li class="getpaid-payment-method form-group"> |
|
605 | + /** |
|
606 | + * Grab and display our saved payment methods. |
|
607 | + * |
|
608 | + * @since 1.0.19 |
|
609 | + */ |
|
610 | + public function saved_payment_methods() { |
|
611 | + $html = '<ul class="getpaid-saved-payment-methods m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
612 | + |
|
613 | + foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
614 | + $html .= $this->get_saved_payment_method_option_html( $token ); |
|
615 | + } |
|
616 | + |
|
617 | + $html .= $this->get_new_payment_method_option_html(); |
|
618 | + $html .= '</ul>'; |
|
619 | + |
|
620 | + echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
621 | + } |
|
622 | + |
|
623 | + /** |
|
624 | + * Gets saved payment method HTML from a token. |
|
625 | + * |
|
626 | + * @since 1.0.19 |
|
627 | + * @param array $token Payment Token. |
|
628 | + * @return string Generated payment method HTML |
|
629 | + */ |
|
630 | + public function get_saved_payment_method_option_html( $token ) { |
|
631 | + |
|
632 | + return sprintf( |
|
633 | + '<li class="getpaid-payment-method form-group"> |
|
634 | 634 | <label> |
635 | 635 | <input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s /> |
636 | 636 | <span>%3$s</span> |
637 | 637 | </label> |
638 | 638 | </li>', |
639 | - esc_attr( $this->id ), |
|
640 | - esc_attr( $token['id'] ), |
|
641 | - esc_html( $token['name'] ), |
|
642 | - checked( empty( $token['default'] ), false, false ) |
|
643 | - ); |
|
639 | + esc_attr( $this->id ), |
|
640 | + esc_attr( $token['id'] ), |
|
641 | + esc_html( $token['name'] ), |
|
642 | + checked( empty( $token['default'] ), false, false ) |
|
643 | + ); |
|
644 | 644 | |
645 | - } |
|
645 | + } |
|
646 | 646 | |
647 | - /** |
|
648 | - * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
649 | - * |
|
650 | - * @since 1.0.19 |
|
651 | - */ |
|
652 | - public function get_new_payment_method_option_html() { |
|
647 | + /** |
|
648 | + * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
649 | + * |
|
650 | + * @since 1.0.19 |
|
651 | + */ |
|
652 | + public function get_new_payment_method_option_html() { |
|
653 | 653 | |
654 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
654 | + $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
655 | 655 | |
656 | - return sprintf( |
|
657 | - '<li class="getpaid-new-payment-method"> |
|
656 | + return sprintf( |
|
657 | + '<li class="getpaid-new-payment-method"> |
|
658 | 658 | <label> |
659 | 659 | <input name="getpaid-%1$s-payment-method" type="radio" value="new" style="width:auto;" /> |
660 | 660 | <span>%2$s</span> |
661 | 661 | </label> |
662 | 662 | </li>', |
663 | - esc_attr( $this->id ), |
|
664 | - esc_html( $label ) |
|
665 | - ); |
|
663 | + esc_attr( $this->id ), |
|
664 | + esc_html( $label ) |
|
665 | + ); |
|
666 | 666 | |
667 | - } |
|
667 | + } |
|
668 | 668 | |
669 | - /** |
|
670 | - * Outputs a checkbox for saving a new payment method to the database. |
|
671 | - * |
|
672 | - * @since 1.0.19 |
|
673 | - */ |
|
674 | - public function save_payment_method_checkbox() { |
|
669 | + /** |
|
670 | + * Outputs a checkbox for saving a new payment method to the database. |
|
671 | + * |
|
672 | + * @since 1.0.19 |
|
673 | + */ |
|
674 | + public function save_payment_method_checkbox() { |
|
675 | 675 | |
676 | - return sprintf( |
|
677 | - '<p class="form-group getpaid-save-payment-method"> |
|
676 | + return sprintf( |
|
677 | + '<p class="form-group getpaid-save-payment-method"> |
|
678 | 678 | <label> |
679 | 679 | <input name="getpaid-%1$s-new-payment-method" type="checkbox" value="true" style="width:auto;" /> |
680 | 680 | <span>%2$s</span> |
681 | 681 | </label> |
682 | 682 | </p>', |
683 | - esc_attr( $this->id ), |
|
684 | - esc_html__( 'Save payment method', 'invoicing' ) |
|
685 | - ); |
|
683 | + esc_attr( $this->id ), |
|
684 | + esc_html__( 'Save payment method', 'invoicing' ) |
|
685 | + ); |
|
686 | 686 | |
687 | - } |
|
687 | + } |
|
688 | 688 | |
689 | - /** |
|
690 | - * Registers the gateway. |
|
691 | - * |
|
692 | - * @return array |
|
693 | - */ |
|
694 | - public function register_gateway( $gateways ) { |
|
689 | + /** |
|
690 | + * Registers the gateway. |
|
691 | + * |
|
692 | + * @return array |
|
693 | + */ |
|
694 | + public function register_gateway( $gateways ) { |
|
695 | 695 | |
696 | - $gateways[ $this->id ] = array( |
|
696 | + $gateways[ $this->id ] = array( |
|
697 | 697 | |
698 | - 'admin_label' => $this->method_title, |
|
698 | + 'admin_label' => $this->method_title, |
|
699 | 699 | 'checkout_label' => $this->title, |
700 | - 'ordering' => $this->order, |
|
701 | - |
|
702 | - ); |
|
703 | - |
|
704 | - return $gateways; |
|
705 | - |
|
706 | - } |
|
707 | - |
|
708 | - /** |
|
709 | - * Checks whether or not this is a sandbox request. |
|
710 | - * |
|
711 | - * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
712 | - * @return bool |
|
713 | - */ |
|
714 | - public function is_sandbox( $invoice = null ) { |
|
715 | - |
|
716 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
717 | - return $invoice->get_mode() == 'test'; |
|
718 | - } |
|
719 | - |
|
720 | - return wpinv_is_test_mode( $this->id ); |
|
721 | - |
|
722 | - } |
|
723 | - |
|
724 | - /** |
|
725 | - * Renames the checkout button |
|
726 | - * |
|
727 | - * @return string |
|
728 | - */ |
|
729 | - public function rename_checkout_button() { |
|
730 | - return $this->checkout_button_text; |
|
731 | - } |
|
732 | - |
|
733 | - /** |
|
734 | - * Validate gateway currency |
|
735 | - * |
|
736 | - * @return bool |
|
737 | - */ |
|
738 | - public function validate_currency( $validation, $currency ) { |
|
739 | - |
|
740 | - // Required currencies. |
|
741 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
742 | - return false; |
|
743 | - } |
|
744 | - |
|
745 | - // Excluded currencies. |
|
746 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
747 | - return false; |
|
748 | - } |
|
749 | - |
|
750 | - return $validation; |
|
751 | - } |
|
700 | + 'ordering' => $this->order, |
|
701 | + |
|
702 | + ); |
|
703 | + |
|
704 | + return $gateways; |
|
705 | + |
|
706 | + } |
|
707 | + |
|
708 | + /** |
|
709 | + * Checks whether or not this is a sandbox request. |
|
710 | + * |
|
711 | + * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
712 | + * @return bool |
|
713 | + */ |
|
714 | + public function is_sandbox( $invoice = null ) { |
|
715 | + |
|
716 | + if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
717 | + return $invoice->get_mode() == 'test'; |
|
718 | + } |
|
719 | + |
|
720 | + return wpinv_is_test_mode( $this->id ); |
|
721 | + |
|
722 | + } |
|
723 | + |
|
724 | + /** |
|
725 | + * Renames the checkout button |
|
726 | + * |
|
727 | + * @return string |
|
728 | + */ |
|
729 | + public function rename_checkout_button() { |
|
730 | + return $this->checkout_button_text; |
|
731 | + } |
|
732 | + |
|
733 | + /** |
|
734 | + * Validate gateway currency |
|
735 | + * |
|
736 | + * @return bool |
|
737 | + */ |
|
738 | + public function validate_currency( $validation, $currency ) { |
|
739 | + |
|
740 | + // Required currencies. |
|
741 | + if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
742 | + return false; |
|
743 | + } |
|
744 | + |
|
745 | + // Excluded currencies. |
|
746 | + if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
747 | + return false; |
|
748 | + } |
|
749 | + |
|
750 | + return $validation; |
|
751 | + } |
|
752 | 752 | |
753 | 753 | } |
@@ -13,58 +13,58 @@ discard block |
||
13 | 13 | class GetPaid_Authorize_Net_Gateway extends GetPaid_Authorize_Net_Legacy_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'authorizenet'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | 34 | public $order = 4; |
35 | 35 | |
36 | 36 | /** |
37 | - * Endpoint for requests from Authorize.net. |
|
38 | - * |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - protected $notify_url; |
|
42 | - |
|
43 | - /** |
|
44 | - * Endpoint for requests to Authorize.net. |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
37 | + * Endpoint for requests from Authorize.net. |
|
38 | + * |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + protected $notify_url; |
|
42 | + |
|
43 | + /** |
|
44 | + * Endpoint for requests to Authorize.net. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | 48 | protected $endpoint; |
49 | 49 | |
50 | 50 | /** |
51 | - * Currencies this gateway is allowed for. |
|
52 | - * |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
51 | + * Currencies this gateway is allowed for. |
|
52 | + * |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
56 | 56 | |
57 | 57 | /** |
58 | - * URL to view a transaction. |
|
59 | - * |
|
60 | - * @var string |
|
61 | - */ |
|
58 | + * URL to view a transaction. |
|
59 | + * |
|
60 | + * @var string |
|
61 | + */ |
|
62 | 62 | public $view_transaction_url = 'https://{sandbox}authorize.net/ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=%s'; |
63 | 63 | |
64 | 64 | /** |
65 | - * Class constructor. |
|
66 | - */ |
|
67 | - public function __construct() { |
|
65 | + * Class constructor. |
|
66 | + */ |
|
67 | + public function __construct() { |
|
68 | 68 | |
69 | 69 | $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
70 | 70 | $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
@@ -76,11 +76,11 @@ discard block |
||
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | - * Displays the payment method select field. |
|
80 | - * |
|
81 | - * @param int $invoice_id 0 or invoice id. |
|
82 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
83 | - */ |
|
79 | + * Displays the payment method select field. |
|
80 | + * |
|
81 | + * @param int $invoice_id 0 or invoice id. |
|
82 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
83 | + */ |
|
84 | 84 | public function payment_fields( $invoice_id, $form ) { |
85 | 85 | |
86 | 86 | // Let the user select a payment method. |
@@ -91,16 +91,16 @@ discard block |
||
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
94 | - * Creates a customer profile. |
|
95 | - * |
|
96 | - * |
|
97 | - * @param WPInv_Invoice $invoice Invoice. |
|
94 | + * Creates a customer profile. |
|
95 | + * |
|
96 | + * |
|
97 | + * @param WPInv_Invoice $invoice Invoice. |
|
98 | 98 | * @param array $submission_data Posted checkout fields. |
99 | 99 | * @param bool $save Whether or not to save the payment as a token. |
100 | 100 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
101 | - * @return string|WP_Error Payment profile id. |
|
102 | - */ |
|
103 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
101 | + * @return string|WP_Error Payment profile id. |
|
102 | + */ |
|
103 | + public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
104 | 104 | |
105 | 105 | // Remove non-digits from the number |
106 | 106 | $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -167,14 +167,14 @@ discard block |
||
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
170 | - * Retrieves a customer profile. |
|
171 | - * |
|
172 | - * |
|
173 | - * @param string $profile_id profile id. |
|
174 | - * @return string|WP_Error Profile id. |
|
170 | + * Retrieves a customer profile. |
|
171 | + * |
|
172 | + * |
|
173 | + * @param string $profile_id profile id. |
|
174 | + * @return string|WP_Error Profile id. |
|
175 | 175 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
176 | - */ |
|
177 | - public function get_customer_profile( $profile_id ) { |
|
176 | + */ |
|
177 | + public function get_customer_profile( $profile_id ) { |
|
178 | 178 | |
179 | 179 | // Generate args. |
180 | 180 | $args = array( |
@@ -189,17 +189,17 @@ discard block |
||
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
192 | - * Creates a customer profile. |
|
193 | - * |
|
194 | - * |
|
192 | + * Creates a customer profile. |
|
193 | + * |
|
194 | + * |
|
195 | 195 | * @param string $profile_id profile id. |
196 | - * @param WPInv_Invoice $invoice Invoice. |
|
196 | + * @param WPInv_Invoice $invoice Invoice. |
|
197 | 197 | * @param array $submission_data Posted checkout fields. |
198 | 198 | * @param bool $save Whether or not to save the payment as a token. |
199 | 199 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
200 | - * @return string|WP_Error Profile id. |
|
201 | - */ |
|
202 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
200 | + * @return string|WP_Error Profile id. |
|
201 | + */ |
|
202 | + public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
203 | 203 | |
204 | 204 | // Remove non-digits from the number |
205 | 205 | $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -259,15 +259,15 @@ discard block |
||
259 | 259 | } |
260 | 260 | |
261 | 261 | /** |
262 | - * Retrieves a customer payment profile. |
|
263 | - * |
|
264 | - * |
|
265 | - * @param string $customer_profile_id customer profile id. |
|
262 | + * Retrieves a customer payment profile. |
|
263 | + * |
|
264 | + * |
|
265 | + * @param string $customer_profile_id customer profile id. |
|
266 | 266 | * @param string $payment_profile_id payment profile id. |
267 | - * @return string|WP_Error Profile id. |
|
267 | + * @return string|WP_Error Profile id. |
|
268 | 268 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
269 | - */ |
|
270 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
269 | + */ |
|
270 | + public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
271 | 271 | |
272 | 272 | // Generate args. |
273 | 273 | $args = array( |
@@ -283,15 +283,15 @@ discard block |
||
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
286 | - * Charges a customer payment profile. |
|
287 | - * |
|
286 | + * Charges a customer payment profile. |
|
287 | + * |
|
288 | 288 | * @param string $customer_profile_id customer profile id. |
289 | 289 | * @param string $payment_profile_id payment profile id. |
290 | - * @param WPInv_Invoice $invoice Invoice. |
|
290 | + * @param WPInv_Invoice $invoice Invoice. |
|
291 | 291 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
292 | - * @return WP_Error|object |
|
293 | - */ |
|
294 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
292 | + * @return WP_Error|object |
|
293 | + */ |
|
294 | + public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
295 | 295 | |
296 | 296 | // Generate args. |
297 | 297 | $args = array( |
@@ -337,41 +337,41 @@ discard block |
||
337 | 337 | } |
338 | 338 | |
339 | 339 | /** |
340 | - * Processes a customer charge. |
|
341 | - * |
|
340 | + * Processes a customer charge. |
|
341 | + * |
|
342 | 342 | * @param stdClass $result Api response. |
343 | - * @param WPInv_Invoice $invoice Invoice. |
|
344 | - */ |
|
345 | - public function process_charge_response( $result, $invoice ) { |
|
343 | + * @param WPInv_Invoice $invoice Invoice. |
|
344 | + */ |
|
345 | + public function process_charge_response( $result, $invoice ) { |
|
346 | 346 | |
347 | 347 | wpinv_clear_errors(); |
348 | - $response_code = (int) $result->transactionResponse->responseCode; |
|
348 | + $response_code = (int) $result->transactionResponse->responseCode; |
|
349 | 349 | |
350 | - // Succeeded. |
|
351 | - if ( 1 == $response_code || 4 == $response_code ) { |
|
350 | + // Succeeded. |
|
351 | + if ( 1 == $response_code || 4 == $response_code ) { |
|
352 | 352 | |
353 | - // Maybe set a transaction id. |
|
354 | - if ( ! empty( $result->transactionResponse->transId ) ) { |
|
355 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
356 | - } |
|
353 | + // Maybe set a transaction id. |
|
354 | + if ( ! empty( $result->transactionResponse->transId ) ) { |
|
355 | + $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
356 | + } |
|
357 | 357 | |
358 | - $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
358 | + $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
359 | 359 | |
360 | - if ( 1 == $response_code ) { |
|
361 | - return $invoice->mark_paid(); |
|
362 | - } |
|
360 | + if ( 1 == $response_code ) { |
|
361 | + return $invoice->mark_paid(); |
|
362 | + } |
|
363 | 363 | |
364 | - $invoice->set_status( 'wpi-onhold' ); |
|
365 | - $invoice->add_note( |
|
364 | + $invoice->set_status( 'wpi-onhold' ); |
|
365 | + $invoice->add_note( |
|
366 | 366 | sprintf( |
367 | 367 | __( 'Held for review: %s', 'invoicing' ), |
368 | 368 | $result->transactionResponse->messages->message[0]->description |
369 | 369 | ) |
370 | - ); |
|
370 | + ); |
|
371 | 371 | |
372 | - return $invoice->save(); |
|
372 | + return $invoice->save(); |
|
373 | 373 | |
374 | - } |
|
374 | + } |
|
375 | 375 | |
376 | 376 | wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) ); |
377 | 377 | |
@@ -383,13 +383,13 @@ discard block |
||
383 | 383 | } |
384 | 384 | |
385 | 385 | /** |
386 | - * Returns payment information. |
|
387 | - * |
|
388 | - * |
|
389 | - * @param array $card Card details. |
|
390 | - * @return array |
|
391 | - */ |
|
392 | - public function get_payment_information( $card ) { |
|
386 | + * Returns payment information. |
|
387 | + * |
|
388 | + * |
|
389 | + * @param array $card Card details. |
|
390 | + * @return array |
|
391 | + */ |
|
392 | + public function get_payment_information( $card ) { |
|
393 | 393 | return array( |
394 | 394 | |
395 | 395 | 'creditCard' => array ( |
@@ -402,25 +402,25 @@ discard block |
||
402 | 402 | } |
403 | 403 | |
404 | 404 | /** |
405 | - * Returns the customer profile meta name. |
|
406 | - * |
|
407 | - * |
|
408 | - * @param WPInv_Invoice $invoice Invoice. |
|
409 | - * @return string |
|
410 | - */ |
|
411 | - public function get_customer_profile_meta_name( $invoice ) { |
|
405 | + * Returns the customer profile meta name. |
|
406 | + * |
|
407 | + * |
|
408 | + * @param WPInv_Invoice $invoice Invoice. |
|
409 | + * @return string |
|
410 | + */ |
|
411 | + public function get_customer_profile_meta_name( $invoice ) { |
|
412 | 412 | return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
413 | 413 | } |
414 | 414 | |
415 | 415 | /** |
416 | - * Validates the submitted data. |
|
417 | - * |
|
418 | - * |
|
419 | - * @param array $submission_data Posted checkout fields. |
|
416 | + * Validates the submitted data. |
|
417 | + * |
|
418 | + * |
|
419 | + * @param array $submission_data Posted checkout fields. |
|
420 | 420 | * @param WPInv_Invoice $invoice |
421 | - * @return WP_Error|string The payment profile id |
|
422 | - */ |
|
423 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
421 | + * @return WP_Error|string The payment profile id |
|
422 | + */ |
|
423 | + public function validate_submission_data( $submission_data, $invoice ) { |
|
424 | 424 | |
425 | 425 | // Validate authentication details. |
426 | 426 | $auth = $this->get_auth_params(); |
@@ -452,13 +452,13 @@ discard block |
||
452 | 452 | } |
453 | 453 | |
454 | 454 | /** |
455 | - * Returns invoice line items. |
|
456 | - * |
|
457 | - * |
|
458 | - * @param WPInv_Invoice $invoice Invoice. |
|
459 | - * @return array |
|
460 | - */ |
|
461 | - public function get_line_items( $invoice ) { |
|
455 | + * Returns invoice line items. |
|
456 | + * |
|
457 | + * |
|
458 | + * @param WPInv_Invoice $invoice Invoice. |
|
459 | + * @return array |
|
460 | + */ |
|
461 | + public function get_line_items( $invoice ) { |
|
462 | 462 | $items = array(); |
463 | 463 | |
464 | 464 | foreach ( $invoice->get_items() as $item ) { |
@@ -496,15 +496,15 @@ discard block |
||
496 | 496 | } |
497 | 497 | |
498 | 498 | /** |
499 | - * Process Payment. |
|
500 | - * |
|
501 | - * |
|
502 | - * @param WPInv_Invoice $invoice Invoice. |
|
503 | - * @param array $submission_data Posted checkout fields. |
|
504 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
505 | - * @return array |
|
506 | - */ |
|
507 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
499 | + * Process Payment. |
|
500 | + * |
|
501 | + * |
|
502 | + * @param WPInv_Invoice $invoice Invoice. |
|
503 | + * @param array $submission_data Posted checkout fields. |
|
504 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
505 | + * @return array |
|
506 | + */ |
|
507 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
508 | 508 | |
509 | 509 | // Validate the submitted data. |
510 | 510 | $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
@@ -537,69 +537,69 @@ discard block |
||
537 | 537 | |
538 | 538 | exit; |
539 | 539 | |
540 | - } |
|
540 | + } |
|
541 | 541 | |
542 | - /** |
|
543 | - * Processes the initial payment. |
|
544 | - * |
|
542 | + /** |
|
543 | + * Processes the initial payment. |
|
544 | + * |
|
545 | 545 | * @param WPInv_Invoice $invoice Invoice. |
546 | - */ |
|
547 | - protected function process_initial_payment( $invoice ) { |
|
546 | + */ |
|
547 | + protected function process_initial_payment( $invoice ) { |
|
548 | 548 | |
549 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
549 | + $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
550 | 550 | $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
551 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
551 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
552 | 552 | |
553 | - // Do we have an error? |
|
554 | - if ( is_wp_error( $result ) ) { |
|
555 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
556 | - wpinv_send_back_to_checkout(); |
|
557 | - } |
|
553 | + // Do we have an error? |
|
554 | + if ( is_wp_error( $result ) ) { |
|
555 | + wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
556 | + wpinv_send_back_to_checkout(); |
|
557 | + } |
|
558 | 558 | |
559 | - // Process the response. |
|
560 | - $this->process_charge_response( $result, $invoice ); |
|
559 | + // Process the response. |
|
560 | + $this->process_charge_response( $result, $invoice ); |
|
561 | 561 | |
562 | - if ( wpinv_get_errors() ) { |
|
563 | - wpinv_send_back_to_checkout(); |
|
564 | - } |
|
562 | + if ( wpinv_get_errors() ) { |
|
563 | + wpinv_send_back_to_checkout(); |
|
564 | + } |
|
565 | 565 | |
566 | - } |
|
566 | + } |
|
567 | 567 | |
568 | 568 | /** |
569 | - * Processes recurring payments. |
|
570 | - * |
|
569 | + * Processes recurring payments. |
|
570 | + * |
|
571 | 571 | * @param WPInv_Invoice $invoice Invoice. |
572 | 572 | * @param WPInv_Subscription $subscription Subscription. |
573 | - */ |
|
574 | - public function process_subscription( $invoice, $subscription ) { |
|
573 | + */ |
|
574 | + public function process_subscription( $invoice, $subscription ) { |
|
575 | 575 | |
576 | 576 | // Check if there is an initial amount to charge. |
577 | 577 | if ( (float) $invoice->get_total() > 0 ) { |
578 | - $this->process_initial_payment( $invoice ); |
|
578 | + $this->process_initial_payment( $invoice ); |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | // Activate the subscription. |
582 | 582 | $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
583 | 583 | $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
584 | 584 | |
585 | - $subscription->set_next_renewal_date( $expiry ); |
|
586 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
587 | - $subscription->set_profile_id( $invoice->generate_key() ); |
|
588 | - $subscription->activate(); |
|
585 | + $subscription->set_next_renewal_date( $expiry ); |
|
586 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
587 | + $subscription->set_profile_id( $invoice->generate_key() ); |
|
588 | + $subscription->activate(); |
|
589 | 589 | |
590 | - // Redirect to the success page. |
|
590 | + // Redirect to the success page. |
|
591 | 591 | wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
592 | 592 | |
593 | 593 | } |
594 | 594 | |
595 | - /** |
|
596 | - * (Maybe) renews an authorize.net subscription profile. |
|
597 | - * |
|
598 | - * |
|
599 | - * @param bool $should_expire |
|
595 | + /** |
|
596 | + * (Maybe) renews an authorize.net subscription profile. |
|
597 | + * |
|
598 | + * |
|
599 | + * @param bool $should_expire |
|
600 | 600 | * @param WPInv_Subscription $subscription |
601 | - */ |
|
602 | - public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
601 | + */ |
|
602 | + public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
603 | 603 | |
604 | 604 | // Ensure its our subscription && it's active. |
605 | 605 | if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) { |
@@ -616,18 +616,18 @@ discard block |
||
616 | 616 | |
617 | 617 | return false; |
618 | 618 | |
619 | - } |
|
619 | + } |
|
620 | 620 | |
621 | 621 | /** |
622 | - * Renews a subscription. |
|
623 | - * |
|
622 | + * Renews a subscription. |
|
623 | + * |
|
624 | 624 | * @param WPInv_Subscription $subscription |
625 | - */ |
|
626 | - public function renew_subscription( $subscription ) { |
|
625 | + */ |
|
626 | + public function renew_subscription( $subscription ) { |
|
627 | 627 | |
628 | - // Generate the renewal invoice. |
|
629 | - $new_invoice = $subscription->create_payment(); |
|
630 | - $old_invoice = $subscription->get_parent_payment(); |
|
628 | + // Generate the renewal invoice. |
|
629 | + $new_invoice = $subscription->create_payment(); |
|
630 | + $old_invoice = $subscription->get_parent_payment(); |
|
631 | 631 | |
632 | 632 | if ( empty( $new_invoice ) ) { |
633 | 633 | $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
@@ -636,37 +636,37 @@ discard block |
||
636 | 636 | } |
637 | 637 | |
638 | 638 | // Charge the payment method. |
639 | - $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
640 | - $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
641 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
642 | - |
|
643 | - // Do we have an error? |
|
644 | - if ( is_wp_error( $result ) ) { |
|
645 | - |
|
646 | - $old_invoice->add_note( |
|
647 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
648 | - true, |
|
649 | - false, |
|
650 | - true |
|
651 | - ); |
|
652 | - $subscription->failing(); |
|
653 | - return; |
|
654 | - |
|
655 | - } |
|
656 | - |
|
657 | - // Process the response. |
|
658 | - $this->process_charge_response( $result, $new_invoice ); |
|
659 | - |
|
660 | - if ( wpinv_get_errors() ) { |
|
661 | - |
|
662 | - $old_invoice->add_note( |
|
663 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
664 | - true, |
|
665 | - false, |
|
666 | - true |
|
667 | - ); |
|
668 | - $subscription->failing(); |
|
669 | - return; |
|
639 | + $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
640 | + $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
641 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
642 | + |
|
643 | + // Do we have an error? |
|
644 | + if ( is_wp_error( $result ) ) { |
|
645 | + |
|
646 | + $old_invoice->add_note( |
|
647 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
648 | + true, |
|
649 | + false, |
|
650 | + true |
|
651 | + ); |
|
652 | + $subscription->failing(); |
|
653 | + return; |
|
654 | + |
|
655 | + } |
|
656 | + |
|
657 | + // Process the response. |
|
658 | + $this->process_charge_response( $result, $new_invoice ); |
|
659 | + |
|
660 | + if ( wpinv_get_errors() ) { |
|
661 | + |
|
662 | + $old_invoice->add_note( |
|
663 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
664 | + true, |
|
665 | + false, |
|
666 | + true |
|
667 | + ); |
|
668 | + $subscription->failing(); |
|
669 | + return; |
|
670 | 670 | |
671 | 671 | } |
672 | 672 | |
@@ -688,11 +688,11 @@ discard block |
||
688 | 688 | } |
689 | 689 | |
690 | 690 | /** |
691 | - * Filters the gateway settings. |
|
692 | - * |
|
693 | - * @param array $admin_settings |
|
694 | - */ |
|
695 | - public function admin_settings( $admin_settings ) { |
|
691 | + * Filters the gateway settings. |
|
692 | + * |
|
693 | + * @param array $admin_settings |
|
694 | + */ |
|
695 | + public function admin_settings( $admin_settings ) { |
|
696 | 696 | |
697 | 697 | $currencies = sprintf( |
698 | 698 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -732,7 +732,7 @@ discard block |
||
732 | 732 | 'readonly' => true, |
733 | 733 | ); |
734 | 734 | |
735 | - return $admin_settings; |
|
736 | - } |
|
735 | + return $admin_settings; |
|
736 | + } |
|
737 | 737 | |
738 | 738 | } |