@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Authorize.net Legacy Payment Gateway class. |
@@ -28,8 +28,8 @@ discard block |
||
| 28 | 28 | * @param WPInv_Invoice $invoice Invoice. |
| 29 | 29 | * @return string |
| 30 | 30 | */ |
| 31 | - public function get_api_url( $invoice ) { |
|
| 32 | - return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
|
| 31 | + public function get_api_url($invoice) { |
|
| 32 | + return $this->is_sandbox($invoice) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -40,40 +40,40 @@ discard block |
||
| 40 | 40 | * @param WPInv_Invoice $invoice Invoice. |
| 41 | 41 | * @return stdClass|WP_Error |
| 42 | 42 | */ |
| 43 | - public function post( $post, $invoice ){ |
|
| 43 | + public function post($post, $invoice) { |
|
| 44 | 44 | |
| 45 | - $url = $this->get_api_url( $invoice ); |
|
| 45 | + $url = $this->get_api_url($invoice); |
|
| 46 | 46 | $response = wp_remote_post( |
| 47 | 47 | $url, |
| 48 | 48 | array( |
| 49 | 49 | 'headers' => array( |
| 50 | 50 | 'Content-Type' => 'application/json; charset=utf-8' |
| 51 | 51 | ), |
| 52 | - 'body' => json_encode( $post ), |
|
| 52 | + 'body' => json_encode($post), |
|
| 53 | 53 | 'method' => 'POST' |
| 54 | 54 | ) |
| 55 | 55 | ); |
| 56 | 56 | |
| 57 | - if ( is_wp_error( $response ) ) { |
|
| 57 | + if (is_wp_error($response)) { |
|
| 58 | 58 | return $response; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - $response = wp_unslash( wp_remote_retrieve_body( $response ) ); |
|
| 61 | + $response = wp_unslash(wp_remote_retrieve_body($response)); |
|
| 62 | 62 | $response = preg_replace('/\xEF\xBB\xBF/', '', $response); // https://community.developer.authorize.net/t5/Integration-and-Testing/JSON-issues/td-p/48851 |
| 63 | - $response = json_decode( $response ); |
|
| 63 | + $response = json_decode($response); |
|
| 64 | 64 | |
| 65 | - if ( empty( $response ) ) { |
|
| 66 | - return new WP_Error( 'invalid_reponse', __( 'Invalid gateway response', 'invoicing' ) ); |
|
| 65 | + if (empty($response)) { |
|
| 66 | + return new WP_Error('invalid_reponse', __('Invalid gateway response', 'invoicing')); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - if ( $response->messages->resultCode == 'Error' ) { |
|
| 69 | + if ($response->messages->resultCode == 'Error') { |
|
| 70 | 70 | |
| 71 | - if ( ! empty( $response->transactionResponse ) && ! empty( $response->transactionResponse->errors ) ) { |
|
| 71 | + if (!empty($response->transactionResponse) && !empty($response->transactionResponse->errors)) { |
|
| 72 | 72 | $error = $response->transactionResponse->errors[0]; |
| 73 | - return new WP_Error( $error->errorCode, $error->errorText ); |
|
| 73 | + return new WP_Error($error->errorCode, $error->errorText); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - return new WP_Error( $response->messages->message[0]->code, $response->messages->message[0]->text ); |
|
| 76 | + return new WP_Error($response->messages->message[0]->code, $response->messages->message[0]->text); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | return $response; |
@@ -89,8 +89,8 @@ discard block |
||
| 89 | 89 | public function get_auth_params() { |
| 90 | 90 | |
| 91 | 91 | return array( |
| 92 | - 'name' => $this->get_option( 'login_id' ), |
|
| 93 | - 'transactionKey' => $this->get_option( 'transaction_key' ), |
|
| 92 | + 'name' => $this->get_option('login_id'), |
|
| 93 | + 'transactionKey' => $this->get_option('transaction_key'), |
|
| 94 | 94 | ); |
| 95 | 95 | |
| 96 | 96 | } |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | * @param WPInv_Subscription $subscription Subscription. |
| 103 | 103 | * @param WPInv_Invoice $invoice Invoice. |
| 104 | 104 | */ |
| 105 | - public function cancel_subscription( $subscription, $invoice ) { |
|
| 105 | + public function cancel_subscription($subscription, $invoice) { |
|
| 106 | 106 | |
| 107 | 107 | // Backwards compatibility. New version do not use authorize.net subscriptions. |
| 108 | 108 | $this->post( |
@@ -127,38 +127,38 @@ discard block |
||
| 127 | 127 | $this->maybe_process_old_ipn(); |
| 128 | 128 | |
| 129 | 129 | // Validate the IPN. |
| 130 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
| 131 | - wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 500 ) ); |
|
| 130 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
| 131 | + wp_die('Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array('response' => 500)); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | // Event type. |
| 135 | - $posted = json_decode( file_get_contents( 'php://input' ) ); |
|
| 136 | - if ( empty( $posted ) ) { |
|
| 137 | - wp_die( 'Invalid JSON', 'Authorize.NET IPN', array( 'response' => 500 ) ); |
|
| 135 | + $posted = json_decode(file_get_contents('php://input')); |
|
| 136 | + if (empty($posted)) { |
|
| 137 | + wp_die('Invalid JSON', 'Authorize.NET IPN', array('response' => 500)); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | // Process the IPN. |
| 141 | - $posted = (object) wp_unslash( $posted ); |
|
| 141 | + $posted = (object) wp_unslash($posted); |
|
| 142 | 142 | |
| 143 | 143 | // Process refunds. |
| 144 | - if ( 'net.authorize.payment.refund.created' == $posted->eventType ) { |
|
| 145 | - $invoice = new WPInv_Invoice( $posted->payload->merchantReferenceId ); |
|
| 146 | - $this->validate_ipn_invoice( $invoice, $posted->payload ); |
|
| 144 | + if ('net.authorize.payment.refund.created' == $posted->eventType) { |
|
| 145 | + $invoice = new WPInv_Invoice($posted->payload->merchantReferenceId); |
|
| 146 | + $this->validate_ipn_invoice($invoice, $posted->payload); |
|
| 147 | 147 | $invoice->refund(); |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | // Held funds approved. |
| 151 | - if ( 'net.authorize.payment.fraud.approved' == $posted->eventType ) { |
|
| 152 | - $invoice = new WPInv_Invoice( $posted->payload->id ); |
|
| 153 | - $this->validate_ipn_invoice( $invoice, $posted->payload ); |
|
| 154 | - $invoice->mark_paid( false, __( 'Payment released', 'invoicing' ) ); |
|
| 151 | + if ('net.authorize.payment.fraud.approved' == $posted->eventType) { |
|
| 152 | + $invoice = new WPInv_Invoice($posted->payload->id); |
|
| 153 | + $this->validate_ipn_invoice($invoice, $posted->payload); |
|
| 154 | + $invoice->mark_paid(false, __('Payment released', 'invoicing')); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | // Held funds declined. |
| 158 | - if ( 'net.authorize.payment.fraud.declined' == $posted->eventType ) { |
|
| 159 | - $invoice = new WPInv_Invoice( $posted->payload->id ); |
|
| 160 | - $this->validate_ipn_invoice( $invoice, $posted->payload ); |
|
| 161 | - $invoice->set_status( 'wpi-failed', __( 'Payment declined', 'invoicing' ) ); |
|
| 158 | + if ('net.authorize.payment.fraud.declined' == $posted->eventType) { |
|
| 159 | + $invoice = new WPInv_Invoice($posted->payload->id); |
|
| 160 | + $this->validate_ipn_invoice($invoice, $posted->payload); |
|
| 161 | + $invoice->set_status('wpi-failed', __('Payment declined', 'invoicing')); |
|
| 162 | 162 | $invoice->save(); |
| 163 | 163 | } |
| 164 | 164 | |
@@ -173,8 +173,8 @@ discard block |
||
| 173 | 173 | * @param object $payload |
| 174 | 174 | * @return void |
| 175 | 175 | */ |
| 176 | - public function validate_ipn_invoice( $invoice, $payload ) { |
|
| 177 | - if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) { |
|
| 176 | + public function validate_ipn_invoice($invoice, $payload) { |
|
| 177 | + if (!$invoice->exists() || $payload->id != $invoice->get_transaction_id()) { |
|
| 178 | 178 | exit; |
| 179 | 179 | } |
| 180 | 180 | } |
@@ -186,32 +186,32 @@ discard block |
||
| 186 | 186 | */ |
| 187 | 187 | public function maybe_process_old_ipn() { |
| 188 | 188 | |
| 189 | - $data = wp_unslash( $_POST ); |
|
| 189 | + $data = wp_unslash($_POST); |
|
| 190 | 190 | |
| 191 | 191 | // Only process subscriptions subscriptions. |
| 192 | - if ( empty( $_POST['x_subscription_id'] ) ) { |
|
| 192 | + if (empty($_POST['x_subscription_id'])) { |
|
| 193 | 193 | return; |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | // Check validity. |
| 197 | - $this->validate_old_ipn_signature( $data ); |
|
| 197 | + $this->validate_old_ipn_signature($data); |
|
| 198 | 198 | |
| 199 | 199 | // Fetch the associated subscription. |
| 200 | - $subscription_id = WPInv_Subscription::get_subscription_id_by_field( $_POST['x_subscription_id'] ); |
|
| 201 | - $subscription = new WPInv_Subscription( $subscription_id ); |
|
| 200 | + $subscription_id = WPInv_Subscription::get_subscription_id_by_field($_POST['x_subscription_id']); |
|
| 201 | + $subscription = new WPInv_Subscription($subscription_id); |
|
| 202 | 202 | |
| 203 | 203 | // Abort if it is missing or completed. |
| 204 | - if ( ! $subscription->get_id() || $subscription->has_status( 'completed' ) ) { |
|
| 204 | + if (!$subscription->get_id() || $subscription->has_status('completed')) { |
|
| 205 | 205 | return; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | // Payment status. |
| 209 | - if ( 1 == $_POST['x_response_code'] ) { |
|
| 209 | + if (1 == $_POST['x_response_code']) { |
|
| 210 | 210 | |
| 211 | 211 | // Renew the subscription. |
| 212 | 212 | $subscription->add_payment( |
| 213 | 213 | array( |
| 214 | - 'transaction_id' => sanitize_text_field( $data['x_trans_id'] ), |
|
| 214 | + 'transaction_id' => sanitize_text_field($data['x_trans_id']), |
|
| 215 | 215 | 'gateway' => $this->id |
| 216 | 216 | ) |
| 217 | 217 | ); |
@@ -230,17 +230,17 @@ discard block |
||
| 230 | 230 | * |
| 231 | 231 | * @param array $posted |
| 232 | 232 | */ |
| 233 | - public function validate_old_ipn_signature( $posted ) { |
|
| 233 | + public function validate_old_ipn_signature($posted) { |
|
| 234 | 234 | |
| 235 | - $signature = $this->get_option( 'signature_key' ); |
|
| 236 | - if ( ! empty( $signature ) ) { |
|
| 237 | - $login_id = $this->get_option( 'login_id' ); |
|
| 235 | + $signature = $this->get_option('signature_key'); |
|
| 236 | + if (!empty($signature)) { |
|
| 237 | + $login_id = $this->get_option('login_id'); |
|
| 238 | 238 | $trans_id = $_POST['x_trans_id']; |
| 239 | 239 | $amount = $_POST['x_amount']; |
| 240 | - $hash = hash_hmac ( 'sha512', "^$login_id^$trans_id^$amount^", hex2bin( $signature ) ); |
|
| 240 | + $hash = hash_hmac('sha512', "^$login_id^$trans_id^$amount^", hex2bin($signature)); |
|
| 241 | 241 | |
| 242 | - if ( ! hash_equals( $hash, $posted['x_SHA2_Hash'] ) ) { |
|
| 243 | - wpinv_error_log( $posted['x_SHA2_Hash'], "Invalid signature. Expected $hash" ); |
|
| 242 | + if (!hash_equals($hash, $posted['x_SHA2_Hash'])) { |
|
| 243 | + wpinv_error_log($posted['x_SHA2_Hash'], "Invalid signature. Expected $hash"); |
|
| 244 | 244 | exit; |
| 245 | 245 | } |
| 246 | 246 | |
@@ -253,28 +253,28 @@ discard block |
||
| 253 | 253 | */ |
| 254 | 254 | public function validate_ipn() { |
| 255 | 255 | |
| 256 | - wpinv_error_log( 'Validating Authorize.NET IPN response' ); |
|
| 256 | + wpinv_error_log('Validating Authorize.NET IPN response'); |
|
| 257 | 257 | |
| 258 | - if ( empty( $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) { |
|
| 258 | + if (empty($_SERVER['HTTP_X_ANET_SIGNATURE'])) { |
|
| 259 | 259 | return false; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - $signature = $this->get_option( 'signature_key' ); |
|
| 262 | + $signature = $this->get_option('signature_key'); |
|
| 263 | 263 | |
| 264 | - if ( empty( $signature ) ) { |
|
| 265 | - wpinv_error_log( 'Error: You have not set a signature key' ); |
|
| 264 | + if (empty($signature)) { |
|
| 265 | + wpinv_error_log('Error: You have not set a signature key'); |
|
| 266 | 266 | return false; |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - $hash = hash_hmac ( 'sha512', file_get_contents( 'php://input' ), hex2bin( $signature ) ); |
|
| 269 | + $hash = hash_hmac('sha512', file_get_contents('php://input'), hex2bin($signature)); |
|
| 270 | 270 | |
| 271 | - if ( hash_equals( $hash, $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) { |
|
| 272 | - wpinv_error_log( 'Successfully validated the IPN' ); |
|
| 271 | + if (hash_equals($hash, $_SERVER['HTTP_X_ANET_SIGNATURE'])) { |
|
| 272 | + wpinv_error_log('Successfully validated the IPN'); |
|
| 273 | 273 | return true; |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | - wpinv_error_log( 'IPN hash is not valid' ); |
|
| 277 | - wpinv_error_log( $_SERVER['HTTP_X_ANET_SIGNATURE'] ); |
|
| 276 | + wpinv_error_log('IPN hash is not valid'); |
|
| 277 | + wpinv_error_log($_SERVER['HTTP_X_ANET_SIGNATURE']); |
|
| 278 | 278 | return false; |
| 279 | 279 | |
| 280 | 280 | } |
@@ -19,16 +19,16 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | // Define constants. |
| 21 | 21 | if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) { |
| 22 | - define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
| 22 | + define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | if ( ! defined( 'WPINV_VERSION' ) ) { |
| 26 | - define( 'WPINV_VERSION', '2.1.10' ); |
|
| 26 | + define( 'WPINV_VERSION', '2.1.10' ); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | // Include the main Invoicing class. |
| 30 | 30 | if ( ! class_exists( 'WPInv_Plugin', false ) ) { |
| 31 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
| 31 | + require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | $GLOBALS['invoicing'] = new WPInv_Plugin(); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - return $GLOBALS['invoicing']; |
|
| 46 | + return $GLOBALS['invoicing']; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -15,20 +15,20 @@ discard block |
||
| 15 | 15 | * @package GetPaid |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | -defined( 'ABSPATH' ) || exit; |
|
| 18 | +defined('ABSPATH') || exit; |
|
| 19 | 19 | |
| 20 | 20 | // Define constants. |
| 21 | -if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) { |
|
| 22 | - define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
| 21 | +if (!defined('WPINV_PLUGIN_FILE')) { |
|
| 22 | + define('WPINV_PLUGIN_FILE', __FILE__); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | -if ( ! defined( 'WPINV_VERSION' ) ) { |
|
| 26 | - define( 'WPINV_VERSION', '2.1.10' ); |
|
| 25 | +if (!defined('WPINV_VERSION')) { |
|
| 26 | + define('WPINV_VERSION', '2.1.10'); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | // Include the main Invoicing class. |
| 30 | -if ( ! class_exists( 'WPInv_Plugin', false ) ) { |
|
| 31 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
| 30 | +if (!class_exists('WPInv_Plugin', false)) { |
|
| 31 | + require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/class-wpinv.php'; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | function getpaid() { |
| 41 | 41 | |
| 42 | - if ( empty( $GLOBALS['invoicing'] ) ) { |
|
| 42 | + if (empty($GLOBALS['invoicing'])) { |
|
| 43 | 43 | $GLOBALS['invoicing'] = new WPInv_Plugin(); |
| 44 | 44 | } |
| 45 | 45 | |
@@ -52,9 +52,9 @@ discard block |
||
| 52 | 52 | * @since 2.0.8 |
| 53 | 53 | */ |
| 54 | 54 | function getpaid_deactivation_hook() { |
| 55 | - update_option( 'wpinv_flush_permalinks', 1 ); |
|
| 55 | + update_option('wpinv_flush_permalinks', 1); |
|
| 56 | 56 | } |
| 57 | -register_deactivation_hook( __FILE__, 'getpaid_deactivation_hook' ); |
|
| 57 | +register_deactivation_hook(__FILE__, 'getpaid_deactivation_hook'); |
|
| 58 | 58 | |
| 59 | 59 | /** |
| 60 | 60 | * @deprecated |
@@ -64,4 +64,4 @@ discard block |
||
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | // Kickstart the plugin. |
| 67 | -add_action( 'plugins_loaded', 'getpaid', -100 ); |
|
| 67 | +add_action('plugins_loaded', 'getpaid', -100); |
|