@@ -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_key' ) : wpinv_get_option( 'paypal_sandbox_secret_key' ); |
|
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_key') : wpinv_get_option('paypal_sandbox_secret_key'); |
|
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,25 +75,25 @@ 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( |
90 | 90 | 'Authorization' => 'Bearer ' . $access_token, |
91 | 91 | 'Content-Type' => 'application/json', |
92 | 92 | ), |
93 | - 'body' => wp_json_encode( $data ), |
|
93 | + 'body' => wp_json_encode($data), |
|
94 | 94 | ); |
95 | 95 | |
96 | - return self::response_or_error( wp_remote_post( $url, $args ) ); |
|
96 | + return self::response_or_error(wp_remote_post($url, $args)); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -103,15 +103,15 @@ discard block |
||
103 | 103 | * @param string $method |
104 | 104 | * @return object|\WP_Error |
105 | 105 | */ |
106 | - public static function get( $path, $mode = 'live', $method = 'GET' ) { |
|
106 | + public static function get($path, $mode = 'live', $method = 'GET') { |
|
107 | 107 | |
108 | - $access_token = self::get_token( $mode ); |
|
108 | + $access_token = self::get_token($mode); |
|
109 | 109 | |
110 | - if ( is_wp_error( $access_token ) ) { |
|
110 | + if (is_wp_error($access_token)) { |
|
111 | 111 | return $access_token; |
112 | 112 | } |
113 | 113 | |
114 | - $url = self::get_api_url( $path, $mode ); |
|
114 | + $url = self::get_api_url($path, $mode); |
|
115 | 115 | $args = array( |
116 | 116 | 'method' => $method, |
117 | 117 | 'headers' => array( |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | ), |
120 | 120 | ); |
121 | 121 | |
122 | - return self::response_or_error( wp_remote_get( $url, $args ) ); |
|
122 | + return self::response_or_error(wp_remote_get($url, $args)); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -130,33 +130,33 @@ discard block |
||
130 | 130 | * @param \WP_Error|array $response |
131 | 131 | * @return \WP_Error|object |
132 | 132 | */ |
133 | - public static function response_or_error( $response ) { |
|
133 | + public static function response_or_error($response) { |
|
134 | 134 | |
135 | - if ( is_wp_error( $response ) ) { |
|
136 | - return new \WP_Error( 'paypal_error', __( 'There was a problem connecting to the PayPal API endpoint.', 'invoicing' ) ); |
|
135 | + if (is_wp_error($response)) { |
|
136 | + return new \WP_Error('paypal_error', __('There was a problem connecting to the PayPal API endpoint.', 'invoicing')); |
|
137 | 137 | } |
138 | 138 | |
139 | - if ( empty( $response['body'] ) ) { |
|
139 | + if (empty($response['body'])) { |
|
140 | 140 | return true; |
141 | 141 | } |
142 | 142 | |
143 | - $response_body = json_decode( wp_remote_retrieve_body( $response ) ); |
|
143 | + $response_body = json_decode(wp_remote_retrieve_body($response)); |
|
144 | 144 | |
145 | - if ( wp_remote_retrieve_response_code( $response ) > 299 ) { |
|
145 | + if (wp_remote_retrieve_response_code($response) > 299) { |
|
146 | 146 | |
147 | 147 | // Normal errors. |
148 | - if ( $response_body && isset( $response_body->message ) ) { |
|
148 | + if ($response_body && isset($response_body->message)) { |
|
149 | 149 | $error_message = $response_body->message; |
150 | 150 | |
151 | 151 | // Identity errors. |
152 | - } elseif ( $response_body && isset( $response_body->error_description ) ) { |
|
152 | + } elseif ($response_body && isset($response_body->error_description)) { |
|
153 | 153 | $error_message = $response_body->error_description; |
154 | - return new \WP_Error( 'paypal_error', wp_kses_post( $response_body->error_description ) ); |
|
154 | + return new \WP_Error('paypal_error', wp_kses_post($response_body->error_description)); |
|
155 | 155 | } else { |
156 | - $error_message = __( 'There was an error connecting to the PayPal API endpoint.', 'invoicing' ); |
|
156 | + $error_message = __('There was an error connecting to the PayPal API endpoint.', 'invoicing'); |
|
157 | 157 | } |
158 | 158 | |
159 | - return new \WP_Error( 'paypal_error', $error_message ); |
|
159 | + return new \WP_Error('paypal_error', $error_message); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | return $response_body; |
@@ -171,8 +171,8 @@ discard block |
||
171 | 171 | * @link https://developer.paypal.com/docs/api/orders/v2/#orders_get |
172 | 172 | * @return \WP_Error|object |
173 | 173 | */ |
174 | - public static function get_order( $order_id, $mode = 'live' ) { |
|
175 | - return self::get( '/v2/checkout/orders/' . $order_id, $mode ); |
|
174 | + public static function get_order($order_id, $mode = 'live') { |
|
175 | + return self::get('/v2/checkout/orders/' . $order_id, $mode); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get |
185 | 185 | * @return \WP_Error|object |
186 | 186 | */ |
187 | - public static function get_subscription( $subscription_id, $mode = 'live' ) { |
|
188 | - return self::get( '/v1/billing/subscriptions/' . $subscription_id, $mode ); |
|
187 | + public static function get_subscription($subscription_id, $mode = 'live') { |
|
188 | + return self::get('/v1/billing/subscriptions/' . $subscription_id, $mode); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
@@ -197,10 +197,10 @@ discard block |
||
197 | 197 | * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_transactions |
198 | 198 | * @return \WP_Error|object |
199 | 199 | */ |
200 | - public static function get_subscription_transaction( $subscription_id, $mode = 'live' ) { |
|
201 | - $start_time = gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '-1 day' ) ); |
|
202 | - $end_time = gmdate( 'Y-m-d\TH:i:s\Z' ); |
|
203 | - return self::get( "/v1/billing/subscriptions/$subscription_id/transactions?start_time=$start_time&end_time=$end_time", $mode ); |
|
200 | + public static function get_subscription_transaction($subscription_id, $mode = 'live') { |
|
201 | + $start_time = gmdate('Y-m-d\TH:i:s\Z', strtotime('-1 day')); |
|
202 | + $end_time = gmdate('Y-m-d\TH:i:s\Z'); |
|
203 | + return self::get("/v1/billing/subscriptions/$subscription_id/transactions?start_time=$start_time&end_time=$end_time", $mode); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -213,8 +213,8 @@ discard block |
||
213 | 213 | * @link https://developer.paypal.com/docs/api/payments/v2/#captures_refund |
214 | 214 | * @return \WP_Error|object |
215 | 215 | */ |
216 | - public static function refund_capture( $capture_id, $args = array(), $mode = 'live' ) { |
|
217 | - return self::post( '/v2/payments/captures/' . $capture_id . '/refund', $args, $mode ); |
|
216 | + public static function refund_capture($capture_id, $args = array(), $mode = 'live') { |
|
217 | + return self::post('/v2/payments/captures/' . $capture_id . '/refund', $args, $mode); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | } |
@@ -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' ); |
|
27 | + protected $supports = array('subscription', 'sandbox', 'single_subscription_group'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @var array |
61 | 61 | */ |
62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
62 | + public $currencies = array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR'); |
|
63 | 63 | |
64 | 64 | /** |
65 | 65 | * URL to view a transaction. |
@@ -80,17 +80,17 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function __construct() { |
82 | 82 | |
83 | - $this->title = __( 'PayPal Standard', 'invoicing' ); |
|
84 | - $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
|
85 | - $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
|
86 | - $this->notify_url = wpinv_get_ipn_url( $this->id ); |
|
87 | - |
|
88 | - add_filter( 'wpinv_subscription_cancel_url', array( $this, 'filter_cancel_subscription_url' ), 10, 2 ); |
|
89 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
90 | - add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
|
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' ) ); |
|
83 | + $this->title = __('PayPal Standard', 'invoicing'); |
|
84 | + $this->method_title = __('PayPal Standard', 'invoicing'); |
|
85 | + $this->checkout_button_text = __('Proceed to PayPal', 'invoicing'); |
|
86 | + $this->notify_url = wpinv_get_ipn_url($this->id); |
|
87 | + |
|
88 | + add_filter('wpinv_subscription_cancel_url', array($this, 'filter_cancel_subscription_url'), 10, 2); |
|
89 | + add_filter('getpaid_paypal_args', array($this, 'process_subscription'), 10, 2); |
|
90 | + add_filter('getpaid_paypal_sandbox_notice', array($this, 'sandbox_notice')); |
|
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 | 94 | parent::__construct(); |
95 | 95 | } |
96 | 96 | |
@@ -103,16 +103,16 @@ discard block |
||
103 | 103 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
104 | 104 | * @return array |
105 | 105 | */ |
106 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
106 | + public function process_payment($invoice, $submission_data, $submission) { |
|
107 | 107 | |
108 | 108 | // Get redirect url. |
109 | - $paypal_redirect = $this->get_request_url( $invoice ); |
|
109 | + $paypal_redirect = $this->get_request_url($invoice); |
|
110 | 110 | |
111 | 111 | // Add a note about the request url. |
112 | 112 | $invoice->add_note( |
113 | 113 | sprintf( |
114 | - __( 'Redirecting to PayPal: %s', 'invoicing' ), |
|
115 | - esc_url( $paypal_redirect ) |
|
114 | + __('Redirecting to PayPal: %s', 'invoicing'), |
|
115 | + esc_url($paypal_redirect) |
|
116 | 116 | ), |
117 | 117 | false, |
118 | 118 | false, |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | ); |
121 | 121 | |
122 | 122 | // Redirect to PayPal |
123 | - wp_redirect( $paypal_redirect ); |
|
123 | + wp_redirect($paypal_redirect); |
|
124 | 124 | exit; |
125 | 125 | |
126 | 126 | } |
@@ -131,21 +131,21 @@ discard block |
||
131 | 131 | * @param WPInv_Invoice $invoice Invoice object. |
132 | 132 | * @return string |
133 | 133 | */ |
134 | - public function get_request_url( $invoice ) { |
|
134 | + public function get_request_url($invoice) { |
|
135 | 135 | |
136 | 136 | // Endpoint for this request |
137 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
137 | + $this->endpoint = $this->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
138 | 138 | |
139 | 139 | // Retrieve paypal args. |
140 | - $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
|
140 | + $paypal_args = map_deep($this->get_paypal_args($invoice), 'urlencode'); |
|
141 | 141 | |
142 | - if ( $invoice->is_recurring() ) { |
|
142 | + if ($invoice->is_recurring()) { |
|
143 | 143 | $paypal_args['bn'] = 'GetPaid_Subscribe_WPS_US'; |
144 | 144 | } else { |
145 | 145 | $paypal_args['bn'] = 'GetPaid_ShoppingCart_WPS_US'; |
146 | 146 | } |
147 | 147 | |
148 | - return add_query_arg( $paypal_args, $this->endpoint ); |
|
148 | + return add_query_arg($paypal_args, $this->endpoint); |
|
149 | 149 | |
150 | 150 | } |
151 | 151 | |
@@ -155,25 +155,25 @@ discard block |
||
155 | 155 | * @param WPInv_Invoice $invoice Invoice object. |
156 | 156 | * @return array |
157 | 157 | */ |
158 | - protected function get_paypal_args( $invoice ) { |
|
158 | + protected function get_paypal_args($invoice) { |
|
159 | 159 | |
160 | 160 | // Whether or not to send the line items as one item. |
161 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
161 | + $force_one_line_item = apply_filters('getpaid_paypal_force_one_line_item', true, $invoice); |
|
162 | 162 | |
163 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
163 | + if ($invoice->is_recurring() || (wpinv_use_taxes() && wpinv_prices_include_tax())) { |
|
164 | 164 | $force_one_line_item = true; |
165 | 165 | } |
166 | 166 | |
167 | 167 | $paypal_args = apply_filters( |
168 | 168 | 'getpaid_paypal_args', |
169 | 169 | array_merge( |
170 | - $this->get_transaction_args( $invoice ), |
|
171 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
170 | + $this->get_transaction_args($invoice), |
|
171 | + $this->get_line_item_args($invoice, $force_one_line_item) |
|
172 | 172 | ), |
173 | 173 | $invoice |
174 | 174 | ); |
175 | 175 | |
176 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
176 | + return $this->fix_request_length($invoice, $paypal_args); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
@@ -182,9 +182,9 @@ discard block |
||
182 | 182 | * @param WPInv_Invoice $invoice Invoice object. |
183 | 183 | * @return array |
184 | 184 | */ |
185 | - protected function get_transaction_args( $invoice ) { |
|
185 | + protected function get_transaction_args($invoice) { |
|
186 | 186 | |
187 | - $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
187 | + $email = $this->is_sandbox($invoice) ? wpinv_get_option('paypal_sandbox_email', wpinv_get_option('paypal_email', '')) : wpinv_get_option('paypal_email', ''); |
|
188 | 188 | return array( |
189 | 189 | 'cmd' => '_cart', |
190 | 190 | 'business' => $email, |
@@ -195,16 +195,16 @@ discard block |
||
195 | 195 | 'rm' => is_ssl() ? 2 : 1, |
196 | 196 | 'upload' => 1, |
197 | 197 | 'currency_code' => $invoice->get_currency(), // https://developer.paypal.com/docs/nvp-soap-api/currency-codes/#paypal |
198 | - 'return' => esc_url_raw( $this->get_return_url( $invoice ) ), |
|
199 | - 'cancel_return' => esc_url_raw( $invoice->get_checkout_payment_url() ), |
|
200 | - 'notify_url' => getpaid_limit_length( $this->notify_url, 255 ), |
|
201 | - 'invoice' => getpaid_limit_length( $invoice->get_number(), 127 ), |
|
198 | + 'return' => esc_url_raw($this->get_return_url($invoice)), |
|
199 | + 'cancel_return' => esc_url_raw($invoice->get_checkout_payment_url()), |
|
200 | + 'notify_url' => getpaid_limit_length($this->notify_url, 255), |
|
201 | + 'invoice' => getpaid_limit_length($invoice->get_number(), 127), |
|
202 | 202 | 'custom' => $invoice->get_id(), |
203 | - 'first_name' => getpaid_limit_length( $invoice->get_first_name(), 32 ), |
|
204 | - 'last_name' => getpaid_limit_length( $invoice->get_last_name(), 64 ), |
|
205 | - 'country' => getpaid_limit_length( $invoice->get_country(), 2 ), |
|
206 | - 'email' => getpaid_limit_length( $invoice->get_email(), 127 ), |
|
207 | - 'cbt' => get_bloginfo( 'name' ), |
|
203 | + 'first_name' => getpaid_limit_length($invoice->get_first_name(), 32), |
|
204 | + 'last_name' => getpaid_limit_length($invoice->get_last_name(), 64), |
|
205 | + 'country' => getpaid_limit_length($invoice->get_country(), 2), |
|
206 | + 'email' => getpaid_limit_length($invoice->get_email(), 127), |
|
207 | + 'cbt' => get_bloginfo('name'), |
|
208 | 208 | ); |
209 | 209 | |
210 | 210 | } |
@@ -216,30 +216,30 @@ discard block |
||
216 | 216 | * @param bool $force_one_line_item Create only one item for this invoice. |
217 | 217 | * @return array |
218 | 218 | */ |
219 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
219 | + protected function get_line_item_args($invoice, $force_one_line_item = false) { |
|
220 | 220 | |
221 | 221 | // Maybe send invoice as a single item. |
222 | - if ( $force_one_line_item ) { |
|
223 | - return $this->get_line_item_args_single_item( $invoice ); |
|
222 | + if ($force_one_line_item) { |
|
223 | + return $this->get_line_item_args_single_item($invoice); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | // Send each line item individually. |
227 | 227 | $line_item_args = array(); |
228 | 228 | |
229 | 229 | // Prepare line items. |
230 | - $this->prepare_line_items( $invoice ); |
|
230 | + $this->prepare_line_items($invoice); |
|
231 | 231 | |
232 | 232 | // Add taxes to the cart |
233 | - if ( wpinv_use_taxes() && $invoice->is_taxable() ) { |
|
234 | - $line_item_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_tax(), 2 ); |
|
233 | + if (wpinv_use_taxes() && $invoice->is_taxable()) { |
|
234 | + $line_item_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_tax(), 2); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | // Add discount. |
238 | - if ( $invoice->get_total_discount() > 0 ) { |
|
239 | - $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
|
238 | + if ($invoice->get_total_discount() > 0) { |
|
239 | + $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_discount(), 2); |
|
240 | 240 | } |
241 | 241 | |
242 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
242 | + return array_merge($line_item_args, $this->get_line_items()); |
|
243 | 243 | |
244 | 244 | } |
245 | 245 | |
@@ -249,11 +249,11 @@ discard block |
||
249 | 249 | * @param WPInv_Invoice $invoice Invoice object. |
250 | 250 | * @return array |
251 | 251 | */ |
252 | - protected function get_line_item_args_single_item( $invoice ) { |
|
252 | + protected function get_line_item_args_single_item($invoice) { |
|
253 | 253 | $this->delete_line_items(); |
254 | 254 | |
255 | - $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
|
256 | - $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
255 | + $item_name = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number()); |
|
256 | + $this->add_line_item($item_name, 1, wpinv_round_amount((float) $invoice->get_total(), 2, true), $invoice->get_id()); |
|
257 | 257 | |
258 | 258 | return $this->get_line_items(); |
259 | 259 | } |
@@ -277,19 +277,19 @@ discard block |
||
277 | 277 | * |
278 | 278 | * @param WPInv_Invoice $invoice Invoice object. |
279 | 279 | */ |
280 | - protected function prepare_line_items( $invoice ) { |
|
280 | + protected function prepare_line_items($invoice) { |
|
281 | 281 | $this->delete_line_items(); |
282 | 282 | |
283 | 283 | // Items. |
284 | - foreach ( $invoice->get_items() as $item ) { |
|
284 | + foreach ($invoice->get_items() as $item) { |
|
285 | 285 | $amount = $item->get_price(); |
286 | 286 | $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
287 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
287 | + $this->add_line_item($item->get_raw_name(), $quantity, $amount, $item->get_id()); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | // Fees. |
291 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
292 | - $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
|
291 | + foreach ($invoice->get_fees() as $fee => $data) { |
|
292 | + $this->add_line_item($fee, 1, wpinv_sanitize_amount($data['initial_fee'])); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | } |
@@ -302,15 +302,15 @@ discard block |
||
302 | 302 | * @param float $amount Amount. |
303 | 303 | * @param string $item_number Item number. |
304 | 304 | */ |
305 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
306 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
305 | + protected function add_line_item($item_name, $quantity = 1, $amount = 0.0, $item_number = '') { |
|
306 | + $index = (count($this->line_items) / 4) + 1; |
|
307 | 307 | |
308 | 308 | $item = apply_filters( |
309 | 309 | 'getpaid_paypal_line_item', |
310 | 310 | array( |
311 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
311 | + 'item_name' => html_entity_decode(getpaid_limit_length($item_name ? wp_strip_all_tags($item_name) : __('Item', 'invoicing'), 127), ENT_NOQUOTES, 'UTF-8'), |
|
312 | 312 | 'quantity' => (float) $quantity, |
313 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
313 | + 'amount' => wpinv_sanitize_amount((float) $amount, 2), |
|
314 | 314 | 'item_number' => $item_number, |
315 | 315 | ), |
316 | 316 | $item_name, |
@@ -319,12 +319,12 @@ discard block |
||
319 | 319 | $item_number |
320 | 320 | ); |
321 | 321 | |
322 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
323 | - $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
|
322 | + $this->line_items['item_name_' . $index] = getpaid_limit_length($item['item_name'], 127); |
|
323 | + $this->line_items['quantity_' . $index] = $item['quantity']; |
|
324 | 324 | |
325 | 325 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
326 | - $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
327 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
326 | + $this->line_items['amount_' . $index] = $item['amount'] * $item['quantity']; |
|
327 | + $this->line_items['item_number_' . $index] = getpaid_limit_length($item['item_number'], 127); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
@@ -336,19 +336,19 @@ discard block |
||
336 | 336 | * @param array $paypal_args Arguments sent to Paypal in the request. |
337 | 337 | * @return array |
338 | 338 | */ |
339 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
339 | + protected function fix_request_length($invoice, $paypal_args) { |
|
340 | 340 | $max_paypal_length = 2083; |
341 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
341 | + $query_candidate = http_build_query($paypal_args, '', '&'); |
|
342 | 342 | |
343 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
343 | + if (strlen($this->endpoint . $query_candidate) <= $max_paypal_length) { |
|
344 | 344 | return $paypal_args; |
345 | 345 | } |
346 | 346 | |
347 | 347 | return apply_filters( |
348 | 348 | 'getpaid_paypal_args', |
349 | 349 | array_merge( |
350 | - $this->get_transaction_args( $invoice ), |
|
351 | - $this->get_line_item_args( $invoice, true ) |
|
350 | + $this->get_transaction_args($invoice), |
|
351 | + $this->get_line_item_args($invoice, true) |
|
352 | 352 | ), |
353 | 353 | $invoice |
354 | 354 | ); |
@@ -361,10 +361,10 @@ discard block |
||
361 | 361 | * @param array $paypal_args PayPal args. |
362 | 362 | * @param WPInv_Invoice $invoice Invoice object. |
363 | 363 | */ |
364 | - public function process_subscription( $paypal_args, $invoice ) { |
|
364 | + public function process_subscription($paypal_args, $invoice) { |
|
365 | 365 | |
366 | 366 | // Make sure this is a subscription. |
367 | - if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) { |
|
367 | + if (!$invoice->is_recurring() || !$subscription = getpaid_get_invoice_subscription($invoice)) { |
|
368 | 368 | return $paypal_args; |
369 | 369 | } |
370 | 370 | |
@@ -372,23 +372,23 @@ discard block |
||
372 | 372 | $paypal_args['cmd'] = '_xclick-subscriptions'; |
373 | 373 | |
374 | 374 | // Subscription name. |
375 | - $paypal_args['item_name'] = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
|
375 | + $paypal_args['item_name'] = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number()); |
|
376 | 376 | |
377 | 377 | // Get subscription args. |
378 | - $period = strtoupper( substr( $subscription->get_period(), 0, 1 ) ); |
|
378 | + $period = strtoupper(substr($subscription->get_period(), 0, 1)); |
|
379 | 379 | $interval = (int) $subscription->get_frequency(); |
380 | 380 | $bill_times = (int) $subscription->get_bill_times(); |
381 | - $initial_amount = (float) wpinv_sanitize_amount( $invoice->get_initial_total(), 2 ); |
|
382 | - $recurring_amount = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 ); |
|
383 | - $subscription_item = $invoice->get_recurring( true ); |
|
381 | + $initial_amount = (float) wpinv_sanitize_amount($invoice->get_initial_total(), 2); |
|
382 | + $recurring_amount = (float) wpinv_sanitize_amount($invoice->get_recurring_total(), 2); |
|
383 | + $subscription_item = $invoice->get_recurring(true); |
|
384 | 384 | |
385 | 385 | // Convert 365 days to 1 year. |
386 | - if ( 'D' == $period && 365 == $interval ) { |
|
386 | + if ('D' == $period && 365 == $interval) { |
|
387 | 387 | $period = 'Y'; |
388 | 388 | $interval = 1; |
389 | 389 | } |
390 | 390 | |
391 | - if ( $subscription_item->has_free_trial() ) { |
|
391 | + if ($subscription_item->has_free_trial()) { |
|
392 | 392 | |
393 | 393 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
394 | 394 | |
@@ -398,28 +398,28 @@ discard block |
||
398 | 398 | // Trial period. |
399 | 399 | $paypal_args['t1'] = $subscription_item->get_trial_period(); |
400 | 400 | |
401 | - } elseif ( $initial_amount != $recurring_amount ) { |
|
401 | + } elseif ($initial_amount != $recurring_amount) { |
|
402 | 402 | |
403 | 403 | // No trial period, but initial amount includes a sign-up fee and/or other items, so charge it as a separate period. |
404 | 404 | |
405 | - if ( 1 == $bill_times ) { |
|
405 | + if (1 == $bill_times) { |
|
406 | 406 | $param_number = 3; |
407 | 407 | } else { |
408 | 408 | $param_number = 1; |
409 | 409 | } |
410 | 410 | |
411 | - $paypal_args[ 'a' . $param_number ] = $initial_amount ? $initial_amount : 0; |
|
411 | + $paypal_args['a' . $param_number] = $initial_amount ? $initial_amount : 0; |
|
412 | 412 | |
413 | 413 | // Sign Up interval |
414 | - $paypal_args[ 'p' . $param_number ] = $interval; |
|
414 | + $paypal_args['p' . $param_number] = $interval; |
|
415 | 415 | |
416 | 416 | // Sign Up unit of duration |
417 | - $paypal_args[ 't' . $param_number ] = $period; |
|
417 | + $paypal_args['t' . $param_number] = $period; |
|
418 | 418 | |
419 | 419 | } |
420 | 420 | |
421 | 421 | // We have a recurring payment |
422 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
422 | + if (!isset($param_number) || 1 == $param_number) { |
|
423 | 423 | |
424 | 424 | // Subscription price |
425 | 425 | $paypal_args['a3'] = $recurring_amount; |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | } |
434 | 434 | |
435 | 435 | // Recurring payments |
436 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
436 | + if (1 == $bill_times || ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial() && 2 == $bill_times)) { |
|
437 | 437 | |
438 | 438 | // Non-recurring payments |
439 | 439 | $paypal_args['src'] = 0; |
@@ -442,15 +442,15 @@ discard block |
||
442 | 442 | |
443 | 443 | $paypal_args['src'] = 1; |
444 | 444 | |
445 | - if ( $bill_times > 0 ) { |
|
445 | + if ($bill_times > 0) { |
|
446 | 446 | |
447 | 447 | // An initial period is being used to charge a sign-up fee |
448 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
448 | + if ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial()) { |
|
449 | 449 | $bill_times--; |
450 | 450 | } |
451 | 451 | |
452 | 452 | // Make sure it's not over the max of 52 |
453 | - $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
|
453 | + $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52); |
|
454 | 454 | |
455 | 455 | } |
456 | 456 | } |
@@ -459,10 +459,10 @@ discard block |
||
459 | 459 | $paypal_args['rm'] = 2; |
460 | 460 | |
461 | 461 | // Get rid of redudant items. |
462 | - foreach ( array( 'item_name_1', 'quantity_1', 'amount_1', 'item_number_1' ) as $arg ) { |
|
462 | + foreach (array('item_name_1', 'quantity_1', 'amount_1', 'item_number_1') as $arg) { |
|
463 | 463 | |
464 | - if ( isset( $paypal_args[ $arg ] ) ) { |
|
465 | - unset( $paypal_args[ $arg ] ); |
|
464 | + if (isset($paypal_args[$arg])) { |
|
465 | + unset($paypal_args[$arg]); |
|
466 | 466 | } |
467 | 467 | } |
468 | 468 | |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | * @return void |
481 | 481 | */ |
482 | 482 | public function verify_ipn() { |
483 | - new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
|
483 | + new GetPaid_Paypal_Gateway_IPN_Handler($this); |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | /** |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | public function sandbox_notice() { |
490 | 490 | |
491 | 491 | return sprintf( |
492 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
492 | + __('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing'), |
|
493 | 493 | '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
494 | 494 | '</a>' |
495 | 495 | ); |
@@ -501,41 +501,41 @@ discard block |
||
501 | 501 | * |
502 | 502 | * @param array $admin_settings |
503 | 503 | */ |
504 | - public function admin_settings( $admin_settings ) { |
|
504 | + public function admin_settings($admin_settings) { |
|
505 | 505 | |
506 | 506 | $currencies = sprintf( |
507 | - __( 'Supported Currencies: %s', 'invoicing' ), |
|
508 | - implode( ', ', $this->currencies ) |
|
507 | + __('Supported Currencies: %s', 'invoicing'), |
|
508 | + implode(', ', $this->currencies) |
|
509 | 509 | ); |
510 | 510 | |
511 | 511 | $admin_settings['paypal_active']['desc'] .= " ($currencies)"; |
512 | - $admin_settings['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
|
512 | + $admin_settings['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing'); |
|
513 | 513 | |
514 | 514 | // Access tokens. |
515 | - $live_email = wpinv_get_option( 'paypal_email' ); |
|
516 | - $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
515 | + $live_email = wpinv_get_option('paypal_email'); |
|
516 | + $sandbox_email = wpinv_get_option('paypal_sandbox_email'); |
|
517 | 517 | |
518 | 518 | $admin_settings['paypal_connect'] = array( |
519 | 519 | 'type' => 'hook', |
520 | 520 | 'id' => 'paypal_connect', |
521 | - 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
521 | + 'name' => __('Connect to PayPal', 'invoicing'), |
|
522 | 522 | ); |
523 | 523 | |
524 | 524 | $admin_settings['paypal_email'] = array( |
525 | 525 | 'type' => 'text', |
526 | 526 | 'class' => 'live-auth-data', |
527 | 527 | 'id' => 'paypal_email', |
528 | - 'name' => __( 'Live Email Address', 'invoicing' ), |
|
529 | - 'desc' => __( 'The email address of your PayPal account.', 'invoicing' ), |
|
528 | + 'name' => __('Live Email Address', 'invoicing'), |
|
529 | + 'desc' => __('The email address of your PayPal account.', 'invoicing'), |
|
530 | 530 | ); |
531 | 531 | |
532 | 532 | $admin_settings['paypal_sandbox_email'] = array( |
533 | 533 | 'type' => 'text', |
534 | 534 | 'class' => 'sandbox-auth-data', |
535 | 535 | 'id' => 'paypal_sandbox_email', |
536 | - 'name' => __( 'Sandbox Email Address', 'invoicing' ), |
|
537 | - 'desc' => __( 'The email address of your sandbox PayPal account.', 'invoicing' ), |
|
538 | - 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
536 | + 'name' => __('Sandbox Email Address', 'invoicing'), |
|
537 | + 'desc' => __('The email address of your sandbox PayPal account.', 'invoicing'), |
|
538 | + 'std' => wpinv_get_option('paypal_email', ''), |
|
539 | 539 | ); |
540 | 540 | |
541 | 541 | // Client ID and secret. |
@@ -543,41 +543,41 @@ discard block |
||
543 | 543 | 'type' => 'text', |
544 | 544 | 'class' => 'live-auth-data', |
545 | 545 | 'id' => 'paypal_client_id', |
546 | - 'name' => __( 'Live Client ID', 'invoicing' ), |
|
547 | - 'desc' => __( 'The client ID of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
546 | + 'name' => __('Live Client ID', 'invoicing'), |
|
547 | + 'desc' => __('The client ID of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing'), |
|
548 | 548 | ); |
549 | 549 | |
550 | 550 | $admin_settings['paypal_sandbox_client_id'] = array( |
551 | 551 | 'type' => 'text', |
552 | 552 | 'class' => 'sandbox-auth-data', |
553 | 553 | 'id' => 'paypal_sandbox_client_id', |
554 | - 'name' => __( 'Sandbox Client ID', 'invoicing' ), |
|
555 | - 'desc' => __( 'The client ID of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
556 | - 'std' => wpinv_get_option( 'paypal_client_id', '' ), |
|
554 | + 'name' => __('Sandbox Client ID', 'invoicing'), |
|
555 | + 'desc' => __('The client ID of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing'), |
|
556 | + 'std' => wpinv_get_option('paypal_client_id', ''), |
|
557 | 557 | ); |
558 | 558 | |
559 | 559 | $admin_settings['paypal_secret'] = array( |
560 | 560 | 'type' => 'text', |
561 | 561 | 'class' => 'live-auth-data', |
562 | 562 | 'id' => 'paypal_secret', |
563 | - 'name' => __( 'Live Secret', 'invoicing' ), |
|
564 | - 'desc' => __( 'The secret of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
563 | + 'name' => __('Live Secret', 'invoicing'), |
|
564 | + 'desc' => __('The secret of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing'), |
|
565 | 565 | ); |
566 | 566 | |
567 | 567 | $admin_settings['paypal_sandbox_secret'] = array( |
568 | 568 | 'type' => 'text', |
569 | 569 | 'class' => 'sandbox-auth-data', |
570 | 570 | 'id' => 'paypal_sandbox_secret', |
571 | - 'name' => __( 'Sandbox Secret', 'invoicing' ), |
|
572 | - 'desc' => __( 'The secret of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
571 | + 'name' => __('Sandbox Secret', 'invoicing'), |
|
572 | + 'desc' => __('The secret of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing'), |
|
573 | 573 | ); |
574 | 574 | |
575 | 575 | $admin_settings['paypal_ipn_url'] = array( |
576 | 576 | 'type' => 'ipn_url', |
577 | 577 | 'id' => 'paypal_ipn_url', |
578 | - 'name' => __( 'IPN Url', 'invoicing' ), |
|
578 | + 'name' => __('IPN Url', 'invoicing'), |
|
579 | 579 | 'std' => $this->notify_url, |
580 | - '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>', |
|
580 | + '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>', |
|
581 | 581 | 'readonly' => true, |
582 | 582 | ); |
583 | 583 | |
@@ -590,9 +590,9 @@ discard block |
||
590 | 590 | * @param string $url |
591 | 591 | * @param WPInv_Subscription $subscription |
592 | 592 | */ |
593 | - public function filter_cancel_subscription_url( $url, $subscription ) { |
|
593 | + public function filter_cancel_subscription_url($url, $subscription) { |
|
594 | 594 | |
595 | - if ( $this->id !== $subscription->get_gateway() ) { |
|
595 | + if ($this->id !== $subscription->get_gateway()) { |
|
596 | 596 | return $url; |
597 | 597 | } |
598 | 598 | |
@@ -600,16 +600,16 @@ discard block |
||
600 | 600 | $profile_id = $subscription->get_profile_id(); |
601 | 601 | |
602 | 602 | // Bail if no profile ID. |
603 | - if ( empty( $profile_id ) ) { |
|
603 | + if (empty($profile_id)) { |
|
604 | 604 | return $url; |
605 | 605 | } |
606 | 606 | |
607 | 607 | $cancel_url = 'https://www.paypal.com/myaccount/autopay/connect/%s/cancel'; |
608 | - if ( $this->is_sandbox( $subscription->get_parent_payment() ) ) { |
|
608 | + if ($this->is_sandbox($subscription->get_parent_payment())) { |
|
609 | 609 | $cancel_url = 'https://www.sandbox.paypal.com/myaccount/autopay/connect/%s/cancel'; |
610 | 610 | } |
611 | 611 | |
612 | - return sprintf( $cancel_url, $profile_id ); |
|
612 | + return sprintf($cancel_url, $profile_id); |
|
613 | 613 | } |
614 | 614 | |
615 | 615 | /** |
@@ -619,8 +619,8 @@ discard block |
||
619 | 619 | * @param array $data |
620 | 620 | * @return string |
621 | 621 | */ |
622 | - public static function maybe_get_connect_url( $url = '', $data = array() ) { |
|
623 | - return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
622 | + public static function maybe_get_connect_url($url = '', $data = array()) { |
|
623 | + return self::get_connect_url(false, urldecode($data['redirect'])); |
|
624 | 624 | } |
625 | 625 | |
626 | 626 | /** |
@@ -631,25 +631,25 @@ discard block |
||
631 | 631 | * @param string $redirect |
632 | 632 | * @return string |
633 | 633 | */ |
634 | - public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
634 | + public static function get_connect_url($is_sandbox, $redirect = '') { |
|
635 | 635 | |
636 | 636 | $redirect_url = add_query_arg( |
637 | 637 | array( |
638 | 638 | 'getpaid-admin-action' => 'connect_paypal', |
639 | 639 | 'page' => 'wpinv-settings', |
640 | - 'live_mode' => (int) empty( $is_sandbox ), |
|
640 | + 'live_mode' => (int) empty($is_sandbox), |
|
641 | 641 | 'tab' => 'gateways', |
642 | 642 | 'section' => 'paypal', |
643 | - 'getpaid-nonce' => wp_create_nonce( 'getpaid-nonce' ), |
|
644 | - 'redirect' => urlencode( $redirect ), |
|
643 | + 'getpaid-nonce' => wp_create_nonce('getpaid-nonce'), |
|
644 | + 'redirect' => urlencode($redirect), |
|
645 | 645 | ), |
646 | - admin_url( 'admin.php' ) |
|
646 | + admin_url('admin.php') |
|
647 | 647 | ); |
648 | 648 | |
649 | 649 | return add_query_arg( |
650 | 650 | array( |
651 | - 'live_mode' => (int) empty( $is_sandbox ), |
|
652 | - 'redirect_url' => urlencode( str_replace( '&', '&', $redirect_url ) ), |
|
651 | + 'live_mode' => (int) empty($is_sandbox), |
|
652 | + 'redirect_url' => urlencode(str_replace('&', '&', $redirect_url)), |
|
653 | 653 | ), |
654 | 654 | 'https://ayecode.io/oauth/paypal' |
655 | 655 | ); |
@@ -665,10 +665,10 @@ discard block |
||
665 | 665 | |
666 | 666 | ?> |
667 | 667 | <div class="wpinv-paypal-connect-live"> |
668 | - <a class="button button-primary" href="<?php echo esc_url( self::get_connect_url( false ) ); ?>"><?php esc_html_e( 'Connect to PayPal', 'invoicing' ); ?></a> |
|
668 | + <a class="button button-primary" href="<?php echo esc_url(self::get_connect_url(false)); ?>"><?php esc_html_e('Connect to PayPal', 'invoicing'); ?></a> |
|
669 | 669 | </div> |
670 | 670 | <div class="wpinv-paypal-connect-sandbox"> |
671 | - <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> |
|
671 | + <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> |
|
672 | 672 | </div> |
673 | 673 | |
674 | 674 | <script> |
@@ -709,26 +709,26 @@ discard block |
||
709 | 709 | * @param array $data Connection data. |
710 | 710 | * @return void |
711 | 711 | */ |
712 | - public function connect_paypal( $data ) { |
|
712 | + public function connect_paypal($data) { |
|
713 | 713 | |
714 | 714 | $sandbox = $this->is_sandbox(); |
715 | - $data = wp_unslash( $data ); |
|
716 | - $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
715 | + $data = wp_unslash($data); |
|
716 | + $access_token = empty($data['access_token']) ? '' : sanitize_text_field($data['access_token']); |
|
717 | 717 | |
718 | - if ( isset( $data['live_mode'] ) ) { |
|
719 | - $sandbox = empty( $data['live_mode'] ); |
|
718 | + if (isset($data['live_mode'])) { |
|
719 | + $sandbox = empty($data['live_mode']); |
|
720 | 720 | } |
721 | 721 | |
722 | - wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
723 | - wpinv_update_option( 'paypal_active', 1 ); |
|
722 | + wpinv_update_option('paypal_sandbox', (int) $sandbox); |
|
723 | + wpinv_update_option('paypal_active', 1); |
|
724 | 724 | |
725 | - if ( ! empty( $data['error_description'] ) ) { |
|
726 | - getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
725 | + if (!empty($data['error_description'])) { |
|
726 | + getpaid_admin()->show_error(wp_kses_post(urldecode($data['error_description']))); |
|
727 | 727 | } else { |
728 | 728 | |
729 | 729 | // Retrieve the user info. |
730 | 730 | $user_info = wp_remote_get( |
731 | - ! $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', |
|
731 | + !$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', |
|
732 | 732 | array( |
733 | 733 | |
734 | 734 | 'headers' => array( |
@@ -739,33 +739,33 @@ discard block |
||
739 | 739 | ) |
740 | 740 | ); |
741 | 741 | |
742 | - if ( is_wp_error( $user_info ) ) { |
|
743 | - getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
742 | + if (is_wp_error($user_info)) { |
|
743 | + getpaid_admin()->show_error(wp_kses_post($user_info->get_error_message())); |
|
744 | 744 | } else { |
745 | 745 | |
746 | 746 | // Create application. |
747 | - $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
747 | + $user_info = json_decode(wp_remote_retrieve_body($user_info)); |
|
748 | 748 | |
749 | - if ( $sandbox ) { |
|
750 | - wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
751 | - wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
752 | - set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
753 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
749 | + if ($sandbox) { |
|
750 | + wpinv_update_option('paypal_sandbox_email', sanitize_email($user_info->emails[0]->value)); |
|
751 | + wpinv_update_option('paypal_sandbox_refresh_token', sanitize_text_field(urldecode($data['refresh_token']))); |
|
752 | + set_transient('getpaid_paypal_sandbox_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']); |
|
753 | + getpaid_admin()->show_success(__('Successfully connected your PayPal sandbox account', 'invoicing')); |
|
754 | 754 | } else { |
755 | - wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
756 | - wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
757 | - set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
758 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
755 | + wpinv_update_option('paypal_email', sanitize_email($user_info->emails[0]->value)); |
|
756 | + wpinv_update_option('paypal_refresh_token', sanitize_text_field(urldecode($data['refresh_token']))); |
|
757 | + set_transient('getpaid_paypal_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']); |
|
758 | + getpaid_admin()->show_success(__('Successfully connected your PayPal account', 'invoicing')); |
|
759 | 759 | } |
760 | 760 | } |
761 | 761 | } |
762 | 762 | |
763 | - $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
763 | + $redirect = empty($data['redirect']) ? admin_url('admin.php?page=wpinv-settings&tab=gateways§ion=paypal') : urldecode($data['redirect']); |
|
764 | 764 | |
765 | - if ( isset( $data['step'] ) ) { |
|
766 | - $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
765 | + if (isset($data['step'])) { |
|
766 | + $redirect = add_query_arg('step', $data['step'], $redirect); |
|
767 | 767 | } |
768 | - wp_redirect( $redirect ); |
|
768 | + wp_redirect($redirect); |
|
769 | 769 | exit; |
770 | 770 | } |
771 | 771 |