@@ -182,7 +182,7 @@ |
||
| 182 | 182 | $string = ""; |
| 183 | 183 | foreach ($array as $key => $value) { |
| 184 | 184 | if ($value) { |
| 185 | - $string .= '<input type="hidden" name="'.$key.'" value="'.$value.'">'; |
|
| 185 | + $string .= '<input type="hidden" name="' . $key . '" value="' . $value . '">'; |
|
| 186 | 186 | } |
| 187 | 187 | } |
| 188 | 188 | return $string; |
@@ -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> |
@@ -64,8 +64,8 @@ discard block |
||
| 64 | 64 | { |
| 65 | 65 | $month = ($month ? $month : date('m')); |
| 66 | 66 | $year = ($year ? $year : date('Y')); |
| 67 | - $firstSettlementDate = substr(date('c',mktime(0, 0, 0, $month, 1, $year)),0,-6); |
|
| 68 | - $lastSettlementDate = substr(date('c',mktime(0, 0, 0, $month+1, 0, $year)),0,-6); |
|
| 67 | + $firstSettlementDate = substr(date('c', mktime(0, 0, 0, $month, 1, $year)), 0, -6); |
|
| 68 | + $lastSettlementDate = substr(date('c', mktime(0, 0, 0, $month + 1, 0, $year)), 0, -6); |
|
| 69 | 69 | return $this->getSettledBatchList(true, $firstSettlementDate, $lastSettlementDate); |
| 70 | 70 | } |
| 71 | 71 | |
@@ -98,8 +98,8 @@ discard block |
||
| 98 | 98 | $month = ($month ? $month : date('m')); |
| 99 | 99 | $day = ($day ? $day : date('d')); |
| 100 | 100 | $year = ($year ? $year : date('Y')); |
| 101 | - $firstSettlementDate = substr(date('c',mktime(0, 0, 0, (int)$month, (int)$day, (int)$year)),0,-6); |
|
| 102 | - $lastSettlementDate = substr(date('c',mktime(0, 0, 0, (int)$month, (int)$day, (int)$year)),0,-6); |
|
| 101 | + $firstSettlementDate = substr(date('c', mktime(0, 0, 0, (int)$month, (int)$day, (int)$year)), 0, -6); |
|
| 102 | + $lastSettlementDate = substr(date('c', mktime(0, 0, 0, (int)$month, (int)$day, (int)$year)), 0, -6); |
|
| 103 | 103 | $response = $this->getSettledBatchList(true, $firstSettlementDate, $lastSettlementDate); |
| 104 | 104 | $batches = $response->xpath("batchList/batch"); |
| 105 | 105 | foreach ($batches as $batch) { |
@@ -187,11 +187,11 @@ discard block |
||
| 187 | 187 | */ |
| 188 | 188 | private function _constructXml($request_type) |
| 189 | 189 | { |
| 190 | - $string = '<?xml version="1.0" encoding="utf-8"?><'.$request_type.' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"></'.$request_type.'>'; |
|
| 190 | + $string = '<?xml version="1.0" encoding="utf-8"?><' . $request_type . ' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"></' . $request_type . '>'; |
|
| 191 | 191 | $this->_xml = @new SimpleXMLElement($string); |
| 192 | 192 | $merchant = $this->_xml->addChild('merchantAuthentication'); |
| 193 | - $merchant->addChild('name',$this->_api_login); |
|
| 194 | - $merchant->addChild('transactionKey',$this->_transaction_key); |
|
| 193 | + $merchant->addChild('name', $this->_api_login); |
|
| 194 | + $merchant->addChild('transactionKey', $this->_transaction_key); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | } |
@@ -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,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-4 control-label"><?php _e( 'Card Owner', 'invoicing' ) ;?></label> |
|
| 15 | + <label for="auth-input-cc-owner" class="col-sm-4 control-label"><?php _e('Card Owner', 'invoicing'); ?></label> |
|
| 16 | 16 | <div class="col-sm-8"> |
| 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-4 control-label"><?php _e( 'Card Number', 'invoicing' ) ;?></label> |
|
| 21 | + <label for="auth-input-cc-number" class="col-sm-4 control-label"><?php _e('Card Number', 'invoicing'); ?></label> |
|
| 22 | 22 | <div class="col-sm-8"> |
| 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-4 control-label"><?php _e( 'Card Expiry Date', 'invoicing' ) ;?></label> |
|
| 27 | + <label for="auth-input-cc-expire-date" class="col-sm-4 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-2"> |
| 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-4 control-label"><?php _e( 'Card Security Code (CVV2)', 'invoicing' ) ;?></label> |
|
| 44 | + <label for="auth-input-cc-cvv2" class="col-sm-4 control-label"><?php _e('Card Security Code (CVV2)', 'invoicing'); ?></label> |
|
| 45 | 45 | <div class="col-sm-8"> |
| 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,27 +83,27 @@ 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(); |
@@ -112,141 +112,141 @@ discard block |
||
| 112 | 112 | $authorizeAIM->first_name = $invoice->get_first_name(); |
| 113 | 113 | $authorizeAIM->last_name = $invoice->get_last_name(); |
| 114 | 114 | $authorizeAIM->company = $invoice->company; |
| 115 | - $authorizeAIM->address = wp_strip_all_tags( $invoice->get_address(), true ); |
|
| 115 | + $authorizeAIM->address = wp_strip_all_tags($invoice->get_address(), true); |
|
| 116 | 116 | $authorizeAIM->city = $invoice->city; |
| 117 | 117 | $authorizeAIM->state = $invoice->state; |
| 118 | 118 | $authorizeAIM->zip = $invoice->zip; |
| 119 | 119 | $authorizeAIM->country = $invoice->country; |
| 120 | 120 | $authorizeAIM->phone = $invoice->phone; |
| 121 | 121 | $authorizeAIM->email = $invoice->get_email(); |
| 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'] ); |
|
| 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_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_desc[] = $item['name'] . ' (' . $quantity . 'x ' . wpinv_price(wpinv_format_amount($item['item_price'])) . ')'; |
|
| 132 | 132 | |
| 133 | - $authorizeAIM->addLineItem( $item['id'], $item['name'], '', $quantity, $item['item_price'], ( $use_taxes && !empty( $item['tax'] ) && $item['tax'] > 0 ? 'Y' : 'N' ) ); |
|
| 133 | + $authorizeAIM->addLineItem($item['id'], $item['name'], '', $quantity, $item['item_price'], ($use_taxes && !empty($item['tax']) && $item['tax'] > 0 ? 'Y' : 'N')); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - $item_desc = '#' . $invoice->get_number() . ': ' . implode( ', ', $item_desc ); |
|
| 136 | + $item_desc = '#' . $invoice->get_number() . ': ' . implode(', ', $item_desc); |
|
| 137 | 137 | |
| 138 | - if ( $use_taxes && $invoice->get_tax() > 0 ) { |
|
| 139 | - $authorizeAIM->tax = $invoice->get_tax(); |
|
| 138 | + if ($use_taxes && $invoice->get_tax() > 0) { |
|
| 139 | + $authorizeAIM->tax = $invoice->get_tax(); |
|
| 140 | 140 | |
| 141 | - $item_desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) ); |
|
| 141 | + $item_desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true)); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - if ( $invoice->get_discount() > 0 ) { |
|
| 145 | - $item_desc .= ', ' . wp_sprintf( __( 'Discount: %s', 'invoicing' ), $invoice->get_discount( true ) ); |
|
| 144 | + if ($invoice->get_discount() > 0) { |
|
| 145 | + $item_desc .= ', ' . wp_sprintf(__('Discount: %s', 'invoicing'), $invoice->get_discount(true)); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - $authorizeAIM->description = html_entity_decode( $item_desc , ENT_QUOTES, 'UTF-8' ); |
|
| 148 | + $authorizeAIM->description = html_entity_decode($item_desc, ENT_QUOTES, 'UTF-8'); |
|
| 149 | 149 | |
| 150 | 150 | $is_recurring = $invoice->is_recurring(); // Recurring payment. |
| 151 | 151 | |
| 152 | - if ( $is_recurring ) { |
|
| 152 | + if ($is_recurring) { |
|
| 153 | 153 | $authorizeAIM->recurring_billing = true; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | try { |
| 157 | - if ( $is_recurring ) { |
|
| 157 | + if ($is_recurring) { |
|
| 158 | 158 | $response = $authorizeAIM->authorizeOnly(); |
| 159 | 159 | } else { |
| 160 | 160 | $response = $authorizeAIM->authorizeAndCapture(); |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - if ( $response->approved || $response->held ) { |
|
| 164 | - if ( $response->approved ) { |
|
| 165 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
| 163 | + if ($response->approved || $response->held) { |
|
| 164 | + if ($response->approved) { |
|
| 165 | + wpinv_update_payment_status($invoice_id, 'publish'); |
|
| 166 | 166 | } |
| 167 | - wpinv_set_payment_transaction_id( $invoice_id, $response->transaction_id ); |
|
| 167 | + wpinv_set_payment_transaction_id($invoice_id, $response->transaction_id); |
|
| 168 | 168 | |
| 169 | - $message = wp_sprintf( __( 'Authorize.Net Payment: %s with transaction id %s using %s and authorization code %s', 'invoicing' ), $response->response_reason_text, $response->transaction_id, strtoupper( $response->transaction_type ), $response->authorization_code ); |
|
| 169 | + $message = wp_sprintf(__('Authorize.Net Payment: %s with transaction id %s using %s and authorization code %s', 'invoicing'), $response->response_reason_text, $response->transaction_id, strtoupper($response->transaction_type), $response->authorization_code); |
|
| 170 | 170 | |
| 171 | - wpinv_insert_payment_note( $invoice_id, $message ); |
|
| 171 | + wpinv_insert_payment_note($invoice_id, $message); |
|
| 172 | 172 | |
| 173 | - do_action( 'wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card ); |
|
| 173 | + do_action('wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card); |
|
| 174 | 174 | |
| 175 | 175 | wpinv_clear_errors(); |
| 176 | 176 | wpinv_empty_cart(); |
| 177 | 177 | |
| 178 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 178 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
| 179 | 179 | } else { |
| 180 | - if ( !empty( $response->response_reason_text ) ) { |
|
| 181 | - $error = __( $response->response_reason_text, 'invoicing' ); |
|
| 182 | - } else if ( !empty( $response->error_message ) ) { |
|
| 183 | - $error = __( $response->error_message, 'invoicing' ); |
|
| 180 | + if (!empty($response->response_reason_text)) { |
|
| 181 | + $error = __($response->response_reason_text, 'invoicing'); |
|
| 182 | + } else if (!empty($response->error_message)) { |
|
| 183 | + $error = __($response->error_message, 'invoicing'); |
|
| 184 | 184 | } else { |
| 185 | - $error = wp_sprintf( __( 'Error data: %s', 'invoicing' ), print_r( $response, true ) ); |
|
| 185 | + $error = wp_sprintf(__('Error data: %s', 'invoicing'), print_r($response, true)); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - $error = wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $error ); |
|
| 188 | + $error = wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $error); |
|
| 189 | 189 | |
| 190 | - wpinv_set_error( 'payment_error', $error ); |
|
| 191 | - wpinv_record_gateway_error( $error, $response ); |
|
| 192 | - wpinv_insert_payment_note( $invoice_id, $error ); |
|
| 190 | + wpinv_set_error('payment_error', $error); |
|
| 191 | + wpinv_record_gateway_error($error, $response); |
|
| 192 | + wpinv_insert_payment_note($invoice_id, $error); |
|
| 193 | 193 | |
| 194 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
| 194 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
| 195 | 195 | } |
| 196 | - } catch ( AuthorizeNetException $e ) { |
|
| 197 | - wpinv_set_error( 'request_error', $e->getMessage() ); |
|
| 198 | - wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $e->getMessage() ) ); |
|
| 199 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
| 196 | + } catch (AuthorizeNetException $e) { |
|
| 197 | + wpinv_set_error('request_error', $e->getMessage()); |
|
| 198 | + wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $e->getMessage())); |
|
| 199 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
| 200 | 200 | } |
| 201 | 201 | } else { |
| 202 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
| 202 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
| 203 | 203 | } |
| 204 | 204 | } else { |
| 205 | - 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 ); |
|
| 206 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
| 205 | + 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); |
|
| 206 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
| 207 | 207 | } |
| 208 | 208 | } |
| 209 | -add_action( 'wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment' ); |
|
| 209 | +add_action('wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment'); |
|
| 210 | 210 | |
| 211 | -function wpinv_authorizenet_cancel_subscription( $subscription_id = '' ) { |
|
| 212 | - if ( empty( $subscription_id ) ) { |
|
| 211 | +function wpinv_authorizenet_cancel_subscription($subscription_id = '') { |
|
| 212 | + if (empty($subscription_id)) { |
|
| 213 | 213 | return false; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | try { |
| 217 | 217 | $authnetXML = wpinv_authorizenet_XML(); |
| 218 | - $authnetXML->ARBCancelSubscriptionRequest( array( 'subscriptionId' => $subscription_id ) ); |
|
| 218 | + $authnetXML->ARBCancelSubscriptionRequest(array('subscriptionId' => $subscription_id)); |
|
| 219 | 219 | |
| 220 | 220 | return $authnetXML->isSuccessful(); |
| 221 | - } catch( Exception $e ) { |
|
| 222 | - wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) ); |
|
| 221 | + } catch (Exception $e) { |
|
| 222 | + wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing')); |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | return false; |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | -function wpinv_authorizenet_valid_ipn( $md5_hash, $transaction_id, $amount ) { |
|
| 229 | - $authorizenet_md5_hash = wpinv_get_option( 'authorizenet_md5_hash' ); |
|
| 230 | - if ( empty( $authorizenet_md5_hash ) ) { |
|
| 228 | +function wpinv_authorizenet_valid_ipn($md5_hash, $transaction_id, $amount) { |
|
| 229 | + $authorizenet_md5_hash = wpinv_get_option('authorizenet_md5_hash'); |
|
| 230 | + if (empty($authorizenet_md5_hash)) { |
|
| 231 | 231 | return true; |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | - $compare_md5 = strtoupper( md5( $authorizenet_md5_hash . $transaction_id . $amount ) ); |
|
| 234 | + $compare_md5 = strtoupper(md5($authorizenet_md5_hash . $transaction_id . $amount)); |
|
| 235 | 235 | |
| 236 | - return hash_equals( $compare_md5, $md5_hash ); |
|
| 236 | + return hash_equals($compare_md5, $md5_hash); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | function wpinv_authorizenet_AIM() { |
| 240 | - if ( !class_exists( 'AuthorizeNetException' ) ) { |
|
| 241 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php'; |
|
| 240 | + if (!class_exists('AuthorizeNetException')) { |
|
| 241 | + require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php'; |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | - $authorizeAIM = new AuthorizeNetAIM( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ) ); |
|
| 244 | + $authorizeAIM = new AuthorizeNetAIM(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key')); |
|
| 245 | 245 | |
| 246 | - if ( wpinv_is_test_mode( 'authorizenet' ) ) { |
|
| 247 | - $authorizeAIM->setSandbox( true ); |
|
| 246 | + if (wpinv_is_test_mode('authorizenet')) { |
|
| 247 | + $authorizeAIM->setSandbox(true); |
|
| 248 | 248 | } else { |
| 249 | - $authorizeAIM->setSandbox( false ); |
|
| 249 | + $authorizeAIM->setSandbox(false); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | $authorizeAIM->customer_ip = wpinv_get_ip(); |
@@ -255,164 +255,164 @@ discard block |
||
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | function wpinv_authorizenet_XML() { |
| 258 | - if ( !class_exists( 'AuthnetXML' ) ) { |
|
| 259 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php'; |
|
| 258 | + if (!class_exists('AuthnetXML')) { |
|
| 259 | + require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php'; |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - $authnetXML = new AuthnetXML( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ), (bool)wpinv_is_test_mode( 'authorizenet' ) ); |
|
| 262 | + $authnetXML = new AuthnetXML(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'), (bool)wpinv_is_test_mode('authorizenet')); |
|
| 263 | 263 | |
| 264 | 264 | return $authnetXML; |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | -function wpinv_authorizenet_handle_response( $response, $invoice, $card_info = array() ) { |
|
| 268 | - if ( empty( $response ) || empty( $invoice ) ) { |
|
| 267 | +function wpinv_authorizenet_handle_response($response, $invoice, $card_info = array()) { |
|
| 268 | + if (empty($response) || empty($invoice)) { |
|
| 269 | 269 | return false; |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - if ( !empty( $response->approved ) ) { |
|
| 273 | - $subscription = wpinv_authorizenet_create_new_subscription( $invoice, $response, $card_info ); |
|
| 272 | + if (!empty($response->approved)) { |
|
| 273 | + $subscription = wpinv_authorizenet_create_new_subscription($invoice, $response, $card_info); |
|
| 274 | 274 | |
| 275 | - if ( !empty( $subscription ) && $subscription->isSuccessful() ) { |
|
| 276 | - do_action( 'wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet' ); |
|
| 275 | + if (!empty($subscription) && $subscription->isSuccessful()) { |
|
| 276 | + do_action('wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet'); |
|
| 277 | 277 | |
| 278 | - wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ); |
|
| 278 | + wpinv_authorizenet_subscription_record_signup($subscription, $invoice); |
|
| 279 | 279 | |
| 280 | - do_action( 'wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet' ); |
|
| 280 | + do_action('wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet'); |
|
| 281 | 281 | } else { |
| 282 | - if ( isset( $subscription->messages->message ) ) { |
|
| 282 | + if (isset($subscription->messages->message)) { |
|
| 283 | 283 | $error = $subscription->messages->message->code . ': ' . $subscription->messages->message->text; |
| 284 | - wpinv_set_error( 'wpinv_authorize_recurring_error', $error, 'invoicing' ); |
|
| 284 | + wpinv_set_error('wpinv_authorize_recurring_error', $error, 'invoicing'); |
|
| 285 | 285 | } else { |
| 286 | - $error = __( 'Your subscription cannot be created due to an error.', 'invoicing' ); |
|
| 287 | - wpinv_set_error( 'wpinv_authorize_recurring_error', $error ); |
|
| 286 | + $error = __('Your subscription cannot be created due to an error.', 'invoicing'); |
|
| 287 | + wpinv_set_error('wpinv_authorize_recurring_error', $error); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - wpinv_record_gateway_error( $error, $subscription ); |
|
| 290 | + wpinv_record_gateway_error($error, $subscription); |
|
| 291 | 291 | |
| 292 | - wpinv_insert_payment_note( $invoice->ID, wp_sprintf( __( 'Authorize.Net subscription error occurred. %s', 'invoicing' ), $error ) ); |
|
| 292 | + wpinv_insert_payment_note($invoice->ID, wp_sprintf(__('Authorize.Net subscription error occurred. %s', 'invoicing'), $error)); |
|
| 293 | 293 | } |
| 294 | 294 | } |
| 295 | 295 | } |
| 296 | -add_action( 'wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3 ); |
|
| 296 | +add_action('wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3); |
|
| 297 | 297 | |
| 298 | -function wpinv_authorizenet_create_new_subscription( $invoice, $response = array(), $card_info = array() ) { |
|
| 299 | - if ( empty( $invoice ) ) { |
|
| 298 | +function wpinv_authorizenet_create_new_subscription($invoice, $response = array(), $card_info = array()) { |
|
| 299 | + if (empty($invoice)) { |
|
| 300 | 300 | return false; |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - $params = wpinv_authorizenet_generate_subscription_params( $invoice, $card_info, $response ); |
|
| 303 | + $params = wpinv_authorizenet_generate_subscription_params($invoice, $card_info, $response); |
|
| 304 | 304 | |
| 305 | 305 | try { |
| 306 | 306 | $authnetXML = wpinv_authorizenet_XML(); |
| 307 | - $authnetXML->ARBCreateSubscriptionRequest( $params ); |
|
| 308 | - } catch( Exception $e ) { |
|
| 307 | + $authnetXML->ARBCreateSubscriptionRequest($params); |
|
| 308 | + } catch (Exception $e) { |
|
| 309 | 309 | $authnetXML = array(); |
| 310 | - wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) ); |
|
| 310 | + wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing')); |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | return $authnetXML; |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | -function wpinv_authorizenet_generate_subscription_params( $invoice, $card_info = array(), $response = array() ) { |
|
| 317 | - if ( empty( $invoice ) ) { |
|
| 316 | +function wpinv_authorizenet_generate_subscription_params($invoice, $card_info = array(), $response = array()) { |
|
| 317 | + if (empty($invoice)) { |
|
| 318 | 318 | return false; |
| 319 | 319 | } |
| 320 | 320 | |
| 321 | - $subscription_item = $invoice->get_recurring( true ); |
|
| 322 | - if ( empty( $subscription_item ) ) { |
|
| 321 | + $subscription_item = $invoice->get_recurring(true); |
|
| 322 | + if (empty($subscription_item)) { |
|
| 323 | 323 | return false; |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | - $card_details = wpinv_authorizenet_generate_card_info( $card_info ); |
|
| 326 | + $card_details = wpinv_authorizenet_generate_card_info($card_info); |
|
| 327 | 327 | $subscription_name = $invoice->get_subscription_name(); |
| 328 | - $initial_amount = wpinv_format_amount( $invoice->get_total() ); |
|
| 329 | - $recurring_amount = wpinv_format_amount( $invoice->get_recurring_details( 'total' ) ); |
|
| 328 | + $initial_amount = wpinv_format_amount($invoice->get_total()); |
|
| 329 | + $recurring_amount = wpinv_format_amount($invoice->get_recurring_details('total')); |
|
| 330 | 330 | $interval = $subscription_item->get_recurring_interval(); |
| 331 | 331 | $period = $subscription_item->get_recurring_period(); |
| 332 | 332 | $bill_times = (int)$subscription_item->get_recurring_limit(); |
| 333 | 333 | $bill_times = $bill_times > 0 ? $bill_times : 9999; |
| 334 | 334 | |
| 335 | - $time_period = wpinv_authorizenet_get_time_period( $interval, $period ); |
|
| 335 | + $time_period = wpinv_authorizenet_get_time_period($interval, $period); |
|
| 336 | 336 | $interval = $time_period['interval']; |
| 337 | 337 | $period = $time_period['period']; |
| 338 | 338 | |
| 339 | 339 | $current_tz = date_default_timezone_get(); |
| 340 | - date_default_timezone_set( 'America/Denver' ); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts. |
|
| 341 | - $today = date( 'Y-m-d' ); |
|
| 342 | - date_default_timezone_set( $current_tz ); |
|
| 340 | + date_default_timezone_set('America/Denver'); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts. |
|
| 341 | + $today = date('Y-m-d'); |
|
| 342 | + date_default_timezone_set($current_tz); |
|
| 343 | 343 | |
| 344 | 344 | $free_trial = $invoice->is_free_trial(); |
| 345 | - if ( $free_trial && $subscription_item->has_free_trial() ) { |
|
| 345 | + if ($free_trial && $subscription_item->has_free_trial()) { |
|
| 346 | 346 | $trial_interval = $subscription_item->get_trial_interval(); |
| 347 | - $trial_period = $subscription_item->get_trial_period( true ); |
|
| 347 | + $trial_period = $subscription_item->get_trial_period(true); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | $subscription = array(); |
| 351 | 351 | $subscription['name'] = $subscription_name; |
| 352 | 352 | |
| 353 | 353 | $subscription['paymentSchedule'] = array( |
| 354 | - 'interval' => array( 'length' => $interval, 'unit' => $period ), |
|
| 354 | + 'interval' => array('length' => $interval, 'unit' => $period), |
|
| 355 | 355 | 'startDate' => $today, |
| 356 | 356 | 'totalOccurrences' => $bill_times, |
| 357 | - 'trialOccurrences' => $free_trial || ( $initial_amount != $recurring_amount ) ? 1 : 0, |
|
| 357 | + 'trialOccurrences' => $free_trial || ($initial_amount != $recurring_amount) ? 1 : 0, |
|
| 358 | 358 | ); |
| 359 | 359 | |
| 360 | 360 | $subscription['amount'] = $recurring_amount; |
| 361 | 361 | $subscription['trialAmount'] = $initial_amount; |
| 362 | - $subscription['payment'] = array( 'creditCard' => $card_details ); |
|
| 363 | - $subscription['order'] = array( 'invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number() ); |
|
| 364 | - $subscription['customer'] = array( 'id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone ); |
|
| 362 | + $subscription['payment'] = array('creditCard' => $card_details); |
|
| 363 | + $subscription['order'] = array('invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number()); |
|
| 364 | + $subscription['customer'] = array('id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone); |
|
| 365 | 365 | |
| 366 | 366 | $subscription['billTo'] = array( |
| 367 | 367 | 'firstName' => $invoice->get_first_name(), |
| 368 | 368 | 'lastName' => $invoice->get_last_name(), |
| 369 | 369 | 'company' => $invoice->company, |
| 370 | - 'address' => wp_strip_all_tags( $invoice->get_address(), true ), |
|
| 370 | + 'address' => wp_strip_all_tags($invoice->get_address(), true), |
|
| 371 | 371 | 'city' => $invoice->city, |
| 372 | 372 | 'state' => $invoice->state, |
| 373 | 373 | 'zip' => $invoice->zip, |
| 374 | 374 | 'country' => $invoice->country, |
| 375 | 375 | ); |
| 376 | 376 | |
| 377 | - $params = array( 'subscription' => $subscription ); |
|
| 377 | + $params = array('subscription' => $subscription); |
|
| 378 | 378 | |
| 379 | - return apply_filters( 'wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response ); |
|
| 379 | + return apply_filters('wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response); |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | -function wpinv_authorizenet_generate_card_info( $card_info = array() ) { |
|
| 383 | - $card_defaults = array( |
|
| 382 | +function wpinv_authorizenet_generate_card_info($card_info = array()) { |
|
| 383 | + $card_defaults = array( |
|
| 384 | 384 | 'cc_owner' => null, |
| 385 | 385 | 'cc_number' => null, |
| 386 | 386 | 'cc_expire_month' => null, |
| 387 | 387 | 'cc_expire_year' => null, |
| 388 | 388 | 'cc_cvv2' => null, |
| 389 | 389 | ); |
| 390 | - $card_info = wp_parse_args( $card_info, $card_defaults ); |
|
| 390 | + $card_info = wp_parse_args($card_info, $card_defaults); |
|
| 391 | 391 | |
| 392 | 392 | $card_details = array( |
| 393 | - 'cardNumber' => str_replace( ' ', '', sanitize_text_field( $card_info['cc_number'] ) ), |
|
| 394 | - 'expirationDate' => sanitize_text_field( $card_info['cc_expire_month'] ) . sanitize_text_field( $card_info['cc_expire_year'] ), |
|
| 395 | - 'cardCode' => sanitize_text_field( $card_info['cc_cvv2'] ), |
|
| 393 | + 'cardNumber' => str_replace(' ', '', sanitize_text_field($card_info['cc_number'])), |
|
| 394 | + 'expirationDate' => sanitize_text_field($card_info['cc_expire_month']) . sanitize_text_field($card_info['cc_expire_year']), |
|
| 395 | + 'cardCode' => sanitize_text_field($card_info['cc_cvv2']), |
|
| 396 | 396 | ); |
| 397 | 397 | |
| 398 | 398 | return $card_details; |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | -function wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ) { |
|
| 402 | - if ( empty( $invoice ) || empty( $subscription ) ) { |
|
| 401 | +function wpinv_authorizenet_subscription_record_signup($subscription, $invoice) { |
|
| 402 | + if (empty($invoice) || empty($subscription)) { |
|
| 403 | 403 | return false; |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | - $subscription_item = $invoice->get_recurring( true ); |
|
| 407 | - if ( empty( $subscription_item ) ) { |
|
| 406 | + $subscription_item = $invoice->get_recurring(true); |
|
| 407 | + if (empty($subscription_item)) { |
|
| 408 | 408 | return false; |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | $invoice_id = $invoice->ID; |
| 412 | 412 | $subscriptionId = (array)$subscription->subscriptionId; |
| 413 | - $subscription_id = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $invoice_id; |
|
| 413 | + $subscription_id = !empty($subscriptionId[0]) ? $subscriptionId[0] : $invoice_id; |
|
| 414 | 414 | |
| 415 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Authorize.Net Subscription ID: %s', 'invoicing' ) , $subscription_id ) ); |
|
| 415 | + wpinv_insert_payment_note($invoice_id, sprintf(__('Authorize.Net Subscription ID: %s', 'invoicing'), $subscription_id)); |
|
| 416 | 416 | |
| 417 | 417 | $status = $invoice->is_free_trial() && $subscription_item->has_free_trial() ? 'trialing' : 'active'; |
| 418 | 418 | |
@@ -420,16 +420,16 @@ discard block |
||
| 420 | 420 | 'profile_id' => $subscription_id, |
| 421 | 421 | 'item_id' => $subscription_item->ID, |
| 422 | 422 | 'initial_amount' => $invoice->get_total(), |
| 423 | - 'recurring_amount' => $invoice->get_recurring_details( 'total' ), |
|
| 423 | + 'recurring_amount' => $invoice->get_recurring_details('total'), |
|
| 424 | 424 | 'period' => $subscription_item->get_recurring_period(), |
| 425 | 425 | 'interval' => $subscription_item->get_recurring_interval(), |
| 426 | 426 | 'bill_times' => $subscription_item->get_recurring_limit(), |
| 427 | - 'expiration' => $invoice->get_new_expiration( $subscription_item->ID ), |
|
| 427 | + 'expiration' => $invoice->get_new_expiration($subscription_item->ID), |
|
| 428 | 428 | 'status' => $status, |
| 429 | - 'created' => current_time( 'mysql', 0 ) |
|
| 429 | + 'created' => current_time('mysql', 0) |
|
| 430 | 430 | ); |
| 431 | 431 | |
| 432 | - if ( $invoice->is_free_trial() && $subscription_item->has_free_trial() ) { |
|
| 432 | + if ($invoice->is_free_trial() && $subscription_item->has_free_trial()) { |
|
| 433 | 433 | $args['trial_period'] = $subscription_item->get_trial_period(); |
| 434 | 434 | $args['trial_interval'] = $subscription_item->get_trial_interval(); |
| 435 | 435 | } else { |
@@ -437,58 +437,58 @@ discard block |
||
| 437 | 437 | $args['trial_interval'] = 0; |
| 438 | 438 | } |
| 439 | 439 | |
| 440 | - return $invoice->update_subscription( $args ); |
|
| 440 | + return $invoice->update_subscription($args); |
|
| 441 | 441 | } |
| 442 | 442 | |
| 443 | -function wpinv_authorizenet_validate_checkout( $valid_data, $post ) { |
|
| 444 | - if ( !empty( $post['wpi-gateway'] ) && $post['wpi-gateway'] == 'authorizenet' ) { |
|
| 443 | +function wpinv_authorizenet_validate_checkout($valid_data, $post) { |
|
| 444 | + if (!empty($post['wpi-gateway']) && $post['wpi-gateway'] == 'authorizenet') { |
|
| 445 | 445 | $error = false; |
| 446 | 446 | |
| 447 | - if ( empty( $post['authorizenet']['cc_owner'] ) ) { |
|
| 447 | + if (empty($post['authorizenet']['cc_owner'])) { |
|
| 448 | 448 | $error = true; |
| 449 | - wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing')); |
|
| 449 | + wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing')); |
|
| 450 | 450 | } |
| 451 | - if ( empty( $post['authorizenet']['cc_number'] ) ) { |
|
| 451 | + if (empty($post['authorizenet']['cc_number'])) { |
|
| 452 | 452 | $error = true; |
| 453 | - wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing')); |
|
| 453 | + wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing')); |
|
| 454 | 454 | } |
| 455 | - if ( empty( $post['authorizenet']['cc_expire_month'] ) ) { |
|
| 455 | + if (empty($post['authorizenet']['cc_expire_month'])) { |
|
| 456 | 456 | $error = true; |
| 457 | - wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing')); |
|
| 457 | + wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing')); |
|
| 458 | 458 | } |
| 459 | - if ( empty( $post['authorizenet']['cc_expire_year'] ) ) { |
|
| 459 | + if (empty($post['authorizenet']['cc_expire_year'])) { |
|
| 460 | 460 | $error = true; |
| 461 | - wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing')); |
|
| 461 | + wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing')); |
|
| 462 | 462 | } |
| 463 | - if ( empty( $post['authorizenet']['cc_cvv2'] ) ) { |
|
| 463 | + if (empty($post['authorizenet']['cc_cvv2'])) { |
|
| 464 | 464 | $error = true; |
| 465 | - wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) ); |
|
| 465 | + wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing')); |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | - if ( $error ) { |
|
| 468 | + if ($error) { |
|
| 469 | 469 | return; |
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | $invoice = wpinv_get_invoice_cart(); |
| 473 | 473 | |
| 474 | - if ( !empty( $invoice ) && $subscription_item = $invoice->get_recurring( true ) ) { |
|
| 475 | - $subscription_item = $invoice->get_recurring( true ); |
|
| 474 | + if (!empty($invoice) && $subscription_item = $invoice->get_recurring(true)) { |
|
| 475 | + $subscription_item = $invoice->get_recurring(true); |
|
| 476 | 476 | |
| 477 | 477 | $interval = $subscription_item->get_recurring_interval(); |
| 478 | 478 | $period = $subscription_item->get_recurring_period(); |
| 479 | 479 | |
| 480 | - if ( $period == 'D' && ( $interval < 7 || $interval > 365 ) ) { |
|
| 481 | - wpinv_set_error( 'authorizenet_subscription_error', __( 'Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing' ) ); |
|
| 480 | + if ($period == 'D' && ($interval < 7 || $interval > 365)) { |
|
| 481 | + wpinv_set_error('authorizenet_subscription_error', __('Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing')); |
|
| 482 | 482 | } |
| 483 | 483 | } |
| 484 | 484 | } |
| 485 | 485 | } |
| 486 | -add_action( 'wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2 ); |
|
| 486 | +add_action('wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2); |
|
| 487 | 487 | |
| 488 | -function wpinv_authorizenet_get_time_period( $subscription_interval, $subscription_period ) { |
|
| 489 | - $subscription_interval = absint( $subscription_interval ); |
|
| 488 | +function wpinv_authorizenet_get_time_period($subscription_interval, $subscription_period) { |
|
| 489 | + $subscription_interval = absint($subscription_interval); |
|
| 490 | 490 | |
| 491 | - switch( $subscription_period ) { |
|
| 491 | + switch ($subscription_period) { |
|
| 492 | 492 | case 'W': |
| 493 | 493 | case 'week': |
| 494 | 494 | case 'weeks': |
@@ -498,14 +498,14 @@ discard block |
||
| 498 | 498 | case 'M': |
| 499 | 499 | case 'month': |
| 500 | 500 | case 'months': |
| 501 | - if ( $subscription_interval > 12 ) { |
|
| 501 | + if ($subscription_interval > 12) { |
|
| 502 | 502 | $subscription_interval = 12; |
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | $interval = $subscription_interval; |
| 506 | 506 | $period = 'months'; |
| 507 | 507 | |
| 508 | - if ( !( $subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12 ) ) { |
|
| 508 | + if (!($subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12)) { |
|
| 509 | 509 | $interval = $subscription_interval * 30; |
| 510 | 510 | $period = 'days'; |
| 511 | 511 | } |
@@ -522,40 +522,40 @@ discard block |
||
| 522 | 522 | break; |
| 523 | 523 | } |
| 524 | 524 | |
| 525 | - return compact( 'interval', 'period' ); |
|
| 525 | + return compact('interval', 'period'); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | function wpinv_authorizenet_process_ipn() { |
| 529 | - if ( !( !empty( $_REQUEST['wpi-gateway'] ) && $_REQUEST['wpi-gateway'] == 'authorizenet' ) ) { |
|
| 529 | + if (!(!empty($_REQUEST['wpi-gateway']) && $_REQUEST['wpi-gateway'] == 'authorizenet')) { |
|
| 530 | 530 | return; |
| 531 | 531 | } |
| 532 | 532 | |
| 533 | - $subscription_id = intval( $_POST['x_subscription_id'] ); |
|
| 533 | + $subscription_id = intval($_POST['x_subscription_id']); |
|
| 534 | 534 | |
| 535 | - if ( $subscription_id ) { |
|
| 536 | - $transaction_id = sanitize_text_field( $_POST['x_trans_id'] ); |
|
| 537 | - $renewal_amount = sanitize_text_field( $_POST['x_amount'] ); |
|
| 538 | - $response_code = intval( $_POST['x_response_code'] ); |
|
| 539 | - $reason_code = intval( $_POST['x_response_reason_code'] ); |
|
| 535 | + if ($subscription_id) { |
|
| 536 | + $transaction_id = sanitize_text_field($_POST['x_trans_id']); |
|
| 537 | + $renewal_amount = sanitize_text_field($_POST['x_amount']); |
|
| 538 | + $response_code = intval($_POST['x_response_code']); |
|
| 539 | + $reason_code = intval($_POST['x_response_reason_code']); |
|
| 540 | 540 | |
| 541 | - if ( 1 == $response_code ) { |
|
| 541 | + if (1 == $response_code) { |
|
| 542 | 542 | // Approved |
| 543 | - do_action( 'wpinv_authorizenet_renewal_payment', $transaction_id ); |
|
| 544 | - } else if ( 2 == $response_code ) { |
|
| 543 | + do_action('wpinv_authorizenet_renewal_payment', $transaction_id); |
|
| 544 | + } else if (2 == $response_code) { |
|
| 545 | 545 | // Declined |
| 546 | - do_action( 'wpinv_authorizenet_renewal_payment_failed', $transaction_id ); |
|
| 547 | - do_action( 'wpinv_authorizenet_renewal_error', $transaction_id ); |
|
| 548 | - } else if ( 3 == $response_code || 8 == $reason_code ) { |
|
| 546 | + do_action('wpinv_authorizenet_renewal_payment_failed', $transaction_id); |
|
| 547 | + do_action('wpinv_authorizenet_renewal_error', $transaction_id); |
|
| 548 | + } else if (3 == $response_code || 8 == $reason_code) { |
|
| 549 | 549 | // An expired card |
| 550 | - do_action( 'wpinv_authorizenet_renewal_payment_failed', $transaction_id ); |
|
| 551 | - do_action( 'wpinv_authorizenet_renewal_payment_error', $transaction_id ); |
|
| 550 | + do_action('wpinv_authorizenet_renewal_payment_failed', $transaction_id); |
|
| 551 | + do_action('wpinv_authorizenet_renewal_payment_error', $transaction_id); |
|
| 552 | 552 | |
| 553 | 553 | } else { |
| 554 | 554 | // Other Error |
| 555 | - do_action( 'wpinv_authorizenet_renewal_payment_error', $subscription ); |
|
| 555 | + do_action('wpinv_authorizenet_renewal_payment_error', $subscription); |
|
| 556 | 556 | } |
| 557 | 557 | |
| 558 | 558 | exit; |
| 559 | 559 | } |
| 560 | 560 | } |
| 561 | -add_action( 'wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn' ); |
|
| 562 | 561 | \ No newline at end of file |
| 562 | +add_action('wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn'); |
|
| 563 | 563 | \ 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_filter( 'wpinv_authorizenet_support_subscription', '__return_true' ); |
| 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_manual_cc_form', '__return_false' ); |
|
| 5 | +add_action('wpinv_manual_cc_form', '__return_false'); |
|
| 6 | 6 | |
| 7 | -function wpinv_process_manual_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_manual_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 | /* |
@@ -41,20 +41,20 @@ discard block |
||
| 41 | 41 | ); |
| 42 | 42 | |
| 43 | 43 | // Record the pending payment |
| 44 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
| 44 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
| 45 | 45 | |
| 46 | - if ( !empty( $invoice ) ) { |
|
| 47 | - wpinv_set_payment_transaction_id( $invoice->ID, $invoice->generate_key() ); |
|
| 48 | - wpinv_update_payment_status( $invoice, 'publish' ); |
|
| 46 | + if (!empty($invoice)) { |
|
| 47 | + wpinv_set_payment_transaction_id($invoice->ID, $invoice->generate_key()); |
|
| 48 | + wpinv_update_payment_status($invoice, 'publish'); |
|
| 49 | 49 | |
| 50 | 50 | // Empty the shopping cart |
| 51 | 51 | wpinv_empty_cart(); |
| 52 | 52 | |
| 53 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 53 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
| 54 | 54 | } else { |
| 55 | - wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice ); |
|
| 55 | + wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice); |
|
| 56 | 56 | // If errors are present, send the user back to the purchase page so they can be corrected |
| 57 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
| 57 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | -add_action( 'wpinv_gateway_manual', 'wpinv_process_manual_payment' ); |
|
| 61 | 60 | \ No newline at end of file |
| 61 | +add_action('wpinv_gateway_manual', 'wpinv_process_manual_payment'); |
|
| 62 | 62 | \ 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_manual_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,37 +24,37 @@ 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, 'pending' ); |
|
| 29 | + if (!empty($invoice)) { |
|
| 30 | + wpinv_set_payment_transaction_id($invoice->ID, $invoice->generate_key()); |
|
| 31 | + wpinv_update_payment_status($invoice, 'pending'); |
|
| 32 | 32 | |
| 33 | 33 | // Empty the shopping cart |
| 34 | 34 | wpinv_empty_cart(); |
| 35 | 35 | |
| 36 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 36 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
| 37 | 37 | } else { |
| 38 | - 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 ); |
|
| 38 | + 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); |
|
| 39 | 39 | // If errors are present, send the user back to the purchase page so they can be corrected |
| 40 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
| 40 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | -add_action( 'wpinv_gateway_bank_transfer', 'wpinv_process_bank_transfer_payment' ); |
|
| 43 | +add_action('wpinv_gateway_bank_transfer', 'wpinv_process_bank_transfer_payment'); |
|
| 44 | 44 | |
| 45 | -function wpinv_show_bank_info( $invoice ) { |
|
| 46 | - if ( !empty( $invoice ) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'pending' ) { |
|
| 47 | - $bank_info = wpinv_get_bank_info( true ); |
|
| 45 | +function wpinv_show_bank_info($invoice) { |
|
| 46 | + if (!empty($invoice) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'pending') { |
|
| 47 | + $bank_info = wpinv_get_bank_info(true); |
|
| 48 | 48 | ?> |
| 49 | 49 | <div class="wpinv-bank-details"> |
| 50 | - <?php if ( $instructions = wpinv_get_bank_instructions() ) { ?> |
|
| 51 | - <div class="alert bg-info"><?php echo wpautop( wp_kses_post( $instructions ) ); ?></div> |
|
| 50 | + <?php if ($instructions = wpinv_get_bank_instructions()) { ?> |
|
| 51 | + <div class="alert bg-info"><?php echo wpautop(wp_kses_post($instructions)); ?></div> |
|
| 52 | 52 | <?php } ?> |
| 53 | - <?php if ( !empty( $bank_info ) ) { ?> |
|
| 54 | - <h3 class="wpinv-bank-t"><?php echo apply_filters( 'wpinv_receipt_bank_details_title', __( 'Our Bank Details', 'invoicing' ) ); ?></h3> |
|
| 53 | + <?php if (!empty($bank_info)) { ?> |
|
| 54 | + <h3 class="wpinv-bank-t"><?php echo apply_filters('wpinv_receipt_bank_details_title', __('Our Bank Details', 'invoicing')); ?></h3> |
|
| 55 | 55 | <table class="table table-bordered table-sm wpi-bank-details"> |
| 56 | - <?php foreach ( $bank_info as $key => $info ) { ?> |
|
| 57 | - <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> |
|
| 56 | + <?php foreach ($bank_info as $key => $info) { ?> |
|
| 57 | + <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 | 58 | <?php } ?> |
| 59 | 59 | </table> |
| 60 | 60 | <?php } ?> |
@@ -62,15 +62,15 @@ discard block |
||
| 62 | 62 | <?php |
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | -add_action( 'wpinv_before_receipt_details', 'wpinv_show_bank_info', 10, 1 ); |
|
| 65 | +add_action('wpinv_before_receipt_details', 'wpinv_show_bank_info', 10, 1); |
|
| 66 | 66 | |
| 67 | -function wpinv_invoice_print_bank_info( $invoice ) { |
|
| 68 | - if ( !empty( $invoice ) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'pending' ) { |
|
| 67 | +function wpinv_invoice_print_bank_info($invoice) { |
|
| 68 | + if (!empty($invoice) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'pending') { |
|
| 69 | 69 | ?> |
| 70 | 70 | <div class="row wpinv-bank-info"> |
| 71 | - <?php echo wpinv_show_bank_info( $invoice ); ?> |
|
| 71 | + <?php echo wpinv_show_bank_info($invoice); ?> |
|
| 72 | 72 | </div> |
| 73 | 73 | <?php |
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | -add_action( 'wpinv_invoice_print_after_top_content', 'wpinv_invoice_print_bank_info', 10, 1 ); |
|
| 77 | 76 | \ No newline at end of file |
| 77 | +add_action('wpinv_invoice_print_after_top_content', 'wpinv_invoice_print_bank_info', 10, 1); |
|
| 78 | 78 | \ 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,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' => '', |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | 'notify_url' => $listener_url, |
| 66 | 66 | 'cbt' => get_bloginfo( 'name' ), |
| 67 | 67 | 'bn' => 'WPInvoicing_SP', |
| 68 | - 'lc' => 'US' // this will force paypal site to english |
|
| 68 | + 'lc' => 'US' // this will force paypal site to english |
|
| 69 | 69 | ); |
| 70 | 70 | |
| 71 | 71 | $paypal_args['address1'] = $invoice->get_address(); |
@@ -217,261 +217,261 @@ discard block |
||
| 217 | 217 | add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 ); |
| 218 | 218 | |
| 219 | 219 | function wpinv_process_paypal_ipn() { |
| 220 | - // Check the request method is POST |
|
| 221 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
| 222 | - return; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - // Set initial post data to empty string |
|
| 226 | - $post_data = ''; |
|
| 227 | - |
|
| 228 | - // Fallback just in case post_max_size is lower than needed |
|
| 229 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
| 230 | - $post_data = file_get_contents( 'php://input' ); |
|
| 231 | - } else { |
|
| 232 | - // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
|
| 233 | - ini_set( 'post_max_size', '12M' ); |
|
| 234 | - } |
|
| 235 | - // Start the encoded data collection with notification command |
|
| 236 | - $encoded_data = 'cmd=_notify-validate'; |
|
| 237 | - |
|
| 238 | - // Get current arg separator |
|
| 239 | - $arg_separator = wpinv_get_php_arg_separator_output(); |
|
| 240 | - |
|
| 241 | - // Verify there is a post_data |
|
| 242 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
| 243 | - // Append the data |
|
| 244 | - $encoded_data .= $arg_separator.$post_data; |
|
| 245 | - } else { |
|
| 246 | - // Check if POST is empty |
|
| 247 | - if ( empty( $_POST ) ) { |
|
| 248 | - // Nothing to do |
|
| 249 | - return; |
|
| 250 | - } else { |
|
| 251 | - // Loop through each POST |
|
| 252 | - foreach ( $_POST as $key => $value ) { |
|
| 253 | - // Encode the value and append the data |
|
| 254 | - $encoded_data .= $arg_separator."$key=" . urlencode( $value ); |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - // Convert collected post data to an array |
|
| 260 | - parse_str( $encoded_data, $encoded_data_array ); |
|
| 261 | - |
|
| 262 | - foreach ( $encoded_data_array as $key => $value ) { |
|
| 263 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
| 264 | - $new_key = str_replace( '&', '&', $key ); |
|
| 265 | - $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
| 266 | - |
|
| 267 | - unset( $encoded_data_array[ $key ] ); |
|
| 268 | - $encoded_data_array[ $new_key ] = $value; |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - // Get the PayPal redirect uri |
|
| 273 | - $paypal_redirect = wpinv_get_paypal_redirect( true ); |
|
| 274 | - |
|
| 275 | - if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
| 276 | - // Validate the IPN |
|
| 277 | - |
|
| 278 | - $remote_post_vars = array( |
|
| 279 | - 'method' => 'POST', |
|
| 280 | - 'timeout' => 45, |
|
| 281 | - 'redirection' => 5, |
|
| 282 | - 'httpversion' => '1.1', |
|
| 283 | - 'blocking' => true, |
|
| 284 | - 'headers' => array( |
|
| 285 | - 'host' => 'www.paypal.com', |
|
| 286 | - 'connection' => 'close', |
|
| 287 | - 'content-type' => 'application/x-www-form-urlencoded', |
|
| 288 | - 'post' => '/cgi-bin/webscr HTTP/1.1', |
|
| 289 | - |
|
| 290 | - ), |
|
| 291 | - 'sslverify' => false, |
|
| 292 | - 'body' => $encoded_data_array |
|
| 293 | - ); |
|
| 294 | - |
|
| 295 | - // Get response |
|
| 296 | - $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars ); |
|
| 297 | - |
|
| 298 | - if ( is_wp_error( $api_response ) ) { |
|
| 299 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
| 300 | - return; // Something went wrong |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
| 304 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
| 305 | - return; // Response not okay |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - // Check if $post_data_array has been populated |
|
| 310 | - if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) |
|
| 311 | - return; |
|
| 312 | - |
|
| 313 | - $defaults = array( |
|
| 314 | - 'txn_type' => '', |
|
| 315 | - 'payment_status' => '' |
|
| 316 | - ); |
|
| 317 | - |
|
| 318 | - $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
| 319 | - |
|
| 320 | - $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
| 220 | + // Check the request method is POST |
|
| 221 | + if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
| 222 | + return; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + // Set initial post data to empty string |
|
| 226 | + $post_data = ''; |
|
| 227 | + |
|
| 228 | + // Fallback just in case post_max_size is lower than needed |
|
| 229 | + if ( ini_get( 'allow_url_fopen' ) ) { |
|
| 230 | + $post_data = file_get_contents( 'php://input' ); |
|
| 231 | + } else { |
|
| 232 | + // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
|
| 233 | + ini_set( 'post_max_size', '12M' ); |
|
| 234 | + } |
|
| 235 | + // Start the encoded data collection with notification command |
|
| 236 | + $encoded_data = 'cmd=_notify-validate'; |
|
| 237 | + |
|
| 238 | + // Get current arg separator |
|
| 239 | + $arg_separator = wpinv_get_php_arg_separator_output(); |
|
| 240 | + |
|
| 241 | + // Verify there is a post_data |
|
| 242 | + if ( $post_data || strlen( $post_data ) > 0 ) { |
|
| 243 | + // Append the data |
|
| 244 | + $encoded_data .= $arg_separator.$post_data; |
|
| 245 | + } else { |
|
| 246 | + // Check if POST is empty |
|
| 247 | + if ( empty( $_POST ) ) { |
|
| 248 | + // Nothing to do |
|
| 249 | + return; |
|
| 250 | + } else { |
|
| 251 | + // Loop through each POST |
|
| 252 | + foreach ( $_POST as $key => $value ) { |
|
| 253 | + // Encode the value and append the data |
|
| 254 | + $encoded_data .= $arg_separator."$key=" . urlencode( $value ); |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + // Convert collected post data to an array |
|
| 260 | + parse_str( $encoded_data, $encoded_data_array ); |
|
| 261 | + |
|
| 262 | + foreach ( $encoded_data_array as $key => $value ) { |
|
| 263 | + if ( false !== strpos( $key, 'amp;' ) ) { |
|
| 264 | + $new_key = str_replace( '&', '&', $key ); |
|
| 265 | + $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
| 266 | + |
|
| 267 | + unset( $encoded_data_array[ $key ] ); |
|
| 268 | + $encoded_data_array[ $new_key ] = $value; |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + // Get the PayPal redirect uri |
|
| 273 | + $paypal_redirect = wpinv_get_paypal_redirect( true ); |
|
| 274 | + |
|
| 275 | + if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
| 276 | + // Validate the IPN |
|
| 277 | + |
|
| 278 | + $remote_post_vars = array( |
|
| 279 | + 'method' => 'POST', |
|
| 280 | + 'timeout' => 45, |
|
| 281 | + 'redirection' => 5, |
|
| 282 | + 'httpversion' => '1.1', |
|
| 283 | + 'blocking' => true, |
|
| 284 | + 'headers' => array( |
|
| 285 | + 'host' => 'www.paypal.com', |
|
| 286 | + 'connection' => 'close', |
|
| 287 | + 'content-type' => 'application/x-www-form-urlencoded', |
|
| 288 | + 'post' => '/cgi-bin/webscr HTTP/1.1', |
|
| 289 | + |
|
| 290 | + ), |
|
| 291 | + 'sslverify' => false, |
|
| 292 | + 'body' => $encoded_data_array |
|
| 293 | + ); |
|
| 294 | + |
|
| 295 | + // Get response |
|
| 296 | + $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars ); |
|
| 297 | + |
|
| 298 | + if ( is_wp_error( $api_response ) ) { |
|
| 299 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
| 300 | + return; // Something went wrong |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
| 304 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
| 305 | + return; // Response not okay |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + // Check if $post_data_array has been populated |
|
| 310 | + if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) |
|
| 311 | + return; |
|
| 312 | + |
|
| 313 | + $defaults = array( |
|
| 314 | + 'txn_type' => '', |
|
| 315 | + 'payment_status' => '' |
|
| 316 | + ); |
|
| 317 | + |
|
| 318 | + $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
| 319 | + |
|
| 320 | + $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
| 321 | 321 | |
| 322 | - wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ ); |
|
| 323 | - |
|
| 324 | - if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
| 325 | - // Allow PayPal IPN types to be processed separately |
|
| 326 | - do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id ); |
|
| 327 | - } else { |
|
| 328 | - // Fallback to web accept just in case the txn_type isn't present |
|
| 329 | - do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id ); |
|
| 330 | - } |
|
| 331 | - exit; |
|
| 322 | + wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ ); |
|
| 323 | + |
|
| 324 | + if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
| 325 | + // Allow PayPal IPN types to be processed separately |
|
| 326 | + do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id ); |
|
| 327 | + } else { |
|
| 328 | + // Fallback to web accept just in case the txn_type isn't present |
|
| 329 | + do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id ); |
|
| 330 | + } |
|
| 331 | + exit; |
|
| 332 | 332 | } |
| 333 | 333 | add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' ); |
| 334 | 334 | |
| 335 | 335 | function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) { |
| 336 | - if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
| 337 | - return; |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - if( empty( $invoice_id ) ) { |
|
| 341 | - return; |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - // Collect payment details |
|
| 345 | - $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
| 346 | - $paypal_amount = $data['mc_gross']; |
|
| 347 | - $payment_status = strtolower( $data['payment_status'] ); |
|
| 348 | - $currency_code = strtolower( $data['mc_currency'] ); |
|
| 349 | - $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
| 350 | - $payment_meta = wpinv_get_invoice_meta( $invoice_id ); |
|
| 351 | - |
|
| 352 | - if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) { |
|
| 353 | - return; // this isn't a PayPal standard IPN |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - // Verify payment recipient |
|
| 357 | - if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) { |
|
| 358 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 359 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 360 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ) ); |
|
| 361 | - return; |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - // Verify payment currency |
|
| 365 | - if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
| 366 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 367 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 368 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ) ); |
|
| 369 | - return; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - if ( !wpinv_get_payment_user_email( $invoice_id ) ) { |
|
| 373 | - // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal |
|
| 374 | - // No email associated with purchase, so store from PayPal |
|
| 375 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] ); |
|
| 376 | - |
|
| 377 | - // Setup and store the customer's details |
|
| 378 | - $user_info = array( |
|
| 379 | - 'user_id' => '-1', |
|
| 380 | - 'email' => sanitize_text_field( $data['payer_email'] ), |
|
| 381 | - 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
| 382 | - 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
| 383 | - 'discount' => '', |
|
| 384 | - ); |
|
| 385 | - $user_info['address'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
| 386 | - $user_info['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
| 387 | - $user_info['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
| 388 | - $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
| 389 | - $user_info['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
| 390 | - |
|
| 391 | - $payment_meta['user_info'] = $user_info; |
|
| 392 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta ); |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
| 396 | - // Process a refund |
|
| 397 | - wpinv_process_paypal_refund( $data, $invoice_id ); |
|
| 398 | - } else { |
|
| 399 | - if ( get_post_status( $invoice_id ) == 'publish' ) { |
|
| 400 | - return; // Only paid payments once |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - // Retrieve the total purchase amount (before PayPal) |
|
| 404 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
| 405 | - |
|
| 406 | - if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
| 407 | - // The prices don't match |
|
| 408 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 409 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 410 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ) ); |
|
| 411 | - return; |
|
| 412 | - } |
|
| 413 | - if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) { |
|
| 414 | - // Purchase keys don't match |
|
| 415 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 416 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 417 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ) ); |
|
| 418 | - return; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) { |
|
| 422 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ) ); |
|
| 423 | - wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] ); |
|
| 424 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
| 425 | - } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
| 426 | - // Look for possible pending reasons, such as an echeck |
|
| 427 | - $note = ''; |
|
| 428 | - |
|
| 429 | - switch( strtolower( $data['pending_reason'] ) ) { |
|
| 430 | - case 'echeck' : |
|
| 431 | - $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' ); |
|
| 432 | - break; |
|
| 336 | + if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
| 337 | + return; |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + if( empty( $invoice_id ) ) { |
|
| 341 | + return; |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + // Collect payment details |
|
| 345 | + $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
| 346 | + $paypal_amount = $data['mc_gross']; |
|
| 347 | + $payment_status = strtolower( $data['payment_status'] ); |
|
| 348 | + $currency_code = strtolower( $data['mc_currency'] ); |
|
| 349 | + $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
| 350 | + $payment_meta = wpinv_get_invoice_meta( $invoice_id ); |
|
| 351 | + |
|
| 352 | + if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) { |
|
| 353 | + return; // this isn't a PayPal standard IPN |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + // Verify payment recipient |
|
| 357 | + if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) { |
|
| 358 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 359 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 360 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ) ); |
|
| 361 | + return; |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + // Verify payment currency |
|
| 365 | + if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
| 366 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 367 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 368 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ) ); |
|
| 369 | + return; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + if ( !wpinv_get_payment_user_email( $invoice_id ) ) { |
|
| 373 | + // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal |
|
| 374 | + // No email associated with purchase, so store from PayPal |
|
| 375 | + wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] ); |
|
| 376 | + |
|
| 377 | + // Setup and store the customer's details |
|
| 378 | + $user_info = array( |
|
| 379 | + 'user_id' => '-1', |
|
| 380 | + 'email' => sanitize_text_field( $data['payer_email'] ), |
|
| 381 | + 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
| 382 | + 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
| 383 | + 'discount' => '', |
|
| 384 | + ); |
|
| 385 | + $user_info['address'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
| 386 | + $user_info['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
| 387 | + $user_info['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
| 388 | + $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
| 389 | + $user_info['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
| 390 | + |
|
| 391 | + $payment_meta['user_info'] = $user_info; |
|
| 392 | + wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta ); |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
| 396 | + // Process a refund |
|
| 397 | + wpinv_process_paypal_refund( $data, $invoice_id ); |
|
| 398 | + } else { |
|
| 399 | + if ( get_post_status( $invoice_id ) == 'publish' ) { |
|
| 400 | + return; // Only paid payments once |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + // Retrieve the total purchase amount (before PayPal) |
|
| 404 | + $payment_amount = wpinv_payment_total( $invoice_id ); |
|
| 405 | + |
|
| 406 | + if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
| 407 | + // The prices don't match |
|
| 408 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 409 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 410 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ) ); |
|
| 411 | + return; |
|
| 412 | + } |
|
| 413 | + if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) { |
|
| 414 | + // Purchase keys don't match |
|
| 415 | + wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 416 | + wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 417 | + wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ) ); |
|
| 418 | + return; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) { |
|
| 422 | + wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ) ); |
|
| 423 | + wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] ); |
|
| 424 | + wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
| 425 | + } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
| 426 | + // Look for possible pending reasons, such as an echeck |
|
| 427 | + $note = ''; |
|
| 428 | + |
|
| 429 | + switch( strtolower( $data['pending_reason'] ) ) { |
|
| 430 | + case 'echeck' : |
|
| 431 | + $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' ); |
|
| 432 | + break; |
|
| 433 | 433 | |
| 434 | 434 | case 'address' : |
| 435 | - $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' ); |
|
| 436 | - break; |
|
| 435 | + $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' ); |
|
| 436 | + break; |
|
| 437 | 437 | |
| 438 | 438 | case 'intl' : |
| 439 | - $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' ); |
|
| 440 | - break; |
|
| 439 | + $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' ); |
|
| 440 | + break; |
|
| 441 | 441 | |
| 442 | 442 | case 'multi-currency' : |
| 443 | - $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' ); |
|
| 444 | - break; |
|
| 443 | + $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' ); |
|
| 444 | + break; |
|
| 445 | 445 | |
| 446 | 446 | case 'paymentreview' : |
| 447 | 447 | case 'regulatory_review' : |
| 448 | - $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' ); |
|
| 449 | - break; |
|
| 448 | + $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' ); |
|
| 449 | + break; |
|
| 450 | 450 | |
| 451 | 451 | case 'unilateral' : |
| 452 | - $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' ); |
|
| 453 | - break; |
|
| 452 | + $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' ); |
|
| 453 | + break; |
|
| 454 | 454 | |
| 455 | 455 | case 'upgrade' : |
| 456 | - $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' ); |
|
| 457 | - break; |
|
| 456 | + $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' ); |
|
| 457 | + break; |
|
| 458 | 458 | |
| 459 | 459 | case 'verify' : |
| 460 | - $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' ); |
|
| 461 | - break; |
|
| 462 | - |
|
| 463 | - case 'other' : |
|
| 464 | - $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' ); |
|
| 465 | - break; |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - if ( ! empty( $note ) ) { |
|
| 469 | - wpinv_insert_payment_note( $invoice_id, $note ); |
|
| 470 | - } |
|
| 471 | - } else { |
|
| 472 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ) ); |
|
| 473 | - } |
|
| 474 | - } |
|
| 460 | + $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' ); |
|
| 461 | + break; |
|
| 462 | + |
|
| 463 | + case 'other' : |
|
| 464 | + $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' ); |
|
| 465 | + break; |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + if ( ! empty( $note ) ) { |
|
| 469 | + wpinv_insert_payment_note( $invoice_id, $note ); |
|
| 470 | + } |
|
| 471 | + } else { |
|
| 472 | + wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ) ); |
|
| 473 | + } |
|
| 474 | + } |
|
| 475 | 475 | } |
| 476 | 476 | add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 ); |
| 477 | 477 | |
@@ -686,27 +686,27 @@ discard block |
||
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) { |
| 689 | - // Collect payment details |
|
| 689 | + // Collect payment details |
|
| 690 | 690 | |
| 691 | - if( empty( $invoice_id ) ) { |
|
| 692 | - return; |
|
| 693 | - } |
|
| 691 | + if( empty( $invoice_id ) ) { |
|
| 692 | + return; |
|
| 693 | + } |
|
| 694 | 694 | |
| 695 | - if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) { |
|
| 696 | - return; // Only refund payments once |
|
| 697 | - } |
|
| 695 | + if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) { |
|
| 696 | + return; // Only refund payments once |
|
| 697 | + } |
|
| 698 | 698 | |
| 699 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
| 700 | - $refund_amount = $data['mc_gross'] * -1; |
|
| 699 | + $payment_amount = wpinv_payment_total( $invoice_id ); |
|
| 700 | + $refund_amount = $data['mc_gross'] * -1; |
|
| 701 | 701 | |
| 702 | - if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
| 703 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Partial PayPal refund processed: %s', 'invoicing' ), $data['parent_txn_id'] ) ); |
|
| 704 | - return; // This is a partial refund |
|
| 705 | - } |
|
| 702 | + if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
| 703 | + wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Partial PayPal refund processed: %s', 'invoicing' ), $data['parent_txn_id'] ) ); |
|
| 704 | + return; // This is a partial refund |
|
| 705 | + } |
|
| 706 | 706 | |
| 707 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ) ); |
|
| 708 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ) ); |
|
| 709 | - wpinv_update_payment_status( $invoice_id, 'wpi-refunded' ); |
|
| 707 | + wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ) ); |
|
| 708 | + wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ) ); |
|
| 709 | + wpinv_update_payment_status( $invoice_id, 'wpi-refunded' ); |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | function wpinv_get_paypal_redirect( $ssl_check = false ) { |
@@ -1,13 +1,13 @@ 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 | -function wpinv_process_paypal_payment( $purchase_data ) { |
|
| 9 | - if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
| 10 | - wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 8 | +function wpinv_process_paypal_payment($purchase_data) { |
|
| 9 | + if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) { |
|
| 10 | + wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | // Collect payment data |
@@ -21,34 +21,34 @@ discard block |
||
| 21 | 21 | 'user_info' => $purchase_data['user_info'], |
| 22 | 22 | 'cart_details' => $purchase_data['cart_details'], |
| 23 | 23 | 'gateway' => 'paypal', |
| 24 | - 'status' => !empty( $purchase_data['buy_now'] ) ? 'private' : 'pending' |
|
| 24 | + 'status' => !empty($purchase_data['buy_now']) ? 'private' : 'pending' |
|
| 25 | 25 | ); |
| 26 | 26 | |
| 27 | 27 | // Record the pending payment |
| 28 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
| 28 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
| 29 | 29 | |
| 30 | 30 | // Check payment |
| 31 | - if ( ! $invoice ) { |
|
| 31 | + if (!$invoice) { |
|
| 32 | 32 | // Record the error |
| 33 | - wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $payment ); |
|
| 33 | + wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing'), json_encode($payment_data)), $payment); |
|
| 34 | 34 | // Problems? send back |
| 35 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
| 35 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
| 36 | 36 | } else { |
| 37 | 37 | // Only send to PayPal if the pending payment is created successfully |
| 38 | - $listener_url = wpinv_get_ipn_url( 'paypal' ); |
|
| 38 | + $listener_url = wpinv_get_ipn_url('paypal'); |
|
| 39 | 39 | |
| 40 | 40 | // Get the success url |
| 41 | - $return_url = add_query_arg( array( |
|
| 41 | + $return_url = add_query_arg(array( |
|
| 42 | 42 | 'payment-confirm' => 'paypal', |
| 43 | 43 | 'invoice-id' => $invoice->ID |
| 44 | - ), get_permalink( wpinv_get_option( 'success_page', false ) ) ); |
|
| 44 | + ), get_permalink(wpinv_get_option('success_page', false))); |
|
| 45 | 45 | |
| 46 | 46 | // Get the PayPal redirect uri |
| 47 | - $paypal_redirect = trailingslashit( wpinv_get_paypal_redirect() ) . '?'; |
|
| 47 | + $paypal_redirect = trailingslashit(wpinv_get_paypal_redirect()) . '?'; |
|
| 48 | 48 | |
| 49 | 49 | // Setup PayPal arguments |
| 50 | 50 | $paypal_args = array( |
| 51 | - 'business' => wpinv_get_option( 'paypal_email', false ), |
|
| 51 | + 'business' => wpinv_get_option('paypal_email', false), |
|
| 52 | 52 | 'email' => $invoice->get_email(), |
| 53 | 53 | 'first_name' => $invoice->get_first_name(), |
| 54 | 54 | 'last_name' => $invoice->get_last_name(), |
@@ -57,13 +57,13 @@ discard block |
||
| 57 | 57 | 'shipping' => '0', |
| 58 | 58 | 'no_note' => '1', |
| 59 | 59 | 'currency_code' => wpinv_get_currency(), |
| 60 | - 'charset' => get_bloginfo( 'charset' ), |
|
| 60 | + 'charset' => get_bloginfo('charset'), |
|
| 61 | 61 | 'custom' => $invoice->ID, |
| 62 | 62 | 'rm' => '2', |
| 63 | 63 | 'return' => $return_url, |
| 64 | - 'cancel_return' => wpinv_get_failed_transaction_uri( '?invoice-id=' . $invoice->ID ), |
|
| 64 | + 'cancel_return' => wpinv_get_failed_transaction_uri('?invoice-id=' . $invoice->ID), |
|
| 65 | 65 | 'notify_url' => $listener_url, |
| 66 | - 'cbt' => get_bloginfo( 'name' ), |
|
| 66 | + 'cbt' => get_bloginfo('name'), |
|
| 67 | 67 | 'bn' => 'WPInvoicing_SP', |
| 68 | 68 | 'lc' => 'US' // this will force paypal site to english |
| 69 | 69 | ); |
@@ -79,57 +79,57 @@ discard block |
||
| 79 | 79 | 'upload' => '1' |
| 80 | 80 | ); |
| 81 | 81 | |
| 82 | - $paypal_args = array_merge( $paypal_extra_args, $paypal_args ); |
|
| 82 | + $paypal_args = array_merge($paypal_extra_args, $paypal_args); |
|
| 83 | 83 | |
| 84 | 84 | // Add cart items |
| 85 | 85 | $i = 1; |
| 86 | - if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) { |
|
| 87 | - foreach ( $purchase_data['cart_details'] as $item ) { |
|
| 86 | + if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) { |
|
| 87 | + foreach ($purchase_data['cart_details'] as $item) { |
|
| 88 | 88 | $item['quantity'] = $item['quantity'] > 0 ? $item['quantity'] : 1; |
| 89 | - $item_amount = round( $item['subtotal'] / $item['quantity'], 2 ); |
|
| 89 | + $item_amount = round($item['subtotal'] / $item['quantity'], 2); |
|
| 90 | 90 | |
| 91 | - if ( $item_amount <= 0 ) { |
|
| 91 | + if ($item_amount <= 0) { |
|
| 92 | 92 | $item_amount = 0; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - $paypal_args['item_number_' . $i ] = $item['id']; |
|
| 96 | - $paypal_args['item_name_' . $i ] = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( $item ), ENT_COMPAT, 'UTF-8' ) ); |
|
| 97 | - $paypal_args['quantity_' . $i ] = $item['quantity']; |
|
| 98 | - $paypal_args['amount_' . $i ] = $item_amount; |
|
| 99 | - $paypal_args['discount_amount_' . $i ] = $item['discount']; |
|
| 95 | + $paypal_args['item_number_' . $i] = $item['id']; |
|
| 96 | + $paypal_args['item_name_' . $i] = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name($item), ENT_COMPAT, 'UTF-8')); |
|
| 97 | + $paypal_args['quantity_' . $i] = $item['quantity']; |
|
| 98 | + $paypal_args['amount_' . $i] = $item_amount; |
|
| 99 | + $paypal_args['discount_amount_' . $i] = $item['discount']; |
|
| 100 | 100 | |
| 101 | 101 | $i++; |
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | // Add taxes to the cart |
| 106 | - if ( wpinv_use_taxes() ) { |
|
| 107 | - $paypal_args['tax_cart'] = wpinv_sanitize_amount( (float)$invoice->get_tax() ); |
|
| 106 | + if (wpinv_use_taxes()) { |
|
| 107 | + $paypal_args['tax_cart'] = wpinv_sanitize_amount((float)$invoice->get_tax()); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - $paypal_args = apply_filters( 'wpinv_paypal_args', $paypal_args, $purchase_data, $invoice ); |
|
| 110 | + $paypal_args = apply_filters('wpinv_paypal_args', $paypal_args, $purchase_data, $invoice); |
|
| 111 | 111 | |
| 112 | 112 | // Build query |
| 113 | - $paypal_redirect .= http_build_query( $paypal_args ); |
|
| 113 | + $paypal_redirect .= http_build_query($paypal_args); |
|
| 114 | 114 | |
| 115 | 115 | // Fix for some sites that encode the entities |
| 116 | - $paypal_redirect = str_replace( '&', '&', $paypal_redirect ); |
|
| 116 | + $paypal_redirect = str_replace('&', '&', $paypal_redirect); |
|
| 117 | 117 | |
| 118 | 118 | // Get rid of cart contents |
| 119 | 119 | wpinv_empty_cart(); |
| 120 | 120 | |
| 121 | 121 | // Redirect to PayPal |
| 122 | - wp_redirect( $paypal_redirect ); |
|
| 122 | + wp_redirect($paypal_redirect); |
|
| 123 | 123 | exit; |
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | -add_action( 'wpinv_gateway_paypal', 'wpinv_process_paypal_payment' ); |
|
| 126 | +add_action('wpinv_gateway_paypal', 'wpinv_process_paypal_payment'); |
|
| 127 | 127 | |
| 128 | -function wpinv_get_paypal_recurring_args( $paypal_args, $purchase_data, $invoice ) { |
|
| 129 | - if ( $invoice->is_recurring() && $item_id = $invoice->get_recurring() ) { |
|
| 130 | - $item = new WPInv_Item( $item_id ); |
|
| 128 | +function wpinv_get_paypal_recurring_args($paypal_args, $purchase_data, $invoice) { |
|
| 129 | + if ($invoice->is_recurring() && $item_id = $invoice->get_recurring()) { |
|
| 130 | + $item = new WPInv_Item($item_id); |
|
| 131 | 131 | |
| 132 | - if ( empty( $item ) ) { |
|
| 132 | + if (empty($item)) { |
|
| 133 | 133 | return $paypal_args; |
| 134 | 134 | } |
| 135 | 135 | |
@@ -137,24 +137,24 @@ discard block |
||
| 137 | 137 | $interval = $item->get_recurring_interval(); |
| 138 | 138 | $bill_times = (int)$item->get_recurring_limit(); |
| 139 | 139 | |
| 140 | - $initial_amount = wpinv_format_amount( $invoice->get_total() ); |
|
| 141 | - $recurring_amount = wpinv_format_amount( $invoice->get_recurring_details( 'total' ) ); |
|
| 140 | + $initial_amount = wpinv_format_amount($invoice->get_total()); |
|
| 141 | + $recurring_amount = wpinv_format_amount($invoice->get_recurring_details('total')); |
|
| 142 | 142 | |
| 143 | 143 | $paypal_args['cmd'] = '_xclick-subscriptions'; |
| 144 | 144 | $paypal_args['sra'] = '1'; |
| 145 | 145 | $paypal_args['src'] = '1'; |
| 146 | 146 | |
| 147 | 147 | // Set item description |
| 148 | - $paypal_args['item_name'] = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( array( 'id' => $item->ID ) ), ENT_COMPAT, 'UTF-8' ) ); |
|
| 148 | + $paypal_args['item_name'] = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name(array('id' => $item->ID)), ENT_COMPAT, 'UTF-8')); |
|
| 149 | 149 | |
| 150 | - if ( $invoice->is_free_trial() && $item->has_free_trial() ) { |
|
| 150 | + if ($invoice->is_free_trial() && $item->has_free_trial()) { |
|
| 151 | 151 | $paypal_args['a1'] = $initial_amount; |
| 152 | 152 | $paypal_args['p1'] = $item->get_trial_interval(); |
| 153 | 153 | $paypal_args['t1'] = $item->get_trial_period(); |
| 154 | 154 | |
| 155 | 155 | // Set the recurring amount |
| 156 | 156 | $paypal_args['a3'] = $recurring_amount; |
| 157 | - } else if ( $initial_amount != $recurring_amount && $bill_times != 1 ) { |
|
| 157 | + } else if ($initial_amount != $recurring_amount && $bill_times != 1) { |
|
| 158 | 158 | $paypal_args['a1'] = $initial_amount; |
| 159 | 159 | $paypal_args['p1'] = $interval; |
| 160 | 160 | $paypal_args['t1'] = $period; |
@@ -162,63 +162,63 @@ discard block |
||
| 162 | 162 | // Set the recurring amount |
| 163 | 163 | $paypal_args['a3'] = $recurring_amount; |
| 164 | 164 | |
| 165 | - if ( $bill_times > 1 ) { |
|
| 165 | + if ($bill_times > 1) { |
|
| 166 | 166 | $bill_times--; |
| 167 | 167 | } |
| 168 | 168 | } else { |
| 169 | - $paypal_args['a3'] = $initial_amount; |
|
| 169 | + $paypal_args['a3'] = $initial_amount; |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | $paypal_args['p3'] = $interval; |
| 173 | 173 | $paypal_args['t3'] = $period; |
| 174 | 174 | |
| 175 | - if ( $bill_times > 1 ) { |
|
| 175 | + if ($bill_times > 1) { |
|
| 176 | 176 | // Make sure it's not over the max of 52 |
| 177 | - $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
|
| 177 | + $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | // Remove cart items |
| 181 | 181 | $i = 1; |
| 182 | - if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) { |
|
| 183 | - foreach ( $purchase_data['cart_details'] as $item ) { |
|
| 184 | - if ( isset( $paypal_args['item_number_' . $i] ) ) { |
|
| 185 | - unset( $paypal_args['item_number_' . $i] ); |
|
| 182 | + if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) { |
|
| 183 | + foreach ($purchase_data['cart_details'] as $item) { |
|
| 184 | + if (isset($paypal_args['item_number_' . $i])) { |
|
| 185 | + unset($paypal_args['item_number_' . $i]); |
|
| 186 | 186 | } |
| 187 | - if ( isset( $paypal_args['item_name_' . $i] ) ) { |
|
| 188 | - unset( $paypal_args['item_name_' . $i] ); |
|
| 187 | + if (isset($paypal_args['item_name_' . $i])) { |
|
| 188 | + unset($paypal_args['item_name_' . $i]); |
|
| 189 | 189 | } |
| 190 | - if ( isset( $paypal_args['quantity_' . $i] ) ) { |
|
| 191 | - unset( $paypal_args['quantity_' . $i] ); |
|
| 190 | + if (isset($paypal_args['quantity_' . $i])) { |
|
| 191 | + unset($paypal_args['quantity_' . $i]); |
|
| 192 | 192 | } |
| 193 | - if ( isset( $paypal_args['amount_' . $i] ) ) { |
|
| 194 | - unset( $paypal_args['amount_' . $i] ); |
|
| 193 | + if (isset($paypal_args['amount_' . $i])) { |
|
| 194 | + unset($paypal_args['amount_' . $i]); |
|
| 195 | 195 | } |
| 196 | - if ( isset( $paypal_args['discount_amount_' . $i] ) ) { |
|
| 197 | - unset( $paypal_args['discount_amount_' . $i] ); |
|
| 196 | + if (isset($paypal_args['discount_amount_' . $i])) { |
|
| 197 | + unset($paypal_args['discount_amount_' . $i]); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | $i++; |
| 201 | 201 | } |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - if ( isset( $paypal_args['tax_cart'] ) ) { |
|
| 205 | - unset( $paypal_args['tax_cart'] ); |
|
| 204 | + if (isset($paypal_args['tax_cart'])) { |
|
| 205 | + unset($paypal_args['tax_cart']); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - if ( isset( $paypal_args['upload'] ) ) { |
|
| 209 | - unset( $paypal_args['upload'] ); |
|
| 208 | + if (isset($paypal_args['upload'])) { |
|
| 209 | + unset($paypal_args['upload']); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | - $paypal_args = apply_filters( 'wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice ); |
|
| 212 | + $paypal_args = apply_filters('wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | return $paypal_args; |
| 216 | 216 | } |
| 217 | -add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 ); |
|
| 217 | +add_filter('wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3); |
|
| 218 | 218 | |
| 219 | 219 | function wpinv_process_paypal_ipn() { |
| 220 | 220 | // Check the request method is POST |
| 221 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
| 221 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') { |
|
| 222 | 222 | return; |
| 223 | 223 | } |
| 224 | 224 | |
@@ -226,11 +226,11 @@ discard block |
||
| 226 | 226 | $post_data = ''; |
| 227 | 227 | |
| 228 | 228 | // Fallback just in case post_max_size is lower than needed |
| 229 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
| 230 | - $post_data = file_get_contents( 'php://input' ); |
|
| 229 | + if (ini_get('allow_url_fopen')) { |
|
| 230 | + $post_data = file_get_contents('php://input'); |
|
| 231 | 231 | } else { |
| 232 | 232 | // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
| 233 | - ini_set( 'post_max_size', '12M' ); |
|
| 233 | + ini_set('post_max_size', '12M'); |
|
| 234 | 234 | } |
| 235 | 235 | // Start the encoded data collection with notification command |
| 236 | 236 | $encoded_data = 'cmd=_notify-validate'; |
@@ -239,43 +239,43 @@ discard block |
||
| 239 | 239 | $arg_separator = wpinv_get_php_arg_separator_output(); |
| 240 | 240 | |
| 241 | 241 | // Verify there is a post_data |
| 242 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
| 242 | + if ($post_data || strlen($post_data) > 0) { |
|
| 243 | 243 | // Append the data |
| 244 | - $encoded_data .= $arg_separator.$post_data; |
|
| 244 | + $encoded_data .= $arg_separator . $post_data; |
|
| 245 | 245 | } else { |
| 246 | 246 | // Check if POST is empty |
| 247 | - if ( empty( $_POST ) ) { |
|
| 247 | + if (empty($_POST)) { |
|
| 248 | 248 | // Nothing to do |
| 249 | 249 | return; |
| 250 | 250 | } else { |
| 251 | 251 | // Loop through each POST |
| 252 | - foreach ( $_POST as $key => $value ) { |
|
| 252 | + foreach ($_POST as $key => $value) { |
|
| 253 | 253 | // Encode the value and append the data |
| 254 | - $encoded_data .= $arg_separator."$key=" . urlencode( $value ); |
|
| 254 | + $encoded_data .= $arg_separator . "$key=" . urlencode($value); |
|
| 255 | 255 | } |
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | // Convert collected post data to an array |
| 260 | - parse_str( $encoded_data, $encoded_data_array ); |
|
| 260 | + parse_str($encoded_data, $encoded_data_array); |
|
| 261 | 261 | |
| 262 | - foreach ( $encoded_data_array as $key => $value ) { |
|
| 263 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
| 264 | - $new_key = str_replace( '&', '&', $key ); |
|
| 265 | - $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
| 262 | + foreach ($encoded_data_array as $key => $value) { |
|
| 263 | + if (false !== strpos($key, 'amp;')) { |
|
| 264 | + $new_key = str_replace('&', '&', $key); |
|
| 265 | + $new_key = str_replace('amp;', '&', $new_key); |
|
| 266 | 266 | |
| 267 | - unset( $encoded_data_array[ $key ] ); |
|
| 268 | - $encoded_data_array[ $new_key ] = $value; |
|
| 267 | + unset($encoded_data_array[$key]); |
|
| 268 | + $encoded_data_array[$new_key] = $value; |
|
| 269 | 269 | } |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | // Get the PayPal redirect uri |
| 273 | - $paypal_redirect = wpinv_get_paypal_redirect( true ); |
|
| 273 | + $paypal_redirect = wpinv_get_paypal_redirect(true); |
|
| 274 | 274 | |
| 275 | - if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
| 275 | + if (!wpinv_get_option('disable_paypal_verification', false)) { |
|
| 276 | 276 | // Validate the IPN |
| 277 | 277 | |
| 278 | - $remote_post_vars = array( |
|
| 278 | + $remote_post_vars = array( |
|
| 279 | 279 | 'method' => 'POST', |
| 280 | 280 | 'timeout' => 45, |
| 281 | 281 | 'redirection' => 5, |
@@ -293,21 +293,21 @@ discard block |
||
| 293 | 293 | ); |
| 294 | 294 | |
| 295 | 295 | // Get response |
| 296 | - $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars ); |
|
| 296 | + $api_response = wp_remote_post(wpinv_get_paypal_redirect(), $remote_post_vars); |
|
| 297 | 297 | |
| 298 | - if ( is_wp_error( $api_response ) ) { |
|
| 299 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
| 298 | + if (is_wp_error($api_response)) { |
|
| 299 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response))); |
|
| 300 | 300 | return; // Something went wrong |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
| 304 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
| 303 | + if ($api_response['body'] !== 'VERIFIED' && wpinv_get_option('disable_paypal_verification', false)) { |
|
| 304 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response))); |
|
| 305 | 305 | return; // Response not okay |
| 306 | 306 | } |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | // Check if $post_data_array has been populated |
| 310 | - if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) |
|
| 310 | + if (!is_array($encoded_data_array) && !empty($encoded_data_array)) |
|
| 311 | 311 | return; |
| 312 | 312 | |
| 313 | 313 | $defaults = array( |
@@ -315,215 +315,215 @@ discard block |
||
| 315 | 315 | 'payment_status' => '' |
| 316 | 316 | ); |
| 317 | 317 | |
| 318 | - $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
| 318 | + $encoded_data_array = wp_parse_args($encoded_data_array, $defaults); |
|
| 319 | 319 | |
| 320 | - $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
| 320 | + $invoice_id = isset($encoded_data_array['custom']) ? absint($encoded_data_array['custom']) : 0; |
|
| 321 | 321 | |
| 322 | - wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ ); |
|
| 322 | + wpinv_error_log($encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__); |
|
| 323 | 323 | |
| 324 | - if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
| 324 | + if (has_action('wpinv_paypal_' . $encoded_data_array['txn_type'])) { |
|
| 325 | 325 | // Allow PayPal IPN types to be processed separately |
| 326 | - do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id ); |
|
| 326 | + do_action('wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id); |
|
| 327 | 327 | } else { |
| 328 | 328 | // Fallback to web accept just in case the txn_type isn't present |
| 329 | - do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id ); |
|
| 329 | + do_action('wpinv_paypal_web_accept', $encoded_data_array, $invoice_id); |
|
| 330 | 330 | } |
| 331 | 331 | exit; |
| 332 | 332 | } |
| 333 | -add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' ); |
|
| 333 | +add_action('wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn'); |
|
| 334 | 334 | |
| 335 | -function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) { |
|
| 336 | - if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
| 335 | +function wpinv_process_paypal_web_accept_and_cart($data, $invoice_id) { |
|
| 336 | + if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') { |
|
| 337 | 337 | return; |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | - if( empty( $invoice_id ) ) { |
|
| 340 | + if (empty($invoice_id)) { |
|
| 341 | 341 | return; |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | // Collect payment details |
| 345 | - $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
| 345 | + $purchase_key = isset($data['invoice']) ? $data['invoice'] : $data['item_number']; |
|
| 346 | 346 | $paypal_amount = $data['mc_gross']; |
| 347 | - $payment_status = strtolower( $data['payment_status'] ); |
|
| 348 | - $currency_code = strtolower( $data['mc_currency'] ); |
|
| 349 | - $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
| 350 | - $payment_meta = wpinv_get_invoice_meta( $invoice_id ); |
|
| 347 | + $payment_status = strtolower($data['payment_status']); |
|
| 348 | + $currency_code = strtolower($data['mc_currency']); |
|
| 349 | + $business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']); |
|
| 350 | + $payment_meta = wpinv_get_invoice_meta($invoice_id); |
|
| 351 | 351 | |
| 352 | - if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) { |
|
| 352 | + if (wpinv_get_payment_gateway($invoice_id) != 'paypal') { |
|
| 353 | 353 | return; // this isn't a PayPal standard IPN |
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | // Verify payment recipient |
| 357 | - if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) { |
|
| 358 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 359 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 360 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ) ); |
|
| 357 | + if (strcasecmp($business_email, trim(wpinv_get_option('paypal_email', false))) != 0) { |
|
| 358 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid business email in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
| 359 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
| 360 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid PayPal business email.', 'invoicing')); |
|
| 361 | 361 | return; |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | // Verify payment currency |
| 365 | - if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
| 366 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 367 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 368 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ) ); |
|
| 365 | + if ($currency_code != strtolower($payment_meta['currency'])) { |
|
| 366 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
| 367 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
| 368 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid currency in PayPal IPN.', 'invoicing')); |
|
| 369 | 369 | return; |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | - if ( !wpinv_get_payment_user_email( $invoice_id ) ) { |
|
| 372 | + if (!wpinv_get_payment_user_email($invoice_id)) { |
|
| 373 | 373 | // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal |
| 374 | 374 | // No email associated with purchase, so store from PayPal |
| 375 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] ); |
|
| 375 | + wpinv_update_invoice_meta($invoice_id, '_wpinv_email', $data['payer_email']); |
|
| 376 | 376 | |
| 377 | 377 | // Setup and store the customer's details |
| 378 | 378 | $user_info = array( |
| 379 | 379 | 'user_id' => '-1', |
| 380 | - 'email' => sanitize_text_field( $data['payer_email'] ), |
|
| 381 | - 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
| 382 | - 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
| 380 | + 'email' => sanitize_text_field($data['payer_email']), |
|
| 381 | + 'first_name' => sanitize_text_field($data['first_name']), |
|
| 382 | + 'last_name' => sanitize_text_field($data['last_name']), |
|
| 383 | 383 | 'discount' => '', |
| 384 | 384 | ); |
| 385 | - $user_info['address'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
| 386 | - $user_info['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
| 387 | - $user_info['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
| 388 | - $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
| 389 | - $user_info['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
| 385 | + $user_info['address'] = !empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false; |
|
| 386 | + $user_info['city'] = !empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false; |
|
| 387 | + $user_info['state'] = !empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false; |
|
| 388 | + $user_info['country'] = !empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false; |
|
| 389 | + $user_info['zip'] = !empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false; |
|
| 390 | 390 | |
| 391 | 391 | $payment_meta['user_info'] = $user_info; |
| 392 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta ); |
|
| 392 | + wpinv_update_invoice_meta($invoice_id, '_wpinv_payment_meta', $payment_meta); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
| 395 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
| 396 | 396 | // Process a refund |
| 397 | - wpinv_process_paypal_refund( $data, $invoice_id ); |
|
| 397 | + wpinv_process_paypal_refund($data, $invoice_id); |
|
| 398 | 398 | } else { |
| 399 | - if ( get_post_status( $invoice_id ) == 'publish' ) { |
|
| 399 | + if (get_post_status($invoice_id) == 'publish') { |
|
| 400 | 400 | return; // Only paid payments once |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | // Retrieve the total purchase amount (before PayPal) |
| 404 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
| 404 | + $payment_amount = wpinv_payment_total($invoice_id); |
|
| 405 | 405 | |
| 406 | - if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
| 406 | + if (number_format((float)$paypal_amount, 2) < number_format((float)$payment_amount, 2)) { |
|
| 407 | 407 | // The prices don't match |
| 408 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 409 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 410 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ) ); |
|
| 408 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid payment amount in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
| 409 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
| 410 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid amount in PayPal IPN.', 'invoicing')); |
|
| 411 | 411 | return; |
| 412 | 412 | } |
| 413 | - if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) { |
|
| 413 | + if ($purchase_key != wpinv_get_payment_key($invoice_id)) { |
|
| 414 | 414 | // Purchase keys don't match |
| 415 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 416 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 417 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ) ); |
|
| 415 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid purchase key in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
| 416 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
| 417 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing')); |
|
| 418 | 418 | return; |
| 419 | 419 | } |
| 420 | 420 | |
| 421 | - if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) { |
|
| 422 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ) ); |
|
| 423 | - wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] ); |
|
| 424 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
| 425 | - } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
| 421 | + if ('complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode('paypal')) { |
|
| 422 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $data['txn_id'])); |
|
| 423 | + wpinv_set_payment_transaction_id($invoice_id, $data['txn_id']); |
|
| 424 | + wpinv_update_payment_status($invoice_id, 'publish'); |
|
| 425 | + } else if ('pending' == $payment_status && isset($data['pending_reason'])) { |
|
| 426 | 426 | // Look for possible pending reasons, such as an echeck |
| 427 | 427 | $note = ''; |
| 428 | 428 | |
| 429 | - switch( strtolower( $data['pending_reason'] ) ) { |
|
| 429 | + switch (strtolower($data['pending_reason'])) { |
|
| 430 | 430 | case 'echeck' : |
| 431 | - $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' ); |
|
| 431 | + $note = __('Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing'); |
|
| 432 | 432 | break; |
| 433 | 433 | |
| 434 | 434 | case 'address' : |
| 435 | - $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' ); |
|
| 435 | + $note = __('Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing'); |
|
| 436 | 436 | break; |
| 437 | 437 | |
| 438 | 438 | case 'intl' : |
| 439 | - $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' ); |
|
| 439 | + $note = __('Payment must be accepted manually through PayPal due to international account regulations', 'invoicing'); |
|
| 440 | 440 | break; |
| 441 | 441 | |
| 442 | 442 | case 'multi-currency' : |
| 443 | - $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' ); |
|
| 443 | + $note = __('Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing'); |
|
| 444 | 444 | break; |
| 445 | 445 | |
| 446 | 446 | case 'paymentreview' : |
| 447 | 447 | case 'regulatory_review' : |
| 448 | - $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' ); |
|
| 448 | + $note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing'); |
|
| 449 | 449 | break; |
| 450 | 450 | |
| 451 | 451 | case 'unilateral' : |
| 452 | - $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' ); |
|
| 452 | + $note = __('Payment was sent to non-confirmed or non-registered email address.', 'invoicing'); |
|
| 453 | 453 | break; |
| 454 | 454 | |
| 455 | 455 | case 'upgrade' : |
| 456 | - $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' ); |
|
| 456 | + $note = __('PayPal account must be upgraded before this payment can be accepted', 'invoicing'); |
|
| 457 | 457 | break; |
| 458 | 458 | |
| 459 | 459 | case 'verify' : |
| 460 | - $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' ); |
|
| 460 | + $note = __('PayPal account is not verified. Verify account in order to accept this payment', 'invoicing'); |
|
| 461 | 461 | break; |
| 462 | 462 | |
| 463 | 463 | case 'other' : |
| 464 | - $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' ); |
|
| 464 | + $note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing'); |
|
| 465 | 465 | break; |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | - if ( ! empty( $note ) ) { |
|
| 469 | - wpinv_insert_payment_note( $invoice_id, $note ); |
|
| 468 | + if (!empty($note)) { |
|
| 469 | + wpinv_insert_payment_note($invoice_id, $note); |
|
| 470 | 470 | } |
| 471 | 471 | } else { |
| 472 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ) ); |
|
| 472 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal IPN has been received with invalid payment status: %s', 'invoicing'), $payment_status)); |
|
| 473 | 473 | } |
| 474 | 474 | } |
| 475 | 475 | } |
| 476 | -add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 ); |
|
| 476 | +add_action('wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2); |
|
| 477 | 477 | |
| 478 | 478 | // Process PayPal subscription sign ups |
| 479 | -add_action( 'wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup' ); |
|
| 479 | +add_action('wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup'); |
|
| 480 | 480 | |
| 481 | 481 | // Process PayPal subscription payments |
| 482 | -add_action( 'wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment' ); |
|
| 482 | +add_action('wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment'); |
|
| 483 | 483 | |
| 484 | 484 | // Process PayPal subscription cancellations |
| 485 | -add_action( 'wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel' ); |
|
| 485 | +add_action('wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel'); |
|
| 486 | 486 | |
| 487 | 487 | // Process PayPal subscription end of term notices |
| 488 | -add_action( 'wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot' ); |
|
| 488 | +add_action('wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot'); |
|
| 489 | 489 | |
| 490 | 490 | // Process PayPal payment failed |
| 491 | -add_action( 'wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed' ); |
|
| 491 | +add_action('wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed'); |
|
| 492 | 492 | |
| 493 | 493 | |
| 494 | 494 | /** |
| 495 | 495 | * Process the subscription started IPN. |
| 496 | 496 | */ |
| 497 | -function wpinv_process_paypal_subscr_signup( $ipn_data ) { |
|
| 498 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
| 499 | - if( empty( $parent_invoice_id ) ) { |
|
| 497 | +function wpinv_process_paypal_subscr_signup($ipn_data) { |
|
| 498 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
| 499 | + if (empty($parent_invoice_id)) { |
|
| 500 | 500 | return; |
| 501 | 501 | } |
| 502 | 502 | |
| 503 | - $invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
| 504 | - if ( empty( $invoice ) ) { |
|
| 503 | + $invoice = wpinv_get_invoice($parent_invoice_id); |
|
| 504 | + if (empty($invoice)) { |
|
| 505 | 505 | return; |
| 506 | 506 | } |
| 507 | 507 | |
| 508 | - if ( $invoice->is_free_trial() && !empty( $ipn_data['invoice'] ) ) { |
|
| 509 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Invoice ID: %s', 'invoicing' ) , $ipn_data['invoice'] ) ); |
|
| 510 | - wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['invoice'] ); |
|
| 508 | + if ($invoice->is_free_trial() && !empty($ipn_data['invoice'])) { |
|
| 509 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Invoice ID: %s', 'invoicing'), $ipn_data['invoice'])); |
|
| 510 | + wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['invoice']); |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | - wpinv_update_payment_status( $parent_invoice_id, 'publish' ); |
|
| 513 | + wpinv_update_payment_status($parent_invoice_id, 'publish'); |
|
| 514 | 514 | sleep(1); |
| 515 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ) ); |
|
| 515 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id'])); |
|
| 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 | - $cart_details = $invoice->cart_details; |
|
| 522 | + $cart_details = $invoice->cart_details; |
|
| 523 | 523 | |
| 524 | - if ( !empty( $cart_details ) ) { |
|
| 525 | - foreach ( $cart_details as $cart_item ) { |
|
| 526 | - $item = new WPInv_Item( $cart_item['id'] ); |
|
| 524 | + if (!empty($cart_details)) { |
|
| 525 | + foreach ($cart_details as $cart_item) { |
|
| 526 | + $item = new WPInv_Item($cart_item['id']); |
|
| 527 | 527 | |
| 528 | 528 | $status = $invoice->is_free_trial() && $item->has_free_trial() ? 'trialing' : 'active'; |
| 529 | 529 | |
@@ -532,15 +532,15 @@ discard block |
||
| 532 | 532 | 'status' => $status, |
| 533 | 533 | 'period' => $item->get_recurring_period(), |
| 534 | 534 | 'initial_amount' => $invoice->get_total(), |
| 535 | - 'recurring_amount' => $invoice->get_recurring_details( 'total' ), |
|
| 535 | + 'recurring_amount' => $invoice->get_recurring_details('total'), |
|
| 536 | 536 | 'interval' => $item->get_recurring_interval(), |
| 537 | 537 | 'bill_times' => $item->get_recurring_limit(), |
| 538 | - 'expiration' => $invoice->get_new_expiration( $cart_item['id'] ), |
|
| 538 | + 'expiration' => $invoice->get_new_expiration($cart_item['id']), |
|
| 539 | 539 | 'profile_id' => $ipn_data['subscr_id'], |
| 540 | - 'created' => date_i18n( 'Y-m-d H:i:s', strtotime( $ipn_data['subscr_date'] ) ) |
|
| 540 | + 'created' => date_i18n('Y-m-d H:i:s', strtotime($ipn_data['subscr_date'])) |
|
| 541 | 541 | ); |
| 542 | 542 | |
| 543 | - if ( $item->has_free_trial() ) { |
|
| 543 | + if ($item->has_free_trial()) { |
|
| 544 | 544 | $args['trial_period'] = $item->get_trial_period(); |
| 545 | 545 | $args['trial_interval'] = $item->get_trial_interval(); |
| 546 | 546 | } else { |
@@ -549,7 +549,7 @@ discard block |
||
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | |
| 552 | - $subscription->update_subscription( $args ); |
|
| 552 | + $subscription->update_subscription($args); |
|
| 553 | 553 | } |
| 554 | 554 | } |
| 555 | 555 | } |
@@ -557,39 +557,39 @@ discard block |
||
| 557 | 557 | /** |
| 558 | 558 | * Process the subscription payment received IPN. |
| 559 | 559 | */ |
| 560 | -function wpinv_process_paypal_subscr_payment( $ipn_data ) { |
|
| 561 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
| 560 | +function wpinv_process_paypal_subscr_payment($ipn_data) { |
|
| 561 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
| 562 | 562 | |
| 563 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
| 564 | - if ( false === $subscription ) { |
|
| 563 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
| 564 | + if (false === $subscription) { |
|
| 565 | 565 | return; |
| 566 | 566 | } |
| 567 | 567 | |
| 568 | - $transaction_id = wpinv_get_payment_transaction_id( $parent_invoice_id ); |
|
| 569 | - $signup_date = strtotime( $subscription->get_subscription_created() ); |
|
| 570 | - $today = date_i18n( 'Y-m-d', $signup_date ) == date_i18n( 'Y-m-d', strtotime( $ipn_data['payment_date'] ) ); |
|
| 568 | + $transaction_id = wpinv_get_payment_transaction_id($parent_invoice_id); |
|
| 569 | + $signup_date = strtotime($subscription->get_subscription_created()); |
|
| 570 | + $today = date_i18n('Y-m-d', $signup_date) == date_i18n('Y-m-d', strtotime($ipn_data['payment_date'])); |
|
| 571 | 571 | |
| 572 | 572 | // Look to see if payment is same day as signup and we have set the transaction ID on the parent payment yet. |
| 573 | - if ( $today && ( !$transaction_id || $transaction_id == $parent_invoice_id ) ) { |
|
| 574 | - wpinv_update_payment_status( $parent_invoice_id, 'publish' ); |
|
| 573 | + if ($today && (!$transaction_id || $transaction_id == $parent_invoice_id)) { |
|
| 574 | + wpinv_update_payment_status($parent_invoice_id, 'publish'); |
|
| 575 | 575 | sleep(1); |
| 576 | 576 | |
| 577 | 577 | // This is the very first payment |
| 578 | - wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] ); |
|
| 579 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ) ); |
|
| 578 | + wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']); |
|
| 579 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id'])); |
|
| 580 | 580 | return; |
| 581 | 581 | } |
| 582 | 582 | |
| 583 | - if ( wpinv_get_id_by_transaction_id( $ipn_data['txn_id'] ) ) { |
|
| 583 | + if (wpinv_get_id_by_transaction_id($ipn_data['txn_id'])) { |
|
| 584 | 584 | return; // Payment already recorded |
| 585 | 585 | } |
| 586 | 586 | |
| 587 | - $currency_code = strtolower( $ipn_data['mc_currency'] ); |
|
| 587 | + $currency_code = strtolower($ipn_data['mc_currency']); |
|
| 588 | 588 | |
| 589 | 589 | // verify details |
| 590 | - if ( $currency_code != strtolower( wpinv_get_currency() ) ) { |
|
| 590 | + if ($currency_code != strtolower(wpinv_get_currency())) { |
|
| 591 | 591 | // the currency code is invalid |
| 592 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: ', 'invoicing' ), json_encode( $ipn_data ) ) ); |
|
| 592 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: ', 'invoicing'), json_encode($ipn_data))); |
|
| 593 | 593 | return; |
| 594 | 594 | } |
| 595 | 595 | |
@@ -598,11 +598,11 @@ discard block |
||
| 598 | 598 | 'transaction_id' => $ipn_data['txn_id'] |
| 599 | 599 | ); |
| 600 | 600 | |
| 601 | - $invoice = wpinv_recurring_add_subscription_payment( $parent_invoice_id, $args ); |
|
| 601 | + $invoice = wpinv_recurring_add_subscription_payment($parent_invoice_id, $args); |
|
| 602 | 602 | |
| 603 | - if ( !empty( $invoice ) ) { |
|
| 603 | + if (!empty($invoice)) { |
|
| 604 | 604 | sleep(1); |
| 605 | - wpinv_insert_payment_note( $invoice->ID, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ) ); |
|
| 605 | + wpinv_insert_payment_note($invoice->ID, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id'])); |
|
| 606 | 606 | |
| 607 | 607 | $invoice->renew_subscription(); |
| 608 | 608 | } |
@@ -611,10 +611,10 @@ discard block |
||
| 611 | 611 | /** |
| 612 | 612 | * Process the subscription canceled IPN. |
| 613 | 613 | */ |
| 614 | -function wpinv_process_paypal_subscr_cancel( $ipn_data ) { |
|
| 615 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
| 614 | +function wpinv_process_paypal_subscr_cancel($ipn_data) { |
|
| 615 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
| 616 | 616 | |
| 617 | - if( false === $subscription ) { |
|
| 617 | + if (false === $subscription) { |
|
| 618 | 618 | return; |
| 619 | 619 | } |
| 620 | 620 | |
@@ -624,10 +624,10 @@ discard block |
||
| 624 | 624 | /** |
| 625 | 625 | * Process the subscription expired IPN. |
| 626 | 626 | */ |
| 627 | -function wpinv_process_paypal_subscr_eot( $ipn_data ) { |
|
| 628 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
| 627 | +function wpinv_process_paypal_subscr_eot($ipn_data) { |
|
| 628 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
| 629 | 629 | |
| 630 | - if( false === $subscription ) { |
|
| 630 | + if (false === $subscription) { |
|
| 631 | 631 | return; |
| 632 | 632 | } |
| 633 | 633 | |
@@ -637,45 +637,45 @@ discard block |
||
| 637 | 637 | /** |
| 638 | 638 | * Process the subscription payment failed IPN. |
| 639 | 639 | */ |
| 640 | -function wpinv_process_paypal_subscr_failed( $ipn_data ) { |
|
| 641 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
| 640 | +function wpinv_process_paypal_subscr_failed($ipn_data) { |
|
| 641 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
| 642 | 642 | |
| 643 | - if( false === $subscription ) { |
|
| 643 | + if (false === $subscription) { |
|
| 644 | 644 | return; |
| 645 | 645 | } |
| 646 | 646 | |
| 647 | 647 | $subscription->failing_subscription(); |
| 648 | 648 | |
| 649 | - do_action( 'wpinv_recurring_payment_failed', $subscription ); |
|
| 649 | + do_action('wpinv_recurring_payment_failed', $subscription); |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | /** |
| 653 | 653 | * Retrieve the subscription this IPN notice is for. |
| 654 | 654 | */ |
| 655 | -function wpinv_get_paypal_subscription( $ipn_data = array() ) { |
|
| 656 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
| 655 | +function wpinv_get_paypal_subscription($ipn_data = array()) { |
|
| 656 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
| 657 | 657 | |
| 658 | - if( empty( $parent_invoice_id ) ) { |
|
| 658 | + if (empty($parent_invoice_id)) { |
|
| 659 | 659 | return false; |
| 660 | 660 | } |
| 661 | 661 | |
| 662 | - $invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
| 663 | - if ( empty( $invoice ) ) { |
|
| 662 | + $invoice = wpinv_get_invoice($parent_invoice_id); |
|
| 663 | + if (empty($invoice)) { |
|
| 664 | 664 | return false; |
| 665 | 665 | } |
| 666 | 666 | |
| 667 | - $subscription = wpinv_get_subscription( $ipn_data['subscr_id'], true ); |
|
| 667 | + $subscription = wpinv_get_subscription($ipn_data['subscr_id'], true); |
|
| 668 | 668 | |
| 669 | - if ( empty( $subscription ) ) { |
|
| 670 | - $subs = wpinv_get_subscriptions( array( 'parent_invoice_id' => $parent_invoice_id, 'numberposts' => 1 ) ); |
|
| 671 | - $subscription = reset( $subs ); |
|
| 669 | + if (empty($subscription)) { |
|
| 670 | + $subs = wpinv_get_subscriptions(array('parent_invoice_id' => $parent_invoice_id, 'numberposts' => 1)); |
|
| 671 | + $subscription = reset($subs); |
|
| 672 | 672 | |
| 673 | - if ( $subscription && $subscription->ID > 0 ) { |
|
| 673 | + if ($subscription && $subscription->ID > 0) { |
|
| 674 | 674 | // Update the profile ID so it is set for future renewals |
| 675 | - $subscription->update_subscription( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) ); |
|
| 675 | + $subscription->update_subscription(array('profile_id' => sanitize_text_field($ipn_data['subscr_id']))); |
|
| 676 | 676 | } else { |
| 677 | 677 | $subscription = $invoice; |
| 678 | - $subscription->update_subscription( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) ); |
|
| 678 | + $subscription->update_subscription(array('profile_id' => sanitize_text_field($ipn_data['subscr_id']))); |
|
| 679 | 679 | // No subscription found with a matching payment ID, bail |
| 680 | 680 | //return false; |
| 681 | 681 | } |
@@ -685,39 +685,39 @@ discard block |
||
| 685 | 685 | |
| 686 | 686 | } |
| 687 | 687 | |
| 688 | -function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) { |
|
| 688 | +function wpinv_process_paypal_refund($data, $invoice_id = 0) { |
|
| 689 | 689 | // Collect payment details |
| 690 | 690 | |
| 691 | - if( empty( $invoice_id ) ) { |
|
| 691 | + if (empty($invoice_id)) { |
|
| 692 | 692 | return; |
| 693 | 693 | } |
| 694 | 694 | |
| 695 | - if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) { |
|
| 695 | + if (get_post_status($invoice_id) == 'wpi-refunded') { |
|
| 696 | 696 | return; // Only refund payments once |
| 697 | 697 | } |
| 698 | 698 | |
| 699 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
| 699 | + $payment_amount = wpinv_payment_total($invoice_id); |
|
| 700 | 700 | $refund_amount = $data['mc_gross'] * -1; |
| 701 | 701 | |
| 702 | - if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
| 703 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Partial PayPal refund processed: %s', 'invoicing' ), $data['parent_txn_id'] ) ); |
|
| 702 | + if (number_format((float)$refund_amount, 2) < number_format((float)$payment_amount, 2)) { |
|
| 703 | + wpinv_insert_payment_note($invoice_id, sprintf(__('Partial PayPal refund processed: %s', 'invoicing'), $data['parent_txn_id'])); |
|
| 704 | 704 | return; // This is a partial refund |
| 705 | 705 | } |
| 706 | 706 | |
| 707 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ) ); |
|
| 708 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ) ); |
|
| 709 | - wpinv_update_payment_status( $invoice_id, 'wpi-refunded' ); |
|
| 707 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Payment #%s Refunded for reason: %s', 'invoicing'), $data['parent_txn_id'], $data['reason_code'])); |
|
| 708 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Refund Transaction ID: %s', 'invoicing'), $data['txn_id'])); |
|
| 709 | + wpinv_update_payment_status($invoice_id, 'wpi-refunded'); |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | -function wpinv_get_paypal_redirect( $ssl_check = false ) { |
|
| 713 | - if ( is_ssl() || ! $ssl_check ) { |
|
| 712 | +function wpinv_get_paypal_redirect($ssl_check = false) { |
|
| 713 | + if (is_ssl() || !$ssl_check) { |
|
| 714 | 714 | $protocol = 'https://'; |
| 715 | 715 | } else { |
| 716 | 716 | $protocol = 'http://'; |
| 717 | 717 | } |
| 718 | 718 | |
| 719 | 719 | // Check the current payment mode |
| 720 | - if ( wpinv_is_test_mode( 'paypal' ) ) { |
|
| 720 | + if (wpinv_is_test_mode('paypal')) { |
|
| 721 | 721 | // Test mode |
| 722 | 722 | $paypal_uri = $protocol . 'www.sandbox.paypal.com/cgi-bin/webscr'; |
| 723 | 723 | } else { |
@@ -725,67 +725,67 @@ discard block |
||
| 725 | 725 | $paypal_uri = $protocol . 'www.paypal.com/cgi-bin/webscr'; |
| 726 | 726 | } |
| 727 | 727 | |
| 728 | - return apply_filters( 'wpinv_paypal_uri', $paypal_uri ); |
|
| 728 | + return apply_filters('wpinv_paypal_uri', $paypal_uri); |
|
| 729 | 729 | } |
| 730 | 730 | |
| 731 | -function wpinv_paypal_success_page_content( $content ) { |
|
| 731 | +function wpinv_paypal_success_page_content($content) { |
|
| 732 | 732 | global $wpi_invoice; |
| 733 | 733 | |
| 734 | 734 | $session = wpinv_get_checkout_session(); |
| 735 | 735 | |
| 736 | - if ( empty( $_GET['invoice-id'] ) && empty( $session['invoice_key'] ) ) { |
|
| 736 | + if (empty($_GET['invoice-id']) && empty($session['invoice_key'])) { |
|
| 737 | 737 | return $content; |
| 738 | 738 | } |
| 739 | 739 | |
| 740 | - $invoice_id = !empty( $_GET['invoice-id'] ) ? absint( $_GET['invoice-id'] ) : wpinv_get_invoice_id_by_key( $session['invoice_key'] ); |
|
| 740 | + $invoice_id = !empty($_GET['invoice-id']) ? absint($_GET['invoice-id']) : wpinv_get_invoice_id_by_key($session['invoice_key']); |
|
| 741 | 741 | |
| 742 | - if ( empty( $invoice_id ) ) { |
|
| 742 | + if (empty($invoice_id)) { |
|
| 743 | 743 | return $content; |
| 744 | 744 | } |
| 745 | 745 | |
| 746 | - $wpi_invoice = wpinv_get_invoice( $invoice_id ); |
|
| 746 | + $wpi_invoice = wpinv_get_invoice($invoice_id); |
|
| 747 | 747 | |
| 748 | - if ( !empty( $wpi_invoice ) && 'pending' == $wpi_invoice->status ) { |
|
| 748 | + if (!empty($wpi_invoice) && 'pending' == $wpi_invoice->status) { |
|
| 749 | 749 | // Payment is still pending so show processing indicator to fix the Race Condition, issue # |
| 750 | 750 | ob_start(); |
| 751 | - wpinv_get_template_part( 'wpinv-payment-processing' ); |
|
| 751 | + wpinv_get_template_part('wpinv-payment-processing'); |
|
| 752 | 752 | $content = ob_get_clean(); |
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | return $content; |
| 756 | 756 | } |
| 757 | -add_filter( 'wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content' ); |
|
| 757 | +add_filter('wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content'); |
|
| 758 | 758 | |
| 759 | -function wpinv_paypal_get_transaction_id( $invoice_id ) { |
|
| 759 | +function wpinv_paypal_get_transaction_id($invoice_id) { |
|
| 760 | 760 | $transaction_id = ''; |
| 761 | - $notes = wpinv_get_invoice_notes( $invoice_id ); |
|
| 761 | + $notes = wpinv_get_invoice_notes($invoice_id); |
|
| 762 | 762 | |
| 763 | - foreach ( $notes as $note ) { |
|
| 764 | - if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) { |
|
| 763 | + foreach ($notes as $note) { |
|
| 764 | + if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) { |
|
| 765 | 765 | $transaction_id = $match[1]; |
| 766 | 766 | continue; |
| 767 | 767 | } |
| 768 | 768 | } |
| 769 | 769 | |
| 770 | - return apply_filters( 'wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id ); |
|
| 770 | + return apply_filters('wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id); |
|
| 771 | 771 | } |
| 772 | -add_filter( 'wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1 ); |
|
| 772 | +add_filter('wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1); |
|
| 773 | 773 | |
| 774 | -function wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice ) { |
|
| 775 | - if ( $invoice->is_free_trial() || $transaction_id == $invoice_id ) { // Free trial does not have transaction at PayPal. |
|
| 774 | +function wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice) { |
|
| 775 | + if ($invoice->is_free_trial() || $transaction_id == $invoice_id) { // Free trial does not have transaction at PayPal. |
|
| 776 | 776 | $transaction_url = $invoice->get_view_url(); |
| 777 | 777 | } else { |
| 778 | - $sandbox = wpinv_is_test_mode( 'paypal' ) ? '.sandbox' : ''; |
|
| 778 | + $sandbox = wpinv_is_test_mode('paypal') ? '.sandbox' : ''; |
|
| 779 | 779 | $transaction_url = 'https://www' . $sandbox . '.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=' . $transaction_id; |
| 780 | 780 | } |
| 781 | 781 | |
| 782 | - $transaction_link = '<a href="' . esc_url( $transaction_url ) . '" target="_blank">' . $transaction_id . '</a>'; |
|
| 782 | + $transaction_link = '<a href="' . esc_url($transaction_url) . '" target="_blank">' . $transaction_id . '</a>'; |
|
| 783 | 783 | |
| 784 | - return apply_filters( 'wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $invoice ); |
|
| 784 | + return apply_filters('wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $invoice); |
|
| 785 | 785 | } |
| 786 | -add_filter( 'wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3 ); |
|
| 786 | +add_filter('wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3); |
|
| 787 | 787 | |
| 788 | 788 | function wpinv_gateway_paypal_button_label($label) { |
| 789 | - return __( 'Proceed to PayPal', 'invoicing' ); |
|
| 789 | + return __('Proceed to PayPal', 'invoicing'); |
|
| 790 | 790 | } |
| 791 | -add_filter( 'wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1 ); |
|
| 792 | 791 | \ No newline at end of file |
| 792 | +add_filter('wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1); |
|
| 793 | 793 | \ No newline at end of file |