@@ -96,7 +96,7 @@ |
||
96 | 96 | curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false); |
97 | 97 | } |
98 | 98 | |
99 | - if (preg_match('/xml/',$post_url)) { |
|
99 | + if (preg_match('/xml/', $post_url)) { |
|
100 | 100 | curl_setopt($curl_request, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); |
101 | 101 | } |
102 | 102 |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | $this->xml = @simplexml_load_string($response); |
30 | 30 | |
31 | 31 | // Remove namespaces for use with XPath. |
32 | - $this->xpath_xml = @simplexml_load_string(preg_replace('/ xmlns:xsi[^>]+/','',$response)); |
|
32 | + $this->xpath_xml = @simplexml_load_string(preg_replace('/ xmlns:xsi[^>]+/', '', $response)); |
|
33 | 33 | } |
34 | 34 | } |
35 | 35 | |
@@ -116,12 +116,12 @@ discard block |
||
116 | 116 | { |
117 | 117 | $start = "<$elementName>"; |
118 | 118 | $end = "</$elementName>"; |
119 | - if (strpos($this->response,$start) === false || strpos($this->response,$end) === false) { |
|
119 | + if (strpos($this->response, $start) === false || strpos($this->response, $end) === false) { |
|
120 | 120 | return false; |
121 | 121 | } else { |
122 | - $start_position = strpos($this->response, $start)+strlen($start); |
|
122 | + $start_position = strpos($this->response, $start) + strlen($start); |
|
123 | 123 | $end_position = strpos($this->response, $end); |
124 | - return substr($this->response, $start_position, $end_position-$start_position); |
|
124 | + return substr($this->response, $start_position, $end_position - $start_position); |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 |
@@ -91,13 +91,13 @@ |
||
91 | 91 | return $this->_sendRequest(); |
92 | 92 | } |
93 | 93 | |
94 | - /** |
|
95 | - * |
|
96 | - * |
|
97 | - * @param string $response |
|
98 | - * |
|
99 | - * @return AuthorizeNetARB_Response |
|
100 | - */ |
|
94 | + /** |
|
95 | + * |
|
96 | + * |
|
97 | + * @param string $response |
|
98 | + * |
|
99 | + * @return AuthorizeNetARB_Response |
|
100 | + */ |
|
101 | 101 | protected function _handleResponse($response) |
102 | 102 | { |
103 | 103 | return new AuthorizeNetARB_Response($response); |
@@ -116,7 +116,7 @@ |
||
116 | 116 | */ |
117 | 117 | protected function _setPostString() |
118 | 118 | { |
119 | - $this->_post_string =<<<XML |
|
119 | + $this->_post_string = <<<XML |
|
120 | 120 | <?xml version="1.0" encoding="utf-8"?> |
121 | 121 | <ARB{$this->_request_type} xmlns= "AnetApi/xml/v1/schema/AnetApiSchema.xsd"> |
122 | 122 | <merchantAuthentication> |
@@ -316,9 +316,9 @@ |
||
316 | 316 | return $this->_sendRequest(); |
317 | 317 | } |
318 | 318 | |
319 | - /** |
|
320 | - * @return string |
|
321 | - */ |
|
319 | + /** |
|
320 | + * @return string |
|
321 | + */ |
|
322 | 322 | protected function _getPostUrl() |
323 | 323 | { |
324 | 324 | return ($this->_sandbox ? self::SANDBOX_URL : self::LIVE_URL); |
@@ -309,10 +309,10 @@ discard block |
||
309 | 309 | { |
310 | 310 | $this->_validationMode = $validationMode; |
311 | 311 | $this->_constructXml("validateCustomerPaymentProfileRequest"); |
312 | - $this->_xml->addChild("customerProfileId",$customerProfileId); |
|
313 | - $this->_xml->addChild("customerPaymentProfileId",$customerPaymentProfileId); |
|
314 | - $this->_xml->addChild("customerShippingAddressId",$customerShippingAddressId); |
|
315 | - $this->_xml->addChild("cardCode",$cardCode); |
|
312 | + $this->_xml->addChild("customerProfileId", $customerProfileId); |
|
313 | + $this->_xml->addChild("customerPaymentProfileId", $customerPaymentProfileId); |
|
314 | + $this->_xml->addChild("customerShippingAddressId", $customerShippingAddressId); |
|
315 | + $this->_xml->addChild("cardCode", $cardCode); |
|
316 | 316 | return $this->_sendRequest(); |
317 | 317 | } |
318 | 318 | |
@@ -341,13 +341,13 @@ discard block |
||
341 | 341 | */ |
342 | 342 | protected function _setPostString() |
343 | 343 | { |
344 | - ($this->_validationMode != "none" ? $this->_xml->addChild('validationMode',$this->_validationMode) : ""); |
|
344 | + ($this->_validationMode != "none" ? $this->_xml->addChild('validationMode', $this->_validationMode) : ""); |
|
345 | 345 | $this->_post_string = $this->_xml->asXML(); |
346 | 346 | |
347 | 347 | // Add extraOptions CDATA |
348 | 348 | if ($this->_extraOptions) { |
349 | 349 | $this->_xml->addChild("extraOptions"); |
350 | - $this->_post_string = str_replace("<extraOptions></extraOptions>",'<extraOptions><![CDATA[' . $this->_extraOptions . ']]></extraOptions>', $this->_xml->asXML()); |
|
350 | + $this->_post_string = str_replace("<extraOptions></extraOptions>", '<extraOptions><![CDATA[' . $this->_extraOptions . ']]></extraOptions>', $this->_xml->asXML()); |
|
351 | 351 | $this->_extraOptions = false; |
352 | 352 | } |
353 | 353 | // Blank out our validation mode, so that we don't include it in calls that |
@@ -362,12 +362,12 @@ discard block |
||
362 | 362 | */ |
363 | 363 | private function _constructXml($request_type) |
364 | 364 | { |
365 | - $string = '<?xml version="1.0" encoding="utf-8"?><'.$request_type.' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"></'.$request_type.'>'; |
|
365 | + $string = '<?xml version="1.0" encoding="utf-8"?><' . $request_type . ' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"></' . $request_type . '>'; |
|
366 | 366 | $this->_xml = @new SimpleXMLElement($string); |
367 | 367 | $merchant = $this->_xml->addChild('merchantAuthentication'); |
368 | - $merchant->addChild('name',$this->_api_login); |
|
369 | - $merchant->addChild('transactionKey',$this->_transaction_key); |
|
370 | - ($this->_refId ? $this->_xml->addChild('refId',$this->_refId) : ""); |
|
368 | + $merchant->addChild('name', $this->_api_login); |
|
369 | + $merchant->addChild('transactionKey', $this->_transaction_key); |
|
370 | + ($this->_refId ? $this->_xml->addChild('refId', $this->_refId) : ""); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | /** |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | */ |
379 | 379 | private function _addObject($destination, $object) |
380 | 380 | { |
381 | - $array = (array)$object; |
|
381 | + $array = (array) $object; |
|
382 | 382 | foreach ($array as $key => $value) { |
383 | 383 | if ($value && !is_object($value)) { |
384 | 384 | if (is_array($value) && count($value)) { |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | $this->_addObject($items, $item); |
388 | 388 | } |
389 | 389 | } else { |
390 | - $destination->addChild($key,$value); |
|
390 | + $destination->addChild($key, $value); |
|
391 | 391 | } |
392 | 392 | } elseif (is_object($value) && self::_notEmpty($value)) { |
393 | 393 | $dest = $destination->addChild($key); |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | */ |
406 | 406 | private static function _notEmpty($object) |
407 | 407 | { |
408 | - $array = (array)$object; |
|
408 | + $array = (array) $object; |
|
409 | 409 | foreach ($array as $key => $value) { |
410 | 410 | if ($value && !is_object($value)) { |
411 | 411 | return true; |
@@ -441,9 +441,9 @@ discard block |
||
441 | 441 | */ |
442 | 442 | public function getValidationResponses() |
443 | 443 | { |
444 | - $responses = (array)$this->xml->validationDirectResponseList; |
|
444 | + $responses = (array) $this->xml->validationDirectResponseList; |
|
445 | 445 | $return = array(); |
446 | - foreach ((array)$responses["string"] as $response) { |
|
446 | + foreach ((array) $responses["string"] as $response) { |
|
447 | 447 | $return[] = new AuthorizeNetAIM_Response($response, ",", "", array()); |
448 | 448 | } |
449 | 449 | return $return; |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | */ |
463 | 463 | public function getCustomerProfileIds() |
464 | 464 | { |
465 | - $ids = (array)$this->xml->ids; |
|
465 | + $ids = (array) $this->xml->ids; |
|
466 | 466 | return $ids["numericString"]; |
467 | 467 | } |
468 | 468 | |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | */ |
472 | 472 | public function getCustomerPaymentProfileIds() |
473 | 473 | { |
474 | - $ids = (array)$this->xml->customerPaymentProfileIdList; |
|
474 | + $ids = (array) $this->xml->customerPaymentProfileIdList; |
|
475 | 475 | return $ids["numericString"]; |
476 | 476 | } |
477 | 477 | |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | */ |
481 | 481 | public function getCustomerShippingAddressIds() |
482 | 482 | { |
483 | - $ids = (array)$this->xml->customerShippingAddressIdList; |
|
483 | + $ids = (array) $this->xml->customerShippingAddressIdList; |
|
484 | 484 | return $ids["numericString"]; |
485 | 485 | } |
486 | 486 |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | $string = ""; |
52 | 52 | $types = $this->__getTypes(); |
53 | 53 | foreach ($types as $type) { |
54 | - if (preg_match("/struct /",$type)) { |
|
55 | - $type = preg_replace("/struct /","class ",$type); |
|
56 | - $type = preg_replace("/ (\w+) (\w+);/"," // $1\n public \$$2;",$type); |
|
57 | - $string .= $type ."\n"; |
|
54 | + if (preg_match("/struct /", $type)) { |
|
55 | + $type = preg_replace("/struct /", "class ", $type); |
|
56 | + $type = preg_replace("/ (\w+) (\w+);/", " // $1\n public \$$2;", $type); |
|
57 | + $string .= $type . "\n"; |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | return $string; |
@@ -84,13 +84,13 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function saveSoapDocumentation($path) |
86 | 86 | { |
87 | - $string = "<?php\n"; |
|
87 | + $string = "<?php\n"; |
|
88 | 88 | $string .= "/**\n"; |
89 | 89 | $string .= " * Auto generated documentation for the AuthorizeNetSOAP API.\n"; |
90 | 90 | $string .= " * Generated " . date("m/d/Y") . "\n"; |
91 | 91 | $string .= " */\n"; |
92 | 92 | $string .= "class AuthorizeNetSOAP\n"; |
93 | - $string .= "{\n" . $this->getSoapMethods() . "\n}\n\n" . $this->getSoapTypes() ."\n\n ?>"; |
|
93 | + $string .= "{\n" . $this->getSoapMethods() . "\n}\n\n" . $this->getSoapTypes() . "\n\n ?>"; |
|
94 | 94 | return file_put_contents($path, $string); |
95 | 95 | } |
96 | 96 |
@@ -76,7 +76,7 @@ |
||
76 | 76 | } |
77 | 77 | else |
78 | 78 | { |
79 | - echo "Sorry, an error occurred: " . htmlentities($_GET['response_reason_text']); |
|
79 | + echo "Sorry, an error occurred: " . htmlentities($_GET['response_reason_text']); |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | else |
58 | 58 | { |
59 | 59 | // Redirect to error page. |
60 | - $redirect_url = $url . '?response_code='.$response->response_code . '&response_reason_text=' . $response->response_reason_text; |
|
60 | + $redirect_url = $url . '?response_code=' . $response->response_code . '&response_reason_text=' . $response->response_reason_text; |
|
61 | 61 | } |
62 | 62 | // Send the Javascript back to AuthorizeNet, which will redirect user back to your site. |
63 | 63 | echo AuthorizeNetDPM::getRelayResponseSnippet($redirect_url); |
@@ -179,54 +179,54 @@ discard block |
||
179 | 179 | -moz-box-shadow: inset 3px -3px 3px rgba(0,0,0,.5), inset 0 3px 3px rgba(255,255,255,.5), inset -3px 0 3px rgba(255,255,255,.75); |
180 | 180 | box-shadow: inset 3px -3px 3px rgba(0,0,0,.5), inset 0 3px 3px rgba(255,255,255,.5), inset -3px 0 3px rgba(255,255,255,.75); } |
181 | 181 | </style> |
182 | - <form method="post" action="'.$post_url.'"> |
|
183 | - '.$hidden_fields.' |
|
182 | + <form method="post" action="'.$post_url . '"> |
|
183 | + '.$hidden_fields . ' |
|
184 | 184 | <fieldset> |
185 | 185 | <div> |
186 | 186 | <label>Credit Card Number</label> |
187 | - <input type="text" class="text" size="15" name="x_card_num" value="'.($prefill ? '6011000000000012' : '').'"></input> |
|
187 | + <input type="text" class="text" size="15" name="x_card_num" value="'.($prefill ? '6011000000000012' : '') . '"></input> |
|
188 | 188 | </div> |
189 | 189 | <div> |
190 | 190 | <label>Exp.</label> |
191 | - <input type="text" class="text" size="4" name="x_exp_date" value="'.($prefill ? '04/17' : '').'"></input> |
|
191 | + <input type="text" class="text" size="4" name="x_exp_date" value="'.($prefill ? '04/17' : '') . '"></input> |
|
192 | 192 | </div> |
193 | 193 | <div> |
194 | 194 | <label>CCV</label> |
195 | - <input type="text" class="text" size="4" name="x_card_code" value="'.($prefill ? '782' : '').'"></input> |
|
195 | + <input type="text" class="text" size="4" name="x_card_code" value="'.($prefill ? '782' : '') . '"></input> |
|
196 | 196 | </div> |
197 | 197 | </fieldset> |
198 | 198 | <fieldset> |
199 | 199 | <div> |
200 | 200 | <label>First Name</label> |
201 | - <input type="text" class="text" size="15" name="x_first_name" value="'.($prefill ? 'John' : '').'"></input> |
|
201 | + <input type="text" class="text" size="15" name="x_first_name" value="'.($prefill ? 'John' : '') . '"></input> |
|
202 | 202 | </div> |
203 | 203 | <div> |
204 | 204 | <label>Last Name</label> |
205 | - <input type="text" class="text" size="14" name="x_last_name" value="'.($prefill ? 'Doe' : '').'"></input> |
|
205 | + <input type="text" class="text" size="14" name="x_last_name" value="'.($prefill ? 'Doe' : '') . '"></input> |
|
206 | 206 | </div> |
207 | 207 | </fieldset> |
208 | 208 | <fieldset> |
209 | 209 | <div> |
210 | 210 | <label>Address</label> |
211 | - <input type="text" class="text" size="26" name="x_address" value="'.($prefill ? '123 Main Street' : '').'"></input> |
|
211 | + <input type="text" class="text" size="26" name="x_address" value="'.($prefill ? '123 Main Street' : '') . '"></input> |
|
212 | 212 | </div> |
213 | 213 | <div> |
214 | 214 | <label>City</label> |
215 | - <input type="text" class="text" size="15" name="x_city" value="'.($prefill ? 'Boston' : '').'"></input> |
|
215 | + <input type="text" class="text" size="15" name="x_city" value="'.($prefill ? 'Boston' : '') . '"></input> |
|
216 | 216 | </div> |
217 | 217 | </fieldset> |
218 | 218 | <fieldset> |
219 | 219 | <div> |
220 | 220 | <label>State</label> |
221 | - <input type="text" class="text" size="4" name="x_state" value="'.($prefill ? 'MA' : '').'"></input> |
|
221 | + <input type="text" class="text" size="4" name="x_state" value="'.($prefill ? 'MA' : '') . '"></input> |
|
222 | 222 | </div> |
223 | 223 | <div> |
224 | 224 | <label>Zip Code</label> |
225 | - <input type="text" class="text" size="9" name="x_zip" value="'.($prefill ? '02142' : '').'"></input> |
|
225 | + <input type="text" class="text" size="9" name="x_zip" value="'.($prefill ? '02142' : '') . '"></input> |
|
226 | 226 | </div> |
227 | 227 | <div> |
228 | 228 | <label>Country</label> |
229 | - <input type="text" class="text" size="22" name="x_country" value="'.($prefill ? 'US' : '').'"></input> |
|
229 | + <input type="text" class="text" size="22" name="x_country" value="'.($prefill ? 'US' : '') . '"></input> |
|
230 | 230 | </div> |
231 | 231 | </fieldset> |
232 | 232 | <input type="submit" value="BUY" class="submit buy"> |
@@ -53,16 +53,14 @@ discard block |
||
53 | 53 | { |
54 | 54 | // Do your processing here. |
55 | 55 | $redirect_url = $url . '?response_code=1&transaction_id=' . $response->transaction_id; |
56 | - } |
|
57 | - else |
|
56 | + } else |
|
58 | 57 | { |
59 | 58 | // Redirect to error page. |
60 | 59 | $redirect_url = $url . '?response_code='.$response->response_code . '&response_reason_text=' . $response->response_reason_text; |
61 | 60 | } |
62 | 61 | // Send the Javascript back to AuthorizeNet, which will redirect user back to your site. |
63 | 62 | echo AuthorizeNetDPM::getRelayResponseSnippet($redirect_url); |
64 | - } |
|
65 | - else |
|
63 | + } else |
|
66 | 64 | { |
67 | 65 | echo "Error -- not AuthorizeNet. Check your MD5 Setting."; |
68 | 66 | } |
@@ -73,8 +71,7 @@ discard block |
||
73 | 71 | if ($_GET['response_code'] == 1) |
74 | 72 | { |
75 | 73 | echo "Thank you for your purchase! Transaction id: " . htmlentities($_GET['transaction_id']); |
76 | - } |
|
77 | - else |
|
74 | + } else |
|
78 | 75 | { |
79 | 76 | echo "Sorry, an error occurred: " . htmlentities($_GET['response_reason_text']); |
80 | 77 | } |
@@ -1,6 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if ( ! defined( 'ABSPATH' ) ) { |
|
4 | + exit; |
|
5 | +} |
|
4 | 6 | |
5 | 7 | add_filter( 'wpinv_authorizenet_support_subscription', '__return_true' ); |
6 | 8 |
@@ -1,60 +1,60 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -add_filter( 'wpinv_authorizenet_support_subscription', '__return_true' ); |
|
5 | +add_filter('wpinv_authorizenet_support_subscription', '__return_true'); |
|
6 | 6 | |
7 | -function wpinv_authorizenet_cc_form( $invoice_id ) { |
|
8 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
9 | - $cc_owner = !empty( $invoice ) ? esc_attr( $invoice->get_user_full_name() ) : ''; |
|
7 | +function wpinv_authorizenet_cc_form($invoice_id) { |
|
8 | + $invoice = wpinv_get_invoice($invoice_id); |
|
9 | + $cc_owner = !empty($invoice) ? esc_attr($invoice->get_user_full_name()) : ''; |
|
10 | 10 | ?> |
11 | 11 | <div id="authorizenet_cc_form" class="form-horizontal wpi-cc-form panel panel-default"> |
12 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Card Details', 'invoicing' ) ;?></h3></div> |
|
12 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Card Details', 'invoicing'); ?></h3></div> |
|
13 | 13 | <div class="panel-body"> |
14 | 14 | <div class="form-group required"> |
15 | - <label for="auth-input-cc-owner" class="col-sm-3 control-label"><?php _e( 'Card Owner', 'invoicing' ) ;?></label> |
|
15 | + <label for="auth-input-cc-owner" class="col-sm-3 control-label"><?php _e('Card Owner', 'invoicing'); ?></label> |
|
16 | 16 | <div class="col-sm-5"> |
17 | - <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e( 'Card Owner', 'invoicing' ) ;?>" value="<?php echo $cc_owner;?>" name="authorizenet[cc_owner]"> |
|
17 | + <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e('Card Owner', 'invoicing'); ?>" value="<?php echo $cc_owner; ?>" name="authorizenet[cc_owner]"> |
|
18 | 18 | </div> |
19 | 19 | </div> |
20 | 20 | <div class="form-group required"> |
21 | - <label for="auth-input-cc-number" class="col-sm-3 control-label"><?php _e( 'Card Number', 'invoicing' ) ;?></label> |
|
21 | + <label for="auth-input-cc-number" class="col-sm-3 control-label"><?php _e('Card Number', 'invoicing'); ?></label> |
|
22 | 22 | <div class="col-sm-5"> |
23 | - <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e( 'Card Number', 'invoicing' ) ;?>" value="" name="authorizenet[cc_number]"> |
|
23 | + <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e('Card Number', 'invoicing'); ?>" value="" name="authorizenet[cc_number]"> |
|
24 | 24 | </div> |
25 | 25 | </div> |
26 | 26 | <div class="form-group required"> |
27 | - <label for="auth-input-cc-expire-date" class="col-sm-3 control-label"><?php _e( 'Card Expiry Date', 'invoicing' ) ;?></label> |
|
27 | + <label for="auth-input-cc-expire-date" class="col-sm-3 control-label"><?php _e('Card Expiry Date', 'invoicing'); ?></label> |
|
28 | 28 | <div class="col-sm-2"> |
29 | 29 | <select class="form-control" id="auth-input-cc-expire-date" name="authorizenet[cc_expire_month]"> |
30 | - <?php for ( $i = 1; $i <= 12; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
31 | - <option value="<?php echo $value;?>"><?php echo $value;?></option> |
|
30 | + <?php for ($i = 1; $i <= 12; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
31 | + <option value="<?php echo $value; ?>"><?php echo $value; ?></option> |
|
32 | 32 | <?php } ?> |
33 | 33 | </select> |
34 | 34 | </div> |
35 | 35 | <div class="col-sm-3"> |
36 | 36 | <select class="form-control" name="authorizenet[cc_expire_year]"> |
37 | - <?php $year = date( 'Y' ); for ( $i = $year; $i <= ( $year + 10 ); $i++ ) { ?> |
|
38 | - <option value="<?php echo $i;?>"><?php echo $i;?></option> |
|
37 | + <?php $year = date('Y'); for ($i = $year; $i <= ($year + 10); $i++) { ?> |
|
38 | + <option value="<?php echo $i; ?>"><?php echo $i; ?></option> |
|
39 | 39 | <?php } ?> |
40 | 40 | </select> |
41 | 41 | </div> |
42 | 42 | </div> |
43 | 43 | <div class="form-group required"> |
44 | - <label for="auth-input-cc-cvv2" class="col-sm-3 control-label"><?php _e( 'Card Security Code (CVV2)', 'invoicing' ) ;?></label> |
|
44 | + <label for="auth-input-cc-cvv2" class="col-sm-3 control-label"><?php _e('Card Security Code (CVV2)', 'invoicing'); ?></label> |
|
45 | 45 | <div class="col-sm-5"> |
46 | - <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e( 'Card Security Code (CVV2)', 'invoicing' ) ;?>" value="" name="authorizenet[cc_cvv2]""> |
|
46 | + <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e('Card Security Code (CVV2)', 'invoicing'); ?>" value="" name="authorizenet[cc_cvv2]""> |
|
47 | 47 | </div> |
48 | 48 | </div> |
49 | 49 | </div> |
50 | 50 | </div> |
51 | 51 | <?php |
52 | 52 | } |
53 | -add_action( 'wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1 ); |
|
53 | +add_action('wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1); |
|
54 | 54 | |
55 | -function wpinv_process_authorizenet_payment( $purchase_data ) { |
|
56 | - if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
57 | - wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
55 | +function wpinv_process_authorizenet_payment($purchase_data) { |
|
56 | + if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) { |
|
57 | + wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | // Collect payment data |
@@ -72,10 +72,10 @@ discard block |
||
72 | 72 | ); |
73 | 73 | |
74 | 74 | // Record the pending payment |
75 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
75 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
76 | 76 | |
77 | - if ( !empty( $invoice ) ) { |
|
78 | - $authorizenet_card = !empty( $_POST['authorizenet'] ) ? $_POST['authorizenet'] : array(); |
|
77 | + if (!empty($invoice)) { |
|
78 | + $authorizenet_card = !empty($_POST['authorizenet']) ? $_POST['authorizenet'] : array(); |
|
79 | 79 | $card_defaults = array( |
80 | 80 | 'cc_owner' => $invoice->get_user_full_name(), |
81 | 81 | 'cc_number' => false, |
@@ -83,192 +83,192 @@ discard block |
||
83 | 83 | 'cc_expire_year' => false, |
84 | 84 | 'cc_cvv2' => false, |
85 | 85 | ); |
86 | - $authorizenet_card = wp_parse_args( $authorizenet_card, $card_defaults ); |
|
86 | + $authorizenet_card = wp_parse_args($authorizenet_card, $card_defaults); |
|
87 | 87 | |
88 | - if ( empty( $authorizenet_card['cc_owner'] ) ) { |
|
89 | - wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing')); |
|
88 | + if (empty($authorizenet_card['cc_owner'])) { |
|
89 | + wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing')); |
|
90 | 90 | } |
91 | - if ( empty( $authorizenet_card['cc_number'] ) ) { |
|
92 | - wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing')); |
|
91 | + if (empty($authorizenet_card['cc_number'])) { |
|
92 | + wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing')); |
|
93 | 93 | } |
94 | - if ( empty( $authorizenet_card['cc_expire_month'] ) ) { |
|
95 | - wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing')); |
|
94 | + if (empty($authorizenet_card['cc_expire_month'])) { |
|
95 | + wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing')); |
|
96 | 96 | } |
97 | - if ( empty( $authorizenet_card['cc_expire_year'] ) ) { |
|
98 | - wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing')); |
|
97 | + if (empty($authorizenet_card['cc_expire_year'])) { |
|
98 | + wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing')); |
|
99 | 99 | } |
100 | - if ( empty( $authorizenet_card['cc_cvv2'] ) ) { |
|
101 | - wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) ); |
|
100 | + if (empty($authorizenet_card['cc_cvv2'])) { |
|
101 | + wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing')); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | $errors = wpinv_get_errors(); |
105 | 105 | |
106 | - if ( empty( $errors ) ) { |
|
106 | + if (empty($errors)) { |
|
107 | 107 | $invoice_id = $invoice->ID; |
108 | 108 | $quantities_enabled = wpinv_item_quantities_enabled(); |
109 | 109 | $use_taxes = wpinv_use_taxes(); |
110 | 110 | |
111 | 111 | $authorizeAIM = wpinv_authorizenet_AIM(); |
112 | - $authorizeAIM->first_name = wpinv_utf8_substr( $invoice->get_first_name(), 0, 50 ); |
|
113 | - $authorizeAIM->last_name = wpinv_utf8_substr( $invoice->get_last_name(), 0, 50 ); |
|
114 | - $authorizeAIM->company = wpinv_utf8_substr( $invoice->company, 0, 50 ); |
|
115 | - $authorizeAIM->address = wpinv_utf8_substr( wp_strip_all_tags( $invoice->get_address(), true ), 0, 60 ); |
|
116 | - $authorizeAIM->city = wpinv_utf8_substr( $invoice->city, 0, 40 ); |
|
117 | - $authorizeAIM->state = wpinv_utf8_substr( $invoice->state, 0, 40 ); |
|
118 | - $authorizeAIM->zip = wpinv_utf8_substr( $invoice->zip, 0, 40 ); |
|
119 | - $authorizeAIM->country = wpinv_utf8_substr( $invoice->country, 0, 60 ); |
|
120 | - $authorizeAIM->phone = wpinv_utf8_substr( $invoice->phone, 0, 25 ); |
|
121 | - $authorizeAIM->email = wpinv_utf8_substr( $invoice->get_email(), 0, 255 ); |
|
122 | - $authorizeAIM->amount = wpinv_sanitize_amount( $invoice->get_total() ); |
|
123 | - $authorizeAIM->card_num = str_replace( ' ', '', sanitize_text_field( $authorizenet_card['cc_number'] ) ); |
|
124 | - $authorizeAIM->exp_date = sanitize_text_field( $authorizenet_card['cc_expire_month'] ) . sanitize_text_field( $authorizenet_card['cc_expire_year'] ); |
|
125 | - $authorizeAIM->card_code = sanitize_text_field( $authorizenet_card['cc_cvv2'] ); |
|
112 | + $authorizeAIM->first_name = wpinv_utf8_substr($invoice->get_first_name(), 0, 50); |
|
113 | + $authorizeAIM->last_name = wpinv_utf8_substr($invoice->get_last_name(), 0, 50); |
|
114 | + $authorizeAIM->company = wpinv_utf8_substr($invoice->company, 0, 50); |
|
115 | + $authorizeAIM->address = wpinv_utf8_substr(wp_strip_all_tags($invoice->get_address(), true), 0, 60); |
|
116 | + $authorizeAIM->city = wpinv_utf8_substr($invoice->city, 0, 40); |
|
117 | + $authorizeAIM->state = wpinv_utf8_substr($invoice->state, 0, 40); |
|
118 | + $authorizeAIM->zip = wpinv_utf8_substr($invoice->zip, 0, 40); |
|
119 | + $authorizeAIM->country = wpinv_utf8_substr($invoice->country, 0, 60); |
|
120 | + $authorizeAIM->phone = wpinv_utf8_substr($invoice->phone, 0, 25); |
|
121 | + $authorizeAIM->email = wpinv_utf8_substr($invoice->get_email(), 0, 255); |
|
122 | + $authorizeAIM->amount = wpinv_sanitize_amount($invoice->get_total()); |
|
123 | + $authorizeAIM->card_num = str_replace(' ', '', sanitize_text_field($authorizenet_card['cc_number'])); |
|
124 | + $authorizeAIM->exp_date = sanitize_text_field($authorizenet_card['cc_expire_month']) . sanitize_text_field($authorizenet_card['cc_expire_year']); |
|
125 | + $authorizeAIM->card_code = sanitize_text_field($authorizenet_card['cc_cvv2']); |
|
126 | 126 | $authorizeAIM->invoice_num = $invoice->ID; |
127 | 127 | |
128 | 128 | $item_desc = array(); |
129 | - foreach ( $invoice->get_cart_details() as $item ) { |
|
130 | - $quantity = $quantities_enabled && !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
131 | - $item_name = wpinv_utf8_substr( $item['name'], 0, 31 ); |
|
132 | - $item_desc[] = $item_name . ' (' . $quantity . 'x ' . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')'; |
|
129 | + foreach ($invoice->get_cart_details() as $item) { |
|
130 | + $quantity = $quantities_enabled && !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
131 | + $item_name = wpinv_utf8_substr($item['name'], 0, 31); |
|
132 | + $item_desc[] = $item_name . ' (' . $quantity . 'x ' . wpinv_price(wpinv_format_amount($item['item_price'])) . ')'; |
|
133 | 133 | |
134 | - $authorizeAIM->addLineItem( $item['id'], $item_name, '', $quantity, $item['item_price'], ( $use_taxes && !empty( $item['tax'] ) && $item['tax'] > 0 ? 'Y' : 'N' ) ); |
|
134 | + $authorizeAIM->addLineItem($item['id'], $item_name, '', $quantity, $item['item_price'], ($use_taxes && !empty($item['tax']) && $item['tax'] > 0 ? 'Y' : 'N')); |
|
135 | 135 | } |
136 | 136 | |
137 | - $item_desc = '#' . $invoice->get_number() . ': ' . implode( ', ', $item_desc ); |
|
137 | + $item_desc = '#' . $invoice->get_number() . ': ' . implode(', ', $item_desc); |
|
138 | 138 | |
139 | - if ( $use_taxes && $invoice->get_tax() > 0 ) { |
|
140 | - $authorizeAIM->tax = $invoice->get_tax(); |
|
139 | + if ($use_taxes && $invoice->get_tax() > 0) { |
|
140 | + $authorizeAIM->tax = $invoice->get_tax(); |
|
141 | 141 | |
142 | - $item_desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) ); |
|
142 | + $item_desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true)); |
|
143 | 143 | } |
144 | 144 | |
145 | - if ( $invoice->get_discount() > 0 ) { |
|
146 | - $item_desc .= ', ' . wp_sprintf( __( 'Discount: %s', 'invoicing' ), $invoice->get_discount( true ) ); |
|
145 | + if ($invoice->get_discount() > 0) { |
|
146 | + $item_desc .= ', ' . wp_sprintf(__('Discount: %s', 'invoicing'), $invoice->get_discount(true)); |
|
147 | 147 | } |
148 | 148 | |
149 | - $item_description = wpinv_utf8_substr( $item_desc, 0, 255 ); |
|
150 | - $item_description = html_entity_decode( $item_desc , ENT_QUOTES, 'UTF-8' ); |
|
149 | + $item_description = wpinv_utf8_substr($item_desc, 0, 255); |
|
150 | + $item_description = html_entity_decode($item_desc, ENT_QUOTES, 'UTF-8'); |
|
151 | 151 | |
152 | - $authorizeAIM->description = wpinv_utf8_substr( $item_description, 0, 255 ); |
|
152 | + $authorizeAIM->description = wpinv_utf8_substr($item_description, 0, 255); |
|
153 | 153 | |
154 | 154 | $is_recurring = $invoice->is_recurring(); // Recurring payment. |
155 | 155 | |
156 | - if ( $is_recurring ) { |
|
156 | + if ($is_recurring) { |
|
157 | 157 | $authorizeAIM->recurring_billing = true; |
158 | 158 | } |
159 | 159 | |
160 | 160 | try { |
161 | 161 | |
162 | - if ( $is_recurring ) { |
|
162 | + if ($is_recurring) { |
|
163 | 163 | $trx_type = wpinv_get_option('authorizenet_transaction_type_recurring', 'authorize_only'); |
164 | - if('authorize_capture' == $trx_type){ |
|
164 | + if ('authorize_capture' == $trx_type) { |
|
165 | 165 | $response = $authorizeAIM->authorizeAndCapture(); |
166 | 166 | } else { |
167 | 167 | $response = $authorizeAIM->authorizeOnly(); |
168 | 168 | } |
169 | 169 | } else { |
170 | 170 | $trx_type = wpinv_get_option('authorizenet_transaction_type', 'authorize_capture'); |
171 | - if('authorize_capture' == $trx_type){ |
|
171 | + if ('authorize_capture' == $trx_type) { |
|
172 | 172 | $response = $authorizeAIM->authorizeAndCapture(); |
173 | 173 | } else { |
174 | 174 | $response = $authorizeAIM->authorizeOnly(); |
175 | 175 | } |
176 | 176 | } |
177 | 177 | |
178 | - if ( $response->approved || $response->held ) { |
|
179 | - if ( $response->approved ) { |
|
180 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
178 | + if ($response->approved || $response->held) { |
|
179 | + if ($response->approved) { |
|
180 | + wpinv_update_payment_status($invoice_id, 'publish'); |
|
181 | 181 | } |
182 | - wpinv_set_payment_transaction_id( $invoice_id, $response->transaction_id ); |
|
182 | + wpinv_set_payment_transaction_id($invoice_id, $response->transaction_id); |
|
183 | 183 | |
184 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'Authorize.Net payment response: %s', 'invoicing' ), $response->response_reason_text ), '', '', true ); |
|
185 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'Authorize.Net payment: Transaction ID %s, Transaction Type %s, Authorization Code %s', 'invoicing' ), $response->transaction_id, strtoupper( $response->transaction_type ), $response->authorization_code ), '', '', true ); |
|
184 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('Authorize.Net payment response: %s', 'invoicing'), $response->response_reason_text), '', '', true); |
|
185 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('Authorize.Net payment: Transaction ID %s, Transaction Type %s, Authorization Code %s', 'invoicing'), $response->transaction_id, strtoupper($response->transaction_type), $response->authorization_code), '', '', true); |
|
186 | 186 | |
187 | - do_action( 'wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card ); |
|
187 | + do_action('wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card); |
|
188 | 188 | |
189 | 189 | wpinv_clear_errors(); |
190 | 190 | wpinv_empty_cart(); |
191 | 191 | |
192 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
192 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
193 | 193 | } else { |
194 | - if ( !empty( $response->response_reason_text ) ) { |
|
195 | - $error = __( $response->response_reason_text, 'invoicing' ); |
|
196 | - } else if ( !empty( $response->error_message ) ) { |
|
197 | - $error = __( $response->error_message, 'invoicing' ); |
|
194 | + if (!empty($response->response_reason_text)) { |
|
195 | + $error = __($response->response_reason_text, 'invoicing'); |
|
196 | + } else if (!empty($response->error_message)) { |
|
197 | + $error = __($response->error_message, 'invoicing'); |
|
198 | 198 | } else { |
199 | - $error = wp_sprintf( __( 'Error data: %s', 'invoicing' ), print_r( $response, true ) ); |
|
199 | + $error = wp_sprintf(__('Error data: %s', 'invoicing'), print_r($response, true)); |
|
200 | 200 | } |
201 | 201 | |
202 | - $error = wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $error ); |
|
202 | + $error = wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $error); |
|
203 | 203 | |
204 | - wpinv_set_error( 'payment_error', $error ); |
|
205 | - wpinv_record_gateway_error( $error, $response ); |
|
206 | - wpinv_insert_payment_note( $invoice_id, $error, '', '', true ); |
|
204 | + wpinv_set_error('payment_error', $error); |
|
205 | + wpinv_record_gateway_error($error, $response); |
|
206 | + wpinv_insert_payment_note($invoice_id, $error, '', '', true); |
|
207 | 207 | |
208 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
208 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
209 | 209 | } |
210 | - } catch ( AuthorizeNetException $e ) { |
|
211 | - wpinv_set_error( 'request_error', $e->getMessage() ); |
|
212 | - wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $e->getMessage() ) ); |
|
213 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
210 | + } catch (AuthorizeNetException $e) { |
|
211 | + wpinv_set_error('request_error', $e->getMessage()); |
|
212 | + wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $e->getMessage())); |
|
213 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
214 | 214 | } |
215 | 215 | } else { |
216 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
216 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
217 | 217 | } |
218 | 218 | } else { |
219 | - wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.Net payment. Payment data: %s', 'invoicing' ), print_r( $payment_data, true ) ), $invoice ); |
|
220 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
219 | + wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.Net payment. Payment data: %s', 'invoicing'), print_r($payment_data, true)), $invoice); |
|
220 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
221 | 221 | } |
222 | 222 | } |
223 | -add_action( 'wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment' ); |
|
223 | +add_action('wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment'); |
|
224 | 224 | |
225 | -function wpinv_authorizenet_cancel_subscription( $subscription_id = '' ) { |
|
226 | - if ( empty( $subscription_id ) ) { |
|
225 | +function wpinv_authorizenet_cancel_subscription($subscription_id = '') { |
|
226 | + if (empty($subscription_id)) { |
|
227 | 227 | return false; |
228 | 228 | } |
229 | 229 | |
230 | 230 | try { |
231 | 231 | $authnetXML = wpinv_authorizenet_XML(); |
232 | - $authnetXML->ARBCancelSubscriptionRequest( array( 'subscriptionId' => $subscription_id ) ); |
|
232 | + $authnetXML->ARBCancelSubscriptionRequest(array('subscriptionId' => $subscription_id)); |
|
233 | 233 | return $authnetXML->isSuccessful(); |
234 | - } catch( Exception $e ) { |
|
235 | - wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) ); |
|
234 | + } catch (Exception $e) { |
|
235 | + wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing')); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | return false; |
239 | 239 | } |
240 | 240 | |
241 | -function wpinv_recurring_cancel_authorizenet_subscription( $subscription, $valid = false ) { |
|
242 | - if ( ! empty( $valid ) && ! empty( $subscription->profile_id ) ) { |
|
243 | - return wpinv_authorizenet_cancel_subscription( $subscription->profile_id ); |
|
241 | +function wpinv_recurring_cancel_authorizenet_subscription($subscription, $valid = false) { |
|
242 | + if (!empty($valid) && !empty($subscription->profile_id)) { |
|
243 | + return wpinv_authorizenet_cancel_subscription($subscription->profile_id); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | return false; |
247 | 247 | } |
248 | -add_action( 'wpinv_recurring_cancel_authorizenet_subscription', 'wpinv_recurring_cancel_authorizenet_subscription', 10, 2 ); |
|
248 | +add_action('wpinv_recurring_cancel_authorizenet_subscription', 'wpinv_recurring_cancel_authorizenet_subscription', 10, 2); |
|
249 | 249 | |
250 | -function wpinv_authorizenet_valid_ipn( $md5_hash, $transaction_id, $amount ) { |
|
251 | - $authorizenet_md5_hash = wpinv_get_option( 'authorizenet_md5_hash' ); |
|
252 | - if ( empty( $authorizenet_md5_hash ) ) { |
|
250 | +function wpinv_authorizenet_valid_ipn($md5_hash, $transaction_id, $amount) { |
|
251 | + $authorizenet_md5_hash = wpinv_get_option('authorizenet_md5_hash'); |
|
252 | + if (empty($authorizenet_md5_hash)) { |
|
253 | 253 | return true; |
254 | 254 | } |
255 | 255 | |
256 | - $compare_md5 = strtoupper( md5( $authorizenet_md5_hash . $transaction_id . $amount ) ); |
|
256 | + $compare_md5 = strtoupper(md5($authorizenet_md5_hash . $transaction_id . $amount)); |
|
257 | 257 | |
258 | - return hash_equals( $compare_md5, $md5_hash ); |
|
258 | + return hash_equals($compare_md5, $md5_hash); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | function wpinv_authorizenet_AIM() { |
262 | - if ( !class_exists( 'AuthorizeNetException' ) ) { |
|
263 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php'; |
|
262 | + if (!class_exists('AuthorizeNetException')) { |
|
263 | + require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php'; |
|
264 | 264 | } |
265 | 265 | |
266 | - $authorizeAIM = new AuthorizeNetAIM( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ) ); |
|
266 | + $authorizeAIM = new AuthorizeNetAIM(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key')); |
|
267 | 267 | |
268 | - if ( wpinv_is_test_mode( 'authorizenet' ) ) { |
|
269 | - $authorizeAIM->setSandbox( true ); |
|
268 | + if (wpinv_is_test_mode('authorizenet')) { |
|
269 | + $authorizeAIM->setSandbox(true); |
|
270 | 270 | } else { |
271 | - $authorizeAIM->setSandbox( false ); |
|
271 | + $authorizeAIM->setSandbox(false); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | $authorizeAIM->customer_ip = wpinv_get_ip(); |
@@ -277,250 +277,250 @@ discard block |
||
277 | 277 | } |
278 | 278 | |
279 | 279 | function wpinv_authorizenet_XML() { |
280 | - if ( !class_exists( 'AuthnetXML' ) ) { |
|
281 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php'; |
|
280 | + if (!class_exists('AuthnetXML')) { |
|
281 | + require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php'; |
|
282 | 282 | } |
283 | 283 | |
284 | - $authnetXML = new AuthnetXML( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ), (bool)wpinv_is_test_mode( 'authorizenet' ) ); |
|
284 | + $authnetXML = new AuthnetXML(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'), (bool) wpinv_is_test_mode('authorizenet')); |
|
285 | 285 | |
286 | 286 | return $authnetXML; |
287 | 287 | } |
288 | 288 | |
289 | -function wpinv_authorizenet_handle_response( $response, $invoice, $card_info = array() ) { |
|
290 | - if ( empty( $response ) || empty( $invoice ) ) { |
|
289 | +function wpinv_authorizenet_handle_response($response, $invoice, $card_info = array()) { |
|
290 | + if (empty($response) || empty($invoice)) { |
|
291 | 291 | return false; |
292 | 292 | } |
293 | 293 | |
294 | - if ( $invoice->is_recurring() && !empty( $response->approved ) ) { |
|
295 | - $subscription = wpinv_authorizenet_create_new_subscription( $invoice, $response, $card_info ); |
|
294 | + if ($invoice->is_recurring() && !empty($response->approved)) { |
|
295 | + $subscription = wpinv_authorizenet_create_new_subscription($invoice, $response, $card_info); |
|
296 | 296 | $success = false; |
297 | - if ( wpinv_is_test_mode( 'authorizenet' ) ) { |
|
297 | + if (wpinv_is_test_mode('authorizenet')) { |
|
298 | 298 | $success = true; |
299 | 299 | } else { |
300 | 300 | $success = $subscription->isSuccessful(); |
301 | 301 | } |
302 | 302 | |
303 | - if ( !empty( $subscription ) && $success ) { |
|
304 | - do_action( 'wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet' ); |
|
303 | + if (!empty($subscription) && $success) { |
|
304 | + do_action('wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet'); |
|
305 | 305 | |
306 | - wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ); |
|
306 | + wpinv_authorizenet_subscription_record_signup($subscription, $invoice); |
|
307 | 307 | |
308 | - do_action( 'wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet' ); |
|
308 | + do_action('wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet'); |
|
309 | 309 | } else { |
310 | - if ( isset( $subscription->messages->message ) ) { |
|
310 | + if (isset($subscription->messages->message)) { |
|
311 | 311 | $error = $subscription->messages->message->code . ': ' . $subscription->messages->message->text; |
312 | - wpinv_set_error( 'wpinv_authorize_recurring_error', $error, 'invoicing' ); |
|
312 | + wpinv_set_error('wpinv_authorize_recurring_error', $error, 'invoicing'); |
|
313 | 313 | } else { |
314 | - $error = __( 'Your subscription cannot be created due to an error.', 'invoicing' ); |
|
315 | - wpinv_set_error( 'wpinv_authorize_recurring_error', $error ); |
|
314 | + $error = __('Your subscription cannot be created due to an error.', 'invoicing'); |
|
315 | + wpinv_set_error('wpinv_authorize_recurring_error', $error); |
|
316 | 316 | } |
317 | 317 | |
318 | - wpinv_record_gateway_error( $error, $subscription ); |
|
318 | + wpinv_record_gateway_error($error, $subscription); |
|
319 | 319 | |
320 | - wpinv_insert_payment_note( $invoice->ID, wp_sprintf( __( 'Authorize.Net subscription error occurred. %s', 'invoicing' ), $error ), '', '', true ); |
|
320 | + wpinv_insert_payment_note($invoice->ID, wp_sprintf(__('Authorize.Net subscription error occurred. %s', 'invoicing'), $error), '', '', true); |
|
321 | 321 | } |
322 | 322 | } |
323 | 323 | } |
324 | -add_action( 'wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3 ); |
|
324 | +add_action('wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3); |
|
325 | 325 | |
326 | -function wpinv_authorizenet_create_new_subscription( $invoice, $response = array(), $card_info = array() ) { |
|
327 | - if ( empty( $invoice ) ) { |
|
326 | +function wpinv_authorizenet_create_new_subscription($invoice, $response = array(), $card_info = array()) { |
|
327 | + if (empty($invoice)) { |
|
328 | 328 | return false; |
329 | 329 | } |
330 | 330 | |
331 | - $params = wpinv_authorizenet_generate_subscription_params( $invoice, $card_info, $response ); |
|
331 | + $params = wpinv_authorizenet_generate_subscription_params($invoice, $card_info, $response); |
|
332 | 332 | |
333 | 333 | try { |
334 | 334 | $authnetXML = wpinv_authorizenet_XML(); |
335 | - $authnetXML->ARBCreateSubscriptionRequest( $params ); |
|
336 | - } catch( Exception $e ) { |
|
335 | + $authnetXML->ARBCreateSubscriptionRequest($params); |
|
336 | + } catch (Exception $e) { |
|
337 | 337 | $authnetXML = array(); |
338 | - wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) ); |
|
338 | + wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing')); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | return $authnetXML; |
342 | 342 | } |
343 | 343 | |
344 | -function wpinv_authorizenet_generate_subscription_params( $invoice, $card_info = array(), $response = array() ) { |
|
345 | - if ( empty( $invoice ) ) { |
|
344 | +function wpinv_authorizenet_generate_subscription_params($invoice, $card_info = array(), $response = array()) { |
|
345 | + if (empty($invoice)) { |
|
346 | 346 | return false; |
347 | 347 | } |
348 | 348 | |
349 | - $subscription_item = $invoice->get_recurring( true ); |
|
350 | - if ( empty( $subscription_item->ID ) ) { |
|
349 | + $subscription_item = $invoice->get_recurring(true); |
|
350 | + if (empty($subscription_item->ID)) { |
|
351 | 351 | return false; |
352 | 352 | } |
353 | 353 | |
354 | - $item = $invoice->get_recurring( true ); |
|
354 | + $item = $invoice->get_recurring(true); |
|
355 | 355 | |
356 | - if ( empty( $item ) ) { |
|
356 | + if (empty($item)) { |
|
357 | 357 | $name = ''; |
358 | 358 | } |
359 | 359 | |
360 | - if ( !( $name = $item->get_name() ) ) { |
|
360 | + if (!($name = $item->get_name())) { |
|
361 | 361 | $name = $item->post_name; |
362 | 362 | } |
363 | 363 | |
364 | - $card_details = wpinv_authorizenet_generate_card_info( $card_info ); |
|
364 | + $card_details = wpinv_authorizenet_generate_card_info($card_info); |
|
365 | 365 | $subscription_name = $invoice->get_subscription_name(); |
366 | - $initial_amount = wpinv_round_amount( $invoice->get_total() ); |
|
367 | - $recurring_amount = wpinv_round_amount( $invoice->get_recurring_details( 'total' ) ); |
|
366 | + $initial_amount = wpinv_round_amount($invoice->get_total()); |
|
367 | + $recurring_amount = wpinv_round_amount($invoice->get_recurring_details('total')); |
|
368 | 368 | $interval = $subscription_item->get_recurring_interval(); |
369 | 369 | $period = $subscription_item->get_recurring_period(); |
370 | - $bill_times = (int)$subscription_item->get_recurring_limit(); |
|
370 | + $bill_times = (int) $subscription_item->get_recurring_limit(); |
|
371 | 371 | $bill_times = $bill_times > 0 ? $bill_times : 9999; |
372 | 372 | |
373 | - $time_period = wpinv_authorizenet_get_time_period( $interval, $period ); |
|
373 | + $time_period = wpinv_authorizenet_get_time_period($interval, $period); |
|
374 | 374 | $interval = $time_period['interval']; |
375 | 375 | $period = $time_period['period']; |
376 | 376 | |
377 | 377 | $current_tz = date_default_timezone_get(); |
378 | - date_default_timezone_set( 'America/Denver' ); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts. |
|
379 | - $today = date( 'Y-m-d' ); |
|
380 | - date_default_timezone_set( $current_tz ); |
|
378 | + date_default_timezone_set('America/Denver'); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts. |
|
379 | + $today = date('Y-m-d'); |
|
380 | + date_default_timezone_set($current_tz); |
|
381 | 381 | |
382 | 382 | $free_trial = $invoice->is_free_trial(); |
383 | - if ( $free_trial && $subscription_item->has_free_trial() ) { |
|
383 | + if ($free_trial && $subscription_item->has_free_trial()) { |
|
384 | 384 | $trial_interval = $subscription_item->get_trial_interval(); |
385 | - $trial_period = $subscription_item->get_trial_period( true ); |
|
385 | + $trial_period = $subscription_item->get_trial_period(true); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | $subscription = array(); |
389 | 389 | $subscription['name'] = $subscription_name; |
390 | 390 | |
391 | 391 | $subscription['paymentSchedule'] = array( |
392 | - 'interval' => array( 'length' => $interval, 'unit' => $period ), |
|
392 | + 'interval' => array('length' => $interval, 'unit' => $period), |
|
393 | 393 | 'startDate' => $today, |
394 | 394 | 'totalOccurrences' => $bill_times, |
395 | - 'trialOccurrences' => $free_trial || ( $initial_amount != $recurring_amount ) ? 1 : 0, |
|
395 | + 'trialOccurrences' => $free_trial || ($initial_amount != $recurring_amount) ? 1 : 0, |
|
396 | 396 | ); |
397 | 397 | |
398 | 398 | $subscription['amount'] = $recurring_amount; |
399 | 399 | $subscription['trialAmount'] = $initial_amount; |
400 | - $subscription['payment'] = array( 'creditCard' => $card_details ); |
|
401 | - $subscription['order'] = array( 'invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number() ); |
|
402 | - $subscription['customer'] = array( 'id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone ); |
|
400 | + $subscription['payment'] = array('creditCard' => $card_details); |
|
401 | + $subscription['order'] = array('invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number()); |
|
402 | + $subscription['customer'] = array('id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone); |
|
403 | 403 | |
404 | 404 | $subscription['billTo'] = array( |
405 | 405 | 'firstName' => $invoice->get_first_name(), |
406 | 406 | 'lastName' => $invoice->get_last_name(), |
407 | 407 | 'company' => $invoice->company, |
408 | - 'address' => wp_strip_all_tags( $invoice->get_address(), true ), |
|
408 | + 'address' => wp_strip_all_tags($invoice->get_address(), true), |
|
409 | 409 | 'city' => $invoice->city, |
410 | 410 | 'state' => $invoice->state, |
411 | 411 | 'zip' => $invoice->zip, |
412 | 412 | 'country' => $invoice->country, |
413 | 413 | ); |
414 | 414 | |
415 | - $params = array( 'subscription' => $subscription ); |
|
415 | + $params = array('subscription' => $subscription); |
|
416 | 416 | |
417 | - return apply_filters( 'wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response ); |
|
417 | + return apply_filters('wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response); |
|
418 | 418 | } |
419 | 419 | |
420 | -function wpinv_authorizenet_generate_card_info( $card_info = array() ) { |
|
421 | - $card_defaults = array( |
|
420 | +function wpinv_authorizenet_generate_card_info($card_info = array()) { |
|
421 | + $card_defaults = array( |
|
422 | 422 | 'cc_owner' => null, |
423 | 423 | 'cc_number' => null, |
424 | 424 | 'cc_expire_month' => null, |
425 | 425 | 'cc_expire_year' => null, |
426 | 426 | 'cc_cvv2' => null, |
427 | 427 | ); |
428 | - $card_info = wp_parse_args( $card_info, $card_defaults ); |
|
428 | + $card_info = wp_parse_args($card_info, $card_defaults); |
|
429 | 429 | |
430 | 430 | $card_details = array( |
431 | - 'cardNumber' => str_replace( ' ', '', sanitize_text_field( $card_info['cc_number'] ) ), |
|
432 | - 'expirationDate' => sanitize_text_field( $card_info['cc_expire_month'] ) . sanitize_text_field( $card_info['cc_expire_year'] ), |
|
433 | - 'cardCode' => sanitize_text_field( $card_info['cc_cvv2'] ), |
|
431 | + 'cardNumber' => str_replace(' ', '', sanitize_text_field($card_info['cc_number'])), |
|
432 | + 'expirationDate' => sanitize_text_field($card_info['cc_expire_month']) . sanitize_text_field($card_info['cc_expire_year']), |
|
433 | + 'cardCode' => sanitize_text_field($card_info['cc_cvv2']), |
|
434 | 434 | ); |
435 | 435 | |
436 | 436 | return $card_details; |
437 | 437 | } |
438 | 438 | |
439 | -function wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ) { |
|
440 | - $parent_invoice_id = absint( $invoice->ID ); |
|
439 | +function wpinv_authorizenet_subscription_record_signup($subscription, $invoice) { |
|
440 | + $parent_invoice_id = absint($invoice->ID); |
|
441 | 441 | |
442 | - if( empty( $parent_invoice_id ) ) { |
|
442 | + if (empty($parent_invoice_id)) { |
|
443 | 443 | return; |
444 | 444 | } |
445 | 445 | |
446 | - $invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
447 | - if ( empty( $invoice ) ) { |
|
446 | + $invoice = wpinv_get_invoice($parent_invoice_id); |
|
447 | + if (empty($invoice)) { |
|
448 | 448 | return; |
449 | 449 | } |
450 | 450 | |
451 | - $subscriptionId = (array)$subscription->subscriptionId; |
|
452 | - $subscription_id = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $parent_invoice_id; |
|
451 | + $subscriptionId = (array) $subscription->subscriptionId; |
|
452 | + $subscription_id = !empty($subscriptionId[0]) ? $subscriptionId[0] : $parent_invoice_id; |
|
453 | 453 | |
454 | - $subscription = wpinv_get_authorizenet_subscription( $subscription, $parent_invoice_id ); |
|
454 | + $subscription = wpinv_get_authorizenet_subscription($subscription, $parent_invoice_id); |
|
455 | 455 | |
456 | - if ( false === $subscription ) { |
|
456 | + if (false === $subscription) { |
|
457 | 457 | return; |
458 | 458 | } |
459 | 459 | |
460 | 460 | // Set payment to complete |
461 | - wpinv_update_payment_status( $subscription->parent_payment_id, 'publish' ); |
|
461 | + wpinv_update_payment_status($subscription->parent_payment_id, 'publish'); |
|
462 | 462 | sleep(1); |
463 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'Authorize.Net Subscription ID: %s', 'invoicing' ) , $subscription_id ), '', '', true ); |
|
464 | - update_post_meta($parent_invoice_id,'_wpinv_subscr_profile_id', $subscription_id); |
|
463 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('Authorize.Net Subscription ID: %s', 'invoicing'), $subscription_id), '', '', true); |
|
464 | + update_post_meta($parent_invoice_id, '_wpinv_subscr_profile_id', $subscription_id); |
|
465 | 465 | |
466 | 466 | $status = 'trialling' == $subscription->status ? 'trialling' : 'active'; |
467 | - $diff_days = absint( ( ( strtotime( $subscription->expiration ) - strtotime( $subscription->created ) ) / DAY_IN_SECONDS ) ); |
|
468 | - $created = date_i18n( 'Y-m-d H:i:s' ); |
|
469 | - $expiration = date_i18n( 'Y-m-d 23:59:59', ( strtotime( $created ) + ( $diff_days * DAY_IN_SECONDS ) ) ); |
|
467 | + $diff_days = absint(((strtotime($subscription->expiration) - strtotime($subscription->created)) / DAY_IN_SECONDS)); |
|
468 | + $created = date_i18n('Y-m-d H:i:s'); |
|
469 | + $expiration = date_i18n('Y-m-d 23:59:59', (strtotime($created) + ($diff_days * DAY_IN_SECONDS))); |
|
470 | 470 | |
471 | 471 | // Retrieve pending subscription from database and update it's status to active and set proper profile ID |
472 | - $subscription->update( array( 'profile_id' => $subscription_id, 'status' => $status, 'created' => $created, 'expiration' => $expiration ) ); |
|
472 | + $subscription->update(array('profile_id' => $subscription_id, 'status' => $status, 'created' => $created, 'expiration' => $expiration)); |
|
473 | 473 | } |
474 | 474 | |
475 | -function wpinv_authorizenet_validate_checkout( $valid_data, $post ) { |
|
476 | - if ( !empty( $post['wpi-gateway'] ) && $post['wpi-gateway'] == 'authorizenet' ) { |
|
475 | +function wpinv_authorizenet_validate_checkout($valid_data, $post) { |
|
476 | + if (!empty($post['wpi-gateway']) && $post['wpi-gateway'] == 'authorizenet') { |
|
477 | 477 | $error = false; |
478 | 478 | |
479 | - if ( empty( $post['authorizenet']['cc_owner'] ) ) { |
|
479 | + if (empty($post['authorizenet']['cc_owner'])) { |
|
480 | 480 | $error = true; |
481 | - wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing')); |
|
481 | + wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing')); |
|
482 | 482 | } |
483 | - if ( empty( $post['authorizenet']['cc_number'] ) ) { |
|
483 | + if (empty($post['authorizenet']['cc_number'])) { |
|
484 | 484 | $error = true; |
485 | - wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing')); |
|
485 | + wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing')); |
|
486 | 486 | } |
487 | - if ( empty( $post['authorizenet']['cc_expire_month'] ) ) { |
|
487 | + if (empty($post['authorizenet']['cc_expire_month'])) { |
|
488 | 488 | $error = true; |
489 | - wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing')); |
|
489 | + wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing')); |
|
490 | 490 | } |
491 | - if ( empty( $post['authorizenet']['cc_expire_year'] ) ) { |
|
491 | + if (empty($post['authorizenet']['cc_expire_year'])) { |
|
492 | 492 | $error = true; |
493 | - wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing')); |
|
493 | + wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing')); |
|
494 | 494 | } |
495 | - if ( empty( $post['authorizenet']['cc_cvv2'] ) ) { |
|
495 | + if (empty($post['authorizenet']['cc_cvv2'])) { |
|
496 | 496 | $error = true; |
497 | - wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) ); |
|
497 | + wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing')); |
|
498 | 498 | } |
499 | 499 | |
500 | - if ( $error ) { |
|
500 | + if ($error) { |
|
501 | 501 | return; |
502 | 502 | } |
503 | 503 | |
504 | 504 | $invoice = wpinv_get_invoice_cart(); |
505 | 505 | |
506 | - if ( !empty( $invoice ) && $subscription_item = $invoice->get_recurring( true ) ) { |
|
507 | - $subscription_item = $invoice->get_recurring( true ); |
|
506 | + if (!empty($invoice) && $subscription_item = $invoice->get_recurring(true)) { |
|
507 | + $subscription_item = $invoice->get_recurring(true); |
|
508 | 508 | |
509 | 509 | $interval = $subscription_item->get_recurring_interval(); |
510 | 510 | $period = $subscription_item->get_recurring_period(); |
511 | 511 | |
512 | - if ( $period == 'D' && ( $interval < 7 || $interval > 365 ) ) { |
|
513 | - wpinv_set_error( 'authorizenet_subscription_error', __( 'Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing' ) ); |
|
512 | + if ($period == 'D' && ($interval < 7 || $interval > 365)) { |
|
513 | + wpinv_set_error('authorizenet_subscription_error', __('Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing')); |
|
514 | 514 | } |
515 | 515 | } |
516 | 516 | } |
517 | 517 | } |
518 | -add_action( 'wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2 ); |
|
518 | +add_action('wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2); |
|
519 | 519 | |
520 | -function wpinv_authorizenet_get_time_period( $subscription_interval, $subscription_period ) { |
|
521 | - $subscription_interval = absint( $subscription_interval ); |
|
520 | +function wpinv_authorizenet_get_time_period($subscription_interval, $subscription_period) { |
|
521 | + $subscription_interval = absint($subscription_interval); |
|
522 | 522 | |
523 | - switch( $subscription_period ) { |
|
523 | + switch ($subscription_period) { |
|
524 | 524 | case 'W': |
525 | 525 | case 'week': |
526 | 526 | case 'weeks': |
@@ -530,14 +530,14 @@ discard block |
||
530 | 530 | case 'M': |
531 | 531 | case 'month': |
532 | 532 | case 'months': |
533 | - if ( $subscription_interval > 12 ) { |
|
533 | + if ($subscription_interval > 12) { |
|
534 | 534 | $subscription_interval = 12; |
535 | 535 | } |
536 | 536 | |
537 | 537 | $interval = $subscription_interval; |
538 | 538 | $period = 'months'; |
539 | 539 | |
540 | - if ( !( $subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12 ) ) { |
|
540 | + if (!($subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12)) { |
|
541 | 541 | $interval = $subscription_interval * 30; |
542 | 542 | $period = 'days'; |
543 | 543 | } |
@@ -554,30 +554,30 @@ discard block |
||
554 | 554 | break; |
555 | 555 | } |
556 | 556 | |
557 | - return compact( 'interval', 'period' ); |
|
557 | + return compact('interval', 'period'); |
|
558 | 558 | } |
559 | 559 | |
560 | 560 | function wpinv_authorizenet_process_ipn() { |
561 | - if ( !( !empty( $_REQUEST['wpi-gateway'] ) && $_REQUEST['wpi-gateway'] == 'authorizenet' ) ) { |
|
561 | + if (!(!empty($_REQUEST['wpi-gateway']) && $_REQUEST['wpi-gateway'] == 'authorizenet')) { |
|
562 | 562 | return; |
563 | 563 | } |
564 | 564 | |
565 | - $subscription_id = !empty( $_POST['x_subscription_id'] ) ? intval( $_POST['x_subscription_id'] ) : false; |
|
565 | + $subscription_id = !empty($_POST['x_subscription_id']) ? intval($_POST['x_subscription_id']) : false; |
|
566 | 566 | |
567 | - if ( $subscription_id ) { |
|
568 | - $response_code = intval( $_POST['x_response_code'] ); |
|
569 | - $reason_code = intval( $_POST['x_response_reason_code'] ); |
|
567 | + if ($subscription_id) { |
|
568 | + $response_code = intval($_POST['x_response_code']); |
|
569 | + $reason_code = intval($_POST['x_response_reason_code']); |
|
570 | 570 | |
571 | - $subscription = new WPInv_Subscription( $subscription_id, true ); |
|
571 | + $subscription = new WPInv_Subscription($subscription_id, true); |
|
572 | 572 | |
573 | - if ( !$subscription->id ) { |
|
573 | + if (!$subscription->id) { |
|
574 | 574 | return; |
575 | 575 | } |
576 | 576 | |
577 | - if ( 1 == $response_code ) { |
|
577 | + if (1 == $response_code) { |
|
578 | 578 | // Approved |
579 | - $transaction_id = sanitize_text_field( $_POST['x_trans_id'] ); |
|
580 | - $renewal_amount = sanitize_text_field( $_POST['x_amount'] ); |
|
579 | + $transaction_id = sanitize_text_field($_POST['x_trans_id']); |
|
580 | + $renewal_amount = sanitize_text_field($_POST['x_amount']); |
|
581 | 581 | |
582 | 582 | $args = array( |
583 | 583 | 'amount' => $renewal_amount, |
@@ -585,63 +585,63 @@ discard block |
||
585 | 585 | 'gateway' => 'authorizenet' |
586 | 586 | ); |
587 | 587 | |
588 | - $subscription->add_payment( $args ); |
|
588 | + $subscription->add_payment($args); |
|
589 | 589 | $subscription->renew(); |
590 | 590 | |
591 | - do_action( 'wpinv_recurring_authorizenet_silent_post_payment', $subscription ); |
|
592 | - do_action( 'wpinv_authorizenet_renewal_payment', $subscription ); |
|
593 | - } else if ( 2 == $response_code ) { |
|
591 | + do_action('wpinv_recurring_authorizenet_silent_post_payment', $subscription); |
|
592 | + do_action('wpinv_authorizenet_renewal_payment', $subscription); |
|
593 | + } else if (2 == $response_code) { |
|
594 | 594 | // Declined |
595 | 595 | $subscription->failing(); |
596 | - do_action( 'wpinv_authorizenet_renewal_payment_failed', $subscription ); |
|
597 | - do_action( 'wpinv_authorizenet_renewal_error', $subscription ); |
|
598 | - } else if ( 3 == $response_code || 8 == $reason_code ) { |
|
596 | + do_action('wpinv_authorizenet_renewal_payment_failed', $subscription); |
|
597 | + do_action('wpinv_authorizenet_renewal_error', $subscription); |
|
598 | + } else if (3 == $response_code || 8 == $reason_code) { |
|
599 | 599 | // An expired card |
600 | 600 | $subscription->failing(); |
601 | - do_action( 'wpinv_authorizenet_renewal_payment_failed', $subscription ); |
|
602 | - do_action( 'wpinv_authorizenet_renewal_error', $subscription ); |
|
601 | + do_action('wpinv_authorizenet_renewal_payment_failed', $subscription); |
|
602 | + do_action('wpinv_authorizenet_renewal_error', $subscription); |
|
603 | 603 | } else { |
604 | 604 | // Other Error |
605 | - do_action( 'wpinv_authorizenet_renewal_payment_error', $subscription ); |
|
605 | + do_action('wpinv_authorizenet_renewal_payment_error', $subscription); |
|
606 | 606 | } |
607 | 607 | |
608 | 608 | exit; |
609 | 609 | } |
610 | 610 | } |
611 | -add_action( 'wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn' ); |
|
611 | +add_action('wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn'); |
|
612 | 612 | |
613 | 613 | /** |
614 | 614 | * Retrieve the subscription |
615 | 615 | */ |
616 | -function wpinv_get_authorizenet_subscription( $subscription_data = array(), $invoice_id ) { |
|
617 | - $parent_invoice_id = absint( $invoice_id ); |
|
616 | +function wpinv_get_authorizenet_subscription($subscription_data = array(), $invoice_id) { |
|
617 | + $parent_invoice_id = absint($invoice_id); |
|
618 | 618 | |
619 | - if ( empty( $subscription_data ) ) { |
|
619 | + if (empty($subscription_data)) { |
|
620 | 620 | return false; |
621 | 621 | } |
622 | 622 | |
623 | - if ( empty( $parent_invoice_id ) ) { |
|
623 | + if (empty($parent_invoice_id)) { |
|
624 | 624 | return false; |
625 | 625 | } |
626 | 626 | |
627 | - $invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
628 | - if ( empty( $invoice ) ) { |
|
627 | + $invoice = wpinv_get_invoice($parent_invoice_id); |
|
628 | + if (empty($invoice)) { |
|
629 | 629 | return false; |
630 | 630 | } |
631 | 631 | |
632 | - $subscriptionId = (array)$subscription_data->subscriptionId; |
|
633 | - $subscription_id = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $parent_invoice_id; |
|
632 | + $subscriptionId = (array) $subscription_data->subscriptionId; |
|
633 | + $subscription_id = !empty($subscriptionId[0]) ? $subscriptionId[0] : $parent_invoice_id; |
|
634 | 634 | |
635 | - $subscription = new WPInv_Subscription( $subscription_id, true ); |
|
635 | + $subscription = new WPInv_Subscription($subscription_id, true); |
|
636 | 636 | |
637 | - if ( ! $subscription || $subscription->id < 1 ) { |
|
637 | + if (!$subscription || $subscription->id < 1) { |
|
638 | 638 | $subs_db = new WPInv_Subscriptions_DB; |
639 | - $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $parent_invoice_id, 'number' => 1 ) ); |
|
640 | - $subscription = reset( $subs ); |
|
639 | + $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $parent_invoice_id, 'number' => 1)); |
|
640 | + $subscription = reset($subs); |
|
641 | 641 | |
642 | - if ( $subscription && $subscription->id > 0 ) { |
|
642 | + if ($subscription && $subscription->id > 0) { |
|
643 | 643 | // Update the profile ID so it is set for future renewals |
644 | - $subscription->update( array( 'profile_id' => sanitize_text_field( $subscription_id ) ) ); |
|
644 | + $subscription->update(array('profile_id' => sanitize_text_field($subscription_id))); |
|
645 | 645 | } else { |
646 | 646 | // No subscription found with a matching payment ID, bail |
647 | 647 | return false; |
@@ -652,67 +652,67 @@ discard block |
||
652 | 652 | } |
653 | 653 | |
654 | 654 | function wpinv_is_authorizenet_valid_for_use() { |
655 | - return in_array( wpinv_get_currency(), apply_filters( 'wpinv_authorizenet_supported_currencies', array( 'AUD', 'CAD', 'CHF', 'DKK', 'EUR', 'GBP', 'JPY', 'NOK', 'NZD', 'PLN', 'SEK', 'USD', 'ZAR' ) ) ); |
|
655 | + return in_array(wpinv_get_currency(), apply_filters('wpinv_authorizenet_supported_currencies', array('AUD', 'CAD', 'CHF', 'DKK', 'EUR', 'GBP', 'JPY', 'NOK', 'NZD', 'PLN', 'SEK', 'USD', 'ZAR'))); |
|
656 | 656 | } |
657 | -function wpinv_check_authorizenet_currency_support( $gateway_list ) { |
|
658 | - if ( isset( $gateway_list['authorizenet'] ) && ! wpinv_is_authorizenet_valid_for_use() ) { |
|
659 | - unset( $gateway_list['authorizenet'] ); |
|
657 | +function wpinv_check_authorizenet_currency_support($gateway_list) { |
|
658 | + if (isset($gateway_list['authorizenet']) && !wpinv_is_authorizenet_valid_for_use()) { |
|
659 | + unset($gateway_list['authorizenet']); |
|
660 | 660 | } |
661 | 661 | return $gateway_list; |
662 | 662 | } |
663 | -add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_authorizenet_currency_support', 10, 1 ); |
|
663 | +add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_authorizenet_currency_support', 10, 1); |
|
664 | 664 | |
665 | -function wpinv_authorizenet_link_transaction_id( $transaction_id, $invoice_id, $invoice ) { |
|
666 | - if ( $transaction_id == $invoice_id ) { |
|
665 | +function wpinv_authorizenet_link_transaction_id($transaction_id, $invoice_id, $invoice) { |
|
666 | + if ($transaction_id == $invoice_id) { |
|
667 | 667 | $link = $transaction_id; |
668 | 668 | } else { |
669 | - if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) { |
|
669 | + if (!empty($invoice) && !empty($invoice->mode)) { |
|
670 | 670 | $mode = $invoice->mode; |
671 | 671 | } else { |
672 | - $mode = wpinv_is_test_mode( 'authorizenet' ) ? 'test' : 'live'; |
|
672 | + $mode = wpinv_is_test_mode('authorizenet') ? 'test' : 'live'; |
|
673 | 673 | } |
674 | 674 | |
675 | 675 | $url = $mode == 'test' ? 'https://sandbox.authorize.net/' : 'https://authorize.net/'; |
676 | 676 | $url .= 'ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=' . $transaction_id; |
677 | 677 | |
678 | - $link = '<a href="' . esc_url( $url ) . '" target="_blank">' . $transaction_id . '</a>'; |
|
678 | + $link = '<a href="' . esc_url($url) . '" target="_blank">' . $transaction_id . '</a>'; |
|
679 | 679 | } |
680 | 680 | |
681 | - return apply_filters( 'wpinv_authorizenet_link_payment_details_transaction_id', $link, $transaction_id, $invoice ); |
|
681 | + return apply_filters('wpinv_authorizenet_link_payment_details_transaction_id', $link, $transaction_id, $invoice); |
|
682 | 682 | } |
683 | -add_filter( 'wpinv_payment_details_transaction_id-authorizenet', 'wpinv_authorizenet_link_transaction_id', 10, 3 ); |
|
683 | +add_filter('wpinv_payment_details_transaction_id-authorizenet', 'wpinv_authorizenet_link_transaction_id', 10, 3); |
|
684 | 684 | |
685 | -function wpinv_authorizenet_transaction_id_link( $transaction_id, $subscription ) { |
|
686 | - if ( ! empty( $transaction_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) { |
|
687 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
685 | +function wpinv_authorizenet_transaction_id_link($transaction_id, $subscription) { |
|
686 | + if (!empty($transaction_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) { |
|
687 | + $invoice = wpinv_get_invoice($invoice_id); |
|
688 | 688 | |
689 | - if ( ! empty( $invoice ) ) { |
|
690 | - return wpinv_authorizenet_link_transaction_id( $transaction_id, $invoice_id, $invoice ); |
|
689 | + if (!empty($invoice)) { |
|
690 | + return wpinv_authorizenet_link_transaction_id($transaction_id, $invoice_id, $invoice); |
|
691 | 691 | } |
692 | 692 | } |
693 | 693 | |
694 | 694 | return $transaction_id; |
695 | 695 | } |
696 | -add_filter( 'wpinv_subscription_transaction_link_authorizenet', 'wpinv_authorizenet_transaction_id_link', 10, 2 ); |
|
696 | +add_filter('wpinv_subscription_transaction_link_authorizenet', 'wpinv_authorizenet_transaction_id_link', 10, 2); |
|
697 | 697 | |
698 | -function wpinv_authorizenet_profile_id_link( $profile_id, $subscription ) { |
|
698 | +function wpinv_authorizenet_profile_id_link($profile_id, $subscription) { |
|
699 | 699 | $link = $profile_id; |
700 | 700 | |
701 | - if ( ! empty( $profile_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) { |
|
702 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
701 | + if (!empty($profile_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) { |
|
702 | + $invoice = wpinv_get_invoice($invoice_id); |
|
703 | 703 | |
704 | - if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) { |
|
704 | + if (!empty($invoice) && !empty($invoice->mode)) { |
|
705 | 705 | $mode = $invoice->mode; |
706 | 706 | } else { |
707 | - $mode = wpinv_is_test_mode( 'authorizenet' ) ? 'test' : 'live'; |
|
707 | + $mode = wpinv_is_test_mode('authorizenet') ? 'test' : 'live'; |
|
708 | 708 | } |
709 | 709 | |
710 | 710 | $url = $mode == 'test' ? 'https://sandbox.authorize.net/' : 'https://authorize.net/'; |
711 | 711 | $url .= 'ui/themes/sandbox/ARB/SubscriptionDetail.aspx?SubscrID=' . $profile_id; |
712 | 712 | |
713 | - $link = '<a href="' . esc_url( $url ) . '" target="_blank">' . $profile_id . '</a>'; |
|
713 | + $link = '<a href="' . esc_url($url) . '" target="_blank">' . $profile_id . '</a>'; |
|
714 | 714 | } |
715 | 715 | |
716 | - return apply_filters( 'wpinv_authorizenet_profile_id_link', $link, $profile_id, $subscription ); |
|
716 | + return apply_filters('wpinv_authorizenet_profile_id_link', $link, $profile_id, $subscription); |
|
717 | 717 | } |
718 | -add_filter( 'wpinv_subscription_profile_link_authorizenet', 'wpinv_authorizenet_profile_id_link', 10, 2 ); |
|
719 | 718 | \ No newline at end of file |
719 | +add_filter('wpinv_subscription_profile_link_authorizenet', 'wpinv_authorizenet_profile_id_link', 10, 2); |
|
720 | 720 | \ No newline at end of file |
@@ -1,6 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if ( ! defined( 'ABSPATH' ) ) { |
|
4 | + exit; |
|
5 | +} |
|
4 | 6 | |
5 | 7 | add_action( 'wpinv_bank_transfer_cc_form', '__return_false' ); |
6 | 8 |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -add_action( 'wpinv_bank_transfer_cc_form', '__return_false' ); |
|
5 | +add_action('wpinv_bank_transfer_cc_form', '__return_false'); |
|
6 | 6 | |
7 | -function wpinv_process_bank_transfer_payment( $purchase_data ) { |
|
8 | - if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
9 | - wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
7 | +function wpinv_process_bank_transfer_payment($purchase_data) { |
|
8 | + if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) { |
|
9 | + wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | // Collect payment data |
@@ -24,39 +24,39 @@ discard block |
||
24 | 24 | ); |
25 | 25 | |
26 | 26 | // Record the pending payment |
27 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
27 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
28 | 28 | |
29 | - if ( !empty( $invoice ) ) { |
|
30 | - wpinv_set_payment_transaction_id( $invoice->ID, $invoice->generate_key() ); |
|
31 | - wpinv_update_payment_status( $invoice, 'wpi-pending' ); |
|
29 | + if (!empty($invoice)) { |
|
30 | + wpinv_set_payment_transaction_id($invoice->ID, $invoice->generate_key()); |
|
31 | + wpinv_update_payment_status($invoice, 'wpi-pending'); |
|
32 | 32 | |
33 | 33 | // Empty the shopping cart |
34 | 34 | wpinv_empty_cart(); |
35 | 35 | |
36 | - do_action( 'wpinv_send_to_success_page', $invoice->ID, $payment_data ); |
|
36 | + do_action('wpinv_send_to_success_page', $invoice->ID, $payment_data); |
|
37 | 37 | |
38 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
38 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
39 | 39 | } else { |
40 | - wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a bank transfer payment. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice ); |
|
40 | + wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a bank transfer payment. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice); |
|
41 | 41 | // If errors are present, send the user back to the purchase page so they can be corrected |
42 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
42 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
43 | 43 | } |
44 | 44 | } |
45 | -add_action( 'wpinv_gateway_bank_transfer', 'wpinv_process_bank_transfer_payment' ); |
|
45 | +add_action('wpinv_gateway_bank_transfer', 'wpinv_process_bank_transfer_payment'); |
|
46 | 46 | |
47 | -function wpinv_show_bank_info( $invoice ) { |
|
48 | - if ( !empty( $invoice ) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending' ) { |
|
49 | - $bank_info = wpinv_get_bank_info( true ); |
|
47 | +function wpinv_show_bank_info($invoice) { |
|
48 | + if (!empty($invoice) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending') { |
|
49 | + $bank_info = wpinv_get_bank_info(true); |
|
50 | 50 | ?> |
51 | 51 | <div class="wpinv-bank-details"> |
52 | - <?php if ( $instructions = wpinv_get_bank_instructions() ) { ?> |
|
53 | - <div class="alert bg-info"><?php echo wpautop( wp_kses_post( $instructions ) ); ?></div> |
|
52 | + <?php if ($instructions = wpinv_get_bank_instructions()) { ?> |
|
53 | + <div class="alert bg-info"><?php echo wpautop(wp_kses_post($instructions)); ?></div> |
|
54 | 54 | <?php } ?> |
55 | - <?php if ( !empty( $bank_info ) ) { ?> |
|
56 | - <h3 class="wpinv-bank-t"><?php echo apply_filters( 'wpinv_receipt_bank_details_title', __( 'Our Bank Details', 'invoicing' ) ); ?></h3> |
|
55 | + <?php if (!empty($bank_info)) { ?> |
|
56 | + <h3 class="wpinv-bank-t"><?php echo apply_filters('wpinv_receipt_bank_details_title', __('Our Bank Details', 'invoicing')); ?></h3> |
|
57 | 57 | <table class="table table-bordered table-sm wpi-bank-details"> |
58 | - <?php foreach ( $bank_info as $key => $info ) { ?> |
|
59 | - <tr class="wpi-<?php echo sanitize_html_class( $key );?>"><th class="text-left"><?php echo $info['label'] ;?></th><td><?php echo $info['value'] ;?></td></tr> |
|
58 | + <?php foreach ($bank_info as $key => $info) { ?> |
|
59 | + <tr class="wpi-<?php echo sanitize_html_class($key); ?>"><th class="text-left"><?php echo $info['label']; ?></th><td><?php echo $info['value']; ?></td></tr> |
|
60 | 60 | <?php } ?> |
61 | 61 | </table> |
62 | 62 | <?php } ?> |
@@ -64,37 +64,37 @@ discard block |
||
64 | 64 | <?php |
65 | 65 | } |
66 | 66 | } |
67 | -add_action( 'wpinv_before_receipt_details', 'wpinv_show_bank_info', 10, 1 ); |
|
67 | +add_action('wpinv_before_receipt_details', 'wpinv_show_bank_info', 10, 1); |
|
68 | 68 | |
69 | -function wpinv_invoice_print_bank_info( $invoice ) { |
|
70 | - if ( !empty( $invoice ) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending' ) { |
|
69 | +function wpinv_invoice_print_bank_info($invoice) { |
|
70 | + if (!empty($invoice) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending') { |
|
71 | 71 | ?> |
72 | 72 | <div class="row wpinv-bank-info"> |
73 | - <?php echo wpinv_show_bank_info( $invoice ); ?> |
|
73 | + <?php echo wpinv_show_bank_info($invoice); ?> |
|
74 | 74 | </div> |
75 | 75 | <?php |
76 | 76 | } |
77 | 77 | } |
78 | -add_action( 'wpinv_invoice_print_after_top_content', 'wpinv_invoice_print_bank_info', 10, 1 ); |
|
78 | +add_action('wpinv_invoice_print_after_top_content', 'wpinv_invoice_print_bank_info', 10, 1); |
|
79 | 79 | |
80 | -function wpinv_bank_transfer_send_notification( $invoice_ID, $payment_data = array() ) { |
|
81 | - if ( !empty( $payment_data['gateway'] ) && $payment_data['gateway'] == 'bank_transfer' ) { |
|
80 | +function wpinv_bank_transfer_send_notification($invoice_ID, $payment_data = array()) { |
|
81 | + if (!empty($payment_data['gateway']) && $payment_data['gateway'] == 'bank_transfer') { |
|
82 | 82 | // Send invoice to user. |
83 | - wpinv_user_invoice_notification( $invoice_ID ); |
|
83 | + wpinv_user_invoice_notification($invoice_ID); |
|
84 | 84 | |
85 | 85 | // Send invoice to admin. |
86 | - wpinv_new_invoice_notification( $invoice_ID ); |
|
86 | + wpinv_new_invoice_notification($invoice_ID); |
|
87 | 87 | } |
88 | 88 | } |
89 | -add_action( 'wpinv_send_to_success_page', 'wpinv_bank_transfer_send_notification', 10, 2 ); |
|
89 | +add_action('wpinv_send_to_success_page', 'wpinv_bank_transfer_send_notification', 10, 2); |
|
90 | 90 | |
91 | -function wpinv_invoice_email_bank_info( $invoice, $email_type = '', $sent_to_admin = false ) { |
|
92 | - if ( !empty( $invoice ) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending' ) { |
|
91 | +function wpinv_invoice_email_bank_info($invoice, $email_type = '', $sent_to_admin = false) { |
|
92 | + if (!empty($invoice) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending') { |
|
93 | 93 | ?> |
94 | 94 | <div class="wpi-email-row"> |
95 | - <?php echo wpinv_show_bank_info( $invoice ); ?> |
|
95 | + <?php echo wpinv_show_bank_info($invoice); ?> |
|
96 | 96 | </div> |
97 | 97 | <?php |
98 | 98 | } |
99 | 99 | } |
100 | -add_action( 'wpinv_email_invoice_details', 'wpinv_invoice_email_bank_info', 9, 3 ); |
|
101 | 100 | \ No newline at end of file |
101 | +add_action('wpinv_email_invoice_details', 'wpinv_invoice_email_bank_info', 9, 3); |
|
102 | 102 | \ No newline at end of file |
@@ -1,6 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if ( ! defined( 'ABSPATH' ) ) { |
|
4 | + exit; |
|
5 | +} |
|
4 | 6 | |
5 | 7 | add_action( 'wpinv_paypal_cc_form', '__return_false' ); |
6 | 8 | add_filter( 'wpinv_paypal_support_subscription', '__return_true' ); |
@@ -307,8 +309,9 @@ discard block |
||
307 | 309 | } |
308 | 310 | |
309 | 311 | // Check if $post_data_array has been populated |
310 | - if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) |
|
311 | - return; |
|
312 | + if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) { |
|
313 | + return; |
|
314 | + } |
|
312 | 315 | |
313 | 316 | $defaults = array( |
314 | 317 | 'txn_type' => '', |
@@ -219,262 +219,262 @@ discard block |
||
219 | 219 | add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 ); |
220 | 220 | |
221 | 221 | function wpinv_process_paypal_ipn() { |
222 | - // Check the request method is POST |
|
223 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
224 | - return; |
|
225 | - } |
|
226 | - |
|
227 | - // Set initial post data to empty string |
|
228 | - $post_data = ''; |
|
229 | - |
|
230 | - // Fallback just in case post_max_size is lower than needed |
|
231 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
232 | - $post_data = file_get_contents( 'php://input' ); |
|
233 | - } else { |
|
234 | - // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
|
235 | - ini_set( 'post_max_size', '12M' ); |
|
236 | - } |
|
237 | - // Start the encoded data collection with notification command |
|
238 | - $encoded_data = 'cmd=_notify-validate'; |
|
239 | - |
|
240 | - // Get current arg separator |
|
241 | - $arg_separator = wpinv_get_php_arg_separator_output(); |
|
242 | - |
|
243 | - // Verify there is a post_data |
|
244 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
245 | - // Append the data |
|
246 | - $encoded_data .= $arg_separator.$post_data; |
|
247 | - } else { |
|
248 | - // Check if POST is empty |
|
249 | - if ( empty( $_POST ) ) { |
|
250 | - // Nothing to do |
|
251 | - return; |
|
252 | - } else { |
|
253 | - // Loop through each POST |
|
254 | - foreach ( $_POST as $key => $value ) { |
|
255 | - // Encode the value and append the data |
|
256 | - $encoded_data .= $arg_separator."$key=" . urlencode( $value ); |
|
257 | - } |
|
258 | - } |
|
259 | - } |
|
260 | - |
|
261 | - // Convert collected post data to an array |
|
262 | - wp_parse_str( $encoded_data, $encoded_data_array ); |
|
263 | - |
|
264 | - foreach ( $encoded_data_array as $key => $value ) { |
|
265 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
266 | - $new_key = str_replace( '&', '&', $key ); |
|
267 | - $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
268 | - |
|
269 | - unset( $encoded_data_array[ $key ] ); |
|
270 | - $encoded_data_array[ $new_key ] = $value; |
|
271 | - } |
|
272 | - } |
|
273 | - |
|
274 | - // Get the PayPal redirect uri |
|
275 | - $paypal_redirect = wpinv_get_paypal_redirect( true ); |
|
276 | - |
|
277 | - if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
278 | - // Validate the IPN |
|
279 | - |
|
280 | - $remote_post_vars = array( |
|
281 | - 'method' => 'POST', |
|
282 | - 'timeout' => 45, |
|
283 | - 'redirection' => 5, |
|
284 | - 'httpversion' => '1.1', |
|
285 | - 'blocking' => true, |
|
286 | - 'headers' => array( |
|
287 | - 'host' => 'www.paypal.com', |
|
288 | - 'connection' => 'close', |
|
289 | - 'content-type' => 'application/x-www-form-urlencoded', |
|
290 | - 'post' => '/cgi-bin/webscr HTTP/1.1', |
|
291 | - |
|
292 | - ), |
|
293 | - 'sslverify' => false, |
|
294 | - 'body' => $encoded_data_array |
|
295 | - ); |
|
296 | - |
|
297 | - // Get response |
|
298 | - $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars ); |
|
299 | - |
|
300 | - if ( is_wp_error( $api_response ) ) { |
|
301 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
302 | - return; // Something went wrong |
|
303 | - } |
|
304 | - |
|
305 | - if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
306 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
307 | - return; // Response not okay |
|
308 | - } |
|
309 | - } |
|
310 | - |
|
311 | - // Check if $post_data_array has been populated |
|
312 | - if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) |
|
313 | - return; |
|
314 | - |
|
315 | - $defaults = array( |
|
316 | - 'txn_type' => '', |
|
317 | - 'payment_status' => '' |
|
318 | - ); |
|
319 | - |
|
320 | - $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
321 | - |
|
322 | - $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
222 | + // Check the request method is POST |
|
223 | + if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
224 | + return; |
|
225 | + } |
|
226 | + |
|
227 | + // Set initial post data to empty string |
|
228 | + $post_data = ''; |
|
229 | + |
|
230 | + // Fallback just in case post_max_size is lower than needed |
|
231 | + if ( ini_get( 'allow_url_fopen' ) ) { |
|
232 | + $post_data = file_get_contents( 'php://input' ); |
|
233 | + } else { |
|
234 | + // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
|
235 | + ini_set( 'post_max_size', '12M' ); |
|
236 | + } |
|
237 | + // Start the encoded data collection with notification command |
|
238 | + $encoded_data = 'cmd=_notify-validate'; |
|
239 | + |
|
240 | + // Get current arg separator |
|
241 | + $arg_separator = wpinv_get_php_arg_separator_output(); |
|
242 | + |
|
243 | + // Verify there is a post_data |
|
244 | + if ( $post_data || strlen( $post_data ) > 0 ) { |
|
245 | + // Append the data |
|
246 | + $encoded_data .= $arg_separator.$post_data; |
|
247 | + } else { |
|
248 | + // Check if POST is empty |
|
249 | + if ( empty( $_POST ) ) { |
|
250 | + // Nothing to do |
|
251 | + return; |
|
252 | + } else { |
|
253 | + // Loop through each POST |
|
254 | + foreach ( $_POST as $key => $value ) { |
|
255 | + // Encode the value and append the data |
|
256 | + $encoded_data .= $arg_separator."$key=" . urlencode( $value ); |
|
257 | + } |
|
258 | + } |
|
259 | + } |
|
260 | + |
|
261 | + // Convert collected post data to an array |
|
262 | + wp_parse_str( $encoded_data, $encoded_data_array ); |
|
263 | + |
|
264 | + foreach ( $encoded_data_array as $key => $value ) { |
|
265 | + if ( false !== strpos( $key, 'amp;' ) ) { |
|
266 | + $new_key = str_replace( '&', '&', $key ); |
|
267 | + $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
268 | + |
|
269 | + unset( $encoded_data_array[ $key ] ); |
|
270 | + $encoded_data_array[ $new_key ] = $value; |
|
271 | + } |
|
272 | + } |
|
273 | + |
|
274 | + // Get the PayPal redirect uri |
|
275 | + $paypal_redirect = wpinv_get_paypal_redirect( true ); |
|
276 | + |
|
277 | + if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
278 | + // Validate the IPN |
|
279 | + |
|
280 | + $remote_post_vars = array( |
|
281 | + 'method' => 'POST', |
|
282 | + 'timeout' => 45, |
|
283 | + 'redirection' => 5, |
|
284 | + 'httpversion' => '1.1', |
|
285 | + 'blocking' => true, |
|
286 | + 'headers' => array( |
|
287 | + 'host' => 'www.paypal.com', |
|
288 | + 'connection' => 'close', |
|
289 | + 'content-type' => 'application/x-www-form-urlencoded', |
|
290 | + 'post' => '/cgi-bin/webscr HTTP/1.1', |
|
291 | + |
|
292 | + ), |
|
293 | + 'sslverify' => false, |
|
294 | + 'body' => $encoded_data_array |
|
295 | + ); |
|
296 | + |
|
297 | + // Get response |
|
298 | + $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars ); |
|
299 | + |
|
300 | + if ( is_wp_error( $api_response ) ) { |
|
301 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
302 | + return; // Something went wrong |
|
303 | + } |
|
304 | + |
|
305 | + if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
306 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
307 | + return; // Response not okay |
|
308 | + } |
|
309 | + } |
|
310 | + |
|
311 | + // Check if $post_data_array has been populated |
|
312 | + if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) |
|
313 | + return; |
|
314 | + |
|
315 | + $defaults = array( |
|
316 | + 'txn_type' => '', |
|
317 | + 'payment_status' => '' |
|
318 | + ); |
|
319 | + |
|
320 | + $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
321 | + |
|
322 | + $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
323 | 323 | |
324 | - wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ ); |
|
325 | - wpinv_error_log( $encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__ ); |
|
326 | - |
|
327 | - if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
328 | - // Allow PayPal IPN types to be processed separately |
|
329 | - do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id ); |
|
330 | - } else { |
|
331 | - // Fallback to web accept just in case the txn_type isn't present |
|
332 | - do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id ); |
|
333 | - } |
|
334 | - exit; |
|
324 | + wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ ); |
|
325 | + wpinv_error_log( $encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__ ); |
|
326 | + |
|
327 | + if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
328 | + // Allow PayPal IPN types to be processed separately |
|
329 | + do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id ); |
|
330 | + } else { |
|
331 | + // Fallback to web accept just in case the txn_type isn't present |
|
332 | + do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id ); |
|
333 | + } |
|
334 | + exit; |
|
335 | 335 | } |
336 | 336 | add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' ); |
337 | 337 | |
338 | 338 | function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) { |
339 | - if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
340 | - return; |
|
341 | - } |
|
342 | - |
|
343 | - if( empty( $invoice_id ) ) { |
|
344 | - return; |
|
345 | - } |
|
346 | - |
|
347 | - // Collect payment details |
|
348 | - $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
349 | - $paypal_amount = $data['mc_gross']; |
|
350 | - $payment_status = strtolower( $data['payment_status'] ); |
|
351 | - $currency_code = strtolower( $data['mc_currency'] ); |
|
352 | - $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
353 | - $payment_meta = wpinv_get_invoice_meta( $invoice_id ); |
|
354 | - |
|
355 | - if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) { |
|
356 | - return; // this isn't a PayPal standard IPN |
|
357 | - } |
|
358 | - |
|
359 | - // Verify payment recipient |
|
360 | - if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) { |
|
361 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
362 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
363 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ), '', '', true ); |
|
364 | - return; |
|
365 | - } |
|
366 | - |
|
367 | - // Verify payment currency |
|
368 | - if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
369 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
370 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
371 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
372 | - return; |
|
373 | - } |
|
374 | - |
|
375 | - if ( !wpinv_get_payment_user_email( $invoice_id ) ) { |
|
376 | - // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal |
|
377 | - // No email associated with purchase, so store from PayPal |
|
378 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] ); |
|
379 | - |
|
380 | - // Setup and store the customer's details |
|
381 | - $user_info = array( |
|
382 | - 'user_id' => '-1', |
|
383 | - 'email' => sanitize_text_field( $data['payer_email'] ), |
|
384 | - 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
385 | - 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
386 | - 'discount' => '', |
|
387 | - ); |
|
388 | - $user_info['address'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
389 | - $user_info['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
390 | - $user_info['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
391 | - $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
392 | - $user_info['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
393 | - |
|
394 | - $payment_meta['user_info'] = $user_info; |
|
395 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta ); |
|
396 | - } |
|
397 | - |
|
398 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
399 | - // Process a refund |
|
400 | - wpinv_process_paypal_refund( $data, $invoice_id ); |
|
401 | - } else { |
|
402 | - if ( get_post_status( $invoice_id ) == 'publish' ) { |
|
403 | - return; // Only paid payments once |
|
404 | - } |
|
405 | - |
|
406 | - // Retrieve the total purchase amount (before PayPal) |
|
407 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
408 | - |
|
409 | - if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
410 | - // The prices don't match |
|
411 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
412 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
413 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
414 | - return; |
|
415 | - } |
|
416 | - if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) { |
|
417 | - // Purchase keys don't match |
|
418 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
419 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
420 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
421 | - return; |
|
422 | - } |
|
423 | - |
|
424 | - if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) { |
|
425 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ), '', '', true ); |
|
426 | - wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] ); |
|
427 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
428 | - } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
429 | - // Look for possible pending reasons, such as an echeck |
|
430 | - $note = ''; |
|
431 | - |
|
432 | - switch( strtolower( $data['pending_reason'] ) ) { |
|
433 | - case 'echeck' : |
|
434 | - $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' ); |
|
435 | - break; |
|
339 | + if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
340 | + return; |
|
341 | + } |
|
342 | + |
|
343 | + if( empty( $invoice_id ) ) { |
|
344 | + return; |
|
345 | + } |
|
346 | + |
|
347 | + // Collect payment details |
|
348 | + $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
349 | + $paypal_amount = $data['mc_gross']; |
|
350 | + $payment_status = strtolower( $data['payment_status'] ); |
|
351 | + $currency_code = strtolower( $data['mc_currency'] ); |
|
352 | + $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
353 | + $payment_meta = wpinv_get_invoice_meta( $invoice_id ); |
|
354 | + |
|
355 | + if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) { |
|
356 | + return; // this isn't a PayPal standard IPN |
|
357 | + } |
|
358 | + |
|
359 | + // Verify payment recipient |
|
360 | + if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) { |
|
361 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
362 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
363 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ), '', '', true ); |
|
364 | + return; |
|
365 | + } |
|
366 | + |
|
367 | + // Verify payment currency |
|
368 | + if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
369 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
370 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
371 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
372 | + return; |
|
373 | + } |
|
374 | + |
|
375 | + if ( !wpinv_get_payment_user_email( $invoice_id ) ) { |
|
376 | + // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal |
|
377 | + // No email associated with purchase, so store from PayPal |
|
378 | + wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] ); |
|
379 | + |
|
380 | + // Setup and store the customer's details |
|
381 | + $user_info = array( |
|
382 | + 'user_id' => '-1', |
|
383 | + 'email' => sanitize_text_field( $data['payer_email'] ), |
|
384 | + 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
385 | + 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
386 | + 'discount' => '', |
|
387 | + ); |
|
388 | + $user_info['address'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
389 | + $user_info['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
390 | + $user_info['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
391 | + $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
392 | + $user_info['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
393 | + |
|
394 | + $payment_meta['user_info'] = $user_info; |
|
395 | + wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta ); |
|
396 | + } |
|
397 | + |
|
398 | + if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
399 | + // Process a refund |
|
400 | + wpinv_process_paypal_refund( $data, $invoice_id ); |
|
401 | + } else { |
|
402 | + if ( get_post_status( $invoice_id ) == 'publish' ) { |
|
403 | + return; // Only paid payments once |
|
404 | + } |
|
405 | + |
|
406 | + // Retrieve the total purchase amount (before PayPal) |
|
407 | + $payment_amount = wpinv_payment_total( $invoice_id ); |
|
408 | + |
|
409 | + if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
410 | + // The prices don't match |
|
411 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
412 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
413 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
414 | + return; |
|
415 | + } |
|
416 | + if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) { |
|
417 | + // Purchase keys don't match |
|
418 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
419 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
420 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
421 | + return; |
|
422 | + } |
|
423 | + |
|
424 | + if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) { |
|
425 | + wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ), '', '', true ); |
|
426 | + wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] ); |
|
427 | + wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
428 | + } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
429 | + // Look for possible pending reasons, such as an echeck |
|
430 | + $note = ''; |
|
431 | + |
|
432 | + switch( strtolower( $data['pending_reason'] ) ) { |
|
433 | + case 'echeck' : |
|
434 | + $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' ); |
|
435 | + break; |
|
436 | 436 | |
437 | 437 | case 'address' : |
438 | - $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' ); |
|
439 | - break; |
|
438 | + $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' ); |
|
439 | + break; |
|
440 | 440 | |
441 | 441 | case 'intl' : |
442 | - $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' ); |
|
443 | - break; |
|
442 | + $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' ); |
|
443 | + break; |
|
444 | 444 | |
445 | 445 | case 'multi-currency' : |
446 | - $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' ); |
|
447 | - break; |
|
446 | + $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' ); |
|
447 | + break; |
|
448 | 448 | |
449 | 449 | case 'paymentreview' : |
450 | 450 | case 'regulatory_review' : |
451 | - $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' ); |
|
452 | - break; |
|
451 | + $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' ); |
|
452 | + break; |
|
453 | 453 | |
454 | 454 | case 'unilateral' : |
455 | - $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' ); |
|
456 | - break; |
|
455 | + $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' ); |
|
456 | + break; |
|
457 | 457 | |
458 | 458 | case 'upgrade' : |
459 | - $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' ); |
|
460 | - break; |
|
459 | + $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' ); |
|
460 | + break; |
|
461 | 461 | |
462 | 462 | case 'verify' : |
463 | - $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' ); |
|
464 | - break; |
|
465 | - |
|
466 | - case 'other' : |
|
467 | - $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' ); |
|
468 | - break; |
|
469 | - } |
|
470 | - |
|
471 | - if ( ! empty( $note ) ) { |
|
472 | - wpinv_insert_payment_note( $invoice_id, $note, '', '', true ); |
|
473 | - } |
|
474 | - } else { |
|
475 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ), '', '', true ); |
|
476 | - } |
|
477 | - } |
|
463 | + $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' ); |
|
464 | + break; |
|
465 | + |
|
466 | + case 'other' : |
|
467 | + $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' ); |
|
468 | + break; |
|
469 | + } |
|
470 | + |
|
471 | + if ( ! empty( $note ) ) { |
|
472 | + wpinv_insert_payment_note( $invoice_id, $note, '', '', true ); |
|
473 | + } |
|
474 | + } else { |
|
475 | + wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ), '', '', true ); |
|
476 | + } |
|
477 | + } |
|
478 | 478 | } |
479 | 479 | add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 ); |
480 | 480 | |
@@ -668,34 +668,34 @@ discard block |
||
668 | 668 | } |
669 | 669 | |
670 | 670 | function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) { |
671 | - // Collect payment details |
|
671 | + // Collect payment details |
|
672 | 672 | |
673 | - if( empty( $invoice_id ) ) { |
|
674 | - return; |
|
675 | - } |
|
673 | + if( empty( $invoice_id ) ) { |
|
674 | + return; |
|
675 | + } |
|
676 | 676 | |
677 | - if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) { |
|
678 | - return; // Only refund payments once |
|
679 | - } |
|
677 | + if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) { |
|
678 | + return; // Only refund payments once |
|
679 | + } |
|
680 | 680 | |
681 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
682 | - $refund_amount = $data['mc_gross'] * -1; |
|
681 | + $payment_amount = wpinv_payment_total( $invoice_id ); |
|
682 | + $refund_amount = $data['mc_gross'] * -1; |
|
683 | 683 | |
684 | - do_action( 'wpinv_paypal_refund_request', $data, $invoice_id ); |
|
684 | + do_action( 'wpinv_paypal_refund_request', $data, $invoice_id ); |
|
685 | 685 | |
686 | - if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
687 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing' ), (float)$refund_amount . ' '. $data['mc_currency'], $data['parent_txn_id'], $data['reason_code'] ), '', '', true ); |
|
686 | + if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
687 | + wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing' ), (float)$refund_amount . ' '. $data['mc_currency'], $data['parent_txn_id'], $data['reason_code'] ), '', '', true ); |
|
688 | 688 | |
689 | - do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount ); |
|
689 | + do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount ); |
|
690 | 690 | |
691 | - return; // This is a partial refund |
|
692 | - } |
|
691 | + return; // This is a partial refund |
|
692 | + } |
|
693 | 693 | |
694 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true ); |
|
695 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true ); |
|
696 | - wpinv_update_payment_status( $invoice_id, 'wpi-refunded' ); |
|
694 | + wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true ); |
|
695 | + wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true ); |
|
696 | + wpinv_update_payment_status( $invoice_id, 'wpi-refunded' ); |
|
697 | 697 | |
698 | - do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id ); |
|
698 | + do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id ); |
|
699 | 699 | } |
700 | 700 | |
701 | 701 | function wpinv_get_paypal_redirect( $ssl_check = false ) { |
@@ -1,15 +1,15 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -add_action( 'wpinv_paypal_cc_form', '__return_false' ); |
|
6 | -add_filter( 'wpinv_paypal_support_subscription', '__return_true' ); |
|
5 | +add_action('wpinv_paypal_cc_form', '__return_false'); |
|
6 | +add_filter('wpinv_paypal_support_subscription', '__return_true'); |
|
7 | 7 | |
8 | 8 | |
9 | -function wpinv_paypal_gateway_description_sandbox_notice( $description, $gateway ) { |
|
10 | - if ( 'paypal' == $gateway && wpinv_is_test_mode( 'paypal' ) ) { |
|
9 | +function wpinv_paypal_gateway_description_sandbox_notice($description, $gateway) { |
|
10 | + if ('paypal' == $gateway && wpinv_is_test_mode('paypal')) { |
|
11 | 11 | $description .= '<br>' . sprintf( |
12 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
12 | + __('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing'), |
|
13 | 13 | '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
14 | 14 | '</a>' |
15 | 15 | ); |
@@ -17,11 +17,11 @@ discard block |
||
17 | 17 | return $description; |
18 | 18 | |
19 | 19 | } |
20 | -add_filter( 'wpinv_gateway_description', 'wpinv_paypal_gateway_description_sandbox_notice', 10, 2 ); |
|
20 | +add_filter('wpinv_gateway_description', 'wpinv_paypal_gateway_description_sandbox_notice', 10, 2); |
|
21 | 21 | |
22 | -function wpinv_process_paypal_payment( $purchase_data ) { |
|
23 | - if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
24 | - wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
22 | +function wpinv_process_paypal_payment($purchase_data) { |
|
23 | + if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) { |
|
24 | + wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | // Collect payment data |
@@ -39,24 +39,24 @@ discard block |
||
39 | 39 | ); |
40 | 40 | |
41 | 41 | // Record the pending payment |
42 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
42 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
43 | 43 | |
44 | 44 | // Check payment |
45 | - if ( ! $invoice ) { |
|
45 | + if (!$invoice) { |
|
46 | 46 | // Record the error |
47 | - wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice ); |
|
47 | + wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice); |
|
48 | 48 | // Problems? send back |
49 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
49 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
50 | 50 | } else { |
51 | 51 | // Only send to PayPal if the pending payment is created successfully |
52 | - $listener_url = wpinv_get_ipn_url( 'paypal' ); |
|
52 | + $listener_url = wpinv_get_ipn_url('paypal'); |
|
53 | 53 | |
54 | 54 | // Get the success url |
55 | - $return_url = add_query_arg( array( |
|
55 | + $return_url = add_query_arg(array( |
|
56 | 56 | 'payment-confirm' => 'paypal', |
57 | 57 | 'invoice-id' => $invoice->ID, |
58 | 58 | 'utm_nooverride' => 1 |
59 | - ), get_permalink( wpinv_get_option( 'success_page', false ) ) ); |
|
59 | + ), get_permalink(wpinv_get_option('success_page', false))); |
|
60 | 60 | |
61 | 61 | // Get the PayPal redirect uri |
62 | 62 | $paypal_redirect = wpinv_get_paypal_redirect(); |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | $paypal_args = array( |
66 | 66 | 'cmd' => '_cart', |
67 | 67 | 'upload' => '1', |
68 | - 'business' => wpinv_get_option( 'paypal_email', false ), |
|
68 | + 'business' => wpinv_get_option('paypal_email', false), |
|
69 | 69 | 'email' => $invoice->get_email(), |
70 | 70 | 'first_name' => $invoice->get_first_name(), |
71 | 71 | 'last_name' => $invoice->get_last_name(), |
@@ -74,88 +74,88 @@ discard block |
||
74 | 74 | 'shipping' => '0', |
75 | 75 | 'no_note' => '1', |
76 | 76 | 'currency_code' => $invoice->get_currency(), |
77 | - 'charset' => get_bloginfo( 'charset' ), |
|
77 | + 'charset' => get_bloginfo('charset'), |
|
78 | 78 | 'custom' => $invoice->ID, |
79 | 79 | 'rm' => is_ssl() ? 2 : 1, |
80 | - 'return' => esc_url_raw( $return_url ), |
|
80 | + 'return' => esc_url_raw($return_url), |
|
81 | 81 | 'cancel_return' => $invoice->get_checkout_payment_url(), |
82 | 82 | 'notify_url' => $listener_url, |
83 | - 'cbt' => get_bloginfo( 'name' ), |
|
83 | + 'cbt' => get_bloginfo('name'), |
|
84 | 84 | 'bn' => 'WPInvoicing_SP', |
85 | 85 | ); |
86 | 86 | |
87 | 87 | // Add cart items |
88 | 88 | $i = 1; |
89 | - if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) { |
|
90 | - foreach ( $purchase_data['cart_details'] as $item ) { |
|
89 | + if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) { |
|
90 | + foreach ($purchase_data['cart_details'] as $item) { |
|
91 | 91 | $item['quantity'] = $item['quantity'] > 0 ? $item['quantity'] : 1; |
92 | - $item_amount = wpinv_sanitize_amount( $item['subtotal'] / $item['quantity'], 2 ); |
|
92 | + $item_amount = wpinv_sanitize_amount($item['subtotal'] / $item['quantity'], 2); |
|
93 | 93 | |
94 | - if ( $item_amount <= 0 ) { |
|
94 | + if ($item_amount <= 0) { |
|
95 | 95 | $item_amount = 0; |
96 | 96 | } |
97 | 97 | |
98 | - $paypal_args['item_number_' . $i ] = $item['id']; |
|
99 | - $paypal_args['item_name_' . $i ] = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( $item ), ENT_COMPAT, 'UTF-8' ) ); |
|
100 | - $paypal_args['quantity_' . $i ] = $item['quantity']; |
|
101 | - $paypal_args['amount_' . $i ] = $item_amount; |
|
102 | - $paypal_args['discount_amount_' . $i ] = wpinv_sanitize_amount( $item['discount'], 2 ); |
|
98 | + $paypal_args['item_number_' . $i] = $item['id']; |
|
99 | + $paypal_args['item_name_' . $i] = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name($item), ENT_COMPAT, 'UTF-8')); |
|
100 | + $paypal_args['quantity_' . $i] = $item['quantity']; |
|
101 | + $paypal_args['amount_' . $i] = $item_amount; |
|
102 | + $paypal_args['discount_amount_' . $i] = wpinv_sanitize_amount($item['discount'], 2); |
|
103 | 103 | |
104 | 104 | $i++; |
105 | 105 | } |
106 | 106 | } |
107 | 107 | |
108 | 108 | // Add taxes to the cart |
109 | - if ( wpinv_use_taxes() && $invoice->is_taxable() ) { |
|
110 | - $paypal_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_tax(), 2 ); |
|
109 | + if (wpinv_use_taxes() && $invoice->is_taxable()) { |
|
110 | + $paypal_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_tax(), 2); |
|
111 | 111 | } |
112 | 112 | |
113 | - $paypal_args = apply_filters( 'wpinv_paypal_args', $paypal_args, $purchase_data, $invoice ); |
|
113 | + $paypal_args = apply_filters('wpinv_paypal_args', $paypal_args, $purchase_data, $invoice); |
|
114 | 114 | |
115 | 115 | // Build query |
116 | - $paypal_redirect .= http_build_query( $paypal_args ); |
|
116 | + $paypal_redirect .= http_build_query($paypal_args); |
|
117 | 117 | |
118 | 118 | // Fix for some sites that encode the entities |
119 | - $paypal_redirect = str_replace( '&', '&', $paypal_redirect ); |
|
119 | + $paypal_redirect = str_replace('&', '&', $paypal_redirect); |
|
120 | 120 | |
121 | 121 | // Get rid of cart contents |
122 | 122 | wpinv_empty_cart(); |
123 | 123 | |
124 | 124 | // Redirect to PayPal |
125 | - wp_redirect( $paypal_redirect ); |
|
125 | + wp_redirect($paypal_redirect); |
|
126 | 126 | exit; |
127 | 127 | } |
128 | 128 | } |
129 | -add_action( 'wpinv_gateway_paypal', 'wpinv_process_paypal_payment' ); |
|
129 | +add_action('wpinv_gateway_paypal', 'wpinv_process_paypal_payment'); |
|
130 | 130 | |
131 | -function wpinv_get_paypal_recurring_args( $paypal_args, $purchase_data, $invoice ) { |
|
132 | - if ( $invoice->is_recurring() && $subscription = wpinv_get_subscription( $invoice->ID ) ) { |
|
131 | +function wpinv_get_paypal_recurring_args($paypal_args, $purchase_data, $invoice) { |
|
132 | + if ($invoice->is_recurring() && $subscription = wpinv_get_subscription($invoice->ID)) { |
|
133 | 133 | |
134 | - $period = strtoupper( substr( $subscription->period, 0, 1) ); |
|
134 | + $period = strtoupper(substr($subscription->period, 0, 1)); |
|
135 | 135 | $interval = $subscription->frequency; |
136 | 136 | $bill_times = (int) $subscription->bill_times; |
137 | 137 | |
138 | - $initial_amount = wpinv_sanitize_amount( $invoice->get_total(), 2 ); |
|
139 | - $recurring_amount = wpinv_sanitize_amount( $invoice->get_recurring_details( 'total' ), 2 ); |
|
138 | + $initial_amount = wpinv_sanitize_amount($invoice->get_total(), 2); |
|
139 | + $recurring_amount = wpinv_sanitize_amount($invoice->get_recurring_details('total'), 2); |
|
140 | 140 | |
141 | 141 | $paypal_args['cmd'] = '_xclick-subscriptions'; |
142 | 142 | $paypal_args['sra'] = '1'; |
143 | 143 | $paypal_args['src'] = '1'; |
144 | 144 | |
145 | 145 | // Set item description |
146 | - $item_name = wpinv_get_cart_item_name( array( 'id' => $subscription->product_id ) ); |
|
147 | - $paypal_args['item_name'] = stripslashes_deep( html_entity_decode( $item_name, ENT_COMPAT, 'UTF-8' ) ); |
|
146 | + $item_name = wpinv_get_cart_item_name(array('id' => $subscription->product_id)); |
|
147 | + $paypal_args['item_name'] = stripslashes_deep(html_entity_decode($item_name, ENT_COMPAT, 'UTF-8')); |
|
148 | 148 | $paypal_args['item_number'] = $subscription->product_id; |
149 | - $item = new WPInv_Item( $subscription->period ); |
|
149 | + $item = new WPInv_Item($subscription->period); |
|
150 | 150 | |
151 | - if ( $invoice->is_free_trial() && $item->has_free_trial() ) { |
|
151 | + if ($invoice->is_free_trial() && $item->has_free_trial()) { |
|
152 | 152 | $paypal_args['a1'] = $initial_amount; |
153 | 153 | $paypal_args['p1'] = $item->get_trial_interval(); |
154 | 154 | $paypal_args['t1'] = $item->get_trial_period(); |
155 | 155 | |
156 | 156 | // Set the recurring amount |
157 | 157 | $paypal_args['a3'] = $recurring_amount; |
158 | - } else if ( $initial_amount != $recurring_amount && $bill_times != 1 ) { |
|
158 | + } else if ($initial_amount != $recurring_amount && $bill_times != 1) { |
|
159 | 159 | $paypal_args['a1'] = $initial_amount; |
160 | 160 | $paypal_args['p1'] = $interval; |
161 | 161 | $paypal_args['t1'] = $period; |
@@ -163,63 +163,63 @@ discard block |
||
163 | 163 | // Set the recurring amount |
164 | 164 | $paypal_args['a3'] = $recurring_amount; |
165 | 165 | |
166 | - if ( $bill_times > 1 ) { |
|
166 | + if ($bill_times > 1) { |
|
167 | 167 | $bill_times--; |
168 | 168 | } |
169 | 169 | } else { |
170 | - $paypal_args['a3'] = $initial_amount; |
|
170 | + $paypal_args['a3'] = $initial_amount; |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | $paypal_args['p3'] = $interval; |
174 | 174 | $paypal_args['t3'] = $period; |
175 | 175 | |
176 | - if ( $bill_times > 1 ) { |
|
176 | + if ($bill_times > 1) { |
|
177 | 177 | // Make sure it's not over the max of 52 |
178 | - $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
|
178 | + $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | // Remove cart items |
182 | 182 | $i = 1; |
183 | - if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) { |
|
184 | - foreach ( $purchase_data['cart_details'] as $item ) { |
|
185 | - if ( isset( $paypal_args['item_number_' . $i] ) ) { |
|
186 | - unset( $paypal_args['item_number_' . $i] ); |
|
183 | + if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) { |
|
184 | + foreach ($purchase_data['cart_details'] as $item) { |
|
185 | + if (isset($paypal_args['item_number_' . $i])) { |
|
186 | + unset($paypal_args['item_number_' . $i]); |
|
187 | 187 | } |
188 | - if ( isset( $paypal_args['item_name_' . $i] ) ) { |
|
189 | - unset( $paypal_args['item_name_' . $i] ); |
|
188 | + if (isset($paypal_args['item_name_' . $i])) { |
|
189 | + unset($paypal_args['item_name_' . $i]); |
|
190 | 190 | } |
191 | - if ( isset( $paypal_args['quantity_' . $i] ) ) { |
|
192 | - unset( $paypal_args['quantity_' . $i] ); |
|
191 | + if (isset($paypal_args['quantity_' . $i])) { |
|
192 | + unset($paypal_args['quantity_' . $i]); |
|
193 | 193 | } |
194 | - if ( isset( $paypal_args['amount_' . $i] ) ) { |
|
195 | - unset( $paypal_args['amount_' . $i] ); |
|
194 | + if (isset($paypal_args['amount_' . $i])) { |
|
195 | + unset($paypal_args['amount_' . $i]); |
|
196 | 196 | } |
197 | - if ( isset( $paypal_args['discount_amount_' . $i] ) ) { |
|
198 | - unset( $paypal_args['discount_amount_' . $i] ); |
|
197 | + if (isset($paypal_args['discount_amount_' . $i])) { |
|
198 | + unset($paypal_args['discount_amount_' . $i]); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | $i++; |
202 | 202 | } |
203 | 203 | } |
204 | 204 | |
205 | - if ( isset( $paypal_args['tax_cart'] ) ) { |
|
206 | - unset( $paypal_args['tax_cart'] ); |
|
205 | + if (isset($paypal_args['tax_cart'])) { |
|
206 | + unset($paypal_args['tax_cart']); |
|
207 | 207 | } |
208 | 208 | |
209 | - if ( isset( $paypal_args['upload'] ) ) { |
|
210 | - unset( $paypal_args['upload'] ); |
|
209 | + if (isset($paypal_args['upload'])) { |
|
210 | + unset($paypal_args['upload']); |
|
211 | 211 | } |
212 | 212 | |
213 | - $paypal_args = apply_filters( 'wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice ); |
|
213 | + $paypal_args = apply_filters('wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | return $paypal_args; |
217 | 217 | } |
218 | -add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 ); |
|
218 | +add_filter('wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3); |
|
219 | 219 | |
220 | 220 | function wpinv_process_paypal_ipn() { |
221 | 221 | // Check the request method is POST |
222 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
222 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') { |
|
223 | 223 | return; |
224 | 224 | } |
225 | 225 | |
@@ -227,11 +227,11 @@ discard block |
||
227 | 227 | $post_data = ''; |
228 | 228 | |
229 | 229 | // Fallback just in case post_max_size is lower than needed |
230 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
231 | - $post_data = file_get_contents( 'php://input' ); |
|
230 | + if (ini_get('allow_url_fopen')) { |
|
231 | + $post_data = file_get_contents('php://input'); |
|
232 | 232 | } else { |
233 | 233 | // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
234 | - ini_set( 'post_max_size', '12M' ); |
|
234 | + ini_set('post_max_size', '12M'); |
|
235 | 235 | } |
236 | 236 | // Start the encoded data collection with notification command |
237 | 237 | $encoded_data = 'cmd=_notify-validate'; |
@@ -240,43 +240,43 @@ discard block |
||
240 | 240 | $arg_separator = wpinv_get_php_arg_separator_output(); |
241 | 241 | |
242 | 242 | // Verify there is a post_data |
243 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
243 | + if ($post_data || strlen($post_data) > 0) { |
|
244 | 244 | // Append the data |
245 | - $encoded_data .= $arg_separator.$post_data; |
|
245 | + $encoded_data .= $arg_separator . $post_data; |
|
246 | 246 | } else { |
247 | 247 | // Check if POST is empty |
248 | - if ( empty( $_POST ) ) { |
|
248 | + if (empty($_POST)) { |
|
249 | 249 | // Nothing to do |
250 | 250 | return; |
251 | 251 | } else { |
252 | 252 | // Loop through each POST |
253 | - foreach ( $_POST as $key => $value ) { |
|
253 | + foreach ($_POST as $key => $value) { |
|
254 | 254 | // Encode the value and append the data |
255 | - $encoded_data .= $arg_separator."$key=" . urlencode( $value ); |
|
255 | + $encoded_data .= $arg_separator . "$key=" . urlencode($value); |
|
256 | 256 | } |
257 | 257 | } |
258 | 258 | } |
259 | 259 | |
260 | 260 | // Convert collected post data to an array |
261 | - wp_parse_str( $encoded_data, $encoded_data_array ); |
|
261 | + wp_parse_str($encoded_data, $encoded_data_array); |
|
262 | 262 | |
263 | - foreach ( $encoded_data_array as $key => $value ) { |
|
264 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
265 | - $new_key = str_replace( '&', '&', $key ); |
|
266 | - $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
263 | + foreach ($encoded_data_array as $key => $value) { |
|
264 | + if (false !== strpos($key, 'amp;')) { |
|
265 | + $new_key = str_replace('&', '&', $key); |
|
266 | + $new_key = str_replace('amp;', '&', $new_key); |
|
267 | 267 | |
268 | - unset( $encoded_data_array[ $key ] ); |
|
269 | - $encoded_data_array[ $new_key ] = $value; |
|
268 | + unset($encoded_data_array[$key]); |
|
269 | + $encoded_data_array[$new_key] = $value; |
|
270 | 270 | } |
271 | 271 | } |
272 | 272 | |
273 | 273 | // Get the PayPal redirect uri |
274 | - $paypal_redirect = wpinv_get_paypal_redirect( true ); |
|
274 | + $paypal_redirect = wpinv_get_paypal_redirect(true); |
|
275 | 275 | |
276 | - if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
276 | + if (!wpinv_get_option('disable_paypal_verification', false)) { |
|
277 | 277 | // Validate the IPN |
278 | 278 | |
279 | - $remote_post_vars = array( |
|
279 | + $remote_post_vars = array( |
|
280 | 280 | 'method' => 'POST', |
281 | 281 | 'timeout' => 45, |
282 | 282 | 'redirection' => 5, |
@@ -294,21 +294,21 @@ discard block |
||
294 | 294 | ); |
295 | 295 | |
296 | 296 | // Get response |
297 | - $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars ); |
|
297 | + $api_response = wp_remote_post(wpinv_get_paypal_redirect(), $remote_post_vars); |
|
298 | 298 | |
299 | - if ( is_wp_error( $api_response ) ) { |
|
300 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
299 | + if (is_wp_error($api_response)) { |
|
300 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response))); |
|
301 | 301 | return; // Something went wrong |
302 | 302 | } |
303 | 303 | |
304 | - if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
305 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
304 | + if ($api_response['body'] !== 'VERIFIED' && wpinv_get_option('disable_paypal_verification', false)) { |
|
305 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response))); |
|
306 | 306 | return; // Response not okay |
307 | 307 | } |
308 | 308 | } |
309 | 309 | |
310 | 310 | // Check if $post_data_array has been populated |
311 | - if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) |
|
311 | + if (!is_array($encoded_data_array) && !empty($encoded_data_array)) |
|
312 | 312 | return; |
313 | 313 | |
314 | 314 | $defaults = array( |
@@ -316,265 +316,265 @@ discard block |
||
316 | 316 | 'payment_status' => '' |
317 | 317 | ); |
318 | 318 | |
319 | - $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
319 | + $encoded_data_array = wp_parse_args($encoded_data_array, $defaults); |
|
320 | 320 | |
321 | - $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
321 | + $invoice_id = isset($encoded_data_array['custom']) ? absint($encoded_data_array['custom']) : 0; |
|
322 | 322 | |
323 | - wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ ); |
|
324 | - wpinv_error_log( $encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__ ); |
|
323 | + wpinv_error_log($encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__); |
|
324 | + wpinv_error_log($encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__); |
|
325 | 325 | |
326 | - if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
326 | + if (has_action('wpinv_paypal_' . $encoded_data_array['txn_type'])) { |
|
327 | 327 | // Allow PayPal IPN types to be processed separately |
328 | - do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id ); |
|
328 | + do_action('wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id); |
|
329 | 329 | } else { |
330 | 330 | // Fallback to web accept just in case the txn_type isn't present |
331 | - do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id ); |
|
331 | + do_action('wpinv_paypal_web_accept', $encoded_data_array, $invoice_id); |
|
332 | 332 | } |
333 | 333 | exit; |
334 | 334 | } |
335 | -add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' ); |
|
335 | +add_action('wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn'); |
|
336 | 336 | |
337 | -function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) { |
|
338 | - if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
337 | +function wpinv_process_paypal_web_accept_and_cart($data, $invoice_id) { |
|
338 | + if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') { |
|
339 | 339 | return; |
340 | 340 | } |
341 | 341 | |
342 | - if( empty( $invoice_id ) ) { |
|
342 | + if (empty($invoice_id)) { |
|
343 | 343 | return; |
344 | 344 | } |
345 | 345 | |
346 | 346 | // Collect payment details |
347 | - $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
347 | + $purchase_key = isset($data['invoice']) ? $data['invoice'] : $data['item_number']; |
|
348 | 348 | $paypal_amount = $data['mc_gross']; |
349 | - $payment_status = strtolower( $data['payment_status'] ); |
|
350 | - $currency_code = strtolower( $data['mc_currency'] ); |
|
351 | - $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
352 | - $payment_meta = wpinv_get_invoice_meta( $invoice_id ); |
|
349 | + $payment_status = strtolower($data['payment_status']); |
|
350 | + $currency_code = strtolower($data['mc_currency']); |
|
351 | + $business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']); |
|
352 | + $payment_meta = wpinv_get_invoice_meta($invoice_id); |
|
353 | 353 | |
354 | - if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) { |
|
354 | + if (wpinv_get_payment_gateway($invoice_id) != 'paypal') { |
|
355 | 355 | return; // this isn't a PayPal standard IPN |
356 | 356 | } |
357 | 357 | |
358 | 358 | // Verify payment recipient |
359 | - if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) { |
|
360 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
361 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
362 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ), '', '', true ); |
|
359 | + if (strcasecmp($business_email, trim(wpinv_get_option('paypal_email', false))) != 0) { |
|
360 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid business email in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
361 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
362 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid PayPal business email.', 'invoicing'), '', '', true); |
|
363 | 363 | return; |
364 | 364 | } |
365 | 365 | |
366 | 366 | // Verify payment currency |
367 | - if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
368 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
369 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
370 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
367 | + if ($currency_code != strtolower($payment_meta['currency'])) { |
|
368 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
369 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
370 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid currency in PayPal IPN.', 'invoicing'), '', '', true); |
|
371 | 371 | return; |
372 | 372 | } |
373 | 373 | |
374 | - if ( !wpinv_get_payment_user_email( $invoice_id ) ) { |
|
374 | + if (!wpinv_get_payment_user_email($invoice_id)) { |
|
375 | 375 | // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal |
376 | 376 | // No email associated with purchase, so store from PayPal |
377 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] ); |
|
377 | + wpinv_update_invoice_meta($invoice_id, '_wpinv_email', $data['payer_email']); |
|
378 | 378 | |
379 | 379 | // Setup and store the customer's details |
380 | 380 | $user_info = array( |
381 | 381 | 'user_id' => '-1', |
382 | - 'email' => sanitize_text_field( $data['payer_email'] ), |
|
383 | - 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
384 | - 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
382 | + 'email' => sanitize_text_field($data['payer_email']), |
|
383 | + 'first_name' => sanitize_text_field($data['first_name']), |
|
384 | + 'last_name' => sanitize_text_field($data['last_name']), |
|
385 | 385 | 'discount' => '', |
386 | 386 | ); |
387 | - $user_info['address'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
388 | - $user_info['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
389 | - $user_info['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
390 | - $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
391 | - $user_info['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
387 | + $user_info['address'] = !empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false; |
|
388 | + $user_info['city'] = !empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false; |
|
389 | + $user_info['state'] = !empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false; |
|
390 | + $user_info['country'] = !empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false; |
|
391 | + $user_info['zip'] = !empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false; |
|
392 | 392 | |
393 | 393 | $payment_meta['user_info'] = $user_info; |
394 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta ); |
|
394 | + wpinv_update_invoice_meta($invoice_id, '_wpinv_payment_meta', $payment_meta); |
|
395 | 395 | } |
396 | 396 | |
397 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
397 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
398 | 398 | // Process a refund |
399 | - wpinv_process_paypal_refund( $data, $invoice_id ); |
|
399 | + wpinv_process_paypal_refund($data, $invoice_id); |
|
400 | 400 | } else { |
401 | - if ( get_post_status( $invoice_id ) == 'publish' ) { |
|
401 | + if (get_post_status($invoice_id) == 'publish') { |
|
402 | 402 | return; // Only paid payments once |
403 | 403 | } |
404 | 404 | |
405 | 405 | // Retrieve the total purchase amount (before PayPal) |
406 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
406 | + $payment_amount = wpinv_payment_total($invoice_id); |
|
407 | 407 | |
408 | - if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
408 | + if (number_format((float) $paypal_amount, 2) < number_format((float) $payment_amount, 2)) { |
|
409 | 409 | // The prices don't match |
410 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
411 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
412 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
410 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid payment amount in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
411 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
412 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid amount in PayPal IPN.', 'invoicing'), '', '', true); |
|
413 | 413 | return; |
414 | 414 | } |
415 | - if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) { |
|
415 | + if ($purchase_key != wpinv_get_payment_key($invoice_id)) { |
|
416 | 416 | // Purchase keys don't match |
417 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
418 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
419 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ), '', '', true ); |
|
417 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid purchase key in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
418 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
419 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing'), '', '', true); |
|
420 | 420 | return; |
421 | 421 | } |
422 | 422 | |
423 | - if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) { |
|
424 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ), '', '', true ); |
|
425 | - wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] ); |
|
426 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
427 | - } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
423 | + if ('complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode('paypal')) { |
|
424 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $data['txn_id']), '', '', true); |
|
425 | + wpinv_set_payment_transaction_id($invoice_id, $data['txn_id']); |
|
426 | + wpinv_update_payment_status($invoice_id, 'publish'); |
|
427 | + } else if ('pending' == $payment_status && isset($data['pending_reason'])) { |
|
428 | 428 | // Look for possible pending reasons, such as an echeck |
429 | 429 | $note = ''; |
430 | 430 | |
431 | - switch( strtolower( $data['pending_reason'] ) ) { |
|
431 | + switch (strtolower($data['pending_reason'])) { |
|
432 | 432 | case 'echeck' : |
433 | - $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' ); |
|
433 | + $note = __('Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing'); |
|
434 | 434 | break; |
435 | 435 | |
436 | 436 | case 'address' : |
437 | - $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' ); |
|
437 | + $note = __('Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing'); |
|
438 | 438 | break; |
439 | 439 | |
440 | 440 | case 'intl' : |
441 | - $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' ); |
|
441 | + $note = __('Payment must be accepted manually through PayPal due to international account regulations', 'invoicing'); |
|
442 | 442 | break; |
443 | 443 | |
444 | 444 | case 'multi-currency' : |
445 | - $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' ); |
|
445 | + $note = __('Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing'); |
|
446 | 446 | break; |
447 | 447 | |
448 | 448 | case 'paymentreview' : |
449 | 449 | case 'regulatory_review' : |
450 | - $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' ); |
|
450 | + $note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing'); |
|
451 | 451 | break; |
452 | 452 | |
453 | 453 | case 'unilateral' : |
454 | - $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' ); |
|
454 | + $note = __('Payment was sent to non-confirmed or non-registered email address.', 'invoicing'); |
|
455 | 455 | break; |
456 | 456 | |
457 | 457 | case 'upgrade' : |
458 | - $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' ); |
|
458 | + $note = __('PayPal account must be upgraded before this payment can be accepted', 'invoicing'); |
|
459 | 459 | break; |
460 | 460 | |
461 | 461 | case 'verify' : |
462 | - $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' ); |
|
462 | + $note = __('PayPal account is not verified. Verify account in order to accept this payment', 'invoicing'); |
|
463 | 463 | break; |
464 | 464 | |
465 | 465 | case 'other' : |
466 | - $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' ); |
|
466 | + $note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing'); |
|
467 | 467 | break; |
468 | 468 | } |
469 | 469 | |
470 | - if ( ! empty( $note ) ) { |
|
471 | - wpinv_insert_payment_note( $invoice_id, $note, '', '', true ); |
|
470 | + if (!empty($note)) { |
|
471 | + wpinv_insert_payment_note($invoice_id, $note, '', '', true); |
|
472 | 472 | } |
473 | 473 | } else { |
474 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ), '', '', true ); |
|
474 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal IPN has been received with invalid payment status: %s', 'invoicing'), $payment_status), '', '', true); |
|
475 | 475 | } |
476 | 476 | } |
477 | 477 | } |
478 | -add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 ); |
|
478 | +add_action('wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2); |
|
479 | 479 | |
480 | 480 | // Process PayPal subscription sign ups |
481 | -add_action( 'wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup' ); |
|
481 | +add_action('wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup'); |
|
482 | 482 | |
483 | 483 | // Process PayPal subscription payments |
484 | -add_action( 'wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment' ); |
|
484 | +add_action('wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment'); |
|
485 | 485 | |
486 | 486 | // Process PayPal subscription cancellations |
487 | -add_action( 'wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel' ); |
|
487 | +add_action('wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel'); |
|
488 | 488 | |
489 | 489 | // Process PayPal subscription end of term notices |
490 | -add_action( 'wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot' ); |
|
490 | +add_action('wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot'); |
|
491 | 491 | |
492 | 492 | // Process PayPal payment failed |
493 | -add_action( 'wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed' ); |
|
493 | +add_action('wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed'); |
|
494 | 494 | |
495 | 495 | |
496 | 496 | /** |
497 | 497 | * Process the subscription started IPN. |
498 | 498 | */ |
499 | -function wpinv_process_paypal_subscr_signup( $ipn_data ) { |
|
500 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
501 | - if( empty( $parent_invoice_id ) ) { |
|
499 | +function wpinv_process_paypal_subscr_signup($ipn_data) { |
|
500 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
501 | + if (empty($parent_invoice_id)) { |
|
502 | 502 | return; |
503 | 503 | } |
504 | 504 | |
505 | - $invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
506 | - if ( empty( $invoice ) ) { |
|
505 | + $invoice = wpinv_get_invoice($parent_invoice_id); |
|
506 | + if (empty($invoice)) { |
|
507 | 507 | return; |
508 | 508 | } |
509 | 509 | |
510 | - if ( $invoice->is_free_trial() && !empty( $ipn_data['invoice'] ) ) { |
|
511 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Invoice ID: %s', 'invoicing' ) , $ipn_data['invoice'] ), '', '', true); |
|
512 | - if ( !empty( $ipn_data['txn_id'] ) ) { |
|
513 | - wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] ); |
|
510 | + if ($invoice->is_free_trial() && !empty($ipn_data['invoice'])) { |
|
511 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Invoice ID: %s', 'invoicing'), $ipn_data['invoice']), '', '', true); |
|
512 | + if (!empty($ipn_data['txn_id'])) { |
|
513 | + wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']); |
|
514 | 514 | } |
515 | 515 | } |
516 | 516 | |
517 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
518 | - if ( false === $subscription ) { |
|
517 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
518 | + if (false === $subscription) { |
|
519 | 519 | return; |
520 | 520 | } |
521 | 521 | |
522 | - wpinv_update_payment_status( $parent_invoice_id, 'publish' ); |
|
522 | + wpinv_update_payment_status($parent_invoice_id, 'publish'); |
|
523 | 523 | sleep(1); |
524 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ), '', '', true ); |
|
525 | - update_post_meta($parent_invoice_id,'_wpinv_subscr_profile_id', $ipn_data['subscr_id']); |
|
524 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id']), '', '', true); |
|
525 | + update_post_meta($parent_invoice_id, '_wpinv_subscr_profile_id', $ipn_data['subscr_id']); |
|
526 | 526 | |
527 | 527 | $status = 'trialling' == $subscription->status ? 'trialling' : 'active'; |
528 | - $diff_days = absint( ( ( strtotime( $subscription->expiration ) - strtotime( $subscription->created ) ) / DAY_IN_SECONDS ) ); |
|
529 | - $created = date_i18n( 'Y-m-d H:i:s' ); |
|
530 | - $expiration = date_i18n( 'Y-m-d 23:59:59', ( strtotime( $created ) + ( $diff_days * DAY_IN_SECONDS ) ) ); |
|
528 | + $diff_days = absint(((strtotime($subscription->expiration) - strtotime($subscription->created)) / DAY_IN_SECONDS)); |
|
529 | + $created = date_i18n('Y-m-d H:i:s'); |
|
530 | + $expiration = date_i18n('Y-m-d 23:59:59', (strtotime($created) + ($diff_days * DAY_IN_SECONDS))); |
|
531 | 531 | |
532 | 532 | // Retrieve pending subscription from database and update it's status to active and set proper profile ID |
533 | - $subscription->update( array( 'profile_id' => $ipn_data['subscr_id'], 'status' => $status, 'created' => $created, 'expiration' => $expiration ) ); |
|
533 | + $subscription->update(array('profile_id' => $ipn_data['subscr_id'], 'status' => $status, 'created' => $created, 'expiration' => $expiration)); |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | /** |
537 | 537 | * Process the subscription payment received IPN. |
538 | 538 | */ |
539 | -function wpinv_process_paypal_subscr_payment( $ipn_data ) { |
|
540 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
539 | +function wpinv_process_paypal_subscr_payment($ipn_data) { |
|
540 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
541 | 541 | |
542 | - $parent_invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
543 | - if ( empty( $parent_invoice ) ) { |
|
542 | + $parent_invoice = wpinv_get_invoice($parent_invoice_id); |
|
543 | + if (empty($parent_invoice)) { |
|
544 | 544 | return; |
545 | 545 | } |
546 | 546 | |
547 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
548 | - if ( false === $subscription ) { |
|
547 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
548 | + if (false === $subscription) { |
|
549 | 549 | return; |
550 | 550 | } |
551 | 551 | |
552 | - $transaction_id = wpinv_get_payment_transaction_id( $parent_invoice_id ); |
|
552 | + $transaction_id = wpinv_get_payment_transaction_id($parent_invoice_id); |
|
553 | 553 | $times_billed = $subscription->get_times_billed(); |
554 | - $signup_date = strtotime( $subscription->created ); |
|
555 | - $today = date( 'Ynd', $signup_date ) == date( 'Ynd', strtotime( $ipn_data['payment_date'] ) ); |
|
554 | + $signup_date = strtotime($subscription->created); |
|
555 | + $today = date('Ynd', $signup_date) == date('Ynd', strtotime($ipn_data['payment_date'])); |
|
556 | 556 | |
557 | 557 | // Look to see if payment is same day as signup and we have set the transaction ID on the parent payment yet. |
558 | - if ( (empty($times_billed) || $today) && ( !$transaction_id || $transaction_id == $parent_invoice_id ) ) { |
|
559 | - wpinv_update_payment_status( $parent_invoice_id, 'publish' ); |
|
558 | + if ((empty($times_billed) || $today) && (!$transaction_id || $transaction_id == $parent_invoice_id)) { |
|
559 | + wpinv_update_payment_status($parent_invoice_id, 'publish'); |
|
560 | 560 | sleep(1); |
561 | 561 | |
562 | 562 | // This is the very first payment |
563 | - wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] ); |
|
564 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ), '', '', true ); |
|
563 | + wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']); |
|
564 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']), '', '', true); |
|
565 | 565 | return; |
566 | 566 | } |
567 | 567 | |
568 | - if ( wpinv_get_id_by_transaction_id( $ipn_data['txn_id'] ) ) { |
|
568 | + if (wpinv_get_id_by_transaction_id($ipn_data['txn_id'])) { |
|
569 | 569 | return; // Payment already recorded |
570 | 570 | } |
571 | 571 | |
572 | - $currency_code = strtolower( $ipn_data['mc_currency'] ); |
|
572 | + $currency_code = strtolower($ipn_data['mc_currency']); |
|
573 | 573 | |
574 | 574 | // verify details |
575 | - if ( $currency_code != strtolower( wpinv_get_currency() ) ) { |
|
575 | + if ($currency_code != strtolower(wpinv_get_currency())) { |
|
576 | 576 | // the currency code is invalid |
577 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: ', 'invoicing' ), json_encode( $ipn_data ) ) ); |
|
577 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: ', 'invoicing'), json_encode($ipn_data))); |
|
578 | 578 | return; |
579 | 579 | } |
580 | 580 | |
@@ -584,11 +584,11 @@ discard block |
||
584 | 584 | 'gateway' => 'paypal' |
585 | 585 | ); |
586 | 586 | |
587 | - $invoice_id = $subscription->add_payment( $args ); |
|
587 | + $invoice_id = $subscription->add_payment($args); |
|
588 | 588 | |
589 | - if ( $invoice_id > 0 ) { |
|
590 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ), '', '', true ); |
|
591 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ), '', '', true ); |
|
589 | + if ($invoice_id > 0) { |
|
590 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']), '', '', true); |
|
591 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id']), '', '', true); |
|
592 | 592 | |
593 | 593 | $subscription->renew(); |
594 | 594 | } |
@@ -597,10 +597,10 @@ discard block |
||
597 | 597 | /** |
598 | 598 | * Process the subscription canceled IPN. |
599 | 599 | */ |
600 | -function wpinv_process_paypal_subscr_cancel( $ipn_data ) { |
|
601 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
600 | +function wpinv_process_paypal_subscr_cancel($ipn_data) { |
|
601 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
602 | 602 | |
603 | - if( false === $subscription ) { |
|
603 | + if (false === $subscription) { |
|
604 | 604 | return; |
605 | 605 | } |
606 | 606 | |
@@ -610,10 +610,10 @@ discard block |
||
610 | 610 | /** |
611 | 611 | * Process the subscription expired IPN. |
612 | 612 | */ |
613 | -function wpinv_process_paypal_subscr_eot( $ipn_data ) { |
|
614 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
613 | +function wpinv_process_paypal_subscr_eot($ipn_data) { |
|
614 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
615 | 615 | |
616 | - if( false === $subscription ) { |
|
616 | + if (false === $subscription) { |
|
617 | 617 | return; |
618 | 618 | } |
619 | 619 | |
@@ -623,40 +623,40 @@ discard block |
||
623 | 623 | /** |
624 | 624 | * Process the subscription payment failed IPN. |
625 | 625 | */ |
626 | -function wpinv_process_paypal_subscr_failed( $ipn_data ) { |
|
627 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
626 | +function wpinv_process_paypal_subscr_failed($ipn_data) { |
|
627 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
628 | 628 | |
629 | - if( false === $subscription ) { |
|
629 | + if (false === $subscription) { |
|
630 | 630 | return; |
631 | 631 | } |
632 | 632 | |
633 | 633 | $subscription->failing(); |
634 | 634 | |
635 | - do_action( 'wpinv_recurring_payment_failed', $subscription ); |
|
635 | + do_action('wpinv_recurring_payment_failed', $subscription); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | /** |
639 | 639 | * Retrieve the subscription this IPN notice is for. |
640 | 640 | */ |
641 | -function wpinv_get_paypal_subscription( $ipn_data = array() ) { |
|
642 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
641 | +function wpinv_get_paypal_subscription($ipn_data = array()) { |
|
642 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
643 | 643 | |
644 | - if( empty( $parent_invoice_id ) ) { |
|
644 | + if (empty($parent_invoice_id)) { |
|
645 | 645 | return false; |
646 | 646 | } |
647 | 647 | |
648 | - $invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
649 | - if ( empty( $invoice ) ) { |
|
648 | + $invoice = wpinv_get_invoice($parent_invoice_id); |
|
649 | + if (empty($invoice)) { |
|
650 | 650 | return false; |
651 | 651 | } |
652 | 652 | |
653 | - $subscription = new WPInv_Subscription( $ipn_data['subscr_id'], true ); |
|
653 | + $subscription = new WPInv_Subscription($ipn_data['subscr_id'], true); |
|
654 | 654 | |
655 | - if ( ! ( ! empty( $subscription ) && $subscription->id > 0 ) ) { |
|
656 | - $subscription = wpinv_get_subscription( $parent_invoice_id ); |
|
655 | + if (!(!empty($subscription) && $subscription->id > 0)) { |
|
656 | + $subscription = wpinv_get_subscription($parent_invoice_id); |
|
657 | 657 | |
658 | - if ( ! empty( $subscription ) && $subscription->id > 0 ) { |
|
659 | - $subscription->update( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) ); |
|
658 | + if (!empty($subscription) && $subscription->id > 0) { |
|
659 | + $subscription->update(array('profile_id' => sanitize_text_field($ipn_data['subscr_id']))); |
|
660 | 660 | } else { |
661 | 661 | return false; |
662 | 662 | } |
@@ -666,39 +666,39 @@ discard block |
||
666 | 666 | |
667 | 667 | } |
668 | 668 | |
669 | -function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) { |
|
669 | +function wpinv_process_paypal_refund($data, $invoice_id = 0) { |
|
670 | 670 | // Collect payment details |
671 | 671 | |
672 | - if( empty( $invoice_id ) ) { |
|
672 | + if (empty($invoice_id)) { |
|
673 | 673 | return; |
674 | 674 | } |
675 | 675 | |
676 | - if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) { |
|
676 | + if (get_post_status($invoice_id) == 'wpi-refunded') { |
|
677 | 677 | return; // Only refund payments once |
678 | 678 | } |
679 | 679 | |
680 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
680 | + $payment_amount = wpinv_payment_total($invoice_id); |
|
681 | 681 | $refund_amount = $data['mc_gross'] * -1; |
682 | 682 | |
683 | - do_action( 'wpinv_paypal_refund_request', $data, $invoice_id ); |
|
683 | + do_action('wpinv_paypal_refund_request', $data, $invoice_id); |
|
684 | 684 | |
685 | - if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
686 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing' ), (float)$refund_amount . ' '. $data['mc_currency'], $data['parent_txn_id'], $data['reason_code'] ), '', '', true ); |
|
685 | + if (number_format((float) $refund_amount, 2) < number_format((float) $payment_amount, 2)) { |
|
686 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing'), (float) $refund_amount . ' ' . $data['mc_currency'], $data['parent_txn_id'], $data['reason_code']), '', '', true); |
|
687 | 687 | |
688 | - do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount ); |
|
688 | + do_action('wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount); |
|
689 | 689 | |
690 | 690 | return; // This is a partial refund |
691 | 691 | } |
692 | 692 | |
693 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true ); |
|
694 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true ); |
|
695 | - wpinv_update_payment_status( $invoice_id, 'wpi-refunded' ); |
|
693 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Payment #%s Refunded for reason: %s', 'invoicing'), $data['parent_txn_id'], $data['reason_code']), '', '', true); |
|
694 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Refund Transaction ID: %s', 'invoicing'), $data['txn_id']), '', '', true); |
|
695 | + wpinv_update_payment_status($invoice_id, 'wpi-refunded'); |
|
696 | 696 | |
697 | - do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id ); |
|
697 | + do_action('wpinv_paypal_invoice_fully_refunded', $data, $invoice_id); |
|
698 | 698 | } |
699 | 699 | |
700 | -function wpinv_get_paypal_redirect( $ssl_check = false ) { |
|
701 | - return apply_filters( 'wpinv_paypal_uri', wpinv_is_test_mode( 'paypal' ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?' ); |
|
700 | +function wpinv_get_paypal_redirect($ssl_check = false) { |
|
701 | + return apply_filters('wpinv_paypal_uri', wpinv_is_test_mode('paypal') ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'); |
|
702 | 702 | } |
703 | 703 | |
704 | 704 | /** |
@@ -706,111 +706,111 @@ discard block |
||
706 | 706 | * |
707 | 707 | * @param string $content Success page content. |
708 | 708 | */ |
709 | -function wpinv_paypal_success_page_content( $content ) { |
|
709 | +function wpinv_paypal_success_page_content($content) { |
|
710 | 710 | |
711 | 711 | // Retrieve the invoice. |
712 | 712 | $invoice_id = getpaid_get_current_invoice_id(); |
713 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
713 | + $invoice = wpinv_get_invoice($invoice_id); |
|
714 | 714 | |
715 | 715 | // Ensure that it exists and that it is pending payment. |
716 | - if ( empty( $invoice_id ) || ! $invoice->has_status( 'wpi-pending' ) ) { |
|
716 | + if (empty($invoice_id) || !$invoice->has_status('wpi-pending')) { |
|
717 | 717 | return $content; |
718 | 718 | } |
719 | 719 | |
720 | 720 | // Can the user view this invoice?? |
721 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
721 | + if (!wpinv_user_can_view_invoice($invoice)) { |
|
722 | 722 | return $content; |
723 | 723 | } |
724 | 724 | |
725 | 725 | // Show payment processing indicator. |
726 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
726 | + return wpinv_get_template_html('wpinv-payment-processing.php', compact('invoice')); |
|
727 | 727 | |
728 | 728 | } |
729 | -add_filter( 'wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content' ); |
|
729 | +add_filter('wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content'); |
|
730 | 730 | |
731 | -function wpinv_paypal_get_transaction_id( $invoice_id ) { |
|
731 | +function wpinv_paypal_get_transaction_id($invoice_id) { |
|
732 | 732 | $transaction_id = ''; |
733 | - $notes = wpinv_get_invoice_notes( $invoice_id ); |
|
733 | + $notes = wpinv_get_invoice_notes($invoice_id); |
|
734 | 734 | |
735 | - foreach ( $notes as $note ) { |
|
736 | - if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) { |
|
735 | + foreach ($notes as $note) { |
|
736 | + if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) { |
|
737 | 737 | $transaction_id = $match[1]; |
738 | 738 | continue; |
739 | 739 | } |
740 | 740 | } |
741 | 741 | |
742 | - return apply_filters( 'wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id ); |
|
742 | + return apply_filters('wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id); |
|
743 | 743 | } |
744 | -add_filter( 'wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1 ); |
|
744 | +add_filter('wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1); |
|
745 | 745 | |
746 | -function wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice ) { |
|
747 | - if ( $transaction_id == $invoice_id ) { |
|
746 | +function wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice) { |
|
747 | + if ($transaction_id == $invoice_id) { |
|
748 | 748 | $transaction_link = $transaction_id; |
749 | 749 | } else { |
750 | - if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) { |
|
750 | + if (!empty($invoice) && !empty($invoice->mode)) { |
|
751 | 751 | $mode = $invoice->mode; |
752 | 752 | } else { |
753 | - $mode = wpinv_is_test_mode( 'paypal' ) ? 'test' : 'live'; |
|
753 | + $mode = wpinv_is_test_mode('paypal') ? 'test' : 'live'; |
|
754 | 754 | } |
755 | 755 | |
756 | 756 | $sandbox = $mode == 'test' ? '.sandbox' : ''; |
757 | 757 | $transaction_url = 'https://www' . $sandbox . '.paypal.com/webscr?cmd=_history-details-from-hub&id=' . $transaction_id; |
758 | 758 | |
759 | - $transaction_link = '<a href="' . esc_url( $transaction_url ) . '" target="_blank">' . $transaction_id . '</a>'; |
|
759 | + $transaction_link = '<a href="' . esc_url($transaction_url) . '" target="_blank">' . $transaction_id . '</a>'; |
|
760 | 760 | } |
761 | 761 | |
762 | - return apply_filters( 'wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $transaction_id, $invoice ); |
|
762 | + return apply_filters('wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $transaction_id, $invoice); |
|
763 | 763 | } |
764 | -add_filter( 'wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3 ); |
|
764 | +add_filter('wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3); |
|
765 | 765 | |
766 | -function wpinv_paypal_profile_id_link( $profile_id, $subscription ) { |
|
766 | +function wpinv_paypal_profile_id_link($profile_id, $subscription) { |
|
767 | 767 | $link = $profile_id; |
768 | 768 | |
769 | - if ( ! empty( $profile_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) { |
|
770 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
769 | + if (!empty($profile_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) { |
|
770 | + $invoice = wpinv_get_invoice($invoice_id); |
|
771 | 771 | |
772 | - if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) { |
|
772 | + if (!empty($invoice) && !empty($invoice->mode)) { |
|
773 | 773 | $mode = $invoice->mode; |
774 | 774 | } else { |
775 | - $mode = wpinv_is_test_mode( 'paypal' ) ? 'test' : 'live'; |
|
775 | + $mode = wpinv_is_test_mode('paypal') ? 'test' : 'live'; |
|
776 | 776 | } |
777 | 777 | |
778 | 778 | $sandbox = $mode == 'test' ? '.sandbox' : ''; |
779 | 779 | $url = 'https://www' . $sandbox . '.paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=' . $profile_id; |
780 | 780 | |
781 | - $link = '<a href="' . esc_url( $url ) . '" target="_blank">' . $profile_id . '</a>'; |
|
781 | + $link = '<a href="' . esc_url($url) . '" target="_blank">' . $profile_id . '</a>'; |
|
782 | 782 | } |
783 | 783 | |
784 | - return apply_filters( 'wpinv_paypal_profile_id_link', $link, $profile_id, $subscription ); |
|
784 | + return apply_filters('wpinv_paypal_profile_id_link', $link, $profile_id, $subscription); |
|
785 | 785 | } |
786 | -add_filter( 'wpinv_subscription_profile_link_paypal', 'wpinv_paypal_profile_id_link', 10, 2 ); |
|
786 | +add_filter('wpinv_subscription_profile_link_paypal', 'wpinv_paypal_profile_id_link', 10, 2); |
|
787 | 787 | |
788 | -function wpinv_paypal_transaction_id_link( $transaction_id, $subscription ) { |
|
789 | - if ( ! empty( $transaction_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) { |
|
790 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
788 | +function wpinv_paypal_transaction_id_link($transaction_id, $subscription) { |
|
789 | + if (!empty($transaction_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) { |
|
790 | + $invoice = wpinv_get_invoice($invoice_id); |
|
791 | 791 | |
792 | - if ( ! empty( $invoice ) ) { |
|
793 | - return wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice ); |
|
792 | + if (!empty($invoice)) { |
|
793 | + return wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice); |
|
794 | 794 | } |
795 | 795 | } |
796 | 796 | |
797 | 797 | return $transaction_id; |
798 | 798 | } |
799 | -add_filter( 'wpinv_subscription_transaction_link_paypal', 'wpinv_paypal_transaction_id_link', 10, 2 ); |
|
799 | +add_filter('wpinv_subscription_transaction_link_paypal', 'wpinv_paypal_transaction_id_link', 10, 2); |
|
800 | 800 | |
801 | 801 | function wpinv_is_paypal_valid_for_use() { |
802 | - return in_array( wpinv_get_currency(), apply_filters( 'wpinv_paypal_supported_currencies', array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ) ) ); |
|
802 | + return in_array(wpinv_get_currency(), apply_filters('wpinv_paypal_supported_currencies', array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR'))); |
|
803 | 803 | } |
804 | 804 | |
805 | -function wpinv_check_paypal_currency_support( $gateway_list ) { |
|
806 | - if ( isset( $gateway_list['paypal'] ) && ! wpinv_is_paypal_valid_for_use() ) { |
|
807 | - unset( $gateway_list['paypal'] ); |
|
805 | +function wpinv_check_paypal_currency_support($gateway_list) { |
|
806 | + if (isset($gateway_list['paypal']) && !wpinv_is_paypal_valid_for_use()) { |
|
807 | + unset($gateway_list['paypal']); |
|
808 | 808 | } |
809 | 809 | return $gateway_list; |
810 | 810 | } |
811 | -add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_paypal_currency_support', 10, 1 ); |
|
811 | +add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_paypal_currency_support', 10, 1); |
|
812 | 812 | |
813 | -function wpinv_gateway_paypal_button_label( $label ) { |
|
814 | - return __( 'Proceed to PayPal', 'invoicing' ); |
|
813 | +function wpinv_gateway_paypal_button_label($label) { |
|
814 | + return __('Proceed to PayPal', 'invoicing'); |
|
815 | 815 | } |
816 | -add_filter( 'wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1 ); |
|
817 | 816 | \ No newline at end of file |
817 | +add_filter('wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1); |
|
818 | 818 | \ No newline at end of file |