Completed
Push — master ( 04a827...87ad6d )
by Kiran
32s queued 28s
created
includes/gateways/class-getpaid-paypal-api.php 1 patch
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-paypal-gateway.php 1 patch
Spacing   +185 added lines, -185 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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( '&amp;', '&', $redirect_url ) ),
755
+                'live_mode'    => (int) empty($is_sandbox),
756
+                'redirect_url' => urlencode(str_replace('&amp;', '&', $redirect_url)),
757 757
             ),
758 758
             'https://ayecode.io/oauth/paypal'
759 759
         );
@@ -769,10 +769,10 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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&section=paypal' ) : urldecode( $data['redirect'] );
867
+		$redirect = empty($data['redirect']) ? admin_url('admin.php?page=wpinv-settings&tab=gateways&section=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
 
Please login to merge, or discard this patch.