@@ -13,96 +13,96 @@ discard block |
||
| 13 | 13 | class GetPaid_Paypal_Gateway extends GetPaid_Payment_Gateway { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Payment method id. |
|
| 17 | - * |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 16 | + * Payment method id. |
|
| 17 | + * |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | 20 | public $id = 'paypal'; |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * An array of features that this gateway supports. |
|
| 24 | - * |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 23 | + * An array of features that this gateway supports. |
|
| 24 | + * |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | 27 | protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' ); |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Payment method order. |
|
| 31 | - * |
|
| 32 | - * @var int |
|
| 33 | - */ |
|
| 30 | + * Payment method order. |
|
| 31 | + * |
|
| 32 | + * @var int |
|
| 33 | + */ |
|
| 34 | 34 | public $order = 1; |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | - * Stores line items to send to PayPal. |
|
| 38 | - * |
|
| 39 | - * @var array |
|
| 40 | - */ |
|
| 37 | + * Stores line items to send to PayPal. |
|
| 38 | + * |
|
| 39 | + * @var array |
|
| 40 | + */ |
|
| 41 | 41 | protected $line_items = array(); |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | - * Endpoint for requests from PayPal. |
|
| 45 | - * |
|
| 46 | - * @var string |
|
| 47 | - */ |
|
| 48 | - protected $notify_url; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Endpoint for requests to PayPal. |
|
| 52 | - * |
|
| 53 | - * @var string |
|
| 54 | - */ |
|
| 44 | + * Endpoint for requests from PayPal. |
|
| 45 | + * |
|
| 46 | + * @var string |
|
| 47 | + */ |
|
| 48 | + protected $notify_url; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Endpoint for requests to PayPal. |
|
| 52 | + * |
|
| 53 | + * @var string |
|
| 54 | + */ |
|
| 55 | 55 | protected $endpoint; |
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | - * Currencies this gateway is allowed for. |
|
| 59 | - * |
|
| 60 | - * @var array |
|
| 61 | - */ |
|
| 62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
| 58 | + * Currencies this gateway is allowed for. |
|
| 59 | + * |
|
| 60 | + * @var array |
|
| 61 | + */ |
|
| 62 | + public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | - * URL to view a transaction. |
|
| 66 | - * |
|
| 67 | - * @var string |
|
| 68 | - */ |
|
| 65 | + * URL to view a transaction. |
|
| 66 | + * |
|
| 67 | + * @var string |
|
| 68 | + */ |
|
| 69 | 69 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | - * URL to view a subscription. |
|
| 73 | - * |
|
| 74 | - * @var string |
|
| 75 | - */ |
|
| 76 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
| 72 | + * URL to view a subscription. |
|
| 73 | + * |
|
| 74 | + * @var string |
|
| 75 | + */ |
|
| 76 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | - * Class constructor. |
|
| 80 | - */ |
|
| 81 | - public function __construct() { |
|
| 79 | + * Class constructor. |
|
| 80 | + */ |
|
| 81 | + public function __construct() { |
|
| 82 | 82 | |
| 83 | 83 | $this->title = __( 'PayPal Standard', 'invoicing' ); |
| 84 | 84 | $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
| 85 | 85 | $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
| 86 | 86 | $this->notify_url = wpinv_get_ipn_url( $this->id ); |
| 87 | 87 | |
| 88 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
| 88 | + add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
| 89 | 89 | add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
| 90 | - add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
| 91 | - add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
| 90 | + add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
| 91 | + add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
| 92 | 92 | |
| 93 | 93 | parent::__construct(); |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
| 97 | - * Process Payment. |
|
| 98 | - * |
|
| 99 | - * |
|
| 100 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 101 | - * @param array $submission_data Posted checkout fields. |
|
| 102 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 103 | - * @return array |
|
| 104 | - */ |
|
| 105 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 97 | + * Process Payment. |
|
| 98 | + * |
|
| 99 | + * |
|
| 100 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 101 | + * @param array $submission_data Posted checkout fields. |
|
| 102 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 103 | + * @return array |
|
| 104 | + */ |
|
| 105 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 106 | 106 | |
| 107 | 107 | // Get redirect url. |
| 108 | 108 | $paypal_redirect = $this->get_request_url( $invoice ); |
@@ -125,15 +125,15 @@ discard block |
||
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
| 128 | - * Get the PayPal request URL for an invoice. |
|
| 129 | - * |
|
| 130 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 131 | - * @return string |
|
| 132 | - */ |
|
| 133 | - public function get_request_url( $invoice ) { |
|
| 128 | + * Get the PayPal request URL for an invoice. |
|
| 129 | + * |
|
| 130 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 131 | + * @return string |
|
| 132 | + */ |
|
| 133 | + public function get_request_url( $invoice ) { |
|
| 134 | 134 | |
| 135 | 135 | // Endpoint for this request |
| 136 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
| 136 | + $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 | 137 | |
| 138 | 138 | // Retrieve paypal args. |
| 139 | 139 | $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
@@ -146,45 +146,45 @@ discard block |
||
| 146 | 146 | |
| 147 | 147 | return add_query_arg( $paypal_args, $this->endpoint ); |
| 148 | 148 | |
| 149 | - } |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | 151 | /** |
| 152 | - * Get PayPal Args for passing to PP. |
|
| 153 | - * |
|
| 154 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 155 | - * @return array |
|
| 156 | - */ |
|
| 157 | - protected function get_paypal_args( $invoice ) { |
|
| 152 | + * Get PayPal Args for passing to PP. |
|
| 153 | + * |
|
| 154 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 155 | + * @return array |
|
| 156 | + */ |
|
| 157 | + protected function get_paypal_args( $invoice ) { |
|
| 158 | 158 | |
| 159 | 159 | // Whether or not to send the line items as one item. |
| 160 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
| 161 | - |
|
| 162 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
| 163 | - $force_one_line_item = true; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - $paypal_args = apply_filters( |
|
| 167 | - 'getpaid_paypal_args', |
|
| 168 | - array_merge( |
|
| 169 | - $this->get_transaction_args( $invoice ), |
|
| 170 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
| 171 | - ), |
|
| 172 | - $invoice |
|
| 173 | - ); |
|
| 174 | - |
|
| 175 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
| 160 | + $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
| 161 | + |
|
| 162 | + if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
| 163 | + $force_one_line_item = true; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + $paypal_args = apply_filters( |
|
| 167 | + 'getpaid_paypal_args', |
|
| 168 | + array_merge( |
|
| 169 | + $this->get_transaction_args( $invoice ), |
|
| 170 | + $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
| 171 | + ), |
|
| 172 | + $invoice |
|
| 173 | + ); |
|
| 174 | + |
|
| 175 | + return $this->fix_request_length( $invoice, $paypal_args ); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
| 179 | - * Get transaction args for paypal request. |
|
| 180 | - * |
|
| 181 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 182 | - * @return array |
|
| 183 | - */ |
|
| 184 | - protected function get_transaction_args( $invoice ) { |
|
| 185 | - |
|
| 186 | - $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
| 187 | - return array( |
|
| 179 | + * Get transaction args for paypal request. |
|
| 180 | + * |
|
| 181 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 182 | + * @return array |
|
| 183 | + */ |
|
| 184 | + protected function get_transaction_args( $invoice ) { |
|
| 185 | + |
|
| 186 | + $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
| 187 | + return array( |
|
| 188 | 188 | 'cmd' => '_cart', |
| 189 | 189 | 'business' => $email, |
| 190 | 190 | 'no_shipping' => '1', |
@@ -209,16 +209,16 @@ discard block |
||
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
| 212 | - * Get line item args for paypal request. |
|
| 213 | - * |
|
| 214 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 215 | - * @param bool $force_one_line_item Create only one item for this invoice. |
|
| 216 | - * @return array |
|
| 217 | - */ |
|
| 218 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
| 212 | + * Get line item args for paypal request. |
|
| 213 | + * |
|
| 214 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 215 | + * @param bool $force_one_line_item Create only one item for this invoice. |
|
| 216 | + * @return array |
|
| 217 | + */ |
|
| 218 | + protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
| 219 | 219 | |
| 220 | 220 | // Maybe send invoice as a single item. |
| 221 | - if ( $force_one_line_item ) { |
|
| 221 | + if ( $force_one_line_item ) { |
|
| 222 | 222 | return $this->get_line_item_args_single_item( $invoice ); |
| 223 | 223 | } |
| 224 | 224 | |
@@ -238,129 +238,129 @@ discard block |
||
| 238 | 238 | $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
| 241 | + return array_merge( $line_item_args, $this->get_line_items() ); |
|
| 242 | 242 | |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
| 246 | - * Get line item args for paypal request as a single line item. |
|
| 247 | - * |
|
| 248 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 249 | - * @return array |
|
| 250 | - */ |
|
| 251 | - protected function get_line_item_args_single_item( $invoice ) { |
|
| 252 | - $this->delete_line_items(); |
|
| 246 | + * Get line item args for paypal request as a single line item. |
|
| 247 | + * |
|
| 248 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 249 | + * @return array |
|
| 250 | + */ |
|
| 251 | + protected function get_line_item_args_single_item( $invoice ) { |
|
| 252 | + $this->delete_line_items(); |
|
| 253 | 253 | |
| 254 | 254 | $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
| 255 | - $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
| 255 | + $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
| 256 | 256 | |
| 257 | - return $this->get_line_items(); |
|
| 257 | + return $this->get_line_items(); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | /** |
| 261 | - * Return all line items. |
|
| 262 | - */ |
|
| 263 | - protected function get_line_items() { |
|
| 264 | - return $this->line_items; |
|
| 265 | - } |
|
| 261 | + * Return all line items. |
|
| 262 | + */ |
|
| 263 | + protected function get_line_items() { |
|
| 264 | + return $this->line_items; |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | 267 | /** |
| 268 | - * Remove all line items. |
|
| 269 | - */ |
|
| 270 | - protected function delete_line_items() { |
|
| 271 | - $this->line_items = array(); |
|
| 268 | + * Remove all line items. |
|
| 269 | + */ |
|
| 270 | + protected function delete_line_items() { |
|
| 271 | + $this->line_items = array(); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | /** |
| 275 | - * Prepare line items to send to paypal. |
|
| 276 | - * |
|
| 277 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 278 | - */ |
|
| 279 | - protected function prepare_line_items( $invoice ) { |
|
| 280 | - $this->delete_line_items(); |
|
| 281 | - |
|
| 282 | - // Items. |
|
| 283 | - foreach ( $invoice->get_items() as $item ) { |
|
| 284 | - $amount = $item->get_price(); |
|
| 285 | - $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
| 286 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
| 275 | + * Prepare line items to send to paypal. |
|
| 276 | + * |
|
| 277 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 278 | + */ |
|
| 279 | + protected function prepare_line_items( $invoice ) { |
|
| 280 | + $this->delete_line_items(); |
|
| 281 | + |
|
| 282 | + // Items. |
|
| 283 | + foreach ( $invoice->get_items() as $item ) { |
|
| 284 | + $amount = $item->get_price(); |
|
| 285 | + $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
| 286 | + $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | // Fees. |
| 290 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
| 290 | + foreach ( $invoice->get_fees() as $fee => $data ) { |
|
| 291 | 291 | $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | /** |
| 297 | - * Add PayPal Line Item. |
|
| 298 | - * |
|
| 299 | - * @param string $item_name Item name. |
|
| 300 | - * @param float $quantity Item quantity. |
|
| 301 | - * @param float $amount Amount. |
|
| 302 | - * @param string $item_number Item number. |
|
| 303 | - */ |
|
| 304 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
| 305 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
| 306 | - |
|
| 307 | - $item = apply_filters( |
|
| 308 | - 'getpaid_paypal_line_item', |
|
| 309 | - array( |
|
| 310 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
| 311 | - 'quantity' => (float) $quantity, |
|
| 312 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
| 313 | - 'item_number' => $item_number, |
|
| 314 | - ), |
|
| 315 | - $item_name, |
|
| 316 | - $quantity, |
|
| 317 | - $amount, |
|
| 318 | - $item_number |
|
| 319 | - ); |
|
| 320 | - |
|
| 321 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
| 297 | + * Add PayPal Line Item. |
|
| 298 | + * |
|
| 299 | + * @param string $item_name Item name. |
|
| 300 | + * @param float $quantity Item quantity. |
|
| 301 | + * @param float $amount Amount. |
|
| 302 | + * @param string $item_number Item number. |
|
| 303 | + */ |
|
| 304 | + protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
| 305 | + $index = ( count( $this->line_items ) / 4 ) + 1; |
|
| 306 | + |
|
| 307 | + $item = apply_filters( |
|
| 308 | + 'getpaid_paypal_line_item', |
|
| 309 | + array( |
|
| 310 | + 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
| 311 | + 'quantity' => (float) $quantity, |
|
| 312 | + 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
| 313 | + 'item_number' => $item_number, |
|
| 314 | + ), |
|
| 315 | + $item_name, |
|
| 316 | + $quantity, |
|
| 317 | + $amount, |
|
| 318 | + $item_number |
|
| 319 | + ); |
|
| 320 | + |
|
| 321 | + $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
| 322 | 322 | $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
| 323 | 323 | |
| 324 | 324 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
| 325 | - $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
| 326 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
| 325 | + $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
| 326 | + $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | /** |
| 330 | - * If the default request with line items is too long, generate a new one with only one line item. |
|
| 331 | - * |
|
| 332 | - * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
| 333 | - * |
|
| 334 | - * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
| 335 | - * @param array $paypal_args Arguments sent to Paypal in the request. |
|
| 336 | - * @return array |
|
| 337 | - */ |
|
| 338 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
| 339 | - $max_paypal_length = 2083; |
|
| 340 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
| 341 | - |
|
| 342 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
| 343 | - return $paypal_args; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - return apply_filters( |
|
| 347 | - 'getpaid_paypal_args', |
|
| 348 | - array_merge( |
|
| 349 | - $this->get_transaction_args( $invoice ), |
|
| 350 | - $this->get_line_item_args( $invoice, true ) |
|
| 351 | - ), |
|
| 352 | - $invoice |
|
| 353 | - ); |
|
| 330 | + * If the default request with line items is too long, generate a new one with only one line item. |
|
| 331 | + * |
|
| 332 | + * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
| 333 | + * |
|
| 334 | + * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
| 335 | + * @param array $paypal_args Arguments sent to Paypal in the request. |
|
| 336 | + * @return array |
|
| 337 | + */ |
|
| 338 | + protected function fix_request_length( $invoice, $paypal_args ) { |
|
| 339 | + $max_paypal_length = 2083; |
|
| 340 | + $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
| 341 | + |
|
| 342 | + if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
| 343 | + return $paypal_args; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + return apply_filters( |
|
| 347 | + 'getpaid_paypal_args', |
|
| 348 | + array_merge( |
|
| 349 | + $this->get_transaction_args( $invoice ), |
|
| 350 | + $this->get_line_item_args( $invoice, true ) |
|
| 351 | + ), |
|
| 352 | + $invoice |
|
| 353 | + ); |
|
| 354 | 354 | |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | /** |
| 358 | - * Processes recurring invoices. |
|
| 359 | - * |
|
| 360 | - * @param array $paypal_args PayPal args. |
|
| 361 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 362 | - */ |
|
| 363 | - public function process_subscription( $paypal_args, $invoice ) { |
|
| 358 | + * Processes recurring invoices. |
|
| 359 | + * |
|
| 360 | + * @param array $paypal_args PayPal args. |
|
| 361 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 362 | + */ |
|
| 363 | + public function process_subscription( $paypal_args, $invoice ) { |
|
| 364 | 364 | |
| 365 | 365 | // Make sure this is a subscription. |
| 366 | 366 | if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) { |
@@ -381,21 +381,21 @@ discard block |
||
| 381 | 381 | $recurring_amount = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 ); |
| 382 | 382 | $subscription_item = $invoice->get_recurring( true ); |
| 383 | 383 | |
| 384 | - // Convert 365 days to 1 year. |
|
| 385 | - if ( 'D' == $period && 365 == $interval ) { |
|
| 386 | - $period = 'Y'; |
|
| 387 | - $interval = 1; |
|
| 388 | - } |
|
| 384 | + // Convert 365 days to 1 year. |
|
| 385 | + if ( 'D' == $period && 365 == $interval ) { |
|
| 386 | + $period = 'Y'; |
|
| 387 | + $interval = 1; |
|
| 388 | + } |
|
| 389 | 389 | |
| 390 | 390 | if ( $subscription_item->has_free_trial() ) { |
| 391 | 391 | |
| 392 | 392 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
| 393 | 393 | |
| 394 | - // Trial period length. |
|
| 395 | - $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
| 394 | + // Trial period length. |
|
| 395 | + $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
| 396 | 396 | |
| 397 | - // Trial period. |
|
| 398 | - $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
| 397 | + // Trial period. |
|
| 398 | + $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
| 399 | 399 | |
| 400 | 400 | } else if ( $initial_amount != $recurring_amount ) { |
| 401 | 401 | |
@@ -418,40 +418,40 @@ discard block |
||
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | // We have a recurring payment |
| 421 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
| 421 | + if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
| 422 | 422 | |
| 423 | - // Subscription price |
|
| 424 | - $paypal_args['a3'] = $recurring_amount; |
|
| 423 | + // Subscription price |
|
| 424 | + $paypal_args['a3'] = $recurring_amount; |
|
| 425 | 425 | |
| 426 | - // Subscription duration |
|
| 427 | - $paypal_args['p3'] = $interval; |
|
| 426 | + // Subscription duration |
|
| 427 | + $paypal_args['p3'] = $interval; |
|
| 428 | 428 | |
| 429 | - // Subscription period |
|
| 430 | - $paypal_args['t3'] = $period; |
|
| 429 | + // Subscription period |
|
| 430 | + $paypal_args['t3'] = $period; |
|
| 431 | 431 | |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | // Recurring payments |
| 435 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
| 435 | + if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
| 436 | 436 | |
| 437 | - // Non-recurring payments |
|
| 438 | - $paypal_args['src'] = 0; |
|
| 437 | + // Non-recurring payments |
|
| 438 | + $paypal_args['src'] = 0; |
|
| 439 | 439 | |
| 440 | - } else { |
|
| 440 | + } else { |
|
| 441 | 441 | |
| 442 | - $paypal_args['src'] = 1; |
|
| 442 | + $paypal_args['src'] = 1; |
|
| 443 | 443 | |
| 444 | - if ( $bill_times > 0 ) { |
|
| 444 | + if ( $bill_times > 0 ) { |
|
| 445 | 445 | |
| 446 | - // An initial period is being used to charge a sign-up fee |
|
| 447 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
| 448 | - $bill_times--; |
|
| 449 | - } |
|
| 446 | + // An initial period is being used to charge a sign-up fee |
|
| 447 | + if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
| 448 | + $bill_times--; |
|
| 449 | + } |
|
| 450 | 450 | |
| 451 | 451 | // Make sure it's not over the max of 52 |
| 452 | 452 | $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
| 453 | 453 | |
| 454 | - } |
|
| 454 | + } |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | // Force return URL so that order description & instructions display |
@@ -467,19 +467,19 @@ discard block |
||
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | return apply_filters( |
| 470 | - 'getpaid_paypal_subscription_args', |
|
| 471 | - $paypal_args, |
|
| 472 | - $invoice |
|
| 470 | + 'getpaid_paypal_subscription_args', |
|
| 471 | + $paypal_args, |
|
| 472 | + $invoice |
|
| 473 | 473 | ); |
| 474 | 474 | |
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | /** |
| 478 | - * Processes ipns and marks payments as complete. |
|
| 479 | - * |
|
| 480 | - * @return void |
|
| 481 | - */ |
|
| 482 | - public function verify_ipn() { |
|
| 478 | + * Processes ipns and marks payments as complete. |
|
| 479 | + * |
|
| 480 | + * @return void |
|
| 481 | + */ |
|
| 482 | + public function verify_ipn() { |
|
| 483 | 483 | new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
| 484 | 484 | } |
| 485 | 485 | |
@@ -489,19 +489,19 @@ 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 %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
| 493 | - '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
| 494 | - '</a>' |
|
| 495 | - ); |
|
| 492 | + __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
| 493 | + '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
| 494 | + '</a>' |
|
| 495 | + ); |
|
| 496 | 496 | |
| 497 | 497 | } |
| 498 | 498 | |
| 499 | - /** |
|
| 500 | - * Filters the gateway settings. |
|
| 501 | - * |
|
| 502 | - * @param array $admin_settings |
|
| 503 | - */ |
|
| 504 | - public function admin_settings( $admin_settings ) { |
|
| 499 | + /** |
|
| 500 | + * Filters the gateway settings. |
|
| 501 | + * |
|
| 502 | + * @param array $admin_settings |
|
| 503 | + */ |
|
| 504 | + public function admin_settings( $admin_settings ) { |
|
| 505 | 505 | |
| 506 | 506 | $currencies = sprintf( |
| 507 | 507 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -511,39 +511,39 @@ discard block |
||
| 511 | 511 | $admin_settings['paypal_active']['desc'] .= " ($currencies)"; |
| 512 | 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 | - // Access tokens. |
|
| 515 | - $live_email = wpinv_get_option( 'paypal_email' ); |
|
| 516 | - $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
| 517 | - |
|
| 518 | - $admin_settings['paypal_connect'] = array( |
|
| 519 | - 'type' => 'raw_html', |
|
| 520 | - 'id' => 'paypal_connect', |
|
| 521 | - 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
| 522 | - 'desc' => sprintf( |
|
| 523 | - '<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a></div>%s', |
|
| 524 | - esc_url( self::get_connect_url( false ) ), |
|
| 525 | - __( 'Connect to PayPal', 'invoicing' ), |
|
| 526 | - esc_url( self::get_connect_url( true ) ), |
|
| 527 | - __( 'Connect to PayPal Sandox', 'invoicing' ), |
|
| 528 | - $this->get_js() |
|
| 529 | - ), |
|
| 530 | - ); |
|
| 514 | + // Access tokens. |
|
| 515 | + $live_email = wpinv_get_option( 'paypal_email' ); |
|
| 516 | + $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
| 517 | + |
|
| 518 | + $admin_settings['paypal_connect'] = array( |
|
| 519 | + 'type' => 'raw_html', |
|
| 520 | + 'id' => 'paypal_connect', |
|
| 521 | + 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
| 522 | + 'desc' => sprintf( |
|
| 523 | + '<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a></div>%s', |
|
| 524 | + esc_url( self::get_connect_url( false ) ), |
|
| 525 | + __( 'Connect to PayPal', 'invoicing' ), |
|
| 526 | + esc_url( self::get_connect_url( true ) ), |
|
| 527 | + __( 'Connect to PayPal Sandox', 'invoicing' ), |
|
| 528 | + $this->get_js() |
|
| 529 | + ), |
|
| 530 | + ); |
|
| 531 | 531 | |
| 532 | 532 | $admin_settings['paypal_email'] = array( |
| 533 | 533 | 'type' => 'text', |
| 534 | - 'class' => 'live-auth-data', |
|
| 534 | + 'class' => 'live-auth-data', |
|
| 535 | 535 | 'id' => 'paypal_email', |
| 536 | 536 | 'name' => __( 'Live Email Address', 'invoicing' ), |
| 537 | 537 | 'desc' => __( 'The email address of your PayPal account.', 'invoicing' ), |
| 538 | 538 | ); |
| 539 | 539 | |
| 540 | - $admin_settings['paypal_sandbox_email'] = array( |
|
| 540 | + $admin_settings['paypal_sandbox_email'] = array( |
|
| 541 | 541 | 'type' => 'text', |
| 542 | - 'class' => 'sandbox-auth-data', |
|
| 542 | + 'class' => 'sandbox-auth-data', |
|
| 543 | 543 | 'id' => 'paypal_sandbox_email', |
| 544 | 544 | 'name' => __( 'Sandbox Email Address', 'invoicing' ), |
| 545 | 545 | 'desc' => __( 'The email address of your sandbox PayPal account.', 'invoicing' ), |
| 546 | - 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
| 546 | + 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
| 547 | 547 | ); |
| 548 | 548 | |
| 549 | 549 | $admin_settings['paypal_ipn_url'] = array( |
@@ -555,29 +555,29 @@ discard block |
||
| 555 | 555 | 'readonly' => true, |
| 556 | 556 | ); |
| 557 | 557 | |
| 558 | - return $admin_settings; |
|
| 559 | - } |
|
| 558 | + return $admin_settings; |
|
| 559 | + } |
|
| 560 | 560 | |
| 561 | - /** |
|
| 562 | - * Retrieves the PayPal connect URL when using the setup wizzard. |
|
| 563 | - * |
|
| 564 | - * |
|
| 561 | + /** |
|
| 562 | + * Retrieves the PayPal connect URL when using the setup wizzard. |
|
| 563 | + * |
|
| 564 | + * |
|
| 565 | 565 | * @param array $data |
| 566 | 566 | * @return string |
| 567 | - */ |
|
| 568 | - public static function maybe_get_connect_url( $url = '', $data ) { |
|
| 569 | - return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * Retrieves the PayPal connect URL. |
|
| 574 | - * |
|
| 575 | - * |
|
| 567 | + */ |
|
| 568 | + public static function maybe_get_connect_url( $url = '', $data ) { |
|
| 569 | + return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * Retrieves the PayPal connect URL. |
|
| 574 | + * |
|
| 575 | + * |
|
| 576 | 576 | * @param bool $is_sandbox |
| 577 | - * @param string $redirect |
|
| 577 | + * @param string $redirect |
|
| 578 | 578 | * @return string |
| 579 | - */ |
|
| 580 | - public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
| 579 | + */ |
|
| 580 | + public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
| 581 | 581 | |
| 582 | 582 | $redirect_url = add_query_arg( |
| 583 | 583 | array( |
@@ -587,7 +587,7 @@ discard block |
||
| 587 | 587 | 'tab' => 'gateways', |
| 588 | 588 | 'section' => 'paypal', |
| 589 | 589 | 'getpaid-nonce' => wp_create_nonce( 'getpaid-nonce' ), |
| 590 | - 'redirect' => urlencode( $redirect ), |
|
| 590 | + 'redirect' => urlencode( $redirect ), |
|
| 591 | 591 | ), |
| 592 | 592 | admin_url( 'admin.php' ) |
| 593 | 593 | ); |
@@ -602,12 +602,12 @@ discard block |
||
| 602 | 602 | |
| 603 | 603 | } |
| 604 | 604 | |
| 605 | - /** |
|
| 606 | - * Generates settings page js. |
|
| 607 | - * |
|
| 605 | + /** |
|
| 606 | + * Generates settings page js. |
|
| 607 | + * |
|
| 608 | 608 | * @return void |
| 609 | - */ |
|
| 610 | - public static function get_js() { |
|
| 609 | + */ |
|
| 610 | + public static function get_js() { |
|
| 611 | 611 | ob_start(); |
| 612 | 612 | ?> |
| 613 | 613 | <script> |
@@ -643,72 +643,72 @@ discard block |
||
| 643 | 643 | return ob_get_clean(); |
| 644 | 644 | } |
| 645 | 645 | |
| 646 | - /** |
|
| 647 | - * Connects to PayPal. |
|
| 648 | - * |
|
| 649 | - * @param array $data Connection data. |
|
| 650 | - * @return void |
|
| 651 | - */ |
|
| 652 | - public function connect_paypal( $data ) { |
|
| 653 | - |
|
| 654 | - $sandbox = $this->is_sandbox(); |
|
| 655 | - $data = wp_unslash( $data ); |
|
| 656 | - $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
| 657 | - |
|
| 658 | - if ( isset( $data['live_mode'] ) ) { |
|
| 659 | - $sandbox = empty( $data['live_mode'] ); |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
| 663 | - wpinv_update_option( 'paypal_active', 1 ); |
|
| 664 | - |
|
| 665 | - if ( ! empty( $data['error_description'] ) ) { |
|
| 666 | - getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
| 667 | - } else { |
|
| 668 | - |
|
| 669 | - // Retrieve the user info. |
|
| 670 | - $user_info = wp_remote_get( |
|
| 671 | - ! $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', |
|
| 672 | - array( |
|
| 673 | - |
|
| 674 | - 'headers' => array( |
|
| 675 | - 'Authorization' => 'Bearer ' . $access_token, |
|
| 676 | - 'Content-type' => 'application/json', |
|
| 677 | - ) |
|
| 678 | - |
|
| 679 | - ) |
|
| 680 | - ); |
|
| 681 | - |
|
| 682 | - if ( is_wp_error( $user_info ) ) { |
|
| 683 | - getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
| 684 | - } else { |
|
| 685 | - |
|
| 686 | - // Create application. |
|
| 687 | - $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
| 688 | - |
|
| 689 | - if ( $sandbox ) { |
|
| 690 | - wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
| 691 | - wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
| 692 | - set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
| 693 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
| 694 | - } else { |
|
| 695 | - wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
| 696 | - wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
| 697 | - set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
| 698 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
| 699 | - } |
|
| 700 | - |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
| 706 | - |
|
| 707 | - if ( isset( $data['step'] ) ) { |
|
| 708 | - $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
| 709 | - } |
|
| 710 | - wp_redirect( $redirect ); |
|
| 711 | - exit; |
|
| 712 | - } |
|
| 646 | + /** |
|
| 647 | + * Connects to PayPal. |
|
| 648 | + * |
|
| 649 | + * @param array $data Connection data. |
|
| 650 | + * @return void |
|
| 651 | + */ |
|
| 652 | + public function connect_paypal( $data ) { |
|
| 653 | + |
|
| 654 | + $sandbox = $this->is_sandbox(); |
|
| 655 | + $data = wp_unslash( $data ); |
|
| 656 | + $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
| 657 | + |
|
| 658 | + if ( isset( $data['live_mode'] ) ) { |
|
| 659 | + $sandbox = empty( $data['live_mode'] ); |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
| 663 | + wpinv_update_option( 'paypal_active', 1 ); |
|
| 664 | + |
|
| 665 | + if ( ! empty( $data['error_description'] ) ) { |
|
| 666 | + getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
| 667 | + } else { |
|
| 668 | + |
|
| 669 | + // Retrieve the user info. |
|
| 670 | + $user_info = wp_remote_get( |
|
| 671 | + ! $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', |
|
| 672 | + array( |
|
| 673 | + |
|
| 674 | + 'headers' => array( |
|
| 675 | + 'Authorization' => 'Bearer ' . $access_token, |
|
| 676 | + 'Content-type' => 'application/json', |
|
| 677 | + ) |
|
| 678 | + |
|
| 679 | + ) |
|
| 680 | + ); |
|
| 681 | + |
|
| 682 | + if ( is_wp_error( $user_info ) ) { |
|
| 683 | + getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
| 684 | + } else { |
|
| 685 | + |
|
| 686 | + // Create application. |
|
| 687 | + $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
| 688 | + |
|
| 689 | + if ( $sandbox ) { |
|
| 690 | + wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
| 691 | + wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
| 692 | + set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
| 693 | + getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
| 694 | + } else { |
|
| 695 | + wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
| 696 | + wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
| 697 | + set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
| 698 | + getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
| 699 | + } |
|
| 700 | + |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
| 706 | + |
|
| 707 | + if ( isset( $data['step'] ) ) { |
|
| 708 | + $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
| 709 | + } |
|
| 710 | + wp_redirect( $redirect ); |
|
| 711 | + exit; |
|
| 712 | + } |
|
| 713 | 713 | |
| 714 | 714 | } |