@@ -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,37 +17,37 @@ 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 | - $page = (int) $page; |
|
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' ), |
|
45 | + 'group_label' => __('Invoicing Data', 'invoicing'), |
|
46 | 46 | 'item_id' => "wpinv-{$invoice->ID}", |
47 | - 'data' => self::get_customer_invoice_data( $invoice ), |
|
47 | + 'data' => self::get_customer_invoice_data($invoice), |
|
48 | 48 | ); |
49 | 49 | } |
50 | - $done = 30 > count( $invoices ); |
|
50 | + $done = 30 > count($invoices); |
|
51 | 51 | } else { |
52 | 52 | $done = true; |
53 | 53 | } |
@@ -65,59 +65,59 @@ discard block |
||
65 | 65 | * @param WPInv_Invoice $invoice invoice object. |
66 | 66 | * @return array |
67 | 67 | */ |
68 | - public static function get_customer_invoice_data( $invoice ) { |
|
68 | + public static function get_customer_invoice_data($invoice) { |
|
69 | 69 | $personal_data = array(); |
70 | 70 | |
71 | 71 | $props_to_export = array( |
72 | - 'number' => __( 'Invoice Number', 'invoicing' ), |
|
73 | - 'created_date' => __( 'Invoice Date', 'invoicing' ), |
|
74 | - 'status' => __( 'Invoice Status', 'invoicing' ), |
|
75 | - 'total' => __( 'Invoice Total', 'invoicing' ), |
|
76 | - 'items' => __( 'Invoice Items', 'invoicing' ), |
|
77 | - 'first_name' => __( 'First Name', 'invoicing' ), |
|
78 | - 'last_name' => __( 'Last Name', 'invoicing' ), |
|
79 | - 'email' => __( 'Email Address', 'invoicing' ), |
|
80 | - '_wpinv_company' => __( 'Company', 'invoicing' ), |
|
81 | - 'phone' => __( 'Phone Number', 'invoicing' ), |
|
82 | - 'address' => __( 'Address', 'invoicing' ), |
|
83 | - '_wpinv_city' => __( 'City', 'invoicing' ), |
|
84 | - '_wpinv_country' => __( 'Country', 'invoicing' ), |
|
85 | - '_wpinv_state' => __( 'State', 'invoicing' ), |
|
86 | - '_wpinv_zip' => __( 'Zip Code', 'invoicing' ), |
|
72 | + 'number' => __('Invoice Number', 'invoicing'), |
|
73 | + 'created_date' => __('Invoice Date', 'invoicing'), |
|
74 | + 'status' => __('Invoice Status', 'invoicing'), |
|
75 | + 'total' => __('Invoice Total', 'invoicing'), |
|
76 | + 'items' => __('Invoice Items', 'invoicing'), |
|
77 | + 'first_name' => __('First Name', 'invoicing'), |
|
78 | + 'last_name' => __('Last Name', 'invoicing'), |
|
79 | + 'email' => __('Email Address', 'invoicing'), |
|
80 | + '_wpinv_company' => __('Company', 'invoicing'), |
|
81 | + 'phone' => __('Phone Number', 'invoicing'), |
|
82 | + 'address' => __('Address', 'invoicing'), |
|
83 | + '_wpinv_city' => __('City', 'invoicing'), |
|
84 | + '_wpinv_country' => __('Country', 'invoicing'), |
|
85 | + '_wpinv_state' => __('State', 'invoicing'), |
|
86 | + '_wpinv_zip' => __('Zip Code', 'invoicing'), |
|
87 | 87 | ); |
88 | 88 | |
89 | - $subscription = wpinv_get_subscription( $invoice ); |
|
89 | + $subscription = wpinv_get_subscription($invoice); |
|
90 | 90 | $period = $initial_amt = $bill_times = $billed = $renewal_date = ''; |
91 | 91 | |
92 | - if ( $invoice->is_recurring() && !empty( $subscription ) ) { |
|
93 | - $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->period,$subscription->frequency ); |
|
94 | - $period = wpinv_price( wpinv_format_amount( $subscription->recurring_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) ) . ' / ' . $frequency; |
|
95 | - $initial_amt = wpinv_price( wpinv_format_amount( $subscription->initial_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) ); |
|
96 | - $bill_times = $subscription->get_times_billed() . ' / ' . ( ( $subscription->bill_times == 0 ) ? 'Until Cancelled' : $subscription->bill_times ); |
|
97 | - $renewal_date = ! empty( $subscription->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $subscription->expiration ) ) : __( 'N/A', 'invoicing' ); |
|
98 | - |
|
99 | - $props_to_export['period'] = __( 'Billing Cycle', 'invoicing' ); |
|
100 | - $props_to_export['initial_amount'] = __( 'Initial Amount', 'invoicing' ); |
|
101 | - $props_to_export['bill_times'] = __( 'Times Billed', 'invoicing' ); |
|
102 | - $props_to_export['renewal_date'] = __( 'Renewal Date', 'invoicing' ); |
|
92 | + if ($invoice->is_recurring() && !empty($subscription)) { |
|
93 | + $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($subscription->period, $subscription->frequency); |
|
94 | + $period = wpinv_price(wpinv_format_amount($subscription->recurring_amount), wpinv_get_invoice_currency_code($subscription->parent_payment_id)) . ' / ' . $frequency; |
|
95 | + $initial_amt = wpinv_price(wpinv_format_amount($subscription->initial_amount), wpinv_get_invoice_currency_code($subscription->parent_payment_id)); |
|
96 | + $bill_times = $subscription->get_times_billed() . ' / ' . (($subscription->bill_times == 0) ? 'Until Cancelled' : $subscription->bill_times); |
|
97 | + $renewal_date = !empty($subscription->expiration) ? date_i18n(get_option('date_format'), strtotime($subscription->expiration)) : __('N/A', 'invoicing'); |
|
98 | + |
|
99 | + $props_to_export['period'] = __('Billing Cycle', 'invoicing'); |
|
100 | + $props_to_export['initial_amount'] = __('Initial Amount', 'invoicing'); |
|
101 | + $props_to_export['bill_times'] = __('Times Billed', 'invoicing'); |
|
102 | + $props_to_export['renewal_date'] = __('Renewal Date', 'invoicing'); |
|
103 | 103 | } |
104 | 104 | |
105 | - $props_to_export['ip'] = __( 'IP Address', 'invoicing' ); |
|
106 | - $props_to_export['view_url'] = __( 'Invoice Link', 'invoicing' ); |
|
105 | + $props_to_export['ip'] = __('IP Address', 'invoicing'); |
|
106 | + $props_to_export['view_url'] = __('Invoice Link', 'invoicing'); |
|
107 | 107 | |
108 | - $props_to_export = apply_filters( 'wpinv_privacy_export_invoice_personal_data_props', $props_to_export, $invoice, $subscription); |
|
108 | + $props_to_export = apply_filters('wpinv_privacy_export_invoice_personal_data_props', $props_to_export, $invoice, $subscription); |
|
109 | 109 | |
110 | - foreach ( $props_to_export as $prop => $name ) { |
|
110 | + foreach ($props_to_export as $prop => $name) { |
|
111 | 111 | $value = ''; |
112 | 112 | |
113 | - switch ( $prop ) { |
|
113 | + switch ($prop) { |
|
114 | 114 | case 'items': |
115 | 115 | $item_names = array(); |
116 | - foreach ( $invoice->get_cart_details() as $key => $cart_item ) { |
|
117 | - $item_quantity = $cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1; |
|
116 | + foreach ($invoice->get_cart_details() as $key => $cart_item) { |
|
117 | + $item_quantity = $cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1; |
|
118 | 118 | $item_names[] = $cart_item['name'] . ' x ' . $item_quantity; |
119 | 119 | } |
120 | - $value = implode( ', ', $item_names ); |
|
120 | + $value = implode(', ', $item_names); |
|
121 | 121 | break; |
122 | 122 | case 'status': |
123 | 123 | $value = $invoice->get_status(true); |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | $value = $renewal_date; |
139 | 139 | break; |
140 | 140 | default: |
141 | - if ( is_callable( array( $invoice, 'get_' . $prop ) ) ) { |
|
141 | + if (is_callable(array($invoice, 'get_' . $prop))) { |
|
142 | 142 | $value = $invoice->{"get_$prop"}(); |
143 | 143 | } else { |
144 | 144 | $value = $invoice->get_meta($prop); |
@@ -146,9 +146,9 @@ discard block |
||
146 | 146 | break; |
147 | 147 | } |
148 | 148 | |
149 | - $value = apply_filters( 'wpi_privacy_export_invoice_personal_data_prop', $value, $prop, $invoice ); |
|
149 | + $value = apply_filters('wpi_privacy_export_invoice_personal_data_prop', $value, $prop, $invoice); |
|
150 | 150 | |
151 | - if ( $value ) { |
|
151 | + if ($value) { |
|
152 | 152 | $personal_data[] = array( |
153 | 153 | 'name' => $name, |
154 | 154 | 'value' => $value, |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | |
158 | 158 | } |
159 | 159 | |
160 | - $personal_data = apply_filters( 'wpinv_privacy_export_invoice_personal_data', $personal_data, $invoice ); |
|
160 | + $personal_data = apply_filters('wpinv_privacy_export_invoice_personal_data', $personal_data, $invoice); |
|
161 | 161 | |
162 | 162 | return $personal_data; |
163 | 163 |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Abstract privacy class. |
4 | 4 | */ |
5 | 5 | |
6 | -defined( 'ABSPATH' ) || exit; |
|
6 | +defined('ABSPATH') || exit; |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * Abstract class that is intended to be extended by |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @param string $name Plugin identifier. |
40 | 40 | */ |
41 | - public function __construct( $name = '' ) { |
|
41 | + public function __construct($name = '') { |
|
42 | 42 | $this->name = $name; |
43 | 43 | $this->init(); |
44 | 44 | } |
@@ -47,22 +47,22 @@ discard block |
||
47 | 47 | * Hook in events. |
48 | 48 | */ |
49 | 49 | protected function init() { |
50 | - add_action( 'admin_init', array( $this, 'add_privacy_message' ) ); |
|
50 | + add_action('admin_init', array($this, 'add_privacy_message')); |
|
51 | 51 | // Register data exporters |
52 | - add_filter( 'wp_privacy_personal_data_exporters', array( $this, 'register_exporters' ), 10 ); |
|
52 | + add_filter('wp_privacy_personal_data_exporters', array($this, 'register_exporters'), 10); |
|
53 | 53 | // Register data erasers |
54 | - add_filter( 'wp_privacy_personal_data_erasers', array( $this, 'register_erasers' ) ); |
|
54 | + add_filter('wp_privacy_personal_data_erasers', array($this, 'register_erasers')); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | 58 | * Adds the privacy message on invoicing privacy page. |
59 | 59 | */ |
60 | 60 | public function add_privacy_message() { |
61 | - if ( function_exists( 'wp_add_privacy_policy_content' ) ) { |
|
61 | + if (function_exists('wp_add_privacy_policy_content')) { |
|
62 | 62 | $content = $this->get_privacy_message(); |
63 | 63 | |
64 | - if ( $content ) { |
|
65 | - wp_add_privacy_policy_content( $this->name, $this->get_privacy_message() ); |
|
64 | + if ($content) { |
|
65 | + wp_add_privacy_policy_content($this->name, $this->get_privacy_message()); |
|
66 | 66 | } |
67 | 67 | } |
68 | 68 | } |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | * @param array $exporters List of exporter callbacks. |
84 | 84 | * @return array |
85 | 85 | */ |
86 | - public function register_exporters( $exporters = array() ) { |
|
87 | - foreach ( $this->exporters as $id => $exporter ) { |
|
88 | - $exporters[ $id ] = $exporter; |
|
86 | + public function register_exporters($exporters = array()) { |
|
87 | + foreach ($this->exporters as $id => $exporter) { |
|
88 | + $exporters[$id] = $exporter; |
|
89 | 89 | } |
90 | 90 | return $exporters; |
91 | 91 | } |
@@ -96,9 +96,9 @@ discard block |
||
96 | 96 | * @param array $erasers List of eraser callbacks. |
97 | 97 | * @return array |
98 | 98 | */ |
99 | - public function register_erasers( $erasers = array() ) { |
|
100 | - foreach ( $this->erasers as $id => $eraser ) { |
|
101 | - $erasers[ $id ] = $eraser; |
|
99 | + public function register_erasers($erasers = array()) { |
|
100 | + foreach ($this->erasers as $id => $eraser) { |
|
101 | + $erasers[$id] = $eraser; |
|
102 | 102 | } |
103 | 103 | return $erasers; |
104 | 104 | } |
@@ -112,8 +112,8 @@ discard block |
||
112 | 112 | * |
113 | 113 | * @return array |
114 | 114 | */ |
115 | - public function add_exporter( $id, $name, $callback ) { |
|
116 | - $this->exporters[ $id ] = array( |
|
115 | + public function add_exporter($id, $name, $callback) { |
|
116 | + $this->exporters[$id] = array( |
|
117 | 117 | 'exporter_friendly_name' => $name, |
118 | 118 | 'callback' => $callback, |
119 | 119 | ); |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | * |
130 | 130 | * @return array |
131 | 131 | */ |
132 | - public function add_eraser( $id, $name, $callback ) { |
|
133 | - $this->erasers[ $id ] = array( |
|
132 | + public function add_eraser($id, $name, $callback) { |
|
133 | + $this->erasers[$id] = array( |
|
134 | 134 | 'eraser_friendly_name' => $name, |
135 | 135 | 'callback' => $callback, |
136 | 136 | ); |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Privacy/GDPR related functionality which ties into WordPress functionality. |
4 | 4 | */ |
5 | 5 | |
6 | -defined( 'ABSPATH' ) || exit; |
|
6 | +defined('ABSPATH') || exit; |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * WPInv_Privacy Class. |
@@ -14,13 +14,13 @@ discard block |
||
14 | 14 | * Init - hook into events. |
15 | 15 | */ |
16 | 16 | public function __construct() { |
17 | - parent::__construct( __( 'Invoicing', 'invoicing' ) ); |
|
17 | + parent::__construct(__('Invoicing', 'invoicing')); |
|
18 | 18 | |
19 | 19 | // Include supporting classes. |
20 | 20 | include_once 'class-wpinv-privacy-exporters.php'; |
21 | 21 | |
22 | 22 | // This hook registers Invoicing data exporters. |
23 | - $this->add_exporter( 'wpinv-customer-invoices', __( 'Customer Invoices', 'invoicing' ), array( 'WPInv_Privacy_Exporters', 'customer_invoice_data_exporter' ) ); |
|
23 | + $this->add_exporter('wpinv-customer-invoices', __('Customer Invoices', 'invoicing'), array('WPInv_Privacy_Exporters', 'customer_invoice_data_exporter')); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -30,28 +30,28 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function get_privacy_message() { |
32 | 32 | |
33 | - $content = '<h2>' . __( 'Invoices and checkout', 'invoicing' ) . '</h2>' . |
|
33 | + $content = '<h2>' . __('Invoices and checkout', 'invoicing') . '</h2>' . |
|
34 | 34 | '<div contenteditable="false">' . |
35 | - '<p class="wp-policy-help">' . __( 'Example privacy texts.', 'invoicing' ) . '</p>' . |
|
35 | + '<p class="wp-policy-help">' . __('Example privacy texts.', 'invoicing') . '</p>' . |
|
36 | 36 | '</div>' . |
37 | - '<p>' . __( 'We collect information about you during the checkout process on our site. This information may include, but is not limited to, your name, email address, phone number, address, IP and any other details that might be requested from you for the purpose of processing your payment and retaining your invoice details for legal reasons.', 'invoicing' ) . '</p>' . |
|
38 | - '<p>' . __( 'Handling this data also allows us to:', 'invoicing' ) . '</p>' . |
|
37 | + '<p>' . __('We collect information about you during the checkout process on our site. This information may include, but is not limited to, your name, email address, phone number, address, IP and any other details that might be requested from you for the purpose of processing your payment and retaining your invoice details for legal reasons.', 'invoicing') . '</p>' . |
|
38 | + '<p>' . __('Handling this data also allows us to:', 'invoicing') . '</p>' . |
|
39 | 39 | '<ul>' . |
40 | - '<li>' . __( '- Send you important account/order/service information.', 'invoicing' ) . '</li>' . |
|
41 | - '<li>' . __( '- Estimate taxes based on your location.', 'invoicing' ) . '</li>' . |
|
42 | - '<li>' . __( '- Respond to your queries or complaints.', 'invoicing' ) . '</li>' . |
|
43 | - '<li>' . __( '- Process payments and to prevent fraudulent transactions. We do this on the basis of our legitimate business interests.', 'invoicing' ) . '</li>' . |
|
44 | - '<li>' . __( '- Retain historical payment and invoice history. We do this on the basis of legal obligations.', 'invoicing' ) . '</li>' . |
|
45 | - '<li>' . __( '- Set up and administer your account, provide technical and/or customer support, and to verify your identity. We do this on the basis of our legitimate business interests.', 'invoicing' ) . '</li>' . |
|
40 | + '<li>' . __('- Send you important account/order/service information.', 'invoicing') . '</li>' . |
|
41 | + '<li>' . __('- Estimate taxes based on your location.', 'invoicing') . '</li>' . |
|
42 | + '<li>' . __('- Respond to your queries or complaints.', 'invoicing') . '</li>' . |
|
43 | + '<li>' . __('- Process payments and to prevent fraudulent transactions. We do this on the basis of our legitimate business interests.', 'invoicing') . '</li>' . |
|
44 | + '<li>' . __('- Retain historical payment and invoice history. We do this on the basis of legal obligations.', 'invoicing') . '</li>' . |
|
45 | + '<li>' . __('- Set up and administer your account, provide technical and/or customer support, and to verify your identity. We do this on the basis of our legitimate business interests.', 'invoicing') . '</li>' . |
|
46 | 46 | '</ul>' . |
47 | - '<p>' . __( 'In addition to collecting information at checkout we may also use and store your contact details when manually creating invoices for require payments relating to prior contractual agreements or agreed terms.', 'invoicing' ) . '</p>' . |
|
48 | - '<h2>' . __( 'What we share with others', 'invoicing' ) . '</h2>' . |
|
49 | - '<p>' . __( 'We share information with third parties who help us provide our payment and invoicing services to you; for example --', 'invoicing' ) . '</p>' . |
|
47 | + '<p>' . __('In addition to collecting information at checkout we may also use and store your contact details when manually creating invoices for require payments relating to prior contractual agreements or agreed terms.', 'invoicing') . '</p>' . |
|
48 | + '<h2>' . __('What we share with others', 'invoicing') . '</h2>' . |
|
49 | + '<p>' . __('We share information with third parties who help us provide our payment and invoicing services to you; for example --', 'invoicing') . '</p>' . |
|
50 | 50 | '<div contenteditable="false">' . |
51 | - '<p class="wp-policy-help">' . __( 'In this subsection you should list which third party payment processors you’re using to take payments since these may handle customer data. We’ve included PayPal as an example, but you should remove this if you’re not using PayPal.', 'invoicing' ) . '</p>' . |
|
51 | + '<p class="wp-policy-help">' . __('In this subsection you should list which third party payment processors you’re using to take payments since these may handle customer data. We’ve included PayPal as an example, but you should remove this if you’re not using PayPal.', 'invoicing') . '</p>' . |
|
52 | 52 | '</div>' . |
53 | - '<p>' . __( 'We accept payments through PayPal. When processing payments, some of your data will be passed to PayPal, including information required to process or support the payment, such as the purchase total and billing information.', 'invoicing' ) . '</p>' . |
|
54 | - '<p>' . __( 'Please see the <a href="https://www.paypal.com/us/webapps/mpp/ua/privacy-full">PayPal Privacy Policy</a> for more details.', 'invoicing' ) . '</p>'; |
|
53 | + '<p>' . __('We accept payments through PayPal. When processing payments, some of your data will be passed to PayPal, including information required to process or support the payment, such as the purchase total and billing information.', 'invoicing') . '</p>' . |
|
54 | + '<p>' . __('Please see the <a href="https://www.paypal.com/us/webapps/mpp/ua/privacy-full">PayPal Privacy Policy</a> for more details.', 'invoicing') . '</p>'; |
|
55 | 55 | |
56 | 56 | |
57 | 57 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | // '</p>' . |
63 | 63 | // '</div>'; |
64 | 64 | |
65 | - return apply_filters( 'wpinv_privacy_policy_content', $content ); |
|
65 | + return apply_filters('wpinv_privacy_policy_content', $content); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; // Exit if accessed directly |
4 | 4 | } |
5 | 5 | |
@@ -14,74 +14,74 @@ discard block |
||
14 | 14 | } |
15 | 15 | |
16 | 16 | public function init() { |
17 | - do_action( 'wpinv_class_notes_init', $this ); |
|
17 | + do_action('wpinv_class_notes_init', $this); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | public function includes() { |
21 | - do_action( 'wpinv_class_notes_includes', $this ); |
|
21 | + do_action('wpinv_class_notes_includes', $this); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | public function actions() { |
25 | 25 | // Secure inovice notes |
26 | - add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 ); |
|
27 | - add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 ); |
|
26 | + add_action('pre_get_comments', array($this, 'set_invoice_note_type'), 11, 1); |
|
27 | + add_action('comment_feed_where', array($this, 'wpinv_comment_feed_where'), 10, 1); |
|
28 | 28 | |
29 | 29 | // Count comments |
30 | - add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 11, 2 ); |
|
30 | + add_filter('wp_count_comments', array($this, 'wp_count_comments'), 11, 2); |
|
31 | 31 | |
32 | 32 | // Delete comments count cache whenever there is a new comment or a comment status changes |
33 | - add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) ); |
|
34 | - add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) ); |
|
33 | + add_action('wp_insert_comment', array($this, 'delete_comments_count_cache')); |
|
34 | + add_action('wp_set_comment_status', array($this, 'delete_comments_count_cache')); |
|
35 | 35 | |
36 | - do_action( 'wpinv_class_notes_actions', $this ); |
|
36 | + do_action('wpinv_class_notes_actions', $this); |
|
37 | 37 | } |
38 | 38 | |
39 | - public function set_invoice_note_type( $query ) { |
|
40 | - $post_ID = !empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
39 | + public function set_invoice_note_type($query) { |
|
40 | + $post_ID = !empty($query->query_vars['post_ID']) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
41 | 41 | |
42 | - if ( $post_ID && in_array(get_post_type( $post_ID ), array($this->invoice_post_type, 'wpi_quote' )) ) { |
|
42 | + if ($post_ID && in_array(get_post_type($post_ID), array($this->invoice_post_type, 'wpi_quote'))) { |
|
43 | 43 | $query->query_vars['type__in'] = $this->comment_type; |
44 | 44 | $query->query_vars['type__not_in'] = ''; |
45 | 45 | } else { |
46 | - if ( isset( $query->query_vars['type__in'] ) && $type_in = $query->query_vars['type__in'] ) { |
|
47 | - if ( is_array( $type_in ) && in_array( $this->comment_type, $type_in ) ) { |
|
48 | - $key = array_search( $this->comment_type, $type_in ); |
|
49 | - unset( $query->query_vars['type__in'][$key] ); |
|
50 | - } else if ( !is_array( $type_in ) && $type_in == $this->comment_type ) { |
|
46 | + if (isset($query->query_vars['type__in']) && $type_in = $query->query_vars['type__in']) { |
|
47 | + if (is_array($type_in) && in_array($this->comment_type, $type_in)) { |
|
48 | + $key = array_search($this->comment_type, $type_in); |
|
49 | + unset($query->query_vars['type__in'][$key]); |
|
50 | + } else if (!is_array($type_in) && $type_in == $this->comment_type) { |
|
51 | 51 | $query->query_vars['type__in'] = ''; |
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
55 | - if ( isset( $query->query_vars['type__not_in'] ) && $type_not_in = $query->query_vars['type__not_in'] ) { |
|
56 | - if ( is_array( $type_not_in ) && !in_array( $this->comment_type, $type_not_in ) ) { |
|
55 | + if (isset($query->query_vars['type__not_in']) && $type_not_in = $query->query_vars['type__not_in']) { |
|
56 | + if (is_array($type_not_in) && !in_array($this->comment_type, $type_not_in)) { |
|
57 | 57 | $query->query_vars['type__not_in'][] = $this->comment_type; |
58 | - } else if ( !is_array( $type_not_in ) && $type_not_in != $this->comment_type ) { |
|
58 | + } else if (!is_array($type_not_in) && $type_not_in != $this->comment_type) { |
|
59 | 59 | $query->query_vars['type__not_in'] = (array)$query->query_vars['type__not_in']; |
60 | 60 | $query->query_vars['type__not_in'][] = $this->comment_type; |
61 | 61 | } |
62 | 62 | } else { |
63 | - $query->query_vars['type__not_in'] = $this->comment_type; |
|
63 | + $query->query_vars['type__not_in'] = $this->comment_type; |
|
64 | 64 | } |
65 | 65 | } |
66 | 66 | |
67 | 67 | return $query; |
68 | 68 | } |
69 | 69 | |
70 | - public function get_invoice_notes( $invoice_id = 0, $type = '' ) { |
|
70 | + public function get_invoice_notes($invoice_id = 0, $type = '') { |
|
71 | 71 | $args = array( |
72 | 72 | 'post_id' => $invoice_id, |
73 | 73 | 'orderby' => 'comment_ID', |
74 | 74 | 'order' => 'ASC', |
75 | 75 | ); |
76 | 76 | |
77 | - if ( $type == 'customer' ) { |
|
77 | + if ($type == 'customer') { |
|
78 | 78 | $args['meta_key'] = '_wpi_customer_note'; |
79 | 79 | $args['meta_value'] = 1; |
80 | 80 | } |
81 | 81 | |
82 | - $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type ); |
|
82 | + $args = apply_filters('wpinv_invoice_notes_args', $args, $this, $invoice_id, $type); |
|
83 | 83 | |
84 | - return get_comments( $args ); |
|
84 | + return get_comments($args); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | * @return void |
93 | 93 | */ |
94 | 94 | public function delete_comments_count_cache() { |
95 | - delete_transient( 'wpinv_count_comments' ); |
|
95 | + delete_transient('wpinv_count_comments'); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -103,16 +103,16 @@ discard block |
||
103 | 103 | * @param int $post_id Post ID. |
104 | 104 | * @return object |
105 | 105 | */ |
106 | - public function wp_count_comments( $stats, $post_id ) { |
|
106 | + public function wp_count_comments($stats, $post_id) { |
|
107 | 107 | global $wpdb; |
108 | 108 | |
109 | - if ( 0 === $post_id ) { |
|
110 | - $stats = get_transient( 'wpinv_count_comments' ); |
|
109 | + if (0 === $post_id) { |
|
110 | + $stats = get_transient('wpinv_count_comments'); |
|
111 | 111 | |
112 | - if ( ! $stats ) { |
|
112 | + if (!$stats) { |
|
113 | 113 | $stats = array(); |
114 | 114 | |
115 | - $count = $wpdb->get_results( "SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('" . $this->comment_type . "') GROUP BY comment_approved", ARRAY_A ); |
|
115 | + $count = $wpdb->get_results("SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('" . $this->comment_type . "') GROUP BY comment_approved", ARRAY_A); |
|
116 | 116 | |
117 | 117 | $total = 0; |
118 | 118 | $approved = array( |
@@ -123,33 +123,33 @@ discard block |
||
123 | 123 | 'post-trashed' => 'post-trashed', |
124 | 124 | ); |
125 | 125 | |
126 | - foreach ( (array) $count as $row ) { |
|
126 | + foreach ((array)$count as $row) { |
|
127 | 127 | // Do not count post-trashed toward totals. |
128 | - if ( 'post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved'] ) { |
|
128 | + if ('post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved']) { |
|
129 | 129 | $total += $row['num_comments']; |
130 | 130 | } |
131 | - if ( isset( $approved[ $row['comment_approved'] ] ) ) { |
|
132 | - $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; |
|
131 | + if (isset($approved[$row['comment_approved']])) { |
|
132 | + $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | |
136 | 136 | $stats['total_comments'] = $total; |
137 | 137 | $stats['all'] = $total; |
138 | - foreach ( $approved as $key ) { |
|
139 | - if ( empty( $stats[ $key ] ) ) { |
|
140 | - $stats[ $key ] = 0; |
|
138 | + foreach ($approved as $key) { |
|
139 | + if (empty($stats[$key])) { |
|
140 | + $stats[$key] = 0; |
|
141 | 141 | } |
142 | 142 | } |
143 | 143 | |
144 | - $stats = (object) $stats; |
|
145 | - set_transient( 'wpinv_count_comments', $stats ); |
|
144 | + $stats = (object)$stats; |
|
145 | + set_transient('wpinv_count_comments', $stats); |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | |
149 | 149 | return $stats; |
150 | 150 | } |
151 | 151 | |
152 | - function wpinv_comment_feed_where($where){ |
|
153 | - return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' "; |
|
152 | + function wpinv_comment_feed_where($where) { |
|
153 | + return $where . ($where ? ' AND ' : '') . " comment_type != 'wpinv_note' "; |
|
154 | 154 | } |
155 | 155 | } |
@@ -11,49 +11,49 @@ discard block |
||
11 | 11 | * @since 1.0.0 |
12 | 12 | */ |
13 | 13 | function wpinv_automatic_upgrade() { |
14 | - $wpi_version = get_option( 'wpinv_version' ); |
|
14 | + $wpi_version = get_option('wpinv_version'); |
|
15 | 15 | |
16 | - if ( $wpi_version == WPINV_VERSION ) { |
|
16 | + if ($wpi_version == WPINV_VERSION) { |
|
17 | 17 | return; |
18 | 18 | } |
19 | 19 | |
20 | - if ( version_compare( $wpi_version, '0.0.5', '<' ) ) { |
|
20 | + if (version_compare($wpi_version, '0.0.5', '<')) { |
|
21 | 21 | wpinv_v005_upgrades(); |
22 | 22 | } |
23 | 23 | |
24 | - if ( version_compare( $wpi_version, '1.0.3', '<' ) ) { |
|
24 | + if (version_compare($wpi_version, '1.0.3', '<')) { |
|
25 | 25 | wpinv_v110_upgrades(); |
26 | 26 | } |
27 | 27 | |
28 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
28 | + update_option('wpinv_version', WPINV_VERSION); |
|
29 | 29 | } |
30 | -add_action( 'admin_init', 'wpinv_automatic_upgrade' ); |
|
30 | +add_action('admin_init', 'wpinv_automatic_upgrade'); |
|
31 | 31 | |
32 | 32 | function wpinv_v005_upgrades() { |
33 | 33 | global $wpdb; |
34 | 34 | |
35 | 35 | // Invoices status |
36 | - $results = $wpdb->get_results( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
37 | - if ( !empty( $results ) ) { |
|
38 | - $wpdb->query( "UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
36 | + $results = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )"); |
|
37 | + if (!empty($results)) { |
|
38 | + $wpdb->query("UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )"); |
|
39 | 39 | |
40 | 40 | // Clean post cache |
41 | - foreach ( $results as $row ) { |
|
42 | - clean_post_cache( $row->ID ); |
|
41 | + foreach ($results as $row) { |
|
42 | + clean_post_cache($row->ID); |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 | |
46 | 46 | // Item meta key changes |
47 | 47 | $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
48 | - $results = $wpdb->get_results( $query ); |
|
48 | + $results = $wpdb->get_results($query); |
|
49 | 49 | |
50 | - if ( !empty( $results ) ) { |
|
51 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
52 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
53 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
50 | + if (!empty($results)) { |
|
51 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )"); |
|
52 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'"); |
|
53 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'"); |
|
54 | 54 | |
55 | - foreach ( $results as $row ) { |
|
56 | - clean_post_cache( $row->post_id ); |
|
55 | + foreach ($results as $row) { |
|
56 | + clean_post_cache($row->post_id); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
@@ -74,79 +74,79 @@ discard block |
||
74 | 74 | function wpinv_convert_old_subscriptions() { |
75 | 75 | global $wpdb; |
76 | 76 | |
77 | - $query = "SELECT ". $wpdb->posts .".ID FROM ". $wpdb->posts ." INNER JOIN ". $wpdb->postmeta ." ON ( ". $wpdb->posts .".ID = ". $wpdb->postmeta .".post_id ) WHERE 1=1 AND ". $wpdb->postmeta .".meta_key = '_wpinv_subscr_status' AND (". $wpdb->postmeta .".meta_value = 'pending' OR ". $wpdb->postmeta .".meta_value = 'active' OR ". $wpdb->postmeta .".meta_value = 'cancelled' OR ". $wpdb->postmeta .".meta_value = 'completed' OR ". $wpdb->postmeta .".meta_value = 'expired' OR ". $wpdb->postmeta .".meta_value = 'trialling' OR ". $wpdb->postmeta .".meta_value = 'failing') AND ". $wpdb->posts .".post_type = 'wpi_invoice' GROUP BY ". $wpdb->posts .".ID ORDER BY ". $wpdb->posts .".ID ASC"; |
|
77 | + $query = "SELECT " . $wpdb->posts . ".ID FROM " . $wpdb->posts . " INNER JOIN " . $wpdb->postmeta . " ON ( " . $wpdb->posts . ".ID = " . $wpdb->postmeta . ".post_id ) WHERE 1=1 AND " . $wpdb->postmeta . ".meta_key = '_wpinv_subscr_status' AND (" . $wpdb->postmeta . ".meta_value = 'pending' OR " . $wpdb->postmeta . ".meta_value = 'active' OR " . $wpdb->postmeta . ".meta_value = 'cancelled' OR " . $wpdb->postmeta . ".meta_value = 'completed' OR " . $wpdb->postmeta . ".meta_value = 'expired' OR " . $wpdb->postmeta . ".meta_value = 'trialling' OR " . $wpdb->postmeta . ".meta_value = 'failing') AND " . $wpdb->posts . ".post_type = 'wpi_invoice' GROUP BY " . $wpdb->posts . ".ID ORDER BY " . $wpdb->posts . ".ID ASC"; |
|
78 | 78 | |
79 | - $results = $wpdb->get_results( $query ); |
|
79 | + $results = $wpdb->get_results($query); |
|
80 | 80 | |
81 | - if ( empty( $results ) ) { |
|
81 | + if (empty($results)) { |
|
82 | 82 | return; |
83 | 83 | } |
84 | 84 | |
85 | - foreach ( $results as $row ) { |
|
86 | - $invoice = new WPInv_Invoice( $row->ID ); |
|
85 | + foreach ($results as $row) { |
|
86 | + $invoice = new WPInv_Invoice($row->ID); |
|
87 | 87 | |
88 | - if ( empty( $invoice->ID ) ) { |
|
88 | + if (empty($invoice->ID)) { |
|
89 | 89 | continue; |
90 | 90 | } |
91 | 91 | |
92 | - if ( $invoice->has_status( 'wpi-renewal' ) ) { |
|
92 | + if ($invoice->has_status('wpi-renewal')) { |
|
93 | 93 | continue; |
94 | 94 | } |
95 | 95 | |
96 | - $item = $invoice->get_recurring( true ); |
|
96 | + $item = $invoice->get_recurring(true); |
|
97 | 97 | |
98 | - if ( empty( $item ) ) { |
|
98 | + if (empty($item)) { |
|
99 | 99 | continue; |
100 | 100 | } |
101 | 101 | |
102 | 102 | $is_free_trial = $invoice->is_free_trial(); |
103 | - $profile_id = get_post_meta( $invoice->ID, '_wpinv_subscr_profile_id', true ); |
|
104 | - $subscription_status = get_post_meta( $invoice->ID, '_wpinv_subscr_status', true ); |
|
103 | + $profile_id = get_post_meta($invoice->ID, '_wpinv_subscr_profile_id', true); |
|
104 | + $subscription_status = get_post_meta($invoice->ID, '_wpinv_subscr_status', true); |
|
105 | 105 | $transaction_id = $invoice->get_transaction_id(); |
106 | 106 | |
107 | 107 | // Last invoice |
108 | - $query = "SELECT ID, post_date FROM ". $wpdb->posts ." WHERE post_type = 'wpi_invoice' AND post_parent = '" . $invoice->ID . "' ORDER BY ID DESC LIMIT 1"; |
|
109 | - $last_payment = $wpdb->get_row( $query ); |
|
108 | + $query = "SELECT ID, post_date FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_parent = '" . $invoice->ID . "' ORDER BY ID DESC LIMIT 1"; |
|
109 | + $last_payment = $wpdb->get_row($query); |
|
110 | 110 | |
111 | - if ( !empty( $last_payment ) ) { |
|
112 | - $invoice_date = $last_payment->post_date; |
|
111 | + if (!empty($last_payment)) { |
|
112 | + $invoice_date = $last_payment->post_date; |
|
113 | 113 | |
114 | - $meta_profile_id = get_post_meta( $last_payment->ID, '_wpinv_subscr_profile_id', true ); |
|
115 | - $meta_transaction_id = get_post_meta( $last_payment->ID, '_wpinv_transaction_id', true ); |
|
114 | + $meta_profile_id = get_post_meta($last_payment->ID, '_wpinv_subscr_profile_id', true); |
|
115 | + $meta_transaction_id = get_post_meta($last_payment->ID, '_wpinv_transaction_id', true); |
|
116 | 116 | |
117 | - if ( !empty( $meta_profile_id ) ) { |
|
118 | - $profile_id = $meta_profile_id; |
|
117 | + if (!empty($meta_profile_id)) { |
|
118 | + $profile_id = $meta_profile_id; |
|
119 | 119 | } |
120 | 120 | |
121 | - if ( !empty( $meta_transaction_id ) ) { |
|
122 | - $transaction_id = $meta_transaction_id; |
|
121 | + if (!empty($meta_transaction_id)) { |
|
122 | + $transaction_id = $meta_transaction_id; |
|
123 | 123 | } |
124 | 124 | } else { |
125 | - $invoice_date = $invoice->get_invoice_date( false ); |
|
125 | + $invoice_date = $invoice->get_invoice_date(false); |
|
126 | 126 | } |
127 | 127 | |
128 | - $profile_id = empty( $profile_id ) ? $invoice->ID : $profile_id; |
|
129 | - $status = empty( $subscription_status ) ? 'pending' : $subscription_status; |
|
128 | + $profile_id = empty($profile_id) ? $invoice->ID : $profile_id; |
|
129 | + $status = empty($subscription_status) ? 'pending' : $subscription_status; |
|
130 | 130 | |
131 | - $period = $item->get_recurring_period( true ); |
|
131 | + $period = $item->get_recurring_period(true); |
|
132 | 132 | $interval = $item->get_recurring_interval(); |
133 | 133 | $bill_times = (int)$item->get_recurring_limit(); |
134 | 134 | $add_period = $interval . ' ' . $period; |
135 | 135 | $trial_period = ''; |
136 | 136 | |
137 | - if ( $invoice->is_free_trial() ) { |
|
138 | - $trial_period = $item->get_trial_period( true ); |
|
137 | + if ($invoice->is_free_trial()) { |
|
138 | + $trial_period = $item->get_trial_period(true); |
|
139 | 139 | $free_interval = $item->get_trial_interval(); |
140 | 140 | $trial_period = $free_interval . ' ' . $trial_period; |
141 | 141 | |
142 | - if ( empty( $last_payment ) ) { |
|
142 | + if (empty($last_payment)) { |
|
143 | 143 | $add_period = $trial_period; |
144 | 144 | } |
145 | 145 | } |
146 | 146 | |
147 | - $expiration = date_i18n( 'Y-m-d H:i:s', strtotime( '+' . $add_period . ' 23:59:59', strtotime( $invoice_date ) ) ); |
|
148 | - if ( strtotime( $expiration ) < strtotime( date_i18n( 'Y-m-d' ) ) ) { |
|
149 | - if ( $status == 'active' || $status == 'trialling' || $status == 'pending' ) { |
|
147 | + $expiration = date_i18n('Y-m-d H:i:s', strtotime('+' . $add_period . ' 23:59:59', strtotime($invoice_date))); |
|
148 | + if (strtotime($expiration) < strtotime(date_i18n('Y-m-d'))) { |
|
149 | + if ($status == 'active' || $status == 'trialling' || $status == 'pending') { |
|
150 | 150 | $status = 'expired'; |
151 | 151 | } |
152 | 152 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | 'frequency' => $interval, |
160 | 160 | 'period' => $period, |
161 | 161 | 'initial_amount' => $invoice->get_total(), |
162 | - 'recurring_amount' => $invoice->get_recurring_details( 'total' ), |
|
162 | + 'recurring_amount' => $invoice->get_recurring_details('total'), |
|
163 | 163 | 'bill_times' => $bill_times, |
164 | 164 | 'created' => $invoice_date, |
165 | 165 | 'expiration' => $expiration, |
@@ -169,14 +169,14 @@ discard block |
||
169 | 169 | ); |
170 | 170 | |
171 | 171 | $subs_db = new WPInv_Subscriptions_DB; |
172 | - $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice->ID, 'number' => 1 ) ); |
|
173 | - $subscription = reset( $subs ); |
|
172 | + $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice->ID, 'number' => 1)); |
|
173 | + $subscription = reset($subs); |
|
174 | 174 | |
175 | - if ( empty( $subscription ) || $subscription->id <= 0 ) { |
|
175 | + if (empty($subscription) || $subscription->id <= 0) { |
|
176 | 176 | $subscription = new WPInv_Subscription(); |
177 | - $new_sub = $subscription->create( $args ); |
|
177 | + $new_sub = $subscription->create($args); |
|
178 | 178 | |
179 | - if ( !empty( $bill_times ) && $new_sub->get_times_billed() >= $bill_times && ( 'active' == $new_sub->status || 'trialling' == $new_sub->status ) ) { |
|
179 | + if (!empty($bill_times) && $new_sub->get_times_billed() >= $bill_times && ('active' == $new_sub->status || 'trialling' == $new_sub->status)) { |
|
180 | 180 | $new_sub->complete(); // Mark completed if all times billed |
181 | 181 | } |
182 | 182 | } |
@@ -186,20 +186,20 @@ discard block |
||
186 | 186 | function wpinv_update_new_email_settings() { |
187 | 187 | global $wpinv_options; |
188 | 188 | |
189 | - $current_options = get_option( 'wpinv_settings', array() ); |
|
189 | + $current_options = get_option('wpinv_settings', array()); |
|
190 | 190 | $options = array( |
191 | - 'email_new_invoice_body' => __( '<p>Hi Admin,</p><p>You have received payment invoice from {name}.</p>', 'invoicing' ), |
|
192 | - 'email_cancelled_invoice_body' => __( '<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing' ), |
|
193 | - 'email_failed_invoice_body' => __( '<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing' ), |
|
194 | - 'email_onhold_invoice_body' => __( '<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing' ), |
|
195 | - 'email_processing_invoice_body' => __( '<p>Hi {name},</p><p>Your invoice has been received at {site_title} and is now being processed.</p>', 'invoicing' ), |
|
196 | - 'email_refunded_invoice_body' => __( '<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing' ), |
|
197 | - 'email_user_invoice_body' => __( '<p>Hi {name},</p><p>An invoice has been created for you on {site_title}. To view / pay for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ), |
|
198 | - 'email_user_note_body' => __( '<p>Hi {name},</p><p>Following note has been added to your {invoice_label}:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing' ), |
|
199 | - 'email_overdue_body' => __( '<p>Hi {full_name},</p><p>This is just a friendly reminder that your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To view / pay now for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ), |
|
191 | + 'email_new_invoice_body' => __('<p>Hi Admin,</p><p>You have received payment invoice from {name}.</p>', 'invoicing'), |
|
192 | + 'email_cancelled_invoice_body' => __('<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing'), |
|
193 | + 'email_failed_invoice_body' => __('<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing'), |
|
194 | + 'email_onhold_invoice_body' => __('<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing'), |
|
195 | + 'email_processing_invoice_body' => __('<p>Hi {name},</p><p>Your invoice has been received at {site_title} and is now being processed.</p>', 'invoicing'), |
|
196 | + 'email_refunded_invoice_body' => __('<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing'), |
|
197 | + 'email_user_invoice_body' => __('<p>Hi {name},</p><p>An invoice has been created for you on {site_title}. To view / pay for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing'), |
|
198 | + 'email_user_note_body' => __('<p>Hi {name},</p><p>Following note has been added to your {invoice_label}:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing'), |
|
199 | + 'email_overdue_body' => __('<p>Hi {full_name},</p><p>This is just a friendly reminder that your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To view / pay now for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing'), |
|
200 | 200 | ); |
201 | 201 | |
202 | - foreach ($options as $option => $value){ |
|
202 | + foreach ($options as $option => $value) { |
|
203 | 203 | if (!isset($current_options[$option])) { |
204 | 204 | $current_options[$option] = $value; |
205 | 205 | } |
@@ -207,5 +207,5 @@ discard block |
||
207 | 207 | |
208 | 208 | $wpinv_options = $current_options; |
209 | 209 | |
210 | - update_option( 'wpinv_settings', $current_options ); |
|
210 | + update_option('wpinv_settings', $current_options); |
|
211 | 211 | } |
212 | 212 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // Exit if accessed directly |
4 | -if ( ! defined( 'ABSPATH' ) ) { |
|
4 | +if (!defined('ABSPATH')) { |
|
5 | 5 | exit; |
6 | 6 | } |
7 | 7 | |
@@ -38,15 +38,15 @@ discard block |
||
38 | 38 | * @since 1.0.0 |
39 | 39 | * @return void |
40 | 40 | */ |
41 | - function __construct( $_id_or_object = 0, $_by_profile_id = false ) { |
|
41 | + function __construct($_id_or_object = 0, $_by_profile_id = false) { |
|
42 | 42 | |
43 | 43 | $this->subs_db = new WPInv_Subscriptions_DB; |
44 | 44 | |
45 | - if( $_by_profile_id ) { |
|
45 | + if ($_by_profile_id) { |
|
46 | 46 | |
47 | - $_sub = $this->subs_db->get_by( 'profile_id', $_id_or_object ); |
|
47 | + $_sub = $this->subs_db->get_by('profile_id', $_id_or_object); |
|
48 | 48 | |
49 | - if( empty( $_sub ) ) { |
|
49 | + if (empty($_sub)) { |
|
50 | 50 | return false; |
51 | 51 | } |
52 | 52 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | |
55 | 55 | } |
56 | 56 | |
57 | - return $this->setup_subscription( $_id_or_object ); |
|
57 | + return $this->setup_subscription($_id_or_object); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -63,34 +63,34 @@ discard block |
||
63 | 63 | * @since 1.0.0 |
64 | 64 | * @return void |
65 | 65 | */ |
66 | - private function setup_subscription( $id_or_object = 0 ) { |
|
66 | + private function setup_subscription($id_or_object = 0) { |
|
67 | 67 | |
68 | - if( empty( $id_or_object ) ) { |
|
68 | + if (empty($id_or_object)) { |
|
69 | 69 | return false; |
70 | 70 | } |
71 | 71 | |
72 | - if( is_numeric( $id_or_object ) ) { |
|
72 | + if (is_numeric($id_or_object)) { |
|
73 | 73 | |
74 | - $sub = $this->subs_db->get( $id_or_object ); |
|
74 | + $sub = $this->subs_db->get($id_or_object); |
|
75 | 75 | |
76 | - } elseif( is_object( $id_or_object ) ) { |
|
76 | + } elseif (is_object($id_or_object)) { |
|
77 | 77 | |
78 | 78 | $sub = $id_or_object; |
79 | 79 | |
80 | 80 | } |
81 | 81 | |
82 | - if( empty( $sub ) ) { |
|
82 | + if (empty($sub)) { |
|
83 | 83 | return false; |
84 | 84 | } |
85 | 85 | |
86 | - foreach( $sub as $key => $value ) { |
|
86 | + foreach ($sub as $key => $value) { |
|
87 | 87 | $this->$key = $value; |
88 | 88 | } |
89 | 89 | |
90 | - $this->customer = get_userdata( $this->customer_id ); |
|
91 | - $this->gateway = wpinv_get_payment_gateway( $this->parent_payment_id ); |
|
90 | + $this->customer = get_userdata($this->customer_id); |
|
91 | + $this->gateway = wpinv_get_payment_gateway($this->parent_payment_id); |
|
92 | 92 | |
93 | - do_action( 'wpinv_recurring_setup_subscription', $this ); |
|
93 | + do_action('wpinv_recurring_setup_subscription', $this); |
|
94 | 94 | |
95 | 95 | return $this; |
96 | 96 | } |
@@ -100,15 +100,15 @@ discard block |
||
100 | 100 | * |
101 | 101 | * @since 1.0.0 |
102 | 102 | */ |
103 | - public function __get( $key ) { |
|
103 | + public function __get($key) { |
|
104 | 104 | |
105 | - if( method_exists( $this, 'get_' . $key ) ) { |
|
105 | + if (method_exists($this, 'get_' . $key)) { |
|
106 | 106 | |
107 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
107 | + return call_user_func(array($this, 'get_' . $key)); |
|
108 | 108 | |
109 | 109 | } else { |
110 | 110 | |
111 | - return new WP_Error( 'wpinv-subscription-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) ); |
|
111 | + return new WP_Error('wpinv-subscription-invalid-property', sprintf(__('Can\'t get property %s', 'invoicing'), $key)); |
|
112 | 112 | |
113 | 113 | } |
114 | 114 | |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | * @param array $data Array of attributes for a subscription |
122 | 122 | * @return mixed false if data isn't passed and class not instantiated for creation |
123 | 123 | */ |
124 | - public function create( $data = array() ) { |
|
124 | + public function create($data = array()) { |
|
125 | 125 | |
126 | - if ( $this->id != 0 ) { |
|
126 | + if ($this->id != 0) { |
|
127 | 127 | return false; |
128 | 128 | } |
129 | 129 | |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | 'profile_id' => '', |
143 | 143 | ); |
144 | 144 | |
145 | - $args = wp_parse_args( $data, $defaults ); |
|
145 | + $args = wp_parse_args($data, $defaults); |
|
146 | 146 | |
147 | - if( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) { |
|
147 | + if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) { |
|
148 | 148 | |
149 | - if( 'active' == $args['status'] || 'trialling' == $args['status'] ) { |
|
149 | + if ('active' == $args['status'] || 'trialling' == $args['status']) { |
|
150 | 150 | |
151 | 151 | // Force an active subscription to expired if expiration date is in the past |
152 | 152 | $args['status'] = 'expired'; |
@@ -154,13 +154,13 @@ discard block |
||
154 | 154 | } |
155 | 155 | } |
156 | 156 | |
157 | - do_action( 'wpinv_subscription_pre_create', $args ); |
|
157 | + do_action('wpinv_subscription_pre_create', $args); |
|
158 | 158 | |
159 | - $id = $this->subs_db->insert( $args, 'subscription' ); |
|
159 | + $id = $this->subs_db->insert($args, 'subscription'); |
|
160 | 160 | |
161 | - do_action( 'wpinv_subscription_post_create', $id, $args ); |
|
161 | + do_action('wpinv_subscription_post_create', $id, $args); |
|
162 | 162 | |
163 | - return $this->setup_subscription( $id ); |
|
163 | + return $this->setup_subscription($id); |
|
164 | 164 | |
165 | 165 | } |
166 | 166 | |
@@ -171,11 +171,11 @@ discard block |
||
171 | 171 | * @param array $args Array of fields to update |
172 | 172 | * @return bool |
173 | 173 | */ |
174 | - public function update( $args = array() ) { |
|
174 | + public function update($args = array()) { |
|
175 | 175 | |
176 | - $ret = $this->subs_db->update( $this->id, $args ); |
|
176 | + $ret = $this->subs_db->update($this->id, $args); |
|
177 | 177 | |
178 | - do_action( 'wpinv_recurring_update_subscription', $this->id, $args, $this ); |
|
178 | + do_action('wpinv_recurring_update_subscription', $this->id, $args, $this); |
|
179 | 179 | |
180 | 180 | return $ret; |
181 | 181 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @return bool |
189 | 189 | */ |
190 | 190 | public function delete() { |
191 | - return $this->subs_db->delete( $this->id ); |
|
191 | + return $this->subs_db->delete($this->id); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -208,14 +208,14 @@ discard block |
||
208 | 208 | * @return array |
209 | 209 | */ |
210 | 210 | public function get_child_payments() { |
211 | - $payments = get_posts( array( |
|
212 | - 'post_parent' => (int) $this->parent_payment_id, |
|
211 | + $payments = get_posts(array( |
|
212 | + 'post_parent' => (int)$this->parent_payment_id, |
|
213 | 213 | 'posts_per_page' => '999', |
214 | - 'post_status' => array( 'publish', 'wpi-processing', 'wpi-renewal' ), |
|
214 | + 'post_status' => array('publish', 'wpi-processing', 'wpi-renewal'), |
|
215 | 215 | 'orderby' => 'ID', |
216 | 216 | 'order' => 'DESC', |
217 | 217 | 'post_type' => 'wpi_invoice' |
218 | - ) ); |
|
218 | + )); |
|
219 | 219 | |
220 | 220 | return $payments; |
221 | 221 | } |
@@ -228,9 +228,9 @@ discard block |
||
228 | 228 | */ |
229 | 229 | public function get_total_payments() { |
230 | 230 | $child_payments = $this->get_child_payments(); |
231 | - $total_payments = !empty( $child_payments ) ? count( $child_payments ) : 0; |
|
231 | + $total_payments = !empty($child_payments) ? count($child_payments) : 0; |
|
232 | 232 | |
233 | - if ( 'pending' != $this->status ) { |
|
233 | + if ('pending' != $this->status) { |
|
234 | 234 | $total_payments++; |
235 | 235 | } |
236 | 236 | |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | public function get_times_billed() { |
247 | 247 | $times_billed = (int)$this->get_total_payments(); |
248 | 248 | |
249 | - if ( ! empty( $this->trial_period ) && $times_billed > 0 ) { |
|
249 | + if (!empty($this->trial_period) && $times_billed > 0) { |
|
250 | 250 | $times_billed--; |
251 | 251 | } |
252 | 252 | |
@@ -260,51 +260,51 @@ discard block |
||
260 | 260 | * @param array $args Array of values for the payment, including amount and transaction ID |
261 | 261 | * @return bool |
262 | 262 | */ |
263 | - public function add_payment( $args = array() ) { |
|
264 | - if ( ! $this->parent_payment_id ) { |
|
263 | + public function add_payment($args = array()) { |
|
264 | + if (!$this->parent_payment_id) { |
|
265 | 265 | return false; |
266 | 266 | } |
267 | 267 | |
268 | - $args = wp_parse_args( $args, array( |
|
268 | + $args = wp_parse_args($args, array( |
|
269 | 269 | 'amount' => '', |
270 | 270 | 'transaction_id' => '', |
271 | 271 | 'gateway' => '' |
272 | - ) ); |
|
272 | + )); |
|
273 | 273 | |
274 | - if ( empty( $args['transaction_id'] ) || $this->payment_exists( $args['transaction_id'] ) ) { |
|
274 | + if (empty($args['transaction_id']) || $this->payment_exists($args['transaction_id'])) { |
|
275 | 275 | return false; |
276 | 276 | } |
277 | 277 | |
278 | - $parent_invoice = wpinv_get_invoice( $this->parent_payment_id ); |
|
279 | - if ( empty( $parent_invoice->ID ) ) { |
|
278 | + $parent_invoice = wpinv_get_invoice($this->parent_payment_id); |
|
279 | + if (empty($parent_invoice->ID)) { |
|
280 | 280 | return false; |
281 | 281 | } |
282 | 282 | |
283 | 283 | $invoice = new WPInv_Invoice(); |
284 | - $invoice->set( 'post_type', 'wpi_invoice' ); |
|
285 | - $invoice->set( 'parent_invoice', $this->parent_payment_id ); |
|
286 | - $invoice->set( 'currency', $parent_invoice->get_currency() ); |
|
287 | - $invoice->set( 'transaction_id', $args['transaction_id'] ); |
|
288 | - $invoice->set( 'key', $parent_invoice->generate_key() ); |
|
289 | - $invoice->set( 'ip', $parent_invoice->ip ); |
|
290 | - $invoice->set( 'user_id', $parent_invoice->get_user_id() ); |
|
291 | - $invoice->set( 'first_name', $parent_invoice->get_first_name() ); |
|
292 | - $invoice->set( 'last_name', $parent_invoice->get_last_name() ); |
|
293 | - $invoice->set( 'phone', $parent_invoice->phone ); |
|
294 | - $invoice->set( 'address', $parent_invoice->address ); |
|
295 | - $invoice->set( 'city', $parent_invoice->city ); |
|
296 | - $invoice->set( 'country', $parent_invoice->country ); |
|
297 | - $invoice->set( 'state', $parent_invoice->state ); |
|
298 | - $invoice->set( 'zip', $parent_invoice->zip ); |
|
299 | - $invoice->set( 'company', $parent_invoice->company ); |
|
300 | - $invoice->set( 'vat_number', $parent_invoice->vat_number ); |
|
301 | - $invoice->set( 'vat_rate', $parent_invoice->vat_rate ); |
|
302 | - $invoice->set( 'adddress_confirmed', $parent_invoice->adddress_confirmed ); |
|
303 | - |
|
304 | - if ( empty( $args['gateway'] ) ) { |
|
305 | - $invoice->set( 'gateway', $parent_invoice->get_gateway() ); |
|
284 | + $invoice->set('post_type', 'wpi_invoice'); |
|
285 | + $invoice->set('parent_invoice', $this->parent_payment_id); |
|
286 | + $invoice->set('currency', $parent_invoice->get_currency()); |
|
287 | + $invoice->set('transaction_id', $args['transaction_id']); |
|
288 | + $invoice->set('key', $parent_invoice->generate_key()); |
|
289 | + $invoice->set('ip', $parent_invoice->ip); |
|
290 | + $invoice->set('user_id', $parent_invoice->get_user_id()); |
|
291 | + $invoice->set('first_name', $parent_invoice->get_first_name()); |
|
292 | + $invoice->set('last_name', $parent_invoice->get_last_name()); |
|
293 | + $invoice->set('phone', $parent_invoice->phone); |
|
294 | + $invoice->set('address', $parent_invoice->address); |
|
295 | + $invoice->set('city', $parent_invoice->city); |
|
296 | + $invoice->set('country', $parent_invoice->country); |
|
297 | + $invoice->set('state', $parent_invoice->state); |
|
298 | + $invoice->set('zip', $parent_invoice->zip); |
|
299 | + $invoice->set('company', $parent_invoice->company); |
|
300 | + $invoice->set('vat_number', $parent_invoice->vat_number); |
|
301 | + $invoice->set('vat_rate', $parent_invoice->vat_rate); |
|
302 | + $invoice->set('adddress_confirmed', $parent_invoice->adddress_confirmed); |
|
303 | + |
|
304 | + if (empty($args['gateway'])) { |
|
305 | + $invoice->set('gateway', $parent_invoice->get_gateway()); |
|
306 | 306 | } else { |
307 | - $invoice->set( 'gateway', $args['gateway'] ); |
|
307 | + $invoice->set('gateway', $args['gateway']); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | $recurring_details = $parent_invoice->get_recurring_details(); |
@@ -312,11 +312,11 @@ discard block |
||
312 | 312 | // increase the earnings for each item in the subscription |
313 | 313 | $items = $recurring_details['cart_details']; |
314 | 314 | |
315 | - if ( $items ) { |
|
315 | + if ($items) { |
|
316 | 316 | $add_items = array(); |
317 | 317 | $cart_details = array(); |
318 | 318 | |
319 | - foreach ( $items as $item ) { |
|
319 | + foreach ($items as $item) { |
|
320 | 320 | $add_item = array(); |
321 | 321 | $add_item['id'] = $item['id']; |
322 | 322 | $add_item['quantity'] = $item['quantity']; |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | break; |
327 | 327 | } |
328 | 328 | |
329 | - $invoice->set( 'items', $add_items ); |
|
329 | + $invoice->set('items', $add_items); |
|
330 | 330 | $invoice->cart_details = $cart_details; |
331 | 331 | } |
332 | 332 | |
@@ -336,29 +336,29 @@ discard block |
||
336 | 336 | $tax = $recurring_details['tax']; |
337 | 337 | $discount = $recurring_details['discount']; |
338 | 338 | |
339 | - if ( $discount > 0 ) { |
|
340 | - $invoice->set( 'discount_code', $parent_invoice->discount_code ); |
|
339 | + if ($discount > 0) { |
|
340 | + $invoice->set('discount_code', $parent_invoice->discount_code); |
|
341 | 341 | } |
342 | 342 | |
343 | - $invoice->subtotal = wpinv_round_amount( $subtotal ); |
|
344 | - $invoice->tax = wpinv_round_amount( $tax ); |
|
345 | - $invoice->discount = wpinv_round_amount( $discount ); |
|
346 | - $invoice->total = wpinv_round_amount( $total ); |
|
343 | + $invoice->subtotal = wpinv_round_amount($subtotal); |
|
344 | + $invoice->tax = wpinv_round_amount($tax); |
|
345 | + $invoice->discount = wpinv_round_amount($discount); |
|
346 | + $invoice->total = wpinv_round_amount($total); |
|
347 | 347 | |
348 | - $invoice = apply_filters( 'wpinv_subscription_add_payment_save', $invoice, $this, $args ); |
|
348 | + $invoice = apply_filters('wpinv_subscription_add_payment_save', $invoice, $this, $args); |
|
349 | 349 | |
350 | 350 | $invoice->save(); |
351 | - $invoice->update_meta( '_wpinv_subscription_id', $this->id ); |
|
351 | + $invoice->update_meta('_wpinv_subscription_id', $this->id); |
|
352 | 352 | |
353 | - if ( !empty( $invoice->ID ) ) { |
|
354 | - wpinv_update_payment_status( $invoice->ID, 'publish' ); |
|
353 | + if (!empty($invoice->ID)) { |
|
354 | + wpinv_update_payment_status($invoice->ID, 'publish'); |
|
355 | 355 | sleep(1); |
356 | - wpinv_update_payment_status( $invoice->ID, 'wpi-renewal' ); |
|
356 | + wpinv_update_payment_status($invoice->ID, 'wpi-renewal'); |
|
357 | 357 | |
358 | - $invoice = wpinv_get_invoice( $invoice->ID ); |
|
358 | + $invoice = wpinv_get_invoice($invoice->ID); |
|
359 | 359 | |
360 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
361 | - do_action( 'wpinv_recurring_record_payment', $invoice->ID, $this->parent_payment_id, $args['amount'], $args['transaction_id'] ); |
|
360 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $this); |
|
361 | + do_action('wpinv_recurring_record_payment', $invoice->ID, $this->parent_payment_id, $args['amount'], $args['transaction_id']); |
|
362 | 362 | |
363 | 363 | return $invoice->ID; |
364 | 364 | } |
@@ -374,12 +374,12 @@ discard block |
||
374 | 374 | */ |
375 | 375 | public function get_transaction_id() { |
376 | 376 | |
377 | - if( empty( $this->transaction_id ) ) { |
|
377 | + if (empty($this->transaction_id)) { |
|
378 | 378 | |
379 | - $txn_id = wpinv_get_payment_transaction_id( $this->parent_payment_id ); |
|
379 | + $txn_id = wpinv_get_payment_transaction_id($this->parent_payment_id); |
|
380 | 380 | |
381 | - if( ! empty( $txn_id ) && (int) $this->parent_payment_id !== (int) $txn_id ) { |
|
382 | - $this->set_transaction_id( $txn_id ); |
|
381 | + if (!empty($txn_id) && (int)$this->parent_payment_id !== (int)$txn_id) { |
|
382 | + $this->set_transaction_id($txn_id); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | } |
@@ -394,8 +394,8 @@ discard block |
||
394 | 394 | * @since 1.0.0.4 |
395 | 395 | * @return bool |
396 | 396 | */ |
397 | - public function set_transaction_id( $txn_id = '' ) { |
|
398 | - $this->update( array( 'transaction_id' => $txn_id ) ); |
|
397 | + public function set_transaction_id($txn_id = '') { |
|
398 | + $this->update(array('transaction_id' => $txn_id)); |
|
399 | 399 | $this->transaction_id = $txn_id; |
400 | 400 | } |
401 | 401 | |
@@ -411,35 +411,35 @@ discard block |
||
411 | 411 | |
412 | 412 | |
413 | 413 | // Determine what date to use as the start for the new expiration calculation |
414 | - if( $expires > current_time( 'timestamp' ) && $this->is_active() ) { |
|
414 | + if ($expires > current_time('timestamp') && $this->is_active()) { |
|
415 | 415 | |
416 | - $base_date = $expires; |
|
416 | + $base_date = $expires; |
|
417 | 417 | |
418 | 418 | } else { |
419 | 419 | |
420 | - $base_date = current_time( 'timestamp' ); |
|
420 | + $base_date = current_time('timestamp'); |
|
421 | 421 | |
422 | 422 | } |
423 | 423 | |
424 | - $last_day = wpinv_cal_days_in_month( CAL_GREGORIAN, date( 'n', $base_date ), date( 'Y', $base_date ) ); |
|
424 | + $last_day = wpinv_cal_days_in_month(CAL_GREGORIAN, date('n', $base_date), date('Y', $base_date)); |
|
425 | 425 | |
426 | 426 | |
427 | 427 | $frequency = isset($this->frequency) ? $this->frequency : 1; |
428 | - $expiration = date( 'Y-m-d H:i:s', strtotime( '+' . $frequency . ' ' . $this->period . ' 23:59:59', $base_date ) ); |
|
428 | + $expiration = date('Y-m-d H:i:s', strtotime('+' . $frequency . ' ' . $this->period . ' 23:59:59', $base_date)); |
|
429 | 429 | |
430 | - if( date( 'j', $base_date ) == $last_day && 'day' != $this->period ) { |
|
431 | - $expiration = date( 'Y-m-d H:i:s', strtotime( $expiration . ' +2 days' ) ); |
|
430 | + if (date('j', $base_date) == $last_day && 'day' != $this->period) { |
|
431 | + $expiration = date('Y-m-d H:i:s', strtotime($expiration . ' +2 days')); |
|
432 | 432 | } |
433 | 433 | |
434 | - $expiration = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->id, $this ); |
|
434 | + $expiration = apply_filters('wpinv_subscription_renewal_expiration', $expiration, $this->id, $this); |
|
435 | 435 | |
436 | - do_action( 'wpinv_subscription_pre_renew', $this->id, $expiration, $this ); |
|
436 | + do_action('wpinv_subscription_pre_renew', $this->id, $expiration, $this); |
|
437 | 437 | |
438 | 438 | $this->status = 'active'; |
439 | 439 | $times_billed = $this->get_times_billed(); |
440 | 440 | |
441 | 441 | // Complete subscription if applicable |
442 | - if ( $this->bill_times > 0 && $times_billed >= $this->bill_times ) { |
|
442 | + if ($this->bill_times > 0 && $times_billed >= $this->bill_times) { |
|
443 | 443 | $this->complete(); |
444 | 444 | $this->status = 'completed'; |
445 | 445 | } |
@@ -449,10 +449,10 @@ discard block |
||
449 | 449 | 'status' => $this->status, |
450 | 450 | ); |
451 | 451 | |
452 | - $this->subs_db->update( $this->id, $args ); |
|
452 | + $this->subs_db->update($this->id, $args); |
|
453 | 453 | |
454 | - do_action( 'wpinv_subscription_post_renew', $this->id, $expiration, $this ); |
|
455 | - do_action( 'wpinv_recurring_set_subscription_status', $this->id, $this->status, $this ); |
|
454 | + do_action('wpinv_subscription_post_renew', $this->id, $expiration, $this); |
|
455 | + do_action('wpinv_recurring_set_subscription_status', $this->id, $this->status, $this); |
|
456 | 456 | |
457 | 457 | } |
458 | 458 | |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | public function complete() { |
468 | 468 | |
469 | 469 | // Only mark a subscription as complete if it's not already cancelled. |
470 | - if ( 'cancelled' === $this->status ) { |
|
470 | + if ('cancelled' === $this->status) { |
|
471 | 471 | return; |
472 | 472 | } |
473 | 473 | |
@@ -475,11 +475,11 @@ discard block |
||
475 | 475 | 'status' => 'completed' |
476 | 476 | ); |
477 | 477 | |
478 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
478 | + if ($this->subs_db->update($this->id, $args)) { |
|
479 | 479 | |
480 | 480 | $this->status = 'completed'; |
481 | 481 | |
482 | - do_action( 'wpinv_subscription_completed', $this->id, $this ); |
|
482 | + do_action('wpinv_subscription_completed', $this->id, $this); |
|
483 | 483 | |
484 | 484 | } |
485 | 485 | |
@@ -494,15 +494,15 @@ discard block |
||
494 | 494 | * @param $check_expiration bool True if expiration date should be checked with merchant processor before expiring |
495 | 495 | * @return void |
496 | 496 | */ |
497 | - public function expire( $check_expiration = false ) { |
|
497 | + public function expire($check_expiration = false) { |
|
498 | 498 | |
499 | 499 | $expiration = $this->expiration; |
500 | 500 | |
501 | - if( $check_expiration ) { |
|
501 | + if ($check_expiration) { |
|
502 | 502 | |
503 | 503 | // check_expiration() updates $this->expiration so compare to $expiration above |
504 | 504 | |
505 | - if( $expiration < $this->get_expiration() && current_time( 'timestamp' ) < $this->get_expiration_time() ) { |
|
505 | + if ($expiration < $this->get_expiration() && current_time('timestamp') < $this->get_expiration_time()) { |
|
506 | 506 | |
507 | 507 | return false; // Do not mark as expired since real expiration date is in the future |
508 | 508 | } |
@@ -513,11 +513,11 @@ discard block |
||
513 | 513 | 'status' => 'expired' |
514 | 514 | ); |
515 | 515 | |
516 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
516 | + if ($this->subs_db->update($this->id, $args)) { |
|
517 | 517 | |
518 | 518 | $this->status = 'expired'; |
519 | 519 | |
520 | - do_action( 'wpinv_subscription_expired', $this->id, $this ); |
|
520 | + do_action('wpinv_subscription_expired', $this->id, $this); |
|
521 | 521 | |
522 | 522 | } |
523 | 523 | |
@@ -535,11 +535,11 @@ discard block |
||
535 | 535 | 'status' => 'failing' |
536 | 536 | ); |
537 | 537 | |
538 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
538 | + if ($this->subs_db->update($this->id, $args)) { |
|
539 | 539 | |
540 | 540 | $this->status = 'failing'; |
541 | 541 | |
542 | - do_action( 'wpinv_subscription_failing', $this->id, $this ); |
|
542 | + do_action('wpinv_subscription_failing', $this->id, $this); |
|
543 | 543 | |
544 | 544 | |
545 | 545 | } |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | * @return void |
554 | 554 | */ |
555 | 555 | public function cancel() { |
556 | - if ( 'cancelled' === $this->status ) { |
|
556 | + if ('cancelled' === $this->status) { |
|
557 | 557 | return; // Already cancelled |
558 | 558 | } |
559 | 559 | |
@@ -561,20 +561,20 @@ discard block |
||
561 | 561 | 'status' => 'cancelled' |
562 | 562 | ); |
563 | 563 | |
564 | - if ( $this->subs_db->update( $this->id, $args ) ) { |
|
565 | - if ( is_user_logged_in() ) { |
|
566 | - $userdata = get_userdata( get_current_user_id() ); |
|
564 | + if ($this->subs_db->update($this->id, $args)) { |
|
565 | + if (is_user_logged_in()) { |
|
566 | + $userdata = get_userdata(get_current_user_id()); |
|
567 | 567 | $user = $userdata->display_name; |
568 | 568 | } else { |
569 | - $user = __( 'gateway', 'invoicing' ); |
|
569 | + $user = __('gateway', 'invoicing'); |
|
570 | 570 | } |
571 | 571 | |
572 | - $note = sprintf( __( 'Subscription has been cancelled by %s', 'invoicing' ), $user ); |
|
573 | - wpinv_insert_payment_note( $this->parent_payment_id, $note, '', '', true ); |
|
572 | + $note = sprintf(__('Subscription has been cancelled by %s', 'invoicing'), $user); |
|
573 | + wpinv_insert_payment_note($this->parent_payment_id, $note, '', '', true); |
|
574 | 574 | |
575 | 575 | $this->status = 'cancelled'; |
576 | 576 | |
577 | - do_action( 'wpinv_subscription_cancelled', $this->id, $this ); |
|
577 | + do_action('wpinv_subscription_cancelled', $this->id, $this); |
|
578 | 578 | } |
579 | 579 | } |
580 | 580 | |
@@ -589,10 +589,10 @@ discard block |
||
589 | 589 | */ |
590 | 590 | public function can_cancel() { |
591 | 591 | $ret = false; |
592 | - if( $this->gateway === 'manual' || in_array( $this->status, $this->get_cancellable_statuses() ) ) { |
|
592 | + if ($this->gateway === 'manual' || in_array($this->status, $this->get_cancellable_statuses())) { |
|
593 | 593 | $ret = true; |
594 | 594 | } |
595 | - return apply_filters( 'wpinv_subscription_can_cancel', $ret, $this ); |
|
595 | + return apply_filters('wpinv_subscription_can_cancel', $ret, $this); |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | /** |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | * @return array |
604 | 604 | */ |
605 | 605 | public function get_cancellable_statuses() { |
606 | - return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
|
606 | + return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing')); |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | /** |
@@ -614,9 +614,9 @@ discard block |
||
614 | 614 | */ |
615 | 615 | public function get_cancel_url() { |
616 | 616 | |
617 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-cancel' ); |
|
617 | + $url = wp_nonce_url(add_query_arg(array('wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id)), 'wpinv-recurring-cancel'); |
|
618 | 618 | |
619 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
619 | + return apply_filters('wpinv_subscription_cancel_url', $url, $this); |
|
620 | 620 | } |
621 | 621 | |
622 | 622 | /** |
@@ -630,7 +630,7 @@ discard block |
||
630 | 630 | */ |
631 | 631 | public function can_renew() { |
632 | 632 | |
633 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
633 | + return apply_filters('wpinv_subscription_can_renew', true, $this); |
|
634 | 634 | } |
635 | 635 | |
636 | 636 | /** |
@@ -641,9 +641,9 @@ discard block |
||
641 | 641 | */ |
642 | 642 | public function get_renew_url() { |
643 | 643 | |
644 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-renew' ); |
|
644 | + $url = wp_nonce_url(add_query_arg(array('wpinv_action' => 'renew_subscription', 'sub_id' => $this->id)), 'wpinv-recurring-renew'); |
|
645 | 645 | |
646 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
646 | + return apply_filters('wpinv_subscription_renew_url', $url, $this); |
|
647 | 647 | } |
648 | 648 | |
649 | 649 | /** |
@@ -653,7 +653,7 @@ discard block |
||
653 | 653 | * @return bool |
654 | 654 | */ |
655 | 655 | public function can_update() { |
656 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
656 | + return apply_filters('wpinv_subscription_can_update', false, $this); |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | /** |
@@ -664,9 +664,9 @@ discard block |
||
664 | 664 | */ |
665 | 665 | public function get_update_url() { |
666 | 666 | |
667 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->id ) ); |
|
667 | + $url = add_query_arg(array('action' => 'update', 'subscription_id' => $this->id)); |
|
668 | 668 | |
669 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
669 | + return apply_filters('wpinv_subscription_update_url', $url, $this); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | /** |
@@ -679,11 +679,11 @@ discard block |
||
679 | 679 | |
680 | 680 | $ret = false; |
681 | 681 | |
682 | - if( ! $this->is_expired() && ( $this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling' ) ) { |
|
682 | + if (!$this->is_expired() && ($this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling')) { |
|
683 | 683 | $ret = true; |
684 | 684 | } |
685 | 685 | |
686 | - return apply_filters( 'wpinv_subscription_is_active', $ret, $this->id, $this ); |
|
686 | + return apply_filters('wpinv_subscription_is_active', $ret, $this->id, $this); |
|
687 | 687 | |
688 | 688 | } |
689 | 689 | |
@@ -697,26 +697,26 @@ discard block |
||
697 | 697 | |
698 | 698 | $ret = false; |
699 | 699 | |
700 | - if ( $this->status == 'expired' ) { |
|
700 | + if ($this->status == 'expired') { |
|
701 | 701 | |
702 | 702 | $ret = true; |
703 | 703 | |
704 | - } elseif( 'active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling' ) { |
|
704 | + } elseif ('active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling') { |
|
705 | 705 | |
706 | 706 | $ret = false; |
707 | 707 | $expiration = $this->get_expiration_time(); |
708 | 708 | |
709 | - if( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) { |
|
709 | + if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) { |
|
710 | 710 | $ret = true; |
711 | 711 | |
712 | - if ( 'active' === $this->status || $this->status == 'trialling' ) { |
|
712 | + if ('active' === $this->status || $this->status == 'trialling') { |
|
713 | 713 | $this->expire(); |
714 | 714 | } |
715 | 715 | } |
716 | 716 | |
717 | 717 | } |
718 | 718 | |
719 | - return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->id, $this ); |
|
719 | + return apply_filters('wpinv_subscription_is_expired', $ret, $this->id, $this); |
|
720 | 720 | |
721 | 721 | } |
722 | 722 | |
@@ -737,7 +737,7 @@ discard block |
||
737 | 737 | * @return int |
738 | 738 | */ |
739 | 739 | public function get_expiration_time() { |
740 | - return strtotime( $this->expiration, current_time( 'timestamp' ) ); |
|
740 | + return strtotime($this->expiration, current_time('timestamp')); |
|
741 | 741 | } |
742 | 742 | |
743 | 743 | /** |
@@ -761,37 +761,37 @@ discard block |
||
761 | 761 | */ |
762 | 762 | public function get_status_label() { |
763 | 763 | |
764 | - switch( $this->get_status() ) { |
|
764 | + switch ($this->get_status()) { |
|
765 | 765 | case 'active' : |
766 | - $status = __( 'Active', 'invoicing' ); |
|
766 | + $status = __('Active', 'invoicing'); |
|
767 | 767 | break; |
768 | 768 | |
769 | 769 | case 'cancelled' : |
770 | - $status = __( 'Cancelled', 'invoicing' ); |
|
770 | + $status = __('Cancelled', 'invoicing'); |
|
771 | 771 | break; |
772 | 772 | |
773 | 773 | case 'expired' : |
774 | - $status = __( 'Expired', 'invoicing' ); |
|
774 | + $status = __('Expired', 'invoicing'); |
|
775 | 775 | break; |
776 | 776 | |
777 | 777 | case 'pending' : |
778 | - $status = __( 'Pending', 'invoicing' ); |
|
778 | + $status = __('Pending', 'invoicing'); |
|
779 | 779 | break; |
780 | 780 | |
781 | 781 | case 'failing' : |
782 | - $status = __( 'Failing', 'invoicing' ); |
|
782 | + $status = __('Failing', 'invoicing'); |
|
783 | 783 | break; |
784 | 784 | |
785 | 785 | case 'trialling' : |
786 | - $status = __( 'Trialling', 'invoicing' ); |
|
786 | + $status = __('Trialling', 'invoicing'); |
|
787 | 787 | break; |
788 | 788 | |
789 | 789 | case 'completed' : |
790 | - $status = __( 'Completed', 'invoicing' ); |
|
790 | + $status = __('Completed', 'invoicing'); |
|
791 | 791 | break; |
792 | 792 | |
793 | 793 | default: |
794 | - $status = ucfirst( $this->get_status() ); |
|
794 | + $status = ucfirst($this->get_status()); |
|
795 | 795 | break; |
796 | 796 | } |
797 | 797 | |
@@ -806,51 +806,51 @@ discard block |
||
806 | 806 | */ |
807 | 807 | public function get_status_label_html() { |
808 | 808 | |
809 | - switch( $get_status = $this->get_status() ) { |
|
809 | + switch ($get_status = $this->get_status()) { |
|
810 | 810 | case 'active' : |
811 | - $status = __( 'Active', 'invoicing' ); |
|
811 | + $status = __('Active', 'invoicing'); |
|
812 | 812 | $class = 'label-info'; |
813 | 813 | break; |
814 | 814 | |
815 | 815 | case 'cancelled' : |
816 | - $status = __( 'Cancelled', 'invoicing' ); |
|
816 | + $status = __('Cancelled', 'invoicing'); |
|
817 | 817 | $class = 'label-danger'; |
818 | 818 | break; |
819 | 819 | |
820 | 820 | case 'expired' : |
821 | - $status = __( 'Expired', 'invoicing' ); |
|
821 | + $status = __('Expired', 'invoicing'); |
|
822 | 822 | $class = 'label-default'; |
823 | 823 | break; |
824 | 824 | |
825 | 825 | case 'pending' : |
826 | - $status = __( 'Pending', 'invoicing' ); |
|
826 | + $status = __('Pending', 'invoicing'); |
|
827 | 827 | $class = 'label-primary'; |
828 | 828 | break; |
829 | 829 | |
830 | 830 | case 'failing' : |
831 | - $status = __( 'Failing', 'invoicing' ); |
|
831 | + $status = __('Failing', 'invoicing'); |
|
832 | 832 | $class = 'label-danger'; |
833 | 833 | break; |
834 | 834 | |
835 | 835 | case 'trialling' : |
836 | - $status = __( 'Trialling', 'invoicing' ); |
|
836 | + $status = __('Trialling', 'invoicing'); |
|
837 | 837 | $class = 'label-info'; |
838 | 838 | break; |
839 | 839 | |
840 | 840 | case 'completed' : |
841 | - $status = __( 'Completed', 'invoicing' ); |
|
841 | + $status = __('Completed', 'invoicing'); |
|
842 | 842 | $class = 'label-success'; |
843 | 843 | break; |
844 | 844 | |
845 | 845 | default: |
846 | - $status = ucfirst( $this->get_status() ); |
|
846 | + $status = ucfirst($this->get_status()); |
|
847 | 847 | $class = 'label-default'; |
848 | 848 | break; |
849 | 849 | } |
850 | 850 | |
851 | 851 | $label = '<span class="sub-status label label-sub-' . $get_status . ' ' . $class . '">' . $status . '</span>'; |
852 | 852 | |
853 | - return apply_filters( 'wpinv_subscription_status_label_html', $label, $get_status, $status ); |
|
853 | + return apply_filters('wpinv_subscription_status_label_html', $label, $get_status, $status); |
|
854 | 854 | } |
855 | 855 | |
856 | 856 | /** |
@@ -860,18 +860,18 @@ discard block |
||
860 | 860 | * @param string $txn_id The transaction ID from the merchant processor |
861 | 861 | * @return bool |
862 | 862 | */ |
863 | - public function payment_exists( $txn_id = '' ) { |
|
863 | + public function payment_exists($txn_id = '') { |
|
864 | 864 | global $wpdb; |
865 | 865 | |
866 | - if ( empty( $txn_id ) ) { |
|
866 | + if (empty($txn_id)) { |
|
867 | 867 | return false; |
868 | 868 | } |
869 | 869 | |
870 | - $txn_id = esc_sql( $txn_id ); |
|
870 | + $txn_id = esc_sql($txn_id); |
|
871 | 871 | |
872 | - $purchase = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1" ); |
|
872 | + $purchase = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1"); |
|
873 | 873 | |
874 | - if ( $purchase != null ) { |
|
874 | + if ($purchase != null) { |
|
875 | 875 | return true; |
876 | 876 | } |
877 | 877 |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -add_action( 'wpinv_worldpay_cc_form', '__return_false' ); |
|
5 | +add_action('wpinv_worldpay_cc_form', '__return_false'); |
|
6 | 6 | |
7 | -function wpinv_process_worldpay_payment( $purchase_data ) { |
|
8 | - if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
9 | - wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
7 | +function wpinv_process_worldpay_payment($purchase_data) { |
|
8 | + if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) { |
|
9 | + wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | // Collect payment data |
@@ -24,132 +24,132 @@ discard block |
||
24 | 24 | ); |
25 | 25 | |
26 | 26 | // Record the pending payment |
27 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
27 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
28 | 28 | |
29 | - if ( !empty( $invoice ) ) { |
|
29 | + if (!empty($invoice)) { |
|
30 | 30 | $quantities_enabled = wpinv_item_quantities_enabled(); |
31 | 31 | |
32 | - $instId = wpinv_get_option( 'worldpay_instId', false ); |
|
32 | + $instId = wpinv_get_option('worldpay_instId', false); |
|
33 | 33 | $cartId = $invoice->get_number(); |
34 | - $testMode = wpinv_is_test_mode( 'worldpay' ) ? 100 : 0; |
|
34 | + $testMode = wpinv_is_test_mode('worldpay') ? 100 : 0; |
|
35 | 35 | $name = $invoice->get_user_full_name(); |
36 | - $address = wp_strip_all_tags( $invoice->get_address(), true ); |
|
36 | + $address = wp_strip_all_tags($invoice->get_address(), true); |
|
37 | 37 | $postcode = $invoice->zip; |
38 | 38 | $tel = $invoice->phone; |
39 | 39 | $email = $invoice->get_email(); |
40 | 40 | $country = $invoice->country; |
41 | - $amount = wpinv_sanitize_amount( $invoice->get_total() ); |
|
41 | + $amount = wpinv_sanitize_amount($invoice->get_total()); |
|
42 | 42 | $currency = wpinv_get_currency(); |
43 | 43 | |
44 | 44 | $items = array(); |
45 | - foreach ( $invoice->get_cart_details() as $item ) { |
|
45 | + foreach ($invoice->get_cart_details() as $item) { |
|
46 | 46 | $item_desc = $item['name']; |
47 | - $quantity = !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
48 | - $item_desc .= ' (' . ( $quantities_enabled ? $quantity . 'x ' : '' ) . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')'; |
|
47 | + $quantity = !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
48 | + $item_desc .= ' (' . ($quantities_enabled ? $quantity . 'x ' : '') . wpinv_price(wpinv_format_amount($item['item_price'])) . ')'; |
|
49 | 49 | |
50 | 50 | $items[] = $item_desc; |
51 | 51 | } |
52 | 52 | |
53 | - $desc = implode( ', ', $items ); |
|
54 | - if ( wpinv_use_taxes() && $invoice->get_tax() > 0 ) { |
|
55 | - $desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) ); |
|
53 | + $desc = implode(', ', $items); |
|
54 | + if (wpinv_use_taxes() && $invoice->get_tax() > 0) { |
|
55 | + $desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true)); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | $extra_params = array(); |
59 | 59 | $extra_params['MC_description'] = $desc; |
60 | - $extra_params['MC_callback'] = wpinv_get_ipn_url( 'worldpay' ); |
|
60 | + $extra_params['MC_callback'] = wpinv_get_ipn_url('worldpay'); |
|
61 | 61 | $extra_params['MC_key'] = $invoice->get_key(); |
62 | 62 | $extra_params['MC_invoice_id'] = $invoice->ID; |
63 | 63 | $extra_params['address1'] = $address; |
64 | 64 | $extra_params['town'] = $invoice->city; |
65 | 65 | $extra_params['region'] = $invoice->state; |
66 | - $extra_params['amountString'] = $invoice->get_total( true ); |
|
67 | - $extra_params['countryString'] = wpinv_country_name( $invoice->country ); |
|
66 | + $extra_params['amountString'] = $invoice->get_total(true); |
|
67 | + $extra_params['countryString'] = wpinv_country_name($invoice->country); |
|
68 | 68 | $extra_params['compName'] = $invoice->company; |
69 | 69 | |
70 | - $extra_params = apply_filters( 'wpinv_worldpay_form_extra_parameters', $extra_params, $invoice ); |
|
70 | + $extra_params = apply_filters('wpinv_worldpay_form_extra_parameters', $extra_params, $invoice); |
|
71 | 71 | |
72 | - $redirect_text = __( 'Redirecting to Worldpay site, click on button if not redirected.', 'invoicing' ); |
|
73 | - $redirect_text = apply_filters( 'wpinv_worldpay_redirect_text', $redirect_text, $invoice ); |
|
72 | + $redirect_text = __('Redirecting to Worldpay site, click on button if not redirected.', 'invoicing'); |
|
73 | + $redirect_text = apply_filters('wpinv_worldpay_redirect_text', $redirect_text, $invoice); |
|
74 | 74 | |
75 | 75 | // Empty the shopping cart |
76 | 76 | wpinv_empty_cart(); |
77 | 77 | ?> |
78 | 78 | <div class="wpi-worldpay-form" style="padding:20px;font-family:arial,sans-serif;text-align:center;color:#555"> |
79 | -<?php do_action( 'wpinv_worldpay_form_before', $invoice ); ?> |
|
80 | -<h3><?php echo $redirect_text ;?></h3> |
|
79 | +<?php do_action('wpinv_worldpay_form_before', $invoice); ?> |
|
80 | +<h3><?php echo $redirect_text; ?></h3> |
|
81 | 81 | <form action="<?php echo wpinv_get_worldpay_redirect(); ?>" name="wpi_worldpay_form" method="POST"> |
82 | - <input type="hidden" value="<?php echo $amount;?>" name="amount"> |
|
83 | - <input type="hidden" value="<?php echo esc_attr( $cartId );?>" name="cartId"> |
|
84 | - <input type="hidden" value="<?php echo $currency;?>" name="currency"> |
|
85 | - <input type="hidden" value="<?php echo $instId;?>" name="instId"> |
|
86 | - <input type="hidden" value="<?php echo $testMode;?>" name="testMode"> |
|
87 | - <input type="hidden" value="<?php echo esc_attr( $name );?>" name="name"> |
|
88 | - <input type="hidden" value="<?php echo esc_attr( $address );?>" name="address"> |
|
89 | - <input type="hidden" value="<?php echo esc_attr( $postcode );?>" name="postcode"> |
|
90 | - <input type="hidden" value="<?php echo esc_attr( $tel );?>" name="tel"> |
|
91 | - <input type="hidden" value="<?php echo esc_attr( $email );?>" name="email"> |
|
92 | - <input type="hidden" value="<?php echo esc_attr( $country );?>" name="country"> |
|
93 | - <input type="hidden" value="<?php echo esc_attr( $desc );?>" name="desc"> |
|
94 | - <?php foreach ( $extra_params as $param => $value ) { ?> |
|
95 | - <?php if ( !empty( $value !== false ) ) { ?> |
|
96 | - <input type="hidden" value="<?php echo esc_attr( $value );?>" name="<?php echo esc_attr( $param );?>"> |
|
82 | + <input type="hidden" value="<?php echo $amount; ?>" name="amount"> |
|
83 | + <input type="hidden" value="<?php echo esc_attr($cartId); ?>" name="cartId"> |
|
84 | + <input type="hidden" value="<?php echo $currency; ?>" name="currency"> |
|
85 | + <input type="hidden" value="<?php echo $instId; ?>" name="instId"> |
|
86 | + <input type="hidden" value="<?php echo $testMode; ?>" name="testMode"> |
|
87 | + <input type="hidden" value="<?php echo esc_attr($name); ?>" name="name"> |
|
88 | + <input type="hidden" value="<?php echo esc_attr($address); ?>" name="address"> |
|
89 | + <input type="hidden" value="<?php echo esc_attr($postcode); ?>" name="postcode"> |
|
90 | + <input type="hidden" value="<?php echo esc_attr($tel); ?>" name="tel"> |
|
91 | + <input type="hidden" value="<?php echo esc_attr($email); ?>" name="email"> |
|
92 | + <input type="hidden" value="<?php echo esc_attr($country); ?>" name="country"> |
|
93 | + <input type="hidden" value="<?php echo esc_attr($desc); ?>" name="desc"> |
|
94 | + <?php foreach ($extra_params as $param => $value) { ?> |
|
95 | + <?php if (!empty($value !== false)) { ?> |
|
96 | + <input type="hidden" value="<?php echo esc_attr($value); ?>" name="<?php echo esc_attr($param); ?>"> |
|
97 | 97 | <?php } ?> |
98 | 98 | <?php } ?> |
99 | - <?php do_action( 'wpinv_worldpay_form_parameters', $invoice ); ?> |
|
100 | - <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e( 'Pay by Credit Card / Debit Card (WorldPay)', 'invoicing' ) ;?>"> |
|
99 | + <?php do_action('wpinv_worldpay_form_parameters', $invoice); ?> |
|
100 | + <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e('Pay by Credit Card / Debit Card (WorldPay)', 'invoicing'); ?>"> |
|
101 | 101 | </form> |
102 | 102 | <script type="text/javascript">document.wpi_worldpay_form.submit();</script> |
103 | -<?php do_action( 'wpinv_worldpay_form_after', $invoice ); ?> |
|
103 | +<?php do_action('wpinv_worldpay_form_after', $invoice); ?> |
|
104 | 104 | </div> |
105 | 105 | <?php |
106 | 106 | } else { |
107 | - wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice ); |
|
107 | + wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice); |
|
108 | 108 | // If errors are present, send the user back to the purchase page so they can be corrected |
109 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
109 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
110 | 110 | } |
111 | 111 | } |
112 | -add_action( 'wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment' ); |
|
112 | +add_action('wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment'); |
|
113 | 113 | |
114 | 114 | function wpinv_get_worldpay_redirect() { |
115 | - $redirect = wpinv_is_test_mode( 'worldpay' ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
115 | + $redirect = wpinv_is_test_mode('worldpay') ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
116 | 116 | |
117 | - return apply_filters( 'wpinv_worldpay_redirect', $redirect ); |
|
117 | + return apply_filters('wpinv_worldpay_redirect', $redirect); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | function wpinv_process_worldpay_ipn() { |
121 | - $request = wpinv_get_post_data( 'post' ); |
|
121 | + $request = wpinv_get_post_data('post'); |
|
122 | 122 | |
123 | - if ( !empty( $request['cartId'] ) && !empty( $request['transStatus'] ) && !empty( $request['installation'] ) && isset( $request['testMode'] ) && isset( $request['MC_invoice_id'] ) && isset( $request['MC_key'] ) ) { |
|
123 | + if (!empty($request['cartId']) && !empty($request['transStatus']) && !empty($request['installation']) && isset($request['testMode']) && isset($request['MC_invoice_id']) && isset($request['MC_key'])) { |
|
124 | 124 | $invoice_id = $request['MC_invoice_id']; |
125 | 125 | |
126 | - if ( $invoice_id == wpinv_get_invoice_id_by_key( $request['MC_key'] ) && $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
127 | - if ( $request['transStatus'] == 'Y' ) { |
|
128 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
129 | - wpinv_set_payment_transaction_id( $invoice_id, $request['transId'] ); |
|
130 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Worldpay Transaction ID: %s', 'invoicing' ), $request['transId'] ) ); |
|
126 | + if ($invoice_id == wpinv_get_invoice_id_by_key($request['MC_key']) && $invoice = wpinv_get_invoice($invoice_id)) { |
|
127 | + if ($request['transStatus'] == 'Y') { |
|
128 | + wpinv_update_payment_status($invoice_id, 'publish'); |
|
129 | + wpinv_set_payment_transaction_id($invoice_id, $request['transId']); |
|
130 | + wpinv_insert_payment_note($invoice_id, sprintf(__('Worldpay Transaction ID: %s', 'invoicing'), $request['transId'])); |
|
131 | 131 | return; |
132 | - } else if ( $request['transStatus'] == 'C' ) { |
|
133 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
134 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing' ) ); |
|
132 | + } else if ($request['transStatus'] == 'C') { |
|
133 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
134 | + wpinv_insert_payment_note($invoice_id, __('Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing')); |
|
135 | 135 | |
136 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing' ), json_encode( $request ) ), $invoice_id ); |
|
136 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing'), json_encode($request)), $invoice_id); |
|
137 | 137 | return; |
138 | 138 | } |
139 | 139 | } |
140 | 140 | } |
141 | 141 | return; |
142 | 142 | } |
143 | -add_action( 'wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn' ); |
|
143 | +add_action('wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn'); |
|
144 | 144 | |
145 | 145 | function wpinv_is_worldpay_valid_for_use() { |
146 | - return in_array( wpinv_get_currency(), apply_filters( 'wpinv_worldpay_supported_currencies', array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' ))); |
|
146 | + return in_array(wpinv_get_currency(), apply_filters('wpinv_worldpay_supported_currencies', array('AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR'))); |
|
147 | 147 | } |
148 | 148 | |
149 | -function wpinv_check_worldpay_currency_support( $gateway_list ) { |
|
150 | - if ( isset( $gateway_list['worldpay'] ) && ! wpinv_is_worldpay_valid_for_use() ) { |
|
151 | - unset( $gateway_list['worldpay'] ); |
|
149 | +function wpinv_check_worldpay_currency_support($gateway_list) { |
|
150 | + if (isset($gateway_list['worldpay']) && !wpinv_is_worldpay_valid_for_use()) { |
|
151 | + unset($gateway_list['worldpay']); |
|
152 | 152 | } |
153 | 153 | return $gateway_list; |
154 | 154 | } |
155 | -add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_worldpay_currency_support', 10, 1 ); |
|
156 | 155 | \ No newline at end of file |
156 | +add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_worldpay_currency_support', 10, 1); |
|
157 | 157 | \ No newline at end of file |
@@ -1,60 +1,60 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -add_filter( 'wpinv_authorizenet_support_subscription', '__return_true' ); |
|
5 | +add_filter('wpinv_authorizenet_support_subscription', '__return_true'); |
|
6 | 6 | |
7 | -function wpinv_authorizenet_cc_form( $invoice_id ) { |
|
8 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
9 | - $cc_owner = !empty( $invoice ) ? esc_attr( $invoice->get_user_full_name() ) : ''; |
|
7 | +function wpinv_authorizenet_cc_form($invoice_id) { |
|
8 | + $invoice = wpinv_get_invoice($invoice_id); |
|
9 | + $cc_owner = !empty($invoice) ? esc_attr($invoice->get_user_full_name()) : ''; |
|
10 | 10 | ?> |
11 | 11 | <div id="authorizenet_cc_form" class="form-horizontal wpi-cc-form panel panel-default"> |
12 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Card Details', 'invoicing' ) ;?></h3></div> |
|
12 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Card Details', 'invoicing'); ?></h3></div> |
|
13 | 13 | <div class="panel-body"> |
14 | 14 | <div class="form-group required"> |
15 | - <label for="auth-input-cc-owner" class="col-sm-3 control-label"><?php _e( 'Card Owner', 'invoicing' ) ;?></label> |
|
15 | + <label for="auth-input-cc-owner" class="col-sm-3 control-label"><?php _e('Card Owner', 'invoicing'); ?></label> |
|
16 | 16 | <div class="col-sm-5"> |
17 | - <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e( 'Card Owner', 'invoicing' ) ;?>" value="<?php echo $cc_owner;?>" name="authorizenet[cc_owner]"> |
|
17 | + <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e('Card Owner', 'invoicing'); ?>" value="<?php echo $cc_owner; ?>" name="authorizenet[cc_owner]"> |
|
18 | 18 | </div> |
19 | 19 | </div> |
20 | 20 | <div class="form-group required"> |
21 | - <label for="auth-input-cc-number" class="col-sm-3 control-label"><?php _e( 'Card Number', 'invoicing' ) ;?></label> |
|
21 | + <label for="auth-input-cc-number" class="col-sm-3 control-label"><?php _e('Card Number', 'invoicing'); ?></label> |
|
22 | 22 | <div class="col-sm-5"> |
23 | - <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e( 'Card Number', 'invoicing' ) ;?>" value="" name="authorizenet[cc_number]"> |
|
23 | + <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e('Card Number', 'invoicing'); ?>" value="" name="authorizenet[cc_number]"> |
|
24 | 24 | </div> |
25 | 25 | </div> |
26 | 26 | <div class="form-group required"> |
27 | - <label for="auth-input-cc-expire-date" class="col-sm-3 control-label"><?php _e( 'Card Expiry Date', 'invoicing' ) ;?></label> |
|
27 | + <label for="auth-input-cc-expire-date" class="col-sm-3 control-label"><?php _e('Card Expiry Date', 'invoicing'); ?></label> |
|
28 | 28 | <div class="col-sm-2"> |
29 | 29 | <select class="form-control" id="auth-input-cc-expire-date" name="authorizenet[cc_expire_month]"> |
30 | - <?php for ( $i = 1; $i <= 12; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
31 | - <option value="<?php echo $value;?>"><?php echo $value;?></option> |
|
30 | + <?php for ($i = 1; $i <= 12; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
31 | + <option value="<?php echo $value; ?>"><?php echo $value; ?></option> |
|
32 | 32 | <?php } ?> |
33 | 33 | </select> |
34 | 34 | </div> |
35 | 35 | <div class="col-sm-3"> |
36 | 36 | <select class="form-control" name="authorizenet[cc_expire_year]"> |
37 | - <?php $year = date( 'Y' ); for ( $i = $year; $i <= ( $year + 10 ); $i++ ) { ?> |
|
38 | - <option value="<?php echo $i;?>"><?php echo $i;?></option> |
|
37 | + <?php $year = date('Y'); for ($i = $year; $i <= ($year + 10); $i++) { ?> |
|
38 | + <option value="<?php echo $i; ?>"><?php echo $i; ?></option> |
|
39 | 39 | <?php } ?> |
40 | 40 | </select> |
41 | 41 | </div> |
42 | 42 | </div> |
43 | 43 | <div class="form-group required"> |
44 | - <label for="auth-input-cc-cvv2" class="col-sm-3 control-label"><?php _e( 'Card Security Code (CVV2)', 'invoicing' ) ;?></label> |
|
44 | + <label for="auth-input-cc-cvv2" class="col-sm-3 control-label"><?php _e('Card Security Code (CVV2)', 'invoicing'); ?></label> |
|
45 | 45 | <div class="col-sm-5"> |
46 | - <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e( 'Card Security Code (CVV2)', 'invoicing' ) ;?>" value="" name="authorizenet[cc_cvv2]""> |
|
46 | + <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e('Card Security Code (CVV2)', 'invoicing'); ?>" value="" name="authorizenet[cc_cvv2]""> |
|
47 | 47 | </div> |
48 | 48 | </div> |
49 | 49 | </div> |
50 | 50 | </div> |
51 | 51 | <?php |
52 | 52 | } |
53 | -add_action( 'wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1 ); |
|
53 | +add_action('wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1); |
|
54 | 54 | |
55 | -function wpinv_process_authorizenet_payment( $purchase_data ) { |
|
56 | - if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
57 | - wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
55 | +function wpinv_process_authorizenet_payment($purchase_data) { |
|
56 | + if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) { |
|
57 | + wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | // Collect payment data |
@@ -72,10 +72,10 @@ discard block |
||
72 | 72 | ); |
73 | 73 | |
74 | 74 | // Record the pending payment |
75 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
75 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
76 | 76 | |
77 | - if ( !empty( $invoice ) ) { |
|
78 | - $authorizenet_card = !empty( $_POST['authorizenet'] ) ? $_POST['authorizenet'] : array(); |
|
77 | + if (!empty($invoice)) { |
|
78 | + $authorizenet_card = !empty($_POST['authorizenet']) ? $_POST['authorizenet'] : array(); |
|
79 | 79 | $card_defaults = array( |
80 | 80 | 'cc_owner' => $invoice->get_user_full_name(), |
81 | 81 | 'cc_number' => false, |
@@ -83,186 +83,186 @@ discard block |
||
83 | 83 | 'cc_expire_year' => false, |
84 | 84 | 'cc_cvv2' => false, |
85 | 85 | ); |
86 | - $authorizenet_card = wp_parse_args( $authorizenet_card, $card_defaults ); |
|
86 | + $authorizenet_card = wp_parse_args($authorizenet_card, $card_defaults); |
|
87 | 87 | |
88 | - if ( empty( $authorizenet_card['cc_owner'] ) ) { |
|
89 | - wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing')); |
|
88 | + if (empty($authorizenet_card['cc_owner'])) { |
|
89 | + wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing')); |
|
90 | 90 | } |
91 | - if ( empty( $authorizenet_card['cc_number'] ) ) { |
|
92 | - wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing')); |
|
91 | + if (empty($authorizenet_card['cc_number'])) { |
|
92 | + wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing')); |
|
93 | 93 | } |
94 | - if ( empty( $authorizenet_card['cc_expire_month'] ) ) { |
|
95 | - wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing')); |
|
94 | + if (empty($authorizenet_card['cc_expire_month'])) { |
|
95 | + wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing')); |
|
96 | 96 | } |
97 | - if ( empty( $authorizenet_card['cc_expire_year'] ) ) { |
|
98 | - wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing')); |
|
97 | + if (empty($authorizenet_card['cc_expire_year'])) { |
|
98 | + wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing')); |
|
99 | 99 | } |
100 | - if ( empty( $authorizenet_card['cc_cvv2'] ) ) { |
|
101 | - wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) ); |
|
100 | + if (empty($authorizenet_card['cc_cvv2'])) { |
|
101 | + wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing')); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | $errors = wpinv_get_errors(); |
105 | 105 | |
106 | - if ( empty( $errors ) ) { |
|
106 | + if (empty($errors)) { |
|
107 | 107 | $invoice_id = $invoice->ID; |
108 | 108 | $quantities_enabled = wpinv_item_quantities_enabled(); |
109 | 109 | $use_taxes = wpinv_use_taxes(); |
110 | 110 | |
111 | 111 | $authorizeAIM = wpinv_authorizenet_AIM(); |
112 | - $authorizeAIM->first_name = wpinv_utf8_substr( $invoice->get_first_name(), 0, 50 ); |
|
113 | - $authorizeAIM->last_name = wpinv_utf8_substr( $invoice->get_last_name(), 0, 50 ); |
|
114 | - $authorizeAIM->company = wpinv_utf8_substr( $invoice->company, 0, 50 ); |
|
115 | - $authorizeAIM->address = wpinv_utf8_substr( wp_strip_all_tags( $invoice->get_address(), true ), 0, 60 ); |
|
116 | - $authorizeAIM->city = wpinv_utf8_substr( $invoice->city, 0, 40 ); |
|
117 | - $authorizeAIM->state = wpinv_utf8_substr( $invoice->state, 0, 40 ); |
|
118 | - $authorizeAIM->zip = wpinv_utf8_substr( $invoice->zip, 0, 40 ); |
|
119 | - $authorizeAIM->country = wpinv_utf8_substr( $invoice->country, 0, 60 ); |
|
120 | - $authorizeAIM->phone = wpinv_utf8_substr( $invoice->phone, 0, 25 ); |
|
121 | - $authorizeAIM->email = wpinv_utf8_substr( $invoice->get_email(), 0, 255 ); |
|
122 | - $authorizeAIM->amount = wpinv_sanitize_amount( $invoice->get_total() ); |
|
123 | - $authorizeAIM->card_num = str_replace( ' ', '', sanitize_text_field( $authorizenet_card['cc_number'] ) ); |
|
124 | - $authorizeAIM->exp_date = sanitize_text_field( $authorizenet_card['cc_expire_month'] ) . sanitize_text_field( $authorizenet_card['cc_expire_year'] ); |
|
125 | - $authorizeAIM->card_code = sanitize_text_field( $authorizenet_card['cc_cvv2'] ); |
|
112 | + $authorizeAIM->first_name = wpinv_utf8_substr($invoice->get_first_name(), 0, 50); |
|
113 | + $authorizeAIM->last_name = wpinv_utf8_substr($invoice->get_last_name(), 0, 50); |
|
114 | + $authorizeAIM->company = wpinv_utf8_substr($invoice->company, 0, 50); |
|
115 | + $authorizeAIM->address = wpinv_utf8_substr(wp_strip_all_tags($invoice->get_address(), true), 0, 60); |
|
116 | + $authorizeAIM->city = wpinv_utf8_substr($invoice->city, 0, 40); |
|
117 | + $authorizeAIM->state = wpinv_utf8_substr($invoice->state, 0, 40); |
|
118 | + $authorizeAIM->zip = wpinv_utf8_substr($invoice->zip, 0, 40); |
|
119 | + $authorizeAIM->country = wpinv_utf8_substr($invoice->country, 0, 60); |
|
120 | + $authorizeAIM->phone = wpinv_utf8_substr($invoice->phone, 0, 25); |
|
121 | + $authorizeAIM->email = wpinv_utf8_substr($invoice->get_email(), 0, 255); |
|
122 | + $authorizeAIM->amount = wpinv_sanitize_amount($invoice->get_total()); |
|
123 | + $authorizeAIM->card_num = str_replace(' ', '', sanitize_text_field($authorizenet_card['cc_number'])); |
|
124 | + $authorizeAIM->exp_date = sanitize_text_field($authorizenet_card['cc_expire_month']) . sanitize_text_field($authorizenet_card['cc_expire_year']); |
|
125 | + $authorizeAIM->card_code = sanitize_text_field($authorizenet_card['cc_cvv2']); |
|
126 | 126 | $authorizeAIM->invoice_num = $invoice->ID; |
127 | 127 | |
128 | 128 | $item_desc = array(); |
129 | - foreach ( $invoice->get_cart_details() as $item ) { |
|
130 | - $quantity = $quantities_enabled && !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
131 | - $item_name = wpinv_utf8_substr( $item['name'], 0, 31 ); |
|
132 | - $item_desc[] = $item_name . ' (' . $quantity . 'x ' . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')'; |
|
129 | + foreach ($invoice->get_cart_details() as $item) { |
|
130 | + $quantity = $quantities_enabled && !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
131 | + $item_name = wpinv_utf8_substr($item['name'], 0, 31); |
|
132 | + $item_desc[] = $item_name . ' (' . $quantity . 'x ' . wpinv_price(wpinv_format_amount($item['item_price'])) . ')'; |
|
133 | 133 | |
134 | - $authorizeAIM->addLineItem( $item['id'], $item_name, '', $quantity, $item['item_price'], ( $use_taxes && !empty( $item['tax'] ) && $item['tax'] > 0 ? 'Y' : 'N' ) ); |
|
134 | + $authorizeAIM->addLineItem($item['id'], $item_name, '', $quantity, $item['item_price'], ($use_taxes && !empty($item['tax']) && $item['tax'] > 0 ? 'Y' : 'N')); |
|
135 | 135 | } |
136 | 136 | |
137 | - $item_desc = '#' . $invoice->get_number() . ': ' . implode( ', ', $item_desc ); |
|
137 | + $item_desc = '#' . $invoice->get_number() . ': ' . implode(', ', $item_desc); |
|
138 | 138 | |
139 | - if ( $use_taxes && $invoice->get_tax() > 0 ) { |
|
140 | - $authorizeAIM->tax = $invoice->get_tax(); |
|
139 | + if ($use_taxes && $invoice->get_tax() > 0) { |
|
140 | + $authorizeAIM->tax = $invoice->get_tax(); |
|
141 | 141 | |
142 | - $item_desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) ); |
|
142 | + $item_desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true)); |
|
143 | 143 | } |
144 | 144 | |
145 | - if ( $invoice->get_discount() > 0 ) { |
|
146 | - $item_desc .= ', ' . wp_sprintf( __( 'Discount: %s', 'invoicing' ), $invoice->get_discount( true ) ); |
|
145 | + if ($invoice->get_discount() > 0) { |
|
146 | + $item_desc .= ', ' . wp_sprintf(__('Discount: %s', 'invoicing'), $invoice->get_discount(true)); |
|
147 | 147 | } |
148 | 148 | |
149 | - $item_description = wpinv_utf8_substr( $item_desc, 0, 255 ); |
|
150 | - $item_description = html_entity_decode( $item_desc , ENT_QUOTES, 'UTF-8' ); |
|
149 | + $item_description = wpinv_utf8_substr($item_desc, 0, 255); |
|
150 | + $item_description = html_entity_decode($item_desc, ENT_QUOTES, 'UTF-8'); |
|
151 | 151 | |
152 | - $authorizeAIM->description = wpinv_utf8_substr( $item_description, 0, 255 ); |
|
152 | + $authorizeAIM->description = wpinv_utf8_substr($item_description, 0, 255); |
|
153 | 153 | |
154 | 154 | $is_recurring = $invoice->is_recurring(); // Recurring payment. |
155 | 155 | |
156 | - if ( $is_recurring ) { |
|
156 | + if ($is_recurring) { |
|
157 | 157 | $authorizeAIM->recurring_billing = true; |
158 | 158 | } |
159 | 159 | |
160 | 160 | try { |
161 | - if ( $is_recurring ) { |
|
161 | + if ($is_recurring) { |
|
162 | 162 | $response = $authorizeAIM->authorizeOnly(); |
163 | 163 | } else { |
164 | 164 | $trx_type = wpinv_get_option('authorizenet_transaction_type', 'authorize_capture'); |
165 | - if('authorize_capture' == $trx_type){ |
|
165 | + if ('authorize_capture' == $trx_type) { |
|
166 | 166 | $response = $authorizeAIM->authorizeAndCapture(); |
167 | 167 | } else { |
168 | 168 | $response = $authorizeAIM->authorizeOnly(); |
169 | 169 | } |
170 | 170 | } |
171 | 171 | |
172 | - if ( $response->approved || $response->held ) { |
|
173 | - if ( $response->approved ) { |
|
174 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
172 | + if ($response->approved || $response->held) { |
|
173 | + if ($response->approved) { |
|
174 | + wpinv_update_payment_status($invoice_id, 'publish'); |
|
175 | 175 | } |
176 | - wpinv_set_payment_transaction_id( $invoice_id, $response->transaction_id ); |
|
176 | + wpinv_set_payment_transaction_id($invoice_id, $response->transaction_id); |
|
177 | 177 | |
178 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'Authorize.Net payment response: %s', 'invoicing' ), $response->response_reason_text ), '', '', true ); |
|
179 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'Authorize.Net payment: Transaction ID %s, Transaction Type %s, Authorization Code %s', 'invoicing' ), $response->transaction_id, strtoupper( $response->transaction_type ), $response->authorization_code ), '', '', true ); |
|
178 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('Authorize.Net payment response: %s', 'invoicing'), $response->response_reason_text), '', '', true); |
|
179 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('Authorize.Net payment: Transaction ID %s, Transaction Type %s, Authorization Code %s', 'invoicing'), $response->transaction_id, strtoupper($response->transaction_type), $response->authorization_code), '', '', true); |
|
180 | 180 | |
181 | - do_action( 'wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card ); |
|
181 | + do_action('wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card); |
|
182 | 182 | |
183 | 183 | wpinv_clear_errors(); |
184 | 184 | wpinv_empty_cart(); |
185 | 185 | |
186 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
186 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
187 | 187 | } else { |
188 | - if ( !empty( $response->response_reason_text ) ) { |
|
189 | - $error = __( $response->response_reason_text, 'invoicing' ); |
|
190 | - } else if ( !empty( $response->error_message ) ) { |
|
191 | - $error = __( $response->error_message, 'invoicing' ); |
|
188 | + if (!empty($response->response_reason_text)) { |
|
189 | + $error = __($response->response_reason_text, 'invoicing'); |
|
190 | + } else if (!empty($response->error_message)) { |
|
191 | + $error = __($response->error_message, 'invoicing'); |
|
192 | 192 | } else { |
193 | - $error = wp_sprintf( __( 'Error data: %s', 'invoicing' ), print_r( $response, true ) ); |
|
193 | + $error = wp_sprintf(__('Error data: %s', 'invoicing'), print_r($response, true)); |
|
194 | 194 | } |
195 | 195 | |
196 | - $error = wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $error ); |
|
196 | + $error = wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $error); |
|
197 | 197 | |
198 | - wpinv_set_error( 'payment_error', $error ); |
|
199 | - wpinv_record_gateway_error( $error, $response ); |
|
200 | - wpinv_insert_payment_note( $invoice_id, $error, '', '', true ); |
|
198 | + wpinv_set_error('payment_error', $error); |
|
199 | + wpinv_record_gateway_error($error, $response); |
|
200 | + wpinv_insert_payment_note($invoice_id, $error, '', '', true); |
|
201 | 201 | |
202 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
202 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
203 | 203 | } |
204 | - } catch ( AuthorizeNetException $e ) { |
|
205 | - wpinv_set_error( 'request_error', $e->getMessage() ); |
|
206 | - wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $e->getMessage() ) ); |
|
207 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
204 | + } catch (AuthorizeNetException $e) { |
|
205 | + wpinv_set_error('request_error', $e->getMessage()); |
|
206 | + wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $e->getMessage())); |
|
207 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
208 | 208 | } |
209 | 209 | } else { |
210 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
210 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
211 | 211 | } |
212 | 212 | } else { |
213 | - wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.Net payment. Payment data: %s', 'invoicing' ), print_r( $payment_data, true ) ), $invoice ); |
|
214 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
213 | + wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.Net payment. Payment data: %s', 'invoicing'), print_r($payment_data, true)), $invoice); |
|
214 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
215 | 215 | } |
216 | 216 | } |
217 | -add_action( 'wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment' ); |
|
217 | +add_action('wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment'); |
|
218 | 218 | |
219 | -function wpinv_authorizenet_cancel_subscription( $subscription_id = '' ) { |
|
220 | - if ( empty( $subscription_id ) ) { |
|
219 | +function wpinv_authorizenet_cancel_subscription($subscription_id = '') { |
|
220 | + if (empty($subscription_id)) { |
|
221 | 221 | return false; |
222 | 222 | } |
223 | 223 | |
224 | 224 | try { |
225 | 225 | $authnetXML = wpinv_authorizenet_XML(); |
226 | - $authnetXML->ARBCancelSubscriptionRequest( array( 'subscriptionId' => $subscription_id ) ); |
|
226 | + $authnetXML->ARBCancelSubscriptionRequest(array('subscriptionId' => $subscription_id)); |
|
227 | 227 | return $authnetXML->isSuccessful(); |
228 | - } catch( Exception $e ) { |
|
229 | - wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) ); |
|
228 | + } catch (Exception $e) { |
|
229 | + wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing')); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | return false; |
233 | 233 | } |
234 | 234 | |
235 | -function wpinv_recurring_cancel_authorizenet_subscription( $subscription, $valid = false ) { |
|
236 | - if ( ! empty( $valid ) && ! empty( $subscription->profile_id ) ) { |
|
237 | - return wpinv_authorizenet_cancel_subscription( $subscription->profile_id ); |
|
235 | +function wpinv_recurring_cancel_authorizenet_subscription($subscription, $valid = false) { |
|
236 | + if (!empty($valid) && !empty($subscription->profile_id)) { |
|
237 | + return wpinv_authorizenet_cancel_subscription($subscription->profile_id); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | return false; |
241 | 241 | } |
242 | -add_action( 'wpinv_recurring_cancel_authorizenet_subscription', 'wpinv_recurring_cancel_authorizenet_subscription', 10, 2 ); |
|
242 | +add_action('wpinv_recurring_cancel_authorizenet_subscription', 'wpinv_recurring_cancel_authorizenet_subscription', 10, 2); |
|
243 | 243 | |
244 | -function wpinv_authorizenet_valid_ipn( $md5_hash, $transaction_id, $amount ) { |
|
245 | - $authorizenet_md5_hash = wpinv_get_option( 'authorizenet_md5_hash' ); |
|
246 | - if ( empty( $authorizenet_md5_hash ) ) { |
|
244 | +function wpinv_authorizenet_valid_ipn($md5_hash, $transaction_id, $amount) { |
|
245 | + $authorizenet_md5_hash = wpinv_get_option('authorizenet_md5_hash'); |
|
246 | + if (empty($authorizenet_md5_hash)) { |
|
247 | 247 | return true; |
248 | 248 | } |
249 | 249 | |
250 | - $compare_md5 = strtoupper( md5( $authorizenet_md5_hash . $transaction_id . $amount ) ); |
|
250 | + $compare_md5 = strtoupper(md5($authorizenet_md5_hash . $transaction_id . $amount)); |
|
251 | 251 | |
252 | - return hash_equals( $compare_md5, $md5_hash ); |
|
252 | + return hash_equals($compare_md5, $md5_hash); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | function wpinv_authorizenet_AIM() { |
256 | - if ( !class_exists( 'AuthorizeNetException' ) ) { |
|
257 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php'; |
|
256 | + if (!class_exists('AuthorizeNetException')) { |
|
257 | + require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php'; |
|
258 | 258 | } |
259 | 259 | |
260 | - $authorizeAIM = new AuthorizeNetAIM( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ) ); |
|
260 | + $authorizeAIM = new AuthorizeNetAIM(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key')); |
|
261 | 261 | |
262 | - if ( wpinv_is_test_mode( 'authorizenet' ) ) { |
|
263 | - $authorizeAIM->setSandbox( true ); |
|
262 | + if (wpinv_is_test_mode('authorizenet')) { |
|
263 | + $authorizeAIM->setSandbox(true); |
|
264 | 264 | } else { |
265 | - $authorizeAIM->setSandbox( false ); |
|
265 | + $authorizeAIM->setSandbox(false); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | $authorizeAIM->customer_ip = wpinv_get_ip(); |
@@ -271,250 +271,250 @@ discard block |
||
271 | 271 | } |
272 | 272 | |
273 | 273 | function wpinv_authorizenet_XML() { |
274 | - if ( !class_exists( 'AuthnetXML' ) ) { |
|
275 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php'; |
|
274 | + if (!class_exists('AuthnetXML')) { |
|
275 | + require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php'; |
|
276 | 276 | } |
277 | 277 | |
278 | - $authnetXML = new AuthnetXML( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ), (bool)wpinv_is_test_mode( 'authorizenet' ) ); |
|
278 | + $authnetXML = new AuthnetXML(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'), (bool)wpinv_is_test_mode('authorizenet')); |
|
279 | 279 | |
280 | 280 | return $authnetXML; |
281 | 281 | } |
282 | 282 | |
283 | -function wpinv_authorizenet_handle_response( $response, $invoice, $card_info = array() ) { |
|
284 | - if ( empty( $response ) || empty( $invoice ) ) { |
|
283 | +function wpinv_authorizenet_handle_response($response, $invoice, $card_info = array()) { |
|
284 | + if (empty($response) || empty($invoice)) { |
|
285 | 285 | return false; |
286 | 286 | } |
287 | 287 | |
288 | - if ( $invoice->is_recurring() && !empty( $response->approved ) ) { |
|
289 | - $subscription = wpinv_authorizenet_create_new_subscription( $invoice, $response, $card_info ); |
|
288 | + if ($invoice->is_recurring() && !empty($response->approved)) { |
|
289 | + $subscription = wpinv_authorizenet_create_new_subscription($invoice, $response, $card_info); |
|
290 | 290 | $success = false; |
291 | - if ( wpinv_is_test_mode( 'authorizenet' ) ) { |
|
291 | + if (wpinv_is_test_mode('authorizenet')) { |
|
292 | 292 | $success = true; |
293 | 293 | } else { |
294 | 294 | $success = $subscription->isSuccessful(); |
295 | 295 | } |
296 | 296 | |
297 | - if ( !empty( $subscription ) && $success ) { |
|
298 | - do_action( 'wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet' ); |
|
297 | + if (!empty($subscription) && $success) { |
|
298 | + do_action('wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet'); |
|
299 | 299 | |
300 | - wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ); |
|
300 | + wpinv_authorizenet_subscription_record_signup($subscription, $invoice); |
|
301 | 301 | |
302 | - do_action( 'wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet' ); |
|
302 | + do_action('wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet'); |
|
303 | 303 | } else { |
304 | - if ( isset( $subscription->messages->message ) ) { |
|
304 | + if (isset($subscription->messages->message)) { |
|
305 | 305 | $error = $subscription->messages->message->code . ': ' . $subscription->messages->message->text; |
306 | - wpinv_set_error( 'wpinv_authorize_recurring_error', $error, 'invoicing' ); |
|
306 | + wpinv_set_error('wpinv_authorize_recurring_error', $error, 'invoicing'); |
|
307 | 307 | } else { |
308 | - $error = __( 'Your subscription cannot be created due to an error.', 'invoicing' ); |
|
309 | - wpinv_set_error( 'wpinv_authorize_recurring_error', $error ); |
|
308 | + $error = __('Your subscription cannot be created due to an error.', 'invoicing'); |
|
309 | + wpinv_set_error('wpinv_authorize_recurring_error', $error); |
|
310 | 310 | } |
311 | 311 | |
312 | - wpinv_record_gateway_error( $error, $subscription ); |
|
312 | + wpinv_record_gateway_error($error, $subscription); |
|
313 | 313 | |
314 | - wpinv_insert_payment_note( $invoice->ID, wp_sprintf( __( 'Authorize.Net subscription error occurred. %s', 'invoicing' ), $error ), '', '', true ); |
|
314 | + wpinv_insert_payment_note($invoice->ID, wp_sprintf(__('Authorize.Net subscription error occurred. %s', 'invoicing'), $error), '', '', true); |
|
315 | 315 | } |
316 | 316 | } |
317 | 317 | } |
318 | -add_action( 'wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3 ); |
|
318 | +add_action('wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3); |
|
319 | 319 | |
320 | -function wpinv_authorizenet_create_new_subscription( $invoice, $response = array(), $card_info = array() ) { |
|
321 | - if ( empty( $invoice ) ) { |
|
320 | +function wpinv_authorizenet_create_new_subscription($invoice, $response = array(), $card_info = array()) { |
|
321 | + if (empty($invoice)) { |
|
322 | 322 | return false; |
323 | 323 | } |
324 | 324 | |
325 | - $params = wpinv_authorizenet_generate_subscription_params( $invoice, $card_info, $response ); |
|
325 | + $params = wpinv_authorizenet_generate_subscription_params($invoice, $card_info, $response); |
|
326 | 326 | |
327 | 327 | try { |
328 | 328 | $authnetXML = wpinv_authorizenet_XML(); |
329 | - $authnetXML->ARBCreateSubscriptionRequest( $params ); |
|
330 | - } catch( Exception $e ) { |
|
329 | + $authnetXML->ARBCreateSubscriptionRequest($params); |
|
330 | + } catch (Exception $e) { |
|
331 | 331 | $authnetXML = array(); |
332 | - wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) ); |
|
332 | + wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing')); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | return $authnetXML; |
336 | 336 | } |
337 | 337 | |
338 | -function wpinv_authorizenet_generate_subscription_params( $invoice, $card_info = array(), $response = array() ) { |
|
339 | - if ( empty( $invoice ) ) { |
|
338 | +function wpinv_authorizenet_generate_subscription_params($invoice, $card_info = array(), $response = array()) { |
|
339 | + if (empty($invoice)) { |
|
340 | 340 | return false; |
341 | 341 | } |
342 | 342 | |
343 | - $subscription_item = $invoice->get_recurring( true ); |
|
344 | - if ( empty( $subscription_item->ID ) ) { |
|
343 | + $subscription_item = $invoice->get_recurring(true); |
|
344 | + if (empty($subscription_item->ID)) { |
|
345 | 345 | return false; |
346 | 346 | } |
347 | 347 | |
348 | - $item = $invoice->get_recurring( true ); |
|
348 | + $item = $invoice->get_recurring(true); |
|
349 | 349 | |
350 | - if ( empty( $item ) ) { |
|
350 | + if (empty($item)) { |
|
351 | 351 | $name = ''; |
352 | 352 | } |
353 | 353 | |
354 | - if ( !( $name = $item->get_name() ) ) { |
|
354 | + if (!($name = $item->get_name())) { |
|
355 | 355 | $name = $item->post_name; |
356 | 356 | } |
357 | 357 | |
358 | - $card_details = wpinv_authorizenet_generate_card_info( $card_info ); |
|
358 | + $card_details = wpinv_authorizenet_generate_card_info($card_info); |
|
359 | 359 | $subscription_name = $invoice->get_subscription_name(); |
360 | - $initial_amount = wpinv_round_amount( $invoice->get_total() ); |
|
361 | - $recurring_amount = wpinv_round_amount( $invoice->get_recurring_details( 'total' ) ); |
|
360 | + $initial_amount = wpinv_round_amount($invoice->get_total()); |
|
361 | + $recurring_amount = wpinv_round_amount($invoice->get_recurring_details('total')); |
|
362 | 362 | $interval = $subscription_item->get_recurring_interval(); |
363 | 363 | $period = $subscription_item->get_recurring_period(); |
364 | 364 | $bill_times = (int)$subscription_item->get_recurring_limit(); |
365 | 365 | $bill_times = $bill_times > 0 ? $bill_times : 9999; |
366 | 366 | |
367 | - $time_period = wpinv_authorizenet_get_time_period( $interval, $period ); |
|
367 | + $time_period = wpinv_authorizenet_get_time_period($interval, $period); |
|
368 | 368 | $interval = $time_period['interval']; |
369 | 369 | $period = $time_period['period']; |
370 | 370 | |
371 | 371 | $current_tz = date_default_timezone_get(); |
372 | - date_default_timezone_set( 'America/Denver' ); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts. |
|
373 | - $today = date( 'Y-m-d' ); |
|
374 | - date_default_timezone_set( $current_tz ); |
|
372 | + date_default_timezone_set('America/Denver'); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts. |
|
373 | + $today = date('Y-m-d'); |
|
374 | + date_default_timezone_set($current_tz); |
|
375 | 375 | |
376 | 376 | $free_trial = $invoice->is_free_trial(); |
377 | - if ( $free_trial && $subscription_item->has_free_trial() ) { |
|
377 | + if ($free_trial && $subscription_item->has_free_trial()) { |
|
378 | 378 | $trial_interval = $subscription_item->get_trial_interval(); |
379 | - $trial_period = $subscription_item->get_trial_period( true ); |
|
379 | + $trial_period = $subscription_item->get_trial_period(true); |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | $subscription = array(); |
383 | 383 | $subscription['name'] = $subscription_name; |
384 | 384 | |
385 | 385 | $subscription['paymentSchedule'] = array( |
386 | - 'interval' => array( 'length' => $interval, 'unit' => $period ), |
|
386 | + 'interval' => array('length' => $interval, 'unit' => $period), |
|
387 | 387 | 'startDate' => $today, |
388 | 388 | 'totalOccurrences' => $bill_times, |
389 | - 'trialOccurrences' => $free_trial || ( $initial_amount != $recurring_amount ) ? 1 : 0, |
|
389 | + 'trialOccurrences' => $free_trial || ($initial_amount != $recurring_amount) ? 1 : 0, |
|
390 | 390 | ); |
391 | 391 | |
392 | 392 | $subscription['amount'] = $recurring_amount; |
393 | 393 | $subscription['trialAmount'] = $initial_amount; |
394 | - $subscription['payment'] = array( 'creditCard' => $card_details ); |
|
395 | - $subscription['order'] = array( 'invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number() ); |
|
396 | - $subscription['customer'] = array( 'id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone ); |
|
394 | + $subscription['payment'] = array('creditCard' => $card_details); |
|
395 | + $subscription['order'] = array('invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number()); |
|
396 | + $subscription['customer'] = array('id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone); |
|
397 | 397 | |
398 | 398 | $subscription['billTo'] = array( |
399 | 399 | 'firstName' => $invoice->get_first_name(), |
400 | 400 | 'lastName' => $invoice->get_last_name(), |
401 | 401 | 'company' => $invoice->company, |
402 | - 'address' => wp_strip_all_tags( $invoice->get_address(), true ), |
|
402 | + 'address' => wp_strip_all_tags($invoice->get_address(), true), |
|
403 | 403 | 'city' => $invoice->city, |
404 | 404 | 'state' => $invoice->state, |
405 | 405 | 'zip' => $invoice->zip, |
406 | 406 | 'country' => $invoice->country, |
407 | 407 | ); |
408 | 408 | |
409 | - $params = array( 'subscription' => $subscription ); |
|
409 | + $params = array('subscription' => $subscription); |
|
410 | 410 | |
411 | - return apply_filters( 'wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response ); |
|
411 | + return apply_filters('wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response); |
|
412 | 412 | } |
413 | 413 | |
414 | -function wpinv_authorizenet_generate_card_info( $card_info = array() ) { |
|
415 | - $card_defaults = array( |
|
414 | +function wpinv_authorizenet_generate_card_info($card_info = array()) { |
|
415 | + $card_defaults = array( |
|
416 | 416 | 'cc_owner' => null, |
417 | 417 | 'cc_number' => null, |
418 | 418 | 'cc_expire_month' => null, |
419 | 419 | 'cc_expire_year' => null, |
420 | 420 | 'cc_cvv2' => null, |
421 | 421 | ); |
422 | - $card_info = wp_parse_args( $card_info, $card_defaults ); |
|
422 | + $card_info = wp_parse_args($card_info, $card_defaults); |
|
423 | 423 | |
424 | 424 | $card_details = array( |
425 | - 'cardNumber' => str_replace( ' ', '', sanitize_text_field( $card_info['cc_number'] ) ), |
|
426 | - 'expirationDate' => sanitize_text_field( $card_info['cc_expire_month'] ) . sanitize_text_field( $card_info['cc_expire_year'] ), |
|
427 | - 'cardCode' => sanitize_text_field( $card_info['cc_cvv2'] ), |
|
425 | + 'cardNumber' => str_replace(' ', '', sanitize_text_field($card_info['cc_number'])), |
|
426 | + 'expirationDate' => sanitize_text_field($card_info['cc_expire_month']) . sanitize_text_field($card_info['cc_expire_year']), |
|
427 | + 'cardCode' => sanitize_text_field($card_info['cc_cvv2']), |
|
428 | 428 | ); |
429 | 429 | |
430 | 430 | return $card_details; |
431 | 431 | } |
432 | 432 | |
433 | -function wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ) { |
|
434 | - $parent_invoice_id = absint( $invoice->ID ); |
|
433 | +function wpinv_authorizenet_subscription_record_signup($subscription, $invoice) { |
|
434 | + $parent_invoice_id = absint($invoice->ID); |
|
435 | 435 | |
436 | - if( empty( $parent_invoice_id ) ) { |
|
436 | + if (empty($parent_invoice_id)) { |
|
437 | 437 | return; |
438 | 438 | } |
439 | 439 | |
440 | - $invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
441 | - if ( empty( $invoice ) ) { |
|
440 | + $invoice = wpinv_get_invoice($parent_invoice_id); |
|
441 | + if (empty($invoice)) { |
|
442 | 442 | return; |
443 | 443 | } |
444 | 444 | |
445 | 445 | $subscriptionId = (array)$subscription->subscriptionId; |
446 | - $subscription_id = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $parent_invoice_id; |
|
446 | + $subscription_id = !empty($subscriptionId[0]) ? $subscriptionId[0] : $parent_invoice_id; |
|
447 | 447 | |
448 | - $subscription = wpinv_get_authorizenet_subscription( $subscription, $parent_invoice_id ); |
|
448 | + $subscription = wpinv_get_authorizenet_subscription($subscription, $parent_invoice_id); |
|
449 | 449 | |
450 | - if ( false === $subscription ) { |
|
450 | + if (false === $subscription) { |
|
451 | 451 | return; |
452 | 452 | } |
453 | 453 | |
454 | 454 | // Set payment to complete |
455 | - wpinv_update_payment_status( $subscription->parent_payment_id, 'publish' ); |
|
455 | + wpinv_update_payment_status($subscription->parent_payment_id, 'publish'); |
|
456 | 456 | sleep(1); |
457 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'Authorize.Net Subscription ID: %s', 'invoicing' ) , $subscription_id ), '', '', true ); |
|
458 | - update_post_meta($parent_invoice_id,'_wpinv_subscr_profile_id', $subscription_id); |
|
457 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('Authorize.Net Subscription ID: %s', 'invoicing'), $subscription_id), '', '', true); |
|
458 | + update_post_meta($parent_invoice_id, '_wpinv_subscr_profile_id', $subscription_id); |
|
459 | 459 | |
460 | 460 | $status = 'trialling' == $subscription->status ? 'trialling' : 'active'; |
461 | - $diff_days = absint( ( ( strtotime( $subscription->expiration ) - strtotime( $subscription->created ) ) / DAY_IN_SECONDS ) ); |
|
462 | - $created = date_i18n( 'Y-m-d H:i:s' ); |
|
463 | - $expiration = date_i18n( 'Y-m-d 23:59:59', ( strtotime( $created ) + ( $diff_days * DAY_IN_SECONDS ) ) ); |
|
461 | + $diff_days = absint(((strtotime($subscription->expiration) - strtotime($subscription->created)) / DAY_IN_SECONDS)); |
|
462 | + $created = date_i18n('Y-m-d H:i:s'); |
|
463 | + $expiration = date_i18n('Y-m-d 23:59:59', (strtotime($created) + ($diff_days * DAY_IN_SECONDS))); |
|
464 | 464 | |
465 | 465 | // Retrieve pending subscription from database and update it's status to active and set proper profile ID |
466 | - $subscription->update( array( 'profile_id' => $subscription_id, 'status' => $status, 'created' => $created, 'expiration' => $expiration ) ); |
|
466 | + $subscription->update(array('profile_id' => $subscription_id, 'status' => $status, 'created' => $created, 'expiration' => $expiration)); |
|
467 | 467 | } |
468 | 468 | |
469 | -function wpinv_authorizenet_validate_checkout( $valid_data, $post ) { |
|
470 | - if ( !empty( $post['wpi-gateway'] ) && $post['wpi-gateway'] == 'authorizenet' ) { |
|
469 | +function wpinv_authorizenet_validate_checkout($valid_data, $post) { |
|
470 | + if (!empty($post['wpi-gateway']) && $post['wpi-gateway'] == 'authorizenet') { |
|
471 | 471 | $error = false; |
472 | 472 | |
473 | - if ( empty( $post['authorizenet']['cc_owner'] ) ) { |
|
473 | + if (empty($post['authorizenet']['cc_owner'])) { |
|
474 | 474 | $error = true; |
475 | - wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing')); |
|
475 | + wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing')); |
|
476 | 476 | } |
477 | - if ( empty( $post['authorizenet']['cc_number'] ) ) { |
|
477 | + if (empty($post['authorizenet']['cc_number'])) { |
|
478 | 478 | $error = true; |
479 | - wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing')); |
|
479 | + wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing')); |
|
480 | 480 | } |
481 | - if ( empty( $post['authorizenet']['cc_expire_month'] ) ) { |
|
481 | + if (empty($post['authorizenet']['cc_expire_month'])) { |
|
482 | 482 | $error = true; |
483 | - wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing')); |
|
483 | + wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing')); |
|
484 | 484 | } |
485 | - if ( empty( $post['authorizenet']['cc_expire_year'] ) ) { |
|
485 | + if (empty($post['authorizenet']['cc_expire_year'])) { |
|
486 | 486 | $error = true; |
487 | - wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing')); |
|
487 | + wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing')); |
|
488 | 488 | } |
489 | - if ( empty( $post['authorizenet']['cc_cvv2'] ) ) { |
|
489 | + if (empty($post['authorizenet']['cc_cvv2'])) { |
|
490 | 490 | $error = true; |
491 | - wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) ); |
|
491 | + wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing')); |
|
492 | 492 | } |
493 | 493 | |
494 | - if ( $error ) { |
|
494 | + if ($error) { |
|
495 | 495 | return; |
496 | 496 | } |
497 | 497 | |
498 | 498 | $invoice = wpinv_get_invoice_cart(); |
499 | 499 | |
500 | - if ( !empty( $invoice ) && $subscription_item = $invoice->get_recurring( true ) ) { |
|
501 | - $subscription_item = $invoice->get_recurring( true ); |
|
500 | + if (!empty($invoice) && $subscription_item = $invoice->get_recurring(true)) { |
|
501 | + $subscription_item = $invoice->get_recurring(true); |
|
502 | 502 | |
503 | 503 | $interval = $subscription_item->get_recurring_interval(); |
504 | 504 | $period = $subscription_item->get_recurring_period(); |
505 | 505 | |
506 | - if ( $period == 'D' && ( $interval < 7 || $interval > 365 ) ) { |
|
507 | - wpinv_set_error( 'authorizenet_subscription_error', __( 'Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing' ) ); |
|
506 | + if ($period == 'D' && ($interval < 7 || $interval > 365)) { |
|
507 | + wpinv_set_error('authorizenet_subscription_error', __('Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing')); |
|
508 | 508 | } |
509 | 509 | } |
510 | 510 | } |
511 | 511 | } |
512 | -add_action( 'wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2 ); |
|
512 | +add_action('wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2); |
|
513 | 513 | |
514 | -function wpinv_authorizenet_get_time_period( $subscription_interval, $subscription_period ) { |
|
515 | - $subscription_interval = absint( $subscription_interval ); |
|
514 | +function wpinv_authorizenet_get_time_period($subscription_interval, $subscription_period) { |
|
515 | + $subscription_interval = absint($subscription_interval); |
|
516 | 516 | |
517 | - switch( $subscription_period ) { |
|
517 | + switch ($subscription_period) { |
|
518 | 518 | case 'W': |
519 | 519 | case 'week': |
520 | 520 | case 'weeks': |
@@ -524,14 +524,14 @@ discard block |
||
524 | 524 | case 'M': |
525 | 525 | case 'month': |
526 | 526 | case 'months': |
527 | - if ( $subscription_interval > 12 ) { |
|
527 | + if ($subscription_interval > 12) { |
|
528 | 528 | $subscription_interval = 12; |
529 | 529 | } |
530 | 530 | |
531 | 531 | $interval = $subscription_interval; |
532 | 532 | $period = 'months'; |
533 | 533 | |
534 | - if ( !( $subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12 ) ) { |
|
534 | + if (!($subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12)) { |
|
535 | 535 | $interval = $subscription_interval * 30; |
536 | 536 | $period = 'days'; |
537 | 537 | } |
@@ -548,30 +548,30 @@ discard block |
||
548 | 548 | break; |
549 | 549 | } |
550 | 550 | |
551 | - return compact( 'interval', 'period' ); |
|
551 | + return compact('interval', 'period'); |
|
552 | 552 | } |
553 | 553 | |
554 | 554 | function wpinv_authorizenet_process_ipn() { |
555 | - if ( !( !empty( $_REQUEST['wpi-gateway'] ) && $_REQUEST['wpi-gateway'] == 'authorizenet' ) ) { |
|
555 | + if (!(!empty($_REQUEST['wpi-gateway']) && $_REQUEST['wpi-gateway'] == 'authorizenet')) { |
|
556 | 556 | return; |
557 | 557 | } |
558 | 558 | |
559 | - $subscription_id = !empty( $_POST['x_subscription_id'] ) ? intval( $_POST['x_subscription_id'] ) : false; |
|
559 | + $subscription_id = !empty($_POST['x_subscription_id']) ? intval($_POST['x_subscription_id']) : false; |
|
560 | 560 | |
561 | - if ( $subscription_id ) { |
|
562 | - $response_code = intval( $_POST['x_response_code'] ); |
|
563 | - $reason_code = intval( $_POST['x_response_reason_code'] ); |
|
561 | + if ($subscription_id) { |
|
562 | + $response_code = intval($_POST['x_response_code']); |
|
563 | + $reason_code = intval($_POST['x_response_reason_code']); |
|
564 | 564 | |
565 | - $subscription = new WPInv_Subscription( $subscription_id, true ); |
|
565 | + $subscription = new WPInv_Subscription($subscription_id, true); |
|
566 | 566 | |
567 | - if ( !$subscription->id ) { |
|
567 | + if (!$subscription->id) { |
|
568 | 568 | return; |
569 | 569 | } |
570 | 570 | |
571 | - if ( 1 == $response_code ) { |
|
571 | + if (1 == $response_code) { |
|
572 | 572 | // Approved |
573 | - $transaction_id = sanitize_text_field( $_POST['x_trans_id'] ); |
|
574 | - $renewal_amount = sanitize_text_field( $_POST['x_amount'] ); |
|
573 | + $transaction_id = sanitize_text_field($_POST['x_trans_id']); |
|
574 | + $renewal_amount = sanitize_text_field($_POST['x_amount']); |
|
575 | 575 | |
576 | 576 | $args = array( |
577 | 577 | 'amount' => $renewal_amount, |
@@ -579,63 +579,63 @@ discard block |
||
579 | 579 | 'gateway' => 'authorizenet' |
580 | 580 | ); |
581 | 581 | |
582 | - $subscription->add_payment( $args ); |
|
582 | + $subscription->add_payment($args); |
|
583 | 583 | $subscription->renew(); |
584 | 584 | |
585 | - do_action( 'wpinv_recurring_authorizenet_silent_post_payment', $subscription ); |
|
586 | - do_action( 'wpinv_authorizenet_renewal_payment', $subscription ); |
|
587 | - } else if ( 2 == $response_code ) { |
|
585 | + do_action('wpinv_recurring_authorizenet_silent_post_payment', $subscription); |
|
586 | + do_action('wpinv_authorizenet_renewal_payment', $subscription); |
|
587 | + } else if (2 == $response_code) { |
|
588 | 588 | // Declined |
589 | 589 | $subscription->failing(); |
590 | - do_action( 'wpinv_authorizenet_renewal_payment_failed', $subscription ); |
|
591 | - do_action( 'wpinv_authorizenet_renewal_error', $subscription ); |
|
592 | - } else if ( 3 == $response_code || 8 == $reason_code ) { |
|
590 | + do_action('wpinv_authorizenet_renewal_payment_failed', $subscription); |
|
591 | + do_action('wpinv_authorizenet_renewal_error', $subscription); |
|
592 | + } else if (3 == $response_code || 8 == $reason_code) { |
|
593 | 593 | // An expired card |
594 | 594 | $subscription->failing(); |
595 | - do_action( 'wpinv_authorizenet_renewal_payment_failed', $subscription ); |
|
596 | - do_action( 'wpinv_authorizenet_renewal_error', $subscription ); |
|
595 | + do_action('wpinv_authorizenet_renewal_payment_failed', $subscription); |
|
596 | + do_action('wpinv_authorizenet_renewal_error', $subscription); |
|
597 | 597 | } else { |
598 | 598 | // Other Error |
599 | - do_action( 'wpinv_authorizenet_renewal_payment_error', $subscription ); |
|
599 | + do_action('wpinv_authorizenet_renewal_payment_error', $subscription); |
|
600 | 600 | } |
601 | 601 | |
602 | 602 | exit; |
603 | 603 | } |
604 | 604 | } |
605 | -add_action( 'wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn' ); |
|
605 | +add_action('wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn'); |
|
606 | 606 | |
607 | 607 | /** |
608 | 608 | * Retrieve the subscription |
609 | 609 | */ |
610 | -function wpinv_get_authorizenet_subscription( $subscription_data = array(), $invoice_id ) { |
|
611 | - $parent_invoice_id = absint( $invoice_id ); |
|
610 | +function wpinv_get_authorizenet_subscription($subscription_data = array(), $invoice_id) { |
|
611 | + $parent_invoice_id = absint($invoice_id); |
|
612 | 612 | |
613 | - if ( empty( $subscription_data ) ) { |
|
613 | + if (empty($subscription_data)) { |
|
614 | 614 | return false; |
615 | 615 | } |
616 | 616 | |
617 | - if ( empty( $parent_invoice_id ) ) { |
|
617 | + if (empty($parent_invoice_id)) { |
|
618 | 618 | return false; |
619 | 619 | } |
620 | 620 | |
621 | - $invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
622 | - if ( empty( $invoice ) ) { |
|
621 | + $invoice = wpinv_get_invoice($parent_invoice_id); |
|
622 | + if (empty($invoice)) { |
|
623 | 623 | return false; |
624 | 624 | } |
625 | 625 | |
626 | 626 | $subscriptionId = (array)$subscription_data->subscriptionId; |
627 | - $subscription_id = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $parent_invoice_id; |
|
627 | + $subscription_id = !empty($subscriptionId[0]) ? $subscriptionId[0] : $parent_invoice_id; |
|
628 | 628 | |
629 | - $subscription = new WPInv_Subscription( $subscription_id, true ); |
|
629 | + $subscription = new WPInv_Subscription($subscription_id, true); |
|
630 | 630 | |
631 | - if ( ! $subscription || $subscription->id < 1 ) { |
|
631 | + if (!$subscription || $subscription->id < 1) { |
|
632 | 632 | $subs_db = new WPInv_Subscriptions_DB; |
633 | - $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $parent_invoice_id, 'number' => 1 ) ); |
|
634 | - $subscription = reset( $subs ); |
|
633 | + $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $parent_invoice_id, 'number' => 1)); |
|
634 | + $subscription = reset($subs); |
|
635 | 635 | |
636 | - if ( $subscription && $subscription->id > 0 ) { |
|
636 | + if ($subscription && $subscription->id > 0) { |
|
637 | 637 | // Update the profile ID so it is set for future renewals |
638 | - $subscription->update( array( 'profile_id' => sanitize_text_field( $subscription_id ) ) ); |
|
638 | + $subscription->update(array('profile_id' => sanitize_text_field($subscription_id))); |
|
639 | 639 | } else { |
640 | 640 | // No subscription found with a matching payment ID, bail |
641 | 641 | return false; |
@@ -646,67 +646,67 @@ discard block |
||
646 | 646 | } |
647 | 647 | |
648 | 648 | function wpinv_is_authorizenet_valid_for_use() { |
649 | - return in_array( wpinv_get_currency(), apply_filters( 'wpinv_authorizenet_supported_currencies', array( 'AUD', 'CAD', 'CHF', 'DKK', 'EUR', 'GBP', 'JPY', 'NOK', 'NZD', 'PLN', 'SEK', 'USD', 'ZAR' ) ) ); |
|
649 | + return in_array(wpinv_get_currency(), apply_filters('wpinv_authorizenet_supported_currencies', array('AUD', 'CAD', 'CHF', 'DKK', 'EUR', 'GBP', 'JPY', 'NOK', 'NZD', 'PLN', 'SEK', 'USD', 'ZAR'))); |
|
650 | 650 | } |
651 | -function wpinv_check_authorizenet_currency_support( $gateway_list ) { |
|
652 | - if ( isset( $gateway_list['authorizenet'] ) && ! wpinv_is_authorizenet_valid_for_use() ) { |
|
653 | - unset( $gateway_list['authorizenet'] ); |
|
651 | +function wpinv_check_authorizenet_currency_support($gateway_list) { |
|
652 | + if (isset($gateway_list['authorizenet']) && !wpinv_is_authorizenet_valid_for_use()) { |
|
653 | + unset($gateway_list['authorizenet']); |
|
654 | 654 | } |
655 | 655 | return $gateway_list; |
656 | 656 | } |
657 | -add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_authorizenet_currency_support', 10, 1 ); |
|
657 | +add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_authorizenet_currency_support', 10, 1); |
|
658 | 658 | |
659 | -function wpinv_authorizenet_link_transaction_id( $transaction_id, $invoice_id, $invoice ) { |
|
660 | - if ( $transaction_id == $invoice_id ) { |
|
659 | +function wpinv_authorizenet_link_transaction_id($transaction_id, $invoice_id, $invoice) { |
|
660 | + if ($transaction_id == $invoice_id) { |
|
661 | 661 | $link = $transaction_id; |
662 | 662 | } else { |
663 | - if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) { |
|
663 | + if (!empty($invoice) && !empty($invoice->mode)) { |
|
664 | 664 | $mode = $invoice->mode; |
665 | 665 | } else { |
666 | - $mode = wpinv_is_test_mode( 'authorizenet' ) ? 'test' : 'live'; |
|
666 | + $mode = wpinv_is_test_mode('authorizenet') ? 'test' : 'live'; |
|
667 | 667 | } |
668 | 668 | |
669 | 669 | $url = $mode == 'test' ? 'https://sandbox.authorize.net/' : 'https://authorize.net/'; |
670 | 670 | $url .= 'ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=' . $transaction_id; |
671 | 671 | |
672 | - $link = '<a href="' . esc_url( $url ) . '" target="_blank">' . $transaction_id . '</a>'; |
|
672 | + $link = '<a href="' . esc_url($url) . '" target="_blank">' . $transaction_id . '</a>'; |
|
673 | 673 | } |
674 | 674 | |
675 | - return apply_filters( 'wpinv_authorizenet_link_payment_details_transaction_id', $link, $transaction_id, $invoice ); |
|
675 | + return apply_filters('wpinv_authorizenet_link_payment_details_transaction_id', $link, $transaction_id, $invoice); |
|
676 | 676 | } |
677 | -add_filter( 'wpinv_payment_details_transaction_id-authorizenet', 'wpinv_authorizenet_link_transaction_id', 10, 3 ); |
|
677 | +add_filter('wpinv_payment_details_transaction_id-authorizenet', 'wpinv_authorizenet_link_transaction_id', 10, 3); |
|
678 | 678 | |
679 | -function wpinv_authorizenet_transaction_id_link( $transaction_id, $subscription ) { |
|
680 | - if ( ! empty( $transaction_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) { |
|
681 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
679 | +function wpinv_authorizenet_transaction_id_link($transaction_id, $subscription) { |
|
680 | + if (!empty($transaction_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) { |
|
681 | + $invoice = wpinv_get_invoice($invoice_id); |
|
682 | 682 | |
683 | - if ( ! empty( $invoice ) ) { |
|
684 | - return wpinv_authorizenet_link_transaction_id( $transaction_id, $invoice_id, $invoice ); |
|
683 | + if (!empty($invoice)) { |
|
684 | + return wpinv_authorizenet_link_transaction_id($transaction_id, $invoice_id, $invoice); |
|
685 | 685 | } |
686 | 686 | } |
687 | 687 | |
688 | 688 | return $transaction_id; |
689 | 689 | } |
690 | -add_filter( 'wpinv_subscription_transaction_link_authorizenet', 'wpinv_authorizenet_transaction_id_link', 10, 2 ); |
|
690 | +add_filter('wpinv_subscription_transaction_link_authorizenet', 'wpinv_authorizenet_transaction_id_link', 10, 2); |
|
691 | 691 | |
692 | -function wpinv_authorizenet_profile_id_link( $profile_id, $subscription ) { |
|
692 | +function wpinv_authorizenet_profile_id_link($profile_id, $subscription) { |
|
693 | 693 | $link = $profile_id; |
694 | 694 | |
695 | - if ( ! empty( $profile_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) { |
|
696 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
695 | + if (!empty($profile_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) { |
|
696 | + $invoice = wpinv_get_invoice($invoice_id); |
|
697 | 697 | |
698 | - if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) { |
|
698 | + if (!empty($invoice) && !empty($invoice->mode)) { |
|
699 | 699 | $mode = $invoice->mode; |
700 | 700 | } else { |
701 | - $mode = wpinv_is_test_mode( 'authorizenet' ) ? 'test' : 'live'; |
|
701 | + $mode = wpinv_is_test_mode('authorizenet') ? 'test' : 'live'; |
|
702 | 702 | } |
703 | 703 | |
704 | 704 | $url = $mode == 'test' ? 'https://sandbox.authorize.net/' : 'https://authorize.net/'; |
705 | 705 | $url .= 'ui/themes/sandbox/ARB/SubscriptionDetail.aspx?SubscrID=' . $profile_id; |
706 | 706 | |
707 | - $link = '<a href="' . esc_url( $url ) . '" target="_blank">' . $profile_id . '</a>'; |
|
707 | + $link = '<a href="' . esc_url($url) . '" target="_blank">' . $profile_id . '</a>'; |
|
708 | 708 | } |
709 | 709 | |
710 | - return apply_filters( 'wpinv_authorizenet_profile_id_link', $link, $profile_id, $subscription ); |
|
710 | + return apply_filters('wpinv_authorizenet_profile_id_link', $link, $profile_id, $subscription); |
|
711 | 711 | } |
712 | -add_filter( 'wpinv_subscription_profile_link_authorizenet', 'wpinv_authorizenet_profile_id_link', 10, 2 ); |
|
713 | 712 | \ No newline at end of file |
713 | +add_filter('wpinv_subscription_profile_link_authorizenet', 'wpinv_authorizenet_profile_id_link', 10, 2); |
|
714 | 714 | \ No newline at end of file |
@@ -1,47 +1,47 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | class WPInv_Meta_Box_Items { |
8 | - public static function output( $post ) { |
|
8 | + public static function output($post) { |
|
9 | 9 | global $wpinv_euvat, $ajax_cart_details; |
10 | 10 | |
11 | - $post_id = !empty( $post->ID ) ? $post->ID : 0; |
|
12 | - $invoice = new WPInv_Invoice( $post_id ); |
|
11 | + $post_id = !empty($post->ID) ? $post->ID : 0; |
|
12 | + $invoice = new WPInv_Invoice($post_id); |
|
13 | 13 | $ajax_cart_details = $invoice->get_cart_details(); |
14 | - $subtotal = $invoice->get_subtotal( true ); |
|
14 | + $subtotal = $invoice->get_subtotal(true); |
|
15 | 15 | $discount_raw = $invoice->get_discount(); |
16 | - $discount = wpinv_price( $discount_raw, $invoice->get_currency() ); |
|
16 | + $discount = wpinv_price($discount_raw, $invoice->get_currency()); |
|
17 | 17 | $discounts = $discount_raw > 0 ? $invoice->get_discounts() : ''; |
18 | - $tax = $invoice->get_tax( true ); |
|
19 | - $total = $invoice->get_total( true ); |
|
18 | + $tax = $invoice->get_tax(true); |
|
19 | + $total = $invoice->get_total(true); |
|
20 | 20 | $item_quantities = wpinv_item_quantities_enabled(); |
21 | 21 | $use_taxes = wpinv_use_taxes(); |
22 | - if ( !$use_taxes && (float)$invoice->get_tax() > 0 ) { |
|
22 | + if (!$use_taxes && (float)$invoice->get_tax() > 0) { |
|
23 | 23 | $use_taxes = true; |
24 | 24 | } |
25 | - $item_types = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post ); |
|
25 | + $item_types = apply_filters('wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post); |
|
26 | 26 | $is_recurring = $invoice->is_recurring(); |
27 | 27 | $post_type_object = get_post_type_object($invoice->post_type); |
28 | 28 | $type_title = $post_type_object->labels->singular_name; |
29 | 29 | |
30 | 30 | $cols = 5; |
31 | - if ( $item_quantities ) { |
|
31 | + if ($item_quantities) { |
|
32 | 32 | $cols++; |
33 | 33 | } |
34 | - if ( $use_taxes ) { |
|
34 | + if ($use_taxes) { |
|
35 | 35 | $cols++; |
36 | 36 | } |
37 | 37 | $class = ''; |
38 | - if ( $invoice->is_paid() ) { |
|
38 | + if ($invoice->is_paid()) { |
|
39 | 39 | $class .= ' wpinv-paid'; |
40 | 40 | } |
41 | - if ( $invoice->is_refunded() ) { |
|
41 | + if ($invoice->is_refunded()) { |
|
42 | 42 | $class .= ' wpinv-refunded'; |
43 | 43 | } |
44 | - if ( $is_recurring ) { |
|
44 | + if ($is_recurring) { |
|
45 | 45 | $class .= ' wpi-recurring'; |
46 | 46 | } |
47 | 47 | ?> |
@@ -49,21 +49,21 @@ discard block |
||
49 | 49 | <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0"> |
50 | 50 | <thead> |
51 | 51 | <tr> |
52 | - <th class="id"><?php _e( 'ID', 'invoicing' );?></th> |
|
53 | - <th class="title"><?php _e( 'Item', 'invoicing' );?></th> |
|
54 | - <th class="price"><?php _e( 'Price', 'invoicing' );?></th> |
|
55 | - <?php if ( $item_quantities ) { ?> |
|
56 | - <th class="qty"><?php _e( 'Qty', 'invoicing' );?></th> |
|
52 | + <th class="id"><?php _e('ID', 'invoicing'); ?></th> |
|
53 | + <th class="title"><?php _e('Item', 'invoicing'); ?></th> |
|
54 | + <th class="price"><?php _e('Price', 'invoicing'); ?></th> |
|
55 | + <?php if ($item_quantities) { ?> |
|
56 | + <th class="qty"><?php _e('Qty', 'invoicing'); ?></th> |
|
57 | 57 | <?php } ?> |
58 | - <th class="total"><?php _e( 'Total', 'invoicing' );?></th> |
|
59 | - <?php if ( $use_taxes ) { ?> |
|
60 | - <th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th> |
|
58 | + <th class="total"><?php _e('Total', 'invoicing'); ?></th> |
|
59 | + <?php if ($use_taxes) { ?> |
|
60 | + <th class="tax"><?php _e('Tax (%)', 'invoicing'); ?></th> |
|
61 | 61 | <?php } ?> |
62 | 62 | <th class="action"></th> |
63 | 63 | </tr> |
64 | 64 | </thead> |
65 | 65 | <tbody class="wpinv-line-items"> |
66 | - <?php echo wpinv_admin_get_line_items( $invoice ); ?> |
|
66 | + <?php echo wpinv_admin_get_line_items($invoice); ?> |
|
67 | 67 | </tbody> |
68 | 68 | <tfoot class="wpinv-totals"> |
69 | 69 | <tr> |
@@ -74,45 +74,45 @@ discard block |
||
74 | 74 | <td class="id"> |
75 | 75 | </td> |
76 | 76 | <td class="title"> |
77 | - <input type="text" class="regular-text" placeholder="<?php _e( 'Item Name', 'invoicing' ); ?>" value="" name="_wpinv_quick[name]"> |
|
78 | - <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?> |
|
77 | + <input type="text" class="regular-text" placeholder="<?php _e('Item Name', 'invoicing'); ?>" value="" name="_wpinv_quick[name]"> |
|
78 | + <?php if ($wpinv_euvat->allow_vat_rules()) { ?> |
|
79 | 79 | <div class="wp-clearfix"> |
80 | 80 | <label class="wpi-vat-rule"> |
81 | - <span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span> |
|
81 | + <span class="title"><?php _e('VAT rule type', 'invoicing'); ?></span> |
|
82 | 82 | <span class="input-text-wrap"> |
83 | - <?php echo wpinv_html_select( array( |
|
83 | + <?php echo wpinv_html_select(array( |
|
84 | 84 | 'options' => $wpinv_euvat->get_rules(), |
85 | 85 | 'name' => '_wpinv_quick[vat_rule]', |
86 | 86 | 'id' => '_wpinv_quick_vat_rule', |
87 | 87 | 'show_option_all' => false, |
88 | 88 | 'show_option_none' => false, |
89 | 89 | 'class' => 'gdmbx2-text-medium wpinv-quick-vat-rule', |
90 | - ) ); ?> |
|
90 | + )); ?> |
|
91 | 91 | </span> |
92 | 92 | </label> |
93 | 93 | </div> |
94 | - <?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?> |
|
94 | + <?php } if ($wpinv_euvat->allow_vat_classes()) { ?> |
|
95 | 95 | <div class="wp-clearfix"> |
96 | 96 | <label class="wpi-vat-class"> |
97 | - <span class="title"><?php _e( 'VAT class', 'invoicing' );?></span> |
|
97 | + <span class="title"><?php _e('VAT class', 'invoicing'); ?></span> |
|
98 | 98 | <span class="input-text-wrap"> |
99 | - <?php echo wpinv_html_select( array( |
|
99 | + <?php echo wpinv_html_select(array( |
|
100 | 100 | 'options' => $wpinv_euvat->get_all_classes(), |
101 | 101 | 'name' => '_wpinv_quick[vat_class]', |
102 | 102 | 'id' => '_wpinv_quick_vat_class', |
103 | 103 | 'show_option_all' => false, |
104 | 104 | 'show_option_none' => false, |
105 | 105 | 'class' => 'gdmbx2-text-medium wpinv-quick-vat-class', |
106 | - ) ); ?> |
|
106 | + )); ?> |
|
107 | 107 | </span> |
108 | 108 | </label> |
109 | 109 | </div> |
110 | 110 | <?php } ?> |
111 | 111 | <div class="wp-clearfix"> |
112 | 112 | <label class="wpi-item-type"> |
113 | - <span class="title"><?php _e( 'Item type', 'invoicing' );?></span> |
|
113 | + <span class="title"><?php _e('Item type', 'invoicing'); ?></span> |
|
114 | 114 | <span class="input-text-wrap"> |
115 | - <?php echo wpinv_html_select( array( |
|
115 | + <?php echo wpinv_html_select(array( |
|
116 | 116 | 'options' => $item_types, |
117 | 117 | 'name' => '_wpinv_quick[type]', |
118 | 118 | 'id' => '_wpinv_quick_type', |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | 'show_option_all' => false, |
121 | 121 | 'show_option_none' => false, |
122 | 122 | 'class' => 'gdmbx2-text-medium wpinv-quick-type', |
123 | - ) ); ?> |
|
123 | + )); ?> |
|
124 | 124 | </span> |
125 | 125 | </label> |
126 | 126 | </div> |
@@ -133,11 +133,11 @@ discard block |
||
133 | 133 | </div> |
134 | 134 | </td> |
135 | 135 | <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td> |
136 | - <?php if ( $item_quantities ) { ?> |
|
136 | + <?php if ($item_quantities) { ?> |
|
137 | 137 | <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td> |
138 | 138 | <?php } ?> |
139 | 139 | <td class="total"></td> |
140 | - <?php if ( $use_taxes ) { ?> |
|
140 | + <?php if ($use_taxes) { ?> |
|
141 | 141 | <td class="tax"></td> |
142 | 142 | <?php } ?> |
143 | 143 | <td class="action"></td> |
@@ -150,29 +150,29 @@ discard block |
||
150 | 150 | <td colspan="<?php echo $cols; ?>"></td> |
151 | 151 | </tr> |
152 | 152 | <tr class="totals"> |
153 | - <td colspan="<?php echo ( $cols - 4 ); ?>"></td> |
|
153 | + <td colspan="<?php echo ($cols - 4); ?>"></td> |
|
154 | 154 | <td colspan="4"> |
155 | 155 | <table cellspacing="0" cellpadding="0"> |
156 | 156 | <tr class="subtotal"> |
157 | - <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td> |
|
158 | - <td class="total"><?php echo $subtotal;?></td> |
|
157 | + <td class="name"><?php _e('Sub Total:', 'invoicing'); ?></td> |
|
158 | + <td class="total"><?php echo $subtotal; ?></td> |
|
159 | 159 | <td class="action"></td> |
160 | 160 | </tr> |
161 | 161 | <tr class="discount"> |
162 | - <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td> |
|
163 | - <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td> |
|
162 | + <td class="name"><?php wpinv_get_discount_label(wpinv_discount_code($invoice->ID)); ?>:</td> |
|
163 | + <td class="total"><?php echo wpinv_discount($invoice->ID, true, true); ?></td> |
|
164 | 164 | <td class="action"></td> |
165 | 165 | </tr> |
166 | - <?php if ( $use_taxes ) { ?> |
|
166 | + <?php if ($use_taxes) { ?> |
|
167 | 167 | <tr class="tax"> |
168 | - <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td> |
|
169 | - <td class="total"><?php echo $tax;?></td> |
|
168 | + <td class="name"><?php _e('Tax:', 'invoicing'); ?></td> |
|
169 | + <td class="total"><?php echo $tax; ?></td> |
|
170 | 170 | <td class="action"></td> |
171 | 171 | </tr> |
172 | 172 | <?php } ?> |
173 | 173 | <tr class="total"> |
174 | - <td class="name"><?php echo apply_filters( 'wpinv_invoice_items_total_label', __( 'Invoice Total:', 'invoicing' ), $invoice );?></td> |
|
175 | - <td class="total"><?php echo $total;?></td> |
|
174 | + <td class="name"><?php echo apply_filters('wpinv_invoice_items_total_label', __('Invoice Total:', 'invoicing'), $invoice); ?></td> |
|
175 | + <td class="total"><?php echo $total; ?></td> |
|
176 | 176 | <td class="action"></td> |
177 | 177 | </tr> |
178 | 178 | </table> |
@@ -183,89 +183,89 @@ discard block |
||
183 | 183 | <div class="wpinv-actions"> |
184 | 184 | <?php ob_start(); ?> |
185 | 185 | <?php |
186 | - if ( !$invoice->is_paid() && !$invoice->is_refunded() ) { |
|
187 | - if ( !$invoice->is_recurring() ) { |
|
188 | - echo wpinv_item_dropdown( array( |
|
186 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
187 | + if (!$invoice->is_recurring()) { |
|
188 | + echo wpinv_item_dropdown(array( |
|
189 | 189 | 'name' => 'wpinv_invoice_item', |
190 | 190 | 'id' => 'wpinv_invoice_item', |
191 | 191 | 'show_recurring' => true, |
192 | - ) ); |
|
192 | + )); |
|
193 | 193 | ?> |
194 | - <input type="button" value="<?php echo sprintf(esc_attr__( 'Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e( 'Recalculate Totals', 'invoicing' );?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals"> |
|
194 | + <input type="button" value="<?php echo sprintf(esc_attr__('Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e('Create new item', 'invoicing'); ?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e('Recalculate Totals', 'invoicing'); ?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals"> |
|
195 | 195 | <?php } ?> |
196 | - <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?> |
|
197 | - <?php $item_actions = ob_get_clean(); echo apply_filters( 'wpinv_invoice_items_actions_content', $item_actions, $invoice, $post ); ?> |
|
196 | + <?php do_action('wpinv_invoice_items_actions', $invoice); ?> |
|
197 | + <?php $item_actions = ob_get_clean(); echo apply_filters('wpinv_invoice_items_actions_content', $item_actions, $invoice, $post); ?> |
|
198 | 198 | </div> |
199 | 199 | </div> |
200 | 200 | <?php |
201 | 201 | } |
202 | 202 | |
203 | - public static function prices( $post ) { |
|
203 | + public static function prices($post) { |
|
204 | 204 | $symbol = wpinv_currency_symbol(); |
205 | 205 | $position = wpinv_currency_position(); |
206 | - $item = new WPInv_Item( $post->ID ); |
|
206 | + $item = new WPInv_Item($post->ID); |
|
207 | 207 | |
208 | 208 | $price = $item->get_price(); |
209 | 209 | $is_recurring = $item->is_recurring(); |
210 | 210 | $period = $item->get_recurring_period(); |
211 | - $interval = absint( $item->get_recurring_interval() ); |
|
212 | - $times = absint( $item->get_recurring_limit() ); |
|
211 | + $interval = absint($item->get_recurring_interval()); |
|
212 | + $times = absint($item->get_recurring_limit()); |
|
213 | 213 | $free_trial = $item->has_free_trial(); |
214 | 214 | $trial_interval = $item->get_trial_interval(); |
215 | 215 | $trial_period = $item->get_trial_period(); |
216 | 216 | |
217 | 217 | $intervals = array(); |
218 | - for ( $i = 1; $i <= 90; $i++ ) { |
|
218 | + for ($i = 1; $i <= 90; $i++) { |
|
219 | 219 | $intervals[$i] = $i; |
220 | 220 | } |
221 | 221 | |
222 | - $interval = $interval > 0 ? $interval : 1; |
|
222 | + $interval = $interval > 0 ? $interval : 1; |
|
223 | 223 | |
224 | 224 | $class = $is_recurring ? 'wpinv-recurring-y' : 'wpinv-recurring-n'; |
225 | 225 | ?> |
226 | - <p class="wpinv-row-prices"><?php echo ( $position != 'right' ? $symbol . ' ' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $price;?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled( $item->is_editable(), false ); ?> /><?php echo ( $position == 'right' ? ' ' . $symbol : '' );?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce( 'wpinv_item_meta_box_save' ) ;?>" /> |
|
227 | - <?php do_action( 'wpinv_prices_metabox_price', $item ); ?> |
|
226 | + <p class="wpinv-row-prices"><?php echo ($position != 'right' ? $symbol . ' ' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $price; ?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled($item->is_editable(), false); ?> /><?php echo ($position == 'right' ? ' ' . $symbol : ''); ?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce('wpinv_item_meta_box_save'); ?>" /> |
|
227 | + <?php do_action('wpinv_prices_metabox_price', $item); ?> |
|
228 | 228 | </p> |
229 | 229 | <p class="wpinv-row-is-recurring"> |
230 | 230 | <label for="wpinv_is_recurring"> |
231 | - <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked( 1, $is_recurring ); ?> /> |
|
232 | - <?php echo apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Is Recurring Item?', 'invoicing' ) ); ?> |
|
231 | + <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked(1, $is_recurring); ?> /> |
|
232 | + <?php echo apply_filters('wpinv_is_recurring_toggle_text', __('Is Recurring Item?', 'invoicing')); ?> |
|
233 | 233 | </label> |
234 | - <?php do_action( 'wpinv_prices_metabox_is_recurring_field', $item ); ?> |
|
234 | + <?php do_action('wpinv_prices_metabox_is_recurring_field', $item); ?> |
|
235 | 235 | </p> |
236 | - <p class="wpinv-row-recurring-fields <?php echo $class;?>"> |
|
237 | - <label class="wpinv-period" for="wpinv_recurring_period"><?php _e( 'Recurring', 'invoicing' );?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e( 'day(s)', 'invoicing' ); ?>" <?php selected( 'D', $period );?>><?php _e( 'Daily', 'invoicing' ); ?></option><option value="W" data-text="<?php esc_attr_e( 'week(s)', 'invoicing' ); ?>" <?php selected( 'W', $period );?>><?php _e( 'Weekly', 'invoicing' ); ?></option><option value="M" data-text="<?php esc_attr_e( 'month(s)', 'invoicing' ); ?>" <?php selected( 'M', $period );?>><?php _e( 'Monthly', 'invoicing' ); ?></option><option value="Y" data-text="<?php esc_attr_e( 'year(s)', 'invoicing' ); ?>" <?php selected( 'Y', $period );?>><?php _e( 'Yearly', 'invoicing' ); ?></option></select></label> |
|
238 | - <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e( 'at every', 'invoicing' );?> <?php echo wpinv_html_select( array( |
|
236 | + <p class="wpinv-row-recurring-fields <?php echo $class; ?>"> |
|
237 | + <label class="wpinv-period" for="wpinv_recurring_period"><?php _e('Recurring', 'invoicing'); ?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e('day(s)', 'invoicing'); ?>" <?php selected('D', $period); ?>><?php _e('Daily', 'invoicing'); ?></option><option value="W" data-text="<?php esc_attr_e('week(s)', 'invoicing'); ?>" <?php selected('W', $period); ?>><?php _e('Weekly', 'invoicing'); ?></option><option value="M" data-text="<?php esc_attr_e('month(s)', 'invoicing'); ?>" <?php selected('M', $period); ?>><?php _e('Monthly', 'invoicing'); ?></option><option value="Y" data-text="<?php esc_attr_e('year(s)', 'invoicing'); ?>" <?php selected('Y', $period); ?>><?php _e('Yearly', 'invoicing'); ?></option></select></label> |
|
238 | + <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e('at every', 'invoicing'); ?> <?php echo wpinv_html_select(array( |
|
239 | 239 | 'options' => $intervals, |
240 | 240 | 'name' => 'wpinv_recurring_interval', |
241 | 241 | 'id' => 'wpinv_recurring_interval', |
242 | 242 | 'selected' => $interval, |
243 | 243 | 'show_option_all' => false, |
244 | 244 | 'show_option_none' => false |
245 | - ) ); ?> <span id="wpinv_interval_text"><?php _e( 'day(s)', 'invoicing' );?></span></label> |
|
246 | - <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e( 'for', 'invoicing' );?> <input class="small-text" type="number" value="<?php echo $times;?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e( 'time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing' );?></label> |
|
245 | + )); ?> <span id="wpinv_interval_text"><?php _e('day(s)', 'invoicing'); ?></span></label> |
|
246 | + <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e('for', 'invoicing'); ?> <input class="small-text" type="number" value="<?php echo $times; ?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e('time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing'); ?></label> |
|
247 | 247 | <span class="clear wpi-trial-clr"></span> |
248 | 248 | <label class="wpinv-free-trial" for="wpinv_free_trial"> |
249 | - <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked( true, (bool)$free_trial ); ?> /> |
|
250 | - <?php echo __( 'Offer free trial for', 'invoicing' ); ?> |
|
249 | + <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked(true, (bool)$free_trial); ?> /> |
|
250 | + <?php echo __('Offer free trial for', 'invoicing'); ?> |
|
251 | 251 | </label> |
252 | 252 | <label class="wpinv-trial-interval" for="wpinv_trial_interval"> |
253 | - <input class="small-text" type="number" value="<?php echo $trial_interval;?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected( 'D', $trial_period );?>><?php _e( 'day(s)', 'invoicing' ); ?></option><option value="W" <?php selected( 'W', $trial_period );?>><?php _e( 'week(s)', 'invoicing' ); ?></option><option value="M" <?php selected( 'M', $trial_period );?>><?php _e( 'month(s)', 'invoicing' ); ?></option><option value="Y" <?php selected( 'Y', $trial_period );?>><?php _e( 'year(s)', 'invoicing' ); ?></option></select> |
|
253 | + <input class="small-text" type="number" value="<?php echo $trial_interval; ?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected('D', $trial_period); ?>><?php _e('day(s)', 'invoicing'); ?></option><option value="W" <?php selected('W', $trial_period); ?>><?php _e('week(s)', 'invoicing'); ?></option><option value="M" <?php selected('M', $trial_period); ?>><?php _e('month(s)', 'invoicing'); ?></option><option value="Y" <?php selected('Y', $trial_period); ?>><?php _e('year(s)', 'invoicing'); ?></option></select> |
|
254 | 254 | </label> |
255 | - <?php do_action( 'wpinv_prices_metabox_recurring_fields', $item ); ?> |
|
255 | + <?php do_action('wpinv_prices_metabox_recurring_fields', $item); ?> |
|
256 | 256 | </p> |
257 | - <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type( $post->ID ); ?>" /> |
|
258 | - <?php do_action( 'wpinv_item_price_field', $post->ID ); ?> |
|
257 | + <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type($post->ID); ?>" /> |
|
258 | + <?php do_action('wpinv_item_price_field', $post->ID); ?> |
|
259 | 259 | <?php |
260 | 260 | } |
261 | 261 | |
262 | - public static function vat_rules( $post ) { |
|
262 | + public static function vat_rules($post) { |
|
263 | 263 | global $wpinv_euvat; |
264 | 264 | |
265 | - $rule_type = $wpinv_euvat->get_item_rule( $post->ID ); |
|
265 | + $rule_type = $wpinv_euvat->get_item_rule($post->ID); |
|
266 | 266 | ?> |
267 | - <p><label for="wpinv_vat_rules"><strong><?php _e( 'Select how VAT rules will be applied:', 'invoicing' );?></strong></label> |
|
268 | - <?php echo wpinv_html_select( array( |
|
267 | + <p><label for="wpinv_vat_rules"><strong><?php _e('Select how VAT rules will be applied:', 'invoicing'); ?></strong></label> |
|
268 | + <?php echo wpinv_html_select(array( |
|
269 | 269 | 'options' => $wpinv_euvat->get_rules(), |
270 | 270 | 'name' => 'wpinv_vat_rules', |
271 | 271 | 'id' => 'wpinv_vat_rules', |
@@ -273,19 +273,19 @@ discard block |
||
273 | 273 | 'show_option_all' => false, |
274 | 274 | 'show_option_none' => false, |
275 | 275 | 'class' => 'gdmbx2-text-medium wpinv-vat-rules', |
276 | - ) ); ?> |
|
276 | + )); ?> |
|
277 | 277 | </p> |
278 | - <p class="wpi-m0"><?php _e( 'When you select physical product rules, only consumers and businesses in your country will be charged VAT. The VAT rate used will be the rate in your country.', 'invoicing' ); ?></p> |
|
279 | - <p class="wpi-m0"><?php _e( 'If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer. Only businesses in your country will be charged VAT.', 'invoicing' ); ?></p> |
|
278 | + <p class="wpi-m0"><?php _e('When you select physical product rules, only consumers and businesses in your country will be charged VAT. The VAT rate used will be the rate in your country.', 'invoicing'); ?></p> |
|
279 | + <p class="wpi-m0"><?php _e('If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer. Only businesses in your country will be charged VAT.', 'invoicing'); ?></p> |
|
280 | 280 | <?php |
281 | 281 | } |
282 | 282 | |
283 | - public static function vat_classes( $post ) { |
|
283 | + public static function vat_classes($post) { |
|
284 | 284 | global $wpinv_euvat; |
285 | 285 | |
286 | - $vat_class = $wpinv_euvat->get_item_class( $post->ID ); |
|
286 | + $vat_class = $wpinv_euvat->get_item_class($post->ID); |
|
287 | 287 | ?> |
288 | - <p><?php echo wpinv_html_select( array( |
|
288 | + <p><?php echo wpinv_html_select(array( |
|
289 | 289 | 'options' => $wpinv_euvat->get_all_classes(), |
290 | 290 | 'name' => 'wpinv_vat_class', |
291 | 291 | 'id' => 'wpinv_vat_class', |
@@ -293,18 +293,18 @@ discard block |
||
293 | 293 | 'show_option_all' => false, |
294 | 294 | 'show_option_none' => false, |
295 | 295 | 'class' => 'gdmbx2-text-medium wpinv-vat-class', |
296 | - ) ); ?> |
|
296 | + )); ?> |
|
297 | 297 | </p> |
298 | - <p class="wpi-m0"><?php _e( 'Select the VAT rate class to use for this invoice item.', 'invoicing' ); ?></p> |
|
298 | + <p class="wpi-m0"><?php _e('Select the VAT rate class to use for this invoice item.', 'invoicing'); ?></p> |
|
299 | 299 | <?php |
300 | 300 | } |
301 | 301 | |
302 | - public static function item_info( $post ) { |
|
303 | - $item_type = wpinv_get_item_type( $post->ID ); |
|
304 | - do_action( 'wpinv_item_info_metabox_before', $post ); |
|
302 | + public static function item_info($post) { |
|
303 | + $item_type = wpinv_get_item_type($post->ID); |
|
304 | + do_action('wpinv_item_info_metabox_before', $post); |
|
305 | 305 | ?> |
306 | - <p><label for="wpinv_item_type"><strong><?php _e( 'Type:', 'invoicing' );?></strong></label> |
|
307 | - <?php echo wpinv_html_select( array( |
|
306 | + <p><label for="wpinv_item_type"><strong><?php _e('Type:', 'invoicing'); ?></strong></label> |
|
307 | + <?php echo wpinv_html_select(array( |
|
308 | 308 | 'options' => wpinv_get_item_types(), |
309 | 309 | 'name' => 'wpinv_item_type', |
310 | 310 | 'id' => 'wpinv_item_type', |
@@ -312,114 +312,114 @@ discard block |
||
312 | 312 | 'show_option_all' => false, |
313 | 313 | 'show_option_none' => false, |
314 | 314 | 'class' => 'gdmbx2-text-medium wpinv-item-type', |
315 | - ) ); ?> |
|
315 | + )); ?> |
|
316 | 316 | </p> |
317 | - <p class="wpi-m0"><?php _e( 'Select item type.', 'invoicing' );?><br><?php _e( '<b>Standard:</b> Standard item type', 'invoicing' );?><br><?php _e( '<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing' );?></p> |
|
317 | + <p class="wpi-m0"><?php _e('Select item type.', 'invoicing'); ?><br><?php _e('<b>Standard:</b> Standard item type', 'invoicing'); ?><br><?php _e('<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing'); ?></p> |
|
318 | 318 | <?php |
319 | - do_action( 'wpinv_item_info_metabox_after', $post ); |
|
319 | + do_action('wpinv_item_info_metabox_after', $post); |
|
320 | 320 | } |
321 | 321 | |
322 | - public static function meta_values( $post ) { |
|
323 | - $meta_keys = apply_filters( 'wpinv_show_meta_values_for_keys', array( |
|
322 | + public static function meta_values($post) { |
|
323 | + $meta_keys = apply_filters('wpinv_show_meta_values_for_keys', array( |
|
324 | 324 | 'type', |
325 | 325 | 'custom_id' |
326 | - ) ); |
|
326 | + )); |
|
327 | 327 | |
328 | - if ( empty( $meta_keys ) ) { |
|
328 | + if (empty($meta_keys)) { |
|
329 | 329 | return; |
330 | 330 | } |
331 | 331 | |
332 | - do_action( 'wpinv_meta_values_metabox_before', $post ); |
|
332 | + do_action('wpinv_meta_values_metabox_before', $post); |
|
333 | 333 | |
334 | - foreach ( $meta_keys as $meta_key ) { |
|
334 | + foreach ($meta_keys as $meta_key) { |
|
335 | 335 | ?> |
336 | - <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta( $post->ID, '_wpinv_' . $meta_key, true ); ?></label></p> |
|
336 | + <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta($post->ID, '_wpinv_' . $meta_key, true); ?></label></p> |
|
337 | 337 | <?php |
338 | 338 | } |
339 | 339 | |
340 | - do_action( 'wpinv_meta_values_metabox_after', $post ); |
|
340 | + do_action('wpinv_meta_values_metabox_after', $post); |
|
341 | 341 | } |
342 | 342 | |
343 | - public static function save( $post_id, $data, $post ) { |
|
344 | - $invoice = new WPInv_Invoice( $post_id ); |
|
343 | + public static function save($post_id, $data, $post) { |
|
344 | + $invoice = new WPInv_Invoice($post_id); |
|
345 | 345 | |
346 | 346 | // Billing |
347 | - $first_name = sanitize_text_field( $data['wpinv_first_name'] ); |
|
348 | - $last_name = sanitize_text_field( $data['wpinv_last_name'] ); |
|
349 | - $company = sanitize_text_field( $data['wpinv_company'] ); |
|
350 | - $vat_number = sanitize_text_field( $data['wpinv_vat_number'] ); |
|
351 | - $phone = sanitize_text_field( $data['wpinv_phone'] ); |
|
352 | - $address = sanitize_text_field( $data['wpinv_address'] ); |
|
353 | - $city = sanitize_text_field( $data['wpinv_city'] ); |
|
354 | - $zip = sanitize_text_field( $data['wpinv_zip'] ); |
|
355 | - $country = sanitize_text_field( $data['wpinv_country'] ); |
|
356 | - $state = sanitize_text_field( $data['wpinv_state'] ); |
|
347 | + $first_name = sanitize_text_field($data['wpinv_first_name']); |
|
348 | + $last_name = sanitize_text_field($data['wpinv_last_name']); |
|
349 | + $company = sanitize_text_field($data['wpinv_company']); |
|
350 | + $vat_number = sanitize_text_field($data['wpinv_vat_number']); |
|
351 | + $phone = sanitize_text_field($data['wpinv_phone']); |
|
352 | + $address = sanitize_text_field($data['wpinv_address']); |
|
353 | + $city = sanitize_text_field($data['wpinv_city']); |
|
354 | + $zip = sanitize_text_field($data['wpinv_zip']); |
|
355 | + $country = sanitize_text_field($data['wpinv_country']); |
|
356 | + $state = sanitize_text_field($data['wpinv_state']); |
|
357 | 357 | |
358 | 358 | // Details |
359 | - $status = sanitize_text_field( $data['wpinv_status'] ); |
|
360 | - $old_status = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status; |
|
361 | - $number = sanitize_text_field( $data['wpinv_number'] ); |
|
362 | - $due_date = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : ''; |
|
359 | + $status = sanitize_text_field($data['wpinv_status']); |
|
360 | + $old_status = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status; |
|
361 | + $number = sanitize_text_field($data['wpinv_number']); |
|
362 | + $due_date = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : ''; |
|
363 | 363 | //$discounts = sanitize_text_field( $data['wpinv_discounts'] ); |
364 | 364 | //$discount = sanitize_text_field( $data['wpinv_discount'] ); |
365 | 365 | |
366 | - $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip(); |
|
366 | + $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip(); |
|
367 | 367 | |
368 | - $invoice->set( 'due_date', $due_date ); |
|
369 | - $invoice->set( 'first_name', $first_name ); |
|
370 | - $invoice->set( 'last_name', $last_name ); |
|
371 | - $invoice->set( 'company', $company ); |
|
372 | - $invoice->set( 'vat_number', $vat_number ); |
|
373 | - $invoice->set( 'phone', $phone ); |
|
374 | - $invoice->set( 'address', $address ); |
|
375 | - $invoice->set( 'city', $city ); |
|
376 | - $invoice->set( 'zip', $zip ); |
|
377 | - $invoice->set( 'country', $country ); |
|
378 | - $invoice->set( 'state', $state ); |
|
379 | - $invoice->set( 'status', $status ); |
|
368 | + $invoice->set('due_date', $due_date); |
|
369 | + $invoice->set('first_name', $first_name); |
|
370 | + $invoice->set('last_name', $last_name); |
|
371 | + $invoice->set('company', $company); |
|
372 | + $invoice->set('vat_number', $vat_number); |
|
373 | + $invoice->set('phone', $phone); |
|
374 | + $invoice->set('address', $address); |
|
375 | + $invoice->set('city', $city); |
|
376 | + $invoice->set('zip', $zip); |
|
377 | + $invoice->set('country', $country); |
|
378 | + $invoice->set('state', $state); |
|
379 | + $invoice->set('status', $status); |
|
380 | 380 | //$invoice->set( 'number', $number ); |
381 | 381 | //$invoice->set( 'discounts', $discounts ); |
382 | 382 | //$invoice->set( 'discount', $discount ); |
383 | - $invoice->set( 'ip', $ip ); |
|
383 | + $invoice->set('ip', $ip); |
|
384 | 384 | $invoice->old_status = $_POST['original_post_status']; |
385 | 385 | $invoice->currency = wpinv_get_currency(); |
386 | - if ( !empty( $data['wpinv_gateway'] ) ) { |
|
387 | - $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) ); |
|
386 | + if (!empty($data['wpinv_gateway'])) { |
|
387 | + $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway'])); |
|
388 | 388 | } |
389 | 389 | $saved = $invoice->save(); |
390 | 390 | |
391 | 391 | // Check for payment notes |
392 | - if ( !empty( $data['invoice_note'] ) ) { |
|
393 | - $note = wp_kses( $data['invoice_note'], array() ); |
|
394 | - $note_type = sanitize_text_field( $data['invoice_note_type'] ); |
|
392 | + if (!empty($data['invoice_note'])) { |
|
393 | + $note = wp_kses($data['invoice_note'], array()); |
|
394 | + $note_type = sanitize_text_field($data['invoice_note_type']); |
|
395 | 395 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
396 | 396 | |
397 | - wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note ); |
|
397 | + wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note); |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | // Update user address if empty. |
401 | - if ( $saved && !empty( $invoice ) ) { |
|
402 | - if ( $user_id = $invoice->get_user_id() ) { |
|
403 | - $user_address = wpinv_get_user_address( $user_id, false ); |
|
401 | + if ($saved && !empty($invoice)) { |
|
402 | + if ($user_id = $invoice->get_user_id()) { |
|
403 | + $user_address = wpinv_get_user_address($user_id, false); |
|
404 | 404 | |
405 | 405 | if (empty($user_address['first_name'])) { |
406 | - update_user_meta( $user_id, '_wpinv_first_name', $first_name ); |
|
407 | - update_user_meta( $user_id, '_wpinv_last_name', $last_name ); |
|
406 | + update_user_meta($user_id, '_wpinv_first_name', $first_name); |
|
407 | + update_user_meta($user_id, '_wpinv_last_name', $last_name); |
|
408 | 408 | } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) { |
409 | - update_user_meta( $user_id, '_wpinv_last_name', $last_name ); |
|
409 | + update_user_meta($user_id, '_wpinv_last_name', $last_name); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) { |
413 | - update_user_meta( $user_id, '_wpinv_address', $address ); |
|
414 | - update_user_meta( $user_id, '_wpinv_city', $city ); |
|
415 | - update_user_meta( $user_id, '_wpinv_state', $state ); |
|
416 | - update_user_meta( $user_id, '_wpinv_country', $country ); |
|
417 | - update_user_meta( $user_id, '_wpinv_zip', $zip ); |
|
418 | - update_user_meta( $user_id, '_wpinv_phone', $phone ); |
|
413 | + update_user_meta($user_id, '_wpinv_address', $address); |
|
414 | + update_user_meta($user_id, '_wpinv_city', $city); |
|
415 | + update_user_meta($user_id, '_wpinv_state', $state); |
|
416 | + update_user_meta($user_id, '_wpinv_country', $country); |
|
417 | + update_user_meta($user_id, '_wpinv_zip', $zip); |
|
418 | + update_user_meta($user_id, '_wpinv_phone', $phone); |
|
419 | 419 | } |
420 | 420 | } |
421 | 421 | |
422 | - do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
422 | + do_action('wpinv_invoice_metabox_saved', $invoice); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | return $saved; |