@@ -4,40 +4,40 @@ |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | global $aui_bs5; |
10 | 10 | ?> |
11 | 11 | <div class="card shadow-sm my-5"> |
12 | 12 | <div class="text-center card-body"> |
13 | - <h1 class="h3"><?php esc_html_e( 'Awesome, you are ready to Get Paid', 'invoicing' ); ?></h1> |
|
13 | + <h1 class="h3"><?php esc_html_e('Awesome, you are ready to Get Paid', 'invoicing'); ?></h1> |
|
14 | 14 | |
15 | 15 | <div class="geodirectory-message geodirectory-tracker"> |
16 | - <p><?php esc_html_e( 'Thank you for choosing GetPaid!', 'invoicing' ); ?> <i class="far fa-smile-beam"></i></p> |
|
16 | + <p><?php esc_html_e('Thank you for choosing GetPaid!', 'invoicing'); ?> <i class="far fa-smile-beam"></i></p> |
|
17 | 17 | </div> |
18 | 18 | |
19 | 19 | <div class="gp-setup-next-steps"> |
20 | 20 | <div class="gp-setup-next-steps-first mb-4"> |
21 | 21 | <div> |
22 | - <h2 class="h3"><i class="fas fa-arrow-down"></i> <?php esc_html_e( 'Watch This', 'invoicing' ); ?> <i class="fas fa-arrow-down"></i></h2> |
|
23 | - <div class="<?php echo( $aui_bs5 ? 'ratio ratio-16x9' : 'embed-responsive embed-responsive-16by9' ); ?> mb-4"> |
|
24 | - <iframe class="<?php echo( $aui_bs5 ? '' : 'embed-responsive-item' ); ?>" src="https://www.youtube.com/embed/TXZuPXHjt9E?rel=0" allowfullscreen></iframe> |
|
22 | + <h2 class="h3"><i class="fas fa-arrow-down"></i> <?php esc_html_e('Watch This', 'invoicing'); ?> <i class="fas fa-arrow-down"></i></h2> |
|
23 | + <div class="<?php echo($aui_bs5 ? 'ratio ratio-16x9' : 'embed-responsive embed-responsive-16by9'); ?> mb-4"> |
|
24 | + <iframe class="<?php echo($aui_bs5 ? '' : 'embed-responsive-item'); ?>" src="https://www.youtube.com/embed/TXZuPXHjt9E?rel=0" allowfullscreen></iframe> |
|
25 | 25 | </div> |
26 | 26 | </div> |
27 | - <h2 class="h3"><?php esc_html_e( 'Next steps', 'invoicing' ); ?></h2> |
|
27 | + <h2 class="h3"><?php esc_html_e('Next steps', 'invoicing'); ?></h2> |
|
28 | 28 | |
29 | 29 | <div class="d-flex justify-content-between"> |
30 | - <a class="btn btn-outline-primary btn-sm" href="<?php echo esc_url( admin_url( 'post-new.php?post_type=wpi_item' ) ); ?>"><span class="h1 d-block"><i class="fas fa-box-open"></i></span> <?php esc_html_e( 'Create Item', 'invoicing' ); ?></a> |
|
31 | - <a class="btn btn-outline-primary btn-sm" href="<?php echo esc_url( admin_url( 'post-new.php?post_type=wpi_payment_form' ) ); ?>"><span class="h1 d-block"><i class="fas fa-align-justify"></i></span> <?php esc_html_e( 'Create Payment Form', 'invoicing' ); ?></a> |
|
32 | - <a class="btn btn-outline-primary btn-sm" href="<?php echo esc_url( admin_url( 'post-new.php?post_type=wpi_invoice' ) ); ?>"><span class="h1 d-block"><i class="fas fa-file-alt"></i></span> <?php esc_html_e( 'Create Invoice', 'invoicing' ); ?></a> |
|
30 | + <a class="btn btn-outline-primary btn-sm" href="<?php echo esc_url(admin_url('post-new.php?post_type=wpi_item')); ?>"><span class="h1 d-block"><i class="fas fa-box-open"></i></span> <?php esc_html_e('Create Item', 'invoicing'); ?></a> |
|
31 | + <a class="btn btn-outline-primary btn-sm" href="<?php echo esc_url(admin_url('post-new.php?post_type=wpi_payment_form')); ?>"><span class="h1 d-block"><i class="fas fa-align-justify"></i></span> <?php esc_html_e('Create Payment Form', 'invoicing'); ?></a> |
|
32 | + <a class="btn btn-outline-primary btn-sm" href="<?php echo esc_url(admin_url('post-new.php?post_type=wpi_invoice')); ?>"><span class="h1 d-block"><i class="fas fa-file-alt"></i></span> <?php esc_html_e('Create Invoice', 'invoicing'); ?></a> |
|
33 | 33 | </div> |
34 | 34 | |
35 | - <h2 class="h3 mt-4"><?php esc_html_e( 'Learn more', 'invoicing' ); ?></h2> |
|
35 | + <h2 class="h3 mt-4"><?php esc_html_e('Learn more', 'invoicing'); ?></h2> |
|
36 | 36 | <div class="gp-setup-next-steps-last mt-2 d-flex justify-content-between"> |
37 | - <a class="btn btn-outline-primary btn-sm" href="https://docs.wpgetpaid.com/collection/114-getting-started?utm_source=setupwizard&utm_medium=product&utm_content=getting-started&utm_campaign=invoicingplugin" target="_blank"><?php esc_html_e( 'Getting Started', 'invoicing' ); ?></a> |
|
38 | - <a class="btn btn-outline-primary btn-sm" href="https://docs.wpgetpaid.com/?utm_source=setupwizard&utm_medium=product&utm_content=docs&utm_campaign=invoicingplugin" target="_blank"><?php esc_html_e( 'Documentation', 'invoicing' ); ?></a> |
|
39 | - <a class="btn btn-outline-primary btn-sm" href="https://wpgetpaid.com/support/?utm_source=setupwizard&utm_medium=product&utm_content=docs&utm_campaign=invoicingyplugin" target="_blank"><?php esc_html_e( 'Support', 'invoicing' ); ?></a> |
|
40 | - <a class="btn btn-outline-primary btn-sm" href="https://demos.ayecode.io/getpaid/?utm_source=setupwizard&utm_medium=product&utm_content=demos&utm_campaign=invoicingyplugin" target="_blank"><?php esc_html_e( 'Demos', 'invoicing' ); ?></a> |
|
37 | + <a class="btn btn-outline-primary btn-sm" href="https://docs.wpgetpaid.com/collection/114-getting-started?utm_source=setupwizard&utm_medium=product&utm_content=getting-started&utm_campaign=invoicingplugin" target="_blank"><?php esc_html_e('Getting Started', 'invoicing'); ?></a> |
|
38 | + <a class="btn btn-outline-primary btn-sm" href="https://docs.wpgetpaid.com/?utm_source=setupwizard&utm_medium=product&utm_content=docs&utm_campaign=invoicingplugin" target="_blank"><?php esc_html_e('Documentation', 'invoicing'); ?></a> |
|
39 | + <a class="btn btn-outline-primary btn-sm" href="https://wpgetpaid.com/support/?utm_source=setupwizard&utm_medium=product&utm_content=docs&utm_campaign=invoicingyplugin" target="_blank"><?php esc_html_e('Support', 'invoicing'); ?></a> |
|
40 | + <a class="btn btn-outline-primary btn-sm" href="https://demos.ayecode.io/getpaid/?utm_source=setupwizard&utm_medium=product&utm_content=demos&utm_campaign=invoicingyplugin" target="_blank"><?php esc_html_e('Demos', 'invoicing'); ?></a> |
|
41 | 41 | </div> |
42 | 42 | </div> |
43 | 43 | </div> |
@@ -4,31 +4,31 @@ |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | global $aui_bs5; |
10 | 10 | ?> |
11 | 11 | <div class="card shadow-sm my-5"> |
12 | - <form method="post" class="text-center card-body" action="<?php echo esc_url( admin_url() ); ?>"> |
|
13 | - <?php getpaid_hidden_field( 'getpaid-admin-action', 'install_plugin' ); ?> |
|
14 | - <?php wp_nonce_field( 'getpaid-nonce', 'getpaid-nonce' ); ?> |
|
15 | - <?php getpaid_hidden_field( 'redirect', $next_url ); ?> |
|
12 | + <form method="post" class="text-center card-body" action="<?php echo esc_url(admin_url()); ?>"> |
|
13 | + <?php getpaid_hidden_field('getpaid-admin-action', 'install_plugin'); ?> |
|
14 | + <?php wp_nonce_field('getpaid-nonce', 'getpaid-nonce'); ?> |
|
15 | + <?php getpaid_hidden_field('redirect', $next_url); ?> |
|
16 | 16 | <div class="gd-wizard-recommend"> |
17 | - <h2 class="gd-settings-title h3"><?php esc_html_e( 'Recommended Plugins', 'invoicing' ); ?></h2> |
|
18 | - <p><?php esc_html_e( 'Below are a few of our own plugins that may help you.', 'invoicing' ); ?></p> |
|
17 | + <h2 class="gd-settings-title h3"><?php esc_html_e('Recommended Plugins', 'invoicing'); ?></h2> |
|
18 | + <p><?php esc_html_e('Below are a few of our own plugins that may help you.', 'invoicing'); ?></p> |
|
19 | 19 | <ul class="list-group"> |
20 | - <?php foreach ( $recommended_plugins as $key => $plugin ) : ?> |
|
21 | - <li class="list-group-item d-flex justify-content-between align-items-center flex-wrap <?php echo( $aui_bs5 ? 'text-start' : 'text-left' ); ?>"> |
|
22 | - <span class="mr-auto"><?php echo esc_html( $plugin['name'] ); ?></span> |
|
23 | - <div class="<?php echo( $aui_bs5 ? 'form-check form-switch me-n2' : 'custom-control custom-switch mr-n2 getpaid-install-plugin-siwtch-div' ); ?>"> |
|
24 | - <input type="checkbox" name="plugins[<?php echo esc_attr( $plugin['slug'] ); ?>]" value="<?php echo esc_attr( $plugin['file'] ); ?>" class="<?php echo ( $aui_bs5 ? 'form-check-input' : 'custom-control-input' ); ?>" <?php if ( is_plugin_active( $plugin['file'] ) ) { echo 'checked';}?> id="ac-setting-updates<?php echo esc_attr( $key ); ?>"> |
|
25 | - <label class="<?php echo ( $aui_bs5 ? 'form-check-label' : 'custom-control-label' ); ?>" for="ac-setting-updates<?php echo esc_attr( $key ); ?>"></label> |
|
20 | + <?php foreach ($recommended_plugins as $key => $plugin) : ?> |
|
21 | + <li class="list-group-item d-flex justify-content-between align-items-center flex-wrap <?php echo($aui_bs5 ? 'text-start' : 'text-left'); ?>"> |
|
22 | + <span class="mr-auto"><?php echo esc_html($plugin['name']); ?></span> |
|
23 | + <div class="<?php echo($aui_bs5 ? 'form-check form-switch me-n2' : 'custom-control custom-switch mr-n2 getpaid-install-plugin-siwtch-div'); ?>"> |
|
24 | + <input type="checkbox" name="plugins[<?php echo esc_attr($plugin['slug']); ?>]" value="<?php echo esc_attr($plugin['file']); ?>" class="<?php echo ($aui_bs5 ? 'form-check-input' : 'custom-control-input'); ?>" <?php if (is_plugin_active($plugin['file'])) { echo 'checked'; }?> id="ac-setting-updates<?php echo esc_attr($key); ?>"> |
|
25 | + <label class="<?php echo ($aui_bs5 ? 'form-check-label' : 'custom-control-label'); ?>" for="ac-setting-updates<?php echo esc_attr($key); ?>"></label> |
|
26 | 26 | </div> |
27 | - <small class="w-100"><?php echo esc_attr( $plugin['desc'] ); ?></small> |
|
27 | + <small class="w-100"><?php echo esc_attr($plugin['desc']); ?></small> |
|
28 | 28 | </li> |
29 | 29 | <?php endforeach; ?> |
30 | 30 | </ul> |
31 | - <p class="gp-setup-actions step text-center mt-4"><input type="submit" class="btn btn-primary button-next" value="<?php esc_attr_e( 'Continue', 'invoicing' ); ?>" name="save_step"/></p> |
|
31 | + <p class="gp-setup-actions step text-center mt-4"><input type="submit" class="btn btn-primary button-next" value="<?php esc_attr_e('Continue', 'invoicing'); ?>" name="save_step"/></p> |
|
32 | 32 | </div> |
33 | 33 | </form> |
34 | 34 | </div> |
35 | 35 | \ No newline at end of file |
@@ -10,227 +10,227 @@ |
||
10 | 10 | */ |
11 | 11 | class GetPaid_PayPal_API { |
12 | 12 | |
13 | - /** |
|
14 | - * Retrieves the bearer token. |
|
15 | - * |
|
13 | + /** |
|
14 | + * Retrieves the bearer token. |
|
15 | + * |
|
16 | 16 | * @return string|\WP_Error |
17 | - */ |
|
18 | - public static function get_token( $mode = 'live' ) { |
|
17 | + */ |
|
18 | + public static function get_token( $mode = 'live' ) { |
|
19 | 19 | |
20 | - $token = get_transient( 'getpaid_paypal_' . $mode . '_token' ); |
|
20 | + $token = get_transient( 'getpaid_paypal_' . $mode . '_token' ); |
|
21 | 21 | |
22 | - if ( $token ) { |
|
23 | - return $token; |
|
24 | - } |
|
22 | + if ( $token ) { |
|
23 | + return $token; |
|
24 | + } |
|
25 | 25 | |
26 | - $client_id = 'live' === $mode ? wpinv_get_option( 'paypal_client_id' ) : wpinv_get_option( 'paypal_sandbox_client_id' ); |
|
27 | - $secret_key = 'live' === $mode ? wpinv_get_option( 'paypal_secret' ) : wpinv_get_option( 'paypal_sandbox_secret' ); |
|
28 | - $url = self::get_api_url( 'v1/oauth2/token?grant_type=client_credentials', $mode ); |
|
26 | + $client_id = 'live' === $mode ? wpinv_get_option( 'paypal_client_id' ) : wpinv_get_option( 'paypal_sandbox_client_id' ); |
|
27 | + $secret_key = 'live' === $mode ? wpinv_get_option( 'paypal_secret' ) : wpinv_get_option( 'paypal_sandbox_secret' ); |
|
28 | + $url = self::get_api_url( 'v1/oauth2/token?grant_type=client_credentials', $mode ); |
|
29 | 29 | |
30 | 30 | if ( empty( $client_id ) || empty( $secret_key ) ) { |
31 | 31 | return new \WP_Error( 'invalid_request', 'Missing client id or secret key.', array( 'status' => 400 ) ); |
32 | 32 | } |
33 | 33 | |
34 | - $args = array( |
|
35 | - 'method' => 'POST', |
|
36 | - 'timeout' => 30, |
|
37 | - 'headers' => array( |
|
38 | - 'Authorization' => 'Basic ' . base64_encode( $client_id . ':' . $secret_key ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode |
|
39 | - 'Accept' => 'application/json', |
|
40 | - 'Content-Type' => 'application/x-www-form-urlencoded', |
|
41 | - ), |
|
42 | - ); |
|
43 | - |
|
44 | - $response = self::response_or_error( wp_remote_post( $url, $args ) ); |
|
45 | - |
|
46 | - if ( is_wp_error( $response ) ) { |
|
47 | - return $response; |
|
48 | - } |
|
49 | - |
|
50 | - if ( ! isset( $response->access_token ) ) { |
|
51 | - return new \WP_Error( 'invalid_request', 'Could not create token.', array( 'status' => 400 ) ); |
|
52 | - } |
|
53 | - |
|
54 | - set_transient( 'getpaid_paypal_' . $mode . '_token', $response->access_token, $response->expires_in - 600 ); |
|
55 | - return $response->access_token; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Retrieves the PayPal API URL. |
|
60 | - * |
|
61 | - * @param string $endpoint |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - public static function get_api_url( $endpoint = '', $mode = 'live' ) { |
|
65 | - $endpoint = ltrim( $endpoint, '/' ); |
|
66 | - return 'live' === $mode ? 'https://api-m.paypal.com/' . $endpoint : 'https://api-m.sandbox.paypal.com/' . $endpoint; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Handles a post request. |
|
71 | - * |
|
72 | - * @param string $path The path to the endpoint. |
|
73 | - * @param mixed $data The data to send. |
|
74 | - * @param string $method The method to use. |
|
75 | - * |
|
76 | - * @return true|\WP_Error |
|
77 | - */ |
|
78 | - public static function post( $path, $data, $mode = 'live', $method = 'POST' ) { |
|
79 | - |
|
80 | - $access_token = self::get_token( $mode ); |
|
81 | - |
|
82 | - if ( is_wp_error( $access_token ) ) { |
|
83 | - return $access_token; |
|
84 | - } |
|
85 | - |
|
86 | - $url = self::get_api_url( $path, $mode ); |
|
87 | - $args = array( |
|
88 | - 'method' => $method, |
|
89 | - 'headers' => array( |
|
90 | - 'Authorization' => 'Bearer ' . $access_token, |
|
91 | - 'Content-Type' => 'application/json', |
|
92 | - ), |
|
93 | - ); |
|
94 | - |
|
95 | - if( ! empty( $data )) { |
|
96 | - $args['body'] = wp_json_encode( $data ); |
|
97 | - } |
|
98 | - |
|
99 | - return self::response_or_error( wp_remote_post( $url, $args ) ); |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Handles a get request. |
|
104 | - * |
|
105 | - * @param string $path The path to the endpoint. |
|
106 | - * @param string $method |
|
107 | - * @return object|\WP_Error |
|
108 | - */ |
|
109 | - public static function get( $path, $mode = 'live', $method = 'GET' ) { |
|
110 | - |
|
111 | - $access_token = self::get_token( $mode ); |
|
112 | - |
|
113 | - if ( is_wp_error( $access_token ) ) { |
|
114 | - return $access_token; |
|
115 | - } |
|
116 | - |
|
117 | - $url = self::get_api_url( $path, $mode ); |
|
118 | - $args = array( |
|
119 | - 'method' => $method, |
|
120 | - 'headers' => array( |
|
121 | - 'Authorization' => 'Bearer ' . $access_token, |
|
122 | - ), |
|
123 | - ); |
|
124 | - |
|
125 | - return self::response_or_error( wp_remote_get( $url, $args ) ); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Returns the response body |
|
130 | - * |
|
131 | - * @since 1.0.0 |
|
132 | - * @version 1.0.0 |
|
133 | - * @param \WP_Error|array $response |
|
134 | - * @return \WP_Error|object |
|
135 | - */ |
|
136 | - public static function response_or_error( $response ) { |
|
137 | - |
|
138 | - if ( is_wp_error( $response ) ) { |
|
139 | - return new \WP_Error( 'paypal_error', __( 'There was a problem connecting to the PayPal API endpoint.', 'invoicing' ) ); |
|
140 | - } |
|
141 | - |
|
142 | - if ( empty( $response['body'] ) ) { |
|
143 | - return true; |
|
144 | - } |
|
145 | - |
|
146 | - $response_body = json_decode( wp_remote_retrieve_body( $response ) ); |
|
147 | - |
|
148 | - if ( wp_remote_retrieve_response_code( $response ) > 299 ) { |
|
149 | - |
|
150 | - // Normal errors. |
|
151 | - if ( $response_body && isset( $response_body->message ) ) { |
|
152 | - $error_message = $response_body->message; |
|
153 | - |
|
154 | - // Identity errors. |
|
155 | - } elseif ( $response_body && isset( $response_body->error_description ) ) { |
|
156 | - $error_message = $response_body->error_description; |
|
157 | - return new \WP_Error( 'paypal_error', wp_kses_post( $response_body->error_description ) ); |
|
158 | - } else { |
|
159 | - $error_message = __( 'There was an error connecting to the PayPal API endpoint.', 'invoicing' ); |
|
160 | - } |
|
161 | - |
|
162 | - return new \WP_Error( 'paypal_error', $error_message ); |
|
163 | - } |
|
164 | - |
|
165 | - return $response_body; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Fetches an order. |
|
170 | - * |
|
171 | - * @since 1.0.0 |
|
172 | - * @version 1.0.0 |
|
173 | - * @param string $order_id |
|
174 | - * @link https://developer.paypal.com/docs/api/orders/v2/#orders_get |
|
175 | - * @return \WP_Error|object |
|
176 | - */ |
|
177 | - public static function get_order( $order_id, $mode = 'live' ) { |
|
178 | - return self::get( '/v2/checkout/orders/' . $order_id, $mode ); |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Fetches a subscription. |
|
183 | - * |
|
184 | - * @since 1.0.0 |
|
185 | - * @version 1.0.0 |
|
186 | - * @param string $subscription_id |
|
187 | - * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get |
|
188 | - * @return \WP_Error|object |
|
189 | - */ |
|
190 | - public static function get_subscription( $subscription_id, $mode = 'live' ) { |
|
191 | - return self::get( '/v1/billing/subscriptions/' . $subscription_id, $mode ); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Fetches a subscription's latest transactions (limits search to last one day). |
|
196 | - * |
|
197 | - * @since 1.0.0 |
|
198 | - * @version 1.0.0 |
|
199 | - * @param string $subscription_id |
|
200 | - * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_transactions |
|
201 | - * @return \WP_Error|object |
|
202 | - */ |
|
203 | - public static function get_subscription_transaction( $subscription_id, $mode = 'live' ) { |
|
204 | - $start_time = gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '-1 day' ) ); |
|
205 | - $end_time = gmdate( 'Y-m-d\TH:i:s\Z' ); |
|
206 | - return self::get( "/v1/billing/subscriptions/$subscription_id/transactions?start_time=$start_time&end_time=$end_time", $mode ); |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Refunds a capture. |
|
211 | - * |
|
212 | - * @since 1.0.0 |
|
213 | - * @version 1.0.0 |
|
214 | - * @param string $capture_id |
|
215 | - * @param array $args |
|
216 | - * @link https://developer.paypal.com/docs/api/payments/v2/#captures_refund |
|
217 | - * @return \WP_Error|object |
|
218 | - */ |
|
219 | - public static function refund_capture( $capture_id, $args = array(), $mode = 'live' ) { |
|
220 | - return self::post( '/v2/payments/captures/' . $capture_id . '/refund', $args, $mode ); |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Cancels a subscription. |
|
225 | - * |
|
226 | - * @since 2.8.24 |
|
227 | - * @version 2.8.24 |
|
228 | - * @param string $subscription_id |
|
229 | - * @param array $args |
|
230 | - * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_cancel |
|
231 | - * @return \WP_Error|object |
|
232 | - */ |
|
233 | - public static function cancel_subscription( $subscription_id, $args = array(), $mode = 'live' ) { |
|
234 | - return self::post( '/v1/billing/subscriptions/' . $subscription_id . '/cancel', $args, $mode ); |
|
235 | - } |
|
34 | + $args = array( |
|
35 | + 'method' => 'POST', |
|
36 | + 'timeout' => 30, |
|
37 | + 'headers' => array( |
|
38 | + 'Authorization' => 'Basic ' . base64_encode( $client_id . ':' . $secret_key ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode |
|
39 | + 'Accept' => 'application/json', |
|
40 | + 'Content-Type' => 'application/x-www-form-urlencoded', |
|
41 | + ), |
|
42 | + ); |
|
43 | + |
|
44 | + $response = self::response_or_error( wp_remote_post( $url, $args ) ); |
|
45 | + |
|
46 | + if ( is_wp_error( $response ) ) { |
|
47 | + return $response; |
|
48 | + } |
|
49 | + |
|
50 | + if ( ! isset( $response->access_token ) ) { |
|
51 | + return new \WP_Error( 'invalid_request', 'Could not create token.', array( 'status' => 400 ) ); |
|
52 | + } |
|
53 | + |
|
54 | + set_transient( 'getpaid_paypal_' . $mode . '_token', $response->access_token, $response->expires_in - 600 ); |
|
55 | + return $response->access_token; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Retrieves the PayPal API URL. |
|
60 | + * |
|
61 | + * @param string $endpoint |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + public static function get_api_url( $endpoint = '', $mode = 'live' ) { |
|
65 | + $endpoint = ltrim( $endpoint, '/' ); |
|
66 | + return 'live' === $mode ? 'https://api-m.paypal.com/' . $endpoint : 'https://api-m.sandbox.paypal.com/' . $endpoint; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Handles a post request. |
|
71 | + * |
|
72 | + * @param string $path The path to the endpoint. |
|
73 | + * @param mixed $data The data to send. |
|
74 | + * @param string $method The method to use. |
|
75 | + * |
|
76 | + * @return true|\WP_Error |
|
77 | + */ |
|
78 | + public static function post( $path, $data, $mode = 'live', $method = 'POST' ) { |
|
79 | + |
|
80 | + $access_token = self::get_token( $mode ); |
|
81 | + |
|
82 | + if ( is_wp_error( $access_token ) ) { |
|
83 | + return $access_token; |
|
84 | + } |
|
85 | + |
|
86 | + $url = self::get_api_url( $path, $mode ); |
|
87 | + $args = array( |
|
88 | + 'method' => $method, |
|
89 | + 'headers' => array( |
|
90 | + 'Authorization' => 'Bearer ' . $access_token, |
|
91 | + 'Content-Type' => 'application/json', |
|
92 | + ), |
|
93 | + ); |
|
94 | + |
|
95 | + if( ! empty( $data )) { |
|
96 | + $args['body'] = wp_json_encode( $data ); |
|
97 | + } |
|
98 | + |
|
99 | + return self::response_or_error( wp_remote_post( $url, $args ) ); |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Handles a get request. |
|
104 | + * |
|
105 | + * @param string $path The path to the endpoint. |
|
106 | + * @param string $method |
|
107 | + * @return object|\WP_Error |
|
108 | + */ |
|
109 | + public static function get( $path, $mode = 'live', $method = 'GET' ) { |
|
110 | + |
|
111 | + $access_token = self::get_token( $mode ); |
|
112 | + |
|
113 | + if ( is_wp_error( $access_token ) ) { |
|
114 | + return $access_token; |
|
115 | + } |
|
116 | + |
|
117 | + $url = self::get_api_url( $path, $mode ); |
|
118 | + $args = array( |
|
119 | + 'method' => $method, |
|
120 | + 'headers' => array( |
|
121 | + 'Authorization' => 'Bearer ' . $access_token, |
|
122 | + ), |
|
123 | + ); |
|
124 | + |
|
125 | + return self::response_or_error( wp_remote_get( $url, $args ) ); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Returns the response body |
|
130 | + * |
|
131 | + * @since 1.0.0 |
|
132 | + * @version 1.0.0 |
|
133 | + * @param \WP_Error|array $response |
|
134 | + * @return \WP_Error|object |
|
135 | + */ |
|
136 | + public static function response_or_error( $response ) { |
|
137 | + |
|
138 | + if ( is_wp_error( $response ) ) { |
|
139 | + return new \WP_Error( 'paypal_error', __( 'There was a problem connecting to the PayPal API endpoint.', 'invoicing' ) ); |
|
140 | + } |
|
141 | + |
|
142 | + if ( empty( $response['body'] ) ) { |
|
143 | + return true; |
|
144 | + } |
|
145 | + |
|
146 | + $response_body = json_decode( wp_remote_retrieve_body( $response ) ); |
|
147 | + |
|
148 | + if ( wp_remote_retrieve_response_code( $response ) > 299 ) { |
|
149 | + |
|
150 | + // Normal errors. |
|
151 | + if ( $response_body && isset( $response_body->message ) ) { |
|
152 | + $error_message = $response_body->message; |
|
153 | + |
|
154 | + // Identity errors. |
|
155 | + } elseif ( $response_body && isset( $response_body->error_description ) ) { |
|
156 | + $error_message = $response_body->error_description; |
|
157 | + return new \WP_Error( 'paypal_error', wp_kses_post( $response_body->error_description ) ); |
|
158 | + } else { |
|
159 | + $error_message = __( 'There was an error connecting to the PayPal API endpoint.', 'invoicing' ); |
|
160 | + } |
|
161 | + |
|
162 | + return new \WP_Error( 'paypal_error', $error_message ); |
|
163 | + } |
|
164 | + |
|
165 | + return $response_body; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Fetches an order. |
|
170 | + * |
|
171 | + * @since 1.0.0 |
|
172 | + * @version 1.0.0 |
|
173 | + * @param string $order_id |
|
174 | + * @link https://developer.paypal.com/docs/api/orders/v2/#orders_get |
|
175 | + * @return \WP_Error|object |
|
176 | + */ |
|
177 | + public static function get_order( $order_id, $mode = 'live' ) { |
|
178 | + return self::get( '/v2/checkout/orders/' . $order_id, $mode ); |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Fetches a subscription. |
|
183 | + * |
|
184 | + * @since 1.0.0 |
|
185 | + * @version 1.0.0 |
|
186 | + * @param string $subscription_id |
|
187 | + * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get |
|
188 | + * @return \WP_Error|object |
|
189 | + */ |
|
190 | + public static function get_subscription( $subscription_id, $mode = 'live' ) { |
|
191 | + return self::get( '/v1/billing/subscriptions/' . $subscription_id, $mode ); |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Fetches a subscription's latest transactions (limits search to last one day). |
|
196 | + * |
|
197 | + * @since 1.0.0 |
|
198 | + * @version 1.0.0 |
|
199 | + * @param string $subscription_id |
|
200 | + * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_transactions |
|
201 | + * @return \WP_Error|object |
|
202 | + */ |
|
203 | + public static function get_subscription_transaction( $subscription_id, $mode = 'live' ) { |
|
204 | + $start_time = gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '-1 day' ) ); |
|
205 | + $end_time = gmdate( 'Y-m-d\TH:i:s\Z' ); |
|
206 | + return self::get( "/v1/billing/subscriptions/$subscription_id/transactions?start_time=$start_time&end_time=$end_time", $mode ); |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Refunds a capture. |
|
211 | + * |
|
212 | + * @since 1.0.0 |
|
213 | + * @version 1.0.0 |
|
214 | + * @param string $capture_id |
|
215 | + * @param array $args |
|
216 | + * @link https://developer.paypal.com/docs/api/payments/v2/#captures_refund |
|
217 | + * @return \WP_Error|object |
|
218 | + */ |
|
219 | + public static function refund_capture( $capture_id, $args = array(), $mode = 'live' ) { |
|
220 | + return self::post( '/v2/payments/captures/' . $capture_id . '/refund', $args, $mode ); |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Cancels a subscription. |
|
225 | + * |
|
226 | + * @since 2.8.24 |
|
227 | + * @version 2.8.24 |
|
228 | + * @param string $subscription_id |
|
229 | + * @param array $args |
|
230 | + * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_cancel |
|
231 | + * @return \WP_Error|object |
|
232 | + */ |
|
233 | + public static function cancel_subscription( $subscription_id, $args = array(), $mode = 'live' ) { |
|
234 | + return self::post( '/v1/billing/subscriptions/' . $subscription_id . '/cancel', $args, $mode ); |
|
235 | + } |
|
236 | 236 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // Exit if accessed directly. |
4 | -defined( 'ABSPATH' ) || exit; |
|
4 | +defined('ABSPATH') || exit; |
|
5 | 5 | |
6 | 6 | /** |
7 | 7 | * PayPal API handler. |
@@ -15,43 +15,43 @@ discard block |
||
15 | 15 | * |
16 | 16 | * @return string|\WP_Error |
17 | 17 | */ |
18 | - public static function get_token( $mode = 'live' ) { |
|
18 | + public static function get_token($mode = 'live') { |
|
19 | 19 | |
20 | - $token = get_transient( 'getpaid_paypal_' . $mode . '_token' ); |
|
20 | + $token = get_transient('getpaid_paypal_' . $mode . '_token'); |
|
21 | 21 | |
22 | - if ( $token ) { |
|
22 | + if ($token) { |
|
23 | 23 | return $token; |
24 | 24 | } |
25 | 25 | |
26 | - $client_id = 'live' === $mode ? wpinv_get_option( 'paypal_client_id' ) : wpinv_get_option( 'paypal_sandbox_client_id' ); |
|
27 | - $secret_key = 'live' === $mode ? wpinv_get_option( 'paypal_secret' ) : wpinv_get_option( 'paypal_sandbox_secret' ); |
|
28 | - $url = self::get_api_url( 'v1/oauth2/token?grant_type=client_credentials', $mode ); |
|
26 | + $client_id = 'live' === $mode ? wpinv_get_option('paypal_client_id') : wpinv_get_option('paypal_sandbox_client_id'); |
|
27 | + $secret_key = 'live' === $mode ? wpinv_get_option('paypal_secret') : wpinv_get_option('paypal_sandbox_secret'); |
|
28 | + $url = self::get_api_url('v1/oauth2/token?grant_type=client_credentials', $mode); |
|
29 | 29 | |
30 | - if ( empty( $client_id ) || empty( $secret_key ) ) { |
|
31 | - return new \WP_Error( 'invalid_request', 'Missing client id or secret key.', array( 'status' => 400 ) ); |
|
30 | + if (empty($client_id) || empty($secret_key)) { |
|
31 | + return new \WP_Error('invalid_request', 'Missing client id or secret key.', array('status' => 400)); |
|
32 | 32 | } |
33 | 33 | |
34 | - $args = array( |
|
34 | + $args = array( |
|
35 | 35 | 'method' => 'POST', |
36 | 36 | 'timeout' => 30, |
37 | 37 | 'headers' => array( |
38 | - 'Authorization' => 'Basic ' . base64_encode( $client_id . ':' . $secret_key ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode |
|
38 | + 'Authorization' => 'Basic ' . base64_encode($client_id . ':' . $secret_key), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode |
|
39 | 39 | 'Accept' => 'application/json', |
40 | 40 | 'Content-Type' => 'application/x-www-form-urlencoded', |
41 | 41 | ), |
42 | 42 | ); |
43 | 43 | |
44 | - $response = self::response_or_error( wp_remote_post( $url, $args ) ); |
|
44 | + $response = self::response_or_error(wp_remote_post($url, $args)); |
|
45 | 45 | |
46 | - if ( is_wp_error( $response ) ) { |
|
46 | + if (is_wp_error($response)) { |
|
47 | 47 | return $response; |
48 | 48 | } |
49 | 49 | |
50 | - if ( ! isset( $response->access_token ) ) { |
|
51 | - return new \WP_Error( 'invalid_request', 'Could not create token.', array( 'status' => 400 ) ); |
|
50 | + if (!isset($response->access_token)) { |
|
51 | + return new \WP_Error('invalid_request', 'Could not create token.', array('status' => 400)); |
|
52 | 52 | } |
53 | 53 | |
54 | - set_transient( 'getpaid_paypal_' . $mode . '_token', $response->access_token, $response->expires_in - 600 ); |
|
54 | + set_transient('getpaid_paypal_' . $mode . '_token', $response->access_token, $response->expires_in - 600); |
|
55 | 55 | return $response->access_token; |
56 | 56 | } |
57 | 57 | |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | * @param string $endpoint |
62 | 62 | * @return string |
63 | 63 | */ |
64 | - public static function get_api_url( $endpoint = '', $mode = 'live' ) { |
|
65 | - $endpoint = ltrim( $endpoint, '/' ); |
|
64 | + public static function get_api_url($endpoint = '', $mode = 'live') { |
|
65 | + $endpoint = ltrim($endpoint, '/'); |
|
66 | 66 | return 'live' === $mode ? 'https://api-m.paypal.com/' . $endpoint : 'https://api-m.sandbox.paypal.com/' . $endpoint; |
67 | 67 | } |
68 | 68 | |
@@ -75,15 +75,15 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @return true|\WP_Error |
77 | 77 | */ |
78 | - public static function post( $path, $data, $mode = 'live', $method = 'POST' ) { |
|
78 | + public static function post($path, $data, $mode = 'live', $method = 'POST') { |
|
79 | 79 | |
80 | - $access_token = self::get_token( $mode ); |
|
80 | + $access_token = self::get_token($mode); |
|
81 | 81 | |
82 | - if ( is_wp_error( $access_token ) ) { |
|
82 | + if (is_wp_error($access_token)) { |
|
83 | 83 | return $access_token; |
84 | 84 | } |
85 | 85 | |
86 | - $url = self::get_api_url( $path, $mode ); |
|
86 | + $url = self::get_api_url($path, $mode); |
|
87 | 87 | $args = array( |
88 | 88 | 'method' => $method, |
89 | 89 | 'headers' => array( |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | ), |
93 | 93 | ); |
94 | 94 | |
95 | - if( ! empty( $data )) { |
|
96 | - $args['body'] = wp_json_encode( $data ); |
|
95 | + if (!empty($data)) { |
|
96 | + $args['body'] = wp_json_encode($data); |
|
97 | 97 | } |
98 | 98 | |
99 | - return self::response_or_error( wp_remote_post( $url, $args ) ); |
|
99 | + return self::response_or_error(wp_remote_post($url, $args)); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -106,15 +106,15 @@ discard block |
||
106 | 106 | * @param string $method |
107 | 107 | * @return object|\WP_Error |
108 | 108 | */ |
109 | - public static function get( $path, $mode = 'live', $method = 'GET' ) { |
|
109 | + public static function get($path, $mode = 'live', $method = 'GET') { |
|
110 | 110 | |
111 | - $access_token = self::get_token( $mode ); |
|
111 | + $access_token = self::get_token($mode); |
|
112 | 112 | |
113 | - if ( is_wp_error( $access_token ) ) { |
|
113 | + if (is_wp_error($access_token)) { |
|
114 | 114 | return $access_token; |
115 | 115 | } |
116 | 116 | |
117 | - $url = self::get_api_url( $path, $mode ); |
|
117 | + $url = self::get_api_url($path, $mode); |
|
118 | 118 | $args = array( |
119 | 119 | 'method' => $method, |
120 | 120 | 'headers' => array( |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | ), |
123 | 123 | ); |
124 | 124 | |
125 | - return self::response_or_error( wp_remote_get( $url, $args ) ); |
|
125 | + return self::response_or_error(wp_remote_get($url, $args)); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -133,33 +133,33 @@ discard block |
||
133 | 133 | * @param \WP_Error|array $response |
134 | 134 | * @return \WP_Error|object |
135 | 135 | */ |
136 | - public static function response_or_error( $response ) { |
|
136 | + public static function response_or_error($response) { |
|
137 | 137 | |
138 | - if ( is_wp_error( $response ) ) { |
|
139 | - return new \WP_Error( 'paypal_error', __( 'There was a problem connecting to the PayPal API endpoint.', 'invoicing' ) ); |
|
138 | + if (is_wp_error($response)) { |
|
139 | + return new \WP_Error('paypal_error', __('There was a problem connecting to the PayPal API endpoint.', 'invoicing')); |
|
140 | 140 | } |
141 | 141 | |
142 | - if ( empty( $response['body'] ) ) { |
|
142 | + if (empty($response['body'])) { |
|
143 | 143 | return true; |
144 | 144 | } |
145 | 145 | |
146 | - $response_body = json_decode( wp_remote_retrieve_body( $response ) ); |
|
146 | + $response_body = json_decode(wp_remote_retrieve_body($response)); |
|
147 | 147 | |
148 | - if ( wp_remote_retrieve_response_code( $response ) > 299 ) { |
|
148 | + if (wp_remote_retrieve_response_code($response) > 299) { |
|
149 | 149 | |
150 | 150 | // Normal errors. |
151 | - if ( $response_body && isset( $response_body->message ) ) { |
|
151 | + if ($response_body && isset($response_body->message)) { |
|
152 | 152 | $error_message = $response_body->message; |
153 | 153 | |
154 | 154 | // Identity errors. |
155 | - } elseif ( $response_body && isset( $response_body->error_description ) ) { |
|
155 | + } elseif ($response_body && isset($response_body->error_description)) { |
|
156 | 156 | $error_message = $response_body->error_description; |
157 | - return new \WP_Error( 'paypal_error', wp_kses_post( $response_body->error_description ) ); |
|
157 | + return new \WP_Error('paypal_error', wp_kses_post($response_body->error_description)); |
|
158 | 158 | } else { |
159 | - $error_message = __( 'There was an error connecting to the PayPal API endpoint.', 'invoicing' ); |
|
159 | + $error_message = __('There was an error connecting to the PayPal API endpoint.', 'invoicing'); |
|
160 | 160 | } |
161 | 161 | |
162 | - return new \WP_Error( 'paypal_error', $error_message ); |
|
162 | + return new \WP_Error('paypal_error', $error_message); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | return $response_body; |
@@ -174,8 +174,8 @@ discard block |
||
174 | 174 | * @link https://developer.paypal.com/docs/api/orders/v2/#orders_get |
175 | 175 | * @return \WP_Error|object |
176 | 176 | */ |
177 | - public static function get_order( $order_id, $mode = 'live' ) { |
|
178 | - return self::get( '/v2/checkout/orders/' . $order_id, $mode ); |
|
177 | + public static function get_order($order_id, $mode = 'live') { |
|
178 | + return self::get('/v2/checkout/orders/' . $order_id, $mode); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -187,8 +187,8 @@ discard block |
||
187 | 187 | * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get |
188 | 188 | * @return \WP_Error|object |
189 | 189 | */ |
190 | - public static function get_subscription( $subscription_id, $mode = 'live' ) { |
|
191 | - return self::get( '/v1/billing/subscriptions/' . $subscription_id, $mode ); |
|
190 | + public static function get_subscription($subscription_id, $mode = 'live') { |
|
191 | + return self::get('/v1/billing/subscriptions/' . $subscription_id, $mode); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -200,10 +200,10 @@ discard block |
||
200 | 200 | * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_transactions |
201 | 201 | * @return \WP_Error|object |
202 | 202 | */ |
203 | - public static function get_subscription_transaction( $subscription_id, $mode = 'live' ) { |
|
204 | - $start_time = gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '-1 day' ) ); |
|
205 | - $end_time = gmdate( 'Y-m-d\TH:i:s\Z' ); |
|
206 | - return self::get( "/v1/billing/subscriptions/$subscription_id/transactions?start_time=$start_time&end_time=$end_time", $mode ); |
|
203 | + public static function get_subscription_transaction($subscription_id, $mode = 'live') { |
|
204 | + $start_time = gmdate('Y-m-d\TH:i:s\Z', strtotime('-1 day')); |
|
205 | + $end_time = gmdate('Y-m-d\TH:i:s\Z'); |
|
206 | + return self::get("/v1/billing/subscriptions/$subscription_id/transactions?start_time=$start_time&end_time=$end_time", $mode); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -216,8 +216,8 @@ discard block |
||
216 | 216 | * @link https://developer.paypal.com/docs/api/payments/v2/#captures_refund |
217 | 217 | * @return \WP_Error|object |
218 | 218 | */ |
219 | - public static function refund_capture( $capture_id, $args = array(), $mode = 'live' ) { |
|
220 | - return self::post( '/v2/payments/captures/' . $capture_id . '/refund', $args, $mode ); |
|
219 | + public static function refund_capture($capture_id, $args = array(), $mode = 'live') { |
|
220 | + return self::post('/v2/payments/captures/' . $capture_id . '/refund', $args, $mode); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_cancel |
231 | 231 | * @return \WP_Error|object |
232 | 232 | */ |
233 | - public static function cancel_subscription( $subscription_id, $args = array(), $mode = 'live' ) { |
|
234 | - return self::post( '/v1/billing/subscriptions/' . $subscription_id . '/cancel', $args, $mode ); |
|
233 | + public static function cancel_subscription($subscription_id, $args = array(), $mode = 'live') { |
|
234 | + return self::post('/v1/billing/subscriptions/' . $subscription_id . '/cancel', $args, $mode); |
|
235 | 235 | } |
236 | 236 | } |
@@ -13,103 +13,103 @@ discard block |
||
13 | 13 | class GetPaid_Paypal_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'paypal'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group', 'refunds' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | 34 | public $order = 1; |
35 | 35 | |
36 | 36 | /** |
37 | - * Stores line items to send to PayPal. |
|
38 | - * |
|
39 | - * @var array |
|
40 | - */ |
|
37 | + * Stores line items to send to PayPal. |
|
38 | + * |
|
39 | + * @var array |
|
40 | + */ |
|
41 | 41 | protected $line_items = array(); |
42 | 42 | |
43 | 43 | /** |
44 | - * Endpoint for requests from PayPal. |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
48 | - protected $notify_url; |
|
44 | + * Endpoint for requests from PayPal. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | + protected $notify_url; |
|
49 | 49 | |
50 | - /** |
|
51 | - * Endpoint for requests to PayPal. |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
50 | + /** |
|
51 | + * Endpoint for requests to PayPal. |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | 55 | protected $endpoint; |
56 | 56 | |
57 | 57 | /** |
58 | - * Currencies this gateway is allowed for. |
|
59 | - * |
|
60 | - * @var array |
|
61 | - */ |
|
62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
58 | + * Currencies this gateway is allowed for. |
|
59 | + * |
|
60 | + * @var array |
|
61 | + */ |
|
62 | + public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
63 | 63 | |
64 | 64 | /** |
65 | - * URL to view a transaction. |
|
66 | - * |
|
67 | - * @var string |
|
68 | - */ |
|
65 | + * URL to view a transaction. |
|
66 | + * |
|
67 | + * @var string |
|
68 | + */ |
|
69 | 69 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
70 | 70 | |
71 | 71 | /** |
72 | - * URL to view a subscription. |
|
73 | - * |
|
74 | - * @var string |
|
75 | - */ |
|
76 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
72 | + * URL to view a subscription. |
|
73 | + * |
|
74 | + * @var string |
|
75 | + */ |
|
76 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
77 | 77 | |
78 | 78 | /** |
79 | - * Class constructor. |
|
80 | - */ |
|
81 | - public function __construct() { |
|
82 | - parent::__construct(); |
|
79 | + * Class constructor. |
|
80 | + */ |
|
81 | + public function __construct() { |
|
82 | + parent::__construct(); |
|
83 | 83 | |
84 | 84 | $this->title = __( 'PayPal Standard', 'invoicing' ); |
85 | 85 | $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
86 | 86 | $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
87 | 87 | $this->notify_url = wpinv_get_ipn_url( $this->id ); |
88 | 88 | |
89 | - add_filter( 'wpinv_subscription_cancel_url', array( $this, 'filter_cancel_subscription_url' ), 10, 2 ); |
|
90 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
91 | - add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
92 | - add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
93 | - add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) ); |
|
94 | - |
|
95 | - if ( $this->enabled ) { |
|
96 | - add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
|
97 | - add_action( 'getpaid_paypal_subscription_cancelled', array( $this, 'subscription_cancelled' ) ); |
|
98 | - add_action( 'getpaid_delete_subscription', array( $this, 'subscription_cancelled' ) ); |
|
99 | - add_action( 'getpaid_refund_invoice_remotely', array( $this, 'refund_invoice' ) ); |
|
100 | - } |
|
89 | + add_filter( 'wpinv_subscription_cancel_url', array( $this, 'filter_cancel_subscription_url' ), 10, 2 ); |
|
90 | + add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
91 | + add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
92 | + add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
93 | + add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) ); |
|
94 | + |
|
95 | + if ( $this->enabled ) { |
|
96 | + add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
|
97 | + add_action( 'getpaid_paypal_subscription_cancelled', array( $this, 'subscription_cancelled' ) ); |
|
98 | + add_action( 'getpaid_delete_subscription', array( $this, 'subscription_cancelled' ) ); |
|
99 | + add_action( 'getpaid_refund_invoice_remotely', array( $this, 'refund_invoice' ) ); |
|
100 | + } |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
104 | - * Process Payment. |
|
105 | - * |
|
106 | - * |
|
107 | - * @param WPInv_Invoice $invoice Invoice. |
|
108 | - * @param array $submission_data Posted checkout fields. |
|
109 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
110 | - * @return array |
|
111 | - */ |
|
112 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
104 | + * Process Payment. |
|
105 | + * |
|
106 | + * |
|
107 | + * @param WPInv_Invoice $invoice Invoice. |
|
108 | + * @param array $submission_data Posted checkout fields. |
|
109 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
110 | + * @return array |
|
111 | + */ |
|
112 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
113 | 113 | |
114 | 114 | // Get redirect url. |
115 | 115 | $paypal_redirect = $this->get_request_url( $invoice ); |
@@ -132,15 +132,15 @@ discard block |
||
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
135 | - * Get the PayPal request URL for an invoice. |
|
136 | - * |
|
137 | - * @param WPInv_Invoice $invoice Invoice object. |
|
138 | - * @return string |
|
139 | - */ |
|
140 | - public function get_request_url( $invoice ) { |
|
135 | + * Get the PayPal request URL for an invoice. |
|
136 | + * |
|
137 | + * @param WPInv_Invoice $invoice Invoice object. |
|
138 | + * @return string |
|
139 | + */ |
|
140 | + public function get_request_url( $invoice ) { |
|
141 | 141 | |
142 | 142 | // Endpoint for this request |
143 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
143 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
144 | 144 | |
145 | 145 | // Retrieve paypal args. |
146 | 146 | $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
@@ -153,45 +153,45 @@ discard block |
||
153 | 153 | |
154 | 154 | return add_query_arg( $paypal_args, $this->endpoint ); |
155 | 155 | |
156 | - } |
|
156 | + } |
|
157 | 157 | |
158 | 158 | /** |
159 | - * Get PayPal Args for passing to PP. |
|
160 | - * |
|
161 | - * @param WPInv_Invoice $invoice Invoice object. |
|
162 | - * @return array |
|
163 | - */ |
|
164 | - protected function get_paypal_args( $invoice ) { |
|
159 | + * Get PayPal Args for passing to PP. |
|
160 | + * |
|
161 | + * @param WPInv_Invoice $invoice Invoice object. |
|
162 | + * @return array |
|
163 | + */ |
|
164 | + protected function get_paypal_args( $invoice ) { |
|
165 | 165 | |
166 | 166 | // Whether or not to send the line items as one item. |
167 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
168 | - |
|
169 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
170 | - $force_one_line_item = true; |
|
171 | - } |
|
172 | - |
|
173 | - $paypal_args = apply_filters( |
|
174 | - 'getpaid_paypal_args', |
|
175 | - array_merge( |
|
176 | - $this->get_transaction_args( $invoice ), |
|
177 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
178 | - ), |
|
179 | - $invoice |
|
180 | - ); |
|
181 | - |
|
182 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
167 | + $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
168 | + |
|
169 | + if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
170 | + $force_one_line_item = true; |
|
171 | + } |
|
172 | + |
|
173 | + $paypal_args = apply_filters( |
|
174 | + 'getpaid_paypal_args', |
|
175 | + array_merge( |
|
176 | + $this->get_transaction_args( $invoice ), |
|
177 | + $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
178 | + ), |
|
179 | + $invoice |
|
180 | + ); |
|
181 | + |
|
182 | + return $this->fix_request_length( $invoice, $paypal_args ); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
186 | - * Get transaction args for paypal request. |
|
187 | - * |
|
188 | - * @param WPInv_Invoice $invoice Invoice object. |
|
189 | - * @return array |
|
190 | - */ |
|
191 | - protected function get_transaction_args( $invoice ) { |
|
186 | + * Get transaction args for paypal request. |
|
187 | + * |
|
188 | + * @param WPInv_Invoice $invoice Invoice object. |
|
189 | + * @return array |
|
190 | + */ |
|
191 | + protected function get_transaction_args( $invoice ) { |
|
192 | 192 | |
193 | - $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
194 | - return array( |
|
193 | + $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
194 | + return array( |
|
195 | 195 | 'cmd' => '_cart', |
196 | 196 | 'business' => $email, |
197 | 197 | 'no_shipping' => '1', |
@@ -216,16 +216,16 @@ discard block |
||
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
219 | - * Get line item args for paypal request. |
|
220 | - * |
|
221 | - * @param WPInv_Invoice $invoice Invoice object. |
|
222 | - * @param bool $force_one_line_item Create only one item for this invoice. |
|
223 | - * @return array |
|
224 | - */ |
|
225 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
219 | + * Get line item args for paypal request. |
|
220 | + * |
|
221 | + * @param WPInv_Invoice $invoice Invoice object. |
|
222 | + * @param bool $force_one_line_item Create only one item for this invoice. |
|
223 | + * @return array |
|
224 | + */ |
|
225 | + protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
226 | 226 | |
227 | 227 | // Maybe send invoice as a single item. |
228 | - if ( $force_one_line_item ) { |
|
228 | + if ( $force_one_line_item ) { |
|
229 | 229 | return $this->get_line_item_args_single_item( $invoice ); |
230 | 230 | } |
231 | 231 | |
@@ -245,134 +245,134 @@ discard block |
||
245 | 245 | $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
246 | 246 | } |
247 | 247 | |
248 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
248 | + return array_merge( $line_item_args, $this->get_line_items() ); |
|
249 | 249 | |
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
253 | - * Get line item args for paypal request as a single line item. |
|
254 | - * |
|
255 | - * @param WPInv_Invoice $invoice Invoice object. |
|
256 | - * @return array |
|
257 | - */ |
|
258 | - protected function get_line_item_args_single_item( $invoice ) { |
|
259 | - $this->delete_line_items(); |
|
253 | + * Get line item args for paypal request as a single line item. |
|
254 | + * |
|
255 | + * @param WPInv_Invoice $invoice Invoice object. |
|
256 | + * @return array |
|
257 | + */ |
|
258 | + protected function get_line_item_args_single_item( $invoice ) { |
|
259 | + $this->delete_line_items(); |
|
260 | 260 | |
261 | 261 | $item_name = wp_sprintf( __( 'Invoice %s', 'invoicing' ), $invoice->get_number() ); |
262 | - $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
262 | + $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
263 | 263 | |
264 | - return $this->get_line_items(); |
|
264 | + return $this->get_line_items(); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
268 | - * Return all line items. |
|
269 | - */ |
|
270 | - protected function get_line_items() { |
|
271 | - return $this->line_items; |
|
272 | - } |
|
268 | + * Return all line items. |
|
269 | + */ |
|
270 | + protected function get_line_items() { |
|
271 | + return $this->line_items; |
|
272 | + } |
|
273 | 273 | |
274 | 274 | /** |
275 | - * Remove all line items. |
|
276 | - */ |
|
277 | - protected function delete_line_items() { |
|
278 | - $this->line_items = array(); |
|
275 | + * Remove all line items. |
|
276 | + */ |
|
277 | + protected function delete_line_items() { |
|
278 | + $this->line_items = array(); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
282 | - * Prepare line items to send to paypal. |
|
283 | - * |
|
284 | - * @param WPInv_Invoice $invoice Invoice object. |
|
285 | - */ |
|
286 | - protected function prepare_line_items( $invoice ) { |
|
287 | - $this->delete_line_items(); |
|
288 | - |
|
289 | - // Items. |
|
290 | - foreach ( $invoice->get_items() as $item ) { |
|
291 | - $amount = $item->get_price(); |
|
292 | - $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
293 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
282 | + * Prepare line items to send to paypal. |
|
283 | + * |
|
284 | + * @param WPInv_Invoice $invoice Invoice object. |
|
285 | + */ |
|
286 | + protected function prepare_line_items( $invoice ) { |
|
287 | + $this->delete_line_items(); |
|
288 | + |
|
289 | + // Items. |
|
290 | + foreach ( $invoice->get_items() as $item ) { |
|
291 | + $amount = $item->get_price(); |
|
292 | + $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
293 | + $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | // Fees. |
297 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
297 | + foreach ( $invoice->get_fees() as $fee => $data ) { |
|
298 | 298 | $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
299 | 299 | } |
300 | 300 | |
301 | 301 | } |
302 | 302 | |
303 | 303 | /** |
304 | - * Add PayPal Line Item. |
|
305 | - * |
|
306 | - * @param string $item_name Item name. |
|
307 | - * @param float $quantity Item quantity. |
|
308 | - * @param float $amount Amount. |
|
309 | - * @param string $item_number Item number. |
|
310 | - */ |
|
311 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
312 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
313 | - |
|
314 | - /** |
|
315 | - * Prevent error "Things don't appear to be working at the moment. (https://www.sandbox.paypal.com/webapps/hermes/error)" |
|
316 | - */ |
|
317 | - $item_name = str_replace( "#", "", $item_name ); |
|
318 | - |
|
319 | - $item = apply_filters( |
|
320 | - 'getpaid_paypal_line_item', |
|
321 | - array( |
|
322 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
323 | - 'quantity' => (float) $quantity, |
|
324 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
325 | - 'item_number' => $item_number, |
|
326 | - ), |
|
327 | - $item_name, |
|
328 | - $quantity, |
|
329 | - $amount, |
|
330 | - $item_number |
|
331 | - ); |
|
332 | - |
|
333 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
304 | + * Add PayPal Line Item. |
|
305 | + * |
|
306 | + * @param string $item_name Item name. |
|
307 | + * @param float $quantity Item quantity. |
|
308 | + * @param float $amount Amount. |
|
309 | + * @param string $item_number Item number. |
|
310 | + */ |
|
311 | + protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
312 | + $index = ( count( $this->line_items ) / 4 ) + 1; |
|
313 | + |
|
314 | + /** |
|
315 | + * Prevent error "Things don't appear to be working at the moment. (https://www.sandbox.paypal.com/webapps/hermes/error)" |
|
316 | + */ |
|
317 | + $item_name = str_replace( "#", "", $item_name ); |
|
318 | + |
|
319 | + $item = apply_filters( |
|
320 | + 'getpaid_paypal_line_item', |
|
321 | + array( |
|
322 | + 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
323 | + 'quantity' => (float) $quantity, |
|
324 | + 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
325 | + 'item_number' => $item_number, |
|
326 | + ), |
|
327 | + $item_name, |
|
328 | + $quantity, |
|
329 | + $amount, |
|
330 | + $item_number |
|
331 | + ); |
|
332 | + |
|
333 | + $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
334 | 334 | $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
335 | 335 | |
336 | 336 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
337 | - $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
338 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
337 | + $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
338 | + $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
342 | - * If the default request with line items is too long, generate a new one with only one line item. |
|
343 | - * |
|
344 | - * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
345 | - * |
|
346 | - * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
347 | - * @param array $paypal_args Arguments sent to Paypal in the request. |
|
348 | - * @return array |
|
349 | - */ |
|
350 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
351 | - $max_paypal_length = 2083; |
|
352 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
353 | - |
|
354 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
355 | - return $paypal_args; |
|
356 | - } |
|
357 | - |
|
358 | - return apply_filters( |
|
359 | - 'getpaid_paypal_args', |
|
360 | - array_merge( |
|
361 | - $this->get_transaction_args( $invoice ), |
|
362 | - $this->get_line_item_args( $invoice, true ) |
|
363 | - ), |
|
364 | - $invoice |
|
365 | - ); |
|
342 | + * If the default request with line items is too long, generate a new one with only one line item. |
|
343 | + * |
|
344 | + * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
345 | + * |
|
346 | + * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
347 | + * @param array $paypal_args Arguments sent to Paypal in the request. |
|
348 | + * @return array |
|
349 | + */ |
|
350 | + protected function fix_request_length( $invoice, $paypal_args ) { |
|
351 | + $max_paypal_length = 2083; |
|
352 | + $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
353 | + |
|
354 | + if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
355 | + return $paypal_args; |
|
356 | + } |
|
357 | + |
|
358 | + return apply_filters( |
|
359 | + 'getpaid_paypal_args', |
|
360 | + array_merge( |
|
361 | + $this->get_transaction_args( $invoice ), |
|
362 | + $this->get_line_item_args( $invoice, true ) |
|
363 | + ), |
|
364 | + $invoice |
|
365 | + ); |
|
366 | 366 | |
367 | 367 | } |
368 | 368 | |
369 | 369 | /** |
370 | - * Processes recurring invoices. |
|
371 | - * |
|
372 | - * @param array $paypal_args PayPal args. |
|
373 | - * @param WPInv_Invoice $invoice Invoice object. |
|
374 | - */ |
|
375 | - public function process_subscription( $paypal_args, $invoice ) { |
|
370 | + * Processes recurring invoices. |
|
371 | + * |
|
372 | + * @param array $paypal_args PayPal args. |
|
373 | + * @param WPInv_Invoice $invoice Invoice object. |
|
374 | + */ |
|
375 | + public function process_subscription( $paypal_args, $invoice ) { |
|
376 | 376 | |
377 | 377 | // Make sure this is a subscription. |
378 | 378 | if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) { |
@@ -393,21 +393,21 @@ discard block |
||
393 | 393 | $recurring_amount = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 ); |
394 | 394 | $subscription_item = $invoice->get_recurring( true ); |
395 | 395 | |
396 | - // Convert 365 days to 1 year. |
|
397 | - if ( 'D' == $period && 365 == $interval ) { |
|
398 | - $period = 'Y'; |
|
399 | - $interval = 1; |
|
400 | - } |
|
396 | + // Convert 365 days to 1 year. |
|
397 | + if ( 'D' == $period && 365 == $interval ) { |
|
398 | + $period = 'Y'; |
|
399 | + $interval = 1; |
|
400 | + } |
|
401 | 401 | |
402 | 402 | if ( $subscription_item->has_free_trial() ) { |
403 | 403 | |
404 | 404 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
405 | 405 | |
406 | - // Trial period length. |
|
407 | - $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
406 | + // Trial period length. |
|
407 | + $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
408 | 408 | |
409 | - // Trial period. |
|
410 | - $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
409 | + // Trial period. |
|
410 | + $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
411 | 411 | |
412 | 412 | } elseif ( $initial_amount != $recurring_amount ) { |
413 | 413 | |
@@ -430,40 +430,40 @@ discard block |
||
430 | 430 | } |
431 | 431 | |
432 | 432 | // We have a recurring payment |
433 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
433 | + if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
434 | 434 | |
435 | - // Subscription price |
|
436 | - $paypal_args['a3'] = $recurring_amount; |
|
435 | + // Subscription price |
|
436 | + $paypal_args['a3'] = $recurring_amount; |
|
437 | 437 | |
438 | - // Subscription duration |
|
439 | - $paypal_args['p3'] = $interval; |
|
438 | + // Subscription duration |
|
439 | + $paypal_args['p3'] = $interval; |
|
440 | 440 | |
441 | - // Subscription period |
|
442 | - $paypal_args['t3'] = $period; |
|
441 | + // Subscription period |
|
442 | + $paypal_args['t3'] = $period; |
|
443 | 443 | |
444 | 444 | } |
445 | 445 | |
446 | 446 | // Recurring payments |
447 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
447 | + if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
448 | 448 | |
449 | - // Non-recurring payments |
|
450 | - $paypal_args['src'] = 0; |
|
449 | + // Non-recurring payments |
|
450 | + $paypal_args['src'] = 0; |
|
451 | 451 | |
452 | - } else { |
|
452 | + } else { |
|
453 | 453 | |
454 | - $paypal_args['src'] = 1; |
|
454 | + $paypal_args['src'] = 1; |
|
455 | 455 | |
456 | - if ( $bill_times > 0 ) { |
|
456 | + if ( $bill_times > 0 ) { |
|
457 | 457 | |
458 | - // An initial period is being used to charge a sign-up fee |
|
459 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
460 | - $bill_times--; |
|
461 | - } |
|
458 | + // An initial period is being used to charge a sign-up fee |
|
459 | + if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
460 | + $bill_times--; |
|
461 | + } |
|
462 | 462 | |
463 | 463 | // Make sure it's not over the max of 52 |
464 | 464 | $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
465 | 465 | |
466 | - } |
|
466 | + } |
|
467 | 467 | } |
468 | 468 | |
469 | 469 | // Force return URL so that order description & instructions display |
@@ -475,115 +475,115 @@ discard block |
||
475 | 475 | if ( isset( $paypal_args[ $arg ] ) ) { |
476 | 476 | unset( $paypal_args[ $arg ] ); |
477 | 477 | } |
478 | - } |
|
478 | + } |
|
479 | 479 | |
480 | 480 | return apply_filters( |
481 | - 'getpaid_paypal_subscription_args', |
|
482 | - $paypal_args, |
|
483 | - $invoice |
|
481 | + 'getpaid_paypal_subscription_args', |
|
482 | + $paypal_args, |
|
483 | + $invoice |
|
484 | + ); |
|
485 | + |
|
486 | + } |
|
487 | + |
|
488 | + /** |
|
489 | + * Refunds an invoice remotely. |
|
490 | + * |
|
491 | + * @since 2.8.24 |
|
492 | + * @param WPInv_Invoice $invoice Invoice object. |
|
493 | + */ |
|
494 | + public function refund_invoice( $invoice ) { |
|
495 | + |
|
496 | + if ( $invoice->get_gateway() !== $this->id ) { |
|
497 | + return; |
|
498 | + } |
|
499 | + |
|
500 | + $mode = $this->is_sandbox( $invoice ) ? 'sandbox' : 'live'; |
|
501 | + $result = GetPaid_PayPal_API::refund_capture( $invoice->get_transaction_id(), array(), $mode ); |
|
502 | + |
|
503 | + if ( is_wp_error( $result ) ) { |
|
504 | + $invoice->add_system_note( |
|
505 | + sprintf( |
|
506 | + // translators: %s is the error message. |
|
507 | + __( 'An error occured while trying to refund invoice #%1$s in PayPal: %2$s', 'invoicing' ), |
|
508 | + $invoice->get_id(), |
|
509 | + $result->get_error_message() |
|
510 | + ) |
|
511 | + ); |
|
512 | + } else { |
|
513 | + $invoice->add_system_note( |
|
514 | + sprintf( |
|
515 | + // translators: %s is the refund ID. |
|
516 | + __( 'Successfully refunded invoice #%1$s in PayPal. Refund ID: %2$s', 'invoicing' ), |
|
517 | + $invoice->get_id(), |
|
518 | + $result->id |
|
519 | + ) |
|
520 | + ); |
|
521 | + } |
|
522 | + } |
|
523 | + |
|
524 | + /** |
|
525 | + * Cancels a subscription remotely. |
|
526 | + * |
|
527 | + * @since 2.8.24 |
|
528 | + * @param WPInv_Subscription $subscription Subscription object. |
|
529 | + */ |
|
530 | + public function subscription_cancelled( $subscription ) { |
|
531 | + |
|
532 | + if ( $subscription->get_gateway() != $this->id ) { |
|
533 | + return; |
|
534 | + } |
|
535 | + |
|
536 | + $invoice = $subscription->get_parent_invoice(); |
|
537 | + |
|
538 | + // Abort if the parent invoice does not exist. |
|
539 | + if ( ! $invoice->exists() ) { |
|
540 | + return; |
|
541 | + } |
|
542 | + |
|
543 | + $mode = $this->is_sandbox( $invoice ) ? 'sandbox' : 'live'; |
|
544 | + $result = GetPaid_PayPal_API::cancel_subscription( |
|
545 | + $invoice->get_remote_subscription_id(), |
|
546 | + array( |
|
547 | + 'reason' => __(' Customer requested cancellation', 'invoicing' ), |
|
548 | + ), |
|
549 | + $mode |
|
484 | 550 | ); |
485 | 551 | |
552 | + if ( is_wp_error( $result ) ) { |
|
553 | + |
|
554 | + $error = sprintf( |
|
555 | + // translators: %s is the subscription ID. |
|
556 | + __( 'An error occured while trying to cancel subscription #%s in PayPal.', 'invoicing' ), |
|
557 | + $subscription->get_id() |
|
558 | + ); |
|
559 | + |
|
560 | + getpaid_admin()->show_error( $error . ' ' . $result->get_error_message() ); |
|
561 | + |
|
562 | + if ( ! is_admin() ) { |
|
563 | + wpinv_set_error( $result->get_error_code(), $error ); |
|
564 | + } |
|
565 | + |
|
566 | + return; |
|
567 | + } |
|
568 | + |
|
569 | + if ( is_admin() ) { |
|
570 | + getpaid_admin()->show_success( |
|
571 | + sprintf( |
|
572 | + // translators: %s is the subscription ID. |
|
573 | + __( 'Successfully cancelled subscription #%s in PayPal.', 'invoicing' ), |
|
574 | + $subscription->get_id() |
|
575 | + ) |
|
576 | + ); |
|
577 | + } |
|
578 | + |
|
486 | 579 | } |
487 | 580 | |
488 | - /** |
|
489 | - * Refunds an invoice remotely. |
|
490 | - * |
|
491 | - * @since 2.8.24 |
|
492 | - * @param WPInv_Invoice $invoice Invoice object. |
|
493 | - */ |
|
494 | - public function refund_invoice( $invoice ) { |
|
495 | - |
|
496 | - if ( $invoice->get_gateway() !== $this->id ) { |
|
497 | - return; |
|
498 | - } |
|
499 | - |
|
500 | - $mode = $this->is_sandbox( $invoice ) ? 'sandbox' : 'live'; |
|
501 | - $result = GetPaid_PayPal_API::refund_capture( $invoice->get_transaction_id(), array(), $mode ); |
|
502 | - |
|
503 | - if ( is_wp_error( $result ) ) { |
|
504 | - $invoice->add_system_note( |
|
505 | - sprintf( |
|
506 | - // translators: %s is the error message. |
|
507 | - __( 'An error occured while trying to refund invoice #%1$s in PayPal: %2$s', 'invoicing' ), |
|
508 | - $invoice->get_id(), |
|
509 | - $result->get_error_message() |
|
510 | - ) |
|
511 | - ); |
|
512 | - } else { |
|
513 | - $invoice->add_system_note( |
|
514 | - sprintf( |
|
515 | - // translators: %s is the refund ID. |
|
516 | - __( 'Successfully refunded invoice #%1$s in PayPal. Refund ID: %2$s', 'invoicing' ), |
|
517 | - $invoice->get_id(), |
|
518 | - $result->id |
|
519 | - ) |
|
520 | - ); |
|
521 | - } |
|
522 | - } |
|
523 | - |
|
524 | - /** |
|
525 | - * Cancels a subscription remotely. |
|
526 | - * |
|
527 | - * @since 2.8.24 |
|
528 | - * @param WPInv_Subscription $subscription Subscription object. |
|
529 | - */ |
|
530 | - public function subscription_cancelled( $subscription ) { |
|
531 | - |
|
532 | - if ( $subscription->get_gateway() != $this->id ) { |
|
533 | - return; |
|
534 | - } |
|
535 | - |
|
536 | - $invoice = $subscription->get_parent_invoice(); |
|
537 | - |
|
538 | - // Abort if the parent invoice does not exist. |
|
539 | - if ( ! $invoice->exists() ) { |
|
540 | - return; |
|
541 | - } |
|
542 | - |
|
543 | - $mode = $this->is_sandbox( $invoice ) ? 'sandbox' : 'live'; |
|
544 | - $result = GetPaid_PayPal_API::cancel_subscription( |
|
545 | - $invoice->get_remote_subscription_id(), |
|
546 | - array( |
|
547 | - 'reason' => __(' Customer requested cancellation', 'invoicing' ), |
|
548 | - ), |
|
549 | - $mode |
|
550 | - ); |
|
551 | - |
|
552 | - if ( is_wp_error( $result ) ) { |
|
553 | - |
|
554 | - $error = sprintf( |
|
555 | - // translators: %s is the subscription ID. |
|
556 | - __( 'An error occured while trying to cancel subscription #%s in PayPal.', 'invoicing' ), |
|
557 | - $subscription->get_id() |
|
558 | - ); |
|
559 | - |
|
560 | - getpaid_admin()->show_error( $error . ' ' . $result->get_error_message() ); |
|
561 | - |
|
562 | - if ( ! is_admin() ) { |
|
563 | - wpinv_set_error( $result->get_error_code(), $error ); |
|
564 | - } |
|
565 | - |
|
566 | - return; |
|
567 | - } |
|
568 | - |
|
569 | - if ( is_admin() ) { |
|
570 | - getpaid_admin()->show_success( |
|
571 | - sprintf( |
|
572 | - // translators: %s is the subscription ID. |
|
573 | - __( 'Successfully cancelled subscription #%s in PayPal.', 'invoicing' ), |
|
574 | - $subscription->get_id() |
|
575 | - ) |
|
576 | - ); |
|
577 | - } |
|
578 | - |
|
579 | - } |
|
580 | - |
|
581 | - /** |
|
582 | - * Processes ipns and marks payments as complete. |
|
583 | - * |
|
584 | - * @return void |
|
585 | - */ |
|
586 | - public function verify_ipn() { |
|
581 | + /** |
|
582 | + * Processes ipns and marks payments as complete. |
|
583 | + * |
|
584 | + * @return void |
|
585 | + */ |
|
586 | + public function verify_ipn() { |
|
587 | 587 | new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
588 | 588 | } |
589 | 589 | |
@@ -593,19 +593,19 @@ discard block |
||
593 | 593 | public function sandbox_notice() { |
594 | 594 | |
595 | 595 | return sprintf( |
596 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
597 | - '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
598 | - '</a>' |
|
599 | - ); |
|
596 | + __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
597 | + '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
598 | + '</a>' |
|
599 | + ); |
|
600 | 600 | |
601 | 601 | } |
602 | 602 | |
603 | - /** |
|
604 | - * Filters the gateway settings. |
|
605 | - * |
|
606 | - * @param array $admin_settings |
|
607 | - */ |
|
608 | - public function admin_settings( $admin_settings ) { |
|
603 | + /** |
|
604 | + * Filters the gateway settings. |
|
605 | + * |
|
606 | + * @param array $admin_settings |
|
607 | + */ |
|
608 | + public function admin_settings( $admin_settings ) { |
|
609 | 609 | |
610 | 610 | $currencies = sprintf( |
611 | 611 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -615,66 +615,66 @@ discard block |
||
615 | 615 | $admin_settings['paypal_active']['desc'] .= " ($currencies)"; |
616 | 616 | $admin_settings['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
617 | 617 | |
618 | - // Access tokens. |
|
619 | - $live_email = wpinv_get_option( 'paypal_email' ); |
|
620 | - $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
618 | + // Access tokens. |
|
619 | + $live_email = wpinv_get_option( 'paypal_email' ); |
|
620 | + $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
621 | 621 | |
622 | - $admin_settings['paypal_connect'] = array( |
|
623 | - 'type' => 'hook', |
|
624 | - 'id' => 'paypal_connect', |
|
625 | - 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
626 | - ); |
|
622 | + $admin_settings['paypal_connect'] = array( |
|
623 | + 'type' => 'hook', |
|
624 | + 'id' => 'paypal_connect', |
|
625 | + 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
626 | + ); |
|
627 | 627 | |
628 | 628 | $admin_settings['paypal_email'] = array( |
629 | 629 | 'type' => 'text', |
630 | - 'class' => 'live-auth-data', |
|
630 | + 'class' => 'live-auth-data', |
|
631 | 631 | 'id' => 'paypal_email', |
632 | 632 | 'name' => __( 'Live Email Address', 'invoicing' ), |
633 | 633 | 'desc' => __( 'The email address of your PayPal account.', 'invoicing' ), |
634 | 634 | ); |
635 | 635 | |
636 | - $admin_settings['paypal_sandbox_email'] = array( |
|
636 | + $admin_settings['paypal_sandbox_email'] = array( |
|
637 | 637 | 'type' => 'text', |
638 | - 'class' => 'sandbox-auth-data', |
|
638 | + 'class' => 'sandbox-auth-data', |
|
639 | 639 | 'id' => 'paypal_sandbox_email', |
640 | 640 | 'name' => __( 'Sandbox Email Address', 'invoicing' ), |
641 | 641 | 'desc' => __( 'The email address of your sandbox PayPal account.', 'invoicing' ), |
642 | - 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
642 | + 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
643 | + ); |
|
644 | + |
|
645 | + // Client ID and secret. |
|
646 | + $admin_settings['paypal_client_id'] = array( |
|
647 | + 'type' => 'text', |
|
648 | + 'class' => 'live-auth-data', |
|
649 | + 'id' => 'paypal_client_id', |
|
650 | + 'name' => __( 'Live Client ID', 'invoicing' ), |
|
651 | + 'desc' => __( 'The client ID of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
652 | + ); |
|
653 | + |
|
654 | + $admin_settings['paypal_sandbox_client_id'] = array( |
|
655 | + 'type' => 'text', |
|
656 | + 'class' => 'sandbox-auth-data', |
|
657 | + 'id' => 'paypal_sandbox_client_id', |
|
658 | + 'name' => __( 'Sandbox Client ID', 'invoicing' ), |
|
659 | + 'desc' => __( 'The client ID of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
660 | + 'std' => wpinv_get_option( 'paypal_client_id', '' ), |
|
643 | 661 | ); |
644 | 662 | |
645 | - // Client ID and secret. |
|
646 | - $admin_settings['paypal_client_id'] = array( |
|
647 | - 'type' => 'text', |
|
648 | - 'class' => 'live-auth-data', |
|
649 | - 'id' => 'paypal_client_id', |
|
650 | - 'name' => __( 'Live Client ID', 'invoicing' ), |
|
651 | - 'desc' => __( 'The client ID of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
652 | - ); |
|
653 | - |
|
654 | - $admin_settings['paypal_sandbox_client_id'] = array( |
|
655 | - 'type' => 'text', |
|
656 | - 'class' => 'sandbox-auth-data', |
|
657 | - 'id' => 'paypal_sandbox_client_id', |
|
658 | - 'name' => __( 'Sandbox Client ID', 'invoicing' ), |
|
659 | - 'desc' => __( 'The client ID of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
660 | - 'std' => wpinv_get_option( 'paypal_client_id', '' ), |
|
661 | - ); |
|
662 | - |
|
663 | - $admin_settings['paypal_secret'] = array( |
|
664 | - 'type' => 'text', |
|
665 | - 'class' => 'live-auth-data', |
|
666 | - 'id' => 'paypal_secret', |
|
667 | - 'name' => __( 'Live Secret', 'invoicing' ), |
|
668 | - 'desc' => __( 'The secret of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
669 | - ); |
|
670 | - |
|
671 | - $admin_settings['paypal_sandbox_secret'] = array( |
|
672 | - 'type' => 'text', |
|
673 | - 'class' => 'sandbox-auth-data', |
|
674 | - 'id' => 'paypal_sandbox_secret', |
|
675 | - 'name' => __( 'Sandbox Secret', 'invoicing' ), |
|
676 | - 'desc' => __( 'The secret of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
677 | - ); |
|
663 | + $admin_settings['paypal_secret'] = array( |
|
664 | + 'type' => 'text', |
|
665 | + 'class' => 'live-auth-data', |
|
666 | + 'id' => 'paypal_secret', |
|
667 | + 'name' => __( 'Live Secret', 'invoicing' ), |
|
668 | + 'desc' => __( 'The secret of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
669 | + ); |
|
670 | + |
|
671 | + $admin_settings['paypal_sandbox_secret'] = array( |
|
672 | + 'type' => 'text', |
|
673 | + 'class' => 'sandbox-auth-data', |
|
674 | + 'id' => 'paypal_sandbox_secret', |
|
675 | + 'name' => __( 'Sandbox Secret', 'invoicing' ), |
|
676 | + 'desc' => __( 'The secret of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
677 | + ); |
|
678 | 678 | |
679 | 679 | $admin_settings['paypal_ipn_url'] = array( |
680 | 680 | 'type' => 'ipn_url', |
@@ -685,57 +685,57 @@ discard block |
||
685 | 685 | 'readonly' => true, |
686 | 686 | ); |
687 | 687 | |
688 | - return $admin_settings; |
|
689 | - } |
|
690 | - |
|
691 | - /** |
|
692 | - * Retrieves the URL to cancel a subscription. |
|
693 | - * |
|
694 | - * @param string $url |
|
695 | - * @param WPInv_Subscription $subscription |
|
696 | - */ |
|
697 | - public function filter_cancel_subscription_url( $url, $subscription ) { |
|
698 | - |
|
699 | - if ( $this->id !== $subscription->get_gateway() ) { |
|
700 | - return $url; |
|
701 | - } |
|
702 | - |
|
703 | - // Get the PayPal profile ID. |
|
704 | - $profile_id = $subscription->get_profile_id(); |
|
705 | - |
|
706 | - // Bail if no profile ID. |
|
707 | - if ( empty( $profile_id ) ) { |
|
708 | - return $url; |
|
709 | - } |
|
710 | - |
|
711 | - $cancel_url = 'https://www.paypal.com/myaccount/autopay/connect/%s/cancel'; |
|
712 | - if ( $this->is_sandbox( $subscription->get_parent_payment() ) ) { |
|
713 | - $cancel_url = 'https://www.sandbox.paypal.com/myaccount/autopay/connect/%s/cancel'; |
|
714 | - } |
|
715 | - |
|
716 | - return sprintf( $cancel_url, $profile_id ); |
|
717 | - } |
|
718 | - |
|
719 | - /** |
|
720 | - * Retrieves the PayPal connect URL when using the setup wizzard. |
|
721 | - * |
|
722 | - * |
|
688 | + return $admin_settings; |
|
689 | + } |
|
690 | + |
|
691 | + /** |
|
692 | + * Retrieves the URL to cancel a subscription. |
|
693 | + * |
|
694 | + * @param string $url |
|
695 | + * @param WPInv_Subscription $subscription |
|
696 | + */ |
|
697 | + public function filter_cancel_subscription_url( $url, $subscription ) { |
|
698 | + |
|
699 | + if ( $this->id !== $subscription->get_gateway() ) { |
|
700 | + return $url; |
|
701 | + } |
|
702 | + |
|
703 | + // Get the PayPal profile ID. |
|
704 | + $profile_id = $subscription->get_profile_id(); |
|
705 | + |
|
706 | + // Bail if no profile ID. |
|
707 | + if ( empty( $profile_id ) ) { |
|
708 | + return $url; |
|
709 | + } |
|
710 | + |
|
711 | + $cancel_url = 'https://www.paypal.com/myaccount/autopay/connect/%s/cancel'; |
|
712 | + if ( $this->is_sandbox( $subscription->get_parent_payment() ) ) { |
|
713 | + $cancel_url = 'https://www.sandbox.paypal.com/myaccount/autopay/connect/%s/cancel'; |
|
714 | + } |
|
715 | + |
|
716 | + return sprintf( $cancel_url, $profile_id ); |
|
717 | + } |
|
718 | + |
|
719 | + /** |
|
720 | + * Retrieves the PayPal connect URL when using the setup wizzard. |
|
721 | + * |
|
722 | + * |
|
723 | 723 | * @param array $data |
724 | 724 | * @return string |
725 | - */ |
|
726 | - public static function maybe_get_connect_url( $url = '', $data = array() ) { |
|
727 | - return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
728 | - } |
|
729 | - |
|
730 | - /** |
|
731 | - * Retrieves the PayPal connect URL. |
|
732 | - * |
|
733 | - * |
|
725 | + */ |
|
726 | + public static function maybe_get_connect_url( $url = '', $data = array() ) { |
|
727 | + return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
728 | + } |
|
729 | + |
|
730 | + /** |
|
731 | + * Retrieves the PayPal connect URL. |
|
732 | + * |
|
733 | + * |
|
734 | 734 | * @param bool $is_sandbox |
735 | - * @param string $redirect |
|
735 | + * @param string $redirect |
|
736 | 736 | * @return string |
737 | - */ |
|
738 | - public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
737 | + */ |
|
738 | + public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
739 | 739 | |
740 | 740 | $redirect_url = add_query_arg( |
741 | 741 | array( |
@@ -745,7 +745,7 @@ discard block |
||
745 | 745 | 'tab' => 'gateways', |
746 | 746 | 'section' => 'paypal', |
747 | 747 | 'getpaid-nonce' => wp_create_nonce( 'getpaid-nonce' ), |
748 | - 'redirect' => urlencode( $redirect ), |
|
748 | + 'redirect' => urlencode( $redirect ), |
|
749 | 749 | ), |
750 | 750 | admin_url( 'admin.php' ) |
751 | 751 | ); |
@@ -760,12 +760,12 @@ discard block |
||
760 | 760 | |
761 | 761 | } |
762 | 762 | |
763 | - /** |
|
764 | - * Generates settings page js. |
|
765 | - * |
|
763 | + /** |
|
764 | + * Generates settings page js. |
|
765 | + * |
|
766 | 766 | * @return void |
767 | - */ |
|
768 | - public static function display_connect_buttons() { |
|
767 | + */ |
|
768 | + public static function display_connect_buttons() { |
|
769 | 769 | |
770 | 770 | ?> |
771 | 771 | <div class="wpinv-paypal-connect-live"> |
@@ -807,70 +807,70 @@ discard block |
||
807 | 807 | <?php |
808 | 808 | } |
809 | 809 | |
810 | - /** |
|
811 | - * Connects to PayPal. |
|
812 | - * |
|
813 | - * @param array $data Connection data. |
|
814 | - * @return void |
|
815 | - */ |
|
816 | - public function connect_paypal( $data ) { |
|
817 | - |
|
818 | - $sandbox = $this->is_sandbox(); |
|
819 | - $data = wp_unslash( $data ); |
|
820 | - $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
821 | - |
|
822 | - if ( isset( $data['live_mode'] ) ) { |
|
823 | - $sandbox = empty( $data['live_mode'] ); |
|
824 | - } |
|
825 | - |
|
826 | - wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
827 | - wpinv_update_option( 'paypal_active', 1 ); |
|
828 | - |
|
829 | - if ( ! empty( $data['error_description'] ) ) { |
|
830 | - getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
831 | - } else { |
|
832 | - |
|
833 | - // Retrieve the user info. |
|
834 | - $user_info = wp_remote_get( |
|
835 | - ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
836 | - array( |
|
837 | - |
|
838 | - 'headers' => array( |
|
839 | - 'Authorization' => 'Bearer ' . $access_token, |
|
840 | - 'Content-type' => 'application/json', |
|
841 | - ), |
|
842 | - |
|
843 | - ) |
|
844 | - ); |
|
845 | - |
|
846 | - if ( is_wp_error( $user_info ) ) { |
|
847 | - getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
848 | - } else { |
|
849 | - |
|
850 | - // Create application. |
|
851 | - $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
852 | - |
|
853 | - if ( $sandbox ) { |
|
854 | - wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
855 | - wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
856 | - set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
857 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
858 | - } else { |
|
859 | - wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
860 | - wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
861 | - set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
862 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
863 | - } |
|
864 | - } |
|
865 | - } |
|
866 | - |
|
867 | - $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
868 | - |
|
869 | - if ( isset( $data['step'] ) ) { |
|
870 | - $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
871 | - } |
|
872 | - wp_redirect( $redirect ); |
|
873 | - exit; |
|
874 | - } |
|
810 | + /** |
|
811 | + * Connects to PayPal. |
|
812 | + * |
|
813 | + * @param array $data Connection data. |
|
814 | + * @return void |
|
815 | + */ |
|
816 | + public function connect_paypal( $data ) { |
|
817 | + |
|
818 | + $sandbox = $this->is_sandbox(); |
|
819 | + $data = wp_unslash( $data ); |
|
820 | + $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
821 | + |
|
822 | + if ( isset( $data['live_mode'] ) ) { |
|
823 | + $sandbox = empty( $data['live_mode'] ); |
|
824 | + } |
|
825 | + |
|
826 | + wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
827 | + wpinv_update_option( 'paypal_active', 1 ); |
|
828 | + |
|
829 | + if ( ! empty( $data['error_description'] ) ) { |
|
830 | + getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
831 | + } else { |
|
832 | + |
|
833 | + // Retrieve the user info. |
|
834 | + $user_info = wp_remote_get( |
|
835 | + ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
836 | + array( |
|
837 | + |
|
838 | + 'headers' => array( |
|
839 | + 'Authorization' => 'Bearer ' . $access_token, |
|
840 | + 'Content-type' => 'application/json', |
|
841 | + ), |
|
842 | + |
|
843 | + ) |
|
844 | + ); |
|
845 | + |
|
846 | + if ( is_wp_error( $user_info ) ) { |
|
847 | + getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
848 | + } else { |
|
849 | + |
|
850 | + // Create application. |
|
851 | + $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
852 | + |
|
853 | + if ( $sandbox ) { |
|
854 | + wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
855 | + wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
856 | + set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
857 | + getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
858 | + } else { |
|
859 | + wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
860 | + wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
861 | + set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
862 | + getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
863 | + } |
|
864 | + } |
|
865 | + } |
|
866 | + |
|
867 | + $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
868 | + |
|
869 | + if ( isset( $data['step'] ) ) { |
|
870 | + $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
871 | + } |
|
872 | + wp_redirect( $redirect ); |
|
873 | + exit; |
|
874 | + } |
|
875 | 875 | |
876 | 876 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Paypal Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group', 'refunds' ); |
|
27 | + protected $supports = array('subscription', 'sandbox', 'single_subscription_group', 'refunds'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @var array |
61 | 61 | */ |
62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
62 | + public $currencies = array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR'); |
|
63 | 63 | |
64 | 64 | /** |
65 | 65 | * URL to view a transaction. |
@@ -81,22 +81,22 @@ discard block |
||
81 | 81 | public function __construct() { |
82 | 82 | parent::__construct(); |
83 | 83 | |
84 | - $this->title = __( 'PayPal Standard', 'invoicing' ); |
|
85 | - $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
|
86 | - $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
|
87 | - $this->notify_url = wpinv_get_ipn_url( $this->id ); |
|
88 | - |
|
89 | - add_filter( 'wpinv_subscription_cancel_url', array( $this, 'filter_cancel_subscription_url' ), 10, 2 ); |
|
90 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
91 | - add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
92 | - add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
93 | - add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) ); |
|
94 | - |
|
95 | - if ( $this->enabled ) { |
|
96 | - add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
|
97 | - add_action( 'getpaid_paypal_subscription_cancelled', array( $this, 'subscription_cancelled' ) ); |
|
98 | - add_action( 'getpaid_delete_subscription', array( $this, 'subscription_cancelled' ) ); |
|
99 | - add_action( 'getpaid_refund_invoice_remotely', array( $this, 'refund_invoice' ) ); |
|
84 | + $this->title = __('PayPal Standard', 'invoicing'); |
|
85 | + $this->method_title = __('PayPal Standard', 'invoicing'); |
|
86 | + $this->checkout_button_text = __('Proceed to PayPal', 'invoicing'); |
|
87 | + $this->notify_url = wpinv_get_ipn_url($this->id); |
|
88 | + |
|
89 | + add_filter('wpinv_subscription_cancel_url', array($this, 'filter_cancel_subscription_url'), 10, 2); |
|
90 | + add_filter('getpaid_paypal_args', array($this, 'process_subscription'), 10, 2); |
|
91 | + add_filter('getpaid_get_paypal_connect_url', array($this, 'maybe_get_connect_url'), 10, 2); |
|
92 | + add_action('getpaid_authenticated_admin_action_connect_paypal', array($this, 'connect_paypal')); |
|
93 | + add_action('wpinv_paypal_connect', array($this, 'display_connect_buttons')); |
|
94 | + |
|
95 | + if ($this->enabled) { |
|
96 | + add_filter('getpaid_paypal_sandbox_notice', array($this, 'sandbox_notice')); |
|
97 | + add_action('getpaid_paypal_subscription_cancelled', array($this, 'subscription_cancelled')); |
|
98 | + add_action('getpaid_delete_subscription', array($this, 'subscription_cancelled')); |
|
99 | + add_action('getpaid_refund_invoice_remotely', array($this, 'refund_invoice')); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
@@ -109,16 +109,16 @@ discard block |
||
109 | 109 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
110 | 110 | * @return array |
111 | 111 | */ |
112 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
112 | + public function process_payment($invoice, $submission_data, $submission) { |
|
113 | 113 | |
114 | 114 | // Get redirect url. |
115 | - $paypal_redirect = $this->get_request_url( $invoice ); |
|
115 | + $paypal_redirect = $this->get_request_url($invoice); |
|
116 | 116 | |
117 | 117 | // Add a note about the request url. |
118 | 118 | $invoice->add_note( |
119 | 119 | sprintf( |
120 | - __( 'Redirecting to PayPal: %s', 'invoicing' ), |
|
121 | - esc_url( $paypal_redirect ) |
|
120 | + __('Redirecting to PayPal: %s', 'invoicing'), |
|
121 | + esc_url($paypal_redirect) |
|
122 | 122 | ), |
123 | 123 | false, |
124 | 124 | false, |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | ); |
127 | 127 | |
128 | 128 | // Redirect to PayPal |
129 | - wp_redirect( $paypal_redirect ); |
|
129 | + wp_redirect($paypal_redirect); |
|
130 | 130 | exit; |
131 | 131 | |
132 | 132 | } |
@@ -137,21 +137,21 @@ discard block |
||
137 | 137 | * @param WPInv_Invoice $invoice Invoice object. |
138 | 138 | * @return string |
139 | 139 | */ |
140 | - public function get_request_url( $invoice ) { |
|
140 | + public function get_request_url($invoice) { |
|
141 | 141 | |
142 | 142 | // Endpoint for this request |
143 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
143 | + $this->endpoint = $this->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
144 | 144 | |
145 | 145 | // Retrieve paypal args. |
146 | - $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
|
146 | + $paypal_args = map_deep($this->get_paypal_args($invoice), 'urlencode'); |
|
147 | 147 | |
148 | - if ( $invoice->is_recurring() ) { |
|
148 | + if ($invoice->is_recurring()) { |
|
149 | 149 | $paypal_args['bn'] = 'GetPaid_Subscribe_WPS_US'; |
150 | 150 | } else { |
151 | 151 | $paypal_args['bn'] = 'GetPaid_ShoppingCart_WPS_US'; |
152 | 152 | } |
153 | 153 | |
154 | - return add_query_arg( $paypal_args, $this->endpoint ); |
|
154 | + return add_query_arg($paypal_args, $this->endpoint); |
|
155 | 155 | |
156 | 156 | } |
157 | 157 | |
@@ -161,25 +161,25 @@ discard block |
||
161 | 161 | * @param WPInv_Invoice $invoice Invoice object. |
162 | 162 | * @return array |
163 | 163 | */ |
164 | - protected function get_paypal_args( $invoice ) { |
|
164 | + protected function get_paypal_args($invoice) { |
|
165 | 165 | |
166 | 166 | // Whether or not to send the line items as one item. |
167 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
167 | + $force_one_line_item = apply_filters('getpaid_paypal_force_one_line_item', true, $invoice); |
|
168 | 168 | |
169 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
169 | + if ($invoice->is_recurring() || (wpinv_use_taxes() && wpinv_prices_include_tax())) { |
|
170 | 170 | $force_one_line_item = true; |
171 | 171 | } |
172 | 172 | |
173 | 173 | $paypal_args = apply_filters( |
174 | 174 | 'getpaid_paypal_args', |
175 | 175 | array_merge( |
176 | - $this->get_transaction_args( $invoice ), |
|
177 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
176 | + $this->get_transaction_args($invoice), |
|
177 | + $this->get_line_item_args($invoice, $force_one_line_item) |
|
178 | 178 | ), |
179 | 179 | $invoice |
180 | 180 | ); |
181 | 181 | |
182 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
182 | + return $this->fix_request_length($invoice, $paypal_args); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -188,9 +188,9 @@ discard block |
||
188 | 188 | * @param WPInv_Invoice $invoice Invoice object. |
189 | 189 | * @return array |
190 | 190 | */ |
191 | - protected function get_transaction_args( $invoice ) { |
|
191 | + protected function get_transaction_args($invoice) { |
|
192 | 192 | |
193 | - $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
193 | + $email = $this->is_sandbox($invoice) ? wpinv_get_option('paypal_sandbox_email', wpinv_get_option('paypal_email', '')) : wpinv_get_option('paypal_email', ''); |
|
194 | 194 | return array( |
195 | 195 | 'cmd' => '_cart', |
196 | 196 | 'business' => $email, |
@@ -201,16 +201,16 @@ discard block |
||
201 | 201 | 'rm' => is_ssl() ? 2 : 1, |
202 | 202 | 'upload' => 1, |
203 | 203 | 'currency_code' => $invoice->get_currency(), // https://developer.paypal.com/docs/nvp-soap-api/currency-codes/#paypal |
204 | - 'return' => esc_url_raw( $this->get_return_url( $invoice ) ), |
|
205 | - 'cancel_return' => esc_url_raw( $invoice->get_checkout_payment_url() ), |
|
206 | - 'notify_url' => getpaid_limit_length( $this->notify_url, 255 ), |
|
207 | - 'invoice' => getpaid_limit_length( $invoice->get_number(), 127 ), |
|
204 | + 'return' => esc_url_raw($this->get_return_url($invoice)), |
|
205 | + 'cancel_return' => esc_url_raw($invoice->get_checkout_payment_url()), |
|
206 | + 'notify_url' => getpaid_limit_length($this->notify_url, 255), |
|
207 | + 'invoice' => getpaid_limit_length($invoice->get_number(), 127), |
|
208 | 208 | 'custom' => $invoice->get_id(), |
209 | - 'first_name' => getpaid_limit_length( $invoice->get_first_name(), 32 ), |
|
210 | - 'last_name' => getpaid_limit_length( $invoice->get_last_name(), 64 ), |
|
211 | - 'country' => getpaid_limit_length( $invoice->get_country(), 2 ), |
|
212 | - 'email' => getpaid_limit_length( $invoice->get_email(), 127 ), |
|
213 | - 'cbt' => get_bloginfo( 'name' ), |
|
209 | + 'first_name' => getpaid_limit_length($invoice->get_first_name(), 32), |
|
210 | + 'last_name' => getpaid_limit_length($invoice->get_last_name(), 64), |
|
211 | + 'country' => getpaid_limit_length($invoice->get_country(), 2), |
|
212 | + 'email' => getpaid_limit_length($invoice->get_email(), 127), |
|
213 | + 'cbt' => get_bloginfo('name'), |
|
214 | 214 | ); |
215 | 215 | |
216 | 216 | } |
@@ -222,30 +222,30 @@ discard block |
||
222 | 222 | * @param bool $force_one_line_item Create only one item for this invoice. |
223 | 223 | * @return array |
224 | 224 | */ |
225 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
225 | + protected function get_line_item_args($invoice, $force_one_line_item = false) { |
|
226 | 226 | |
227 | 227 | // Maybe send invoice as a single item. |
228 | - if ( $force_one_line_item ) { |
|
229 | - return $this->get_line_item_args_single_item( $invoice ); |
|
228 | + if ($force_one_line_item) { |
|
229 | + return $this->get_line_item_args_single_item($invoice); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | // Send each line item individually. |
233 | 233 | $line_item_args = array(); |
234 | 234 | |
235 | 235 | // Prepare line items. |
236 | - $this->prepare_line_items( $invoice ); |
|
236 | + $this->prepare_line_items($invoice); |
|
237 | 237 | |
238 | 238 | // Add taxes to the cart |
239 | - if ( wpinv_use_taxes() && $invoice->is_taxable() ) { |
|
240 | - $line_item_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_tax(), 2 ); |
|
239 | + if (wpinv_use_taxes() && $invoice->is_taxable()) { |
|
240 | + $line_item_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_tax(), 2); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | // Add discount. |
244 | - if ( $invoice->get_total_discount() > 0 ) { |
|
245 | - $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
|
244 | + if ($invoice->get_total_discount() > 0) { |
|
245 | + $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_discount(), 2); |
|
246 | 246 | } |
247 | 247 | |
248 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
248 | + return array_merge($line_item_args, $this->get_line_items()); |
|
249 | 249 | |
250 | 250 | } |
251 | 251 | |
@@ -255,11 +255,11 @@ discard block |
||
255 | 255 | * @param WPInv_Invoice $invoice Invoice object. |
256 | 256 | * @return array |
257 | 257 | */ |
258 | - protected function get_line_item_args_single_item( $invoice ) { |
|
258 | + protected function get_line_item_args_single_item($invoice) { |
|
259 | 259 | $this->delete_line_items(); |
260 | 260 | |
261 | - $item_name = wp_sprintf( __( 'Invoice %s', 'invoicing' ), $invoice->get_number() ); |
|
262 | - $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
261 | + $item_name = wp_sprintf(__('Invoice %s', 'invoicing'), $invoice->get_number()); |
|
262 | + $this->add_line_item($item_name, 1, wpinv_round_amount((float) $invoice->get_total(), 2, true), $invoice->get_id()); |
|
263 | 263 | |
264 | 264 | return $this->get_line_items(); |
265 | 265 | } |
@@ -283,19 +283,19 @@ discard block |
||
283 | 283 | * |
284 | 284 | * @param WPInv_Invoice $invoice Invoice object. |
285 | 285 | */ |
286 | - protected function prepare_line_items( $invoice ) { |
|
286 | + protected function prepare_line_items($invoice) { |
|
287 | 287 | $this->delete_line_items(); |
288 | 288 | |
289 | 289 | // Items. |
290 | - foreach ( $invoice->get_items() as $item ) { |
|
290 | + foreach ($invoice->get_items() as $item) { |
|
291 | 291 | $amount = $item->get_price(); |
292 | 292 | $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
293 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
293 | + $this->add_line_item($item->get_raw_name(), $quantity, $amount, $item->get_id()); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | // Fees. |
297 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
298 | - $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
|
297 | + foreach ($invoice->get_fees() as $fee => $data) { |
|
298 | + $this->add_line_item($fee, 1, wpinv_sanitize_amount($data['initial_fee'])); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | } |
@@ -308,20 +308,20 @@ discard block |
||
308 | 308 | * @param float $amount Amount. |
309 | 309 | * @param string $item_number Item number. |
310 | 310 | */ |
311 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
312 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
311 | + protected function add_line_item($item_name, $quantity = 1, $amount = 0.0, $item_number = '') { |
|
312 | + $index = (count($this->line_items) / 4) + 1; |
|
313 | 313 | |
314 | 314 | /** |
315 | 315 | * Prevent error "Things don't appear to be working at the moment. (https://www.sandbox.paypal.com/webapps/hermes/error)" |
316 | 316 | */ |
317 | - $item_name = str_replace( "#", "", $item_name ); |
|
317 | + $item_name = str_replace("#", "", $item_name); |
|
318 | 318 | |
319 | 319 | $item = apply_filters( |
320 | 320 | 'getpaid_paypal_line_item', |
321 | 321 | array( |
322 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
322 | + 'item_name' => html_entity_decode(getpaid_limit_length($item_name ? wp_strip_all_tags($item_name) : __('Item', 'invoicing'), 127), ENT_NOQUOTES, 'UTF-8'), |
|
323 | 323 | 'quantity' => (float) $quantity, |
324 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
324 | + 'amount' => wpinv_sanitize_amount((float) $amount, 2), |
|
325 | 325 | 'item_number' => $item_number, |
326 | 326 | ), |
327 | 327 | $item_name, |
@@ -330,12 +330,12 @@ discard block |
||
330 | 330 | $item_number |
331 | 331 | ); |
332 | 332 | |
333 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
334 | - $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
|
333 | + $this->line_items['item_name_' . $index] = getpaid_limit_length($item['item_name'], 127); |
|
334 | + $this->line_items['quantity_' . $index] = $item['quantity']; |
|
335 | 335 | |
336 | 336 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
337 | - $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
338 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
337 | + $this->line_items['amount_' . $index] = $item['amount'] * $item['quantity']; |
|
338 | + $this->line_items['item_number_' . $index] = getpaid_limit_length($item['item_number'], 127); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
@@ -347,19 +347,19 @@ discard block |
||
347 | 347 | * @param array $paypal_args Arguments sent to Paypal in the request. |
348 | 348 | * @return array |
349 | 349 | */ |
350 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
350 | + protected function fix_request_length($invoice, $paypal_args) { |
|
351 | 351 | $max_paypal_length = 2083; |
352 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
352 | + $query_candidate = http_build_query($paypal_args, '', '&'); |
|
353 | 353 | |
354 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
354 | + if (strlen($this->endpoint . $query_candidate) <= $max_paypal_length) { |
|
355 | 355 | return $paypal_args; |
356 | 356 | } |
357 | 357 | |
358 | 358 | return apply_filters( |
359 | 359 | 'getpaid_paypal_args', |
360 | 360 | array_merge( |
361 | - $this->get_transaction_args( $invoice ), |
|
362 | - $this->get_line_item_args( $invoice, true ) |
|
361 | + $this->get_transaction_args($invoice), |
|
362 | + $this->get_line_item_args($invoice, true) |
|
363 | 363 | ), |
364 | 364 | $invoice |
365 | 365 | ); |
@@ -372,10 +372,10 @@ discard block |
||
372 | 372 | * @param array $paypal_args PayPal args. |
373 | 373 | * @param WPInv_Invoice $invoice Invoice object. |
374 | 374 | */ |
375 | - public function process_subscription( $paypal_args, $invoice ) { |
|
375 | + public function process_subscription($paypal_args, $invoice) { |
|
376 | 376 | |
377 | 377 | // Make sure this is a subscription. |
378 | - if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) { |
|
378 | + if (!$invoice->is_recurring() || !$subscription = getpaid_get_invoice_subscription($invoice)) { |
|
379 | 379 | return $paypal_args; |
380 | 380 | } |
381 | 381 | |
@@ -383,23 +383,23 @@ discard block |
||
383 | 383 | $paypal_args['cmd'] = '_xclick-subscriptions'; |
384 | 384 | |
385 | 385 | // Subscription name. |
386 | - $paypal_args['item_name'] = wp_sprintf( __( 'Invoice %s', 'invoicing' ), $invoice->get_number() ); |
|
386 | + $paypal_args['item_name'] = wp_sprintf(__('Invoice %s', 'invoicing'), $invoice->get_number()); |
|
387 | 387 | |
388 | 388 | // Get subscription args. |
389 | - $period = strtoupper( substr( $subscription->get_period(), 0, 1 ) ); |
|
389 | + $period = strtoupper(substr($subscription->get_period(), 0, 1)); |
|
390 | 390 | $interval = (int) $subscription->get_frequency(); |
391 | 391 | $bill_times = (int) $subscription->get_bill_times(); |
392 | - $initial_amount = (float) wpinv_sanitize_amount( $invoice->get_initial_total(), 2 ); |
|
393 | - $recurring_amount = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 ); |
|
394 | - $subscription_item = $invoice->get_recurring( true ); |
|
392 | + $initial_amount = (float) wpinv_sanitize_amount($invoice->get_initial_total(), 2); |
|
393 | + $recurring_amount = (float) wpinv_sanitize_amount($invoice->get_recurring_total(), 2); |
|
394 | + $subscription_item = $invoice->get_recurring(true); |
|
395 | 395 | |
396 | 396 | // Convert 365 days to 1 year. |
397 | - if ( 'D' == $period && 365 == $interval ) { |
|
397 | + if ('D' == $period && 365 == $interval) { |
|
398 | 398 | $period = 'Y'; |
399 | 399 | $interval = 1; |
400 | 400 | } |
401 | 401 | |
402 | - if ( $subscription_item->has_free_trial() ) { |
|
402 | + if ($subscription_item->has_free_trial()) { |
|
403 | 403 | |
404 | 404 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
405 | 405 | |
@@ -409,28 +409,28 @@ discard block |
||
409 | 409 | // Trial period. |
410 | 410 | $paypal_args['t1'] = $subscription_item->get_trial_period(); |
411 | 411 | |
412 | - } elseif ( $initial_amount != $recurring_amount ) { |
|
412 | + } elseif ($initial_amount != $recurring_amount) { |
|
413 | 413 | |
414 | 414 | // No trial period, but initial amount includes a sign-up fee and/or other items, so charge it as a separate period. |
415 | 415 | |
416 | - if ( 1 == $bill_times ) { |
|
416 | + if (1 == $bill_times) { |
|
417 | 417 | $param_number = 3; |
418 | 418 | } else { |
419 | 419 | $param_number = 1; |
420 | 420 | } |
421 | 421 | |
422 | - $paypal_args[ 'a' . $param_number ] = $initial_amount ? $initial_amount : 0; |
|
422 | + $paypal_args['a' . $param_number] = $initial_amount ? $initial_amount : 0; |
|
423 | 423 | |
424 | 424 | // Sign Up interval |
425 | - $paypal_args[ 'p' . $param_number ] = $interval; |
|
425 | + $paypal_args['p' . $param_number] = $interval; |
|
426 | 426 | |
427 | 427 | // Sign Up unit of duration |
428 | - $paypal_args[ 't' . $param_number ] = $period; |
|
428 | + $paypal_args['t' . $param_number] = $period; |
|
429 | 429 | |
430 | 430 | } |
431 | 431 | |
432 | 432 | // We have a recurring payment |
433 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
433 | + if (!isset($param_number) || 1 == $param_number) { |
|
434 | 434 | |
435 | 435 | // Subscription price |
436 | 436 | $paypal_args['a3'] = $recurring_amount; |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | } |
445 | 445 | |
446 | 446 | // Recurring payments |
447 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
447 | + if (1 == $bill_times || ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial() && 2 == $bill_times)) { |
|
448 | 448 | |
449 | 449 | // Non-recurring payments |
450 | 450 | $paypal_args['src'] = 0; |
@@ -453,15 +453,15 @@ discard block |
||
453 | 453 | |
454 | 454 | $paypal_args['src'] = 1; |
455 | 455 | |
456 | - if ( $bill_times > 0 ) { |
|
456 | + if ($bill_times > 0) { |
|
457 | 457 | |
458 | 458 | // An initial period is being used to charge a sign-up fee |
459 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
459 | + if ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial()) { |
|
460 | 460 | $bill_times--; |
461 | 461 | } |
462 | 462 | |
463 | 463 | // Make sure it's not over the max of 52 |
464 | - $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
|
464 | + $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52); |
|
465 | 465 | |
466 | 466 | } |
467 | 467 | } |
@@ -470,10 +470,10 @@ discard block |
||
470 | 470 | $paypal_args['rm'] = 2; |
471 | 471 | |
472 | 472 | // Get rid of redudant items. |
473 | - foreach ( array( 'item_name_1', 'quantity_1', 'amount_1', 'item_number_1' ) as $arg ) { |
|
473 | + foreach (array('item_name_1', 'quantity_1', 'amount_1', 'item_number_1') as $arg) { |
|
474 | 474 | |
475 | - if ( isset( $paypal_args[ $arg ] ) ) { |
|
476 | - unset( $paypal_args[ $arg ] ); |
|
475 | + if (isset($paypal_args[$arg])) { |
|
476 | + unset($paypal_args[$arg]); |
|
477 | 477 | } |
478 | 478 | } |
479 | 479 | |
@@ -491,20 +491,20 @@ discard block |
||
491 | 491 | * @since 2.8.24 |
492 | 492 | * @param WPInv_Invoice $invoice Invoice object. |
493 | 493 | */ |
494 | - public function refund_invoice( $invoice ) { |
|
494 | + public function refund_invoice($invoice) { |
|
495 | 495 | |
496 | - if ( $invoice->get_gateway() !== $this->id ) { |
|
496 | + if ($invoice->get_gateway() !== $this->id) { |
|
497 | 497 | return; |
498 | 498 | } |
499 | 499 | |
500 | - $mode = $this->is_sandbox( $invoice ) ? 'sandbox' : 'live'; |
|
501 | - $result = GetPaid_PayPal_API::refund_capture( $invoice->get_transaction_id(), array(), $mode ); |
|
500 | + $mode = $this->is_sandbox($invoice) ? 'sandbox' : 'live'; |
|
501 | + $result = GetPaid_PayPal_API::refund_capture($invoice->get_transaction_id(), array(), $mode); |
|
502 | 502 | |
503 | - if ( is_wp_error( $result ) ) { |
|
503 | + if (is_wp_error($result)) { |
|
504 | 504 | $invoice->add_system_note( |
505 | 505 | sprintf( |
506 | 506 | // translators: %s is the error message. |
507 | - __( 'An error occured while trying to refund invoice #%1$s in PayPal: %2$s', 'invoicing' ), |
|
507 | + __('An error occured while trying to refund invoice #%1$s in PayPal: %2$s', 'invoicing'), |
|
508 | 508 | $invoice->get_id(), |
509 | 509 | $result->get_error_message() |
510 | 510 | ) |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | $invoice->add_system_note( |
514 | 514 | sprintf( |
515 | 515 | // translators: %s is the refund ID. |
516 | - __( 'Successfully refunded invoice #%1$s in PayPal. Refund ID: %2$s', 'invoicing' ), |
|
516 | + __('Successfully refunded invoice #%1$s in PayPal. Refund ID: %2$s', 'invoicing'), |
|
517 | 517 | $invoice->get_id(), |
518 | 518 | $result->id |
519 | 519 | ) |
@@ -527,50 +527,50 @@ discard block |
||
527 | 527 | * @since 2.8.24 |
528 | 528 | * @param WPInv_Subscription $subscription Subscription object. |
529 | 529 | */ |
530 | - public function subscription_cancelled( $subscription ) { |
|
530 | + public function subscription_cancelled($subscription) { |
|
531 | 531 | |
532 | - if ( $subscription->get_gateway() != $this->id ) { |
|
532 | + if ($subscription->get_gateway() != $this->id) { |
|
533 | 533 | return; |
534 | 534 | } |
535 | 535 | |
536 | 536 | $invoice = $subscription->get_parent_invoice(); |
537 | 537 | |
538 | 538 | // Abort if the parent invoice does not exist. |
539 | - if ( ! $invoice->exists() ) { |
|
539 | + if (!$invoice->exists()) { |
|
540 | 540 | return; |
541 | 541 | } |
542 | 542 | |
543 | - $mode = $this->is_sandbox( $invoice ) ? 'sandbox' : 'live'; |
|
543 | + $mode = $this->is_sandbox($invoice) ? 'sandbox' : 'live'; |
|
544 | 544 | $result = GetPaid_PayPal_API::cancel_subscription( |
545 | 545 | $invoice->get_remote_subscription_id(), |
546 | 546 | array( |
547 | - 'reason' => __(' Customer requested cancellation', 'invoicing' ), |
|
547 | + 'reason' => __(' Customer requested cancellation', 'invoicing'), |
|
548 | 548 | ), |
549 | 549 | $mode |
550 | 550 | ); |
551 | 551 | |
552 | - if ( is_wp_error( $result ) ) { |
|
552 | + if (is_wp_error($result)) { |
|
553 | 553 | |
554 | 554 | $error = sprintf( |
555 | 555 | // translators: %s is the subscription ID. |
556 | - __( 'An error occured while trying to cancel subscription #%s in PayPal.', 'invoicing' ), |
|
556 | + __('An error occured while trying to cancel subscription #%s in PayPal.', 'invoicing'), |
|
557 | 557 | $subscription->get_id() |
558 | 558 | ); |
559 | 559 | |
560 | - getpaid_admin()->show_error( $error . ' ' . $result->get_error_message() ); |
|
560 | + getpaid_admin()->show_error($error . ' ' . $result->get_error_message()); |
|
561 | 561 | |
562 | - if ( ! is_admin() ) { |
|
563 | - wpinv_set_error( $result->get_error_code(), $error ); |
|
562 | + if (!is_admin()) { |
|
563 | + wpinv_set_error($result->get_error_code(), $error); |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | return; |
567 | 567 | } |
568 | 568 | |
569 | - if ( is_admin() ) { |
|
569 | + if (is_admin()) { |
|
570 | 570 | getpaid_admin()->show_success( |
571 | 571 | sprintf( |
572 | 572 | // translators: %s is the subscription ID. |
573 | - __( 'Successfully cancelled subscription #%s in PayPal.', 'invoicing' ), |
|
573 | + __('Successfully cancelled subscription #%s in PayPal.', 'invoicing'), |
|
574 | 574 | $subscription->get_id() |
575 | 575 | ) |
576 | 576 | ); |
@@ -584,7 +584,7 @@ discard block |
||
584 | 584 | * @return void |
585 | 585 | */ |
586 | 586 | public function verify_ipn() { |
587 | - new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
|
587 | + new GetPaid_Paypal_Gateway_IPN_Handler($this); |
|
588 | 588 | } |
589 | 589 | |
590 | 590 | /** |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | public function sandbox_notice() { |
594 | 594 | |
595 | 595 | return sprintf( |
596 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
596 | + __('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing'), |
|
597 | 597 | '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
598 | 598 | '</a>' |
599 | 599 | ); |
@@ -605,41 +605,41 @@ discard block |
||
605 | 605 | * |
606 | 606 | * @param array $admin_settings |
607 | 607 | */ |
608 | - public function admin_settings( $admin_settings ) { |
|
608 | + public function admin_settings($admin_settings) { |
|
609 | 609 | |
610 | 610 | $currencies = sprintf( |
611 | - __( 'Supported Currencies: %s', 'invoicing' ), |
|
612 | - implode( ', ', $this->currencies ) |
|
611 | + __('Supported Currencies: %s', 'invoicing'), |
|
612 | + implode(', ', $this->currencies) |
|
613 | 613 | ); |
614 | 614 | |
615 | 615 | $admin_settings['paypal_active']['desc'] .= " ($currencies)"; |
616 | - $admin_settings['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
|
616 | + $admin_settings['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing'); |
|
617 | 617 | |
618 | 618 | // Access tokens. |
619 | - $live_email = wpinv_get_option( 'paypal_email' ); |
|
620 | - $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
619 | + $live_email = wpinv_get_option('paypal_email'); |
|
620 | + $sandbox_email = wpinv_get_option('paypal_sandbox_email'); |
|
621 | 621 | |
622 | 622 | $admin_settings['paypal_connect'] = array( |
623 | 623 | 'type' => 'hook', |
624 | 624 | 'id' => 'paypal_connect', |
625 | - 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
625 | + 'name' => __('Connect to PayPal', 'invoicing'), |
|
626 | 626 | ); |
627 | 627 | |
628 | 628 | $admin_settings['paypal_email'] = array( |
629 | 629 | 'type' => 'text', |
630 | 630 | 'class' => 'live-auth-data', |
631 | 631 | 'id' => 'paypal_email', |
632 | - 'name' => __( 'Live Email Address', 'invoicing' ), |
|
633 | - 'desc' => __( 'The email address of your PayPal account.', 'invoicing' ), |
|
632 | + 'name' => __('Live Email Address', 'invoicing'), |
|
633 | + 'desc' => __('The email address of your PayPal account.', 'invoicing'), |
|
634 | 634 | ); |
635 | 635 | |
636 | 636 | $admin_settings['paypal_sandbox_email'] = array( |
637 | 637 | 'type' => 'text', |
638 | 638 | 'class' => 'sandbox-auth-data', |
639 | 639 | 'id' => 'paypal_sandbox_email', |
640 | - 'name' => __( 'Sandbox Email Address', 'invoicing' ), |
|
641 | - 'desc' => __( 'The email address of your sandbox PayPal account.', 'invoicing' ), |
|
642 | - 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
640 | + 'name' => __('Sandbox Email Address', 'invoicing'), |
|
641 | + 'desc' => __('The email address of your sandbox PayPal account.', 'invoicing'), |
|
642 | + 'std' => wpinv_get_option('paypal_email', ''), |
|
643 | 643 | ); |
644 | 644 | |
645 | 645 | // Client ID and secret. |
@@ -647,41 +647,41 @@ discard block |
||
647 | 647 | 'type' => 'text', |
648 | 648 | 'class' => 'live-auth-data', |
649 | 649 | 'id' => 'paypal_client_id', |
650 | - 'name' => __( 'Live Client ID', 'invoicing' ), |
|
651 | - 'desc' => __( 'The client ID of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
650 | + 'name' => __('Live Client ID', 'invoicing'), |
|
651 | + 'desc' => __('The client ID of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing'), |
|
652 | 652 | ); |
653 | 653 | |
654 | 654 | $admin_settings['paypal_sandbox_client_id'] = array( |
655 | 655 | 'type' => 'text', |
656 | 656 | 'class' => 'sandbox-auth-data', |
657 | 657 | 'id' => 'paypal_sandbox_client_id', |
658 | - 'name' => __( 'Sandbox Client ID', 'invoicing' ), |
|
659 | - 'desc' => __( 'The client ID of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
660 | - 'std' => wpinv_get_option( 'paypal_client_id', '' ), |
|
658 | + 'name' => __('Sandbox Client ID', 'invoicing'), |
|
659 | + 'desc' => __('The client ID of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing'), |
|
660 | + 'std' => wpinv_get_option('paypal_client_id', ''), |
|
661 | 661 | ); |
662 | 662 | |
663 | 663 | $admin_settings['paypal_secret'] = array( |
664 | 664 | 'type' => 'text', |
665 | 665 | 'class' => 'live-auth-data', |
666 | 666 | 'id' => 'paypal_secret', |
667 | - 'name' => __( 'Live Secret', 'invoicing' ), |
|
668 | - 'desc' => __( 'The secret of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
667 | + 'name' => __('Live Secret', 'invoicing'), |
|
668 | + 'desc' => __('The secret of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing'), |
|
669 | 669 | ); |
670 | 670 | |
671 | 671 | $admin_settings['paypal_sandbox_secret'] = array( |
672 | 672 | 'type' => 'text', |
673 | 673 | 'class' => 'sandbox-auth-data', |
674 | 674 | 'id' => 'paypal_sandbox_secret', |
675 | - 'name' => __( 'Sandbox Secret', 'invoicing' ), |
|
676 | - 'desc' => __( 'The secret of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
675 | + 'name' => __('Sandbox Secret', 'invoicing'), |
|
676 | + 'desc' => __('The secret of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing'), |
|
677 | 677 | ); |
678 | 678 | |
679 | 679 | $admin_settings['paypal_ipn_url'] = array( |
680 | 680 | 'type' => 'ipn_url', |
681 | 681 | 'id' => 'paypal_ipn_url', |
682 | - 'name' => __( 'IPN Url', 'invoicing' ), |
|
682 | + 'name' => __('IPN Url', 'invoicing'), |
|
683 | 683 | 'std' => $this->notify_url, |
684 | - 'desc' => __( "If you've not enabled IPNs in your paypal account, use the above URL to enable them.", 'invoicing' ) . ' <a href="https://developer.paypal.com/docs/api-basics/notifications/ipn/"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
684 | + 'desc' => __("If you've not enabled IPNs in your paypal account, use the above URL to enable them.", 'invoicing') . ' <a href="https://developer.paypal.com/docs/api-basics/notifications/ipn/"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
685 | 685 | 'readonly' => true, |
686 | 686 | ); |
687 | 687 | |
@@ -694,9 +694,9 @@ discard block |
||
694 | 694 | * @param string $url |
695 | 695 | * @param WPInv_Subscription $subscription |
696 | 696 | */ |
697 | - public function filter_cancel_subscription_url( $url, $subscription ) { |
|
697 | + public function filter_cancel_subscription_url($url, $subscription) { |
|
698 | 698 | |
699 | - if ( $this->id !== $subscription->get_gateway() ) { |
|
699 | + if ($this->id !== $subscription->get_gateway()) { |
|
700 | 700 | return $url; |
701 | 701 | } |
702 | 702 | |
@@ -704,16 +704,16 @@ discard block |
||
704 | 704 | $profile_id = $subscription->get_profile_id(); |
705 | 705 | |
706 | 706 | // Bail if no profile ID. |
707 | - if ( empty( $profile_id ) ) { |
|
707 | + if (empty($profile_id)) { |
|
708 | 708 | return $url; |
709 | 709 | } |
710 | 710 | |
711 | 711 | $cancel_url = 'https://www.paypal.com/myaccount/autopay/connect/%s/cancel'; |
712 | - if ( $this->is_sandbox( $subscription->get_parent_payment() ) ) { |
|
712 | + if ($this->is_sandbox($subscription->get_parent_payment())) { |
|
713 | 713 | $cancel_url = 'https://www.sandbox.paypal.com/myaccount/autopay/connect/%s/cancel'; |
714 | 714 | } |
715 | 715 | |
716 | - return sprintf( $cancel_url, $profile_id ); |
|
716 | + return sprintf($cancel_url, $profile_id); |
|
717 | 717 | } |
718 | 718 | |
719 | 719 | /** |
@@ -723,8 +723,8 @@ discard block |
||
723 | 723 | * @param array $data |
724 | 724 | * @return string |
725 | 725 | */ |
726 | - public static function maybe_get_connect_url( $url = '', $data = array() ) { |
|
727 | - return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
726 | + public static function maybe_get_connect_url($url = '', $data = array()) { |
|
727 | + return self::get_connect_url(false, urldecode($data['redirect'])); |
|
728 | 728 | } |
729 | 729 | |
730 | 730 | /** |
@@ -735,25 +735,25 @@ discard block |
||
735 | 735 | * @param string $redirect |
736 | 736 | * @return string |
737 | 737 | */ |
738 | - public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
738 | + public static function get_connect_url($is_sandbox, $redirect = '') { |
|
739 | 739 | |
740 | 740 | $redirect_url = add_query_arg( |
741 | 741 | array( |
742 | 742 | 'getpaid-admin-action' => 'connect_paypal', |
743 | 743 | 'page' => 'wpinv-settings', |
744 | - 'live_mode' => (int) empty( $is_sandbox ), |
|
744 | + 'live_mode' => (int) empty($is_sandbox), |
|
745 | 745 | 'tab' => 'gateways', |
746 | 746 | 'section' => 'paypal', |
747 | - 'getpaid-nonce' => wp_create_nonce( 'getpaid-nonce' ), |
|
748 | - 'redirect' => urlencode( $redirect ), |
|
747 | + 'getpaid-nonce' => wp_create_nonce('getpaid-nonce'), |
|
748 | + 'redirect' => urlencode($redirect), |
|
749 | 749 | ), |
750 | - admin_url( 'admin.php' ) |
|
750 | + admin_url('admin.php') |
|
751 | 751 | ); |
752 | 752 | |
753 | 753 | return add_query_arg( |
754 | 754 | array( |
755 | - 'live_mode' => (int) empty( $is_sandbox ), |
|
756 | - 'redirect_url' => urlencode( str_replace( '&', '&', $redirect_url ) ), |
|
755 | + 'live_mode' => (int) empty($is_sandbox), |
|
756 | + 'redirect_url' => urlencode(str_replace('&', '&', $redirect_url)), |
|
757 | 757 | ), |
758 | 758 | 'https://ayecode.io/oauth/paypal' |
759 | 759 | ); |
@@ -769,10 +769,10 @@ discard block |
||
769 | 769 | |
770 | 770 | ?> |
771 | 771 | <div class="wpinv-paypal-connect-live"> |
772 | - <a class="button button-primary" href="<?php echo esc_url( self::get_connect_url( false ) ); ?>"><?php esc_html_e( 'Connect to PayPal', 'invoicing' ); ?></a> |
|
772 | + <a class="button button-primary" href="<?php echo esc_url(self::get_connect_url(false)); ?>"><?php esc_html_e('Connect to PayPal', 'invoicing'); ?></a> |
|
773 | 773 | </div> |
774 | 774 | <div class="wpinv-paypal-connect-sandbox"> |
775 | - <a class="button button-primary" href="<?php echo esc_url( self::get_connect_url( true ) ); ?>"><?php esc_html_e( 'Connect to PayPal Sandbox', 'invoicing' ); ?></a> |
|
775 | + <a class="button button-primary" href="<?php echo esc_url(self::get_connect_url(true)); ?>"><?php esc_html_e('Connect to PayPal Sandbox', 'invoicing'); ?></a> |
|
776 | 776 | </div> |
777 | 777 | |
778 | 778 | <script> |
@@ -813,26 +813,26 @@ discard block |
||
813 | 813 | * @param array $data Connection data. |
814 | 814 | * @return void |
815 | 815 | */ |
816 | - public function connect_paypal( $data ) { |
|
816 | + public function connect_paypal($data) { |
|
817 | 817 | |
818 | 818 | $sandbox = $this->is_sandbox(); |
819 | - $data = wp_unslash( $data ); |
|
820 | - $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
819 | + $data = wp_unslash($data); |
|
820 | + $access_token = empty($data['access_token']) ? '' : sanitize_text_field($data['access_token']); |
|
821 | 821 | |
822 | - if ( isset( $data['live_mode'] ) ) { |
|
823 | - $sandbox = empty( $data['live_mode'] ); |
|
822 | + if (isset($data['live_mode'])) { |
|
823 | + $sandbox = empty($data['live_mode']); |
|
824 | 824 | } |
825 | 825 | |
826 | - wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
827 | - wpinv_update_option( 'paypal_active', 1 ); |
|
826 | + wpinv_update_option('paypal_sandbox', (int) $sandbox); |
|
827 | + wpinv_update_option('paypal_active', 1); |
|
828 | 828 | |
829 | - if ( ! empty( $data['error_description'] ) ) { |
|
830 | - getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
829 | + if (!empty($data['error_description'])) { |
|
830 | + getpaid_admin()->show_error(wp_kses_post(urldecode($data['error_description']))); |
|
831 | 831 | } else { |
832 | 832 | |
833 | 833 | // Retrieve the user info. |
834 | 834 | $user_info = wp_remote_get( |
835 | - ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
835 | + !$sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
836 | 836 | array( |
837 | 837 | |
838 | 838 | 'headers' => array( |
@@ -843,33 +843,33 @@ discard block |
||
843 | 843 | ) |
844 | 844 | ); |
845 | 845 | |
846 | - if ( is_wp_error( $user_info ) ) { |
|
847 | - getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
846 | + if (is_wp_error($user_info)) { |
|
847 | + getpaid_admin()->show_error(wp_kses_post($user_info->get_error_message())); |
|
848 | 848 | } else { |
849 | 849 | |
850 | 850 | // Create application. |
851 | - $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
851 | + $user_info = json_decode(wp_remote_retrieve_body($user_info)); |
|
852 | 852 | |
853 | - if ( $sandbox ) { |
|
854 | - wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
855 | - wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
856 | - set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
857 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
853 | + if ($sandbox) { |
|
854 | + wpinv_update_option('paypal_sandbox_email', sanitize_email($user_info->emails[0]->value)); |
|
855 | + wpinv_update_option('paypal_sandbox_refresh_token', sanitize_text_field(urldecode($data['refresh_token']))); |
|
856 | + set_transient('getpaid_paypal_sandbox_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']); |
|
857 | + getpaid_admin()->show_success(__('Successfully connected your PayPal sandbox account', 'invoicing')); |
|
858 | 858 | } else { |
859 | - wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
860 | - wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
861 | - set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
862 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
859 | + wpinv_update_option('paypal_email', sanitize_email($user_info->emails[0]->value)); |
|
860 | + wpinv_update_option('paypal_refresh_token', sanitize_text_field(urldecode($data['refresh_token']))); |
|
861 | + set_transient('getpaid_paypal_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']); |
|
862 | + getpaid_admin()->show_success(__('Successfully connected your PayPal account', 'invoicing')); |
|
863 | 863 | } |
864 | 864 | } |
865 | 865 | } |
866 | 866 | |
867 | - $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
867 | + $redirect = empty($data['redirect']) ? admin_url('admin.php?page=wpinv-settings&tab=gateways§ion=paypal') : urldecode($data['redirect']); |
|
868 | 868 | |
869 | - if ( isset( $data['step'] ) ) { |
|
870 | - $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
869 | + if (isset($data['step'])) { |
|
870 | + $redirect = add_query_arg('step', $data['step'], $redirect); |
|
871 | 871 | } |
872 | - wp_redirect( $redirect ); |
|
872 | + wp_redirect($redirect); |
|
873 | 873 | exit; |
874 | 874 | } |
875 | 875 |
@@ -13,19 +13,19 @@ |
||
13 | 13 | $label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) ); |
14 | 14 | |
15 | 15 | if ( ! empty( $required ) ) { |
16 | - $label .= "<span class='text-danger'> *</span>"; |
|
16 | + $label .= "<span class='text-danger'> *</span>"; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | aui()->input( |
20 | - array( |
|
21 | - 'type' => 'checkbox', |
|
22 | - 'name' => esc_attr( $id ), |
|
23 | - 'id' => esc_attr( $element_id ), |
|
24 | - 'required' => ! empty( $required ), |
|
25 | - 'label' => $label, |
|
26 | - 'value' => esc_attr__( 'Yes', 'invoicing' ), |
|
27 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
28 | - 'class' => $label_class |
|
29 | - ), |
|
30 | - true |
|
20 | + array( |
|
21 | + 'type' => 'checkbox', |
|
22 | + 'name' => esc_attr( $id ), |
|
23 | + 'id' => esc_attr( $element_id ), |
|
24 | + 'required' => ! empty( $required ), |
|
25 | + 'label' => $label, |
|
26 | + 'value' => esc_attr__( 'Yes', 'invoicing' ), |
|
27 | + 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
28 | + 'class' => $label_class |
|
29 | + ), |
|
30 | + true |
|
31 | 31 | ); |
@@ -7,24 +7,24 @@ |
||
7 | 7 | * @version 2.8.24 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | -$label = empty( $label ) ? '' : wp_kses_post( $label ); |
|
13 | -$label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) ); |
|
12 | +$label = empty($label) ? '' : wp_kses_post($label); |
|
13 | +$label_class = sanitize_key(preg_replace('/[^A-Za-z0-9_-]/', '-', $label)); |
|
14 | 14 | |
15 | -if ( ! empty( $required ) ) { |
|
15 | +if (!empty($required)) { |
|
16 | 16 | $label .= "<span class='text-danger'> *</span>"; |
17 | 17 | } |
18 | 18 | |
19 | 19 | aui()->input( |
20 | 20 | array( |
21 | 21 | 'type' => 'checkbox', |
22 | - 'name' => esc_attr( $id ), |
|
23 | - 'id' => esc_attr( $element_id ), |
|
24 | - 'required' => ! empty( $required ), |
|
22 | + 'name' => esc_attr($id), |
|
23 | + 'id' => esc_attr($element_id), |
|
24 | + 'required' => !empty($required), |
|
25 | 25 | 'label' => $label, |
26 | - 'value' => esc_attr__( 'Yes', 'invoicing' ), |
|
27 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
26 | + 'value' => esc_attr__('Yes', 'invoicing'), |
|
27 | + 'help_text' => empty($description) ? '' : wp_kses_post($description), |
|
28 | 28 | 'class' => $label_class |
29 | 29 | ), |
30 | 30 | true |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | defined( 'ABSPATH' ) || exit; |
11 | 11 | |
12 | 12 | if ( empty( $fields ) ) { |
13 | - return; |
|
13 | + return; |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | // A prefix for all ids (so that a form can be included in the same page multiple times). |
@@ -18,12 +18,12 @@ discard block |
||
18 | 18 | |
19 | 19 | // Prepare the user's country. |
20 | 20 | if ( ! empty( $form->invoice ) ) { |
21 | - $country = $form->invoice->get_country(); |
|
21 | + $country = $form->invoice->get_country(); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | if ( empty( $country ) ) { |
25 | - $country = empty( $country ) ? getpaid_get_ip_country() : $country; |
|
26 | - $country = empty( $country ) ? wpinv_get_default_country() : $country; |
|
25 | + $country = empty( $country ) ? getpaid_get_ip_country() : $country; |
|
26 | + $country = empty( $country ) ? wpinv_get_default_country() : $country; |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | // A prefix for all ids (so that a form can be included in the same page multiple times). |
@@ -50,32 +50,32 @@ discard block |
||
50 | 50 | <!-- Start Billing Address --> |
51 | 51 | <div class="getpaid-billing-address-wrapper"> |
52 | 52 | <?php |
53 | - $field_type = 'billing'; |
|
53 | + $field_type = 'billing'; |
|
54 | 54 | |
55 | - wpinv_get_template( 'payment-forms/elements/address-fields.php', array( 'form' => $form, 'fields' => $fields, 'address_type' => $address_type, 'field_type' => $field_type, 'uniqid' => $uniqid, 'country' => $country ) ); |
|
55 | + wpinv_get_template( 'payment-forms/elements/address-fields.php', array( 'form' => $form, 'fields' => $fields, 'address_type' => $address_type, 'field_type' => $field_type, 'uniqid' => $uniqid, 'country' => $country ) ); |
|
56 | 56 | |
57 | - do_action( 'getpaid_after_payment_form_billing_fields', $form ); |
|
58 | - ?> |
|
57 | + do_action( 'getpaid_after_payment_form_billing_fields', $form ); |
|
58 | + ?> |
|
59 | 59 | </div> |
60 | 60 | <!-- End Billing Address --> |
61 | 61 | <?php endif; ?> |
62 | 62 | |
63 | 63 | <?php if ( 'both' === $address_type ) : ?> |
64 | 64 | <?php |
65 | - aui()->input( |
|
66 | - array( |
|
67 | - 'type' => 'checkbox', |
|
68 | - 'name' => 'same-shipping-address', |
|
69 | - 'id' => "shipping-toggle$uniqid", |
|
70 | - 'required' => false, |
|
71 | - 'label' => empty( $shipping_address_toggle ) ? esc_html__( 'Same billing & shipping address.', 'invoicing' ) : wp_kses_post( $shipping_address_toggle ), |
|
72 | - 'value' => 1, |
|
73 | - 'checked' => true, |
|
74 | - 'class' => 'chkbox-same-shipping-address' |
|
75 | - ), |
|
76 | - true |
|
77 | - ); |
|
78 | - ?> |
|
65 | + aui()->input( |
|
66 | + array( |
|
67 | + 'type' => 'checkbox', |
|
68 | + 'name' => 'same-shipping-address', |
|
69 | + 'id' => "shipping-toggle$uniqid", |
|
70 | + 'required' => false, |
|
71 | + 'label' => empty( $shipping_address_toggle ) ? esc_html__( 'Same billing & shipping address.', 'invoicing' ) : wp_kses_post( $shipping_address_toggle ), |
|
72 | + 'value' => 1, |
|
73 | + 'checked' => true, |
|
74 | + 'class' => 'chkbox-same-shipping-address' |
|
75 | + ), |
|
76 | + true |
|
77 | + ); |
|
78 | + ?> |
|
79 | 79 | <!-- Start Shipping Address Title --> |
80 | 80 | <h4 class="mb-3 getpaid-shipping-address-title"> |
81 | 81 | <?php esc_html_e( 'Shipping Address', 'invoicing' ); ?> |
@@ -87,12 +87,12 @@ discard block |
||
87 | 87 | <!-- Start Shipping Address --> |
88 | 88 | <div class="getpaid-shipping-address-wrapper"> |
89 | 89 | <?php |
90 | - $field_type = 'shipping'; |
|
90 | + $field_type = 'shipping'; |
|
91 | 91 | |
92 | - wpinv_get_template( 'payment-forms/elements/address-fields.php', array( 'form' => $form, 'fields' => $fields, 'address_type' => $address_type, 'field_type' => $field_type, 'uniqid' => $uniqid, 'country' => $country ) ); |
|
92 | + wpinv_get_template( 'payment-forms/elements/address-fields.php', array( 'form' => $form, 'fields' => $fields, 'address_type' => $address_type, 'field_type' => $field_type, 'uniqid' => $uniqid, 'country' => $country ) ); |
|
93 | 93 | |
94 | - do_action( 'getpaid_after_payment_form_shipping_fields', $form ); |
|
95 | - ?> |
|
94 | + do_action( 'getpaid_after_payment_form_shipping_fields', $form ); |
|
95 | + ?> |
|
96 | 96 | </div> |
97 | 97 | <!-- End Shipping Address --> |
98 | 98 | <?php endif; ?> |
@@ -7,60 +7,60 @@ discard block |
||
7 | 7 | * @version 2.8.24 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | -if ( empty( $fields ) ) { |
|
12 | +if (empty($fields)) { |
|
13 | 13 | return; |
14 | 14 | } |
15 | 15 | |
16 | 16 | // A prefix for all ids (so that a form can be included in the same page multiple times). |
17 | -$uniqid = uniqid( '_' ); |
|
17 | +$uniqid = uniqid('_'); |
|
18 | 18 | |
19 | 19 | // Prepare the user's country. |
20 | -if ( ! empty( $form->invoice ) ) { |
|
20 | +if (!empty($form->invoice)) { |
|
21 | 21 | $country = $form->invoice->get_country(); |
22 | 22 | } |
23 | 23 | |
24 | -if ( empty( $country ) ) { |
|
25 | - $country = empty( $country ) ? getpaid_get_ip_country() : $country; |
|
26 | - $country = empty( $country ) ? wpinv_get_default_country() : $country; |
|
24 | +if (empty($country)) { |
|
25 | + $country = empty($country) ? getpaid_get_ip_country() : $country; |
|
26 | + $country = empty($country) ? wpinv_get_default_country() : $country; |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | // A prefix for all ids (so that a form can be included in the same page multiple times). |
30 | -$uniqid = uniqid( '_' ); |
|
30 | +$uniqid = uniqid('_'); |
|
31 | 31 | |
32 | -$address_type = empty( $address_type ) ? 'billing' : $address_type; |
|
32 | +$address_type = empty($address_type) ? 'billing' : $address_type; |
|
33 | 33 | ?> |
34 | 34 | |
35 | -<?php if ( 'both' === $address_type ) : ?> |
|
35 | +<?php if ('both' === $address_type) : ?> |
|
36 | 36 | <!-- Start Billing/Shipping Address Title --> |
37 | 37 | <h4 class="mb-3 getpaid-shipping-billing-address-title"> |
38 | - <?php esc_html_e( 'Billing / Shipping Address', 'invoicing' ); ?> |
|
38 | + <?php esc_html_e('Billing / Shipping Address', 'invoicing'); ?> |
|
39 | 39 | </h4> |
40 | 40 | <!-- End Billing Address Title --> |
41 | 41 | |
42 | 42 | <!-- Start Billing Address Title --> |
43 | 43 | <h4 class="mb-3 getpaid-billing-address-title"> |
44 | - <?php esc_html_e( 'Billing Address', 'invoicing' ); ?> |
|
44 | + <?php esc_html_e('Billing Address', 'invoicing'); ?> |
|
45 | 45 | </h4> |
46 | 46 | <!-- End Billing Address Title --> |
47 | 47 | <?php endif; ?> |
48 | 48 | |
49 | -<?php if ( 'both' === $address_type || 'billing' === $address_type ) : ?> |
|
49 | +<?php if ('both' === $address_type || 'billing' === $address_type) : ?> |
|
50 | 50 | <!-- Start Billing Address --> |
51 | 51 | <div class="getpaid-billing-address-wrapper"> |
52 | 52 | <?php |
53 | 53 | $field_type = 'billing'; |
54 | 54 | |
55 | - wpinv_get_template( 'payment-forms/elements/address-fields.php', array( 'form' => $form, 'fields' => $fields, 'address_type' => $address_type, 'field_type' => $field_type, 'uniqid' => $uniqid, 'country' => $country ) ); |
|
55 | + wpinv_get_template('payment-forms/elements/address-fields.php', array('form' => $form, 'fields' => $fields, 'address_type' => $address_type, 'field_type' => $field_type, 'uniqid' => $uniqid, 'country' => $country)); |
|
56 | 56 | |
57 | - do_action( 'getpaid_after_payment_form_billing_fields', $form ); |
|
57 | + do_action('getpaid_after_payment_form_billing_fields', $form); |
|
58 | 58 | ?> |
59 | 59 | </div> |
60 | 60 | <!-- End Billing Address --> |
61 | 61 | <?php endif; ?> |
62 | 62 | |
63 | -<?php if ( 'both' === $address_type ) : ?> |
|
63 | +<?php if ('both' === $address_type) : ?> |
|
64 | 64 | <?php |
65 | 65 | aui()->input( |
66 | 66 | array( |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | 'name' => 'same-shipping-address', |
69 | 69 | 'id' => "shipping-toggle$uniqid", |
70 | 70 | 'required' => false, |
71 | - 'label' => empty( $shipping_address_toggle ) ? esc_html__( 'Same billing & shipping address.', 'invoicing' ) : wp_kses_post( $shipping_address_toggle ), |
|
71 | + 'label' => empty($shipping_address_toggle) ? esc_html__('Same billing & shipping address.', 'invoicing') : wp_kses_post($shipping_address_toggle), |
|
72 | 72 | 'value' => 1, |
73 | 73 | 'checked' => true, |
74 | 74 | 'class' => 'chkbox-same-shipping-address' |
@@ -78,20 +78,20 @@ discard block |
||
78 | 78 | ?> |
79 | 79 | <!-- Start Shipping Address Title --> |
80 | 80 | <h4 class="mb-3 getpaid-shipping-address-title"> |
81 | - <?php esc_html_e( 'Shipping Address', 'invoicing' ); ?> |
|
81 | + <?php esc_html_e('Shipping Address', 'invoicing'); ?> |
|
82 | 82 | </h4> |
83 | 83 | <!-- End Shipping Address Title --> |
84 | 84 | <?php endif; ?> |
85 | 85 | |
86 | -<?php if ( 'both' === $address_type || 'shipping' === $address_type ) : ?> |
|
86 | +<?php if ('both' === $address_type || 'shipping' === $address_type) : ?> |
|
87 | 87 | <!-- Start Shipping Address --> |
88 | 88 | <div class="getpaid-shipping-address-wrapper"> |
89 | 89 | <?php |
90 | 90 | $field_type = 'shipping'; |
91 | 91 | |
92 | - wpinv_get_template( 'payment-forms/elements/address-fields.php', array( 'form' => $form, 'fields' => $fields, 'address_type' => $address_type, 'field_type' => $field_type, 'uniqid' => $uniqid, 'country' => $country ) ); |
|
92 | + wpinv_get_template('payment-forms/elements/address-fields.php', array('form' => $form, 'fields' => $fields, 'address_type' => $address_type, 'field_type' => $field_type, 'uniqid' => $uniqid, 'country' => $country)); |
|
93 | 93 | |
94 | - do_action( 'getpaid_after_payment_form_shipping_fields', $form ); |
|
94 | + do_action('getpaid_after_payment_form_shipping_fields', $form); |
|
95 | 95 | ?> |
96 | 96 | </div> |
97 | 97 | <!-- End Shipping Address --> |
@@ -14,620 +14,620 @@ |
||
14 | 14 | */ |
15 | 15 | class WPInv_Plugin { |
16 | 16 | |
17 | - /** |
|
18 | - * GetPaid version. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - public $version; |
|
23 | - |
|
24 | - /** |
|
25 | - * Data container. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $data = array(); |
|
30 | - |
|
31 | - /** |
|
32 | - * Form elements instance. |
|
33 | - * |
|
34 | - * @var WPInv_Payment_Form_Elements |
|
35 | - */ |
|
36 | - public $form_elements; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var array An array of payment gateways. |
|
40 | - */ |
|
41 | - public $gateways; |
|
42 | - |
|
43 | - /** |
|
44 | - * Class constructor. |
|
45 | - */ |
|
46 | - public function __construct() { |
|
47 | - $this->define_constants(); |
|
48 | - $this->includes(); |
|
49 | - $this->init_hooks(); |
|
50 | - $this->set_properties(); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Sets a custom data property. |
|
55 | - * |
|
56 | - * @param string $prop The prop to set. |
|
57 | - * @param mixed $value The value to retrieve. |
|
58 | - */ |
|
59 | - public function set( $prop, $value ) { |
|
60 | - $this->data[ $prop ] = $value; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Gets a custom data property. |
|
65 | - * |
|
66 | - * @param string $prop The prop to set. |
|
67 | - * @return mixed The value. |
|
68 | - */ |
|
69 | - public function get( $prop ) { |
|
70 | - if ( isset( $this->data[ $prop ] ) ) { |
|
71 | - return $this->data[ $prop ]; |
|
72 | - } |
|
73 | - |
|
74 | - return null; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Define class properties. |
|
79 | - */ |
|
80 | - public function set_properties() { |
|
81 | - // Sessions. |
|
82 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
83 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
84 | - $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
85 | - |
|
86 | - // Init other objects. |
|
87 | - $this->set( 'notes', new WPInv_Notes() ); |
|
88 | - $this->set( 'api', new WPInv_API() ); |
|
89 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
90 | - $this->set( 'template', new GetPaid_Template() ); |
|
91 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
92 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
93 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
94 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
95 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
96 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
97 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
98 | - $this->set( 'data_retention', new WPInv_Data_Retention() ); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Define plugin constants. |
|
103 | - */ |
|
104 | - public function define_constants() { |
|
105 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
106 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
107 | - $this->version = WPINV_VERSION; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Hook into actions and filters. |
|
112 | - * |
|
113 | - * @since 1.0.19 |
|
114 | - */ |
|
115 | - protected function init_hooks() { |
|
116 | - /* Internationalize the text strings used. */ |
|
117 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
118 | - |
|
119 | - // Init the plugin after WordPress inits. |
|
120 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
121 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 100 ); |
|
122 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
123 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
124 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
125 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
126 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
127 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
128 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
129 | - add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
130 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
131 | - |
|
132 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
133 | - add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
|
134 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
135 | - |
|
136 | - // Fires after registering actions. |
|
137 | - do_action( 'wpinv_actions', $this ); |
|
138 | - do_action( 'getpaid_actions', $this ); |
|
139 | - } |
|
140 | - |
|
141 | - public function plugins_loaded() { |
|
142 | - /* Internationalize the text strings used. */ |
|
143 | - $this->load_textdomain(); |
|
144 | - |
|
145 | - do_action( 'wpinv_loaded' ); |
|
146 | - |
|
147 | - // Fix oxygen page builder conflict |
|
148 | - if ( function_exists( 'ct_css_output' ) ) { |
|
149 | - wpinv_oxygen_fix_conflict(); |
|
150 | - } |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Load Localisation files. |
|
155 | - * |
|
156 | - * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
157 | - * |
|
158 | - * Locales found in: |
|
159 | - * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
160 | - * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
161 | - * |
|
162 | - * @since 1.0.0 |
|
163 | - */ |
|
164 | - public function load_textdomain() { |
|
165 | - // Determines the current locale. |
|
166 | - if ( function_exists( 'determine_locale' ) ) { |
|
167 | - $locale = determine_locale(); |
|
168 | - } else if ( function_exists( 'get_user_locale' ) ) { |
|
169 | - $locale = get_user_locale(); |
|
170 | - } else { |
|
171 | - $locale = get_locale(); |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Filter the locale to use for translations. |
|
176 | - */ |
|
177 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
178 | - |
|
179 | - unload_textdomain( 'invoicing', true ); |
|
180 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
181 | - load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' ); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Include required core files used in admin and on the frontend. |
|
186 | - */ |
|
187 | - public function includes() { |
|
188 | - // Start with the settings. |
|
189 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
190 | - |
|
191 | - // Packages/libraries. |
|
192 | - require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
193 | - require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
194 | - |
|
195 | - // Load functions. |
|
196 | - require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
197 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
198 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
199 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
200 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
201 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
202 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
203 | - require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
204 | - require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
205 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
206 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
207 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
208 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
209 | - require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
210 | - require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
211 | - |
|
212 | - // Register autoloader. |
|
213 | - try { |
|
214 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
215 | - } catch ( Exception $e ) { |
|
216 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
217 | - } |
|
218 | - |
|
219 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
220 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
221 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
222 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
223 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
224 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
225 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
226 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
227 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
228 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
229 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
230 | - require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
231 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
232 | - require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
233 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
234 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
235 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
236 | - require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
237 | - require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
238 | - require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
239 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
240 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
241 | - |
|
242 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
243 | - GetPaid_Post_Types_Admin::init(); |
|
244 | - |
|
245 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
246 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
247 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
248 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
249 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
250 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
251 | - // load the user class only on the users.php page |
|
252 | - global $pagenow; |
|
253 | - if ( $pagenow == 'users.php' ) { |
|
254 | - new WPInv_Admin_Users(); |
|
255 | - } |
|
256 | - } |
|
257 | - |
|
258 | - // Register cli commands |
|
259 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
260 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
261 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
262 | - } |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * Class autoloader |
|
267 | - * |
|
268 | - * @param string $class_name The name of the class to load. |
|
269 | - * @access public |
|
270 | - * @since 1.0.19 |
|
271 | - * @return void |
|
272 | - */ |
|
273 | - public function autoload( $class_name ) { |
|
274 | - // Normalize the class name... |
|
275 | - $class_name = strtolower( $class_name ); |
|
276 | - |
|
277 | - // ... and make sure it is our class. |
|
278 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
279 | - return; |
|
280 | - } |
|
281 | - |
|
282 | - // Next, prepare the file name from the class. |
|
283 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
284 | - |
|
285 | - // Base path of the classes. |
|
286 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
287 | - |
|
288 | - // And an array of possible locations in order of importance. |
|
289 | - $locations = array( |
|
290 | - "$plugin_path/includes", |
|
291 | - "$plugin_path/includes/data-stores", |
|
292 | - "$plugin_path/includes/gateways", |
|
293 | - "$plugin_path/includes/payments", |
|
294 | - "$plugin_path/includes/geolocation", |
|
295 | - "$plugin_path/includes/reports", |
|
296 | - "$plugin_path/includes/api", |
|
297 | - "$plugin_path/includes/admin", |
|
298 | - "$plugin_path/includes/admin/meta-boxes", |
|
299 | - ); |
|
300 | - |
|
301 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
302 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
303 | - include trailingslashit( $location ) . $file_name; |
|
304 | - break; |
|
305 | - } |
|
306 | - } |
|
307 | - } |
|
308 | - |
|
309 | - /** |
|
310 | - * Inits hooks etc. |
|
311 | - */ |
|
312 | - public function init() { |
|
313 | - // Fires before getpaid inits. |
|
314 | - do_action( 'before_getpaid_init', $this ); |
|
315 | - |
|
316 | - // Maybe upgrade. |
|
317 | - $this->maybe_upgrade_database(); |
|
318 | - |
|
319 | - // Load default gateways. |
|
320 | - $gateways = apply_filters( |
|
321 | - 'getpaid_default_gateways', |
|
322 | - array( |
|
323 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
324 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
325 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
326 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
327 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
328 | - ) |
|
329 | - ); |
|
330 | - |
|
331 | - foreach ( $gateways as $id => $class ) { |
|
332 | - $this->gateways[ $id ] = new $class(); |
|
333 | - } |
|
334 | - |
|
335 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
336 | - GetPaid_Installer::rename_gateways_label(); |
|
337 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
338 | - } |
|
339 | - |
|
340 | - // Fires after getpaid inits. |
|
341 | - do_action( 'getpaid_init', $this ); |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Checks if this is an IPN request and processes it. |
|
346 | - */ |
|
347 | - public function maybe_process_ipn() { |
|
348 | - // Ensure that this is an IPN request. |
|
349 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
350 | - return; |
|
351 | - } |
|
352 | - |
|
353 | - $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
354 | - |
|
355 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
356 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
357 | - exit; |
|
358 | - } |
|
359 | - |
|
360 | - public function enqueue_scripts() { |
|
361 | - // Fires before adding scripts. |
|
362 | - do_action( 'getpaid_enqueue_scripts' ); |
|
363 | - |
|
364 | - $localize = array(); |
|
365 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
366 | - $localize['thousands'] = wpinv_thousands_separator(); |
|
367 | - $localize['decimals'] = wpinv_decimal_separator(); |
|
368 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
369 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
370 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
371 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
372 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
373 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
374 | - $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
|
375 | - |
|
376 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
377 | - |
|
378 | - // reCaptcha. |
|
379 | - if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) { |
|
380 | - wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
381 | - } |
|
382 | - |
|
383 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.min.js', array( 'jquery' ), WPINV_VERSION, true ); |
|
384 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
385 | - } |
|
386 | - |
|
387 | - public function wpinv_actions() { |
|
388 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
389 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
390 | - } |
|
391 | - |
|
392 | - if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
393 | - include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
394 | - } |
|
395 | - } |
|
396 | - |
|
397 | - /** |
|
398 | - * Fires an action after verifying that a user can fire them. |
|
399 | - * |
|
400 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
401 | - * current user owns the invoice/subscription. |
|
402 | - */ |
|
403 | - public function maybe_do_authenticated_action() { |
|
404 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
405 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
406 | - $data = wp_unslash( $_REQUEST ); |
|
407 | - |
|
408 | - if ( is_user_logged_in() ) { |
|
409 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
410 | - } |
|
411 | - |
|
412 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
413 | - } |
|
414 | - } |
|
415 | - |
|
416 | - public function pre_get_posts( $wp_query ) { |
|
417 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
418 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
419 | - } |
|
420 | - |
|
421 | - return $wp_query; |
|
422 | - } |
|
423 | - |
|
424 | - /** |
|
425 | - * Register widgets |
|
426 | - * |
|
427 | - */ |
|
428 | - public function register_widgets() { |
|
429 | - global $pagenow; |
|
430 | - |
|
431 | - // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
432 | - // So we disable our widgets when editing a page with UX Builder. |
|
433 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
434 | - return; |
|
435 | - } |
|
436 | - |
|
437 | - $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
438 | - |
|
439 | - if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
440 | - // don't initiate in these conditions. |
|
441 | - } else { |
|
442 | - // Only load allowed widgets. |
|
443 | - $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
444 | - $widgets = apply_filters( |
|
445 | - 'getpaid_widget_classes', |
|
446 | - array( |
|
447 | - 'WPInv_Checkout_Widget', |
|
448 | - 'WPInv_History_Widget', |
|
449 | - 'WPInv_Receipt_Widget', |
|
450 | - 'WPInv_Subscriptions_Widget', |
|
451 | - 'WPInv_Buy_Item_Widget', |
|
452 | - 'WPInv_Messages_Widget', |
|
453 | - 'WPInv_GetPaid_Widget', |
|
454 | - 'WPInv_Invoice_Widget', |
|
455 | - ) |
|
456 | - ); |
|
457 | - |
|
458 | - // For each widget... |
|
459 | - foreach ( $widgets as $widget ) { |
|
460 | - // Abort early if it is excluded for this page. |
|
461 | - if ( in_array( $widget, $exclude ) ) { |
|
462 | - continue; |
|
463 | - } |
|
464 | - |
|
465 | - // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
466 | - if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
467 | - register_widget( $widget ); |
|
468 | - } else { |
|
469 | - new $widget(); |
|
470 | - } |
|
471 | - } |
|
472 | - } |
|
473 | - } |
|
474 | - |
|
475 | - /** |
|
476 | - * Upgrades the database. |
|
477 | - * |
|
478 | - * @since 2.0.2 |
|
479 | - */ |
|
480 | - public function maybe_upgrade_database() { |
|
481 | - // Ensure the database tables are up to date. |
|
482 | - GetPaid_Installer::maybe_create_db_tables(); |
|
483 | - |
|
484 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
485 | - |
|
486 | - if ( $wpi_version == WPINV_VERSION ) { |
|
487 | - return; |
|
488 | - } |
|
489 | - |
|
490 | - $installer = new GetPaid_Installer(); |
|
491 | - |
|
492 | - if ( empty( $wpi_version ) ) { |
|
493 | - return $installer->upgrade_db( 0 ); |
|
494 | - } |
|
495 | - |
|
496 | - $upgrades = array( |
|
497 | - '0.0.5' => '004', |
|
498 | - '1.0.3' => '102', |
|
499 | - '2.0.0' => '118', |
|
500 | - '2.8.0' => '279', |
|
501 | - ); |
|
502 | - |
|
503 | - foreach ( $upgrades as $key => $method ) { |
|
504 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
505 | - return $installer->upgrade_db( $method ); |
|
506 | - } |
|
507 | - } |
|
508 | - } |
|
509 | - |
|
510 | - /** |
|
511 | - * Flushes the permalinks if needed. |
|
512 | - * |
|
513 | - * @since 2.0.8 |
|
514 | - */ |
|
515 | - public function maybe_flush_permalinks() { |
|
516 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
517 | - |
|
518 | - if ( ! empty( $flush ) ) { |
|
519 | - flush_rewrite_rules(); |
|
520 | - delete_option( 'wpinv_flush_permalinks' ); |
|
521 | - } |
|
522 | - } |
|
523 | - |
|
524 | - /** |
|
525 | - * Remove our pages from yoast sitemaps. |
|
526 | - * |
|
527 | - * @since 1.0.19 |
|
528 | - * @param int[] $excluded_posts_ids |
|
529 | - */ |
|
530 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
531 | - // Ensure that we have an array. |
|
532 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
533 | - $excluded_posts_ids = array(); |
|
534 | - } |
|
535 | - |
|
536 | - // Prepare our pages. |
|
537 | - $our_pages = array(); |
|
538 | - |
|
539 | - // Checkout page. |
|
540 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
541 | - |
|
542 | - // Success page. |
|
543 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
544 | - |
|
545 | - // Failure page. |
|
546 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
547 | - |
|
548 | - // History page. |
|
549 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
550 | - |
|
551 | - // Subscriptions page. |
|
552 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
553 | - |
|
554 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
555 | - |
|
556 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
557 | - |
|
558 | - return array_unique( $excluded_posts_ids ); |
|
559 | - } |
|
560 | - |
|
561 | - /** |
|
562 | - * Remove our pages from yoast sitemaps. |
|
563 | - * |
|
564 | - * @since 1.0.19 |
|
565 | - * @param string[] $post_types |
|
566 | - */ |
|
567 | - public function exclude_invoicing_post_types( $post_types ) { |
|
568 | - // Ensure that we have an array. |
|
569 | - if ( ! is_array( $post_types ) ) { |
|
570 | - $post_types = array(); |
|
571 | - } |
|
572 | - |
|
573 | - // Remove our post types. |
|
574 | - return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
575 | - } |
|
576 | - |
|
577 | - /** |
|
578 | - * Displays additional footer code. |
|
579 | - * |
|
580 | - * @since 2.0.0 |
|
581 | - */ |
|
582 | - public function wp_footer() { |
|
583 | - wpinv_get_template( 'frontend-footer.php' ); |
|
584 | - } |
|
585 | - |
|
586 | - /** |
|
587 | - * Displays additional header code. |
|
588 | - * |
|
589 | - * @since 2.0.0 |
|
590 | - */ |
|
591 | - public function wp_head() { |
|
592 | - wpinv_get_template( 'frontend-head.php' ); |
|
593 | - } |
|
594 | - |
|
595 | - /** |
|
596 | - * Custom query vars. |
|
597 | - * |
|
598 | - */ |
|
599 | - public function custom_query_vars( $vars ) { |
|
600 | - $vars[] = 'getpaid-ipn'; |
|
601 | - return $vars; |
|
602 | - } |
|
603 | - |
|
604 | - /** |
|
605 | - * Add rewrite tags and rules. |
|
606 | - * |
|
607 | - */ |
|
608 | - public function add_rewrite_rule() { |
|
609 | - $tag = 'getpaid-ipn'; |
|
610 | - add_rewrite_tag( "%$tag%", '([^&]+)' ); |
|
611 | - add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
|
612 | - } |
|
613 | - |
|
614 | - /** |
|
615 | - * Processes non-query string ipns. |
|
616 | - * |
|
617 | - */ |
|
618 | - public function maybe_process_new_ipn( $query ) { |
|
619 | - if ( is_admin() || ! $query->is_main_query() ) { |
|
620 | - return; |
|
621 | - } |
|
622 | - |
|
623 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
624 | - |
|
625 | - if ( ! empty( $gateway ) ) { |
|
626 | - $gateway = sanitize_text_field( $gateway ); |
|
627 | - nocache_headers(); |
|
628 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
629 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
630 | - exit; |
|
631 | - } |
|
632 | - } |
|
17 | + /** |
|
18 | + * GetPaid version. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + public $version; |
|
23 | + |
|
24 | + /** |
|
25 | + * Data container. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $data = array(); |
|
30 | + |
|
31 | + /** |
|
32 | + * Form elements instance. |
|
33 | + * |
|
34 | + * @var WPInv_Payment_Form_Elements |
|
35 | + */ |
|
36 | + public $form_elements; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var array An array of payment gateways. |
|
40 | + */ |
|
41 | + public $gateways; |
|
42 | + |
|
43 | + /** |
|
44 | + * Class constructor. |
|
45 | + */ |
|
46 | + public function __construct() { |
|
47 | + $this->define_constants(); |
|
48 | + $this->includes(); |
|
49 | + $this->init_hooks(); |
|
50 | + $this->set_properties(); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Sets a custom data property. |
|
55 | + * |
|
56 | + * @param string $prop The prop to set. |
|
57 | + * @param mixed $value The value to retrieve. |
|
58 | + */ |
|
59 | + public function set( $prop, $value ) { |
|
60 | + $this->data[ $prop ] = $value; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Gets a custom data property. |
|
65 | + * |
|
66 | + * @param string $prop The prop to set. |
|
67 | + * @return mixed The value. |
|
68 | + */ |
|
69 | + public function get( $prop ) { |
|
70 | + if ( isset( $this->data[ $prop ] ) ) { |
|
71 | + return $this->data[ $prop ]; |
|
72 | + } |
|
73 | + |
|
74 | + return null; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Define class properties. |
|
79 | + */ |
|
80 | + public function set_properties() { |
|
81 | + // Sessions. |
|
82 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
83 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
84 | + $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
85 | + |
|
86 | + // Init other objects. |
|
87 | + $this->set( 'notes', new WPInv_Notes() ); |
|
88 | + $this->set( 'api', new WPInv_API() ); |
|
89 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
90 | + $this->set( 'template', new GetPaid_Template() ); |
|
91 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
92 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
93 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
94 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
95 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
96 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
97 | + $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
98 | + $this->set( 'data_retention', new WPInv_Data_Retention() ); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Define plugin constants. |
|
103 | + */ |
|
104 | + public function define_constants() { |
|
105 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
106 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
107 | + $this->version = WPINV_VERSION; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Hook into actions and filters. |
|
112 | + * |
|
113 | + * @since 1.0.19 |
|
114 | + */ |
|
115 | + protected function init_hooks() { |
|
116 | + /* Internationalize the text strings used. */ |
|
117 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
118 | + |
|
119 | + // Init the plugin after WordPress inits. |
|
120 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
121 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 100 ); |
|
122 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
123 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
124 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
125 | + add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
126 | + add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
127 | + add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
128 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
129 | + add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
130 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
131 | + |
|
132 | + add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
133 | + add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
|
134 | + add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
135 | + |
|
136 | + // Fires after registering actions. |
|
137 | + do_action( 'wpinv_actions', $this ); |
|
138 | + do_action( 'getpaid_actions', $this ); |
|
139 | + } |
|
140 | + |
|
141 | + public function plugins_loaded() { |
|
142 | + /* Internationalize the text strings used. */ |
|
143 | + $this->load_textdomain(); |
|
144 | + |
|
145 | + do_action( 'wpinv_loaded' ); |
|
146 | + |
|
147 | + // Fix oxygen page builder conflict |
|
148 | + if ( function_exists( 'ct_css_output' ) ) { |
|
149 | + wpinv_oxygen_fix_conflict(); |
|
150 | + } |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Load Localisation files. |
|
155 | + * |
|
156 | + * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
157 | + * |
|
158 | + * Locales found in: |
|
159 | + * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
160 | + * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
161 | + * |
|
162 | + * @since 1.0.0 |
|
163 | + */ |
|
164 | + public function load_textdomain() { |
|
165 | + // Determines the current locale. |
|
166 | + if ( function_exists( 'determine_locale' ) ) { |
|
167 | + $locale = determine_locale(); |
|
168 | + } else if ( function_exists( 'get_user_locale' ) ) { |
|
169 | + $locale = get_user_locale(); |
|
170 | + } else { |
|
171 | + $locale = get_locale(); |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Filter the locale to use for translations. |
|
176 | + */ |
|
177 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
178 | + |
|
179 | + unload_textdomain( 'invoicing', true ); |
|
180 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
181 | + load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' ); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Include required core files used in admin and on the frontend. |
|
186 | + */ |
|
187 | + public function includes() { |
|
188 | + // Start with the settings. |
|
189 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
190 | + |
|
191 | + // Packages/libraries. |
|
192 | + require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
193 | + require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
194 | + |
|
195 | + // Load functions. |
|
196 | + require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
197 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
198 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
199 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
200 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
201 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
202 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
203 | + require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
204 | + require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
205 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
206 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
207 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
208 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
209 | + require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
210 | + require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
211 | + |
|
212 | + // Register autoloader. |
|
213 | + try { |
|
214 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
215 | + } catch ( Exception $e ) { |
|
216 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
217 | + } |
|
218 | + |
|
219 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
220 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
221 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
222 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
223 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
224 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
225 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
226 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
227 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
228 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
229 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
230 | + require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
231 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
232 | + require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
233 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
234 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
235 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
236 | + require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
237 | + require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
238 | + require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
239 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
240 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
241 | + |
|
242 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
243 | + GetPaid_Post_Types_Admin::init(); |
|
244 | + |
|
245 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
246 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
247 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
248 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
249 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
250 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
251 | + // load the user class only on the users.php page |
|
252 | + global $pagenow; |
|
253 | + if ( $pagenow == 'users.php' ) { |
|
254 | + new WPInv_Admin_Users(); |
|
255 | + } |
|
256 | + } |
|
257 | + |
|
258 | + // Register cli commands |
|
259 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
260 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
261 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
262 | + } |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * Class autoloader |
|
267 | + * |
|
268 | + * @param string $class_name The name of the class to load. |
|
269 | + * @access public |
|
270 | + * @since 1.0.19 |
|
271 | + * @return void |
|
272 | + */ |
|
273 | + public function autoload( $class_name ) { |
|
274 | + // Normalize the class name... |
|
275 | + $class_name = strtolower( $class_name ); |
|
276 | + |
|
277 | + // ... and make sure it is our class. |
|
278 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
279 | + return; |
|
280 | + } |
|
281 | + |
|
282 | + // Next, prepare the file name from the class. |
|
283 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
284 | + |
|
285 | + // Base path of the classes. |
|
286 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
287 | + |
|
288 | + // And an array of possible locations in order of importance. |
|
289 | + $locations = array( |
|
290 | + "$plugin_path/includes", |
|
291 | + "$plugin_path/includes/data-stores", |
|
292 | + "$plugin_path/includes/gateways", |
|
293 | + "$plugin_path/includes/payments", |
|
294 | + "$plugin_path/includes/geolocation", |
|
295 | + "$plugin_path/includes/reports", |
|
296 | + "$plugin_path/includes/api", |
|
297 | + "$plugin_path/includes/admin", |
|
298 | + "$plugin_path/includes/admin/meta-boxes", |
|
299 | + ); |
|
300 | + |
|
301 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
302 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
303 | + include trailingslashit( $location ) . $file_name; |
|
304 | + break; |
|
305 | + } |
|
306 | + } |
|
307 | + } |
|
308 | + |
|
309 | + /** |
|
310 | + * Inits hooks etc. |
|
311 | + */ |
|
312 | + public function init() { |
|
313 | + // Fires before getpaid inits. |
|
314 | + do_action( 'before_getpaid_init', $this ); |
|
315 | + |
|
316 | + // Maybe upgrade. |
|
317 | + $this->maybe_upgrade_database(); |
|
318 | + |
|
319 | + // Load default gateways. |
|
320 | + $gateways = apply_filters( |
|
321 | + 'getpaid_default_gateways', |
|
322 | + array( |
|
323 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
324 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
325 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
326 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
327 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
328 | + ) |
|
329 | + ); |
|
330 | + |
|
331 | + foreach ( $gateways as $id => $class ) { |
|
332 | + $this->gateways[ $id ] = new $class(); |
|
333 | + } |
|
334 | + |
|
335 | + if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
336 | + GetPaid_Installer::rename_gateways_label(); |
|
337 | + update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
338 | + } |
|
339 | + |
|
340 | + // Fires after getpaid inits. |
|
341 | + do_action( 'getpaid_init', $this ); |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Checks if this is an IPN request and processes it. |
|
346 | + */ |
|
347 | + public function maybe_process_ipn() { |
|
348 | + // Ensure that this is an IPN request. |
|
349 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
350 | + return; |
|
351 | + } |
|
352 | + |
|
353 | + $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
354 | + |
|
355 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
356 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
357 | + exit; |
|
358 | + } |
|
359 | + |
|
360 | + public function enqueue_scripts() { |
|
361 | + // Fires before adding scripts. |
|
362 | + do_action( 'getpaid_enqueue_scripts' ); |
|
363 | + |
|
364 | + $localize = array(); |
|
365 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
366 | + $localize['thousands'] = wpinv_thousands_separator(); |
|
367 | + $localize['decimals'] = wpinv_decimal_separator(); |
|
368 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
369 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
370 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
371 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
372 | + $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
373 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
374 | + $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
|
375 | + |
|
376 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
377 | + |
|
378 | + // reCaptcha. |
|
379 | + if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) { |
|
380 | + wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
381 | + } |
|
382 | + |
|
383 | + wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.min.js', array( 'jquery' ), WPINV_VERSION, true ); |
|
384 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
385 | + } |
|
386 | + |
|
387 | + public function wpinv_actions() { |
|
388 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
389 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
390 | + } |
|
391 | + |
|
392 | + if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
393 | + include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
394 | + } |
|
395 | + } |
|
396 | + |
|
397 | + /** |
|
398 | + * Fires an action after verifying that a user can fire them. |
|
399 | + * |
|
400 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
401 | + * current user owns the invoice/subscription. |
|
402 | + */ |
|
403 | + public function maybe_do_authenticated_action() { |
|
404 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
405 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
406 | + $data = wp_unslash( $_REQUEST ); |
|
407 | + |
|
408 | + if ( is_user_logged_in() ) { |
|
409 | + do_action( "getpaid_authenticated_action_$key", $data ); |
|
410 | + } |
|
411 | + |
|
412 | + do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
413 | + } |
|
414 | + } |
|
415 | + |
|
416 | + public function pre_get_posts( $wp_query ) { |
|
417 | + if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
418 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
419 | + } |
|
420 | + |
|
421 | + return $wp_query; |
|
422 | + } |
|
423 | + |
|
424 | + /** |
|
425 | + * Register widgets |
|
426 | + * |
|
427 | + */ |
|
428 | + public function register_widgets() { |
|
429 | + global $pagenow; |
|
430 | + |
|
431 | + // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
432 | + // So we disable our widgets when editing a page with UX Builder. |
|
433 | + if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
434 | + return; |
|
435 | + } |
|
436 | + |
|
437 | + $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
438 | + |
|
439 | + if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
440 | + // don't initiate in these conditions. |
|
441 | + } else { |
|
442 | + // Only load allowed widgets. |
|
443 | + $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
444 | + $widgets = apply_filters( |
|
445 | + 'getpaid_widget_classes', |
|
446 | + array( |
|
447 | + 'WPInv_Checkout_Widget', |
|
448 | + 'WPInv_History_Widget', |
|
449 | + 'WPInv_Receipt_Widget', |
|
450 | + 'WPInv_Subscriptions_Widget', |
|
451 | + 'WPInv_Buy_Item_Widget', |
|
452 | + 'WPInv_Messages_Widget', |
|
453 | + 'WPInv_GetPaid_Widget', |
|
454 | + 'WPInv_Invoice_Widget', |
|
455 | + ) |
|
456 | + ); |
|
457 | + |
|
458 | + // For each widget... |
|
459 | + foreach ( $widgets as $widget ) { |
|
460 | + // Abort early if it is excluded for this page. |
|
461 | + if ( in_array( $widget, $exclude ) ) { |
|
462 | + continue; |
|
463 | + } |
|
464 | + |
|
465 | + // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
466 | + if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
467 | + register_widget( $widget ); |
|
468 | + } else { |
|
469 | + new $widget(); |
|
470 | + } |
|
471 | + } |
|
472 | + } |
|
473 | + } |
|
474 | + |
|
475 | + /** |
|
476 | + * Upgrades the database. |
|
477 | + * |
|
478 | + * @since 2.0.2 |
|
479 | + */ |
|
480 | + public function maybe_upgrade_database() { |
|
481 | + // Ensure the database tables are up to date. |
|
482 | + GetPaid_Installer::maybe_create_db_tables(); |
|
483 | + |
|
484 | + $wpi_version = get_option( 'wpinv_version', 0 ); |
|
485 | + |
|
486 | + if ( $wpi_version == WPINV_VERSION ) { |
|
487 | + return; |
|
488 | + } |
|
489 | + |
|
490 | + $installer = new GetPaid_Installer(); |
|
491 | + |
|
492 | + if ( empty( $wpi_version ) ) { |
|
493 | + return $installer->upgrade_db( 0 ); |
|
494 | + } |
|
495 | + |
|
496 | + $upgrades = array( |
|
497 | + '0.0.5' => '004', |
|
498 | + '1.0.3' => '102', |
|
499 | + '2.0.0' => '118', |
|
500 | + '2.8.0' => '279', |
|
501 | + ); |
|
502 | + |
|
503 | + foreach ( $upgrades as $key => $method ) { |
|
504 | + if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
505 | + return $installer->upgrade_db( $method ); |
|
506 | + } |
|
507 | + } |
|
508 | + } |
|
509 | + |
|
510 | + /** |
|
511 | + * Flushes the permalinks if needed. |
|
512 | + * |
|
513 | + * @since 2.0.8 |
|
514 | + */ |
|
515 | + public function maybe_flush_permalinks() { |
|
516 | + $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
517 | + |
|
518 | + if ( ! empty( $flush ) ) { |
|
519 | + flush_rewrite_rules(); |
|
520 | + delete_option( 'wpinv_flush_permalinks' ); |
|
521 | + } |
|
522 | + } |
|
523 | + |
|
524 | + /** |
|
525 | + * Remove our pages from yoast sitemaps. |
|
526 | + * |
|
527 | + * @since 1.0.19 |
|
528 | + * @param int[] $excluded_posts_ids |
|
529 | + */ |
|
530 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
531 | + // Ensure that we have an array. |
|
532 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
533 | + $excluded_posts_ids = array(); |
|
534 | + } |
|
535 | + |
|
536 | + // Prepare our pages. |
|
537 | + $our_pages = array(); |
|
538 | + |
|
539 | + // Checkout page. |
|
540 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
541 | + |
|
542 | + // Success page. |
|
543 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
544 | + |
|
545 | + // Failure page. |
|
546 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
547 | + |
|
548 | + // History page. |
|
549 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
550 | + |
|
551 | + // Subscriptions page. |
|
552 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
553 | + |
|
554 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
555 | + |
|
556 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
557 | + |
|
558 | + return array_unique( $excluded_posts_ids ); |
|
559 | + } |
|
560 | + |
|
561 | + /** |
|
562 | + * Remove our pages from yoast sitemaps. |
|
563 | + * |
|
564 | + * @since 1.0.19 |
|
565 | + * @param string[] $post_types |
|
566 | + */ |
|
567 | + public function exclude_invoicing_post_types( $post_types ) { |
|
568 | + // Ensure that we have an array. |
|
569 | + if ( ! is_array( $post_types ) ) { |
|
570 | + $post_types = array(); |
|
571 | + } |
|
572 | + |
|
573 | + // Remove our post types. |
|
574 | + return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
575 | + } |
|
576 | + |
|
577 | + /** |
|
578 | + * Displays additional footer code. |
|
579 | + * |
|
580 | + * @since 2.0.0 |
|
581 | + */ |
|
582 | + public function wp_footer() { |
|
583 | + wpinv_get_template( 'frontend-footer.php' ); |
|
584 | + } |
|
585 | + |
|
586 | + /** |
|
587 | + * Displays additional header code. |
|
588 | + * |
|
589 | + * @since 2.0.0 |
|
590 | + */ |
|
591 | + public function wp_head() { |
|
592 | + wpinv_get_template( 'frontend-head.php' ); |
|
593 | + } |
|
594 | + |
|
595 | + /** |
|
596 | + * Custom query vars. |
|
597 | + * |
|
598 | + */ |
|
599 | + public function custom_query_vars( $vars ) { |
|
600 | + $vars[] = 'getpaid-ipn'; |
|
601 | + return $vars; |
|
602 | + } |
|
603 | + |
|
604 | + /** |
|
605 | + * Add rewrite tags and rules. |
|
606 | + * |
|
607 | + */ |
|
608 | + public function add_rewrite_rule() { |
|
609 | + $tag = 'getpaid-ipn'; |
|
610 | + add_rewrite_tag( "%$tag%", '([^&]+)' ); |
|
611 | + add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
|
612 | + } |
|
613 | + |
|
614 | + /** |
|
615 | + * Processes non-query string ipns. |
|
616 | + * |
|
617 | + */ |
|
618 | + public function maybe_process_new_ipn( $query ) { |
|
619 | + if ( is_admin() || ! $query->is_main_query() ) { |
|
620 | + return; |
|
621 | + } |
|
622 | + |
|
623 | + $gateway = get_query_var( 'getpaid-ipn' ); |
|
624 | + |
|
625 | + if ( ! empty( $gateway ) ) { |
|
626 | + $gateway = sanitize_text_field( $gateway ); |
|
627 | + nocache_headers(); |
|
628 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
629 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
630 | + exit; |
|
631 | + } |
|
632 | + } |
|
633 | 633 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 1.0.0 |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Main Invoicing class. |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | * @param string $prop The prop to set. |
57 | 57 | * @param mixed $value The value to retrieve. |
58 | 58 | */ |
59 | - public function set( $prop, $value ) { |
|
60 | - $this->data[ $prop ] = $value; |
|
59 | + public function set($prop, $value) { |
|
60 | + $this->data[$prop] = $value; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | * @param string $prop The prop to set. |
67 | 67 | * @return mixed The value. |
68 | 68 | */ |
69 | - public function get( $prop ) { |
|
70 | - if ( isset( $this->data[ $prop ] ) ) { |
|
71 | - return $this->data[ $prop ]; |
|
69 | + public function get($prop) { |
|
70 | + if (isset($this->data[$prop])) { |
|
71 | + return $this->data[$prop]; |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | return null; |
@@ -79,31 +79,31 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public function set_properties() { |
81 | 81 | // Sessions. |
82 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
83 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
82 | + $this->set('session', new WPInv_Session_Handler()); |
|
83 | + $GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility. |
|
84 | 84 | $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
85 | 85 | |
86 | 86 | // Init other objects. |
87 | - $this->set( 'notes', new WPInv_Notes() ); |
|
88 | - $this->set( 'api', new WPInv_API() ); |
|
89 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
90 | - $this->set( 'template', new GetPaid_Template() ); |
|
91 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
92 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
93 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
94 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
95 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
96 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
97 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
98 | - $this->set( 'data_retention', new WPInv_Data_Retention() ); |
|
87 | + $this->set('notes', new WPInv_Notes()); |
|
88 | + $this->set('api', new WPInv_API()); |
|
89 | + $this->set('post_types', new GetPaid_Post_Types()); |
|
90 | + $this->set('template', new GetPaid_Template()); |
|
91 | + $this->set('admin', new GetPaid_Admin()); |
|
92 | + $this->set('subscriptions', new WPInv_Subscriptions()); |
|
93 | + $this->set('invoice_emails', new GetPaid_Invoice_Notification_Emails()); |
|
94 | + $this->set('subscription_emails', new GetPaid_Subscription_Notification_Emails()); |
|
95 | + $this->set('daily_maintenace', new GetPaid_Daily_Maintenance()); |
|
96 | + $this->set('payment_forms', new GetPaid_Payment_Forms()); |
|
97 | + $this->set('maxmind', new GetPaid_MaxMind_Geolocation()); |
|
98 | + $this->set('data_retention', new WPInv_Data_Retention()); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
102 | 102 | * Define plugin constants. |
103 | 103 | */ |
104 | 104 | public function define_constants() { |
105 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
106 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
105 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
106 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
107 | 107 | $this->version = WPINV_VERSION; |
108 | 108 | } |
109 | 109 | |
@@ -114,38 +114,38 @@ discard block |
||
114 | 114 | */ |
115 | 115 | protected function init_hooks() { |
116 | 116 | /* Internationalize the text strings used. */ |
117 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
117 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
118 | 118 | |
119 | 119 | // Init the plugin after WordPress inits. |
120 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
121 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 100 ); |
|
122 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
123 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
124 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
125 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
126 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
127 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
128 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
129 | - add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
130 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
131 | - |
|
132 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
133 | - add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
|
134 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
120 | + add_action('init', array($this, 'init'), 1); |
|
121 | + add_action('init', array($this, 'maybe_process_ipn'), 100); |
|
122 | + add_action('init', array($this, 'wpinv_actions')); |
|
123 | + add_action('init', array($this, 'maybe_do_authenticated_action'), 100); |
|
124 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 11); |
|
125 | + add_action('wp_footer', array($this, 'wp_footer')); |
|
126 | + add_action('wp_head', array($this, 'wp_head')); |
|
127 | + add_action('widgets_init', array($this, 'register_widgets')); |
|
128 | + add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids')); |
|
129 | + add_filter('the_seo_framework_sitemap_supported_post_types', array($this, 'exclude_invoicing_post_types')); |
|
130 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
131 | + |
|
132 | + add_filter('query_vars', array($this, 'custom_query_vars')); |
|
133 | + add_action('init', array($this, 'add_rewrite_rule'), 10, 0); |
|
134 | + add_action('pre_get_posts', array($this, 'maybe_process_new_ipn'), 1); |
|
135 | 135 | |
136 | 136 | // Fires after registering actions. |
137 | - do_action( 'wpinv_actions', $this ); |
|
138 | - do_action( 'getpaid_actions', $this ); |
|
137 | + do_action('wpinv_actions', $this); |
|
138 | + do_action('getpaid_actions', $this); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | public function plugins_loaded() { |
142 | 142 | /* Internationalize the text strings used. */ |
143 | 143 | $this->load_textdomain(); |
144 | 144 | |
145 | - do_action( 'wpinv_loaded' ); |
|
145 | + do_action('wpinv_loaded'); |
|
146 | 146 | |
147 | 147 | // Fix oxygen page builder conflict |
148 | - if ( function_exists( 'ct_css_output' ) ) { |
|
148 | + if (function_exists('ct_css_output')) { |
|
149 | 149 | wpinv_oxygen_fix_conflict(); |
150 | 150 | } |
151 | 151 | } |
@@ -163,9 +163,9 @@ discard block |
||
163 | 163 | */ |
164 | 164 | public function load_textdomain() { |
165 | 165 | // Determines the current locale. |
166 | - if ( function_exists( 'determine_locale' ) ) { |
|
166 | + if (function_exists('determine_locale')) { |
|
167 | 167 | $locale = determine_locale(); |
168 | - } else if ( function_exists( 'get_user_locale' ) ) { |
|
168 | + } else if (function_exists('get_user_locale')) { |
|
169 | 169 | $locale = get_user_locale(); |
170 | 170 | } else { |
171 | 171 | $locale = get_locale(); |
@@ -174,11 +174,11 @@ discard block |
||
174 | 174 | /** |
175 | 175 | * Filter the locale to use for translations. |
176 | 176 | */ |
177 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
177 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
178 | 178 | |
179 | - unload_textdomain( 'invoicing', true ); |
|
180 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
181 | - load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' ); |
|
179 | + unload_textdomain('invoicing', true); |
|
180 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
181 | + load_plugin_textdomain('invoicing', false, plugin_basename(dirname(WPINV_PLUGIN_FILE)) . '/languages/'); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -211,9 +211,9 @@ discard block |
||
211 | 211 | |
212 | 212 | // Register autoloader. |
213 | 213 | try { |
214 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
215 | - } catch ( Exception $e ) { |
|
216 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
214 | + spl_autoload_register(array($this, 'autoload'), true); |
|
215 | + } catch (Exception $e) { |
|
216 | + wpinv_error_log($e->getMessage(), '', __FILE__, 149, true); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
240 | 240 | require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
241 | 241 | |
242 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
242 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
243 | 243 | GetPaid_Post_Types_Admin::init(); |
244 | 244 | |
245 | 245 | require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
@@ -250,15 +250,15 @@ discard block |
||
250 | 250 | require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
251 | 251 | // load the user class only on the users.php page |
252 | 252 | global $pagenow; |
253 | - if ( $pagenow == 'users.php' ) { |
|
253 | + if ($pagenow == 'users.php') { |
|
254 | 254 | new WPInv_Admin_Users(); |
255 | 255 | } |
256 | 256 | } |
257 | 257 | |
258 | 258 | // Register cli commands |
259 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
259 | + if (defined('WP_CLI') && WP_CLI) { |
|
260 | 260 | require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
261 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
261 | + WP_CLI::add_command('invoicing', 'WPInv_CLI'); |
|
262 | 262 | } |
263 | 263 | } |
264 | 264 | |
@@ -270,20 +270,20 @@ discard block |
||
270 | 270 | * @since 1.0.19 |
271 | 271 | * @return void |
272 | 272 | */ |
273 | - public function autoload( $class_name ) { |
|
273 | + public function autoload($class_name) { |
|
274 | 274 | // Normalize the class name... |
275 | - $class_name = strtolower( $class_name ); |
|
275 | + $class_name = strtolower($class_name); |
|
276 | 276 | |
277 | 277 | // ... and make sure it is our class. |
278 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
278 | + if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) { |
|
279 | 279 | return; |
280 | 280 | } |
281 | 281 | |
282 | 282 | // Next, prepare the file name from the class. |
283 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
283 | + $file_name = 'class-' . str_replace('_', '-', $class_name) . '.php'; |
|
284 | 284 | |
285 | 285 | // Base path of the classes. |
286 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
286 | + $plugin_path = untrailingslashit(WPINV_PLUGIN_DIR); |
|
287 | 287 | |
288 | 288 | // And an array of possible locations in order of importance. |
289 | 289 | $locations = array( |
@@ -298,9 +298,9 @@ discard block |
||
298 | 298 | "$plugin_path/includes/admin/meta-boxes", |
299 | 299 | ); |
300 | 300 | |
301 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
302 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
303 | - include trailingslashit( $location ) . $file_name; |
|
301 | + foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) { |
|
302 | + if (file_exists(trailingslashit($location) . $file_name)) { |
|
303 | + include trailingslashit($location) . $file_name; |
|
304 | 304 | break; |
305 | 305 | } |
306 | 306 | } |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | */ |
312 | 312 | public function init() { |
313 | 313 | // Fires before getpaid inits. |
314 | - do_action( 'before_getpaid_init', $this ); |
|
314 | + do_action('before_getpaid_init', $this); |
|
315 | 315 | |
316 | 316 | // Maybe upgrade. |
317 | 317 | $this->maybe_upgrade_database(); |
@@ -328,17 +328,17 @@ discard block |
||
328 | 328 | ) |
329 | 329 | ); |
330 | 330 | |
331 | - foreach ( $gateways as $id => $class ) { |
|
332 | - $this->gateways[ $id ] = new $class(); |
|
331 | + foreach ($gateways as $id => $class) { |
|
332 | + $this->gateways[$id] = new $class(); |
|
333 | 333 | } |
334 | 334 | |
335 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
335 | + if ('yes' != get_option('wpinv_renamed_gateways')) { |
|
336 | 336 | GetPaid_Installer::rename_gateways_label(); |
337 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
337 | + update_option('wpinv_renamed_gateways', 'yes'); |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | // Fires after getpaid inits. |
341 | - do_action( 'getpaid_init', $this ); |
|
341 | + do_action('getpaid_init', $this); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | /** |
@@ -346,51 +346,51 @@ discard block |
||
346 | 346 | */ |
347 | 347 | public function maybe_process_ipn() { |
348 | 348 | // Ensure that this is an IPN request. |
349 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
349 | + if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) { |
|
350 | 350 | return; |
351 | 351 | } |
352 | 352 | |
353 | - $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
353 | + $gateway = sanitize_text_field($_GET['wpi-gateway']); |
|
354 | 354 | |
355 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
356 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
355 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
356 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
357 | 357 | exit; |
358 | 358 | } |
359 | 359 | |
360 | 360 | public function enqueue_scripts() { |
361 | 361 | // Fires before adding scripts. |
362 | - do_action( 'getpaid_enqueue_scripts' ); |
|
362 | + do_action('getpaid_enqueue_scripts'); |
|
363 | 363 | |
364 | 364 | $localize = array(); |
365 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
365 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
366 | 366 | $localize['thousands'] = wpinv_thousands_separator(); |
367 | 367 | $localize['decimals'] = wpinv_decimal_separator(); |
368 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
369 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
368 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
369 | + $localize['txtComplete'] = __('Continue', 'invoicing'); |
|
370 | 370 | $localize['UseTaxes'] = wpinv_use_taxes(); |
371 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
372 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
373 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
371 | + $localize['formNonce'] = wp_create_nonce('getpaid_form_nonce'); |
|
372 | + $localize['loading'] = __('Loading...', 'invoicing'); |
|
373 | + $localize['connectionError'] = __('Could not establish a connection to the server.', 'invoicing'); |
|
374 | 374 | $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
375 | 375 | |
376 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
376 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
377 | 377 | |
378 | 378 | // reCaptcha. |
379 | - if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) { |
|
380 | - wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
379 | + if (getpaid_is_recaptcha_enabled() && ($recaptcha_js = getpaid_recaptcha_api_url())) { |
|
380 | + wp_enqueue_script('recaptcha', $recaptcha_js, array(), null, true); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
381 | 381 | } |
382 | 382 | |
383 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.min.js', array( 'jquery' ), WPINV_VERSION, true ); |
|
384 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
383 | + wp_enqueue_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.min.js', array('jquery'), WPINV_VERSION, true); |
|
384 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | public function wpinv_actions() { |
388 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
389 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
388 | + if (isset($_REQUEST['wpi_action'])) { |
|
389 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
390 | 390 | } |
391 | 391 | |
392 | - if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
393 | - include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
392 | + if (defined('WP_ALL_IMPORT_ROOT_DIR')) { |
|
393 | + include plugin_dir_path(__FILE__) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
394 | 394 | } |
395 | 395 | } |
396 | 396 | |
@@ -401,21 +401,21 @@ discard block |
||
401 | 401 | * current user owns the invoice/subscription. |
402 | 402 | */ |
403 | 403 | public function maybe_do_authenticated_action() { |
404 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
405 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
406 | - $data = wp_unslash( $_REQUEST ); |
|
404 | + if (isset($_REQUEST['getpaid-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
405 | + $key = sanitize_key($_REQUEST['getpaid-action']); |
|
406 | + $data = wp_unslash($_REQUEST); |
|
407 | 407 | |
408 | - if ( is_user_logged_in() ) { |
|
409 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
408 | + if (is_user_logged_in()) { |
|
409 | + do_action("getpaid_authenticated_action_$key", $data); |
|
410 | 410 | } |
411 | 411 | |
412 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
412 | + do_action("getpaid_unauthenticated_action_$key", $data); |
|
413 | 413 | } |
414 | 414 | } |
415 | 415 | |
416 | - public function pre_get_posts( $wp_query ) { |
|
417 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
418 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
416 | + public function pre_get_posts($wp_query) { |
|
417 | + if (!is_admin() && !empty($wp_query->query_vars['post_type']) && getpaid_is_invoice_post_type($wp_query->query_vars['post_type']) && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
418 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses(false, false, $wp_query->query_vars['post_type'])); |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | return $wp_query; |
@@ -430,17 +430,17 @@ discard block |
||
430 | 430 | |
431 | 431 | // Currently, UX Builder does not work particulaly well with SuperDuper. |
432 | 432 | // So we disable our widgets when editing a page with UX Builder. |
433 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
433 | + if (function_exists('ux_builder_is_active') && ux_builder_is_active()) { |
|
434 | 434 | return; |
435 | 435 | } |
436 | 436 | |
437 | - $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
437 | + $block_widget_init_screens = function_exists('sd_pagenow_exclude') ? sd_pagenow_exclude() : array(); |
|
438 | 438 | |
439 | - if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
439 | + if (is_admin() && $pagenow && in_array($pagenow, $block_widget_init_screens)) { |
|
440 | 440 | // don't initiate in these conditions. |
441 | 441 | } else { |
442 | 442 | // Only load allowed widgets. |
443 | - $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
443 | + $exclude = function_exists('sd_widget_exclude') ? sd_widget_exclude() : array(); |
|
444 | 444 | $widgets = apply_filters( |
445 | 445 | 'getpaid_widget_classes', |
446 | 446 | array( |
@@ -456,15 +456,15 @@ discard block |
||
456 | 456 | ); |
457 | 457 | |
458 | 458 | // For each widget... |
459 | - foreach ( $widgets as $widget ) { |
|
459 | + foreach ($widgets as $widget) { |
|
460 | 460 | // Abort early if it is excluded for this page. |
461 | - if ( in_array( $widget, $exclude ) ) { |
|
461 | + if (in_array($widget, $exclude)) { |
|
462 | 462 | continue; |
463 | 463 | } |
464 | 464 | |
465 | 465 | // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
466 | - if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
467 | - register_widget( $widget ); |
|
466 | + if (is_subclass_of($widget, 'WP_Widget')) { |
|
467 | + register_widget($widget); |
|
468 | 468 | } else { |
469 | 469 | new $widget(); |
470 | 470 | } |
@@ -481,28 +481,28 @@ discard block |
||
481 | 481 | // Ensure the database tables are up to date. |
482 | 482 | GetPaid_Installer::maybe_create_db_tables(); |
483 | 483 | |
484 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
484 | + $wpi_version = get_option('wpinv_version', 0); |
|
485 | 485 | |
486 | - if ( $wpi_version == WPINV_VERSION ) { |
|
486 | + if ($wpi_version == WPINV_VERSION) { |
|
487 | 487 | return; |
488 | 488 | } |
489 | 489 | |
490 | 490 | $installer = new GetPaid_Installer(); |
491 | 491 | |
492 | - if ( empty( $wpi_version ) ) { |
|
493 | - return $installer->upgrade_db( 0 ); |
|
492 | + if (empty($wpi_version)) { |
|
493 | + return $installer->upgrade_db(0); |
|
494 | 494 | } |
495 | 495 | |
496 | - $upgrades = array( |
|
496 | + $upgrades = array( |
|
497 | 497 | '0.0.5' => '004', |
498 | 498 | '1.0.3' => '102', |
499 | 499 | '2.0.0' => '118', |
500 | 500 | '2.8.0' => '279', |
501 | 501 | ); |
502 | 502 | |
503 | - foreach ( $upgrades as $key => $method ) { |
|
504 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
505 | - return $installer->upgrade_db( $method ); |
|
503 | + foreach ($upgrades as $key => $method) { |
|
504 | + if (version_compare($wpi_version, $key, '<')) { |
|
505 | + return $installer->upgrade_db($method); |
|
506 | 506 | } |
507 | 507 | } |
508 | 508 | } |
@@ -513,11 +513,11 @@ discard block |
||
513 | 513 | * @since 2.0.8 |
514 | 514 | */ |
515 | 515 | public function maybe_flush_permalinks() { |
516 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
516 | + $flush = get_option('wpinv_flush_permalinks', 0); |
|
517 | 517 | |
518 | - if ( ! empty( $flush ) ) { |
|
518 | + if (!empty($flush)) { |
|
519 | 519 | flush_rewrite_rules(); |
520 | - delete_option( 'wpinv_flush_permalinks' ); |
|
520 | + delete_option('wpinv_flush_permalinks'); |
|
521 | 521 | } |
522 | 522 | } |
523 | 523 | |
@@ -527,9 +527,9 @@ discard block |
||
527 | 527 | * @since 1.0.19 |
528 | 528 | * @param int[] $excluded_posts_ids |
529 | 529 | */ |
530 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
530 | + public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) { |
|
531 | 531 | // Ensure that we have an array. |
532 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
532 | + if (!is_array($excluded_posts_ids)) { |
|
533 | 533 | $excluded_posts_ids = array(); |
534 | 534 | } |
535 | 535 | |
@@ -537,25 +537,25 @@ discard block |
||
537 | 537 | $our_pages = array(); |
538 | 538 | |
539 | 539 | // Checkout page. |
540 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
540 | + $our_pages[] = wpinv_get_option('checkout_page', false); |
|
541 | 541 | |
542 | 542 | // Success page. |
543 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
543 | + $our_pages[] = wpinv_get_option('success_page', false); |
|
544 | 544 | |
545 | 545 | // Failure page. |
546 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
546 | + $our_pages[] = wpinv_get_option('failure_page', false); |
|
547 | 547 | |
548 | 548 | // History page. |
549 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
549 | + $our_pages[] = wpinv_get_option('invoice_history_page', false); |
|
550 | 550 | |
551 | 551 | // Subscriptions page. |
552 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
552 | + $our_pages[] = wpinv_get_option('invoice_subscription_page', false); |
|
553 | 553 | |
554 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
554 | + $our_pages = array_map('intval', array_filter($our_pages)); |
|
555 | 555 | |
556 | 556 | $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
557 | 557 | |
558 | - return array_unique( $excluded_posts_ids ); |
|
558 | + return array_unique($excluded_posts_ids); |
|
559 | 559 | } |
560 | 560 | |
561 | 561 | /** |
@@ -564,14 +564,14 @@ discard block |
||
564 | 564 | * @since 1.0.19 |
565 | 565 | * @param string[] $post_types |
566 | 566 | */ |
567 | - public function exclude_invoicing_post_types( $post_types ) { |
|
567 | + public function exclude_invoicing_post_types($post_types) { |
|
568 | 568 | // Ensure that we have an array. |
569 | - if ( ! is_array( $post_types ) ) { |
|
569 | + if (!is_array($post_types)) { |
|
570 | 570 | $post_types = array(); |
571 | 571 | } |
572 | 572 | |
573 | 573 | // Remove our post types. |
574 | - return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
574 | + return array_diff($post_types, array_keys(getpaid_get_invoice_post_types())); |
|
575 | 575 | } |
576 | 576 | |
577 | 577 | /** |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | * @since 2.0.0 |
581 | 581 | */ |
582 | 582 | public function wp_footer() { |
583 | - wpinv_get_template( 'frontend-footer.php' ); |
|
583 | + wpinv_get_template('frontend-footer.php'); |
|
584 | 584 | } |
585 | 585 | |
586 | 586 | /** |
@@ -589,14 +589,14 @@ discard block |
||
589 | 589 | * @since 2.0.0 |
590 | 590 | */ |
591 | 591 | public function wp_head() { |
592 | - wpinv_get_template( 'frontend-head.php' ); |
|
592 | + wpinv_get_template('frontend-head.php'); |
|
593 | 593 | } |
594 | 594 | |
595 | 595 | /** |
596 | 596 | * Custom query vars. |
597 | 597 | * |
598 | 598 | */ |
599 | - public function custom_query_vars( $vars ) { |
|
599 | + public function custom_query_vars($vars) { |
|
600 | 600 | $vars[] = 'getpaid-ipn'; |
601 | 601 | return $vars; |
602 | 602 | } |
@@ -607,26 +607,26 @@ discard block |
||
607 | 607 | */ |
608 | 608 | public function add_rewrite_rule() { |
609 | 609 | $tag = 'getpaid-ipn'; |
610 | - add_rewrite_tag( "%$tag%", '([^&]+)' ); |
|
611 | - add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
|
610 | + add_rewrite_tag("%$tag%", '([^&]+)'); |
|
611 | + add_rewrite_rule("^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top'); |
|
612 | 612 | } |
613 | 613 | |
614 | 614 | /** |
615 | 615 | * Processes non-query string ipns. |
616 | 616 | * |
617 | 617 | */ |
618 | - public function maybe_process_new_ipn( $query ) { |
|
619 | - if ( is_admin() || ! $query->is_main_query() ) { |
|
618 | + public function maybe_process_new_ipn($query) { |
|
619 | + if (is_admin() || !$query->is_main_query()) { |
|
620 | 620 | return; |
621 | 621 | } |
622 | 622 | |
623 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
623 | + $gateway = get_query_var('getpaid-ipn'); |
|
624 | 624 | |
625 | - if ( ! empty( $gateway ) ) { |
|
626 | - $gateway = sanitize_text_field( $gateway ); |
|
625 | + if (!empty($gateway)) { |
|
626 | + $gateway = sanitize_text_field($gateway); |
|
627 | 627 | nocache_headers(); |
628 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
629 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
628 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
629 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
630 | 630 | exit; |
631 | 631 | } |
632 | 632 | } |
@@ -13,47 +13,47 @@ discard block |
||
13 | 13 | class GetPaid_Bank_Transfer_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'bank_transfer'; |
21 | 21 | |
22 | - /** |
|
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - protected $supports = array( |
|
28 | - 'subscription', |
|
29 | - 'addons', |
|
30 | - 'single_subscription_group', |
|
31 | - 'multiple_subscription_groups', |
|
32 | - 'subscription_date_change', |
|
33 | - 'subscription_bill_times_change', |
|
34 | - ); |
|
22 | + /** |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + protected $supports = array( |
|
28 | + 'subscription', |
|
29 | + 'addons', |
|
30 | + 'single_subscription_group', |
|
31 | + 'multiple_subscription_groups', |
|
32 | + 'subscription_date_change', |
|
33 | + 'subscription_bill_times_change', |
|
34 | + ); |
|
35 | + |
|
36 | + /** |
|
37 | + * Payment method order. |
|
38 | + * |
|
39 | + * @var int |
|
40 | + */ |
|
41 | + public $order = 8; |
|
42 | + |
|
43 | + /** |
|
44 | + * Bank transfer instructions. |
|
45 | + */ |
|
46 | + public $instructions; |
|
35 | 47 | |
36 | 48 | /** |
37 | - * Payment method order. |
|
38 | - * |
|
39 | - * @var int |
|
40 | - */ |
|
41 | - public $order = 8; |
|
42 | - |
|
43 | - /** |
|
44 | - * Bank transfer instructions. |
|
45 | - */ |
|
46 | - public $instructions; |
|
47 | - |
|
48 | - /** |
|
49 | - * Locale array. |
|
50 | - */ |
|
51 | - public $locale; |
|
49 | + * Locale array. |
|
50 | + */ |
|
51 | + public $locale; |
|
52 | 52 | |
53 | 53 | /** |
54 | - * Class constructor. |
|
55 | - */ |
|
56 | - public function __construct() { |
|
54 | + * Class constructor. |
|
55 | + */ |
|
56 | + public function __construct() { |
|
57 | 57 | parent::__construct(); |
58 | 58 | |
59 | 59 | $this->title = __( 'Direct bank transfer', 'invoicing' ); |
@@ -61,43 +61,43 @@ discard block |
||
61 | 61 | $this->checkout_button_text = __( 'Proceed', 'invoicing' ); |
62 | 62 | $this->instructions = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) ); |
63 | 63 | |
64 | - add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
65 | - add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
66 | - add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 ); |
|
67 | - add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
68 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ), 12, 2 ); |
|
69 | - add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 ); |
|
70 | - |
|
71 | - add_filter( 'wpinv_' . $this->id . '_support_subscription', array( $this, 'supports_subscription' ), 20, 1 ); |
|
72 | - add_filter( 'getpaid_' . $this->id . '_support_subscription', array( $this, 'supports_subscription' ), 20, 1 ); |
|
73 | - add_filter( 'getpaid_' . $this->id . '_supports_subscription', array( $this, 'supports_subscription' ), 20, 1 ); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Check gateway supports for subscription. |
|
78 | - * |
|
79 | - * @since 2.8.24 |
|
80 | - * |
|
81 | - * @param bool $supports True if supports else False. |
|
82 | - * @return bool True if supports else False. |
|
83 | - */ |
|
84 | - public function supports_subscription( $supports ) { |
|
85 | - if ( $supports && (int) $this->get_option( 'no_subscription' ) ) { |
|
86 | - $supports = false; |
|
87 | - } |
|
88 | - |
|
89 | - return $supports; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Process Payment. |
|
94 | - * |
|
95 | - * @param WPInv_Invoice $invoice Invoice. |
|
96 | - * @param array $submission_data Posted checkout fields. |
|
97 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
98 | - * @return array |
|
99 | - */ |
|
100 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
64 | + add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
65 | + add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
66 | + add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 ); |
|
67 | + add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
68 | + add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ), 12, 2 ); |
|
69 | + add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 ); |
|
70 | + |
|
71 | + add_filter( 'wpinv_' . $this->id . '_support_subscription', array( $this, 'supports_subscription' ), 20, 1 ); |
|
72 | + add_filter( 'getpaid_' . $this->id . '_support_subscription', array( $this, 'supports_subscription' ), 20, 1 ); |
|
73 | + add_filter( 'getpaid_' . $this->id . '_supports_subscription', array( $this, 'supports_subscription' ), 20, 1 ); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Check gateway supports for subscription. |
|
78 | + * |
|
79 | + * @since 2.8.24 |
|
80 | + * |
|
81 | + * @param bool $supports True if supports else False. |
|
82 | + * @return bool True if supports else False. |
|
83 | + */ |
|
84 | + public function supports_subscription( $supports ) { |
|
85 | + if ( $supports && (int) $this->get_option( 'no_subscription' ) ) { |
|
86 | + $supports = false; |
|
87 | + } |
|
88 | + |
|
89 | + return $supports; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Process Payment. |
|
94 | + * |
|
95 | + * @param WPInv_Invoice $invoice Invoice. |
|
96 | + * @param array $submission_data Posted checkout fields. |
|
97 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
98 | + * @return array |
|
99 | + */ |
|
100 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
101 | 101 | |
102 | 102 | // Add a transaction id. |
103 | 103 | $invoice->set_transaction_id( $invoice->generate_key( 'bt_' ) ); |
@@ -118,66 +118,66 @@ discard block |
||
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
121 | - * Output for the order received page. |
|
122 | - * |
|
123 | - * @param WPInv_Invoice $invoice Invoice. |
|
124 | - */ |
|
125 | - public function thankyou_page( $invoice ) { |
|
121 | + * Output for the order received page. |
|
122 | + * |
|
123 | + * @param WPInv_Invoice $invoice Invoice. |
|
124 | + */ |
|
125 | + public function thankyou_page( $invoice ) { |
|
126 | 126 | |
127 | 127 | if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
128 | 128 | |
129 | - echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
|
129 | + echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
|
130 | 130 | |
131 | 131 | if ( ! empty( $this->instructions ) ) { |
132 | 132 | echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) ); |
133 | - } |
|
133 | + } |
|
134 | 134 | |
135 | - $this->bank_details( $invoice ); |
|
135 | + $this->bank_details( $invoice ); |
|
136 | 136 | |
137 | - echo '</div>'; |
|
137 | + echo '</div>'; |
|
138 | 138 | |
139 | 139 | } |
140 | 140 | |
141 | - } |
|
141 | + } |
|
142 | 142 | |
143 | 143 | /** |
144 | - * Add content to the WPI emails. |
|
145 | - * |
|
146 | - * @param WPInv_Invoice $invoice Invoice. |
|
147 | - * @param string $email_type Email format: plain text or HTML. |
|
148 | - * @param bool $sent_to_admin Sent to admin. |
|
149 | - */ |
|
150 | - public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
144 | + * Add content to the WPI emails. |
|
145 | + * |
|
146 | + * @param WPInv_Invoice $invoice Invoice. |
|
147 | + * @param string $email_type Email format: plain text or HTML. |
|
148 | + * @param bool $sent_to_admin Sent to admin. |
|
149 | + */ |
|
150 | + public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
151 | 151 | |
152 | - if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
152 | + if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
153 | 153 | |
154 | - echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
|
154 | + echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
|
155 | 155 | |
156 | - if ( $this->instructions ) { |
|
157 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
156 | + if ( $this->instructions ) { |
|
157 | + echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
158 | 158 | } |
159 | 159 | |
160 | - $this->bank_details( $invoice ); |
|
160 | + $this->bank_details( $invoice ); |
|
161 | 161 | |
162 | - echo '</div>'; |
|
162 | + echo '</div>'; |
|
163 | 163 | |
164 | - } |
|
164 | + } |
|
165 | 165 | |
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
169 | - * Get bank details and place into a list format. |
|
170 | - * |
|
171 | - * @param WPInv_Invoice $invoice Invoice. |
|
172 | - */ |
|
173 | - protected function bank_details( $invoice ) { |
|
169 | + * Get bank details and place into a list format. |
|
170 | + * |
|
171 | + * @param WPInv_Invoice $invoice Invoice. |
|
172 | + */ |
|
173 | + protected function bank_details( $invoice ) { |
|
174 | 174 | |
175 | - // Get the invoice country and country $locale. |
|
176 | - $country = $invoice->get_country(); |
|
177 | - $locale = $this->get_country_locale(); |
|
175 | + // Get the invoice country and country $locale. |
|
176 | + $country = $invoice->get_country(); |
|
177 | + $locale = $this->get_country_locale(); |
|
178 | 178 | |
179 | - // Get shortcode label in the $locale array and use appropriate one. |
|
180 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
179 | + // Get shortcode label in the $locale array and use appropriate one. |
|
180 | + $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
181 | 181 | |
182 | 182 | $bank_fields = array( |
183 | 183 | 'ac_name' => __( 'Account Name', 'invoicing' ), |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | |
197 | 197 | if ( ! empty( $value ) ) { |
198 | 198 | $bank_info[ $field ] = array( |
199 | - 'label' => $label, |
|
200 | - 'value' => $value, |
|
201 | - ); |
|
199 | + 'label' => $label, |
|
200 | + 'value' => $value, |
|
201 | + ); |
|
202 | 202 | } |
203 | - } |
|
203 | + } |
|
204 | 204 | |
205 | 205 | $bank_info = apply_filters( 'wpinv_bank_info', $bank_info, $invoice ); |
206 | 206 | |
@@ -208,177 +208,177 @@ discard block |
||
208 | 208 | return; |
209 | 209 | } |
210 | 210 | |
211 | - echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL; |
|
211 | + echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL; |
|
212 | + |
|
213 | + echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
|
214 | + |
|
215 | + foreach ( $bank_info as $key => $data ) { |
|
216 | + echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . '</td></tr>' . PHP_EOL; |
|
217 | + } |
|
218 | + |
|
219 | + echo '</table>'; |
|
220 | + |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Get country locale if localized. |
|
225 | + * |
|
226 | + * @return array |
|
227 | + */ |
|
228 | + public function get_country_locale() { |
|
229 | + |
|
230 | + if ( empty( $this->locale ) ) { |
|
231 | + |
|
232 | + // Locale information to be used - only those that are not 'Sort Code'. |
|
233 | + $this->locale = apply_filters( |
|
234 | + 'getpaid_get_bank_transfer_locale', |
|
235 | + array( |
|
236 | + 'AU' => array( |
|
237 | + 'sortcode' => array( |
|
238 | + 'label' => __( 'BSB', 'invoicing' ), |
|
239 | + ), |
|
240 | + ), |
|
241 | + 'CA' => array( |
|
242 | + 'sortcode' => array( |
|
243 | + 'label' => __( 'Bank transit number', 'invoicing' ), |
|
244 | + ), |
|
245 | + ), |
|
246 | + 'IN' => array( |
|
247 | + 'sortcode' => array( |
|
248 | + 'label' => __( 'IFSC', 'invoicing' ), |
|
249 | + ), |
|
250 | + ), |
|
251 | + 'IT' => array( |
|
252 | + 'sortcode' => array( |
|
253 | + 'label' => __( 'Branch sort', 'invoicing' ), |
|
254 | + ), |
|
255 | + ), |
|
256 | + 'NZ' => array( |
|
257 | + 'sortcode' => array( |
|
258 | + 'label' => __( 'Bank code', 'invoicing' ), |
|
259 | + ), |
|
260 | + ), |
|
261 | + 'SE' => array( |
|
262 | + 'sortcode' => array( |
|
263 | + 'label' => __( 'Bank code', 'invoicing' ), |
|
264 | + ), |
|
265 | + ), |
|
266 | + 'US' => array( |
|
267 | + 'sortcode' => array( |
|
268 | + 'label' => __( 'Routing number', 'invoicing' ), |
|
269 | + ), |
|
270 | + ), |
|
271 | + 'ZA' => array( |
|
272 | + 'sortcode' => array( |
|
273 | + 'label' => __( 'Branch code', 'invoicing' ), |
|
274 | + ), |
|
275 | + ), |
|
276 | + ) |
|
277 | + ); |
|
278 | + |
|
279 | + } |
|
280 | + |
|
281 | + return $this->locale; |
|
282 | + |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * Filters the gateway settings. |
|
287 | + * |
|
288 | + * @param array $admin_settings |
|
289 | + */ |
|
290 | + public function admin_settings( $admin_settings ) { |
|
291 | + $admin_settings['bank_transfer_desc']['std'] = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ); |
|
292 | + $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
293 | + |
|
294 | + $_settings = array(); |
|
295 | + |
|
296 | + foreach ( $admin_settings as $key => $setting ) { |
|
297 | + $_settings[ $key ] = $setting; |
|
298 | + |
|
299 | + if ( $key == 'bank_transfer_active' ) { |
|
300 | + // Enable/disable subscriptions setting. |
|
301 | + $_settings['bank_transfer_no_subscription'] = array( |
|
302 | + 'id' => 'bank_transfer_no_subscription', |
|
303 | + 'type' => 'checkbox', |
|
304 | + 'name' => __( 'Disable Subscriptions', 'invoicing' ), |
|
305 | + 'desc' => __( 'Tick to disable support for recurring items.', 'invoicing' ), |
|
306 | + 'std' => 0 |
|
307 | + ); |
|
308 | + } |
|
309 | + } |
|
310 | + |
|
311 | + $admin_settings = $_settings; |
|
312 | + |
|
313 | + $locale = $this->get_country_locale(); |
|
314 | + |
|
315 | + // Get sortcode label in the $locale array and use appropriate one. |
|
316 | + $country = wpinv_default_billing_country(); |
|
317 | + $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
318 | + |
|
319 | + $admin_settings['bank_transfer_ac_name'] = array( |
|
320 | + 'type' => 'text', |
|
321 | + 'id' => 'bank_transfer_ac_name', |
|
322 | + 'name' => __( 'Account Name', 'invoicing' ), |
|
323 | + ); |
|
324 | + |
|
325 | + $admin_settings['bank_transfer_ac_no'] = array( |
|
326 | + 'type' => 'text', |
|
327 | + 'id' => 'bank_transfer_ac_no', |
|
328 | + 'name' => __( 'Account Number', 'invoicing' ), |
|
329 | + ); |
|
330 | + |
|
331 | + $admin_settings['bank_transfer_bank_name'] = array( |
|
332 | + 'type' => 'text', |
|
333 | + 'id' => 'bank_transfer_bank_name', |
|
334 | + 'name' => __( 'Bank Name', 'invoicing' ), |
|
335 | + ); |
|
212 | 336 | |
213 | - echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
|
337 | + $admin_settings['bank_transfer_ifsc'] = array( |
|
338 | + 'type' => 'text', |
|
339 | + 'id' => 'bank_transfer_ifsc', |
|
340 | + 'name' => __( 'IFSC Code', 'invoicing' ), |
|
341 | + ); |
|
342 | + |
|
343 | + $admin_settings['bank_transfer_iban'] = array( |
|
344 | + 'type' => 'text', |
|
345 | + 'id' => 'bank_transfer_iban', |
|
346 | + 'name' => __( 'IBAN', 'invoicing' ), |
|
347 | + ); |
|
348 | + |
|
349 | + $admin_settings['bank_transfer_bic'] = array( |
|
350 | + 'type' => 'text', |
|
351 | + 'id' => 'bank_transfer_bic', |
|
352 | + 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
|
353 | + ); |
|
214 | 354 | |
215 | - foreach ( $bank_info as $key => $data ) { |
|
216 | - echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . '</td></tr>' . PHP_EOL; |
|
217 | - } |
|
355 | + $admin_settings['bank_transfer_sort_code'] = array( |
|
356 | + 'type' => 'text', |
|
357 | + 'id' => 'bank_transfer_sort_code', |
|
358 | + 'name' => $sortcode, |
|
359 | + ); |
|
218 | 360 | |
219 | - echo '</table>'; |
|
361 | + $admin_settings['bank_transfer_info'] = array( |
|
362 | + 'id' => 'bank_transfer_info', |
|
363 | + 'name' => __( 'Instructions', 'invoicing' ), |
|
364 | + 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
|
365 | + 'type' => 'textarea', |
|
366 | + 'std' => __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ), |
|
367 | + 'cols' => 50, |
|
368 | + 'rows' => 5, |
|
369 | + ); |
|
220 | 370 | |
371 | + return $admin_settings; |
|
221 | 372 | } |
222 | 373 | |
223 | 374 | /** |
224 | - * Get country locale if localized. |
|
225 | - * |
|
226 | - * @return array |
|
227 | - */ |
|
228 | - public function get_country_locale() { |
|
229 | - |
|
230 | - if ( empty( $this->locale ) ) { |
|
231 | - |
|
232 | - // Locale information to be used - only those that are not 'Sort Code'. |
|
233 | - $this->locale = apply_filters( |
|
234 | - 'getpaid_get_bank_transfer_locale', |
|
235 | - array( |
|
236 | - 'AU' => array( |
|
237 | - 'sortcode' => array( |
|
238 | - 'label' => __( 'BSB', 'invoicing' ), |
|
239 | - ), |
|
240 | - ), |
|
241 | - 'CA' => array( |
|
242 | - 'sortcode' => array( |
|
243 | - 'label' => __( 'Bank transit number', 'invoicing' ), |
|
244 | - ), |
|
245 | - ), |
|
246 | - 'IN' => array( |
|
247 | - 'sortcode' => array( |
|
248 | - 'label' => __( 'IFSC', 'invoicing' ), |
|
249 | - ), |
|
250 | - ), |
|
251 | - 'IT' => array( |
|
252 | - 'sortcode' => array( |
|
253 | - 'label' => __( 'Branch sort', 'invoicing' ), |
|
254 | - ), |
|
255 | - ), |
|
256 | - 'NZ' => array( |
|
257 | - 'sortcode' => array( |
|
258 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
259 | - ), |
|
260 | - ), |
|
261 | - 'SE' => array( |
|
262 | - 'sortcode' => array( |
|
263 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
264 | - ), |
|
265 | - ), |
|
266 | - 'US' => array( |
|
267 | - 'sortcode' => array( |
|
268 | - 'label' => __( 'Routing number', 'invoicing' ), |
|
269 | - ), |
|
270 | - ), |
|
271 | - 'ZA' => array( |
|
272 | - 'sortcode' => array( |
|
273 | - 'label' => __( 'Branch code', 'invoicing' ), |
|
274 | - ), |
|
275 | - ), |
|
276 | - ) |
|
277 | - ); |
|
278 | - |
|
279 | - } |
|
280 | - |
|
281 | - return $this->locale; |
|
282 | - |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * Filters the gateway settings. |
|
287 | - * |
|
288 | - * @param array $admin_settings |
|
289 | - */ |
|
290 | - public function admin_settings( $admin_settings ) { |
|
291 | - $admin_settings['bank_transfer_desc']['std'] = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ); |
|
292 | - $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
293 | - |
|
294 | - $_settings = array(); |
|
295 | - |
|
296 | - foreach ( $admin_settings as $key => $setting ) { |
|
297 | - $_settings[ $key ] = $setting; |
|
298 | - |
|
299 | - if ( $key == 'bank_transfer_active' ) { |
|
300 | - // Enable/disable subscriptions setting. |
|
301 | - $_settings['bank_transfer_no_subscription'] = array( |
|
302 | - 'id' => 'bank_transfer_no_subscription', |
|
303 | - 'type' => 'checkbox', |
|
304 | - 'name' => __( 'Disable Subscriptions', 'invoicing' ), |
|
305 | - 'desc' => __( 'Tick to disable support for recurring items.', 'invoicing' ), |
|
306 | - 'std' => 0 |
|
307 | - ); |
|
308 | - } |
|
309 | - } |
|
310 | - |
|
311 | - $admin_settings = $_settings; |
|
312 | - |
|
313 | - $locale = $this->get_country_locale(); |
|
314 | - |
|
315 | - // Get sortcode label in the $locale array and use appropriate one. |
|
316 | - $country = wpinv_default_billing_country(); |
|
317 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
318 | - |
|
319 | - $admin_settings['bank_transfer_ac_name'] = array( |
|
320 | - 'type' => 'text', |
|
321 | - 'id' => 'bank_transfer_ac_name', |
|
322 | - 'name' => __( 'Account Name', 'invoicing' ), |
|
323 | - ); |
|
324 | - |
|
325 | - $admin_settings['bank_transfer_ac_no'] = array( |
|
326 | - 'type' => 'text', |
|
327 | - 'id' => 'bank_transfer_ac_no', |
|
328 | - 'name' => __( 'Account Number', 'invoicing' ), |
|
329 | - ); |
|
330 | - |
|
331 | - $admin_settings['bank_transfer_bank_name'] = array( |
|
332 | - 'type' => 'text', |
|
333 | - 'id' => 'bank_transfer_bank_name', |
|
334 | - 'name' => __( 'Bank Name', 'invoicing' ), |
|
335 | - ); |
|
336 | - |
|
337 | - $admin_settings['bank_transfer_ifsc'] = array( |
|
338 | - 'type' => 'text', |
|
339 | - 'id' => 'bank_transfer_ifsc', |
|
340 | - 'name' => __( 'IFSC Code', 'invoicing' ), |
|
341 | - ); |
|
342 | - |
|
343 | - $admin_settings['bank_transfer_iban'] = array( |
|
344 | - 'type' => 'text', |
|
345 | - 'id' => 'bank_transfer_iban', |
|
346 | - 'name' => __( 'IBAN', 'invoicing' ), |
|
347 | - ); |
|
348 | - |
|
349 | - $admin_settings['bank_transfer_bic'] = array( |
|
350 | - 'type' => 'text', |
|
351 | - 'id' => 'bank_transfer_bic', |
|
352 | - 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
|
353 | - ); |
|
354 | - |
|
355 | - $admin_settings['bank_transfer_sort_code'] = array( |
|
356 | - 'type' => 'text', |
|
357 | - 'id' => 'bank_transfer_sort_code', |
|
358 | - 'name' => $sortcode, |
|
359 | - ); |
|
360 | - |
|
361 | - $admin_settings['bank_transfer_info'] = array( |
|
362 | - 'id' => 'bank_transfer_info', |
|
363 | - 'name' => __( 'Instructions', 'invoicing' ), |
|
364 | - 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
|
365 | - 'type' => 'textarea', |
|
366 | - 'std' => __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ), |
|
367 | - 'cols' => 50, |
|
368 | - 'rows' => 5, |
|
369 | - ); |
|
370 | - |
|
371 | - return $admin_settings; |
|
372 | - } |
|
373 | - |
|
374 | - /** |
|
375 | - * Processes invoice addons. |
|
376 | - * |
|
377 | - * @param WPInv_Invoice $invoice |
|
378 | - * @param GetPaid_Form_Item[] $items |
|
379 | - * @return WPInv_Invoice |
|
380 | - */ |
|
381 | - public function process_addons( $invoice, $items ) { |
|
375 | + * Processes invoice addons. |
|
376 | + * |
|
377 | + * @param WPInv_Invoice $invoice |
|
378 | + * @param GetPaid_Form_Item[] $items |
|
379 | + * @return WPInv_Invoice |
|
380 | + */ |
|
381 | + public function process_addons( $invoice, $items ) { |
|
382 | 382 | |
383 | 383 | foreach ( $items as $item ) { |
384 | 384 | $invoice->add_item( $item ); |
@@ -386,98 +386,98 @@ discard block |
||
386 | 386 | |
387 | 387 | $invoice->recalculate_total(); |
388 | 388 | $invoice->save(); |
389 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * (Maybe) renews a bank transfer subscription profile. |
|
393 | - * |
|
394 | - * |
|
395 | - * @param WPInv_Subscription $subscription |
|
396 | - */ |
|
397 | - public function maybe_renew_subscription( $subscription, $parent_invoice ) { |
|
398 | - // Ensure its our subscription && it's active. |
|
399 | - if ( ! empty( $parent_invoice ) && $this->id === $parent_invoice->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
|
400 | - add_filter( 'getpaid_invoice_notifications_is_payment_form_invoice', array( $this, 'force_is_payment_form_invoice' ), 10, 2 ); |
|
401 | - |
|
402 | - $invoice = $subscription->create_payment(); |
|
403 | - |
|
404 | - if ( ! empty( $invoice ) ) { |
|
405 | - $is_logged_in = is_user_logged_in(); |
|
406 | - |
|
407 | - // Cron run. |
|
408 | - if ( ! $is_logged_in ) { |
|
409 | - $note = wp_sprintf( __( 'Renewal %1$s created with the status "%2$s".', 'invoicing' ), $invoice->get_invoice_quote_type(), wpinv_status_nicename( $invoice->get_status(), $invoice ) ); |
|
410 | - |
|
411 | - $invoice->add_note( $note, false, $is_logged_in, ! $is_logged_in ); |
|
412 | - } |
|
413 | - } |
|
414 | - |
|
415 | - remove_filter( 'getpaid_invoice_notifications_is_payment_form_invoice', array( $this, 'force_is_payment_form_invoice' ), 10, 2 ); |
|
416 | - } |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * Process a bank transfer payment. |
|
421 | - * |
|
422 | - * |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * (Maybe) renews a bank transfer subscription profile. |
|
393 | + * |
|
394 | + * |
|
395 | + * @param WPInv_Subscription $subscription |
|
396 | + */ |
|
397 | + public function maybe_renew_subscription( $subscription, $parent_invoice ) { |
|
398 | + // Ensure its our subscription && it's active. |
|
399 | + if ( ! empty( $parent_invoice ) && $this->id === $parent_invoice->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
|
400 | + add_filter( 'getpaid_invoice_notifications_is_payment_form_invoice', array( $this, 'force_is_payment_form_invoice' ), 10, 2 ); |
|
401 | + |
|
402 | + $invoice = $subscription->create_payment(); |
|
403 | + |
|
404 | + if ( ! empty( $invoice ) ) { |
|
405 | + $is_logged_in = is_user_logged_in(); |
|
406 | + |
|
407 | + // Cron run. |
|
408 | + if ( ! $is_logged_in ) { |
|
409 | + $note = wp_sprintf( __( 'Renewal %1$s created with the status "%2$s".', 'invoicing' ), $invoice->get_invoice_quote_type(), wpinv_status_nicename( $invoice->get_status(), $invoice ) ); |
|
410 | + |
|
411 | + $invoice->add_note( $note, false, $is_logged_in, ! $is_logged_in ); |
|
412 | + } |
|
413 | + } |
|
414 | + |
|
415 | + remove_filter( 'getpaid_invoice_notifications_is_payment_form_invoice', array( $this, 'force_is_payment_form_invoice' ), 10, 2 ); |
|
416 | + } |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * Process a bank transfer payment. |
|
421 | + * |
|
422 | + * |
|
423 | 423 | * @param WPInv_Invoice $invoice |
424 | - */ |
|
425 | - public function invoice_paid( $invoice ) { |
|
426 | - |
|
427 | - // Abort if not paid by bank transfer. |
|
428 | - if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) { |
|
429 | - return; |
|
430 | - } |
|
431 | - |
|
432 | - // Is it a parent payment? |
|
433 | - if ( 0 == $invoice->get_parent_id() ) { |
|
434 | - |
|
435 | - // (Maybe) activate subscriptions. |
|
436 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
437 | - |
|
438 | - if ( ! empty( $subscriptions ) ) { |
|
439 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
440 | - |
|
441 | - foreach ( $subscriptions as $subscription ) { |
|
442 | - if ( $subscription->exists() ) { |
|
443 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
444 | - $expiry = gmdate( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
445 | - |
|
446 | - $subscription->set_next_renewal_date( $expiry ); |
|
447 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
448 | - $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ); |
|
449 | - $subscription->activate(); |
|
450 | - } |
|
451 | - } |
|
452 | - } |
|
453 | - } else { |
|
454 | - |
|
455 | - $subscription = getpaid_get_subscription( $invoice->get_subscription_id() ); |
|
456 | - |
|
457 | - // Renew the subscription. |
|
458 | - if ( $subscription && $subscription->exists() ) { |
|
459 | - $subscription->add_payment( array(), $invoice ); |
|
460 | - $subscription->renew( strtotime( $invoice->get_date_created() ) ); |
|
461 | - } |
|
462 | - } |
|
424 | + */ |
|
425 | + public function invoice_paid( $invoice ) { |
|
426 | + |
|
427 | + // Abort if not paid by bank transfer. |
|
428 | + if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) { |
|
429 | + return; |
|
430 | + } |
|
431 | + |
|
432 | + // Is it a parent payment? |
|
433 | + if ( 0 == $invoice->get_parent_id() ) { |
|
434 | + |
|
435 | + // (Maybe) activate subscriptions. |
|
436 | + $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
437 | + |
|
438 | + if ( ! empty( $subscriptions ) ) { |
|
439 | + $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
440 | + |
|
441 | + foreach ( $subscriptions as $subscription ) { |
|
442 | + if ( $subscription->exists() ) { |
|
443 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
444 | + $expiry = gmdate( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
445 | + |
|
446 | + $subscription->set_next_renewal_date( $expiry ); |
|
447 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
448 | + $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ); |
|
449 | + $subscription->activate(); |
|
450 | + } |
|
451 | + } |
|
452 | + } |
|
453 | + } else { |
|
454 | + |
|
455 | + $subscription = getpaid_get_subscription( $invoice->get_subscription_id() ); |
|
456 | + |
|
457 | + // Renew the subscription. |
|
458 | + if ( $subscription && $subscription->exists() ) { |
|
459 | + $subscription->add_payment( array(), $invoice ); |
|
460 | + $subscription->renew( strtotime( $invoice->get_date_created() ) ); |
|
461 | + } |
|
462 | + } |
|
463 | 463 | |
464 | 464 | } |
465 | 465 | |
466 | - /** |
|
467 | - * Force created from payment false to allow email for auto renewal generation invoice. |
|
468 | - * |
|
469 | - * @since 2.8.11 |
|
470 | - * |
|
471 | - * @param bool $is_payment_form_invoice True when invoice created via payment form else false. |
|
472 | - * @param int $invoice Invoice ID. |
|
473 | - * @return bool True when invoice created via payment form else false. |
|
474 | - */ |
|
475 | - public function force_is_payment_form_invoice( $is_payment_form_invoice, $invoice ) { |
|
476 | - if ( $is_payment_form_invoice ) { |
|
477 | - $is_payment_form_invoice = false; |
|
478 | - } |
|
479 | - |
|
480 | - return $is_payment_form_invoice; |
|
481 | - } |
|
466 | + /** |
|
467 | + * Force created from payment false to allow email for auto renewal generation invoice. |
|
468 | + * |
|
469 | + * @since 2.8.11 |
|
470 | + * |
|
471 | + * @param bool $is_payment_form_invoice True when invoice created via payment form else false. |
|
472 | + * @param int $invoice Invoice ID. |
|
473 | + * @return bool True when invoice created via payment form else false. |
|
474 | + */ |
|
475 | + public function force_is_payment_form_invoice( $is_payment_form_invoice, $invoice ) { |
|
476 | + if ( $is_payment_form_invoice ) { |
|
477 | + $is_payment_form_invoice = false; |
|
478 | + } |
|
479 | + |
|
480 | + return $is_payment_form_invoice; |
|
481 | + } |
|
482 | 482 | |
483 | 483 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Bank transfer Payment Gateway class. |
@@ -56,21 +56,21 @@ discard block |
||
56 | 56 | public function __construct() { |
57 | 57 | parent::__construct(); |
58 | 58 | |
59 | - $this->title = __( 'Direct bank transfer', 'invoicing' ); |
|
60 | - $this->method_title = __( 'Bank transfer', 'invoicing' ); |
|
61 | - $this->checkout_button_text = __( 'Proceed', 'invoicing' ); |
|
62 | - $this->instructions = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) ); |
|
63 | - |
|
64 | - add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
65 | - add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
66 | - add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 ); |
|
67 | - add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
68 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ), 12, 2 ); |
|
69 | - add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 ); |
|
70 | - |
|
71 | - add_filter( 'wpinv_' . $this->id . '_support_subscription', array( $this, 'supports_subscription' ), 20, 1 ); |
|
72 | - add_filter( 'getpaid_' . $this->id . '_support_subscription', array( $this, 'supports_subscription' ), 20, 1 ); |
|
73 | - add_filter( 'getpaid_' . $this->id . '_supports_subscription', array( $this, 'supports_subscription' ), 20, 1 ); |
|
59 | + $this->title = __('Direct bank transfer', 'invoicing'); |
|
60 | + $this->method_title = __('Bank transfer', 'invoicing'); |
|
61 | + $this->checkout_button_text = __('Proceed', 'invoicing'); |
|
62 | + $this->instructions = apply_filters('wpinv_bank_instructions', $this->get_option('info')); |
|
63 | + |
|
64 | + add_action('wpinv_receipt_end', array($this, 'thankyou_page')); |
|
65 | + add_action('getpaid_invoice_line_items', array($this, 'thankyou_page'), 40); |
|
66 | + add_action('wpinv_pdf_content_billing', array($this, 'thankyou_page'), 11); |
|
67 | + add_action('wpinv_email_invoice_details', array($this, 'email_instructions'), 10, 3); |
|
68 | + add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription'), 12, 2); |
|
69 | + add_action('getpaid_invoice_status_publish', array($this, 'invoice_paid'), 20); |
|
70 | + |
|
71 | + add_filter('wpinv_' . $this->id . '_support_subscription', array($this, 'supports_subscription'), 20, 1); |
|
72 | + add_filter('getpaid_' . $this->id . '_support_subscription', array($this, 'supports_subscription'), 20, 1); |
|
73 | + add_filter('getpaid_' . $this->id . '_supports_subscription', array($this, 'supports_subscription'), 20, 1); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | * @param bool $supports True if supports else False. |
82 | 82 | * @return bool True if supports else False. |
83 | 83 | */ |
84 | - public function supports_subscription( $supports ) { |
|
85 | - if ( $supports && (int) $this->get_option( 'no_subscription' ) ) { |
|
84 | + public function supports_subscription($supports) { |
|
85 | + if ($supports && (int) $this->get_option('no_subscription')) { |
|
86 | 86 | $supports = false; |
87 | 87 | } |
88 | 88 | |
@@ -97,23 +97,23 @@ discard block |
||
97 | 97 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
98 | 98 | * @return array |
99 | 99 | */ |
100 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
100 | + public function process_payment($invoice, $submission_data, $submission) { |
|
101 | 101 | |
102 | 102 | // Add a transaction id. |
103 | - $invoice->set_transaction_id( $invoice->generate_key( 'bt_' ) ); |
|
103 | + $invoice->set_transaction_id($invoice->generate_key('bt_')); |
|
104 | 104 | |
105 | 105 | // Set it as pending payment. |
106 | - if ( ! $invoice->needs_payment() ) { |
|
106 | + if (!$invoice->needs_payment()) { |
|
107 | 107 | $invoice->mark_paid(); |
108 | - } elseif ( ! $invoice->is_paid() ) { |
|
109 | - $invoice->set_status( 'wpi-onhold' ); |
|
108 | + } elseif (!$invoice->is_paid()) { |
|
109 | + $invoice->set_status('wpi-onhold'); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | // Save it. |
113 | 113 | $invoice->save(); |
114 | 114 | |
115 | 115 | // Send to the success page. |
116 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
116 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
117 | 117 | |
118 | 118 | } |
119 | 119 | |
@@ -122,17 +122,17 @@ discard block |
||
122 | 122 | * |
123 | 123 | * @param WPInv_Invoice $invoice Invoice. |
124 | 124 | */ |
125 | - public function thankyou_page( $invoice ) { |
|
125 | + public function thankyou_page($invoice) { |
|
126 | 126 | |
127 | - if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
127 | + if ('bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment()) { |
|
128 | 128 | |
129 | 129 | echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
130 | 130 | |
131 | - if ( ! empty( $this->instructions ) ) { |
|
132 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) ); |
|
131 | + if (!empty($this->instructions)) { |
|
132 | + echo wp_kses_post(wpautop(wptexturize($this->instructions))); |
|
133 | 133 | } |
134 | 134 | |
135 | - $this->bank_details( $invoice ); |
|
135 | + $this->bank_details($invoice); |
|
136 | 136 | |
137 | 137 | echo '</div>'; |
138 | 138 | |
@@ -147,17 +147,17 @@ discard block |
||
147 | 147 | * @param string $email_type Email format: plain text or HTML. |
148 | 148 | * @param bool $sent_to_admin Sent to admin. |
149 | 149 | */ |
150 | - public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
150 | + public function email_instructions($invoice, $email_type, $sent_to_admin) { |
|
151 | 151 | |
152 | - if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
152 | + if (!$sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment()) { |
|
153 | 153 | |
154 | 154 | echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
155 | 155 | |
156 | - if ( $this->instructions ) { |
|
157 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
156 | + if ($this->instructions) { |
|
157 | + echo wp_kses_post(wpautop(wptexturize($this->instructions)) . PHP_EOL); |
|
158 | 158 | } |
159 | 159 | |
160 | - $this->bank_details( $invoice ); |
|
160 | + $this->bank_details($invoice); |
|
161 | 161 | |
162 | 162 | echo '</div>'; |
163 | 163 | |
@@ -170,50 +170,50 @@ discard block |
||
170 | 170 | * |
171 | 171 | * @param WPInv_Invoice $invoice Invoice. |
172 | 172 | */ |
173 | - protected function bank_details( $invoice ) { |
|
173 | + protected function bank_details($invoice) { |
|
174 | 174 | |
175 | 175 | // Get the invoice country and country $locale. |
176 | 176 | $country = $invoice->get_country(); |
177 | 177 | $locale = $this->get_country_locale(); |
178 | 178 | |
179 | 179 | // Get shortcode label in the $locale array and use appropriate one. |
180 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
180 | + $sortcode = isset($locale[$country]['sortcode']['label']) ? $locale[$country]['sortcode']['label'] : __('Sort code', 'invoicing'); |
|
181 | 181 | |
182 | 182 | $bank_fields = array( |
183 | - 'ac_name' => __( 'Account Name', 'invoicing' ), |
|
184 | - 'ac_no' => __( 'Account Number', 'invoicing' ), |
|
185 | - 'bank_name' => __( 'Bank Name', 'invoicing' ), |
|
186 | - 'ifsc' => __( 'IFSC code', 'invoicing' ), |
|
187 | - 'iban' => __( 'IBAN', 'invoicing' ), |
|
188 | - 'bic' => __( 'BIC/Swift code', 'invoicing' ), |
|
183 | + 'ac_name' => __('Account Name', 'invoicing'), |
|
184 | + 'ac_no' => __('Account Number', 'invoicing'), |
|
185 | + 'bank_name' => __('Bank Name', 'invoicing'), |
|
186 | + 'ifsc' => __('IFSC code', 'invoicing'), |
|
187 | + 'iban' => __('IBAN', 'invoicing'), |
|
188 | + 'bic' => __('BIC/Swift code', 'invoicing'), |
|
189 | 189 | 'sort_code' => $sortcode, |
190 | 190 | ); |
191 | 191 | |
192 | 192 | $bank_info = array(); |
193 | 193 | |
194 | - foreach ( $bank_fields as $field => $label ) { |
|
195 | - $value = $this->get_option( $field ); |
|
194 | + foreach ($bank_fields as $field => $label) { |
|
195 | + $value = $this->get_option($field); |
|
196 | 196 | |
197 | - if ( ! empty( $value ) ) { |
|
198 | - $bank_info[ $field ] = array( |
|
197 | + if (!empty($value)) { |
|
198 | + $bank_info[$field] = array( |
|
199 | 199 | 'label' => $label, |
200 | 200 | 'value' => $value, |
201 | 201 | ); |
202 | 202 | } |
203 | 203 | } |
204 | 204 | |
205 | - $bank_info = apply_filters( 'wpinv_bank_info', $bank_info, $invoice ); |
|
205 | + $bank_info = apply_filters('wpinv_bank_info', $bank_info, $invoice); |
|
206 | 206 | |
207 | - if ( empty( $bank_info ) ) { |
|
207 | + if (empty($bank_info)) { |
|
208 | 208 | return; |
209 | 209 | } |
210 | 210 | |
211 | - echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL; |
|
211 | + echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html(apply_filters('wpinv_receipt_bank_details_title', __('Bank Details', 'invoicing'), $invoice)) . '</h3>' . PHP_EOL; |
|
212 | 212 | |
213 | 213 | echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
214 | 214 | |
215 | - foreach ( $bank_info as $key => $data ) { |
|
216 | - echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . '</td></tr>' . PHP_EOL; |
|
215 | + foreach ($bank_info as $key => $data) { |
|
216 | + echo "<tr class='getpaid-bank-transfer-" . esc_attr($key) . "'><th class='font-weight-bold'>" . wp_kses_post($data['label']) . "</th><td class='w-75'>" . wp_kses_post(wptexturize($data['value'])) . '</td></tr>' . PHP_EOL; |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | echo '</table>'; |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | */ |
228 | 228 | public function get_country_locale() { |
229 | 229 | |
230 | - if ( empty( $this->locale ) ) { |
|
230 | + if (empty($this->locale)) { |
|
231 | 231 | |
232 | 232 | // Locale information to be used - only those that are not 'Sort Code'. |
233 | 233 | $this->locale = apply_filters( |
@@ -235,42 +235,42 @@ discard block |
||
235 | 235 | array( |
236 | 236 | 'AU' => array( |
237 | 237 | 'sortcode' => array( |
238 | - 'label' => __( 'BSB', 'invoicing' ), |
|
238 | + 'label' => __('BSB', 'invoicing'), |
|
239 | 239 | ), |
240 | 240 | ), |
241 | 241 | 'CA' => array( |
242 | 242 | 'sortcode' => array( |
243 | - 'label' => __( 'Bank transit number', 'invoicing' ), |
|
243 | + 'label' => __('Bank transit number', 'invoicing'), |
|
244 | 244 | ), |
245 | 245 | ), |
246 | 246 | 'IN' => array( |
247 | 247 | 'sortcode' => array( |
248 | - 'label' => __( 'IFSC', 'invoicing' ), |
|
248 | + 'label' => __('IFSC', 'invoicing'), |
|
249 | 249 | ), |
250 | 250 | ), |
251 | 251 | 'IT' => array( |
252 | 252 | 'sortcode' => array( |
253 | - 'label' => __( 'Branch sort', 'invoicing' ), |
|
253 | + 'label' => __('Branch sort', 'invoicing'), |
|
254 | 254 | ), |
255 | 255 | ), |
256 | 256 | 'NZ' => array( |
257 | 257 | 'sortcode' => array( |
258 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
258 | + 'label' => __('Bank code', 'invoicing'), |
|
259 | 259 | ), |
260 | 260 | ), |
261 | 261 | 'SE' => array( |
262 | 262 | 'sortcode' => array( |
263 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
263 | + 'label' => __('Bank code', 'invoicing'), |
|
264 | 264 | ), |
265 | 265 | ), |
266 | 266 | 'US' => array( |
267 | 267 | 'sortcode' => array( |
268 | - 'label' => __( 'Routing number', 'invoicing' ), |
|
268 | + 'label' => __('Routing number', 'invoicing'), |
|
269 | 269 | ), |
270 | 270 | ), |
271 | 271 | 'ZA' => array( |
272 | 272 | 'sortcode' => array( |
273 | - 'label' => __( 'Branch code', 'invoicing' ), |
|
273 | + 'label' => __('Branch code', 'invoicing'), |
|
274 | 274 | ), |
275 | 275 | ), |
276 | 276 | ) |
@@ -287,22 +287,22 @@ discard block |
||
287 | 287 | * |
288 | 288 | * @param array $admin_settings |
289 | 289 | */ |
290 | - public function admin_settings( $admin_settings ) { |
|
291 | - $admin_settings['bank_transfer_desc']['std'] = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ); |
|
292 | - $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
290 | + public function admin_settings($admin_settings) { |
|
291 | + $admin_settings['bank_transfer_desc']['std'] = __("Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing'); |
|
292 | + $admin_settings['bank_transfer_active']['desc'] = __('Enable bank transfer', 'invoicing'); |
|
293 | 293 | |
294 | 294 | $_settings = array(); |
295 | 295 | |
296 | - foreach ( $admin_settings as $key => $setting ) { |
|
297 | - $_settings[ $key ] = $setting; |
|
296 | + foreach ($admin_settings as $key => $setting) { |
|
297 | + $_settings[$key] = $setting; |
|
298 | 298 | |
299 | - if ( $key == 'bank_transfer_active' ) { |
|
299 | + if ($key == 'bank_transfer_active') { |
|
300 | 300 | // Enable/disable subscriptions setting. |
301 | 301 | $_settings['bank_transfer_no_subscription'] = array( |
302 | 302 | 'id' => 'bank_transfer_no_subscription', |
303 | 303 | 'type' => 'checkbox', |
304 | - 'name' => __( 'Disable Subscriptions', 'invoicing' ), |
|
305 | - 'desc' => __( 'Tick to disable support for recurring items.', 'invoicing' ), |
|
304 | + 'name' => __('Disable Subscriptions', 'invoicing'), |
|
305 | + 'desc' => __('Tick to disable support for recurring items.', 'invoicing'), |
|
306 | 306 | 'std' => 0 |
307 | 307 | ); |
308 | 308 | } |
@@ -310,46 +310,46 @@ discard block |
||
310 | 310 | |
311 | 311 | $admin_settings = $_settings; |
312 | 312 | |
313 | - $locale = $this->get_country_locale(); |
|
313 | + $locale = $this->get_country_locale(); |
|
314 | 314 | |
315 | 315 | // Get sortcode label in the $locale array and use appropriate one. |
316 | 316 | $country = wpinv_default_billing_country(); |
317 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
317 | + $sortcode = isset($locale[$country]['sortcode']['label']) ? $locale[$country]['sortcode']['label'] : __('Sort code', 'invoicing'); |
|
318 | 318 | |
319 | 319 | $admin_settings['bank_transfer_ac_name'] = array( |
320 | 320 | 'type' => 'text', |
321 | 321 | 'id' => 'bank_transfer_ac_name', |
322 | - 'name' => __( 'Account Name', 'invoicing' ), |
|
322 | + 'name' => __('Account Name', 'invoicing'), |
|
323 | 323 | ); |
324 | 324 | |
325 | 325 | $admin_settings['bank_transfer_ac_no'] = array( |
326 | 326 | 'type' => 'text', |
327 | 327 | 'id' => 'bank_transfer_ac_no', |
328 | - 'name' => __( 'Account Number', 'invoicing' ), |
|
328 | + 'name' => __('Account Number', 'invoicing'), |
|
329 | 329 | ); |
330 | 330 | |
331 | 331 | $admin_settings['bank_transfer_bank_name'] = array( |
332 | 332 | 'type' => 'text', |
333 | 333 | 'id' => 'bank_transfer_bank_name', |
334 | - 'name' => __( 'Bank Name', 'invoicing' ), |
|
334 | + 'name' => __('Bank Name', 'invoicing'), |
|
335 | 335 | ); |
336 | 336 | |
337 | 337 | $admin_settings['bank_transfer_ifsc'] = array( |
338 | 338 | 'type' => 'text', |
339 | 339 | 'id' => 'bank_transfer_ifsc', |
340 | - 'name' => __( 'IFSC Code', 'invoicing' ), |
|
340 | + 'name' => __('IFSC Code', 'invoicing'), |
|
341 | 341 | ); |
342 | 342 | |
343 | 343 | $admin_settings['bank_transfer_iban'] = array( |
344 | 344 | 'type' => 'text', |
345 | 345 | 'id' => 'bank_transfer_iban', |
346 | - 'name' => __( 'IBAN', 'invoicing' ), |
|
346 | + 'name' => __('IBAN', 'invoicing'), |
|
347 | 347 | ); |
348 | 348 | |
349 | 349 | $admin_settings['bank_transfer_bic'] = array( |
350 | 350 | 'type' => 'text', |
351 | 351 | 'id' => 'bank_transfer_bic', |
352 | - 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
|
352 | + 'name' => __('BIC/Swift Code', 'invoicing'), |
|
353 | 353 | ); |
354 | 354 | |
355 | 355 | $admin_settings['bank_transfer_sort_code'] = array( |
@@ -360,10 +360,10 @@ discard block |
||
360 | 360 | |
361 | 361 | $admin_settings['bank_transfer_info'] = array( |
362 | 362 | 'id' => 'bank_transfer_info', |
363 | - 'name' => __( 'Instructions', 'invoicing' ), |
|
364 | - 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
|
363 | + 'name' => __('Instructions', 'invoicing'), |
|
364 | + 'desc' => __('Instructions that will be added to the thank you page and emails.', 'invoicing'), |
|
365 | 365 | 'type' => 'textarea', |
366 | - 'std' => __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ), |
|
366 | + 'std' => __("Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing'), |
|
367 | 367 | 'cols' => 50, |
368 | 368 | 'rows' => 5, |
369 | 369 | ); |
@@ -378,10 +378,10 @@ discard block |
||
378 | 378 | * @param GetPaid_Form_Item[] $items |
379 | 379 | * @return WPInv_Invoice |
380 | 380 | */ |
381 | - public function process_addons( $invoice, $items ) { |
|
381 | + public function process_addons($invoice, $items) { |
|
382 | 382 | |
383 | - foreach ( $items as $item ) { |
|
384 | - $invoice->add_item( $item ); |
|
383 | + foreach ($items as $item) { |
|
384 | + $invoice->add_item($item); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | $invoice->recalculate_total(); |
@@ -394,25 +394,25 @@ discard block |
||
394 | 394 | * |
395 | 395 | * @param WPInv_Subscription $subscription |
396 | 396 | */ |
397 | - public function maybe_renew_subscription( $subscription, $parent_invoice ) { |
|
397 | + public function maybe_renew_subscription($subscription, $parent_invoice) { |
|
398 | 398 | // Ensure its our subscription && it's active. |
399 | - if ( ! empty( $parent_invoice ) && $this->id === $parent_invoice->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
|
400 | - add_filter( 'getpaid_invoice_notifications_is_payment_form_invoice', array( $this, 'force_is_payment_form_invoice' ), 10, 2 ); |
|
399 | + if (!empty($parent_invoice) && $this->id === $parent_invoice->get_gateway() && $subscription->has_status('active trialling')) { |
|
400 | + add_filter('getpaid_invoice_notifications_is_payment_form_invoice', array($this, 'force_is_payment_form_invoice'), 10, 2); |
|
401 | 401 | |
402 | 402 | $invoice = $subscription->create_payment(); |
403 | 403 | |
404 | - if ( ! empty( $invoice ) ) { |
|
404 | + if (!empty($invoice)) { |
|
405 | 405 | $is_logged_in = is_user_logged_in(); |
406 | 406 | |
407 | 407 | // Cron run. |
408 | - if ( ! $is_logged_in ) { |
|
409 | - $note = wp_sprintf( __( 'Renewal %1$s created with the status "%2$s".', 'invoicing' ), $invoice->get_invoice_quote_type(), wpinv_status_nicename( $invoice->get_status(), $invoice ) ); |
|
408 | + if (!$is_logged_in) { |
|
409 | + $note = wp_sprintf(__('Renewal %1$s created with the status "%2$s".', 'invoicing'), $invoice->get_invoice_quote_type(), wpinv_status_nicename($invoice->get_status(), $invoice)); |
|
410 | 410 | |
411 | - $invoice->add_note( $note, false, $is_logged_in, ! $is_logged_in ); |
|
411 | + $invoice->add_note($note, false, $is_logged_in, !$is_logged_in); |
|
412 | 412 | } |
413 | 413 | } |
414 | 414 | |
415 | - remove_filter( 'getpaid_invoice_notifications_is_payment_form_invoice', array( $this, 'force_is_payment_form_invoice' ), 10, 2 ); |
|
415 | + remove_filter('getpaid_invoice_notifications_is_payment_form_invoice', array($this, 'force_is_payment_form_invoice'), 10, 2); |
|
416 | 416 | } |
417 | 417 | } |
418 | 418 | |
@@ -422,42 +422,42 @@ discard block |
||
422 | 422 | * |
423 | 423 | * @param WPInv_Invoice $invoice |
424 | 424 | */ |
425 | - public function invoice_paid( $invoice ) { |
|
425 | + public function invoice_paid($invoice) { |
|
426 | 426 | |
427 | 427 | // Abort if not paid by bank transfer. |
428 | - if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) { |
|
428 | + if ($this->id !== $invoice->get_gateway() || !$invoice->is_recurring()) { |
|
429 | 429 | return; |
430 | 430 | } |
431 | 431 | |
432 | 432 | // Is it a parent payment? |
433 | - if ( 0 == $invoice->get_parent_id() ) { |
|
433 | + if (0 == $invoice->get_parent_id()) { |
|
434 | 434 | |
435 | 435 | // (Maybe) activate subscriptions. |
436 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
436 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
437 | 437 | |
438 | - if ( ! empty( $subscriptions ) ) { |
|
439 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
438 | + if (!empty($subscriptions)) { |
|
439 | + $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions); |
|
440 | 440 | |
441 | - foreach ( $subscriptions as $subscription ) { |
|
442 | - if ( $subscription->exists() ) { |
|
443 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
444 | - $expiry = gmdate( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
441 | + foreach ($subscriptions as $subscription) { |
|
442 | + if ($subscription->exists()) { |
|
443 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
444 | + $expiry = gmdate('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
445 | 445 | |
446 | - $subscription->set_next_renewal_date( $expiry ); |
|
447 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
448 | - $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ); |
|
446 | + $subscription->set_next_renewal_date($expiry); |
|
447 | + $subscription->set_date_created(current_time('mysql')); |
|
448 | + $subscription->set_profile_id('bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id()); |
|
449 | 449 | $subscription->activate(); |
450 | 450 | } |
451 | 451 | } |
452 | 452 | } |
453 | 453 | } else { |
454 | 454 | |
455 | - $subscription = getpaid_get_subscription( $invoice->get_subscription_id() ); |
|
455 | + $subscription = getpaid_get_subscription($invoice->get_subscription_id()); |
|
456 | 456 | |
457 | 457 | // Renew the subscription. |
458 | - if ( $subscription && $subscription->exists() ) { |
|
459 | - $subscription->add_payment( array(), $invoice ); |
|
460 | - $subscription->renew( strtotime( $invoice->get_date_created() ) ); |
|
458 | + if ($subscription && $subscription->exists()) { |
|
459 | + $subscription->add_payment(array(), $invoice); |
|
460 | + $subscription->renew(strtotime($invoice->get_date_created())); |
|
461 | 461 | } |
462 | 462 | } |
463 | 463 | |
@@ -472,8 +472,8 @@ discard block |
||
472 | 472 | * @param int $invoice Invoice ID. |
473 | 473 | * @return bool True when invoice created via payment form else false. |
474 | 474 | */ |
475 | - public function force_is_payment_form_invoice( $is_payment_form_invoice, $invoice ) { |
|
476 | - if ( $is_payment_form_invoice ) { |
|
475 | + public function force_is_payment_form_invoice($is_payment_form_invoice, $invoice) { |
|
476 | + if ($is_payment_form_invoice) { |
|
477 | 477 | $is_payment_form_invoice = false; |
478 | 478 | } |
479 | 479 |
@@ -17,402 +17,402 @@ |
||
17 | 17 | */ |
18 | 18 | class GetPaid_Admin_Setup_Wizard { |
19 | 19 | |
20 | - /** |
|
21 | - * @var string Current Step |
|
22 | - */ |
|
23 | - protected $step = ''; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var string|false Previous Step |
|
27 | - */ |
|
28 | - protected $previous_step = ''; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var string|false Next Step |
|
32 | - */ |
|
33 | - protected $next_step = ''; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var array All available steps for the setup wizard |
|
37 | - */ |
|
38 | - protected $steps = array(); |
|
39 | - |
|
40 | - /** |
|
41 | - * Class constructor. |
|
42 | - * |
|
43 | - * @since 2.4.0 |
|
44 | - */ |
|
45 | - public function __construct() { |
|
46 | - |
|
47 | - if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) { |
|
48 | - add_action( 'admin_menu', array( $this, 'add_menu' ) ); |
|
49 | - add_action( 'current_screen', array( $this, 'setup_wizard' ) ); |
|
50 | - add_action( 'admin_init', array( $this, 'remove_deprecated_functions' ) ); |
|
51 | - } |
|
52 | - |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Add admin menus/screens. |
|
57 | - * |
|
58 | - * @since 2.4.0 |
|
59 | - */ |
|
60 | - public function add_menu() { |
|
61 | - add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' ); |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Sets up the setup wizard. |
|
66 | - * |
|
67 | - * @since 2.4.0 |
|
68 | - */ |
|
69 | - public function setup_wizard() { |
|
70 | - |
|
71 | - if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) { |
|
72 | - $this->setup_globals(); |
|
73 | - $this->maybe_save_current_step(); |
|
74 | - $this->display_wizard(); |
|
75 | - exit; |
|
76 | - } |
|
77 | - |
|
78 | - } |
|
79 | - |
|
80 | - public function remove_deprecated_functions() { |
|
81 | - // removes deprecated warnings from page |
|
82 | - remove_action('admin_print_styles', 'print_emoji_styles'); |
|
83 | - remove_action( 'admin_head', 'wp_admin_bar_header' ); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Sets up class variables. |
|
88 | - * |
|
89 | - * @since 2.4.0 |
|
90 | - */ |
|
91 | - protected function setup_globals() { |
|
92 | - $this->steps = $this->get_setup_steps(); |
|
93 | - $this->step = $this->get_current_step(); |
|
94 | - $this->previous_step = $this->get_previous_step(); |
|
95 | - $this->next_step = $this->get_next_step(); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Saves the current step. |
|
100 | - * |
|
101 | - * @since 2.4.0 |
|
102 | - */ |
|
103 | - protected function maybe_save_current_step() { |
|
104 | - if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) { |
|
105 | - call_user_func( $this->steps[ $this->step ]['handler'], $this ); |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Returns the setup steps. |
|
111 | - * |
|
112 | - * @since 2.4.0 |
|
113 | - * @return array |
|
114 | - */ |
|
115 | - protected function get_setup_steps() { |
|
116 | - |
|
117 | - $steps = array( |
|
118 | - |
|
119 | - 'introduction' => array( |
|
120 | - 'name' => __( 'Introduction', 'invoicing' ), |
|
121 | - 'view' => array( $this, 'setup_introduction' ), |
|
122 | - 'handler' => '', |
|
123 | - ), |
|
124 | - |
|
125 | - 'business_details' => array( |
|
126 | - 'name' => __( 'Business Details', 'invoicing' ), |
|
127 | - 'view' => array( $this, 'setup_business' ), |
|
128 | - 'handler' => '', |
|
129 | - ), |
|
130 | - |
|
131 | - 'currency' => array( |
|
132 | - 'name' => __( 'Currency', 'invoicing' ), |
|
133 | - 'view' => array( $this, 'setup_currency' ), |
|
134 | - 'handler' => '', |
|
135 | - ), |
|
136 | - |
|
137 | - 'payments' => array( |
|
138 | - 'name' => __( 'Payment Gateways', 'invoicing' ), |
|
139 | - 'view' => array( $this, 'setup_payments' ), |
|
140 | - 'handler' => array( $this, 'setup_payments_save' ), |
|
141 | - ), |
|
142 | - |
|
143 | - 'recommend' => array( |
|
144 | - 'name' => __( 'Recommend', 'invoicing' ), |
|
145 | - 'view' => array( $this, 'setup_recommend' ), |
|
146 | - 'handler' => '', |
|
147 | - ), |
|
148 | - |
|
149 | - 'next_steps' => array( |
|
150 | - 'name' => __( 'Get Paid', 'invoicing' ), |
|
151 | - 'view' => array( $this, 'setup_ready' ), |
|
152 | - 'handler' => '', |
|
153 | - ), |
|
154 | - |
|
155 | - ); |
|
156 | - |
|
157 | - return apply_filters( 'getpaid_setup_wizard_steps', $steps ); |
|
158 | - |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * Returns the current step. |
|
163 | - * |
|
164 | - * @since 2.4.0 |
|
165 | - * @return string |
|
166 | - */ |
|
167 | - protected function get_current_step() { |
|
168 | - $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : ''; |
|
169 | - return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) ); |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Returns the previous step. |
|
174 | - * |
|
175 | - * @since 2.4.0 |
|
176 | - * @return string|false |
|
177 | - */ |
|
178 | - protected function get_previous_step() { |
|
179 | - |
|
180 | - $previous = false; |
|
181 | - $current = $this->step; |
|
182 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
183 | - if ( $current === $step ) { |
|
184 | - return $previous; |
|
185 | - } |
|
186 | - |
|
187 | - $previous = $step; |
|
188 | - } |
|
189 | - |
|
190 | - return false; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Returns the next step. |
|
195 | - * |
|
196 | - * @since 2.4.0 |
|
197 | - * @return string|false |
|
198 | - */ |
|
199 | - protected function get_next_step() { |
|
200 | - |
|
201 | - $on_current = false; |
|
202 | - $current = $this->step; |
|
203 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
204 | - |
|
205 | - if ( $on_current ) { |
|
206 | - return $step; |
|
207 | - } |
|
208 | - |
|
209 | - if ( $current === $step ) { |
|
210 | - return $on_current = true; |
|
211 | - } |
|
20 | + /** |
|
21 | + * @var string Current Step |
|
22 | + */ |
|
23 | + protected $step = ''; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var string|false Previous Step |
|
27 | + */ |
|
28 | + protected $previous_step = ''; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var string|false Next Step |
|
32 | + */ |
|
33 | + protected $next_step = ''; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var array All available steps for the setup wizard |
|
37 | + */ |
|
38 | + protected $steps = array(); |
|
39 | + |
|
40 | + /** |
|
41 | + * Class constructor. |
|
42 | + * |
|
43 | + * @since 2.4.0 |
|
44 | + */ |
|
45 | + public function __construct() { |
|
46 | + |
|
47 | + if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) { |
|
48 | + add_action( 'admin_menu', array( $this, 'add_menu' ) ); |
|
49 | + add_action( 'current_screen', array( $this, 'setup_wizard' ) ); |
|
50 | + add_action( 'admin_init', array( $this, 'remove_deprecated_functions' ) ); |
|
51 | + } |
|
52 | + |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Add admin menus/screens. |
|
57 | + * |
|
58 | + * @since 2.4.0 |
|
59 | + */ |
|
60 | + public function add_menu() { |
|
61 | + add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' ); |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Sets up the setup wizard. |
|
66 | + * |
|
67 | + * @since 2.4.0 |
|
68 | + */ |
|
69 | + public function setup_wizard() { |
|
70 | + |
|
71 | + if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) { |
|
72 | + $this->setup_globals(); |
|
73 | + $this->maybe_save_current_step(); |
|
74 | + $this->display_wizard(); |
|
75 | + exit; |
|
76 | + } |
|
77 | + |
|
78 | + } |
|
79 | + |
|
80 | + public function remove_deprecated_functions() { |
|
81 | + // removes deprecated warnings from page |
|
82 | + remove_action('admin_print_styles', 'print_emoji_styles'); |
|
83 | + remove_action( 'admin_head', 'wp_admin_bar_header' ); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Sets up class variables. |
|
88 | + * |
|
89 | + * @since 2.4.0 |
|
90 | + */ |
|
91 | + protected function setup_globals() { |
|
92 | + $this->steps = $this->get_setup_steps(); |
|
93 | + $this->step = $this->get_current_step(); |
|
94 | + $this->previous_step = $this->get_previous_step(); |
|
95 | + $this->next_step = $this->get_next_step(); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Saves the current step. |
|
100 | + * |
|
101 | + * @since 2.4.0 |
|
102 | + */ |
|
103 | + protected function maybe_save_current_step() { |
|
104 | + if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) { |
|
105 | + call_user_func( $this->steps[ $this->step ]['handler'], $this ); |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Returns the setup steps. |
|
111 | + * |
|
112 | + * @since 2.4.0 |
|
113 | + * @return array |
|
114 | + */ |
|
115 | + protected function get_setup_steps() { |
|
116 | + |
|
117 | + $steps = array( |
|
118 | + |
|
119 | + 'introduction' => array( |
|
120 | + 'name' => __( 'Introduction', 'invoicing' ), |
|
121 | + 'view' => array( $this, 'setup_introduction' ), |
|
122 | + 'handler' => '', |
|
123 | + ), |
|
124 | + |
|
125 | + 'business_details' => array( |
|
126 | + 'name' => __( 'Business Details', 'invoicing' ), |
|
127 | + 'view' => array( $this, 'setup_business' ), |
|
128 | + 'handler' => '', |
|
129 | + ), |
|
130 | + |
|
131 | + 'currency' => array( |
|
132 | + 'name' => __( 'Currency', 'invoicing' ), |
|
133 | + 'view' => array( $this, 'setup_currency' ), |
|
134 | + 'handler' => '', |
|
135 | + ), |
|
136 | + |
|
137 | + 'payments' => array( |
|
138 | + 'name' => __( 'Payment Gateways', 'invoicing' ), |
|
139 | + 'view' => array( $this, 'setup_payments' ), |
|
140 | + 'handler' => array( $this, 'setup_payments_save' ), |
|
141 | + ), |
|
142 | + |
|
143 | + 'recommend' => array( |
|
144 | + 'name' => __( 'Recommend', 'invoicing' ), |
|
145 | + 'view' => array( $this, 'setup_recommend' ), |
|
146 | + 'handler' => '', |
|
147 | + ), |
|
148 | + |
|
149 | + 'next_steps' => array( |
|
150 | + 'name' => __( 'Get Paid', 'invoicing' ), |
|
151 | + 'view' => array( $this, 'setup_ready' ), |
|
152 | + 'handler' => '', |
|
153 | + ), |
|
154 | + |
|
155 | + ); |
|
156 | + |
|
157 | + return apply_filters( 'getpaid_setup_wizard_steps', $steps ); |
|
158 | + |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * Returns the current step. |
|
163 | + * |
|
164 | + * @since 2.4.0 |
|
165 | + * @return string |
|
166 | + */ |
|
167 | + protected function get_current_step() { |
|
168 | + $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : ''; |
|
169 | + return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) ); |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Returns the previous step. |
|
174 | + * |
|
175 | + * @since 2.4.0 |
|
176 | + * @return string|false |
|
177 | + */ |
|
178 | + protected function get_previous_step() { |
|
179 | + |
|
180 | + $previous = false; |
|
181 | + $current = $this->step; |
|
182 | + foreach ( array_keys( $this->steps ) as $step ) { |
|
183 | + if ( $current === $step ) { |
|
184 | + return $previous; |
|
185 | + } |
|
186 | + |
|
187 | + $previous = $step; |
|
188 | + } |
|
189 | + |
|
190 | + return false; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Returns the next step. |
|
195 | + * |
|
196 | + * @since 2.4.0 |
|
197 | + * @return string|false |
|
198 | + */ |
|
199 | + protected function get_next_step() { |
|
200 | + |
|
201 | + $on_current = false; |
|
202 | + $current = $this->step; |
|
203 | + foreach ( array_keys( $this->steps ) as $step ) { |
|
204 | + |
|
205 | + if ( $on_current ) { |
|
206 | + return $step; |
|
207 | + } |
|
208 | + |
|
209 | + if ( $current === $step ) { |
|
210 | + return $on_current = true; |
|
211 | + } |
|
212 | 212 | } |
213 | 213 | |
214 | - return false; |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * Displays the setup wizard. |
|
219 | - * |
|
220 | - * @since 2.4.0 |
|
221 | - */ |
|
222 | - public function display_wizard() { |
|
223 | - $this->display_header(); |
|
224 | - $this->display_current_step(); |
|
225 | - $this->display_footer(); |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * Displays the Wizard Header. |
|
230 | - * |
|
231 | - * @since 2.0.0 |
|
232 | - */ |
|
233 | - public function display_header() { |
|
234 | - $steps = $this->steps; |
|
235 | - $current = $this->step; |
|
236 | - $next_step = $this->next_step; |
|
237 | - array_shift( $steps ); |
|
238 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php'; |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * Displays the content for the current step. |
|
243 | - * |
|
244 | - * @since 2.4.0 |
|
245 | - */ |
|
246 | - public function display_current_step() { |
|
247 | - ?> |
|
214 | + return false; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * Displays the setup wizard. |
|
219 | + * |
|
220 | + * @since 2.4.0 |
|
221 | + */ |
|
222 | + public function display_wizard() { |
|
223 | + $this->display_header(); |
|
224 | + $this->display_current_step(); |
|
225 | + $this->display_footer(); |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * Displays the Wizard Header. |
|
230 | + * |
|
231 | + * @since 2.0.0 |
|
232 | + */ |
|
233 | + public function display_header() { |
|
234 | + $steps = $this->steps; |
|
235 | + $current = $this->step; |
|
236 | + $next_step = $this->next_step; |
|
237 | + array_shift( $steps ); |
|
238 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php'; |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * Displays the content for the current step. |
|
243 | + * |
|
244 | + * @since 2.4.0 |
|
245 | + */ |
|
246 | + public function display_current_step() { |
|
247 | + ?> |
|
248 | 248 | <div class="gp-setup-content rowx mw-100 text-center mb-3"> |
249 | 249 | <div class="col-12 col-md-5 m-auto"> |
250 | 250 | <?php call_user_func( $this->steps[ $this->step ]['view'], $this ); ?> |
251 | 251 | </div> |
252 | 252 | </div> |
253 | 253 | <?php |
254 | - } |
|
255 | - |
|
256 | - /** |
|
257 | - * Setup Wizard Footer. |
|
258 | - * |
|
259 | - * @since 2.4.0 |
|
260 | - */ |
|
261 | - public function display_footer() { |
|
262 | - |
|
263 | - if ( isset( $_GET['step'] ) ) { |
|
264 | - $label = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' ); |
|
265 | - |
|
266 | - echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . esc_url( $this->get_next_step_link() ) . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . esc_html( $label ) . '</a></p>'; |
|
267 | - } |
|
268 | - |
|
269 | - echo '</body></html>'; |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * Introduction step. |
|
274 | - * |
|
275 | - * @since 2.0.0 |
|
276 | - */ |
|
277 | - public function setup_introduction() { |
|
278 | - $next_url = $this->get_next_step_link(); |
|
279 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php'; |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * Get the URL for the next step's screen. |
|
284 | - * |
|
285 | - * @param string step slug (default: current step) |
|
286 | - * |
|
287 | - * @return string URL for next step if a next step exists. |
|
288 | - * Admin URL if it's the last step. |
|
289 | - * Empty string on failure. |
|
290 | - * @since 3.0.0 |
|
291 | - */ |
|
292 | - public function get_next_step_link( $step = '' ) { |
|
293 | - if ( ! $step ) { |
|
294 | - $step = $this->step; |
|
295 | - } |
|
296 | - |
|
297 | - $keys = array_keys( $this->steps ); |
|
298 | - if ( end( $keys ) === $step ) { |
|
299 | - return admin_url(); |
|
300 | - } |
|
301 | - |
|
302 | - $step_index = array_search( $step, $keys ); |
|
303 | - if ( false === $step_index ) { |
|
304 | - return ''; |
|
305 | - } |
|
306 | - |
|
307 | - return remove_query_arg( 'settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] ) ); |
|
308 | - } |
|
309 | - |
|
310 | - /** |
|
311 | - * Setup maps api. |
|
312 | - * |
|
313 | - * @since 2.0.0 |
|
314 | - */ |
|
315 | - public function setup_business() { |
|
316 | - $next_url = $this->get_next_step_link(); |
|
317 | - $wizard = $this; |
|
318 | - $page = 'wpinv_settings_general_main'; |
|
319 | - $section = 'wpinv_settings_general_main'; |
|
320 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * Default Location settings. |
|
325 | - * |
|
326 | - * @since 2.0.0 |
|
327 | - */ |
|
328 | - public function setup_currency() { |
|
329 | - $next_url = $this->get_next_step_link(); |
|
330 | - $wizard = $this; |
|
331 | - $page = 'wpinv_settings_general_currency_section'; |
|
332 | - $section = 'wpinv_settings_general_currency_section'; |
|
333 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
334 | - } |
|
335 | - |
|
336 | - /** |
|
337 | - * Installation of recommended plugins. |
|
338 | - * |
|
339 | - * @since 1.0.0 |
|
340 | - */ |
|
341 | - public function setup_recommend() { |
|
342 | - $next_url = $this->get_next_step_link(); |
|
343 | - $recommended_plugins = self::get_recommend_wp_plugins(); |
|
344 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php'; |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * A list of recommended wp.org plugins. |
|
349 | - * @return array |
|
350 | - */ |
|
351 | - public static function get_recommend_wp_plugins() { |
|
352 | - return array( |
|
353 | - 'ayecode-connect' => array( |
|
354 | - 'file' => 'ayecode-connect/ayecode-connect.php', |
|
355 | - 'url' => 'https://wordpress.org/plugins/ayecode-connect/', |
|
356 | - 'slug' => 'ayecode-connect', |
|
357 | - 'name' => 'AyeCode Connect', |
|
358 | - 'desc' => __( 'Documentation and Support from within your WordPress admin.', 'invoicing' ), |
|
359 | - ), |
|
360 | - 'invoicing-quotes' => array( |
|
361 | - 'file' => 'invoicing-quotes/wpinv-quote.php', |
|
362 | - 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
|
363 | - 'slug' => 'invoicing-quotes', |
|
364 | - 'name' => 'Customer Quotes', |
|
365 | - 'desc' => __( 'Create & Send Quotes to Customers and have them accept and pay.', 'invoicing' ), |
|
366 | - ), |
|
367 | - 'userswp' => array( |
|
368 | - 'file' => 'userswp/userswp.php', |
|
369 | - 'url' => 'https://wordpress.org/plugins/userswp/', |
|
370 | - 'slug' => 'userswp', |
|
371 | - 'name' => 'UsersWP', |
|
372 | - 'desc' => __( 'Frontend user login and registration as well as slick profile pages.', 'invoicing' ), |
|
373 | - ), |
|
374 | - ); |
|
375 | - } |
|
376 | - |
|
377 | - /** |
|
378 | - * Dummy Data setup. |
|
379 | - * |
|
380 | - * @since 2.4.0 |
|
381 | - */ |
|
382 | - public function setup_payments() { |
|
383 | - $next_url = $this->get_next_step_link(); |
|
384 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php'; |
|
385 | - } |
|
386 | - |
|
387 | - /** |
|
388 | - * Dummy data save. |
|
389 | - * |
|
390 | - * This is done via ajax so we just pass onto the next step. |
|
391 | - * |
|
392 | - * @since 2.0.0 |
|
393 | - */ |
|
394 | - public function setup_payments_save() { |
|
395 | - check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); |
|
396 | - wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) ); |
|
397 | - |
|
398 | - if ( ! empty( $_POST['paypal-email'] ) ) { |
|
399 | - wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) ); |
|
400 | - wpinv_update_option( 'paypal_active', 1 ); |
|
401 | - wpinv_update_option( 'paypal_sandbox', 0 ); |
|
402 | - } |
|
403 | - |
|
404 | - wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
|
405 | - exit; |
|
406 | - } |
|
407 | - |
|
408 | - /** |
|
409 | - * Final step. |
|
410 | - * |
|
411 | - * @since 2.0.0 |
|
412 | - */ |
|
413 | - public function setup_ready() { |
|
414 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php'; |
|
415 | - } |
|
254 | + } |
|
255 | + |
|
256 | + /** |
|
257 | + * Setup Wizard Footer. |
|
258 | + * |
|
259 | + * @since 2.4.0 |
|
260 | + */ |
|
261 | + public function display_footer() { |
|
262 | + |
|
263 | + if ( isset( $_GET['step'] ) ) { |
|
264 | + $label = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' ); |
|
265 | + |
|
266 | + echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . esc_url( $this->get_next_step_link() ) . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . esc_html( $label ) . '</a></p>'; |
|
267 | + } |
|
268 | + |
|
269 | + echo '</body></html>'; |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * Introduction step. |
|
274 | + * |
|
275 | + * @since 2.0.0 |
|
276 | + */ |
|
277 | + public function setup_introduction() { |
|
278 | + $next_url = $this->get_next_step_link(); |
|
279 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php'; |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * Get the URL for the next step's screen. |
|
284 | + * |
|
285 | + * @param string step slug (default: current step) |
|
286 | + * |
|
287 | + * @return string URL for next step if a next step exists. |
|
288 | + * Admin URL if it's the last step. |
|
289 | + * Empty string on failure. |
|
290 | + * @since 3.0.0 |
|
291 | + */ |
|
292 | + public function get_next_step_link( $step = '' ) { |
|
293 | + if ( ! $step ) { |
|
294 | + $step = $this->step; |
|
295 | + } |
|
296 | + |
|
297 | + $keys = array_keys( $this->steps ); |
|
298 | + if ( end( $keys ) === $step ) { |
|
299 | + return admin_url(); |
|
300 | + } |
|
301 | + |
|
302 | + $step_index = array_search( $step, $keys ); |
|
303 | + if ( false === $step_index ) { |
|
304 | + return ''; |
|
305 | + } |
|
306 | + |
|
307 | + return remove_query_arg( 'settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] ) ); |
|
308 | + } |
|
309 | + |
|
310 | + /** |
|
311 | + * Setup maps api. |
|
312 | + * |
|
313 | + * @since 2.0.0 |
|
314 | + */ |
|
315 | + public function setup_business() { |
|
316 | + $next_url = $this->get_next_step_link(); |
|
317 | + $wizard = $this; |
|
318 | + $page = 'wpinv_settings_general_main'; |
|
319 | + $section = 'wpinv_settings_general_main'; |
|
320 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * Default Location settings. |
|
325 | + * |
|
326 | + * @since 2.0.0 |
|
327 | + */ |
|
328 | + public function setup_currency() { |
|
329 | + $next_url = $this->get_next_step_link(); |
|
330 | + $wizard = $this; |
|
331 | + $page = 'wpinv_settings_general_currency_section'; |
|
332 | + $section = 'wpinv_settings_general_currency_section'; |
|
333 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
334 | + } |
|
335 | + |
|
336 | + /** |
|
337 | + * Installation of recommended plugins. |
|
338 | + * |
|
339 | + * @since 1.0.0 |
|
340 | + */ |
|
341 | + public function setup_recommend() { |
|
342 | + $next_url = $this->get_next_step_link(); |
|
343 | + $recommended_plugins = self::get_recommend_wp_plugins(); |
|
344 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php'; |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * A list of recommended wp.org plugins. |
|
349 | + * @return array |
|
350 | + */ |
|
351 | + public static function get_recommend_wp_plugins() { |
|
352 | + return array( |
|
353 | + 'ayecode-connect' => array( |
|
354 | + 'file' => 'ayecode-connect/ayecode-connect.php', |
|
355 | + 'url' => 'https://wordpress.org/plugins/ayecode-connect/', |
|
356 | + 'slug' => 'ayecode-connect', |
|
357 | + 'name' => 'AyeCode Connect', |
|
358 | + 'desc' => __( 'Documentation and Support from within your WordPress admin.', 'invoicing' ), |
|
359 | + ), |
|
360 | + 'invoicing-quotes' => array( |
|
361 | + 'file' => 'invoicing-quotes/wpinv-quote.php', |
|
362 | + 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
|
363 | + 'slug' => 'invoicing-quotes', |
|
364 | + 'name' => 'Customer Quotes', |
|
365 | + 'desc' => __( 'Create & Send Quotes to Customers and have them accept and pay.', 'invoicing' ), |
|
366 | + ), |
|
367 | + 'userswp' => array( |
|
368 | + 'file' => 'userswp/userswp.php', |
|
369 | + 'url' => 'https://wordpress.org/plugins/userswp/', |
|
370 | + 'slug' => 'userswp', |
|
371 | + 'name' => 'UsersWP', |
|
372 | + 'desc' => __( 'Frontend user login and registration as well as slick profile pages.', 'invoicing' ), |
|
373 | + ), |
|
374 | + ); |
|
375 | + } |
|
376 | + |
|
377 | + /** |
|
378 | + * Dummy Data setup. |
|
379 | + * |
|
380 | + * @since 2.4.0 |
|
381 | + */ |
|
382 | + public function setup_payments() { |
|
383 | + $next_url = $this->get_next_step_link(); |
|
384 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php'; |
|
385 | + } |
|
386 | + |
|
387 | + /** |
|
388 | + * Dummy data save. |
|
389 | + * |
|
390 | + * This is done via ajax so we just pass onto the next step. |
|
391 | + * |
|
392 | + * @since 2.0.0 |
|
393 | + */ |
|
394 | + public function setup_payments_save() { |
|
395 | + check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); |
|
396 | + wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) ); |
|
397 | + |
|
398 | + if ( ! empty( $_POST['paypal-email'] ) ) { |
|
399 | + wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) ); |
|
400 | + wpinv_update_option( 'paypal_active', 1 ); |
|
401 | + wpinv_update_option( 'paypal_sandbox', 0 ); |
|
402 | + } |
|
403 | + |
|
404 | + wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
|
405 | + exit; |
|
406 | + } |
|
407 | + |
|
408 | + /** |
|
409 | + * Final step. |
|
410 | + * |
|
411 | + * @since 2.0.0 |
|
412 | + */ |
|
413 | + public function setup_ready() { |
|
414 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php'; |
|
415 | + } |
|
416 | 416 | |
417 | 417 | } |
418 | 418 |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @version 2.4.0 |
11 | 11 | * @info GetPaid Setup Wizard. |
12 | 12 | */ |
13 | -defined( 'ABSPATH' ) || exit; |
|
13 | +defined('ABSPATH') || exit; |
|
14 | 14 | |
15 | 15 | /** |
16 | 16 | * GetPaid_Admin_Setup_Wizard class. |
@@ -44,10 +44,10 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public function __construct() { |
46 | 46 | |
47 | - if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) { |
|
48 | - add_action( 'admin_menu', array( $this, 'add_menu' ) ); |
|
49 | - add_action( 'current_screen', array( $this, 'setup_wizard' ) ); |
|
50 | - add_action( 'admin_init', array( $this, 'remove_deprecated_functions' ) ); |
|
47 | + if (apply_filters('getpaid_enable_setup_wizard', true) && wpinv_current_user_can_manage_invoicing()) { |
|
48 | + add_action('admin_menu', array($this, 'add_menu')); |
|
49 | + add_action('current_screen', array($this, 'setup_wizard')); |
|
50 | + add_action('admin_init', array($this, 'remove_deprecated_functions')); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @since 2.4.0 |
59 | 59 | */ |
60 | 60 | public function add_menu() { |
61 | - add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' ); |
|
61 | + add_dashboard_page('', '', wpinv_get_capability(), 'gp-setup', ''); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function setup_wizard() { |
70 | 70 | |
71 | - if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) { |
|
71 | + if (isset($_GET['page']) && 'gp-setup' === $_GET['page']) { |
|
72 | 72 | $this->setup_globals(); |
73 | 73 | $this->maybe_save_current_step(); |
74 | 74 | $this->display_wizard(); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | public function remove_deprecated_functions() { |
81 | 81 | // removes deprecated warnings from page |
82 | 82 | remove_action('admin_print_styles', 'print_emoji_styles'); |
83 | - remove_action( 'admin_head', 'wp_admin_bar_header' ); |
|
83 | + remove_action('admin_head', 'wp_admin_bar_header'); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | * @since 2.4.0 |
102 | 102 | */ |
103 | 103 | protected function maybe_save_current_step() { |
104 | - if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) { |
|
105 | - call_user_func( $this->steps[ $this->step ]['handler'], $this ); |
|
104 | + if (!empty($_POST['save_step']) && is_callable($this->steps[$this->step]['handler'])) { |
|
105 | + call_user_func($this->steps[$this->step]['handler'], $this); |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | |
@@ -117,44 +117,44 @@ discard block |
||
117 | 117 | $steps = array( |
118 | 118 | |
119 | 119 | 'introduction' => array( |
120 | - 'name' => __( 'Introduction', 'invoicing' ), |
|
121 | - 'view' => array( $this, 'setup_introduction' ), |
|
120 | + 'name' => __('Introduction', 'invoicing'), |
|
121 | + 'view' => array($this, 'setup_introduction'), |
|
122 | 122 | 'handler' => '', |
123 | 123 | ), |
124 | 124 | |
125 | 125 | 'business_details' => array( |
126 | - 'name' => __( 'Business Details', 'invoicing' ), |
|
127 | - 'view' => array( $this, 'setup_business' ), |
|
126 | + 'name' => __('Business Details', 'invoicing'), |
|
127 | + 'view' => array($this, 'setup_business'), |
|
128 | 128 | 'handler' => '', |
129 | 129 | ), |
130 | 130 | |
131 | 131 | 'currency' => array( |
132 | - 'name' => __( 'Currency', 'invoicing' ), |
|
133 | - 'view' => array( $this, 'setup_currency' ), |
|
132 | + 'name' => __('Currency', 'invoicing'), |
|
133 | + 'view' => array($this, 'setup_currency'), |
|
134 | 134 | 'handler' => '', |
135 | 135 | ), |
136 | 136 | |
137 | 137 | 'payments' => array( |
138 | - 'name' => __( 'Payment Gateways', 'invoicing' ), |
|
139 | - 'view' => array( $this, 'setup_payments' ), |
|
140 | - 'handler' => array( $this, 'setup_payments_save' ), |
|
138 | + 'name' => __('Payment Gateways', 'invoicing'), |
|
139 | + 'view' => array($this, 'setup_payments'), |
|
140 | + 'handler' => array($this, 'setup_payments_save'), |
|
141 | 141 | ), |
142 | 142 | |
143 | 143 | 'recommend' => array( |
144 | - 'name' => __( 'Recommend', 'invoicing' ), |
|
145 | - 'view' => array( $this, 'setup_recommend' ), |
|
144 | + 'name' => __('Recommend', 'invoicing'), |
|
145 | + 'view' => array($this, 'setup_recommend'), |
|
146 | 146 | 'handler' => '', |
147 | 147 | ), |
148 | 148 | |
149 | 149 | 'next_steps' => array( |
150 | - 'name' => __( 'Get Paid', 'invoicing' ), |
|
151 | - 'view' => array( $this, 'setup_ready' ), |
|
150 | + 'name' => __('Get Paid', 'invoicing'), |
|
151 | + 'view' => array($this, 'setup_ready'), |
|
152 | 152 | 'handler' => '', |
153 | 153 | ), |
154 | 154 | |
155 | 155 | ); |
156 | 156 | |
157 | - return apply_filters( 'getpaid_setup_wizard_steps', $steps ); |
|
157 | + return apply_filters('getpaid_setup_wizard_steps', $steps); |
|
158 | 158 | |
159 | 159 | } |
160 | 160 | |
@@ -165,8 +165,8 @@ discard block |
||
165 | 165 | * @return string |
166 | 166 | */ |
167 | 167 | protected function get_current_step() { |
168 | - $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : ''; |
|
169 | - return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) ); |
|
168 | + $step = isset($_GET['step']) ? sanitize_key($_GET['step']) : ''; |
|
169 | + return !empty($step) && in_array($step, array_keys($this->steps)) ? $step : current(array_keys($this->steps)); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
@@ -179,8 +179,8 @@ discard block |
||
179 | 179 | |
180 | 180 | $previous = false; |
181 | 181 | $current = $this->step; |
182 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
183 | - if ( $current === $step ) { |
|
182 | + foreach (array_keys($this->steps) as $step) { |
|
183 | + if ($current === $step) { |
|
184 | 184 | return $previous; |
185 | 185 | } |
186 | 186 | |
@@ -200,13 +200,13 @@ discard block |
||
200 | 200 | |
201 | 201 | $on_current = false; |
202 | 202 | $current = $this->step; |
203 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
203 | + foreach (array_keys($this->steps) as $step) { |
|
204 | 204 | |
205 | - if ( $on_current ) { |
|
205 | + if ($on_current) { |
|
206 | 206 | return $step; |
207 | 207 | } |
208 | 208 | |
209 | - if ( $current === $step ) { |
|
209 | + if ($current === $step) { |
|
210 | 210 | return $on_current = true; |
211 | 211 | } |
212 | 212 | } |
@@ -234,8 +234,8 @@ discard block |
||
234 | 234 | $steps = $this->steps; |
235 | 235 | $current = $this->step; |
236 | 236 | $next_step = $this->next_step; |
237 | - array_shift( $steps ); |
|
238 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php'; |
|
237 | + array_shift($steps); |
|
238 | + include plugin_dir_path(__FILE__) . 'views/wizard-header.php'; |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | /** |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | ?> |
248 | 248 | <div class="gp-setup-content rowx mw-100 text-center mb-3"> |
249 | 249 | <div class="col-12 col-md-5 m-auto"> |
250 | - <?php call_user_func( $this->steps[ $this->step ]['view'], $this ); ?> |
|
250 | + <?php call_user_func($this->steps[$this->step]['view'], $this); ?> |
|
251 | 251 | </div> |
252 | 252 | </div> |
253 | 253 | <?php |
@@ -260,10 +260,10 @@ discard block |
||
260 | 260 | */ |
261 | 261 | public function display_footer() { |
262 | 262 | |
263 | - if ( isset( $_GET['step'] ) ) { |
|
264 | - $label = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' ); |
|
263 | + if (isset($_GET['step'])) { |
|
264 | + $label = $this->step == 'next_steps' ? __('Return to the WordPress Dashboard', 'invoicing') : __('Skip this step', 'invoicing'); |
|
265 | 265 | |
266 | - echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . esc_url( $this->get_next_step_link() ) . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . esc_html( $label ) . '</a></p>'; |
|
266 | + echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . esc_url($this->get_next_step_link()) . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . esc_html($label) . '</a></p>'; |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | echo '</body></html>'; |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | */ |
277 | 277 | public function setup_introduction() { |
278 | 278 | $next_url = $this->get_next_step_link(); |
279 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php'; |
|
279 | + include plugin_dir_path(__FILE__) . 'views/wizard-introduction.php'; |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | /** |
@@ -289,22 +289,22 @@ discard block |
||
289 | 289 | * Empty string on failure. |
290 | 290 | * @since 3.0.0 |
291 | 291 | */ |
292 | - public function get_next_step_link( $step = '' ) { |
|
293 | - if ( ! $step ) { |
|
292 | + public function get_next_step_link($step = '') { |
|
293 | + if (!$step) { |
|
294 | 294 | $step = $this->step; |
295 | 295 | } |
296 | 296 | |
297 | - $keys = array_keys( $this->steps ); |
|
298 | - if ( end( $keys ) === $step ) { |
|
297 | + $keys = array_keys($this->steps); |
|
298 | + if (end($keys) === $step) { |
|
299 | 299 | return admin_url(); |
300 | 300 | } |
301 | 301 | |
302 | - $step_index = array_search( $step, $keys ); |
|
303 | - if ( false === $step_index ) { |
|
302 | + $step_index = array_search($step, $keys); |
|
303 | + if (false === $step_index) { |
|
304 | 304 | return ''; |
305 | 305 | } |
306 | 306 | |
307 | - return remove_query_arg( 'settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] ) ); |
|
307 | + return remove_query_arg('settings-updated', add_query_arg('step', $keys[$step_index + 1])); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | $wizard = $this; |
318 | 318 | $page = 'wpinv_settings_general_main'; |
319 | 319 | $section = 'wpinv_settings_general_main'; |
320 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
320 | + include plugin_dir_path(__FILE__) . 'views/wizard-settings.php'; |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | /** |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | $wizard = $this; |
331 | 331 | $page = 'wpinv_settings_general_currency_section'; |
332 | 332 | $section = 'wpinv_settings_general_currency_section'; |
333 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
333 | + include plugin_dir_path(__FILE__) . 'views/wizard-settings.php'; |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | public function setup_recommend() { |
342 | 342 | $next_url = $this->get_next_step_link(); |
343 | 343 | $recommended_plugins = self::get_recommend_wp_plugins(); |
344 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php'; |
|
344 | + include plugin_dir_path(__FILE__) . 'views/wizard-plugins.php'; |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | /** |
@@ -355,21 +355,21 @@ discard block |
||
355 | 355 | 'url' => 'https://wordpress.org/plugins/ayecode-connect/', |
356 | 356 | 'slug' => 'ayecode-connect', |
357 | 357 | 'name' => 'AyeCode Connect', |
358 | - 'desc' => __( 'Documentation and Support from within your WordPress admin.', 'invoicing' ), |
|
358 | + 'desc' => __('Documentation and Support from within your WordPress admin.', 'invoicing'), |
|
359 | 359 | ), |
360 | 360 | 'invoicing-quotes' => array( |
361 | 361 | 'file' => 'invoicing-quotes/wpinv-quote.php', |
362 | 362 | 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
363 | 363 | 'slug' => 'invoicing-quotes', |
364 | 364 | 'name' => 'Customer Quotes', |
365 | - 'desc' => __( 'Create & Send Quotes to Customers and have them accept and pay.', 'invoicing' ), |
|
365 | + 'desc' => __('Create & Send Quotes to Customers and have them accept and pay.', 'invoicing'), |
|
366 | 366 | ), |
367 | 367 | 'userswp' => array( |
368 | 368 | 'file' => 'userswp/userswp.php', |
369 | 369 | 'url' => 'https://wordpress.org/plugins/userswp/', |
370 | 370 | 'slug' => 'userswp', |
371 | 371 | 'name' => 'UsersWP', |
372 | - 'desc' => __( 'Frontend user login and registration as well as slick profile pages.', 'invoicing' ), |
|
372 | + 'desc' => __('Frontend user login and registration as well as slick profile pages.', 'invoicing'), |
|
373 | 373 | ), |
374 | 374 | ); |
375 | 375 | } |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | */ |
382 | 382 | public function setup_payments() { |
383 | 383 | $next_url = $this->get_next_step_link(); |
384 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php'; |
|
384 | + include plugin_dir_path(__FILE__) . 'views/wizard-gateways.php'; |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | /** |
@@ -392,16 +392,16 @@ discard block |
||
392 | 392 | * @since 2.0.0 |
393 | 393 | */ |
394 | 394 | public function setup_payments_save() { |
395 | - check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); |
|
396 | - wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) ); |
|
395 | + check_admin_referer('getpaid-setup-wizard', 'getpaid-setup-wizard'); |
|
396 | + wpinv_update_option('manual_active', !empty($_POST['enable-manual-gateway'])); |
|
397 | 397 | |
398 | - if ( ! empty( $_POST['paypal-email'] ) ) { |
|
399 | - wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) ); |
|
400 | - wpinv_update_option( 'paypal_active', 1 ); |
|
401 | - wpinv_update_option( 'paypal_sandbox', 0 ); |
|
398 | + if (!empty($_POST['paypal-email'])) { |
|
399 | + wpinv_update_option('paypal_email', sanitize_email($_POST['paypal-email'])); |
|
400 | + wpinv_update_option('paypal_active', 1); |
|
401 | + wpinv_update_option('paypal_sandbox', 0); |
|
402 | 402 | } |
403 | 403 | |
404 | - wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
|
404 | + wp_redirect(esc_url_raw($this->get_next_step_link())); |
|
405 | 405 | exit; |
406 | 406 | } |
407 | 407 | |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | * @since 2.0.0 |
412 | 412 | */ |
413 | 413 | public function setup_ready() { |
414 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php'; |
|
414 | + include plugin_dir_path(__FILE__) . 'views/wizard-thank-you.php'; |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | } |