@@ -7,23 +7,23 @@ discard block |
||
| 7 | 7 | * @version 1.0.19 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -defined( 'ABSPATH' ) || exit; |
|
| 10 | +defined('ABSPATH') || exit; |
|
| 11 | 11 | |
| 12 | 12 | ?> |
| 13 | 13 | |
| 14 | 14 | <div v-if="!is_default"> |
| 15 | 15 | |
| 16 | 16 | <small class='form-text text-muted mb-2'> |
| 17 | - <?php esc_html_e( 'This section allows you to add an existing item to the form that users can then buy. If you do not add an item, ensure that you add a price select or input field to the form.', 'invoicing' ); ?> |
|
| 17 | + <?php esc_html_e('This section allows you to add an existing item to the form that users can then buy. If you do not add an item, ensure that you add a price select or input field to the form.', 'invoicing'); ?> |
|
| 18 | 18 | </small> |
| 19 | 19 | |
| 20 | 20 | <label class='form-group'> |
| 21 | 21 | <input v-model='active_form_element.hide_cart' type='checkbox' /> |
| 22 | - <span class='form-check-label'><?php esc_html_e( 'Hide cart details', 'invoicing' ); ?></span> |
|
| 22 | + <span class='form-check-label'><?php esc_html_e('Hide cart details', 'invoicing'); ?></span> |
|
| 23 | 23 | </label> |
| 24 | 24 | |
| 25 | 25 | <div class="mb-1"> |
| 26 | - <?php esc_html_e( 'Form Items', 'invoicing' ); ?> |
|
| 26 | + <?php esc_html_e('Form Items', 'invoicing'); ?> |
|
| 27 | 27 | </div> |
| 28 | 28 | |
| 29 | 29 | <draggable v-model='form_items' group='selectable_form_items'> |
@@ -42,22 +42,22 @@ discard block |
||
| 42 | 42 | <div class='p-3'> |
| 43 | 43 | |
| 44 | 44 | <span class='form-text'> |
| 45 | - <a target="_blank" :href="'<?php echo esc_url( admin_url( '/post.php?action=edit&post' ) ) ?>=' + item.id"> |
|
| 46 | - <?php _e( 'Edit the item name, price and other details', 'invoicing' ); ?> |
|
| 45 | + <a target="_blank" :href="'<?php echo esc_url(admin_url('/post.php?action=edit&post')) ?>=' + item.id"> |
|
| 46 | + <?php _e('Edit the item name, price and other details', 'invoicing'); ?> |
|
| 47 | 47 | </a> |
| 48 | 48 | </span> |
| 49 | 49 | |
| 50 | 50 | <label class='form-group d-block'> |
| 51 | 51 | <input v-model='item.allow_quantities' type='checkbox' /> |
| 52 | - <span><?php _e( 'Allow users to buy several quantities', 'invoicing' ); ?></span> |
|
| 52 | + <span><?php _e('Allow users to buy several quantities', 'invoicing'); ?></span> |
|
| 53 | 53 | </label> |
| 54 | 54 | |
| 55 | 55 | <label class='form-group d-block'> |
| 56 | 56 | <input v-model='item.required' type='checkbox' /> |
| 57 | - <span><?php _e( 'This item is required', 'invoicing' ); ?></span> |
|
| 57 | + <span><?php _e('This item is required', 'invoicing'); ?></span> |
|
| 58 | 58 | </label> |
| 59 | 59 | |
| 60 | - <button type='button' class='button button-link button-link-delete' @click.prevent='removeItem(item)'><?php _e( 'Delete Item', 'invoicing' ); ?></button> |
|
| 60 | + <button type='button' class='button button-link button-link-delete' @click.prevent='removeItem(item)'><?php _e('Delete Item', 'invoicing'); ?></button> |
|
| 61 | 61 | |
| 62 | 62 | </div> |
| 63 | 63 | </div> |
@@ -65,19 +65,19 @@ discard block |
||
| 65 | 65 | </div> |
| 66 | 66 | </draggable> |
| 67 | 67 | |
| 68 | - <small v-if='! form_items.length' class='form-text text-danger'><?php _e( 'You have not set up any items. Please select an item below or create a new item.', 'invoicing' ); ?></small> |
|
| 68 | + <small v-if='! form_items.length' class='form-text text-danger'><?php _e('You have not set up any items. Please select an item below or create a new item.', 'invoicing'); ?></small> |
|
| 69 | 69 | |
| 70 | 70 | <div class="mt-4 mb-4"> |
| 71 | 71 | |
| 72 | 72 | <div class="mb-2"> |
| 73 | 73 | <select class='w-100' v-init-item-search> |
| 74 | - <option value="" selected="selected"><?php _e( 'Select an item to add...', 'invoicing' ) ?></option> |
|
| 74 | + <option value="" selected="selected"><?php _e('Select an item to add...', 'invoicing') ?></option> |
|
| 75 | 75 | </select> |
| 76 | 76 | |
| 77 | 77 | </div> |
| 78 | 78 | |
| 79 | - <button type="button" @click.prevent='addSelectedItem' class="button button-primary"><?php _e( 'Add Selected Item', 'invoicing' ) ?></button> |
|
| 80 | - <a href="<?php echo esc_url( admin_url( 'post-new.php?post_type=wpi_item' ) ); ?>" target="_blank" class="button button-secondary"><?php _e( 'Create New Item.', 'invoicing' ) ?></a> |
|
| 79 | + <button type="button" @click.prevent='addSelectedItem' class="button button-primary"><?php _e('Add Selected Item', 'invoicing') ?></button> |
|
| 80 | + <a href="<?php echo esc_url(admin_url('post-new.php?post_type=wpi_item')); ?>" target="_blank" class="button button-secondary"><?php _e('Create New Item.', 'invoicing') ?></a> |
|
| 81 | 81 | |
| 82 | 82 | </div> |
| 83 | 83 | </div> |
@@ -86,13 +86,13 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | <label class="w-100 d-block"> |
| 88 | 88 | |
| 89 | - <span><?php esc_html_e( 'Let customers...', 'invoicing' ) ?></span> |
|
| 89 | + <span><?php esc_html_e('Let customers...', 'invoicing') ?></span> |
|
| 90 | 90 | |
| 91 | 91 | <select class='w-100' style="padding: 6px 24px 6px 8px; border-color: #e0e0e0;" v-model='active_form_element.items_type'> |
| 92 | - <option value='total'><?php _e( 'Buy all items on the list', 'invoicing' ); ?></option> |
|
| 93 | - <option value='radio'><?php _e( 'Select a single item from the list', 'invoicing' ); ?></option> |
|
| 94 | - <option value='checkbox'><?php _e( 'Select one or more items on the list', 'invoicing' ) ;?></option> |
|
| 95 | - <option value='select'><?php _e( 'Select a single item from a dropdown', 'invoicing' ); ?></option> |
|
| 92 | + <option value='total'><?php _e('Buy all items on the list', 'invoicing'); ?></option> |
|
| 93 | + <option value='radio'><?php _e('Select a single item from the list', 'invoicing'); ?></option> |
|
| 94 | + <option value='checkbox'><?php _e('Select one or more items on the list', 'invoicing'); ?></option> |
|
| 95 | + <option value='select'><?php _e('Select a single item from a dropdown', 'invoicing'); ?></option> |
|
| 96 | 96 | </select> |
| 97 | 97 | |
| 98 | 98 | </label> |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | <div class='form-group'> |
| 103 | 103 | <label class="d-block"> |
| 104 | - <span><?php esc_html_e( 'Help Text', 'invoicing' ); ?></span> |
|
| 105 | - <textarea placeholder='<?php esc_attr_e( 'Add some help text for this field', 'invoicing' ); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea> |
|
| 104 | + <span><?php esc_html_e('Help Text', 'invoicing'); ?></span> |
|
| 105 | + <textarea placeholder='<?php esc_attr_e('Add some help text for this field', 'invoicing'); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea> |
|
| 106 | 106 | </label> |
| 107 | 107 | </div> |
@@ -12,432 +12,432 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Paypal_Gateway_IPN_Handler { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Payment method id. |
|
| 17 | - * |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 20 | - protected $id = 'paypal'; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Payment method object. |
|
| 24 | - * |
|
| 25 | - * @var GetPaid_Paypal_Gateway |
|
| 26 | - */ |
|
| 27 | - protected $gateway; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Class constructor. |
|
| 31 | - * |
|
| 32 | - * @param GetPaid_Paypal_Gateway $gateway |
|
| 33 | - */ |
|
| 34 | - public function __construct( $gateway ) { |
|
| 35 | - $this->gateway = $gateway; |
|
| 36 | - $this->verify_ipn(); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Processes ipns and marks payments as complete. |
|
| 41 | - * |
|
| 42 | - * @return void |
|
| 43 | - */ |
|
| 44 | - public function verify_ipn() { |
|
| 45 | - |
|
| 46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler' ); |
|
| 47 | - |
|
| 48 | - // Validate the IPN. |
|
| 49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
| 50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - // Process the IPN. |
|
| 54 | - $posted = wp_unslash( $_POST ); |
|
| 55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
| 56 | - |
|
| 57 | - // Abort if it was not paid by our gateway. |
|
| 58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
| 59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal' ); |
|
| 60 | - wp_die( 'Invoice not paid via PayPal', 500 ); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - $posted['payment_status'] = sanitize_key( strtolower( $posted['payment_status'] ) ); |
|
| 64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
| 65 | - |
|
| 66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'] ); |
|
| 67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'] ); |
|
| 68 | - |
|
| 69 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
| 70 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data' ); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
| 74 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
| 75 | - wpinv_error_log( 'Done processing IPN' ); |
|
| 76 | - wp_die( 'Processed', 200 ); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'] ); |
|
| 80 | - wp_die( 'Unsupported IPN type', 200 ); |
|
| 81 | - |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Retrieves IPN Invoice. |
|
| 86 | - * |
|
| 87 | - * @param array $posted |
|
| 88 | - * @return WPInv_Invoice |
|
| 89 | - */ |
|
| 90 | - protected function get_ipn_invoice( $posted ) { |
|
| 91 | - |
|
| 92 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice' ); |
|
| 93 | - |
|
| 94 | - if ( ! empty( $posted['custom'] ) ) { |
|
| 95 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
| 96 | - |
|
| 97 | - if ( $invoice->exists() ) { |
|
| 98 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number() ); |
|
| 99 | - return $invoice; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - wpinv_error_log( 'Could not retrieve the associated invoice.' ); |
|
| 105 | - wp_die( 'Could not retrieve the associated invoice.', 500 ); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Check PayPal IPN validity. |
|
| 110 | - */ |
|
| 111 | - protected function validate_ipn() { |
|
| 112 | - |
|
| 113 | - wpinv_error_log( 'Validating PayPal IPN response' ); |
|
| 114 | - |
|
| 115 | - // Retrieve the associated invoice. |
|
| 116 | - $posted = wp_unslash( $_POST ); |
|
| 117 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
| 118 | - |
|
| 119 | - // Validate the IPN. |
|
| 120 | - $posted['cmd'] = '_notify-validate'; |
|
| 121 | - |
|
| 122 | - // Send back post vars to paypal. |
|
| 123 | - $params = array( |
|
| 124 | - 'body' => $posted, |
|
| 125 | - 'timeout' => 60, |
|
| 126 | - 'httpversion' => '1.1', |
|
| 127 | - 'compress' => false, |
|
| 128 | - 'decompress' => false, |
|
| 129 | - 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
| 130 | - ); |
|
| 131 | - |
|
| 132 | - // Post back to get a response. |
|
| 133 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
| 134 | - |
|
| 135 | - // Check to see if the request was valid. |
|
| 136 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
| 137 | - wpinv_error_log( $response['body'], 'Received valid response from PayPal IPN' ); |
|
| 138 | - return true; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - if ( is_wp_error( $response ) ) { |
|
| 142 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
| 143 | - return false; |
|
| 144 | - } |
|
| 15 | + /** |
|
| 16 | + * Payment method id. |
|
| 17 | + * |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | + protected $id = 'paypal'; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Payment method object. |
|
| 24 | + * |
|
| 25 | + * @var GetPaid_Paypal_Gateway |
|
| 26 | + */ |
|
| 27 | + protected $gateway; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Class constructor. |
|
| 31 | + * |
|
| 32 | + * @param GetPaid_Paypal_Gateway $gateway |
|
| 33 | + */ |
|
| 34 | + public function __construct( $gateway ) { |
|
| 35 | + $this->gateway = $gateway; |
|
| 36 | + $this->verify_ipn(); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Processes ipns and marks payments as complete. |
|
| 41 | + * |
|
| 42 | + * @return void |
|
| 43 | + */ |
|
| 44 | + public function verify_ipn() { |
|
| 45 | + |
|
| 46 | + wpinv_error_log( 'GetPaid PayPal IPN Handler' ); |
|
| 47 | + |
|
| 48 | + // Validate the IPN. |
|
| 49 | + if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
| 50 | + wp_die( 'PayPal IPN Request Failure', 500 ); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + // Process the IPN. |
|
| 54 | + $posted = wp_unslash( $_POST ); |
|
| 55 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
| 56 | + |
|
| 57 | + // Abort if it was not paid by our gateway. |
|
| 58 | + if ( $this->id != $invoice->get_gateway() ) { |
|
| 59 | + wpinv_error_log( 'Aborting, Invoice was not paid via PayPal' ); |
|
| 60 | + wp_die( 'Invoice not paid via PayPal', 500 ); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + $posted['payment_status'] = sanitize_key( strtolower( $posted['payment_status'] ) ); |
|
| 64 | + $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
| 65 | + |
|
| 66 | + wpinv_error_log( 'Payment status:' . $posted['payment_status'] ); |
|
| 67 | + wpinv_error_log( 'IPN Type:' . $posted['txn_type'] ); |
|
| 68 | + |
|
| 69 | + if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
| 70 | + wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data' ); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
| 74 | + call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
| 75 | + wpinv_error_log( 'Done processing IPN' ); |
|
| 76 | + wp_die( 'Processed', 200 ); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'] ); |
|
| 80 | + wp_die( 'Unsupported IPN type', 200 ); |
|
| 81 | + |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Retrieves IPN Invoice. |
|
| 86 | + * |
|
| 87 | + * @param array $posted |
|
| 88 | + * @return WPInv_Invoice |
|
| 89 | + */ |
|
| 90 | + protected function get_ipn_invoice( $posted ) { |
|
| 91 | + |
|
| 92 | + wpinv_error_log( 'Retrieving PayPal IPN Response Invoice' ); |
|
| 93 | + |
|
| 94 | + if ( ! empty( $posted['custom'] ) ) { |
|
| 95 | + $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
| 96 | + |
|
| 97 | + if ( $invoice->exists() ) { |
|
| 98 | + wpinv_error_log( 'Found invoice #' . $invoice->get_number() ); |
|
| 99 | + return $invoice; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + wpinv_error_log( 'Could not retrieve the associated invoice.' ); |
|
| 105 | + wp_die( 'Could not retrieve the associated invoice.', 500 ); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Check PayPal IPN validity. |
|
| 110 | + */ |
|
| 111 | + protected function validate_ipn() { |
|
| 112 | + |
|
| 113 | + wpinv_error_log( 'Validating PayPal IPN response' ); |
|
| 114 | + |
|
| 115 | + // Retrieve the associated invoice. |
|
| 116 | + $posted = wp_unslash( $_POST ); |
|
| 117 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
| 118 | + |
|
| 119 | + // Validate the IPN. |
|
| 120 | + $posted['cmd'] = '_notify-validate'; |
|
| 121 | + |
|
| 122 | + // Send back post vars to paypal. |
|
| 123 | + $params = array( |
|
| 124 | + 'body' => $posted, |
|
| 125 | + 'timeout' => 60, |
|
| 126 | + 'httpversion' => '1.1', |
|
| 127 | + 'compress' => false, |
|
| 128 | + 'decompress' => false, |
|
| 129 | + 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
| 130 | + ); |
|
| 131 | + |
|
| 132 | + // Post back to get a response. |
|
| 133 | + $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
| 134 | + |
|
| 135 | + // Check to see if the request was valid. |
|
| 136 | + if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
| 137 | + wpinv_error_log( $response['body'], 'Received valid response from PayPal IPN' ); |
|
| 138 | + return true; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + if ( is_wp_error( $response ) ) { |
|
| 142 | + wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
| 143 | + return false; |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
| 147 | - return false; |
|
| 148 | - |
|
| 149 | - } |
|
| 146 | + wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
| 147 | + return false; |
|
| 148 | + |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * Check currency from IPN matches the invoice. |
|
| 153 | - * |
|
| 154 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 155 | - * @param string $currency currency to validate. |
|
| 156 | - */ |
|
| 157 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
| 151 | + /** |
|
| 152 | + * Check currency from IPN matches the invoice. |
|
| 153 | + * |
|
| 154 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 155 | + * @param string $currency currency to validate. |
|
| 156 | + */ |
|
| 157 | + protected function validate_ipn_currency( $invoice, $currency ) { |
|
| 158 | 158 | |
| 159 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
| 159 | + if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
| 160 | 160 | |
| 161 | - /* translators: %s: currency code. */ |
|
| 162 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
| 161 | + /* translators: %s: currency code. */ |
|
| 162 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
| 163 | 163 | |
| 164 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 165 | - } |
|
| 164 | + wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - wpinv_error_log( $currency, 'Validated IPN Currency' ); |
|
| 168 | - } |
|
| 167 | + wpinv_error_log( $currency, 'Validated IPN Currency' ); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - /** |
|
| 171 | - * Check payment amount from IPN matches the invoice. |
|
| 172 | - * |
|
| 173 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 174 | - * @param float $amount amount to validate. |
|
| 175 | - */ |
|
| 176 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
| 177 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
| 170 | + /** |
|
| 171 | + * Check payment amount from IPN matches the invoice. |
|
| 172 | + * |
|
| 173 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 174 | + * @param float $amount amount to validate. |
|
| 175 | + */ |
|
| 176 | + protected function validate_ipn_amount( $invoice, $amount ) { |
|
| 177 | + if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
| 178 | 178 | |
| 179 | - /* translators: %s: Amount. */ |
|
| 180 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
| 179 | + /* translators: %s: Amount. */ |
|
| 180 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
| 181 | 181 | |
| 182 | - wpinv_error_log( "Currencies do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 183 | - } |
|
| 182 | + wpinv_error_log( "Currencies do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - wpinv_error_log( $amount, 'Validated IPN Amount' ); |
|
| 186 | - } |
|
| 185 | + wpinv_error_log( $amount, 'Validated IPN Amount' ); |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - /** |
|
| 189 | - * Verify receiver email from PayPal. |
|
| 190 | - * |
|
| 191 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 192 | - * @param string $receiver_email Email to validate. |
|
| 193 | - */ |
|
| 194 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
| 195 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
| 188 | + /** |
|
| 189 | + * Verify receiver email from PayPal. |
|
| 190 | + * |
|
| 191 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 192 | + * @param string $receiver_email Email to validate. |
|
| 193 | + */ |
|
| 194 | + protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
| 195 | + $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
| 196 | 196 | |
| 197 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
| 198 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
| 197 | + if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
| 198 | + wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
| 199 | 199 | |
| 200 | - /* translators: %s: email address . */ |
|
| 201 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
| 200 | + /* translators: %s: email address . */ |
|
| 201 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
| 202 | 202 | |
| 203 | - wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 204 | - } |
|
| 203 | + wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - wpinv_error_log( 'Validated PayPal Email' ); |
|
| 207 | - } |
|
| 206 | + wpinv_error_log( 'Validated PayPal Email' ); |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Handles one time payments. |
|
| 211 | - * |
|
| 212 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 213 | - * @param array $posted Posted data. |
|
| 214 | - */ |
|
| 215 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
| 216 | - |
|
| 217 | - // Collect payment details |
|
| 218 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
| 219 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 220 | - |
|
| 221 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 222 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 223 | - |
|
| 224 | - // Update the transaction id. |
|
| 225 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
| 226 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
| 227 | - $invoice->save(); |
|
| 228 | - } |
|
| 209 | + /** |
|
| 210 | + * Handles one time payments. |
|
| 211 | + * |
|
| 212 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 213 | + * @param array $posted Posted data. |
|
| 214 | + */ |
|
| 215 | + protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
| 216 | + |
|
| 217 | + // Collect payment details |
|
| 218 | + $payment_status = strtolower( $posted['payment_status'] ); |
|
| 219 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 220 | + |
|
| 221 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 222 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 223 | + |
|
| 224 | + // Update the transaction id. |
|
| 225 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
| 226 | + $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
| 227 | + $invoice->save(); |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | - // Process a refund. |
|
| 231 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
| 230 | + // Process a refund. |
|
| 231 | + if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
| 232 | 232 | |
| 233 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
| 233 | + update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
| 234 | 234 | |
| 235 | - if ( ! $invoice->is_refunded() ) { |
|
| 236 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
| 237 | - } |
|
| 235 | + if ( ! $invoice->is_refunded() ) { |
|
| 236 | + $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - return wpinv_error_log( $posted['reason_code'] ); |
|
| 240 | - } |
|
| 239 | + return wpinv_error_log( $posted['reason_code'] ); |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | - // Process payments. |
|
| 243 | - if ( $payment_status == 'completed' ) { |
|
| 242 | + // Process payments. |
|
| 243 | + if ( $payment_status == 'completed' ) { |
|
| 244 | 244 | |
| 245 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
| 246 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.' ); |
|
| 247 | - } |
|
| 245 | + if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
| 246 | + return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.' ); |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
| 249 | + $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
| 250 | 250 | |
| 251 | - $note = ''; |
|
| 252 | - |
|
| 253 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
| 254 | - $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
| 255 | - } |
|
| 251 | + $note = ''; |
|
| 252 | + |
|
| 253 | + if ( ! empty( $posted['mc_fee'] ) ) { |
|
| 254 | + $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
| 258 | - $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
| 259 | - } |
|
| 257 | + if ( ! empty( $posted['payer_status'] ) ) { |
|
| 258 | + $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
| 262 | - return wpinv_error_log( 'Invoice marked as paid.' ); |
|
| 261 | + $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
| 262 | + return wpinv_error_log( 'Invoice marked as paid.' ); |
|
| 263 | 263 | |
| 264 | - } |
|
| 265 | - |
|
| 266 | - // Pending payments. |
|
| 267 | - if ( $payment_status == 'pending' ) { |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + // Pending payments. |
|
| 267 | + if ( $payment_status == 'pending' ) { |
|
| 268 | 268 | |
| 269 | - /* translators: %s: pending reason. */ |
|
| 270 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
| 271 | - |
|
| 272 | - return wpinv_error_log( 'Invoice marked as "payment held".' ); |
|
| 273 | - } |
|
| 269 | + /* translators: %s: pending reason. */ |
|
| 270 | + $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
| 271 | + |
|
| 272 | + return wpinv_error_log( 'Invoice marked as "payment held".' ); |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | - /* translators: %s: payment status. */ |
|
| 276 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
| 275 | + /* translators: %s: payment status. */ |
|
| 276 | + $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
| 277 | 277 | |
| 278 | - } |
|
| 278 | + } |
|
| 279 | 279 | |
| 280 | - /** |
|
| 281 | - * Handles one time payments. |
|
| 282 | - * |
|
| 283 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 284 | - * @param array $posted Posted data. |
|
| 285 | - */ |
|
| 286 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
| 287 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
| 288 | - } |
|
| 280 | + /** |
|
| 281 | + * Handles one time payments. |
|
| 282 | + * |
|
| 283 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 284 | + * @param array $posted Posted data. |
|
| 285 | + */ |
|
| 286 | + protected function ipn_txn_cart( $invoice, $posted ) { |
|
| 287 | + $this->ipn_txn_web_accept( $invoice, $posted ); |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | - /** |
|
| 291 | - * Handles subscription sign ups. |
|
| 292 | - * |
|
| 293 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 294 | - * @param array $posted Posted data. |
|
| 295 | - */ |
|
| 296 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
| 290 | + /** |
|
| 291 | + * Handles subscription sign ups. |
|
| 292 | + * |
|
| 293 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 294 | + * @param array $posted Posted data. |
|
| 295 | + */ |
|
| 296 | + protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
| 297 | 297 | |
| 298 | - wpinv_error_log( $posted, 'Processing subscription signup' ); |
|
| 298 | + wpinv_error_log( $posted, 'Processing subscription signup' ); |
|
| 299 | 299 | |
| 300 | - // Make sure the invoice has a subscription. |
|
| 301 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 300 | + // Make sure the invoice has a subscription. |
|
| 301 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 302 | 302 | |
| 303 | - if ( empty( $subscription ) ) { |
|
| 304 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 305 | - } |
|
| 303 | + if ( empty( $subscription ) ) { |
|
| 304 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - // Validate the IPN. |
|
| 308 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 309 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 310 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 311 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
| 307 | + // Validate the IPN. |
|
| 308 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 309 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 310 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 311 | + $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
| 312 | 312 | |
| 313 | - // Activate the subscription. |
|
| 314 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
| 315 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 316 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
| 317 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
| 318 | - $subscription->activate(); |
|
| 313 | + // Activate the subscription. |
|
| 314 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
| 315 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 316 | + $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
| 317 | + $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
| 318 | + $subscription->activate(); |
|
| 319 | 319 | |
| 320 | - // Set the transaction id. |
|
| 321 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
| 322 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
| 323 | - } |
|
| 320 | + // Set the transaction id. |
|
| 321 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
| 322 | + $invoice->set_transaction_id( $posted['txn_id'] ); |
|
| 323 | + } |
|
| 324 | 324 | |
| 325 | - // Update the payment status. |
|
| 326 | - $invoice->mark_paid(); |
|
| 325 | + // Update the payment status. |
|
| 326 | + $invoice->mark_paid(); |
|
| 327 | 327 | |
| 328 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
| 328 | + $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
| 329 | 329 | |
| 330 | - wpinv_error_log( 'Subscription started.' ); |
|
| 331 | - } |
|
| 330 | + wpinv_error_log( 'Subscription started.' ); |
|
| 331 | + } |
|
| 332 | 332 | |
| 333 | - /** |
|
| 334 | - * Handles subscription renewals. |
|
| 335 | - * |
|
| 336 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 337 | - * @param array $posted Posted data. |
|
| 338 | - */ |
|
| 339 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
| 333 | + /** |
|
| 334 | + * Handles subscription renewals. |
|
| 335 | + * |
|
| 336 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 337 | + * @param array $posted Posted data. |
|
| 338 | + */ |
|
| 339 | + protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
| 340 | 340 | |
| 341 | - // Make sure the invoice has a subscription. |
|
| 342 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 341 | + // Make sure the invoice has a subscription. |
|
| 342 | + $subscription = wpinv_get_subscription( $invoice ); |
|
| 343 | 343 | |
| 344 | - if ( empty( $subscription ) ) { |
|
| 345 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 346 | - } |
|
| 344 | + if ( empty( $subscription ) ) { |
|
| 345 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 346 | + } |
|
| 347 | 347 | |
| 348 | - // Abort if this is the first payment. |
|
| 349 | - if ( date( 'Ynd', $subscription->get_date_created() ) == date( 'Ynd', strtotime( $posted['payment_date'] ) ) ) { |
|
| 350 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
| 351 | - $invoice->save(); |
|
| 352 | - return; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id() ); |
|
| 348 | + // Abort if this is the first payment. |
|
| 349 | + if ( date( 'Ynd', $subscription->get_date_created() ) == date( 'Ynd', strtotime( $posted['payment_date'] ) ) ) { |
|
| 350 | + $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
| 351 | + $invoice->save(); |
|
| 352 | + return; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id() ); |
|
| 356 | 356 | |
| 357 | - // Abort if the payment is already recorded. |
|
| 358 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
| 359 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed' ); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - $args = array( |
|
| 363 | - 'transaction_id' => $posted['txn_id'], |
|
| 364 | - 'gateway' => $this->id, |
|
| 365 | - ); |
|
| 366 | - |
|
| 367 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
| 368 | - |
|
| 369 | - if ( empty( $invoice ) ) { |
|
| 370 | - return; |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
| 374 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
| 375 | - |
|
| 376 | - $subscription->renew(); |
|
| 377 | - wpinv_error_log( 'Subscription renewed.' ); |
|
| 378 | - |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * Handles subscription cancelations. |
|
| 383 | - * |
|
| 384 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 385 | - */ |
|
| 386 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
| 387 | - |
|
| 388 | - // Make sure the invoice has a subscription. |
|
| 389 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 390 | - |
|
| 391 | - if ( empty( $subscription ) ) { |
|
| 392 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id() ); |
|
| 396 | - $subscription->cancel(); |
|
| 397 | - wpinv_error_log( 'Subscription cancelled.' ); |
|
| 398 | - |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * Handles subscription completions. |
|
| 403 | - * |
|
| 404 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 405 | - * @param array $posted Posted data. |
|
| 406 | - */ |
|
| 407 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
| 408 | - |
|
| 409 | - // Make sure the invoice has a subscription. |
|
| 410 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 357 | + // Abort if the payment is already recorded. |
|
| 358 | + if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
| 359 | + return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed' ); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + $args = array( |
|
| 363 | + 'transaction_id' => $posted['txn_id'], |
|
| 364 | + 'gateway' => $this->id, |
|
| 365 | + ); |
|
| 366 | + |
|
| 367 | + $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
| 368 | + |
|
| 369 | + if ( empty( $invoice ) ) { |
|
| 370 | + return; |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
| 374 | + $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
| 375 | + |
|
| 376 | + $subscription->renew(); |
|
| 377 | + wpinv_error_log( 'Subscription renewed.' ); |
|
| 378 | + |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * Handles subscription cancelations. |
|
| 383 | + * |
|
| 384 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 385 | + */ |
|
| 386 | + protected function ipn_txn_subscr_cancel( $invoice ) { |
|
| 387 | + |
|
| 388 | + // Make sure the invoice has a subscription. |
|
| 389 | + $subscription = wpinv_get_subscription( $invoice ); |
|
| 390 | + |
|
| 391 | + if ( empty( $subscription ) ) { |
|
| 392 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id() ); |
|
| 396 | + $subscription->cancel(); |
|
| 397 | + wpinv_error_log( 'Subscription cancelled.' ); |
|
| 398 | + |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * Handles subscription completions. |
|
| 403 | + * |
|
| 404 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 405 | + * @param array $posted Posted data. |
|
| 406 | + */ |
|
| 407 | + protected function ipn_txn_subscr_eot( $invoice ) { |
|
| 408 | + |
|
| 409 | + // Make sure the invoice has a subscription. |
|
| 410 | + $subscription = wpinv_get_subscription( $invoice ); |
|
| 411 | 411 | |
| 412 | - if ( empty( $subscription ) ) { |
|
| 413 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 414 | - } |
|
| 412 | + if ( empty( $subscription ) ) { |
|
| 413 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 414 | + } |
|
| 415 | 415 | |
| 416 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id() ); |
|
| 417 | - $subscription->complete(); |
|
| 418 | - wpinv_error_log( 'Subscription completed.' ); |
|
| 416 | + wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id() ); |
|
| 417 | + $subscription->complete(); |
|
| 418 | + wpinv_error_log( 'Subscription completed.' ); |
|
| 419 | 419 | |
| 420 | - } |
|
| 420 | + } |
|
| 421 | 421 | |
| 422 | - /** |
|
| 423 | - * Handles subscription fails. |
|
| 424 | - * |
|
| 425 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 426 | - * @param array $posted Posted data. |
|
| 427 | - */ |
|
| 428 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
| 422 | + /** |
|
| 423 | + * Handles subscription fails. |
|
| 424 | + * |
|
| 425 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 426 | + * @param array $posted Posted data. |
|
| 427 | + */ |
|
| 428 | + protected function ipn_txn_subscr_failed( $invoice ) { |
|
| 429 | 429 | |
| 430 | - // Make sure the invoice has a subscription. |
|
| 431 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 430 | + // Make sure the invoice has a subscription. |
|
| 431 | + $subscription = wpinv_get_subscription( $invoice ); |
|
| 432 | 432 | |
| 433 | - if ( empty( $subscription ) ) { |
|
| 434 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 435 | - } |
|
| 433 | + if ( empty( $subscription ) ) { |
|
| 434 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 435 | + } |
|
| 436 | 436 | |
| 437 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id() ); |
|
| 438 | - $subscription->failing(); |
|
| 439 | - wpinv_error_log( 'Subscription marked as failing.' ); |
|
| 437 | + wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id() ); |
|
| 438 | + $subscription->failing(); |
|
| 439 | + wpinv_error_log( 'Subscription marked as failing.' ); |
|
| 440 | 440 | |
| 441 | - } |
|
| 441 | + } |
|
| 442 | 442 | |
| 443 | 443 | } |
@@ -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 | * Paypal Payment Gateway IPN handler class. |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * |
| 32 | 32 | * @param GetPaid_Paypal_Gateway $gateway |
| 33 | 33 | */ |
| 34 | - public function __construct( $gateway ) { |
|
| 34 | + public function __construct($gateway) { |
|
| 35 | 35 | $this->gateway = $gateway; |
| 36 | 36 | $this->verify_ipn(); |
| 37 | 37 | } |
@@ -43,41 +43,41 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function verify_ipn() { |
| 45 | 45 | |
| 46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler' ); |
|
| 46 | + wpinv_error_log('GetPaid PayPal IPN Handler'); |
|
| 47 | 47 | |
| 48 | 48 | // Validate the IPN. |
| 49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
| 50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
| 49 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
| 50 | + wp_die('PayPal IPN Request Failure', 500); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | // Process the IPN. |
| 54 | - $posted = wp_unslash( $_POST ); |
|
| 55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
| 54 | + $posted = wp_unslash($_POST); |
|
| 55 | + $invoice = $this->get_ipn_invoice($posted); |
|
| 56 | 56 | |
| 57 | 57 | // Abort if it was not paid by our gateway. |
| 58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
| 59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal' ); |
|
| 60 | - wp_die( 'Invoice not paid via PayPal', 500 ); |
|
| 58 | + if ($this->id != $invoice->get_gateway()) { |
|
| 59 | + wpinv_error_log('Aborting, Invoice was not paid via PayPal'); |
|
| 60 | + wp_die('Invoice not paid via PayPal', 500); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - $posted['payment_status'] = sanitize_key( strtolower( $posted['payment_status'] ) ); |
|
| 64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
| 63 | + $posted['payment_status'] = sanitize_key(strtolower($posted['payment_status'])); |
|
| 64 | + $posted['txn_type'] = sanitize_key(strtolower($posted['txn_type'])); |
|
| 65 | 65 | |
| 66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'] ); |
|
| 67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'] ); |
|
| 66 | + wpinv_error_log('Payment status:' . $posted['payment_status']); |
|
| 67 | + wpinv_error_log('IPN Type:' . $posted['txn_type']); |
|
| 68 | 68 | |
| 69 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
| 70 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data' ); |
|
| 69 | + if ($this->gateway->is_sandbox($invoice)) { |
|
| 70 | + wpinv_error_log($posted, 'Invoice was processed in sandbox hence logging the posted data'); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
| 74 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
| 75 | - wpinv_error_log( 'Done processing IPN' ); |
|
| 76 | - wp_die( 'Processed', 200 ); |
|
| 73 | + if (method_exists($this, 'ipn_txn_' . $posted['txn_type'])) { |
|
| 74 | + call_user_func(array($this, 'ipn_txn_' . $posted['txn_type']), $invoice, $posted); |
|
| 75 | + wpinv_error_log('Done processing IPN'); |
|
| 76 | + wp_die('Processed', 200); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'] ); |
|
| 80 | - wp_die( 'Unsupported IPN type', 200 ); |
|
| 79 | + wpinv_error_log('Aborting, Unsupported IPN type:' . $posted['txn_type']); |
|
| 80 | + wp_die('Unsupported IPN type', 200); |
|
| 81 | 81 | |
| 82 | 82 | } |
| 83 | 83 | |
@@ -87,22 +87,22 @@ discard block |
||
| 87 | 87 | * @param array $posted |
| 88 | 88 | * @return WPInv_Invoice |
| 89 | 89 | */ |
| 90 | - protected function get_ipn_invoice( $posted ) { |
|
| 90 | + protected function get_ipn_invoice($posted) { |
|
| 91 | 91 | |
| 92 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice' ); |
|
| 92 | + wpinv_error_log('Retrieving PayPal IPN Response Invoice'); |
|
| 93 | 93 | |
| 94 | - if ( ! empty( $posted['custom'] ) ) { |
|
| 95 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
| 94 | + if (!empty($posted['custom'])) { |
|
| 95 | + $invoice = new WPInv_Invoice($posted['custom']); |
|
| 96 | 96 | |
| 97 | - if ( $invoice->exists() ) { |
|
| 98 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number() ); |
|
| 97 | + if ($invoice->exists()) { |
|
| 98 | + wpinv_error_log('Found invoice #' . $invoice->get_number()); |
|
| 99 | 99 | return $invoice; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - wpinv_error_log( 'Could not retrieve the associated invoice.' ); |
|
| 105 | - wp_die( 'Could not retrieve the associated invoice.', 500 ); |
|
| 104 | + wpinv_error_log('Could not retrieve the associated invoice.'); |
|
| 105 | + wp_die('Could not retrieve the associated invoice.', 500); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -110,11 +110,11 @@ discard block |
||
| 110 | 110 | */ |
| 111 | 111 | protected function validate_ipn() { |
| 112 | 112 | |
| 113 | - wpinv_error_log( 'Validating PayPal IPN response' ); |
|
| 113 | + wpinv_error_log('Validating PayPal IPN response'); |
|
| 114 | 114 | |
| 115 | 115 | // Retrieve the associated invoice. |
| 116 | - $posted = wp_unslash( $_POST ); |
|
| 117 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
| 116 | + $posted = wp_unslash($_POST); |
|
| 117 | + $invoice = $this->get_ipn_invoice($posted); |
|
| 118 | 118 | |
| 119 | 119 | // Validate the IPN. |
| 120 | 120 | $posted['cmd'] = '_notify-validate'; |
@@ -130,20 +130,20 @@ discard block |
||
| 130 | 130 | ); |
| 131 | 131 | |
| 132 | 132 | // Post back to get a response. |
| 133 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
| 133 | + $response = wp_safe_remote_post($this->gateway->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params); |
|
| 134 | 134 | |
| 135 | 135 | // Check to see if the request was valid. |
| 136 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
| 137 | - wpinv_error_log( $response['body'], 'Received valid response from PayPal IPN' ); |
|
| 136 | + if (!is_wp_error($response) && $response['response']['code'] < 300 && strstr($response['body'], 'VERIFIED')) { |
|
| 137 | + wpinv_error_log($response['body'], 'Received valid response from PayPal IPN'); |
|
| 138 | 138 | return true; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - if ( is_wp_error( $response ) ) { |
|
| 142 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
| 141 | + if (is_wp_error($response)) { |
|
| 142 | + wpinv_error_log($response->get_error_message(), 'Received invalid response from PayPal IPN'); |
|
| 143 | 143 | return false; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
| 146 | + wpinv_error_log($response['body'], 'Received invalid response from PayPal IPN'); |
|
| 147 | 147 | return false; |
| 148 | 148 | |
| 149 | 149 | } |
@@ -154,17 +154,17 @@ discard block |
||
| 154 | 154 | * @param WPInv_Invoice $invoice Invoice object. |
| 155 | 155 | * @param string $currency currency to validate. |
| 156 | 156 | */ |
| 157 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
| 157 | + protected function validate_ipn_currency($invoice, $currency) { |
|
| 158 | 158 | |
| 159 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
| 159 | + if (strtolower($invoice->get_currency()) !== strtolower($currency)) { |
|
| 160 | 160 | |
| 161 | 161 | /* translators: %s: currency code. */ |
| 162 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
| 162 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal currencies do not match (code %s).', 'invoicing'), $currency)); |
|
| 163 | 163 | |
| 164 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 164 | + wpinv_error_log("Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - wpinv_error_log( $currency, 'Validated IPN Currency' ); |
|
| 167 | + wpinv_error_log($currency, 'Validated IPN Currency'); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -173,16 +173,16 @@ discard block |
||
| 173 | 173 | * @param WPInv_Invoice $invoice Invoice object. |
| 174 | 174 | * @param float $amount amount to validate. |
| 175 | 175 | */ |
| 176 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
| 177 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
| 176 | + protected function validate_ipn_amount($invoice, $amount) { |
|
| 177 | + if (number_format($invoice->get_total(), 2, '.', '') !== number_format($amount, 2, '.', '')) { |
|
| 178 | 178 | |
| 179 | 179 | /* translators: %s: Amount. */ |
| 180 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
| 180 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal amounts do not match (gross %s).', 'invoicing'), $amount)); |
|
| 181 | 181 | |
| 182 | - wpinv_error_log( "Currencies do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 182 | + wpinv_error_log("Currencies do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - wpinv_error_log( $amount, 'Validated IPN Amount' ); |
|
| 185 | + wpinv_error_log($amount, 'Validated IPN Amount'); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -191,19 +191,19 @@ discard block |
||
| 191 | 191 | * @param WPInv_Invoice $invoice Invoice object. |
| 192 | 192 | * @param string $receiver_email Email to validate. |
| 193 | 193 | */ |
| 194 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
| 195 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
| 194 | + protected function validate_ipn_receiver_email($invoice, $receiver_email) { |
|
| 195 | + $paypal_email = wpinv_get_option('paypal_email'); |
|
| 196 | 196 | |
| 197 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
| 198 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
| 197 | + if (strcasecmp(trim($receiver_email), trim($paypal_email)) !== 0) { |
|
| 198 | + wpinv_record_gateway_error('IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}"); |
|
| 199 | 199 | |
| 200 | 200 | /* translators: %s: email address . */ |
| 201 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
| 201 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal IPN response from a different email address (%s).', 'invoicing'), $receiver_email)); |
|
| 202 | 202 | |
| 203 | - wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 203 | + wpinv_error_log("IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - wpinv_error_log( 'Validated PayPal Email' ); |
|
| 206 | + wpinv_error_log('Validated PayPal Email'); |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | /** |
@@ -212,68 +212,68 @@ discard block |
||
| 212 | 212 | * @param WPInv_Invoice $invoice Invoice object. |
| 213 | 213 | * @param array $posted Posted data. |
| 214 | 214 | */ |
| 215 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
| 215 | + protected function ipn_txn_web_accept($invoice, $posted) { |
|
| 216 | 216 | |
| 217 | 217 | // Collect payment details |
| 218 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
| 219 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 218 | + $payment_status = strtolower($posted['payment_status']); |
|
| 219 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
| 220 | 220 | |
| 221 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 222 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 221 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
| 222 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
| 223 | 223 | |
| 224 | 224 | // Update the transaction id. |
| 225 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
| 226 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
| 225 | + if (!empty($posted['txn_id'])) { |
|
| 226 | + $invoice->set_transaction_id(wpinv_clean($posted['txn_id'])); |
|
| 227 | 227 | $invoice->save(); |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | // Process a refund. |
| 231 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
| 231 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
| 232 | 232 | |
| 233 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
| 233 | + update_post_meta($invoice->get_id(), 'refunded_remotely', 1); |
|
| 234 | 234 | |
| 235 | - if ( ! $invoice->is_refunded() ) { |
|
| 236 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
| 235 | + if (!$invoice->is_refunded()) { |
|
| 236 | + $invoice->update_status('wpi-refunded', $posted['reason_code']); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - return wpinv_error_log( $posted['reason_code'] ); |
|
| 239 | + return wpinv_error_log($posted['reason_code']); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | // Process payments. |
| 243 | - if ( $payment_status == 'completed' ) { |
|
| 243 | + if ($payment_status == 'completed') { |
|
| 244 | 244 | |
| 245 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
| 246 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.' ); |
|
| 245 | + if ($invoice->is_paid() && 'wpi_processing' != $invoice->get_status()) { |
|
| 246 | + return wpinv_error_log('Aborting, Invoice #' . $invoice->get_number() . ' is already paid.'); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
| 249 | + $this->validate_ipn_amount($invoice, $posted['mc_gross']); |
|
| 250 | 250 | |
| 251 | 251 | $note = ''; |
| 252 | 252 | |
| 253 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
| 254 | - $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
| 253 | + if (!empty($posted['mc_fee'])) { |
|
| 254 | + $note = sprintf(__('PayPal Transaction Fee %.', 'invoicing'), sanitize_text_field($posted['mc_fee'])); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
| 258 | - $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
| 257 | + if (!empty($posted['payer_status'])) { |
|
| 258 | + $note = ' ' . sprintf(__('Buyer status %.', 'invoicing'), sanitize_text_field($posted['payer_status'])); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
| 262 | - return wpinv_error_log( 'Invoice marked as paid.' ); |
|
| 261 | + $invoice->mark_paid((!empty($posted['txn_id']) ? sanitize_text_field($posted['txn_id']) : ''), trim($note)); |
|
| 262 | + return wpinv_error_log('Invoice marked as paid.'); |
|
| 263 | 263 | |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | // Pending payments. |
| 267 | - if ( $payment_status == 'pending' ) { |
|
| 267 | + if ($payment_status == 'pending') { |
|
| 268 | 268 | |
| 269 | 269 | /* translators: %s: pending reason. */ |
| 270 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
| 270 | + $invoice->update_status('wpi-onhold', sprintf(__('Payment pending (%s).', 'invoicing'), $posted['pending_reason'])); |
|
| 271 | 271 | |
| 272 | - return wpinv_error_log( 'Invoice marked as "payment held".' ); |
|
| 272 | + return wpinv_error_log('Invoice marked as "payment held".'); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | /* translators: %s: payment status. */ |
| 276 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
| 276 | + $invoice->update_status('wpi-failed', sprintf(__('Payment %s via IPN.', 'invoicing'), sanitize_text_field($posted['payment_status']))); |
|
| 277 | 277 | |
| 278 | 278 | } |
| 279 | 279 | |
@@ -283,8 +283,8 @@ discard block |
||
| 283 | 283 | * @param WPInv_Invoice $invoice Invoice object. |
| 284 | 284 | * @param array $posted Posted data. |
| 285 | 285 | */ |
| 286 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
| 287 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
| 286 | + protected function ipn_txn_cart($invoice, $posted) { |
|
| 287 | + $this->ipn_txn_web_accept($invoice, $posted); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -293,41 +293,41 @@ discard block |
||
| 293 | 293 | * @param WPInv_Invoice $invoice Invoice object. |
| 294 | 294 | * @param array $posted Posted data. |
| 295 | 295 | */ |
| 296 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
| 296 | + protected function ipn_txn_subscr_signup($invoice, $posted) { |
|
| 297 | 297 | |
| 298 | - wpinv_error_log( $posted, 'Processing subscription signup' ); |
|
| 298 | + wpinv_error_log($posted, 'Processing subscription signup'); |
|
| 299 | 299 | |
| 300 | 300 | // Make sure the invoice has a subscription. |
| 301 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 301 | + $subscription = getpaid_get_invoice_subscription($invoice); |
|
| 302 | 302 | |
| 303 | - if ( empty( $subscription ) ) { |
|
| 304 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 303 | + if (empty($subscription)) { |
|
| 304 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found'); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | // Validate the IPN. |
| 308 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 309 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 310 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 311 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
| 308 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
| 309 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
| 310 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
| 311 | + $this->validate_ipn_amount($invoice, $posted['mc_gross']); |
|
| 312 | 312 | |
| 313 | 313 | // Activate the subscription. |
| 314 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
| 315 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 316 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
| 317 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
| 314 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
| 315 | + $subscription->set_date_created(current_time('mysql')); |
|
| 316 | + $subscription->set_expiration(date('Y-m-d H:i:s', (current_time('timestamp') + $duration))); |
|
| 317 | + $subscription->set_profile_id(sanitize_text_field($posted['subscr_id'])); |
|
| 318 | 318 | $subscription->activate(); |
| 319 | 319 | |
| 320 | 320 | // Set the transaction id. |
| 321 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
| 322 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
| 321 | + if (!empty($posted['txn_id'])) { |
|
| 322 | + $invoice->set_transaction_id($posted['txn_id']); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | // Update the payment status. |
| 326 | 326 | $invoice->mark_paid(); |
| 327 | 327 | |
| 328 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
| 328 | + $invoice->add_note(sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
| 329 | 329 | |
| 330 | - wpinv_error_log( 'Subscription started.' ); |
|
| 330 | + wpinv_error_log('Subscription started.'); |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | /** |
@@ -336,27 +336,27 @@ discard block |
||
| 336 | 336 | * @param WPInv_Invoice $invoice Invoice object. |
| 337 | 337 | * @param array $posted Posted data. |
| 338 | 338 | */ |
| 339 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
| 339 | + protected function ipn_txn_subscr_payment($invoice, $posted) { |
|
| 340 | 340 | |
| 341 | 341 | // Make sure the invoice has a subscription. |
| 342 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 342 | + $subscription = wpinv_get_subscription($invoice); |
|
| 343 | 343 | |
| 344 | - if ( empty( $subscription ) ) { |
|
| 345 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 344 | + if (empty($subscription)) { |
|
| 345 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found'); |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | // Abort if this is the first payment. |
| 349 | - if ( date( 'Ynd', $subscription->get_date_created() ) == date( 'Ynd', strtotime( $posted['payment_date'] ) ) ) { |
|
| 350 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
| 349 | + if (date('Ynd', $subscription->get_date_created()) == date('Ynd', strtotime($posted['payment_date']))) { |
|
| 350 | + $invoice->set_transaction_id(sanitize_text_field($posted['txn_id'])); |
|
| 351 | 351 | $invoice->save(); |
| 352 | 352 | return; |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id() ); |
|
| 355 | + wpinv_error_log('Processing subscription renewal payment for the invoice ' . $invoice->get_id()); |
|
| 356 | 356 | |
| 357 | 357 | // Abort if the payment is already recorded. |
| 358 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
| 359 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed' ); |
|
| 358 | + if (wpinv_get_id_by_transaction_id($posted['txn_id'])) { |
|
| 359 | + return wpinv_error_log('Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed'); |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | $args = array( |
@@ -364,17 +364,17 @@ discard block |
||
| 364 | 364 | 'gateway' => $this->id, |
| 365 | 365 | ); |
| 366 | 366 | |
| 367 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
| 367 | + $invoice = wpinv_get_invoice($subscription->add_payment($args)); |
|
| 368 | 368 | |
| 369 | - if ( empty( $invoice ) ) { |
|
| 369 | + if (empty($invoice)) { |
|
| 370 | 370 | return; |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
| 374 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
| 373 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
| 374 | + $invoice->add_note(wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
| 375 | 375 | |
| 376 | 376 | $subscription->renew(); |
| 377 | - wpinv_error_log( 'Subscription renewed.' ); |
|
| 377 | + wpinv_error_log('Subscription renewed.'); |
|
| 378 | 378 | |
| 379 | 379 | } |
| 380 | 380 | |
@@ -383,18 +383,18 @@ discard block |
||
| 383 | 383 | * |
| 384 | 384 | * @param WPInv_Invoice $invoice Invoice object. |
| 385 | 385 | */ |
| 386 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
| 386 | + protected function ipn_txn_subscr_cancel($invoice) { |
|
| 387 | 387 | |
| 388 | 388 | // Make sure the invoice has a subscription. |
| 389 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 389 | + $subscription = wpinv_get_subscription($invoice); |
|
| 390 | 390 | |
| 391 | - if ( empty( $subscription ) ) { |
|
| 392 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 391 | + if (empty($subscription)) { |
|
| 392 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found'); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id() ); |
|
| 395 | + wpinv_error_log('Processing subscription cancellation for the invoice ' . $invoice->get_id()); |
|
| 396 | 396 | $subscription->cancel(); |
| 397 | - wpinv_error_log( 'Subscription cancelled.' ); |
|
| 397 | + wpinv_error_log('Subscription cancelled.'); |
|
| 398 | 398 | |
| 399 | 399 | } |
| 400 | 400 | |
@@ -404,18 +404,18 @@ discard block |
||
| 404 | 404 | * @param WPInv_Invoice $invoice Invoice object. |
| 405 | 405 | * @param array $posted Posted data. |
| 406 | 406 | */ |
| 407 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
| 407 | + protected function ipn_txn_subscr_eot($invoice) { |
|
| 408 | 408 | |
| 409 | 409 | // Make sure the invoice has a subscription. |
| 410 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 410 | + $subscription = wpinv_get_subscription($invoice); |
|
| 411 | 411 | |
| 412 | - if ( empty( $subscription ) ) { |
|
| 413 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 412 | + if (empty($subscription)) { |
|
| 413 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found'); |
|
| 414 | 414 | } |
| 415 | 415 | |
| 416 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id() ); |
|
| 416 | + wpinv_error_log('Processing subscription end of life for the invoice ' . $invoice->get_id()); |
|
| 417 | 417 | $subscription->complete(); |
| 418 | - wpinv_error_log( 'Subscription completed.' ); |
|
| 418 | + wpinv_error_log('Subscription completed.'); |
|
| 419 | 419 | |
| 420 | 420 | } |
| 421 | 421 | |
@@ -425,18 +425,18 @@ discard block |
||
| 425 | 425 | * @param WPInv_Invoice $invoice Invoice object. |
| 426 | 426 | * @param array $posted Posted data. |
| 427 | 427 | */ |
| 428 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
| 428 | + protected function ipn_txn_subscr_failed($invoice) { |
|
| 429 | 429 | |
| 430 | 430 | // Make sure the invoice has a subscription. |
| 431 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 431 | + $subscription = wpinv_get_subscription($invoice); |
|
| 432 | 432 | |
| 433 | - if ( empty( $subscription ) ) { |
|
| 434 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 433 | + if (empty($subscription)) { |
|
| 434 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found'); |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id() ); |
|
| 437 | + wpinv_error_log('Processing subscription payment failure for the invoice ' . $invoice->get_id()); |
|
| 438 | 438 | $subscription->failing(); |
| 439 | - wpinv_error_log( 'Subscription marked as failing.' ); |
|
| 439 | + wpinv_error_log('Subscription marked as failing.'); |
|
| 440 | 440 | |
| 441 | 441 | } |
| 442 | 442 | |
@@ -13,72 +13,72 @@ discard block |
||
| 13 | 13 | class GetPaid_Paypal_Gateway extends GetPaid_Payment_Gateway { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Payment method id. |
|
| 17 | - * |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 16 | + * Payment method id. |
|
| 17 | + * |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | 20 | public $id = 'paypal'; |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * An array of features that this gateway supports. |
|
| 24 | - * |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 23 | + * An array of features that this gateway supports. |
|
| 24 | + * |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | 27 | protected $supports = array( 'subscription', 'sandbox' ); |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Payment method order. |
|
| 31 | - * |
|
| 32 | - * @var int |
|
| 33 | - */ |
|
| 30 | + * Payment method order. |
|
| 31 | + * |
|
| 32 | + * @var int |
|
| 33 | + */ |
|
| 34 | 34 | public $order = 1; |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | - * Stores line items to send to PayPal. |
|
| 38 | - * |
|
| 39 | - * @var array |
|
| 40 | - */ |
|
| 37 | + * Stores line items to send to PayPal. |
|
| 38 | + * |
|
| 39 | + * @var array |
|
| 40 | + */ |
|
| 41 | 41 | protected $line_items = array(); |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | - * Endpoint for requests from PayPal. |
|
| 45 | - * |
|
| 46 | - * @var string |
|
| 47 | - */ |
|
| 48 | - protected $notify_url; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Endpoint for requests to PayPal. |
|
| 52 | - * |
|
| 53 | - * @var string |
|
| 54 | - */ |
|
| 44 | + * Endpoint for requests from PayPal. |
|
| 45 | + * |
|
| 46 | + * @var string |
|
| 47 | + */ |
|
| 48 | + protected $notify_url; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Endpoint for requests to PayPal. |
|
| 52 | + * |
|
| 53 | + * @var string |
|
| 54 | + */ |
|
| 55 | 55 | protected $endpoint; |
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | - * Currencies this gateway is allowed for. |
|
| 59 | - * |
|
| 60 | - * @var array |
|
| 61 | - */ |
|
| 62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
| 58 | + * Currencies this gateway is allowed for. |
|
| 59 | + * |
|
| 60 | + * @var array |
|
| 61 | + */ |
|
| 62 | + public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | - * URL to view a transaction. |
|
| 66 | - * |
|
| 67 | - * @var string |
|
| 68 | - */ |
|
| 65 | + * URL to view a transaction. |
|
| 66 | + * |
|
| 67 | + * @var string |
|
| 68 | + */ |
|
| 69 | 69 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | - * URL to view a subscription. |
|
| 73 | - * |
|
| 74 | - * @var string |
|
| 75 | - */ |
|
| 76 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
| 72 | + * URL to view a subscription. |
|
| 73 | + * |
|
| 74 | + * @var string |
|
| 75 | + */ |
|
| 76 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | - * Class constructor. |
|
| 80 | - */ |
|
| 81 | - public function __construct() { |
|
| 79 | + * Class constructor. |
|
| 80 | + */ |
|
| 81 | + public function __construct() { |
|
| 82 | 82 | |
| 83 | 83 | $this->title = __( 'PayPal Standard', 'invoicing' ); |
| 84 | 84 | $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
@@ -92,15 +92,15 @@ discard block |
||
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
| 95 | - * Process Payment. |
|
| 96 | - * |
|
| 97 | - * |
|
| 98 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 99 | - * @param array $submission_data Posted checkout fields. |
|
| 100 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 101 | - * @return array |
|
| 102 | - */ |
|
| 103 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 95 | + * Process Payment. |
|
| 96 | + * |
|
| 97 | + * |
|
| 98 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 99 | + * @param array $submission_data Posted checkout fields. |
|
| 100 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 101 | + * @return array |
|
| 102 | + */ |
|
| 103 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 104 | 104 | |
| 105 | 105 | // Get redirect url. |
| 106 | 106 | $paypal_redirect = $this->get_request_url( $invoice ); |
@@ -123,15 +123,15 @@ discard block |
||
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
| 126 | - * Get the PayPal request URL for an invoice. |
|
| 127 | - * |
|
| 128 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 129 | - * @return string |
|
| 130 | - */ |
|
| 131 | - public function get_request_url( $invoice ) { |
|
| 126 | + * Get the PayPal request URL for an invoice. |
|
| 127 | + * |
|
| 128 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 129 | + * @return string |
|
| 130 | + */ |
|
| 131 | + public function get_request_url( $invoice ) { |
|
| 132 | 132 | |
| 133 | 133 | // Endpoint for this request |
| 134 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
| 134 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
| 135 | 135 | |
| 136 | 136 | // Retrieve paypal args. |
| 137 | 137 | $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
@@ -144,44 +144,44 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | return add_query_arg( $paypal_args, $this->endpoint ); |
| 146 | 146 | |
| 147 | - } |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | 149 | /** |
| 150 | - * Get PayPal Args for passing to PP. |
|
| 151 | - * |
|
| 152 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 153 | - * @return array |
|
| 154 | - */ |
|
| 155 | - protected function get_paypal_args( $invoice ) { |
|
| 150 | + * Get PayPal Args for passing to PP. |
|
| 151 | + * |
|
| 152 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 153 | + * @return array |
|
| 154 | + */ |
|
| 155 | + protected function get_paypal_args( $invoice ) { |
|
| 156 | 156 | |
| 157 | 157 | // Whether or not to send the line items as one item. |
| 158 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice ); |
|
| 159 | - |
|
| 160 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
| 161 | - $force_one_line_item = true; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - $paypal_args = apply_filters( |
|
| 165 | - 'getpaid_paypal_args', |
|
| 166 | - array_merge( |
|
| 167 | - $this->get_transaction_args( $invoice ), |
|
| 168 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
| 169 | - ), |
|
| 170 | - $invoice |
|
| 171 | - ); |
|
| 172 | - |
|
| 173 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
| 158 | + $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice ); |
|
| 159 | + |
|
| 160 | + if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
| 161 | + $force_one_line_item = true; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + $paypal_args = apply_filters( |
|
| 165 | + 'getpaid_paypal_args', |
|
| 166 | + array_merge( |
|
| 167 | + $this->get_transaction_args( $invoice ), |
|
| 168 | + $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
| 169 | + ), |
|
| 170 | + $invoice |
|
| 171 | + ); |
|
| 172 | + |
|
| 173 | + return $this->fix_request_length( $invoice, $paypal_args ); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
| 177 | - * Get transaction args for paypal request. |
|
| 178 | - * |
|
| 179 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 180 | - * @return array |
|
| 181 | - */ |
|
| 182 | - protected function get_transaction_args( $invoice ) { |
|
| 183 | - |
|
| 184 | - return array( |
|
| 177 | + * Get transaction args for paypal request. |
|
| 178 | + * |
|
| 179 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 180 | + * @return array |
|
| 181 | + */ |
|
| 182 | + protected function get_transaction_args( $invoice ) { |
|
| 183 | + |
|
| 184 | + return array( |
|
| 185 | 185 | 'cmd' => '_cart', |
| 186 | 186 | 'business' => wpinv_get_option( 'paypal_email', false ), |
| 187 | 187 | 'no_shipping' => '1', |
@@ -206,16 +206,16 @@ discard block |
||
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /** |
| 209 | - * Get line item args for paypal request. |
|
| 210 | - * |
|
| 211 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 212 | - * @param bool $force_one_line_item Create only one item for this invoice. |
|
| 213 | - * @return array |
|
| 214 | - */ |
|
| 215 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
| 209 | + * Get line item args for paypal request. |
|
| 210 | + * |
|
| 211 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 212 | + * @param bool $force_one_line_item Create only one item for this invoice. |
|
| 213 | + * @return array |
|
| 214 | + */ |
|
| 215 | + protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
| 216 | 216 | |
| 217 | 217 | // Maybe send invoice as a single item. |
| 218 | - if ( $force_one_line_item ) { |
|
| 218 | + if ( $force_one_line_item ) { |
|
| 219 | 219 | return $this->get_line_item_args_single_item( $invoice ); |
| 220 | 220 | } |
| 221 | 221 | |
@@ -235,129 +235,129 @@ discard block |
||
| 235 | 235 | $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
| 238 | + return array_merge( $line_item_args, $this->get_line_items() ); |
|
| 239 | 239 | |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
| 243 | - * Get line item args for paypal request as a single line item. |
|
| 244 | - * |
|
| 245 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 246 | - * @return array |
|
| 247 | - */ |
|
| 248 | - protected function get_line_item_args_single_item( $invoice ) { |
|
| 249 | - $this->delete_line_items(); |
|
| 243 | + * Get line item args for paypal request as a single line item. |
|
| 244 | + * |
|
| 245 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 246 | + * @return array |
|
| 247 | + */ |
|
| 248 | + protected function get_line_item_args_single_item( $invoice ) { |
|
| 249 | + $this->delete_line_items(); |
|
| 250 | 250 | |
| 251 | 251 | $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
| 252 | - $this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() ); |
|
| 252 | + $this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() ); |
|
| 253 | 253 | |
| 254 | - return $this->get_line_items(); |
|
| 254 | + return $this->get_line_items(); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | /** |
| 258 | - * Return all line items. |
|
| 259 | - */ |
|
| 260 | - protected function get_line_items() { |
|
| 261 | - return $this->line_items; |
|
| 262 | - } |
|
| 258 | + * Return all line items. |
|
| 259 | + */ |
|
| 260 | + protected function get_line_items() { |
|
| 261 | + return $this->line_items; |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | 264 | /** |
| 265 | - * Remove all line items. |
|
| 266 | - */ |
|
| 267 | - protected function delete_line_items() { |
|
| 268 | - $this->line_items = array(); |
|
| 265 | + * Remove all line items. |
|
| 266 | + */ |
|
| 267 | + protected function delete_line_items() { |
|
| 268 | + $this->line_items = array(); |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | /** |
| 272 | - * Prepare line items to send to paypal. |
|
| 273 | - * |
|
| 274 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 275 | - */ |
|
| 276 | - protected function prepare_line_items( $invoice ) { |
|
| 277 | - $this->delete_line_items(); |
|
| 278 | - |
|
| 279 | - // Items. |
|
| 280 | - foreach ( $invoice->get_items() as $item ) { |
|
| 281 | - $amount = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total(); |
|
| 282 | - $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
| 283 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
| 272 | + * Prepare line items to send to paypal. |
|
| 273 | + * |
|
| 274 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 275 | + */ |
|
| 276 | + protected function prepare_line_items( $invoice ) { |
|
| 277 | + $this->delete_line_items(); |
|
| 278 | + |
|
| 279 | + // Items. |
|
| 280 | + foreach ( $invoice->get_items() as $item ) { |
|
| 281 | + $amount = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total(); |
|
| 282 | + $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
| 283 | + $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | // Fees. |
| 287 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
| 287 | + foreach ( $invoice->get_fees() as $fee => $data ) { |
|
| 288 | 288 | $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | /** |
| 294 | - * Add PayPal Line Item. |
|
| 295 | - * |
|
| 296 | - * @param string $item_name Item name. |
|
| 297 | - * @param int $quantity Item quantity. |
|
| 298 | - * @param float $amount Amount. |
|
| 299 | - * @param string $item_number Item number. |
|
| 300 | - */ |
|
| 301 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
| 302 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
| 303 | - |
|
| 304 | - $item = apply_filters( |
|
| 305 | - 'getpaid_paypal_line_item', |
|
| 306 | - array( |
|
| 307 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
| 308 | - 'quantity' => (int) $quantity, |
|
| 309 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
| 310 | - 'item_number' => $item_number, |
|
| 311 | - ), |
|
| 312 | - $item_name, |
|
| 313 | - $quantity, |
|
| 314 | - $amount, |
|
| 315 | - $item_number |
|
| 316 | - ); |
|
| 317 | - |
|
| 318 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
| 294 | + * Add PayPal Line Item. |
|
| 295 | + * |
|
| 296 | + * @param string $item_name Item name. |
|
| 297 | + * @param int $quantity Item quantity. |
|
| 298 | + * @param float $amount Amount. |
|
| 299 | + * @param string $item_number Item number. |
|
| 300 | + */ |
|
| 301 | + protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
| 302 | + $index = ( count( $this->line_items ) / 4 ) + 1; |
|
| 303 | + |
|
| 304 | + $item = apply_filters( |
|
| 305 | + 'getpaid_paypal_line_item', |
|
| 306 | + array( |
|
| 307 | + 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
| 308 | + 'quantity' => (int) $quantity, |
|
| 309 | + 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
| 310 | + 'item_number' => $item_number, |
|
| 311 | + ), |
|
| 312 | + $item_name, |
|
| 313 | + $quantity, |
|
| 314 | + $amount, |
|
| 315 | + $item_number |
|
| 316 | + ); |
|
| 317 | + |
|
| 318 | + $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
| 319 | 319 | $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
| 320 | 320 | |
| 321 | 321 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
| 322 | - $this->line_items[ 'amount_' . $index ] = $item['amount']; |
|
| 323 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
| 322 | + $this->line_items[ 'amount_' . $index ] = $item['amount']; |
|
| 323 | + $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | /** |
| 327 | - * If the default request with line items is too long, generate a new one with only one line item. |
|
| 328 | - * |
|
| 329 | - * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
| 330 | - * |
|
| 331 | - * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
| 332 | - * @param array $paypal_args Arguments sent to Paypal in the request. |
|
| 333 | - * @return array |
|
| 334 | - */ |
|
| 335 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
| 336 | - $max_paypal_length = 2083; |
|
| 337 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
| 338 | - |
|
| 339 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
| 340 | - return $paypal_args; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - return apply_filters( |
|
| 344 | - 'getpaid_paypal_args', |
|
| 345 | - array_merge( |
|
| 346 | - $this->get_transaction_args( $invoice ), |
|
| 347 | - $this->get_line_item_args( $invoice, true ) |
|
| 348 | - ), |
|
| 349 | - $invoice |
|
| 350 | - ); |
|
| 327 | + * If the default request with line items is too long, generate a new one with only one line item. |
|
| 328 | + * |
|
| 329 | + * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
| 330 | + * |
|
| 331 | + * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
| 332 | + * @param array $paypal_args Arguments sent to Paypal in the request. |
|
| 333 | + * @return array |
|
| 334 | + */ |
|
| 335 | + protected function fix_request_length( $invoice, $paypal_args ) { |
|
| 336 | + $max_paypal_length = 2083; |
|
| 337 | + $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
| 338 | + |
|
| 339 | + if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
| 340 | + return $paypal_args; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + return apply_filters( |
|
| 344 | + 'getpaid_paypal_args', |
|
| 345 | + array_merge( |
|
| 346 | + $this->get_transaction_args( $invoice ), |
|
| 347 | + $this->get_line_item_args( $invoice, true ) |
|
| 348 | + ), |
|
| 349 | + $invoice |
|
| 350 | + ); |
|
| 351 | 351 | |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | /** |
| 355 | - * Processes recurring invoices. |
|
| 356 | - * |
|
| 357 | - * @param array $paypal_args PayPal args. |
|
| 358 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 359 | - */ |
|
| 360 | - public function process_subscription( $paypal_args, $invoice ) { |
|
| 355 | + * Processes recurring invoices. |
|
| 356 | + * |
|
| 357 | + * @param array $paypal_args PayPal args. |
|
| 358 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 359 | + */ |
|
| 360 | + public function process_subscription( $paypal_args, $invoice ) { |
|
| 361 | 361 | |
| 362 | 362 | // Make sure this is a subscription. |
| 363 | 363 | if ( ! $invoice->is_recurring() || ! $subscription = wpinv_get_subscription( $invoice ) ) { |
@@ -382,11 +382,11 @@ discard block |
||
| 382 | 382 | |
| 383 | 383 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
| 384 | 384 | |
| 385 | - // Trial period length. |
|
| 386 | - $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
| 385 | + // Trial period length. |
|
| 386 | + $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
| 387 | 387 | |
| 388 | - // Trial period. |
|
| 389 | - $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
| 388 | + // Trial period. |
|
| 389 | + $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
| 390 | 390 | |
| 391 | 391 | } else if ( $initial_amount != $recurring_amount ) { |
| 392 | 392 | |
@@ -409,40 +409,40 @@ discard block |
||
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | // We have a recurring payment |
| 412 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
| 412 | + if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
| 413 | 413 | |
| 414 | - // Subscription price |
|
| 415 | - $paypal_args['a3'] = $recurring_amount; |
|
| 414 | + // Subscription price |
|
| 415 | + $paypal_args['a3'] = $recurring_amount; |
|
| 416 | 416 | |
| 417 | - // Subscription duration |
|
| 418 | - $paypal_args['p3'] = $interval; |
|
| 417 | + // Subscription duration |
|
| 418 | + $paypal_args['p3'] = $interval; |
|
| 419 | 419 | |
| 420 | - // Subscription period |
|
| 421 | - $paypal_args['t3'] = $period; |
|
| 420 | + // Subscription period |
|
| 421 | + $paypal_args['t3'] = $period; |
|
| 422 | 422 | |
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | // Recurring payments |
| 426 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
| 426 | + if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
| 427 | 427 | |
| 428 | - // Non-recurring payments |
|
| 429 | - $paypal_args['src'] = 0; |
|
| 428 | + // Non-recurring payments |
|
| 429 | + $paypal_args['src'] = 0; |
|
| 430 | 430 | |
| 431 | - } else { |
|
| 431 | + } else { |
|
| 432 | 432 | |
| 433 | - $paypal_args['src'] = 1; |
|
| 433 | + $paypal_args['src'] = 1; |
|
| 434 | 434 | |
| 435 | - if ( $bill_times > 0 ) { |
|
| 435 | + if ( $bill_times > 0 ) { |
|
| 436 | 436 | |
| 437 | - // An initial period is being used to charge a sign-up fee |
|
| 438 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
| 439 | - $bill_times--; |
|
| 440 | - } |
|
| 437 | + // An initial period is being used to charge a sign-up fee |
|
| 438 | + if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
| 439 | + $bill_times--; |
|
| 440 | + } |
|
| 441 | 441 | |
| 442 | 442 | // Make sure it's not over the max of 52 |
| 443 | 443 | $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
| 444 | 444 | |
| 445 | - } |
|
| 445 | + } |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | // Force return URL so that order description & instructions display |
@@ -458,19 +458,19 @@ discard block |
||
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | return apply_filters( |
| 461 | - 'getpaid_paypal_subscription_args', |
|
| 462 | - $paypal_args, |
|
| 463 | - $invoice |
|
| 461 | + 'getpaid_paypal_subscription_args', |
|
| 462 | + $paypal_args, |
|
| 463 | + $invoice |
|
| 464 | 464 | ); |
| 465 | 465 | |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | /** |
| 469 | - * Processes ipns and marks payments as complete. |
|
| 470 | - * |
|
| 471 | - * @return void |
|
| 472 | - */ |
|
| 473 | - public function verify_ipn() { |
|
| 469 | + * Processes ipns and marks payments as complete. |
|
| 470 | + * |
|
| 471 | + * @return void |
|
| 472 | + */ |
|
| 473 | + public function verify_ipn() { |
|
| 474 | 474 | new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
| 475 | 475 | } |
| 476 | 476 | |
@@ -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 | * Paypal Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @var array |
| 26 | 26 | */ |
| 27 | - protected $supports = array( 'subscription', 'sandbox' ); |
|
| 27 | + protected $supports = array('subscription', 'sandbox'); |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * Payment method order. |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * |
| 60 | 60 | * @var array |
| 61 | 61 | */ |
| 62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
| 62 | + public $currencies = array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR'); |
|
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | 65 | * URL to view a transaction. |
@@ -80,13 +80,13 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | public function __construct() { |
| 82 | 82 | |
| 83 | - $this->title = __( 'PayPal Standard', 'invoicing' ); |
|
| 84 | - $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
|
| 85 | - $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
|
| 86 | - $this->notify_url = wpinv_get_ipn_url( $this->id ); |
|
| 83 | + $this->title = __('PayPal Standard', 'invoicing'); |
|
| 84 | + $this->method_title = __('PayPal Standard', 'invoicing'); |
|
| 85 | + $this->checkout_button_text = __('Proceed to PayPal', 'invoicing'); |
|
| 86 | + $this->notify_url = wpinv_get_ipn_url($this->id); |
|
| 87 | 87 | |
| 88 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
| 89 | - add_filter( 'wpinv_gateway_description', array( $this, 'sandbox_notice' ), 10, 2 ); |
|
| 88 | + add_filter('getpaid_paypal_args', array($this, 'process_subscription'), 10, 2); |
|
| 89 | + add_filter('wpinv_gateway_description', array($this, 'sandbox_notice'), 10, 2); |
|
| 90 | 90 | |
| 91 | 91 | parent::__construct(); |
| 92 | 92 | } |
@@ -100,16 +100,16 @@ discard block |
||
| 100 | 100 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
| 101 | 101 | * @return array |
| 102 | 102 | */ |
| 103 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 103 | + public function process_payment($invoice, $submission_data, $submission) { |
|
| 104 | 104 | |
| 105 | 105 | // Get redirect url. |
| 106 | - $paypal_redirect = $this->get_request_url( $invoice ); |
|
| 106 | + $paypal_redirect = $this->get_request_url($invoice); |
|
| 107 | 107 | |
| 108 | 108 | // Add a note about the request url. |
| 109 | 109 | $invoice->add_note( |
| 110 | 110 | sprintf( |
| 111 | - __( 'Redirecting to PayPal: %s', 'invoicing' ), |
|
| 112 | - esc_url( $paypal_redirect ) |
|
| 111 | + __('Redirecting to PayPal: %s', 'invoicing'), |
|
| 112 | + esc_url($paypal_redirect) |
|
| 113 | 113 | ), |
| 114 | 114 | false, |
| 115 | 115 | false, |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | ); |
| 118 | 118 | |
| 119 | 119 | // Redirect to PayPal |
| 120 | - wp_redirect( $paypal_redirect ); |
|
| 120 | + wp_redirect($paypal_redirect); |
|
| 121 | 121 | exit; |
| 122 | 122 | |
| 123 | 123 | } |
@@ -128,21 +128,21 @@ discard block |
||
| 128 | 128 | * @param WPInv_Invoice $invoice Invoice object. |
| 129 | 129 | * @return string |
| 130 | 130 | */ |
| 131 | - public function get_request_url( $invoice ) { |
|
| 131 | + public function get_request_url($invoice) { |
|
| 132 | 132 | |
| 133 | 133 | // Endpoint for this request |
| 134 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
| 134 | + $this->endpoint = $this->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
| 135 | 135 | |
| 136 | 136 | // Retrieve paypal args. |
| 137 | - $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
|
| 137 | + $paypal_args = map_deep($this->get_paypal_args($invoice), 'urlencode'); |
|
| 138 | 138 | |
| 139 | - if ( $invoice->is_recurring() ) { |
|
| 139 | + if ($invoice->is_recurring()) { |
|
| 140 | 140 | $paypal_args['bn'] = 'GetPaid_Subscribe_WPS_US'; |
| 141 | 141 | } else { |
| 142 | 142 | $paypal_args['bn'] = 'GetPaid_ShoppingCart_WPS_US'; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - return add_query_arg( $paypal_args, $this->endpoint ); |
|
| 145 | + return add_query_arg($paypal_args, $this->endpoint); |
|
| 146 | 146 | |
| 147 | 147 | } |
| 148 | 148 | |
@@ -152,25 +152,25 @@ discard block |
||
| 152 | 152 | * @param WPInv_Invoice $invoice Invoice object. |
| 153 | 153 | * @return array |
| 154 | 154 | */ |
| 155 | - protected function get_paypal_args( $invoice ) { |
|
| 155 | + protected function get_paypal_args($invoice) { |
|
| 156 | 156 | |
| 157 | 157 | // Whether or not to send the line items as one item. |
| 158 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice ); |
|
| 158 | + $force_one_line_item = apply_filters('getpaid_paypal_force_one_line_item', false, $invoice); |
|
| 159 | 159 | |
| 160 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
| 160 | + if ($invoice->is_recurring() || (wpinv_use_taxes() && wpinv_prices_include_tax())) { |
|
| 161 | 161 | $force_one_line_item = true; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | $paypal_args = apply_filters( |
| 165 | 165 | 'getpaid_paypal_args', |
| 166 | 166 | array_merge( |
| 167 | - $this->get_transaction_args( $invoice ), |
|
| 168 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
| 167 | + $this->get_transaction_args($invoice), |
|
| 168 | + $this->get_line_item_args($invoice, $force_one_line_item) |
|
| 169 | 169 | ), |
| 170 | 170 | $invoice |
| 171 | 171 | ); |
| 172 | 172 | |
| 173 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
| 173 | + return $this->fix_request_length($invoice, $paypal_args); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -179,11 +179,11 @@ discard block |
||
| 179 | 179 | * @param WPInv_Invoice $invoice Invoice object. |
| 180 | 180 | * @return array |
| 181 | 181 | */ |
| 182 | - protected function get_transaction_args( $invoice ) { |
|
| 182 | + protected function get_transaction_args($invoice) { |
|
| 183 | 183 | |
| 184 | 184 | return array( |
| 185 | 185 | 'cmd' => '_cart', |
| 186 | - 'business' => wpinv_get_option( 'paypal_email', false ), |
|
| 186 | + 'business' => wpinv_get_option('paypal_email', false), |
|
| 187 | 187 | 'no_shipping' => '1', |
| 188 | 188 | 'shipping' => '0', |
| 189 | 189 | 'no_note' => '1', |
@@ -191,16 +191,16 @@ discard block |
||
| 191 | 191 | 'rm' => is_ssl() ? 2 : 1, |
| 192 | 192 | 'upload' => 1, |
| 193 | 193 | 'currency_code' => $invoice->get_currency(), // https://developer.paypal.com/docs/nvp-soap-api/currency-codes/#paypal |
| 194 | - 'return' => esc_url_raw( $this->get_return_url( $invoice ) ), |
|
| 195 | - 'cancel_return' => esc_url_raw( $invoice->get_checkout_payment_url() ), |
|
| 196 | - 'notify_url' => getpaid_limit_length( $this->notify_url, 255 ), |
|
| 197 | - 'invoice' => getpaid_limit_length( $invoice->get_number(), 127 ), |
|
| 194 | + 'return' => esc_url_raw($this->get_return_url($invoice)), |
|
| 195 | + 'cancel_return' => esc_url_raw($invoice->get_checkout_payment_url()), |
|
| 196 | + 'notify_url' => getpaid_limit_length($this->notify_url, 255), |
|
| 197 | + 'invoice' => getpaid_limit_length($invoice->get_number(), 127), |
|
| 198 | 198 | 'custom' => $invoice->get_id(), |
| 199 | - 'first_name' => getpaid_limit_length( $invoice->get_first_name(), 32 ), |
|
| 200 | - 'last_name' => getpaid_limit_length( $invoice->get_last_name(), 64 ), |
|
| 201 | - 'country' => getpaid_limit_length( $invoice->get_country(), 2 ), |
|
| 202 | - 'email' => getpaid_limit_length( $invoice->get_email(), 127 ), |
|
| 203 | - 'cbt' => get_bloginfo( 'name' ) |
|
| 199 | + 'first_name' => getpaid_limit_length($invoice->get_first_name(), 32), |
|
| 200 | + 'last_name' => getpaid_limit_length($invoice->get_last_name(), 64), |
|
| 201 | + 'country' => getpaid_limit_length($invoice->get_country(), 2), |
|
| 202 | + 'email' => getpaid_limit_length($invoice->get_email(), 127), |
|
| 203 | + 'cbt' => get_bloginfo('name') |
|
| 204 | 204 | ); |
| 205 | 205 | |
| 206 | 206 | } |
@@ -212,30 +212,30 @@ discard block |
||
| 212 | 212 | * @param bool $force_one_line_item Create only one item for this invoice. |
| 213 | 213 | * @return array |
| 214 | 214 | */ |
| 215 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
| 215 | + protected function get_line_item_args($invoice, $force_one_line_item = false) { |
|
| 216 | 216 | |
| 217 | 217 | // Maybe send invoice as a single item. |
| 218 | - if ( $force_one_line_item ) { |
|
| 219 | - return $this->get_line_item_args_single_item( $invoice ); |
|
| 218 | + if ($force_one_line_item) { |
|
| 219 | + return $this->get_line_item_args_single_item($invoice); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | // Send each line item individually. |
| 223 | 223 | $line_item_args = array(); |
| 224 | 224 | |
| 225 | 225 | // Prepare line items. |
| 226 | - $this->prepare_line_items( $invoice ); |
|
| 226 | + $this->prepare_line_items($invoice); |
|
| 227 | 227 | |
| 228 | 228 | // Add taxes to the cart |
| 229 | - if ( wpinv_use_taxes() && $invoice->is_taxable() ) { |
|
| 230 | - $line_item_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_tax(), 2 ); |
|
| 229 | + if (wpinv_use_taxes() && $invoice->is_taxable()) { |
|
| 230 | + $line_item_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_tax(), 2); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | // Add discount. |
| 234 | - if ( $invoice->get_total_discount() > 0 ) { |
|
| 235 | - $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
|
| 234 | + if ($invoice->get_total_discount() > 0) { |
|
| 235 | + $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_discount(), 2); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
| 238 | + return array_merge($line_item_args, $this->get_line_items()); |
|
| 239 | 239 | |
| 240 | 240 | } |
| 241 | 241 | |
@@ -245,11 +245,11 @@ discard block |
||
| 245 | 245 | * @param WPInv_Invoice $invoice Invoice object. |
| 246 | 246 | * @return array |
| 247 | 247 | */ |
| 248 | - protected function get_line_item_args_single_item( $invoice ) { |
|
| 248 | + protected function get_line_item_args_single_item($invoice) { |
|
| 249 | 249 | $this->delete_line_items(); |
| 250 | 250 | |
| 251 | - $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
|
| 252 | - $this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() ); |
|
| 251 | + $item_name = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number()); |
|
| 252 | + $this->add_line_item($item_name, 1, wpinv_sanitize_amount((float) $invoice->get_total(), 2), $invoice->get_id()); |
|
| 253 | 253 | |
| 254 | 254 | return $this->get_line_items(); |
| 255 | 255 | } |
@@ -273,19 +273,19 @@ discard block |
||
| 273 | 273 | * |
| 274 | 274 | * @param WPInv_Invoice $invoice Invoice object. |
| 275 | 275 | */ |
| 276 | - protected function prepare_line_items( $invoice ) { |
|
| 276 | + protected function prepare_line_items($invoice) { |
|
| 277 | 277 | $this->delete_line_items(); |
| 278 | 278 | |
| 279 | 279 | // Items. |
| 280 | - foreach ( $invoice->get_items() as $item ) { |
|
| 280 | + foreach ($invoice->get_items() as $item) { |
|
| 281 | 281 | $amount = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total(); |
| 282 | 282 | $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
| 283 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
| 283 | + $this->add_line_item($item->get_raw_name(), $quantity, $amount, $item->get_id()); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | // Fees. |
| 287 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
| 288 | - $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
|
| 287 | + foreach ($invoice->get_fees() as $fee => $data) { |
|
| 288 | + $this->add_line_item($fee, 1, wpinv_sanitize_amount($data['initial_fee'])); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | } |
@@ -298,15 +298,15 @@ discard block |
||
| 298 | 298 | * @param float $amount Amount. |
| 299 | 299 | * @param string $item_number Item number. |
| 300 | 300 | */ |
| 301 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
| 302 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
| 301 | + protected function add_line_item($item_name, $quantity = 1, $amount = 0.0, $item_number = '') { |
|
| 302 | + $index = (count($this->line_items) / 4) + 1; |
|
| 303 | 303 | |
| 304 | 304 | $item = apply_filters( |
| 305 | 305 | 'getpaid_paypal_line_item', |
| 306 | 306 | array( |
| 307 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
| 307 | + 'item_name' => html_entity_decode(getpaid_limit_length($item_name ? wp_strip_all_tags($item_name) : __('Item', 'invoicing'), 127), ENT_NOQUOTES, 'UTF-8'), |
|
| 308 | 308 | 'quantity' => (int) $quantity, |
| 309 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
| 309 | + 'amount' => wpinv_sanitize_amount((float) $amount, 2), |
|
| 310 | 310 | 'item_number' => $item_number, |
| 311 | 311 | ), |
| 312 | 312 | $item_name, |
@@ -315,12 +315,12 @@ discard block |
||
| 315 | 315 | $item_number |
| 316 | 316 | ); |
| 317 | 317 | |
| 318 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
| 319 | - $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
|
| 318 | + $this->line_items['item_name_' . $index] = getpaid_limit_length($item['item_name'], 127); |
|
| 319 | + $this->line_items['quantity_' . $index] = $item['quantity']; |
|
| 320 | 320 | |
| 321 | 321 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
| 322 | - $this->line_items[ 'amount_' . $index ] = $item['amount']; |
|
| 323 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
| 322 | + $this->line_items['amount_' . $index] = $item['amount']; |
|
| 323 | + $this->line_items['item_number_' . $index] = getpaid_limit_length($item['item_number'], 127); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | /** |
@@ -332,19 +332,19 @@ discard block |
||
| 332 | 332 | * @param array $paypal_args Arguments sent to Paypal in the request. |
| 333 | 333 | * @return array |
| 334 | 334 | */ |
| 335 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
| 335 | + protected function fix_request_length($invoice, $paypal_args) { |
|
| 336 | 336 | $max_paypal_length = 2083; |
| 337 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
| 337 | + $query_candidate = http_build_query($paypal_args, '', '&'); |
|
| 338 | 338 | |
| 339 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
| 339 | + if (strlen($this->endpoint . $query_candidate) <= $max_paypal_length) { |
|
| 340 | 340 | return $paypal_args; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | return apply_filters( |
| 344 | 344 | 'getpaid_paypal_args', |
| 345 | 345 | array_merge( |
| 346 | - $this->get_transaction_args( $invoice ), |
|
| 347 | - $this->get_line_item_args( $invoice, true ) |
|
| 346 | + $this->get_transaction_args($invoice), |
|
| 347 | + $this->get_line_item_args($invoice, true) |
|
| 348 | 348 | ), |
| 349 | 349 | $invoice |
| 350 | 350 | ); |
@@ -357,10 +357,10 @@ discard block |
||
| 357 | 357 | * @param array $paypal_args PayPal args. |
| 358 | 358 | * @param WPInv_Invoice $invoice Invoice object. |
| 359 | 359 | */ |
| 360 | - public function process_subscription( $paypal_args, $invoice ) { |
|
| 360 | + public function process_subscription($paypal_args, $invoice) { |
|
| 361 | 361 | |
| 362 | 362 | // Make sure this is a subscription. |
| 363 | - if ( ! $invoice->is_recurring() || ! $subscription = wpinv_get_subscription( $invoice ) ) { |
|
| 363 | + if (!$invoice->is_recurring() || !$subscription = wpinv_get_subscription($invoice)) { |
|
| 364 | 364 | return $paypal_args; |
| 365 | 365 | } |
| 366 | 366 | |
@@ -368,17 +368,17 @@ discard block |
||
| 368 | 368 | $paypal_args['cmd'] = '_xclick-subscriptions'; |
| 369 | 369 | |
| 370 | 370 | // Subscription name. |
| 371 | - $paypal_args['item_name'] = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
|
| 371 | + $paypal_args['item_name'] = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number()); |
|
| 372 | 372 | |
| 373 | 373 | // Get subscription args. |
| 374 | - $period = strtoupper( substr( $subscription->get_period(), 0, 1) ); |
|
| 374 | + $period = strtoupper(substr($subscription->get_period(), 0, 1)); |
|
| 375 | 375 | $interval = (int) $subscription->get_frequency(); |
| 376 | 376 | $bill_times = (int) $subscription->get_bill_times(); |
| 377 | - $initial_amount = (float) wpinv_sanitize_amount( $invoice->get_initial_total(), 2 ); |
|
| 378 | - $recurring_amount = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 ); |
|
| 379 | - $subscription_item = $invoice->get_recurring( true ); |
|
| 377 | + $initial_amount = (float) wpinv_sanitize_amount($invoice->get_initial_total(), 2); |
|
| 378 | + $recurring_amount = (float) wpinv_sanitize_amount($invoice->get_recurring_total(), 2); |
|
| 379 | + $subscription_item = $invoice->get_recurring(true); |
|
| 380 | 380 | |
| 381 | - if ( $subscription_item->has_free_trial() ) { |
|
| 381 | + if ($subscription_item->has_free_trial()) { |
|
| 382 | 382 | |
| 383 | 383 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
| 384 | 384 | |
@@ -388,28 +388,28 @@ discard block |
||
| 388 | 388 | // Trial period. |
| 389 | 389 | $paypal_args['t1'] = $subscription_item->get_trial_period(); |
| 390 | 390 | |
| 391 | - } else if ( $initial_amount != $recurring_amount ) { |
|
| 391 | + } else if ($initial_amount != $recurring_amount) { |
|
| 392 | 392 | |
| 393 | 393 | // No trial period, but initial amount includes a sign-up fee and/or other items, so charge it as a separate period. |
| 394 | 394 | |
| 395 | - if ( 1 == $bill_times ) { |
|
| 395 | + if (1 == $bill_times) { |
|
| 396 | 396 | $param_number = 3; |
| 397 | 397 | } else { |
| 398 | 398 | $param_number = 1; |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | - $paypal_args[ 'a' . $param_number ] = $initial_amount ? 0 : $initial_amount; |
|
| 401 | + $paypal_args['a' . $param_number] = $initial_amount ? 0 : $initial_amount; |
|
| 402 | 402 | |
| 403 | 403 | // Sign Up interval |
| 404 | - $paypal_args[ 'p' . $param_number ] = $interval; |
|
| 404 | + $paypal_args['p' . $param_number] = $interval; |
|
| 405 | 405 | |
| 406 | 406 | // Sign Up unit of duration |
| 407 | - $paypal_args[ 't' . $param_number ] = $period; |
|
| 407 | + $paypal_args['t' . $param_number] = $period; |
|
| 408 | 408 | |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | // We have a recurring payment |
| 412 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
| 412 | + if (!isset($param_number) || 1 == $param_number) { |
|
| 413 | 413 | |
| 414 | 414 | // Subscription price |
| 415 | 415 | $paypal_args['a3'] = $recurring_amount; |
@@ -423,7 +423,7 @@ discard block |
||
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | // Recurring payments |
| 426 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
| 426 | + if (1 == $bill_times || ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial() && 2 == $bill_times)) { |
|
| 427 | 427 | |
| 428 | 428 | // Non-recurring payments |
| 429 | 429 | $paypal_args['src'] = 0; |
@@ -432,15 +432,15 @@ discard block |
||
| 432 | 432 | |
| 433 | 433 | $paypal_args['src'] = 1; |
| 434 | 434 | |
| 435 | - if ( $bill_times > 0 ) { |
|
| 435 | + if ($bill_times > 0) { |
|
| 436 | 436 | |
| 437 | 437 | // An initial period is being used to charge a sign-up fee |
| 438 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
| 438 | + if ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial()) { |
|
| 439 | 439 | $bill_times--; |
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | // Make sure it's not over the max of 52 |
| 443 | - $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
|
| 443 | + $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52); |
|
| 444 | 444 | |
| 445 | 445 | } |
| 446 | 446 | } |
@@ -449,10 +449,10 @@ discard block |
||
| 449 | 449 | $paypal_args['rm'] = 2; |
| 450 | 450 | |
| 451 | 451 | // Get rid of redudant items. |
| 452 | - foreach ( array( 'item_name_1', 'quantity_1', 'amount_1', 'item_number_1' ) as $arg ) { |
|
| 452 | + foreach (array('item_name_1', 'quantity_1', 'amount_1', 'item_number_1') as $arg) { |
|
| 453 | 453 | |
| 454 | - if ( isset( $paypal_args[ $arg ] ) ) { |
|
| 455 | - unset( $paypal_args[ $arg ] ); |
|
| 454 | + if (isset($paypal_args[$arg])) { |
|
| 455 | + unset($paypal_args[$arg]); |
|
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | } |
@@ -471,16 +471,16 @@ discard block |
||
| 471 | 471 | * @return void |
| 472 | 472 | */ |
| 473 | 473 | public function verify_ipn() { |
| 474 | - new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
|
| 474 | + new GetPaid_Paypal_Gateway_IPN_Handler($this); |
|
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | /** |
| 478 | 478 | * Displays a notice on the checkout page if sandbox is enabled. |
| 479 | 479 | */ |
| 480 | - public function sandbox_notice( $description, $gateway ) { |
|
| 481 | - if ( 'paypal' == $gateway && wpinv_is_test_mode( 'paypal' ) ) { |
|
| 480 | + public function sandbox_notice($description, $gateway) { |
|
| 481 | + if ('paypal' == $gateway && wpinv_is_test_mode('paypal')) { |
|
| 482 | 482 | $description .= '<br> <br>' . sprintf( |
| 483 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
| 483 | + __('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing'), |
|
| 484 | 484 | '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
| 485 | 485 | '</a>' |
| 486 | 486 | ); |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | * Personal data exporters. |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | -defined( 'ABSPATH' ) || exit; |
|
| 6 | +defined('ABSPATH') || exit; |
|
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * WPInv_Privacy_Exporters Class. |
@@ -17,38 +17,38 @@ discard block |
||
| 17 | 17 | * @param int $page Page. |
| 18 | 18 | * @return array An array of invoice data in name value pairs |
| 19 | 19 | */ |
| 20 | - public static function customer_invoice_data_exporter( $email_address, $page ) { |
|
| 20 | + public static function customer_invoice_data_exporter($email_address, $page) { |
|
| 21 | 21 | $done = false; |
| 22 | 22 | $page = (int) $page; |
| 23 | 23 | $data_to_export = array(); |
| 24 | 24 | |
| 25 | - $user = get_user_by( 'email', $email_address ); |
|
| 26 | - if ( ! $user instanceof WP_User ) { |
|
| 25 | + $user = get_user_by('email', $email_address); |
|
| 26 | + if (!$user instanceof WP_User) { |
|
| 27 | 27 | return array( |
| 28 | 28 | 'data' => $data_to_export, |
| 29 | 29 | 'done' => true, |
| 30 | 30 | ); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - $args = array( |
|
| 33 | + $args = array( |
|
| 34 | 34 | 'limit' => 30, |
| 35 | 35 | 'page' => $page, |
| 36 | 36 | 'user' => $user->ID, |
| 37 | 37 | ); |
| 38 | 38 | |
| 39 | - $invoices = wpinv_get_invoices( $args ); |
|
| 39 | + $invoices = wpinv_get_invoices($args); |
|
| 40 | 40 | |
| 41 | - if ( 0 < count( $invoices ) ) { |
|
| 42 | - foreach ( $invoices as $invoice ) { |
|
| 41 | + if (0 < count($invoices)) { |
|
| 42 | + foreach ($invoices as $invoice) { |
|
| 43 | 43 | $data_to_export[] = array( |
| 44 | 44 | 'group_id' => 'customer_invoices', |
| 45 | - 'group_label' => __( 'Invoicing Data', 'invoicing' ), |
|
| 46 | - 'group_description' => __( 'Customer invoicing data.', 'invoicing' ), |
|
| 45 | + 'group_label' => __('Invoicing Data', 'invoicing'), |
|
| 46 | + 'group_description' => __('Customer invoicing data.', 'invoicing'), |
|
| 47 | 47 | 'item_id' => "wpinv-{$invoice->ID}", |
| 48 | - 'data' => self::get_customer_invoice_data( $invoice ), |
|
| 48 | + 'data' => self::get_customer_invoice_data($invoice), |
|
| 49 | 49 | ); |
| 50 | 50 | } |
| 51 | - $done = 30 > count( $invoices ); |
|
| 51 | + $done = 30 > count($invoices); |
|
| 52 | 52 | } else { |
| 53 | 53 | $done = true; |
| 54 | 54 | } |
@@ -66,59 +66,59 @@ discard block |
||
| 66 | 66 | * @param WPInv_Invoice $invoice invoice object. |
| 67 | 67 | * @return array |
| 68 | 68 | */ |
| 69 | - public static function get_customer_invoice_data( $invoice ) { |
|
| 69 | + public static function get_customer_invoice_data($invoice) { |
|
| 70 | 70 | $personal_data = array(); |
| 71 | 71 | |
| 72 | 72 | $props_to_export = array( |
| 73 | - 'number' => __( 'Invoice Number', 'invoicing' ), |
|
| 74 | - 'created_date' => __( 'Invoice Date', 'invoicing' ), |
|
| 75 | - 'status' => __( 'Invoice Status', 'invoicing' ), |
|
| 76 | - 'total' => __( 'Invoice Total', 'invoicing' ), |
|
| 77 | - 'items' => __( 'Invoice Items', 'invoicing' ), |
|
| 78 | - 'first_name' => __( 'First Name', 'invoicing' ), |
|
| 79 | - 'last_name' => __( 'Last Name', 'invoicing' ), |
|
| 80 | - 'email' => __( 'Email Address', 'invoicing' ), |
|
| 81 | - '_wpinv_company' => __( 'Company', 'invoicing' ), |
|
| 82 | - 'phone' => __( 'Phone Number', 'invoicing' ), |
|
| 83 | - 'address' => __( 'Address', 'invoicing' ), |
|
| 84 | - '_wpinv_city' => __( 'City', 'invoicing' ), |
|
| 85 | - '_wpinv_country' => __( 'Country', 'invoicing' ), |
|
| 86 | - '_wpinv_state' => __( 'State', 'invoicing' ), |
|
| 87 | - '_wpinv_zip' => __( 'Zip Code', 'invoicing' ), |
|
| 73 | + 'number' => __('Invoice Number', 'invoicing'), |
|
| 74 | + 'created_date' => __('Invoice Date', 'invoicing'), |
|
| 75 | + 'status' => __('Invoice Status', 'invoicing'), |
|
| 76 | + 'total' => __('Invoice Total', 'invoicing'), |
|
| 77 | + 'items' => __('Invoice Items', 'invoicing'), |
|
| 78 | + 'first_name' => __('First Name', 'invoicing'), |
|
| 79 | + 'last_name' => __('Last Name', 'invoicing'), |
|
| 80 | + 'email' => __('Email Address', 'invoicing'), |
|
| 81 | + '_wpinv_company' => __('Company', 'invoicing'), |
|
| 82 | + 'phone' => __('Phone Number', 'invoicing'), |
|
| 83 | + 'address' => __('Address', 'invoicing'), |
|
| 84 | + '_wpinv_city' => __('City', 'invoicing'), |
|
| 85 | + '_wpinv_country' => __('Country', 'invoicing'), |
|
| 86 | + '_wpinv_state' => __('State', 'invoicing'), |
|
| 87 | + '_wpinv_zip' => __('Zip Code', 'invoicing'), |
|
| 88 | 88 | ); |
| 89 | 89 | |
| 90 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 90 | + $subscription = wpinv_get_subscription($invoice); |
|
| 91 | 91 | $period = $initial_amt = $bill_times = $billed = $renewal_date = ''; |
| 92 | 92 | |
| 93 | - if ( $invoice->is_recurring() && !empty( $subscription ) ) { |
|
| 94 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(),$subscription->get_frequency() ); |
|
| 95 | - $period = wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $subscription->get_parent_payment()->get_currency() ) . ' / ' . $frequency; |
|
| 96 | - $initial_amt = wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
| 97 | - $bill_times = $subscription->get_times_billed() . ' / ' . ( ( $subscription->get_bill_times() == 0 ) ? __( 'Until Cancelled', 'invoicing' ) : $subscription->get_bill_times() ); |
|
| 98 | - $renewal_date = ! empty( $subscription->get_expiration() ) ? getpaid_format_date( $subscription->get_expiration() ) : __( 'N/A', 'invoicing' ); |
|
| 99 | - |
|
| 100 | - $props_to_export['period'] = __( 'Billing Cycle', 'invoicing' ); |
|
| 101 | - $props_to_export['initial_amount'] = __( 'Initial Amount', 'invoicing' ); |
|
| 102 | - $props_to_export['bill_times'] = __( 'Times Billed', 'invoicing' ); |
|
| 103 | - $props_to_export['renewal_date'] = __( 'Renewal Date', 'invoicing' ); |
|
| 93 | + if ($invoice->is_recurring() && !empty($subscription)) { |
|
| 94 | + $frequency = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency()); |
|
| 95 | + $period = wpinv_price(wpinv_format_amount($subscription->get_recurring_amount()), $subscription->get_parent_payment()->get_currency()) . ' / ' . $frequency; |
|
| 96 | + $initial_amt = wpinv_price(wpinv_format_amount($subscription->get_initial_amount()), $subscription->get_parent_payment()->get_currency()); |
|
| 97 | + $bill_times = $subscription->get_times_billed() . ' / ' . (($subscription->get_bill_times() == 0) ? __('Until Cancelled', 'invoicing') : $subscription->get_bill_times()); |
|
| 98 | + $renewal_date = !empty($subscription->get_expiration()) ? getpaid_format_date($subscription->get_expiration()) : __('N/A', 'invoicing'); |
|
| 99 | + |
|
| 100 | + $props_to_export['period'] = __('Billing Cycle', 'invoicing'); |
|
| 101 | + $props_to_export['initial_amount'] = __('Initial Amount', 'invoicing'); |
|
| 102 | + $props_to_export['bill_times'] = __('Times Billed', 'invoicing'); |
|
| 103 | + $props_to_export['renewal_date'] = __('Renewal Date', 'invoicing'); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - $props_to_export['ip'] = __( 'IP Address', 'invoicing' ); |
|
| 107 | - $props_to_export['view_url'] = __( 'Invoice Link', 'invoicing' ); |
|
| 106 | + $props_to_export['ip'] = __('IP Address', 'invoicing'); |
|
| 107 | + $props_to_export['view_url'] = __('Invoice Link', 'invoicing'); |
|
| 108 | 108 | |
| 109 | - $props_to_export = apply_filters( 'wpinv_privacy_export_invoice_personal_data_props', $props_to_export, $invoice, $subscription); |
|
| 109 | + $props_to_export = apply_filters('wpinv_privacy_export_invoice_personal_data_props', $props_to_export, $invoice, $subscription); |
|
| 110 | 110 | |
| 111 | - foreach ( $props_to_export as $prop => $name ) { |
|
| 111 | + foreach ($props_to_export as $prop => $name) { |
|
| 112 | 112 | $value = ''; |
| 113 | 113 | |
| 114 | - switch ( $prop ) { |
|
| 114 | + switch ($prop) { |
|
| 115 | 115 | case 'items': |
| 116 | 116 | $item_names = array(); |
| 117 | - foreach ( $invoice->get_cart_details() as $key => $cart_item ) { |
|
| 118 | - $item_quantity = $cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1; |
|
| 117 | + foreach ($invoice->get_cart_details() as $key => $cart_item) { |
|
| 118 | + $item_quantity = $cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1; |
|
| 119 | 119 | $item_names[] = $cart_item['name'] . ' x ' . $item_quantity; |
| 120 | 120 | } |
| 121 | - $value = implode( ', ', $item_names ); |
|
| 121 | + $value = implode(', ', $item_names); |
|
| 122 | 122 | break; |
| 123 | 123 | case 'status': |
| 124 | 124 | $value = $invoice->get_status(true); |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | $value = $renewal_date; |
| 140 | 140 | break; |
| 141 | 141 | default: |
| 142 | - if ( is_callable( array( $invoice, 'get_' . $prop ) ) ) { |
|
| 142 | + if (is_callable(array($invoice, 'get_' . $prop))) { |
|
| 143 | 143 | $value = $invoice->{"get_$prop"}(); |
| 144 | 144 | } else { |
| 145 | 145 | $value = $invoice->get_meta($prop); |
@@ -147,9 +147,9 @@ discard block |
||
| 147 | 147 | break; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - $value = apply_filters( 'wpi_privacy_export_invoice_personal_data_prop', $value, $prop, $invoice ); |
|
| 150 | + $value = apply_filters('wpi_privacy_export_invoice_personal_data_prop', $value, $prop, $invoice); |
|
| 151 | 151 | |
| 152 | - if ( $value ) { |
|
| 152 | + if ($value) { |
|
| 153 | 153 | $personal_data[] = array( |
| 154 | 154 | 'name' => $name, |
| 155 | 155 | 'value' => $value, |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - $personal_data = apply_filters( 'wpinv_privacy_export_invoice_personal_data', $personal_data, $invoice ); |
|
| 161 | + $personal_data = apply_filters('wpinv_privacy_export_invoice_personal_data', $personal_data, $invoice); |
|
| 162 | 162 | |
| 163 | 163 | return $personal_data; |
| 164 | 164 | |
@@ -14,420 +14,420 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class WPInv_Plugin { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * GetPaid version. |
|
| 19 | - * |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - public $version; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Data container. |
|
| 26 | - * |
|
| 27 | - * @var array |
|
| 28 | - */ |
|
| 29 | - protected $data = array(); |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Form elements instance. |
|
| 33 | - * |
|
| 34 | - * @var WPInv_Payment_Form_Elements |
|
| 35 | - */ |
|
| 36 | - public $form_elements; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Tax instance. |
|
| 40 | - * |
|
| 41 | - * @var WPInv_EUVat |
|
| 42 | - */ |
|
| 43 | - public $tax; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @param array An array of payment gateways. |
|
| 47 | - */ |
|
| 48 | - public $gateways; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Class constructor. |
|
| 52 | - */ |
|
| 53 | - public function __construct() { |
|
| 54 | - $this->define_constants(); |
|
| 55 | - $this->includes(); |
|
| 56 | - $this->init_hooks(); |
|
| 57 | - $this->set_properties(); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Sets a custom data property. |
|
| 62 | - * |
|
| 63 | - * @param string $prop The prop to set. |
|
| 64 | - * @param mixed $value The value to retrieve. |
|
| 65 | - */ |
|
| 66 | - public function set( $prop, $value ) { |
|
| 67 | - $this->data[ $prop ] = $value; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Gets a custom data property. |
|
| 72 | - * |
|
| 73 | - * @param string $prop The prop to set. |
|
| 74 | - * @return mixed The value. |
|
| 75 | - */ |
|
| 76 | - public function get( $prop ) { |
|
| 77 | - |
|
| 78 | - if ( isset( $this->data[ $prop ] ) ) { |
|
| 79 | - return $this->data[ $prop ]; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - return null; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Define class properties. |
|
| 87 | - */ |
|
| 88 | - public function set_properties() { |
|
| 89 | - |
|
| 90 | - // Sessions. |
|
| 91 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 92 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
| 93 | - $this->tax = new WPInv_EUVat(); |
|
| 94 | - $this->tax->init(); |
|
| 95 | - $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility. |
|
| 96 | - |
|
| 97 | - // Init other objects. |
|
| 98 | - $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor. |
|
| 99 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 100 | - $this->set( 'notes', new WPInv_Notes() ); |
|
| 101 | - $this->set( 'api', new WPInv_API() ); |
|
| 102 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 103 | - $this->set( 'template', new GetPaid_Template() ); |
|
| 104 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
| 105 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
| 106 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
| 107 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
| 108 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
| 109 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
| 110 | - |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Define plugin constants. |
|
| 115 | - */ |
|
| 116 | - public function define_constants() { |
|
| 117 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 118 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 119 | - $this->version = WPINV_VERSION; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Hook into actions and filters. |
|
| 124 | - * |
|
| 125 | - * @since 1.0.19 |
|
| 126 | - */ |
|
| 127 | - protected function init_hooks() { |
|
| 128 | - /* Internationalize the text strings used. */ |
|
| 129 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 130 | - |
|
| 131 | - // Init the plugin after WordPress inits. |
|
| 132 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 133 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
| 134 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
| 135 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
| 136 | - |
|
| 137 | - if ( class_exists( 'BuddyPress' ) ) { |
|
| 138 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
| 142 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
| 143 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
| 144 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 145 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 146 | - |
|
| 147 | - // Fires after registering actions. |
|
| 148 | - do_action( 'wpinv_actions', $this ); |
|
| 149 | - do_action( 'getpaid_actions', $this ); |
|
| 150 | - |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - public function plugins_loaded() { |
|
| 154 | - /* Internationalize the text strings used. */ |
|
| 155 | - $this->load_textdomain(); |
|
| 156 | - |
|
| 157 | - do_action( 'wpinv_loaded' ); |
|
| 158 | - |
|
| 159 | - // Fix oxygen page builder conflict |
|
| 160 | - if ( function_exists( 'ct_css_output' ) ) { |
|
| 161 | - wpinv_oxygen_fix_conflict(); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Load the translation of the plugin. |
|
| 167 | - * |
|
| 168 | - * @since 1.0 |
|
| 169 | - */ |
|
| 170 | - public function load_textdomain( $locale = NULL ) { |
|
| 171 | - if ( empty( $locale ) ) { |
|
| 172 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 176 | - |
|
| 177 | - unload_textdomain( 'invoicing' ); |
|
| 178 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 179 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Define language constants. |
|
| 183 | - */ |
|
| 184 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Include required core files used in admin and on the frontend. |
|
| 189 | - */ |
|
| 190 | - public function includes() { |
|
| 191 | - |
|
| 192 | - // Start with the settings. |
|
| 193 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
| 194 | - |
|
| 195 | - // Packages/libraries. |
|
| 196 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
| 197 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
| 198 | - |
|
| 199 | - // Load functions. |
|
| 200 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
| 201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
| 202 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
| 203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
| 204 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
| 205 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
| 206 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
| 207 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
| 208 | - require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
| 209 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
| 210 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
| 211 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
| 212 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
| 213 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
| 214 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
| 215 | - |
|
| 216 | - // Register autoloader. |
|
| 217 | - try { |
|
| 218 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 219 | - } catch ( Exception $e ) { |
|
| 220 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
| 224 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
| 225 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
| 226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
| 227 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
| 228 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
| 229 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
| 230 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
| 231 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
| 232 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
| 233 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
| 234 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
| 235 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
| 236 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
| 237 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
| 238 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
| 239 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
| 240 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
| 241 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
| 242 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
| 243 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * Load the tax class. |
|
| 247 | - */ |
|
| 248 | - if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
| 249 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 253 | - GetPaid_Post_Types_Admin::init(); |
|
| 254 | - |
|
| 255 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
| 256 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
| 257 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
| 258 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
| 259 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
| 260 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
| 261 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
| 262 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
| 263 | - // load the user class only on the users.php page |
|
| 264 | - global $pagenow; |
|
| 265 | - if($pagenow=='users.php'){ |
|
| 266 | - new WPInv_Admin_Users(); |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - // Register cli commands |
|
| 271 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 272 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
| 273 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * Class autoloader |
|
| 281 | - * |
|
| 282 | - * @param string $class_name The name of the class to load. |
|
| 283 | - * @access public |
|
| 284 | - * @since 1.0.19 |
|
| 285 | - * @return void |
|
| 286 | - */ |
|
| 287 | - public function autoload( $class_name ) { |
|
| 288 | - |
|
| 289 | - // Normalize the class name... |
|
| 290 | - $class_name = strtolower( $class_name ); |
|
| 291 | - |
|
| 292 | - // ... and make sure it is our class. |
|
| 293 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 294 | - return; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - // Next, prepare the file name from the class. |
|
| 298 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 299 | - |
|
| 300 | - // Base path of the classes. |
|
| 301 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 302 | - |
|
| 303 | - // And an array of possible locations in order of importance. |
|
| 304 | - $locations = array( |
|
| 305 | - "$plugin_path/includes", |
|
| 306 | - "$plugin_path/includes/data-stores", |
|
| 307 | - "$plugin_path/includes/gateways", |
|
| 308 | - "$plugin_path/includes/payments", |
|
| 309 | - "$plugin_path/includes/api", |
|
| 310 | - "$plugin_path/includes/admin", |
|
| 311 | - "$plugin_path/includes/admin/meta-boxes", |
|
| 312 | - ); |
|
| 313 | - |
|
| 314 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 315 | - |
|
| 316 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 317 | - include trailingslashit( $location ) . $file_name; |
|
| 318 | - break; |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * Inits hooks etc. |
|
| 327 | - */ |
|
| 328 | - public function init() { |
|
| 329 | - |
|
| 330 | - // Fires before getpaid inits. |
|
| 331 | - do_action( 'before_getpaid_init', $this ); |
|
| 332 | - |
|
| 333 | - // Load default gateways. |
|
| 334 | - $gateways = apply_filters( |
|
| 335 | - 'getpaid_default_gateways', |
|
| 336 | - array( |
|
| 337 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
| 338 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
| 339 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
| 340 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
| 341 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
| 342 | - ) |
|
| 343 | - ); |
|
| 344 | - |
|
| 345 | - foreach ( $gateways as $id => $class ) { |
|
| 346 | - $this->gateways[ $id ] = new $class(); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - // Fires after getpaid inits. |
|
| 350 | - do_action( 'getpaid_init', $this ); |
|
| 351 | - |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * Checks if this is an IPN request and processes it. |
|
| 356 | - */ |
|
| 357 | - public function maybe_process_ipn() { |
|
| 358 | - |
|
| 359 | - // Ensure that this is an IPN request. |
|
| 360 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 361 | - return; |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
| 365 | - |
|
| 366 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 367 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 368 | - exit; |
|
| 369 | - |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - public function enqueue_scripts() { |
|
| 373 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 374 | - |
|
| 375 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
| 376 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
| 377 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
| 378 | - |
|
| 379 | - // Register scripts |
|
| 380 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
| 381 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
| 382 | - |
|
| 383 | - $localize = array(); |
|
| 384 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 385 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 386 | - $localize['currency_symbol'] = wpinv_currency_symbol(); |
|
| 387 | - $localize['currency_pos'] = wpinv_currency_position(); |
|
| 388 | - $localize['thousand_sep'] = wpinv_thousands_separator(); |
|
| 389 | - $localize['decimal_sep'] = wpinv_decimal_separator(); |
|
| 390 | - $localize['decimals'] = wpinv_decimals(); |
|
| 391 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 392 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
| 393 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
| 394 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 395 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 396 | - |
|
| 397 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 398 | - |
|
| 399 | - wp_enqueue_script( 'jquery-blockui' ); |
|
| 400 | - $autofill_api = wpinv_get_option('address_autofill_api'); |
|
| 401 | - $autofill_active = wpinv_get_option('address_autofill_active'); |
|
| 402 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
| 403 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
| 404 | - wp_dequeue_script( 'google-maps-api' ); |
|
| 405 | - } |
|
| 406 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
| 407 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' ); |
|
| 411 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
| 412 | - |
|
| 413 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
| 414 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 415 | - |
|
| 416 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 417 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - public function wpinv_actions() { |
|
| 421 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 422 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - /** |
|
| 17 | + /** |
|
| 18 | + * GetPaid version. |
|
| 19 | + * |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + public $version; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Data container. |
|
| 26 | + * |
|
| 27 | + * @var array |
|
| 28 | + */ |
|
| 29 | + protected $data = array(); |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Form elements instance. |
|
| 33 | + * |
|
| 34 | + * @var WPInv_Payment_Form_Elements |
|
| 35 | + */ |
|
| 36 | + public $form_elements; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Tax instance. |
|
| 40 | + * |
|
| 41 | + * @var WPInv_EUVat |
|
| 42 | + */ |
|
| 43 | + public $tax; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @param array An array of payment gateways. |
|
| 47 | + */ |
|
| 48 | + public $gateways; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Class constructor. |
|
| 52 | + */ |
|
| 53 | + public function __construct() { |
|
| 54 | + $this->define_constants(); |
|
| 55 | + $this->includes(); |
|
| 56 | + $this->init_hooks(); |
|
| 57 | + $this->set_properties(); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Sets a custom data property. |
|
| 62 | + * |
|
| 63 | + * @param string $prop The prop to set. |
|
| 64 | + * @param mixed $value The value to retrieve. |
|
| 65 | + */ |
|
| 66 | + public function set( $prop, $value ) { |
|
| 67 | + $this->data[ $prop ] = $value; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Gets a custom data property. |
|
| 72 | + * |
|
| 73 | + * @param string $prop The prop to set. |
|
| 74 | + * @return mixed The value. |
|
| 75 | + */ |
|
| 76 | + public function get( $prop ) { |
|
| 77 | + |
|
| 78 | + if ( isset( $this->data[ $prop ] ) ) { |
|
| 79 | + return $this->data[ $prop ]; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + return null; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Define class properties. |
|
| 87 | + */ |
|
| 88 | + public function set_properties() { |
|
| 89 | + |
|
| 90 | + // Sessions. |
|
| 91 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 92 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
| 93 | + $this->tax = new WPInv_EUVat(); |
|
| 94 | + $this->tax->init(); |
|
| 95 | + $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility. |
|
| 96 | + |
|
| 97 | + // Init other objects. |
|
| 98 | + $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor. |
|
| 99 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 100 | + $this->set( 'notes', new WPInv_Notes() ); |
|
| 101 | + $this->set( 'api', new WPInv_API() ); |
|
| 102 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 103 | + $this->set( 'template', new GetPaid_Template() ); |
|
| 104 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
| 105 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
| 106 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
| 107 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
| 108 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
| 109 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
| 110 | + |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Define plugin constants. |
|
| 115 | + */ |
|
| 116 | + public function define_constants() { |
|
| 117 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 118 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 119 | + $this->version = WPINV_VERSION; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Hook into actions and filters. |
|
| 124 | + * |
|
| 125 | + * @since 1.0.19 |
|
| 126 | + */ |
|
| 127 | + protected function init_hooks() { |
|
| 128 | + /* Internationalize the text strings used. */ |
|
| 129 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 130 | + |
|
| 131 | + // Init the plugin after WordPress inits. |
|
| 132 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 133 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
| 134 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
| 135 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
| 136 | + |
|
| 137 | + if ( class_exists( 'BuddyPress' ) ) { |
|
| 138 | + add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
| 142 | + add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
| 143 | + add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
| 144 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 145 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 146 | + |
|
| 147 | + // Fires after registering actions. |
|
| 148 | + do_action( 'wpinv_actions', $this ); |
|
| 149 | + do_action( 'getpaid_actions', $this ); |
|
| 150 | + |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + public function plugins_loaded() { |
|
| 154 | + /* Internationalize the text strings used. */ |
|
| 155 | + $this->load_textdomain(); |
|
| 156 | + |
|
| 157 | + do_action( 'wpinv_loaded' ); |
|
| 158 | + |
|
| 159 | + // Fix oxygen page builder conflict |
|
| 160 | + if ( function_exists( 'ct_css_output' ) ) { |
|
| 161 | + wpinv_oxygen_fix_conflict(); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Load the translation of the plugin. |
|
| 167 | + * |
|
| 168 | + * @since 1.0 |
|
| 169 | + */ |
|
| 170 | + public function load_textdomain( $locale = NULL ) { |
|
| 171 | + if ( empty( $locale ) ) { |
|
| 172 | + $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 176 | + |
|
| 177 | + unload_textdomain( 'invoicing' ); |
|
| 178 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 179 | + load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Define language constants. |
|
| 183 | + */ |
|
| 184 | + require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Include required core files used in admin and on the frontend. |
|
| 189 | + */ |
|
| 190 | + public function includes() { |
|
| 191 | + |
|
| 192 | + // Start with the settings. |
|
| 193 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
| 194 | + |
|
| 195 | + // Packages/libraries. |
|
| 196 | + require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
| 197 | + require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
| 198 | + |
|
| 199 | + // Load functions. |
|
| 200 | + require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
| 201 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
| 202 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
| 203 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
| 204 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
| 205 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
| 206 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
| 207 | + require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
| 208 | + require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
| 209 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
| 210 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
| 211 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
| 212 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
| 213 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
| 214 | + require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
| 215 | + |
|
| 216 | + // Register autoloader. |
|
| 217 | + try { |
|
| 218 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 219 | + } catch ( Exception $e ) { |
|
| 220 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
| 224 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
| 225 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
| 226 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
| 227 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
| 228 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
| 229 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
| 230 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
| 231 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
| 232 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
| 233 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
| 234 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
| 235 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
| 236 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
| 237 | + require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
| 238 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
| 239 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
| 240 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
| 241 | + require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
| 242 | + require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
| 243 | + require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * Load the tax class. |
|
| 247 | + */ |
|
| 248 | + if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
| 249 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 253 | + GetPaid_Post_Types_Admin::init(); |
|
| 254 | + |
|
| 255 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
| 256 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
| 257 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
| 258 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
| 259 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
| 260 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
| 261 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
| 262 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
| 263 | + // load the user class only on the users.php page |
|
| 264 | + global $pagenow; |
|
| 265 | + if($pagenow=='users.php'){ |
|
| 266 | + new WPInv_Admin_Users(); |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + // Register cli commands |
|
| 271 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 272 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
| 273 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * Class autoloader |
|
| 281 | + * |
|
| 282 | + * @param string $class_name The name of the class to load. |
|
| 283 | + * @access public |
|
| 284 | + * @since 1.0.19 |
|
| 285 | + * @return void |
|
| 286 | + */ |
|
| 287 | + public function autoload( $class_name ) { |
|
| 288 | + |
|
| 289 | + // Normalize the class name... |
|
| 290 | + $class_name = strtolower( $class_name ); |
|
| 291 | + |
|
| 292 | + // ... and make sure it is our class. |
|
| 293 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 294 | + return; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + // Next, prepare the file name from the class. |
|
| 298 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 299 | + |
|
| 300 | + // Base path of the classes. |
|
| 301 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 302 | + |
|
| 303 | + // And an array of possible locations in order of importance. |
|
| 304 | + $locations = array( |
|
| 305 | + "$plugin_path/includes", |
|
| 306 | + "$plugin_path/includes/data-stores", |
|
| 307 | + "$plugin_path/includes/gateways", |
|
| 308 | + "$plugin_path/includes/payments", |
|
| 309 | + "$plugin_path/includes/api", |
|
| 310 | + "$plugin_path/includes/admin", |
|
| 311 | + "$plugin_path/includes/admin/meta-boxes", |
|
| 312 | + ); |
|
| 313 | + |
|
| 314 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 315 | + |
|
| 316 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 317 | + include trailingslashit( $location ) . $file_name; |
|
| 318 | + break; |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * Inits hooks etc. |
|
| 327 | + */ |
|
| 328 | + public function init() { |
|
| 329 | + |
|
| 330 | + // Fires before getpaid inits. |
|
| 331 | + do_action( 'before_getpaid_init', $this ); |
|
| 332 | + |
|
| 333 | + // Load default gateways. |
|
| 334 | + $gateways = apply_filters( |
|
| 335 | + 'getpaid_default_gateways', |
|
| 336 | + array( |
|
| 337 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
| 338 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
| 339 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
| 340 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
| 341 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
| 342 | + ) |
|
| 343 | + ); |
|
| 344 | + |
|
| 345 | + foreach ( $gateways as $id => $class ) { |
|
| 346 | + $this->gateways[ $id ] = new $class(); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + // Fires after getpaid inits. |
|
| 350 | + do_action( 'getpaid_init', $this ); |
|
| 351 | + |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * Checks if this is an IPN request and processes it. |
|
| 356 | + */ |
|
| 357 | + public function maybe_process_ipn() { |
|
| 358 | + |
|
| 359 | + // Ensure that this is an IPN request. |
|
| 360 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 361 | + return; |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
| 365 | + |
|
| 366 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 367 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 368 | + exit; |
|
| 369 | + |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + public function enqueue_scripts() { |
|
| 373 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 374 | + |
|
| 375 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
| 376 | + wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
| 377 | + wp_enqueue_style( 'wpinv_front_style' ); |
|
| 378 | + |
|
| 379 | + // Register scripts |
|
| 380 | + wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
| 381 | + wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
| 382 | + |
|
| 383 | + $localize = array(); |
|
| 384 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 385 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 386 | + $localize['currency_symbol'] = wpinv_currency_symbol(); |
|
| 387 | + $localize['currency_pos'] = wpinv_currency_position(); |
|
| 388 | + $localize['thousand_sep'] = wpinv_thousands_separator(); |
|
| 389 | + $localize['decimal_sep'] = wpinv_decimal_separator(); |
|
| 390 | + $localize['decimals'] = wpinv_decimals(); |
|
| 391 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 392 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
| 393 | + $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
| 394 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 395 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 396 | + |
|
| 397 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 398 | + |
|
| 399 | + wp_enqueue_script( 'jquery-blockui' ); |
|
| 400 | + $autofill_api = wpinv_get_option('address_autofill_api'); |
|
| 401 | + $autofill_active = wpinv_get_option('address_autofill_active'); |
|
| 402 | + if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
| 403 | + if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
| 404 | + wp_dequeue_script( 'google-maps-api' ); |
|
| 405 | + } |
|
| 406 | + wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
| 407 | + wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' ); |
|
| 411 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
| 412 | + |
|
| 413 | + wp_enqueue_script( 'wpinv-front-script' ); |
|
| 414 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 415 | + |
|
| 416 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 417 | + wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + public function wpinv_actions() { |
|
| 421 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 422 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | 427 | * Fires an action after verifying that a user can fire them. |
| 428 | - * |
|
| 429 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
| 430 | - * current user owns the invoice/subscription. |
|
| 428 | + * |
|
| 429 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
| 430 | + * current user owns the invoice/subscription. |
|
| 431 | 431 | */ |
| 432 | 432 | public function maybe_do_authenticated_action() { |
| 433 | 433 | |
@@ -438,82 +438,82 @@ discard block |
||
| 438 | 438 | |
| 439 | 439 | } |
| 440 | 440 | |
| 441 | - public function pre_get_posts( $wp_query ) { |
|
| 442 | - if ( ! is_admin() && !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 443 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - return $wp_query; |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - public function bp_invoicing_init() { |
|
| 450 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * Register widgets |
|
| 455 | - * |
|
| 456 | - */ |
|
| 457 | - public function register_widgets() { |
|
| 458 | - $widgets = apply_filters( |
|
| 459 | - 'getpaid_widget_classes', |
|
| 460 | - array( |
|
| 461 | - 'WPInv_Checkout_Widget', |
|
| 462 | - 'WPInv_History_Widget', |
|
| 463 | - 'WPInv_Receipt_Widget', |
|
| 464 | - 'WPInv_Subscriptions_Widget', |
|
| 465 | - 'WPInv_Buy_Item_Widget', |
|
| 466 | - 'WPInv_Messages_Widget', |
|
| 467 | - 'WPInv_GetPaid_Widget' |
|
| 468 | - ) |
|
| 469 | - ); |
|
| 470 | - |
|
| 471 | - foreach ( $widgets as $widget ) { |
|
| 472 | - register_widget( $widget ); |
|
| 473 | - } |
|
| 441 | + public function pre_get_posts( $wp_query ) { |
|
| 442 | + if ( ! is_admin() && !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 443 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + return $wp_query; |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + public function bp_invoicing_init() { |
|
| 450 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * Register widgets |
|
| 455 | + * |
|
| 456 | + */ |
|
| 457 | + public function register_widgets() { |
|
| 458 | + $widgets = apply_filters( |
|
| 459 | + 'getpaid_widget_classes', |
|
| 460 | + array( |
|
| 461 | + 'WPInv_Checkout_Widget', |
|
| 462 | + 'WPInv_History_Widget', |
|
| 463 | + 'WPInv_Receipt_Widget', |
|
| 464 | + 'WPInv_Subscriptions_Widget', |
|
| 465 | + 'WPInv_Buy_Item_Widget', |
|
| 466 | + 'WPInv_Messages_Widget', |
|
| 467 | + 'WPInv_GetPaid_Widget' |
|
| 468 | + ) |
|
| 469 | + ); |
|
| 470 | + |
|
| 471 | + foreach ( $widgets as $widget ) { |
|
| 472 | + register_widget( $widget ); |
|
| 473 | + } |
|
| 474 | 474 | |
| 475 | - } |
|
| 475 | + } |
|
| 476 | 476 | |
| 477 | - /** |
|
| 478 | - * Remove our pages from yoast sitemaps. |
|
| 479 | - * |
|
| 480 | - * @since 1.0.19 |
|
| 481 | - * @param int[] $excluded_posts_ids |
|
| 482 | - */ |
|
| 483 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
| 477 | + /** |
|
| 478 | + * Remove our pages from yoast sitemaps. |
|
| 479 | + * |
|
| 480 | + * @since 1.0.19 |
|
| 481 | + * @param int[] $excluded_posts_ids |
|
| 482 | + */ |
|
| 483 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
| 484 | 484 | |
| 485 | - // Ensure that we have an array. |
|
| 486 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 487 | - $excluded_posts_ids = array(); |
|
| 488 | - } |
|
| 485 | + // Ensure that we have an array. |
|
| 486 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 487 | + $excluded_posts_ids = array(); |
|
| 488 | + } |
|
| 489 | 489 | |
| 490 | - // Prepare our pages. |
|
| 491 | - $our_pages = array(); |
|
| 490 | + // Prepare our pages. |
|
| 491 | + $our_pages = array(); |
|
| 492 | 492 | |
| 493 | - // Checkout page. |
|
| 494 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 493 | + // Checkout page. |
|
| 494 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 495 | 495 | |
| 496 | - // Success page. |
|
| 497 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 496 | + // Success page. |
|
| 497 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 498 | 498 | |
| 499 | - // Failure page. |
|
| 500 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 499 | + // Failure page. |
|
| 500 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 501 | 501 | |
| 502 | - // History page. |
|
| 503 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 502 | + // History page. |
|
| 503 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 504 | 504 | |
| 505 | - // Subscriptions page. |
|
| 506 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 505 | + // Subscriptions page. |
|
| 506 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 507 | 507 | |
| 508 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 508 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 509 | 509 | |
| 510 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
| 511 | - return array_unique( $excluded_posts_ids ); |
|
| 510 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
| 511 | + return array_unique( $excluded_posts_ids ); |
|
| 512 | 512 | |
| 513 | - } |
|
| 513 | + } |
|
| 514 | 514 | |
| 515 | - public function wp_footer() { |
|
| 516 | - echo ' |
|
| 515 | + public function wp_footer() { |
|
| 516 | + echo ' |
|
| 517 | 517 | <div class="bsui"> |
| 518 | 518 | <div id="getpaid-payment-modal" class="modal" tabindex="-1" role="dialog"> |
| 519 | 519 | <div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;"> |
@@ -524,6 +524,6 @@ discard block |
||
| 524 | 524 | </div> |
| 525 | 525 | </div> |
| 526 | 526 | '; |
| 527 | - } |
|
| 527 | + } |
|
| 528 | 528 | |
| 529 | 529 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @since 1.0.0 |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * Main Invoicing class. |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | * @param string $prop The prop to set. |
| 64 | 64 | * @param mixed $value The value to retrieve. |
| 65 | 65 | */ |
| 66 | - public function set( $prop, $value ) { |
|
| 67 | - $this->data[ $prop ] = $value; |
|
| 66 | + public function set($prop, $value) { |
|
| 67 | + $this->data[$prop] = $value; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -73,10 +73,10 @@ discard block |
||
| 73 | 73 | * @param string $prop The prop to set. |
| 74 | 74 | * @return mixed The value. |
| 75 | 75 | */ |
| 76 | - public function get( $prop ) { |
|
| 76 | + public function get($prop) { |
|
| 77 | 77 | |
| 78 | - if ( isset( $this->data[ $prop ] ) ) { |
|
| 79 | - return $this->data[ $prop ]; |
|
| 78 | + if (isset($this->data[$prop])) { |
|
| 79 | + return $this->data[$prop]; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | return null; |
@@ -88,25 +88,25 @@ discard block |
||
| 88 | 88 | public function set_properties() { |
| 89 | 89 | |
| 90 | 90 | // Sessions. |
| 91 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 92 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
| 91 | + $this->set('session', new WPInv_Session_Handler()); |
|
| 92 | + $GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility. |
|
| 93 | 93 | $this->tax = new WPInv_EUVat(); |
| 94 | 94 | $this->tax->init(); |
| 95 | 95 | $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility. |
| 96 | 96 | |
| 97 | 97 | // Init other objects. |
| 98 | - $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor. |
|
| 99 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 100 | - $this->set( 'notes', new WPInv_Notes() ); |
|
| 101 | - $this->set( 'api', new WPInv_API() ); |
|
| 102 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 103 | - $this->set( 'template', new GetPaid_Template() ); |
|
| 104 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
| 105 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
| 106 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
| 107 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
| 108 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
| 109 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
| 98 | + $this->set('reports', new WPInv_Reports()); // TODO: Refactor. |
|
| 99 | + $this->set('session', new WPInv_Session_Handler()); |
|
| 100 | + $this->set('notes', new WPInv_Notes()); |
|
| 101 | + $this->set('api', new WPInv_API()); |
|
| 102 | + $this->set('post_types', new GetPaid_Post_Types()); |
|
| 103 | + $this->set('template', new GetPaid_Template()); |
|
| 104 | + $this->set('admin', new GetPaid_Admin()); |
|
| 105 | + $this->set('subscriptions', new WPInv_Subscriptions()); |
|
| 106 | + $this->set('invoice_emails', new GetPaid_Invoice_Notification_Emails()); |
|
| 107 | + $this->set('subscription_emails', new GetPaid_Subscription_Notification_Emails()); |
|
| 108 | + $this->set('daily_maintenace', new GetPaid_Daily_Maintenance()); |
|
| 109 | + $this->set('payment_forms', new GetPaid_Payment_Forms()); |
|
| 110 | 110 | |
| 111 | 111 | } |
| 112 | 112 | |
@@ -114,8 +114,8 @@ discard block |
||
| 114 | 114 | * Define plugin constants. |
| 115 | 115 | */ |
| 116 | 116 | public function define_constants() { |
| 117 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 118 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 117 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
| 118 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
| 119 | 119 | $this->version = WPINV_VERSION; |
| 120 | 120 | } |
| 121 | 121 | |
@@ -126,27 +126,27 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | protected function init_hooks() { |
| 128 | 128 | /* Internationalize the text strings used. */ |
| 129 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 129 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
| 130 | 130 | |
| 131 | 131 | // Init the plugin after WordPress inits. |
| 132 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 133 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
| 134 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
| 135 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
| 132 | + add_action('init', array($this, 'init'), 1); |
|
| 133 | + add_action('init', array($this, 'maybe_process_ipn'), 10); |
|
| 134 | + add_action('init', array($this, 'wpinv_actions')); |
|
| 135 | + add_action('init', array($this, 'maybe_do_authenticated_action'), 100); |
|
| 136 | 136 | |
| 137 | - if ( class_exists( 'BuddyPress' ) ) { |
|
| 138 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
| 137 | + if (class_exists('BuddyPress')) { |
|
| 138 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
| 142 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
| 143 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
| 144 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 145 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 141 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
| 142 | + add_action('wp_footer', array(&$this, 'wp_footer')); |
|
| 143 | + add_action('widgets_init', array(&$this, 'register_widgets')); |
|
| 144 | + add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids')); |
|
| 145 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
| 146 | 146 | |
| 147 | 147 | // Fires after registering actions. |
| 148 | - do_action( 'wpinv_actions', $this ); |
|
| 149 | - do_action( 'getpaid_actions', $this ); |
|
| 148 | + do_action('wpinv_actions', $this); |
|
| 149 | + do_action('getpaid_actions', $this); |
|
| 150 | 150 | |
| 151 | 151 | } |
| 152 | 152 | |
@@ -154,10 +154,10 @@ discard block |
||
| 154 | 154 | /* Internationalize the text strings used. */ |
| 155 | 155 | $this->load_textdomain(); |
| 156 | 156 | |
| 157 | - do_action( 'wpinv_loaded' ); |
|
| 157 | + do_action('wpinv_loaded'); |
|
| 158 | 158 | |
| 159 | 159 | // Fix oxygen page builder conflict |
| 160 | - if ( function_exists( 'ct_css_output' ) ) { |
|
| 160 | + if (function_exists('ct_css_output')) { |
|
| 161 | 161 | wpinv_oxygen_fix_conflict(); |
| 162 | 162 | } |
| 163 | 163 | } |
@@ -167,21 +167,21 @@ discard block |
||
| 167 | 167 | * |
| 168 | 168 | * @since 1.0 |
| 169 | 169 | */ |
| 170 | - public function load_textdomain( $locale = NULL ) { |
|
| 171 | - if ( empty( $locale ) ) { |
|
| 172 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
| 170 | + public function load_textdomain($locale = NULL) { |
|
| 171 | + if (empty($locale)) { |
|
| 172 | + $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 175 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
| 176 | 176 | |
| 177 | - unload_textdomain( 'invoicing' ); |
|
| 178 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 179 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
| 177 | + unload_textdomain('invoicing'); |
|
| 178 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
| 179 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
| 180 | 180 | |
| 181 | 181 | /** |
| 182 | 182 | * Define language constants. |
| 183 | 183 | */ |
| 184 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
| 184 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -190,90 +190,90 @@ discard block |
||
| 190 | 190 | public function includes() { |
| 191 | 191 | |
| 192 | 192 | // Start with the settings. |
| 193 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
| 193 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
| 194 | 194 | |
| 195 | 195 | // Packages/libraries. |
| 196 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
| 197 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
| 196 | + require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php'); |
|
| 197 | + require_once(WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'); |
|
| 198 | 198 | |
| 199 | 199 | // Load functions. |
| 200 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
| 201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
| 202 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
| 203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
| 204 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
| 205 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
| 206 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
| 207 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
| 208 | - require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
| 209 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
| 210 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
| 211 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
| 212 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
| 213 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
| 214 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
| 200 | + require_once(WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'); |
|
| 201 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
| 202 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
| 203 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
| 204 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
| 205 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
| 206 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
| 207 | + require_once(WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'); |
|
| 208 | + require_once(WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'); |
|
| 209 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
| 210 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
| 211 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
| 212 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
| 213 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
| 214 | + require_once(WPINV_PLUGIN_DIR . 'includes/error-functions.php'); |
|
| 215 | 215 | |
| 216 | 216 | // Register autoloader. |
| 217 | 217 | try { |
| 218 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 219 | - } catch ( Exception $e ) { |
|
| 220 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 218 | + spl_autoload_register(array($this, 'autoload'), true); |
|
| 219 | + } catch (Exception $e) { |
|
| 220 | + wpinv_error_log($e->getMessage(), '', __FILE__, 149, true); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
| 224 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
| 225 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
| 226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
| 227 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
| 228 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
| 229 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
| 230 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
| 231 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
| 232 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
| 233 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
| 234 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
| 235 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
| 236 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
| 237 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
| 238 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
| 239 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
| 240 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
| 241 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
| 242 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
| 243 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
| 223 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'); |
|
| 224 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'); |
|
| 225 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
| 226 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
| 227 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php'); |
|
| 228 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'); |
|
| 229 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'); |
|
| 230 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'); |
|
| 231 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'); |
|
| 232 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'); |
|
| 233 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'); |
|
| 234 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'); |
|
| 235 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'); |
|
| 236 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'); |
|
| 237 | + require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php'); |
|
| 238 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'); |
|
| 239 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'); |
|
| 240 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'); |
|
| 241 | + require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'); |
|
| 242 | + require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php'); |
|
| 243 | + require_once(WPINV_PLUGIN_DIR . 'widgets/getpaid.php'); |
|
| 244 | 244 | |
| 245 | 245 | /** |
| 246 | 246 | * Load the tax class. |
| 247 | 247 | */ |
| 248 | - if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
| 249 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
| 248 | + if (!class_exists('WPInv_EUVat')) { |
|
| 249 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 252 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
| 253 | 253 | GetPaid_Post_Types_Admin::init(); |
| 254 | 254 | |
| 255 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
| 256 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
| 257 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
| 258 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
| 259 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
| 260 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
| 261 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
| 262 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
| 255 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php'); |
|
| 256 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
| 257 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'); |
|
| 258 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
| 259 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
| 260 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'); |
|
| 261 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'); |
|
| 262 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'); |
|
| 263 | 263 | // load the user class only on the users.php page |
| 264 | 264 | global $pagenow; |
| 265 | - if($pagenow=='users.php'){ |
|
| 265 | + if ($pagenow == 'users.php') { |
|
| 266 | 266 | new WPInv_Admin_Users(); |
| 267 | 267 | } |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | // Register cli commands |
| 271 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 272 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
| 273 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 271 | + if (defined('WP_CLI') && WP_CLI) { |
|
| 272 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'); |
|
| 273 | + WP_CLI::add_command('invoicing', 'WPInv_CLI'); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
| 276 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | /** |
@@ -284,21 +284,21 @@ discard block |
||
| 284 | 284 | * @since 1.0.19 |
| 285 | 285 | * @return void |
| 286 | 286 | */ |
| 287 | - public function autoload( $class_name ) { |
|
| 287 | + public function autoload($class_name) { |
|
| 288 | 288 | |
| 289 | 289 | // Normalize the class name... |
| 290 | - $class_name = strtolower( $class_name ); |
|
| 290 | + $class_name = strtolower($class_name); |
|
| 291 | 291 | |
| 292 | 292 | // ... and make sure it is our class. |
| 293 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 293 | + if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) { |
|
| 294 | 294 | return; |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | // Next, prepare the file name from the class. |
| 298 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 298 | + $file_name = 'class-' . str_replace('_', '-', $class_name) . '.php'; |
|
| 299 | 299 | |
| 300 | 300 | // Base path of the classes. |
| 301 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 301 | + $plugin_path = untrailingslashit(WPINV_PLUGIN_DIR); |
|
| 302 | 302 | |
| 303 | 303 | // And an array of possible locations in order of importance. |
| 304 | 304 | $locations = array( |
@@ -311,10 +311,10 @@ discard block |
||
| 311 | 311 | "$plugin_path/includes/admin/meta-boxes", |
| 312 | 312 | ); |
| 313 | 313 | |
| 314 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 314 | + foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) { |
|
| 315 | 315 | |
| 316 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 317 | - include trailingslashit( $location ) . $file_name; |
|
| 316 | + if (file_exists(trailingslashit($location) . $file_name)) { |
|
| 317 | + include trailingslashit($location) . $file_name; |
|
| 318 | 318 | break; |
| 319 | 319 | } |
| 320 | 320 | |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | public function init() { |
| 329 | 329 | |
| 330 | 330 | // Fires before getpaid inits. |
| 331 | - do_action( 'before_getpaid_init', $this ); |
|
| 331 | + do_action('before_getpaid_init', $this); |
|
| 332 | 332 | |
| 333 | 333 | // Load default gateways. |
| 334 | 334 | $gateways = apply_filters( |
@@ -342,12 +342,12 @@ discard block |
||
| 342 | 342 | ) |
| 343 | 343 | ); |
| 344 | 344 | |
| 345 | - foreach ( $gateways as $id => $class ) { |
|
| 346 | - $this->gateways[ $id ] = new $class(); |
|
| 345 | + foreach ($gateways as $id => $class) { |
|
| 346 | + $this->gateways[$id] = new $class(); |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | // Fires after getpaid inits. |
| 350 | - do_action( 'getpaid_init', $this ); |
|
| 350 | + do_action('getpaid_init', $this); |
|
| 351 | 351 | |
| 352 | 352 | } |
| 353 | 353 | |
@@ -357,69 +357,69 @@ discard block |
||
| 357 | 357 | public function maybe_process_ipn() { |
| 358 | 358 | |
| 359 | 359 | // Ensure that this is an IPN request. |
| 360 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 360 | + if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) { |
|
| 361 | 361 | return; |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
| 364 | + $gateway = wpinv_clean($_GET['wpi-gateway']); |
|
| 365 | 365 | |
| 366 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 367 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 366 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
| 367 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
| 368 | 368 | exit; |
| 369 | 369 | |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | public function enqueue_scripts() { |
| 373 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 373 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 374 | 374 | |
| 375 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
| 376 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
| 377 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
| 375 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css'); |
|
| 376 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version); |
|
| 377 | + wp_enqueue_style('wpinv_front_style'); |
|
| 378 | 378 | |
| 379 | 379 | // Register scripts |
| 380 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
| 381 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
| 380 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
| 381 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array('jquery'), filemtime(WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js')); |
|
| 382 | 382 | |
| 383 | 383 | $localize = array(); |
| 384 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 385 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 384 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
| 385 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
| 386 | 386 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
| 387 | 387 | $localize['currency_pos'] = wpinv_currency_position(); |
| 388 | 388 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
| 389 | 389 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
| 390 | 390 | $localize['decimals'] = wpinv_decimals(); |
| 391 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 391 | + $localize['txtComplete'] = __('Continue', 'invoicing'); |
|
| 392 | 392 | $localize['UseTaxes'] = wpinv_use_taxes(); |
| 393 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
| 394 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 395 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 393 | + $localize['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce'); |
|
| 394 | + $localize['formNonce'] = wp_create_nonce('getpaid_form_nonce'); |
|
| 395 | + $localize['connectionError'] = __('Could not establish a connection to the server.', 'invoicing'); |
|
| 396 | 396 | |
| 397 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 397 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
| 398 | 398 | |
| 399 | - wp_enqueue_script( 'jquery-blockui' ); |
|
| 399 | + wp_enqueue_script('jquery-blockui'); |
|
| 400 | 400 | $autofill_api = wpinv_get_option('address_autofill_api'); |
| 401 | 401 | $autofill_active = wpinv_get_option('address_autofill_active'); |
| 402 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
| 403 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
| 404 | - wp_dequeue_script( 'google-maps-api' ); |
|
| 402 | + if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) { |
|
| 403 | + if (wp_script_is('google-maps-api', 'enqueued')) { |
|
| 404 | + wp_dequeue_script('google-maps-api'); |
|
| 405 | 405 | } |
| 406 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
| 407 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
| 406 | + wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false); |
|
| 407 | + wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true); |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' ); |
|
| 411 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
| 410 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all'); |
|
| 411 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
| 412 | 412 | |
| 413 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
| 414 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 413 | + wp_enqueue_script('wpinv-front-script'); |
|
| 414 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
| 415 | 415 | |
| 416 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 417 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
| 416 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js'); |
|
| 417 | + wp_enqueue_script('wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('wpinv-front-script', 'wp-hooks'), $version, true); |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | public function wpinv_actions() { |
| 421 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 422 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 421 | + if (isset($_REQUEST['wpi_action'])) { |
|
| 422 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
| 423 | 423 | } |
| 424 | 424 | } |
| 425 | 425 | |
@@ -431,23 +431,23 @@ discard block |
||
| 431 | 431 | */ |
| 432 | 432 | public function maybe_do_authenticated_action() { |
| 433 | 433 | |
| 434 | - if ( is_user_logged_in() && isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
| 435 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
| 436 | - do_action( "getpaid_authenticated_action_$key", $_REQUEST ); |
|
| 434 | + if (is_user_logged_in() && isset($_REQUEST['getpaid-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
| 435 | + $key = sanitize_key($_REQUEST['getpaid-action']); |
|
| 436 | + do_action("getpaid_authenticated_action_$key", $_REQUEST); |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | } |
| 440 | 440 | |
| 441 | - public function pre_get_posts( $wp_query ) { |
|
| 442 | - if ( ! is_admin() && !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 443 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
| 441 | + public function pre_get_posts($wp_query) { |
|
| 442 | + if (!is_admin() && !empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
| 443 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses()); |
|
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | return $wp_query; |
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | public function bp_invoicing_init() { |
| 450 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
| 450 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | /** |
@@ -468,8 +468,8 @@ discard block |
||
| 468 | 468 | ) |
| 469 | 469 | ); |
| 470 | 470 | |
| 471 | - foreach ( $widgets as $widget ) { |
|
| 472 | - register_widget( $widget ); |
|
| 471 | + foreach ($widgets as $widget) { |
|
| 472 | + register_widget($widget); |
|
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | } |
@@ -480,10 +480,10 @@ discard block |
||
| 480 | 480 | * @since 1.0.19 |
| 481 | 481 | * @param int[] $excluded_posts_ids |
| 482 | 482 | */ |
| 483 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
| 483 | + public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) { |
|
| 484 | 484 | |
| 485 | 485 | // Ensure that we have an array. |
| 486 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 486 | + if (!is_array($excluded_posts_ids)) { |
|
| 487 | 487 | $excluded_posts_ids = array(); |
| 488 | 488 | } |
| 489 | 489 | |
@@ -491,24 +491,24 @@ discard block |
||
| 491 | 491 | $our_pages = array(); |
| 492 | 492 | |
| 493 | 493 | // Checkout page. |
| 494 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 494 | + $our_pages[] = wpinv_get_option('checkout_page', false); |
|
| 495 | 495 | |
| 496 | 496 | // Success page. |
| 497 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 497 | + $our_pages[] = wpinv_get_option('success_page', false); |
|
| 498 | 498 | |
| 499 | 499 | // Failure page. |
| 500 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 500 | + $our_pages[] = wpinv_get_option('failure_page', false); |
|
| 501 | 501 | |
| 502 | 502 | // History page. |
| 503 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 503 | + $our_pages[] = wpinv_get_option('invoice_history_page', false); |
|
| 504 | 504 | |
| 505 | 505 | // Subscriptions page. |
| 506 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 506 | + $our_pages[] = wpinv_get_option('invoice_subscription_page', false); |
|
| 507 | 507 | |
| 508 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 508 | + $our_pages = array_map('intval', array_filter($our_pages)); |
|
| 509 | 509 | |
| 510 | 510 | $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
| 511 | - return array_unique( $excluded_posts_ids ); |
|
| 511 | + return array_unique($excluded_posts_ids); |
|
| 512 | 512 | |
| 513 | 513 | } |
| 514 | 514 | |
@@ -7,24 +7,24 @@ discard block |
||
| 7 | 7 | * @version 1.0.19 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -defined( 'ABSPATH' ) || exit; |
|
| 10 | +defined('ABSPATH') || exit; |
|
| 11 | 11 | |
| 12 | -$bg = wpinv_get_option( 'email_background_color', '#f5f5f5' ); |
|
| 13 | -$body = wpinv_get_option( 'email_body_background_color', '#fdfdfd' ); |
|
| 14 | -$base = wpinv_get_option( 'email_base_color', '#557da2' ); |
|
| 15 | -$base_text = wpinv_light_or_dark( $base, '#202020', '#ffffff' ); |
|
| 16 | -$text = wpinv_get_option( 'email_text_color', '#505050' ); |
|
| 12 | +$bg = wpinv_get_option('email_background_color', '#f5f5f5'); |
|
| 13 | +$body = wpinv_get_option('email_body_background_color', '#fdfdfd'); |
|
| 14 | +$base = wpinv_get_option('email_base_color', '#557da2'); |
|
| 15 | +$base_text = wpinv_light_or_dark($base, '#202020', '#ffffff'); |
|
| 16 | +$text = wpinv_get_option('email_text_color', '#505050'); |
|
| 17 | 17 | |
| 18 | -$bg_darker_10 = wpinv_hex_darker( $bg, 10 ); |
|
| 19 | -$body_darker_10 = wpinv_hex_darker( $body, 10 ); |
|
| 20 | -$base_lighter_20 = wpinv_hex_lighter( $base, 20 ); |
|
| 21 | -$base_lighter_40 = wpinv_hex_lighter( $base, 40 ); |
|
| 22 | -$text_lighter_20 = wpinv_hex_lighter( $text, 20 ); |
|
| 18 | +$bg_darker_10 = wpinv_hex_darker($bg, 10); |
|
| 19 | +$body_darker_10 = wpinv_hex_darker($body, 10); |
|
| 20 | +$base_lighter_20 = wpinv_hex_lighter($base, 20); |
|
| 21 | +$base_lighter_40 = wpinv_hex_lighter($base, 40); |
|
| 22 | +$text_lighter_20 = wpinv_hex_lighter($text, 20); |
|
| 23 | 23 | |
| 24 | 24 | // !important; is a gmail hack to prevent styles being stripped if it doesn't like something. |
| 25 | 25 | ?> |
| 26 | 26 | #wrapper { |
| 27 | - background-color: <?php echo esc_attr( $bg ); ?>; |
|
| 27 | + background-color: <?php echo esc_attr($bg); ?>; |
|
| 28 | 28 | margin: 0; |
| 29 | 29 | -webkit-text-size-adjust: none !important; |
| 30 | 30 | padding: 3%; |
@@ -45,15 +45,15 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | #template_container { |
| 47 | 47 | box-shadow: 0 1px 4px rgba(0,0,0,0.1) !important; |
| 48 | - background-color: <?php echo esc_attr( $body ); ?>; |
|
| 49 | - border: 1px solid <?php echo esc_attr( $bg_darker_10 ); ?>; |
|
| 48 | + background-color: <?php echo esc_attr($body); ?>; |
|
| 49 | + border: 1px solid <?php echo esc_attr($bg_darker_10); ?>; |
|
| 50 | 50 | border-radius: 3px !important; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | #template_header { |
| 54 | - background-color: <?php echo esc_attr( $base ); ?>; |
|
| 54 | + background-color: <?php echo esc_attr($base); ?>; |
|
| 55 | 55 | border-radius: 3px 3px 0 0 !important; |
| 56 | - color: <?php echo esc_attr( $base_text ); ?>; |
|
| 56 | + color: <?php echo esc_attr($base_text); ?>; |
|
| 57 | 57 | border-bottom: 0; |
| 58 | 58 | font-weight: bold; |
| 59 | 59 | line-height: 100%; |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | #template_header h1 { |
| 69 | - color: <?php echo esc_attr( $base_text ); ?>; |
|
| 69 | + color: <?php echo esc_attr($base_text); ?>; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | #template_footer td { |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | |
| 78 | 78 | #template_footer #credit { |
| 79 | 79 | border:0; |
| 80 | - color: <?php echo esc_attr( $base_lighter_40 ); ?>; |
|
| 80 | + color: <?php echo esc_attr($base_lighter_40); ?>; |
|
| 81 | 81 | font-family: Arial; |
| 82 | 82 | font-size:12px; |
| 83 | 83 | line-height:125%; |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | #body_content { |
| 89 | - background-color: <?php echo esc_attr( $body ); ?>; |
|
| 89 | + background-color: <?php echo esc_attr($body); ?>; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | #body_content table td { |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | #body_content_inner { |
| 109 | - color: <?php echo esc_attr( $text_lighter_20 ); ?>; |
|
| 109 | + color: <?php echo esc_attr($text_lighter_20); ?>; |
|
| 110 | 110 | font-family: Arial,Helvetica,sans-serif; |
| 111 | 111 | font-size: 14px; |
| 112 | 112 | line-height: 150%; |
@@ -114,17 +114,17 @@ discard block |
||
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | .td { |
| 117 | - color: <?php echo esc_attr( $text_lighter_20 ); ?>; |
|
| 118 | - border: 1px solid <?php echo esc_attr( $body_darker_10 ); ?>; |
|
| 117 | + color: <?php echo esc_attr($text_lighter_20); ?>; |
|
| 118 | + border: 1px solid <?php echo esc_attr($body_darker_10); ?>; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | .text { |
| 122 | - color: <?php echo esc_attr( $text ); ?>; |
|
| 122 | + color: <?php echo esc_attr($text); ?>; |
|
| 123 | 123 | font-family: Arial,Helvetica,sans-serif; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | .link { |
| 127 | - color: <?php echo esc_attr( $base ); ?>; |
|
| 127 | + color: <?php echo esc_attr($base); ?>; |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | #header_wrapper { |
@@ -133,19 +133,19 @@ discard block |
||
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | h1 { |
| 136 | - color: <?php echo esc_attr( $base ); ?>; |
|
| 136 | + color: <?php echo esc_attr($base); ?>; |
|
| 137 | 137 | font-family: Arial,Helvetica,sans-serif; |
| 138 | 138 | font-size: 30px; |
| 139 | 139 | font-weight: 300; |
| 140 | 140 | line-height: 150%; |
| 141 | 141 | margin: 0; |
| 142 | 142 | text-align: <?php echo is_rtl() ? 'right' : 'left'; ?>; |
| 143 | - text-shadow: 0 1px 0 <?php echo esc_attr( $base_lighter_20 ); ?>; |
|
| 143 | + text-shadow: 0 1px 0 <?php echo esc_attr($base_lighter_20); ?>; |
|
| 144 | 144 | -webkit-font-smoothing: antialiased; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | h2 { |
| 148 | - color: <?php echo esc_attr( $base ); ?>; |
|
| 148 | + color: <?php echo esc_attr($base); ?>; |
|
| 149 | 149 | display: block; |
| 150 | 150 | font-family: Arial,Helvetica,sans-serif; |
| 151 | 151 | font-size: 18px; |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | h3 { |
| 159 | - color: <?php echo esc_attr( $base ); ?>; |
|
| 159 | + color: <?php echo esc_attr($base); ?>; |
|
| 160 | 160 | display: block; |
| 161 | 161 | font-family: Arial,Helvetica,sans-serif; |
| 162 | 162 | font-size: 16px; |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | a { |
| 170 | - color: <?php echo esc_attr( $base ); ?>; |
|
| 170 | + color: <?php echo esc_attr($base); ?>; |
|
| 171 | 171 | font-weight: normal; |
| 172 | 172 | text-decoration: underline; |
| 173 | 173 | } |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | .table-bordered { |
| 188 | - border: 1px solid <?php echo esc_attr( $body_darker_10 ); ?>; |
|
| 188 | + border: 1px solid <?php echo esc_attr($body_darker_10); ?>; |
|
| 189 | 189 | border-collapse: collapse; |
| 190 | 190 | border-spacing: 0; |
| 191 | 191 | width: 100%; |
@@ -193,8 +193,8 @@ discard block |
||
| 193 | 193 | |
| 194 | 194 | .table-bordered th, |
| 195 | 195 | .table-bordered td { |
| 196 | - border: 1px solid <?php echo esc_attr( $body_darker_10 ); ?>; |
|
| 197 | - color: <?php echo esc_attr( $text_lighter_20 ); ?>; |
|
| 196 | + border: 1px solid <?php echo esc_attr($body_darker_10); ?>; |
|
| 197 | + color: <?php echo esc_attr($text_lighter_20); ?>; |
|
| 198 | 198 | font-size: 14px; |
| 199 | 199 | } |
| 200 | 200 | .small { |
@@ -294,9 +294,9 @@ discard block |
||
| 294 | 294 | text-decoration: none; |
| 295 | 295 | } |
| 296 | 296 | .btn-default { |
| 297 | - color: <?php echo esc_attr( $base_text ); ?>; |
|
| 298 | - background-color: <?php echo esc_attr( $base ); ?>; |
|
| 299 | - border-color: <?php echo esc_attr( $base ); ?>; |
|
| 297 | + color: <?php echo esc_attr($base_text); ?>; |
|
| 298 | + background-color: <?php echo esc_attr($base); ?>; |
|
| 299 | + border-color: <?php echo esc_attr($base); ?>; |
|
| 300 | 300 | } |
| 301 | 301 | .btn-primary { |
| 302 | 302 | color: #fff; |
@@ -7,19 +7,19 @@ |
||
| 7 | 7 | * @version 1.0.19 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -defined( 'ABSPATH' ) || exit; |
|
| 10 | +defined('ABSPATH') || exit; |
|
| 11 | 11 | |
| 12 | 12 | // Print the email header. |
| 13 | -do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin ); |
|
| 13 | +do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin); |
|
| 14 | 14 | |
| 15 | 15 | // Generate the custom message body. |
| 16 | 16 | echo $message_body; |
| 17 | 17 | |
| 18 | 18 | // Print invoice details. |
| 19 | -do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin ); |
|
| 19 | +do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin); |
|
| 20 | 20 | |
| 21 | 21 | // Print the billing details. |
| 22 | -do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin ); |
|
| 22 | +do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin); |
|
| 23 | 23 | |
| 24 | 24 | // Print the email footer. |
| 25 | -do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin ); |
|
| 25 | +do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin); |
|
@@ -7,22 +7,22 @@ |
||
| 7 | 7 | * @version 1.0.19 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -defined( 'ABSPATH' ) || exit; |
|
| 10 | +defined('ABSPATH') || exit; |
|
| 11 | 11 | |
| 12 | 12 | // Print the email header. |
| 13 | -do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin ); |
|
| 13 | +do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin); |
|
| 14 | 14 | |
| 15 | 15 | // Generate the custom message body. |
| 16 | 16 | echo $message_body; |
| 17 | 17 | |
| 18 | 18 | // Print invoice details. |
| 19 | -do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin ); |
|
| 19 | +do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin); |
|
| 20 | 20 | |
| 21 | 21 | // Print invoice items. |
| 22 | -do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin ); |
|
| 22 | +do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin); |
|
| 23 | 23 | |
| 24 | 24 | // Print the billing details. |
| 25 | -do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin ); |
|
| 25 | +do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin); |
|
| 26 | 26 | |
| 27 | 27 | // Print the email footer. |
| 28 | -do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin ); |
|
| 28 | +do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin); |
|
@@ -8,45 +8,45 @@ discard block |
||
| 8 | 8 | * @var WPInv_Invoice $invoice |
| 9 | 9 | * @var array $columns |
| 10 | 10 | */ |
| 11 | -defined( 'ABSPATH' ) || exit; |
|
| 11 | +defined('ABSPATH') || exit; |
|
| 12 | 12 | |
| 13 | -$meta_data = getpaid_get_invoice_meta( $invoice ); |
|
| 13 | +$meta_data = getpaid_get_invoice_meta($invoice); |
|
| 14 | 14 | |
| 15 | -if ( isset( $meta_data['status'] ) ) { |
|
| 15 | +if (isset($meta_data['status'])) { |
|
| 16 | 16 | $meta_data['status']['value'] = $invoice->get_status_nicename(); |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | -do_action( 'wpinv_email_before_invoice_details', $invoice, $sent_to_admin ); |
|
| 19 | +do_action('wpinv_email_before_invoice_details', $invoice, $sent_to_admin); |
|
| 20 | 20 | |
| 21 | 21 | ?> |
| 22 | 22 | |
| 23 | 23 | <div id="wpinv-email-details"> |
| 24 | 24 | |
| 25 | 25 | <h3 class="invoice-details-title"> |
| 26 | - <?php echo sprintf( esc_html__( '%s Details', 'invoicing' ), ucfirst( $invoice->get_type() )); ?> |
|
| 26 | + <?php echo sprintf(esc_html__('%s Details', 'invoicing'), ucfirst($invoice->get_type())); ?> |
|
| 27 | 27 | </h3> |
| 28 | 28 | |
| 29 | 29 | <table class="table table-bordered table-sm"> |
| 30 | 30 | |
| 31 | - <?php foreach ( $meta_data as $key => $data ) : ?> |
|
| 31 | + <?php foreach ($meta_data as $key => $data) : ?> |
|
| 32 | 32 | |
| 33 | - <?php if ( ! empty( $data['value'] ) ) : ?> |
|
| 33 | + <?php if (!empty($data['value'])) : ?> |
|
| 34 | 34 | |
| 35 | - <?php do_action( "getpaid_before_email_details_$key", $invoice, $data ); ?> |
|
| 35 | + <?php do_action("getpaid_before_email_details_$key", $invoice, $data); ?> |
|
| 36 | 36 | |
| 37 | - <tr class="getpaid-email-details-<?php echo sanitize_html_class( $key ); ?>"> |
|
| 37 | + <tr class="getpaid-email-details-<?php echo sanitize_html_class($key); ?>"> |
|
| 38 | 38 | |
| 39 | 39 | <td class="getpaid-lable-td"> |
| 40 | - <?php echo sanitize_text_field( $data['label'] ); ?> |
|
| 40 | + <?php echo sanitize_text_field($data['label']); ?> |
|
| 41 | 41 | </td> |
| 42 | 42 | |
| 43 | 43 | <td class="getpaid-value-td"> |
| 44 | - <span class="getpaid-invoice-meta-<?php echo sanitize_html_class( $key ); ?>-value"><?php echo wp_kses_post( $data['value'] ); ?></span> |
|
| 44 | + <span class="getpaid-invoice-meta-<?php echo sanitize_html_class($key); ?>-value"><?php echo wp_kses_post($data['value']); ?></span> |
|
| 45 | 45 | </td> |
| 46 | 46 | |
| 47 | 47 | </tr> |
| 48 | 48 | |
| 49 | - <?php do_action( "getpaid_after_email_details_$key", $invoice, $data ); ?> |
|
| 49 | + <?php do_action("getpaid_after_email_details_$key", $invoice, $data); ?> |
|
| 50 | 50 | |
| 51 | 51 | <?php endif; ?> |
| 52 | 52 | |
@@ -56,4 +56,4 @@ discard block |
||
| 56 | 56 | |
| 57 | 57 | </div> |
| 58 | 58 | |
| 59 | -<?php do_action( 'wpinv_email_after_invoice_details', $invoice, $sent_to_admin ); ?> |
|
| 59 | +<?php do_action('wpinv_email_after_invoice_details', $invoice, $sent_to_admin); ?> |
|