@@ -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 | - parent::__construct(); |
|
| 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 = array() ) { |
|
| 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 = array() ) { |
|
| 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 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Paypal Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @var array |
| 26 | 26 | */ |
| 27 | - protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' ); |
|
| 27 | + protected $supports = array('subscription', 'sandbox', 'single_subscription_group'); |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * Payment method order. |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * |
| 60 | 60 | * @var array |
| 61 | 61 | */ |
| 62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
| 62 | + public $currencies = array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR'); |
|
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | 65 | * URL to view a transaction. |
@@ -80,15 +80,15 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | public function __construct() { |
| 82 | 82 | |
| 83 | - $this->title = __( 'PayPal Standard', 'invoicing' ); |
|
| 84 | - $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
|
| 85 | - $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
|
| 86 | - $this->notify_url = wpinv_get_ipn_url( $this->id ); |
|
| 83 | + $this->title = __('PayPal Standard', 'invoicing'); |
|
| 84 | + $this->method_title = __('PayPal Standard', 'invoicing'); |
|
| 85 | + $this->checkout_button_text = __('Proceed to PayPal', 'invoicing'); |
|
| 86 | + $this->notify_url = wpinv_get_ipn_url($this->id); |
|
| 87 | 87 | |
| 88 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
| 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' ) ); |
|
| 88 | + add_filter('getpaid_paypal_args', array($this, 'process_subscription'), 10, 2); |
|
| 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')); |
|
| 92 | 92 | |
| 93 | 93 | parent::__construct(); |
| 94 | 94 | } |
@@ -102,16 +102,16 @@ discard block |
||
| 102 | 102 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
| 103 | 103 | * @return array |
| 104 | 104 | */ |
| 105 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 105 | + public function process_payment($invoice, $submission_data, $submission) { |
|
| 106 | 106 | |
| 107 | 107 | // Get redirect url. |
| 108 | - $paypal_redirect = $this->get_request_url( $invoice ); |
|
| 108 | + $paypal_redirect = $this->get_request_url($invoice); |
|
| 109 | 109 | |
| 110 | 110 | // Add a note about the request url. |
| 111 | 111 | $invoice->add_note( |
| 112 | 112 | sprintf( |
| 113 | - __( 'Redirecting to PayPal: %s', 'invoicing' ), |
|
| 114 | - esc_url( $paypal_redirect ) |
|
| 113 | + __('Redirecting to PayPal: %s', 'invoicing'), |
|
| 114 | + esc_url($paypal_redirect) |
|
| 115 | 115 | ), |
| 116 | 116 | false, |
| 117 | 117 | false, |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | ); |
| 120 | 120 | |
| 121 | 121 | // Redirect to PayPal |
| 122 | - wp_redirect( $paypal_redirect ); |
|
| 122 | + wp_redirect($paypal_redirect); |
|
| 123 | 123 | exit; |
| 124 | 124 | |
| 125 | 125 | } |
@@ -130,21 +130,21 @@ discard block |
||
| 130 | 130 | * @param WPInv_Invoice $invoice Invoice object. |
| 131 | 131 | * @return string |
| 132 | 132 | */ |
| 133 | - public function get_request_url( $invoice ) { |
|
| 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 | - $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
|
| 139 | + $paypal_args = map_deep($this->get_paypal_args($invoice), 'urlencode'); |
|
| 140 | 140 | |
| 141 | - if ( $invoice->is_recurring() ) { |
|
| 141 | + if ($invoice->is_recurring()) { |
|
| 142 | 142 | $paypal_args['bn'] = 'GetPaid_Subscribe_WPS_US'; |
| 143 | 143 | } else { |
| 144 | 144 | $paypal_args['bn'] = 'GetPaid_ShoppingCart_WPS_US'; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - return add_query_arg( $paypal_args, $this->endpoint ); |
|
| 147 | + return add_query_arg($paypal_args, $this->endpoint); |
|
| 148 | 148 | |
| 149 | 149 | } |
| 150 | 150 | |
@@ -154,25 +154,25 @@ discard block |
||
| 154 | 154 | * @param WPInv_Invoice $invoice Invoice object. |
| 155 | 155 | * @return array |
| 156 | 156 | */ |
| 157 | - protected function get_paypal_args( $invoice ) { |
|
| 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 ); |
|
| 160 | + $force_one_line_item = apply_filters('getpaid_paypal_force_one_line_item', true, $invoice); |
|
| 161 | 161 | |
| 162 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
| 162 | + if ($invoice->is_recurring() || (wpinv_use_taxes() && wpinv_prices_include_tax())) { |
|
| 163 | 163 | $force_one_line_item = true; |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | $paypal_args = apply_filters( |
| 167 | 167 | 'getpaid_paypal_args', |
| 168 | 168 | array_merge( |
| 169 | - $this->get_transaction_args( $invoice ), |
|
| 170 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
| 169 | + $this->get_transaction_args($invoice), |
|
| 170 | + $this->get_line_item_args($invoice, $force_one_line_item) |
|
| 171 | 171 | ), |
| 172 | 172 | $invoice |
| 173 | 173 | ); |
| 174 | 174 | |
| 175 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
| 175 | + return $this->fix_request_length($invoice, $paypal_args); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -181,9 +181,9 @@ discard block |
||
| 181 | 181 | * @param WPInv_Invoice $invoice Invoice object. |
| 182 | 182 | * @return array |
| 183 | 183 | */ |
| 184 | - protected function get_transaction_args( $invoice ) { |
|
| 184 | + protected function get_transaction_args($invoice) { |
|
| 185 | 185 | |
| 186 | - $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
| 186 | + $email = $this->is_sandbox($invoice) ? wpinv_get_option('paypal_sandbox_email', wpinv_get_option('paypal_email', '')) : wpinv_get_option('paypal_email', ''); |
|
| 187 | 187 | return array( |
| 188 | 188 | 'cmd' => '_cart', |
| 189 | 189 | 'business' => $email, |
@@ -194,16 +194,16 @@ discard block |
||
| 194 | 194 | 'rm' => is_ssl() ? 2 : 1, |
| 195 | 195 | 'upload' => 1, |
| 196 | 196 | 'currency_code' => $invoice->get_currency(), // https://developer.paypal.com/docs/nvp-soap-api/currency-codes/#paypal |
| 197 | - 'return' => esc_url_raw( $this->get_return_url( $invoice ) ), |
|
| 198 | - 'cancel_return' => esc_url_raw( $invoice->get_checkout_payment_url() ), |
|
| 199 | - 'notify_url' => getpaid_limit_length( $this->notify_url, 255 ), |
|
| 200 | - 'invoice' => getpaid_limit_length( $invoice->get_number(), 127 ), |
|
| 197 | + 'return' => esc_url_raw($this->get_return_url($invoice)), |
|
| 198 | + 'cancel_return' => esc_url_raw($invoice->get_checkout_payment_url()), |
|
| 199 | + 'notify_url' => getpaid_limit_length($this->notify_url, 255), |
|
| 200 | + 'invoice' => getpaid_limit_length($invoice->get_number(), 127), |
|
| 201 | 201 | 'custom' => $invoice->get_id(), |
| 202 | - 'first_name' => getpaid_limit_length( $invoice->get_first_name(), 32 ), |
|
| 203 | - 'last_name' => getpaid_limit_length( $invoice->get_last_name(), 64 ), |
|
| 204 | - 'country' => getpaid_limit_length( $invoice->get_country(), 2 ), |
|
| 205 | - 'email' => getpaid_limit_length( $invoice->get_email(), 127 ), |
|
| 206 | - 'cbt' => get_bloginfo( 'name' ) |
|
| 202 | + 'first_name' => getpaid_limit_length($invoice->get_first_name(), 32), |
|
| 203 | + 'last_name' => getpaid_limit_length($invoice->get_last_name(), 64), |
|
| 204 | + 'country' => getpaid_limit_length($invoice->get_country(), 2), |
|
| 205 | + 'email' => getpaid_limit_length($invoice->get_email(), 127), |
|
| 206 | + 'cbt' => get_bloginfo('name') |
|
| 207 | 207 | ); |
| 208 | 208 | |
| 209 | 209 | } |
@@ -215,30 +215,30 @@ discard block |
||
| 215 | 215 | * @param bool $force_one_line_item Create only one item for this invoice. |
| 216 | 216 | * @return array |
| 217 | 217 | */ |
| 218 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
| 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 ) { |
|
| 222 | - return $this->get_line_item_args_single_item( $invoice ); |
|
| 221 | + if ($force_one_line_item) { |
|
| 222 | + return $this->get_line_item_args_single_item($invoice); |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | // Send each line item individually. |
| 226 | 226 | $line_item_args = array(); |
| 227 | 227 | |
| 228 | 228 | // Prepare line items. |
| 229 | - $this->prepare_line_items( $invoice ); |
|
| 229 | + $this->prepare_line_items($invoice); |
|
| 230 | 230 | |
| 231 | 231 | // Add taxes to the cart |
| 232 | - if ( wpinv_use_taxes() && $invoice->is_taxable() ) { |
|
| 233 | - $line_item_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_tax(), 2 ); |
|
| 232 | + if (wpinv_use_taxes() && $invoice->is_taxable()) { |
|
| 233 | + $line_item_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_tax(), 2); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | // Add discount. |
| 237 | - if ( $invoice->get_total_discount() > 0 ) { |
|
| 238 | - $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
|
| 237 | + if ($invoice->get_total_discount() > 0) { |
|
| 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 | |
@@ -248,11 +248,11 @@ discard block |
||
| 248 | 248 | * @param WPInv_Invoice $invoice Invoice object. |
| 249 | 249 | * @return array |
| 250 | 250 | */ |
| 251 | - protected function get_line_item_args_single_item( $invoice ) { |
|
| 251 | + protected function get_line_item_args_single_item($invoice) { |
|
| 252 | 252 | $this->delete_line_items(); |
| 253 | 253 | |
| 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() ); |
|
| 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()); |
|
| 256 | 256 | |
| 257 | 257 | return $this->get_line_items(); |
| 258 | 258 | } |
@@ -276,19 +276,19 @@ discard block |
||
| 276 | 276 | * |
| 277 | 277 | * @param WPInv_Invoice $invoice Invoice object. |
| 278 | 278 | */ |
| 279 | - protected function prepare_line_items( $invoice ) { |
|
| 279 | + protected function prepare_line_items($invoice) { |
|
| 280 | 280 | $this->delete_line_items(); |
| 281 | 281 | |
| 282 | 282 | // Items. |
| 283 | - foreach ( $invoice->get_items() as $item ) { |
|
| 283 | + foreach ($invoice->get_items() as $item) { |
|
| 284 | 284 | $amount = $item->get_price(); |
| 285 | 285 | $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
| 286 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
| 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 ) { |
|
| 291 | - $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
|
| 290 | + foreach ($invoice->get_fees() as $fee => $data) { |
|
| 291 | + $this->add_line_item($fee, 1, wpinv_sanitize_amount($data['initial_fee'])); |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | } |
@@ -301,15 +301,15 @@ discard block |
||
| 301 | 301 | * @param float $amount Amount. |
| 302 | 302 | * @param string $item_number Item number. |
| 303 | 303 | */ |
| 304 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
| 305 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
| 304 | + protected function add_line_item($item_name, $quantity = 1, $amount = 0.0, $item_number = '') { |
|
| 305 | + $index = (count($this->line_items) / 4) + 1; |
|
| 306 | 306 | |
| 307 | 307 | $item = apply_filters( |
| 308 | 308 | 'getpaid_paypal_line_item', |
| 309 | 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' ), |
|
| 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 | 311 | 'quantity' => (float) $quantity, |
| 312 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
| 312 | + 'amount' => wpinv_sanitize_amount((float) $amount, 2), |
|
| 313 | 313 | 'item_number' => $item_number, |
| 314 | 314 | ), |
| 315 | 315 | $item_name, |
@@ -318,12 +318,12 @@ discard block |
||
| 318 | 318 | $item_number |
| 319 | 319 | ); |
| 320 | 320 | |
| 321 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
| 322 | - $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
|
| 321 | + $this->line_items['item_name_' . $index] = getpaid_limit_length($item['item_name'], 127); |
|
| 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 | /** |
@@ -335,19 +335,19 @@ discard block |
||
| 335 | 335 | * @param array $paypal_args Arguments sent to Paypal in the request. |
| 336 | 336 | * @return array |
| 337 | 337 | */ |
| 338 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
| 338 | + protected function fix_request_length($invoice, $paypal_args) { |
|
| 339 | 339 | $max_paypal_length = 2083; |
| 340 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
| 340 | + $query_candidate = http_build_query($paypal_args, '', '&'); |
|
| 341 | 341 | |
| 342 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
| 342 | + if (strlen($this->endpoint . $query_candidate) <= $max_paypal_length) { |
|
| 343 | 343 | return $paypal_args; |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | return apply_filters( |
| 347 | 347 | 'getpaid_paypal_args', |
| 348 | 348 | array_merge( |
| 349 | - $this->get_transaction_args( $invoice ), |
|
| 350 | - $this->get_line_item_args( $invoice, true ) |
|
| 349 | + $this->get_transaction_args($invoice), |
|
| 350 | + $this->get_line_item_args($invoice, true) |
|
| 351 | 351 | ), |
| 352 | 352 | $invoice |
| 353 | 353 | ); |
@@ -360,10 +360,10 @@ discard block |
||
| 360 | 360 | * @param array $paypal_args PayPal args. |
| 361 | 361 | * @param WPInv_Invoice $invoice Invoice object. |
| 362 | 362 | */ |
| 363 | - public function process_subscription( $paypal_args, $invoice ) { |
|
| 363 | + public function process_subscription($paypal_args, $invoice) { |
|
| 364 | 364 | |
| 365 | 365 | // Make sure this is a subscription. |
| 366 | - if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) { |
|
| 366 | + if (!$invoice->is_recurring() || !$subscription = getpaid_get_invoice_subscription($invoice)) { |
|
| 367 | 367 | return $paypal_args; |
| 368 | 368 | } |
| 369 | 369 | |
@@ -371,23 +371,23 @@ discard block |
||
| 371 | 371 | $paypal_args['cmd'] = '_xclick-subscriptions'; |
| 372 | 372 | |
| 373 | 373 | // Subscription name. |
| 374 | - $paypal_args['item_name'] = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
|
| 374 | + $paypal_args['item_name'] = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number()); |
|
| 375 | 375 | |
| 376 | 376 | // Get subscription args. |
| 377 | - $period = strtoupper( substr( $subscription->get_period(), 0, 1) ); |
|
| 377 | + $period = strtoupper(substr($subscription->get_period(), 0, 1)); |
|
| 378 | 378 | $interval = (int) $subscription->get_frequency(); |
| 379 | 379 | $bill_times = (int) $subscription->get_bill_times(); |
| 380 | - $initial_amount = (float) wpinv_sanitize_amount( $invoice->get_initial_total(), 2 ); |
|
| 381 | - $recurring_amount = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 ); |
|
| 382 | - $subscription_item = $invoice->get_recurring( true ); |
|
| 380 | + $initial_amount = (float) wpinv_sanitize_amount($invoice->get_initial_total(), 2); |
|
| 381 | + $recurring_amount = (float) wpinv_sanitize_amount($invoice->get_recurring_total(), 2); |
|
| 382 | + $subscription_item = $invoice->get_recurring(true); |
|
| 383 | 383 | |
| 384 | 384 | // Convert 365 days to 1 year. |
| 385 | - if ( 'D' == $period && 365 == $interval ) { |
|
| 385 | + if ('D' == $period && 365 == $interval) { |
|
| 386 | 386 | $period = 'Y'; |
| 387 | 387 | $interval = 1; |
| 388 | 388 | } |
| 389 | 389 | |
| 390 | - if ( $subscription_item->has_free_trial() ) { |
|
| 390 | + if ($subscription_item->has_free_trial()) { |
|
| 391 | 391 | |
| 392 | 392 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
| 393 | 393 | |
@@ -397,28 +397,28 @@ discard block |
||
| 397 | 397 | // Trial period. |
| 398 | 398 | $paypal_args['t1'] = $subscription_item->get_trial_period(); |
| 399 | 399 | |
| 400 | - } else if ( $initial_amount != $recurring_amount ) { |
|
| 400 | + } else if ($initial_amount != $recurring_amount) { |
|
| 401 | 401 | |
| 402 | 402 | // No trial period, but initial amount includes a sign-up fee and/or other items, so charge it as a separate period. |
| 403 | 403 | |
| 404 | - if ( 1 == $bill_times ) { |
|
| 404 | + if (1 == $bill_times) { |
|
| 405 | 405 | $param_number = 3; |
| 406 | 406 | } else { |
| 407 | 407 | $param_number = 1; |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | - $paypal_args[ 'a' . $param_number ] = $initial_amount ? $initial_amount : 0; |
|
| 410 | + $paypal_args['a' . $param_number] = $initial_amount ? $initial_amount : 0; |
|
| 411 | 411 | |
| 412 | 412 | // Sign Up interval |
| 413 | - $paypal_args[ 'p' . $param_number ] = $interval; |
|
| 413 | + $paypal_args['p' . $param_number] = $interval; |
|
| 414 | 414 | |
| 415 | 415 | // Sign Up unit of duration |
| 416 | - $paypal_args[ 't' . $param_number ] = $period; |
|
| 416 | + $paypal_args['t' . $param_number] = $period; |
|
| 417 | 417 | |
| 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 | 423 | // Subscription price |
| 424 | 424 | $paypal_args['a3'] = $recurring_amount; |
@@ -432,7 +432,7 @@ discard block |
||
| 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 | 437 | // Non-recurring payments |
| 438 | 438 | $paypal_args['src'] = 0; |
@@ -441,15 +441,15 @@ discard block |
||
| 441 | 441 | |
| 442 | 442 | $paypal_args['src'] = 1; |
| 443 | 443 | |
| 444 | - if ( $bill_times > 0 ) { |
|
| 444 | + if ($bill_times > 0) { |
|
| 445 | 445 | |
| 446 | 446 | // An initial period is being used to charge a sign-up fee |
| 447 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
| 447 | + if ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial()) { |
|
| 448 | 448 | $bill_times--; |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | // Make sure it's not over the max of 52 |
| 452 | - $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
|
| 452 | + $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52); |
|
| 453 | 453 | |
| 454 | 454 | } |
| 455 | 455 | } |
@@ -458,10 +458,10 @@ discard block |
||
| 458 | 458 | $paypal_args['rm'] = 2; |
| 459 | 459 | |
| 460 | 460 | // Get rid of redudant items. |
| 461 | - foreach ( array( 'item_name_1', 'quantity_1', 'amount_1', 'item_number_1' ) as $arg ) { |
|
| 461 | + foreach (array('item_name_1', 'quantity_1', 'amount_1', 'item_number_1') as $arg) { |
|
| 462 | 462 | |
| 463 | - if ( isset( $paypal_args[ $arg ] ) ) { |
|
| 464 | - unset( $paypal_args[ $arg ] ); |
|
| 463 | + if (isset($paypal_args[$arg])) { |
|
| 464 | + unset($paypal_args[$arg]); |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | } |
@@ -480,7 +480,7 @@ discard block |
||
| 480 | 480 | * @return void |
| 481 | 481 | */ |
| 482 | 482 | public function verify_ipn() { |
| 483 | - new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
|
| 483 | + new GetPaid_Paypal_Gateway_IPN_Handler($this); |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | /** |
@@ -489,7 +489,7 @@ discard block |
||
| 489 | 489 | public function sandbox_notice() { |
| 490 | 490 | |
| 491 | 491 | return sprintf( |
| 492 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
| 492 | + __('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing'), |
|
| 493 | 493 | '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
| 494 | 494 | '</a>' |
| 495 | 495 | ); |
@@ -501,30 +501,30 @@ discard block |
||
| 501 | 501 | * |
| 502 | 502 | * @param array $admin_settings |
| 503 | 503 | */ |
| 504 | - public function admin_settings( $admin_settings ) { |
|
| 504 | + public function admin_settings($admin_settings) { |
|
| 505 | 505 | |
| 506 | 506 | $currencies = sprintf( |
| 507 | - __( 'Supported Currencies: %s', 'invoicing' ), |
|
| 508 | - implode( ', ', $this->currencies ) |
|
| 507 | + __('Supported Currencies: %s', 'invoicing'), |
|
| 508 | + implode(', ', $this->currencies) |
|
| 509 | 509 | ); |
| 510 | 510 | |
| 511 | 511 | $admin_settings['paypal_active']['desc'] .= " ($currencies)"; |
| 512 | - $admin_settings['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
|
| 512 | + $admin_settings['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing'); |
|
| 513 | 513 | |
| 514 | 514 | // Access tokens. |
| 515 | - $live_email = wpinv_get_option( 'paypal_email' ); |
|
| 516 | - $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
| 515 | + $live_email = wpinv_get_option('paypal_email'); |
|
| 516 | + $sandbox_email = wpinv_get_option('paypal_sandbox_email'); |
|
| 517 | 517 | |
| 518 | 518 | $admin_settings['paypal_connect'] = array( |
| 519 | 519 | 'type' => 'raw_html', |
| 520 | 520 | 'id' => 'paypal_connect', |
| 521 | - 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
| 521 | + 'name' => __('Connect to PayPal', 'invoicing'), |
|
| 522 | 522 | 'desc' => sprintf( |
| 523 | 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' ), |
|
| 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 | 528 | $this->get_js() |
| 529 | 529 | ), |
| 530 | 530 | ); |
@@ -533,25 +533,25 @@ discard block |
||
| 533 | 533 | 'type' => 'text', |
| 534 | 534 | 'class' => 'live-auth-data', |
| 535 | 535 | 'id' => 'paypal_email', |
| 536 | - 'name' => __( 'Live Email Address', 'invoicing' ), |
|
| 537 | - 'desc' => __( 'The email address of your PayPal account.', 'invoicing' ), |
|
| 536 | + 'name' => __('Live Email Address', 'invoicing'), |
|
| 537 | + 'desc' => __('The email address of your PayPal account.', 'invoicing'), |
|
| 538 | 538 | ); |
| 539 | 539 | |
| 540 | 540 | $admin_settings['paypal_sandbox_email'] = array( |
| 541 | 541 | 'type' => 'text', |
| 542 | 542 | 'class' => 'sandbox-auth-data', |
| 543 | 543 | 'id' => 'paypal_sandbox_email', |
| 544 | - 'name' => __( 'Sandbox Email Address', 'invoicing' ), |
|
| 545 | - 'desc' => __( 'The email address of your sandbox PayPal account.', 'invoicing' ), |
|
| 546 | - 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
| 544 | + 'name' => __('Sandbox Email Address', 'invoicing'), |
|
| 545 | + 'desc' => __('The email address of your sandbox PayPal account.', 'invoicing'), |
|
| 546 | + 'std' => wpinv_get_option('paypal_email', ''), |
|
| 547 | 547 | ); |
| 548 | 548 | |
| 549 | 549 | $admin_settings['paypal_ipn_url'] = array( |
| 550 | 550 | 'type' => 'ipn_url', |
| 551 | 551 | 'id' => 'paypal_ipn_url', |
| 552 | - 'name' => __( 'IPN Url', 'invoicing' ), |
|
| 552 | + 'name' => __('IPN Url', 'invoicing'), |
|
| 553 | 553 | 'std' => $this->notify_url, |
| 554 | - '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>', |
|
| 554 | + '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>', |
|
| 555 | 555 | 'readonly' => true, |
| 556 | 556 | ); |
| 557 | 557 | |
@@ -565,8 +565,8 @@ discard block |
||
| 565 | 565 | * @param array $data |
| 566 | 566 | * @return string |
| 567 | 567 | */ |
| 568 | - public static function maybe_get_connect_url( $url = '', $data = array() ) { |
|
| 569 | - return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
| 568 | + public static function maybe_get_connect_url($url = '', $data = array()) { |
|
| 569 | + return self::get_connect_url(false, urldecode($data['redirect'])); |
|
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | /** |
@@ -577,25 +577,25 @@ discard block |
||
| 577 | 577 | * @param string $redirect |
| 578 | 578 | * @return string |
| 579 | 579 | */ |
| 580 | - public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
| 580 | + public static function get_connect_url($is_sandbox, $redirect = '') { |
|
| 581 | 581 | |
| 582 | 582 | $redirect_url = add_query_arg( |
| 583 | 583 | array( |
| 584 | 584 | 'getpaid-admin-action' => 'connect_paypal', |
| 585 | 585 | 'page' => 'wpinv-settings', |
| 586 | - 'live_mode' => (int) empty( $is_sandbox ), |
|
| 586 | + 'live_mode' => (int) empty($is_sandbox), |
|
| 587 | 587 | 'tab' => 'gateways', |
| 588 | 588 | 'section' => 'paypal', |
| 589 | - 'getpaid-nonce' => wp_create_nonce( 'getpaid-nonce' ), |
|
| 590 | - 'redirect' => urlencode( $redirect ), |
|
| 589 | + 'getpaid-nonce' => wp_create_nonce('getpaid-nonce'), |
|
| 590 | + 'redirect' => urlencode($redirect), |
|
| 591 | 591 | ), |
| 592 | - admin_url( 'admin.php' ) |
|
| 592 | + admin_url('admin.php') |
|
| 593 | 593 | ); |
| 594 | 594 | |
| 595 | 595 | return add_query_arg( |
| 596 | 596 | array( |
| 597 | - 'live_mode' => (int) empty( $is_sandbox ), |
|
| 598 | - 'redirect_url' => urlencode( str_replace( '&', '&', $redirect_url ) ) |
|
| 597 | + 'live_mode' => (int) empty($is_sandbox), |
|
| 598 | + 'redirect_url' => urlencode(str_replace('&', '&', $redirect_url)) |
|
| 599 | 599 | ), |
| 600 | 600 | 'https://ayecode.io/oauth/paypal' |
| 601 | 601 | ); |
@@ -649,26 +649,26 @@ discard block |
||
| 649 | 649 | * @param array $data Connection data. |
| 650 | 650 | * @return void |
| 651 | 651 | */ |
| 652 | - public function connect_paypal( $data ) { |
|
| 652 | + public function connect_paypal($data) { |
|
| 653 | 653 | |
| 654 | 654 | $sandbox = $this->is_sandbox(); |
| 655 | - $data = wp_unslash( $data ); |
|
| 656 | - $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
| 655 | + $data = wp_unslash($data); |
|
| 656 | + $access_token = empty($data['access_token']) ? '' : sanitize_text_field($data['access_token']); |
|
| 657 | 657 | |
| 658 | - if ( isset( $data['live_mode'] ) ) { |
|
| 659 | - $sandbox = empty( $data['live_mode'] ); |
|
| 658 | + if (isset($data['live_mode'])) { |
|
| 659 | + $sandbox = empty($data['live_mode']); |
|
| 660 | 660 | } |
| 661 | 661 | |
| 662 | - wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
| 663 | - wpinv_update_option( 'paypal_active', 1 ); |
|
| 662 | + wpinv_update_option('paypal_sandbox', (int) $sandbox); |
|
| 663 | + wpinv_update_option('paypal_active', 1); |
|
| 664 | 664 | |
| 665 | - if ( ! empty( $data['error_description'] ) ) { |
|
| 666 | - getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
| 665 | + if (!empty($data['error_description'])) { |
|
| 666 | + getpaid_admin()->show_error(wp_kses_post(urldecode($data['error_description']))); |
|
| 667 | 667 | } else { |
| 668 | 668 | |
| 669 | 669 | // Retrieve the user info. |
| 670 | 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', |
|
| 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 | 672 | array( |
| 673 | 673 | |
| 674 | 674 | 'headers' => array( |
@@ -679,35 +679,35 @@ discard block |
||
| 679 | 679 | ) |
| 680 | 680 | ); |
| 681 | 681 | |
| 682 | - if ( is_wp_error( $user_info ) ) { |
|
| 683 | - getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
| 682 | + if (is_wp_error($user_info)) { |
|
| 683 | + getpaid_admin()->show_error(wp_kses_post($user_info->get_error_message())); |
|
| 684 | 684 | } else { |
| 685 | 685 | |
| 686 | 686 | // Create application. |
| 687 | - $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
| 687 | + $user_info = json_decode(wp_remote_retrieve_body($user_info)); |
|
| 688 | 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' ) ); |
|
| 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 | 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' ) ); |
|
| 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 | 699 | } |
| 700 | 700 | |
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | } |
| 704 | 704 | |
| 705 | - $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
| 705 | + $redirect = empty($data['redirect']) ? admin_url('admin.php?page=wpinv-settings&tab=gateways§ion=paypal') : urldecode($data['redirect']); |
|
| 706 | 706 | |
| 707 | - if ( isset( $data['step'] ) ) { |
|
| 708 | - $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
| 707 | + if (isset($data['step'])) { |
|
| 708 | + $redirect = add_query_arg('step', $data['step'], $redirect); |
|
| 709 | 709 | } |
| 710 | - wp_redirect( $redirect ); |
|
| 710 | + wp_redirect($redirect); |
|
| 711 | 711 | exit; |
| 712 | 712 | } |
| 713 | 713 | |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @package Invoicing |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * @deprecated |
@@ -19,48 +19,48 @@ discard block |
||
| 19 | 19 | * @deprecated |
| 20 | 20 | */ |
| 21 | 21 | function wpinv_get_invoice_cart() { |
| 22 | - return wpinv_get_invoice( getpaid_get_current_invoice_id() ); |
|
| 22 | + return wpinv_get_invoice(getpaid_get_current_invoice_id()); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * @deprecated |
| 27 | 27 | */ |
| 28 | -function wpinv_get_invoice_description( $invoice ) { |
|
| 29 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 28 | +function wpinv_get_invoice_description($invoice) { |
|
| 29 | + $invoice = new WPInv_Invoice($invoice); |
|
| 30 | 30 | return $invoice->get_description(); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * @deprecated |
| 35 | 35 | */ |
| 36 | -function wpinv_get_invoice_currency_code( $invoice ) { |
|
| 37 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 36 | +function wpinv_get_invoice_currency_code($invoice) { |
|
| 37 | + $invoice = new WPInv_Invoice($invoice); |
|
| 38 | 38 | return $invoice->get_currency(); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * @deprecated |
| 43 | 43 | */ |
| 44 | -function wpinv_get_payment_user_email( $invoice ) { |
|
| 45 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 44 | +function wpinv_get_payment_user_email($invoice) { |
|
| 45 | + $invoice = new WPInv_Invoice($invoice); |
|
| 46 | 46 | return $invoice->get_email(); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * @deprecated |
| 51 | 51 | */ |
| 52 | -function wpinv_get_user_id( $invoice ) { |
|
| 53 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 52 | +function wpinv_get_user_id($invoice) { |
|
| 53 | + $invoice = new WPInv_Invoice($invoice); |
|
| 54 | 54 | return $invoice->get_user_id(); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * @deprecated |
| 59 | 59 | */ |
| 60 | -function wpinv_get_invoice_status( $invoice, $return_label = false ) { |
|
| 61 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 60 | +function wpinv_get_invoice_status($invoice, $return_label = false) { |
|
| 61 | + $invoice = new WPInv_Invoice($invoice); |
|
| 62 | 62 | |
| 63 | - if ( $return_label ) { |
|
| 63 | + if ($return_label) { |
|
| 64 | 64 | return $invoice->get_status_nicename(); |
| 65 | 65 | } |
| 66 | 66 | |
@@ -70,10 +70,10 @@ discard block |
||
| 70 | 70 | /** |
| 71 | 71 | * @deprecated |
| 72 | 72 | */ |
| 73 | -function wpinv_get_payment_gateway( $invoice, $return_label = false ) { |
|
| 74 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 73 | +function wpinv_get_payment_gateway($invoice, $return_label = false) { |
|
| 74 | + $invoice = new WPInv_Invoice($invoice); |
|
| 75 | 75 | |
| 76 | - if ( $return_label ) { |
|
| 76 | + if ($return_label) { |
|
| 77 | 77 | return $invoice->get_gateway_title(); |
| 78 | 78 | } |
| 79 | 79 | |
@@ -83,75 +83,75 @@ discard block |
||
| 83 | 83 | /** |
| 84 | 84 | * @deprecated |
| 85 | 85 | */ |
| 86 | -function wpinv_get_payment_gateway_name( $invoice ) { |
|
| 87 | - return wpinv_get_payment_gateway( $invoice, true ); |
|
| 86 | +function wpinv_get_payment_gateway_name($invoice) { |
|
| 87 | + return wpinv_get_payment_gateway($invoice, true); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
| 91 | 91 | * @deprecated |
| 92 | 92 | */ |
| 93 | -function wpinv_get_payment_transaction_id( $invoice ) { |
|
| 94 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 93 | +function wpinv_get_payment_transaction_id($invoice) { |
|
| 94 | + $invoice = new WPInv_Invoice($invoice); |
|
| 95 | 95 | return $invoice->get_transaction_id(); |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
| 99 | 99 | * @deprecated |
| 100 | 100 | */ |
| 101 | -function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
| 102 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 103 | - return $invoice->get_meta( $meta_key, $single ); |
|
| 101 | +function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) { |
|
| 102 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 103 | + return $invoice->get_meta($meta_key, $single); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
| 107 | 107 | * @deprecated |
| 108 | 108 | */ |
| 109 | -function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '' ) { |
|
| 110 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 111 | - return $invoice->update_meta_data( $meta_key, $meta_value ); |
|
| 109 | +function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '') { |
|
| 110 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 111 | + return $invoice->update_meta_data($meta_key, $meta_value); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
| 115 | 115 | * @deprecated |
| 116 | 116 | */ |
| 117 | -function wpinv_get_items( $invoice = 0 ) { |
|
| 118 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 117 | +function wpinv_get_items($invoice = 0) { |
|
| 118 | + $invoice = new WPInv_Invoice($invoice); |
|
| 119 | 119 | return $invoice->get_items(); |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
| 123 | 123 | * @deprecated |
| 124 | 124 | */ |
| 125 | -function wpinv_get_fees( $invoice = 0 ) { |
|
| 126 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 125 | +function wpinv_get_fees($invoice = 0) { |
|
| 126 | + $invoice = new WPInv_Invoice($invoice); |
|
| 127 | 127 | return $invoice->get_fees(); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
| 131 | 131 | * @deprecated |
| 132 | 132 | */ |
| 133 | -function wpinv_get_invoice_ip( $invoice ) { |
|
| 134 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 133 | +function wpinv_get_invoice_ip($invoice) { |
|
| 134 | + $invoice = new WPInv_Invoice($invoice); |
|
| 135 | 135 | return $invoice->get_ip(); |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
| 139 | 139 | * @deprecated |
| 140 | 140 | */ |
| 141 | -function wpinv_get_invoice_user_info( $invoice ) { |
|
| 142 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 141 | +function wpinv_get_invoice_user_info($invoice) { |
|
| 142 | + $invoice = new WPInv_Invoice($invoice); |
|
| 143 | 143 | return $invoice->get_user_info(); |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
| 147 | 147 | * @deprecated |
| 148 | 148 | */ |
| 149 | -function wpinv_subtotal( $invoice = 0, $currency = false ) { |
|
| 150 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 149 | +function wpinv_subtotal($invoice = 0, $currency = false) { |
|
| 150 | + $invoice = new WPInv_Invoice($invoice); |
|
| 151 | 151 | $subtotal = $invoice->get_subtotal(); |
| 152 | 152 | |
| 153 | - if ( $currency ) { |
|
| 154 | - return wpinv_price( $subtotal, $invoice->get_currency() ); |
|
| 153 | + if ($currency) { |
|
| 154 | + return wpinv_price($subtotal, $invoice->get_currency()); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | return $subtotal; |
@@ -160,12 +160,12 @@ discard block |
||
| 160 | 160 | /** |
| 161 | 161 | * @deprecated |
| 162 | 162 | */ |
| 163 | -function wpinv_tax( $invoice = 0, $currency = false ) { |
|
| 164 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 163 | +function wpinv_tax($invoice = 0, $currency = false) { |
|
| 164 | + $invoice = new WPInv_Invoice($invoice); |
|
| 165 | 165 | $tax = $invoice->get_total_tax(); |
| 166 | 166 | |
| 167 | - if ( $currency ) { |
|
| 168 | - return wpinv_price( $tax, $invoice->get_currency() ); |
|
| 167 | + if ($currency) { |
|
| 168 | + return wpinv_price($tax, $invoice->get_currency()); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | return $tax; |
@@ -174,12 +174,12 @@ discard block |
||
| 174 | 174 | /** |
| 175 | 175 | * @deprecated |
| 176 | 176 | */ |
| 177 | -function wpinv_discount( $invoice = 0, $currency = false ) { |
|
| 178 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 177 | +function wpinv_discount($invoice = 0, $currency = false) { |
|
| 178 | + $invoice = new WPInv_Invoice($invoice); |
|
| 179 | 179 | $discount = $invoice->get_total_discount(); |
| 180 | 180 | |
| 181 | - if ( $currency ) { |
|
| 182 | - return wpinv_price( $discount, $invoice->get_currency() ); |
|
| 181 | + if ($currency) { |
|
| 182 | + return wpinv_price($discount, $invoice->get_currency()); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | return $discount; |
@@ -188,20 +188,20 @@ discard block |
||
| 188 | 188 | /** |
| 189 | 189 | * @deprecated |
| 190 | 190 | */ |
| 191 | -function wpinv_discount_code( $invoice = 0 ) { |
|
| 192 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 191 | +function wpinv_discount_code($invoice = 0) { |
|
| 192 | + $invoice = new WPInv_Invoice($invoice); |
|
| 193 | 193 | return $invoice->get_discount_code(); |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /** |
| 197 | 197 | * @deprecated |
| 198 | 198 | */ |
| 199 | -function wpinv_payment_total( $invoice = 0, $currency = false ) { |
|
| 200 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 199 | +function wpinv_payment_total($invoice = 0, $currency = false) { |
|
| 200 | + $invoice = new WPInv_Invoice($invoice); |
|
| 201 | 201 | $total = $invoice->get_total(); |
| 202 | 202 | |
| 203 | - if ( $currency ) { |
|
| 204 | - return wpinv_price( $total, $invoice->get_currency() ); |
|
| 203 | + if ($currency) { |
|
| 204 | + return wpinv_price($total, $invoice->get_currency()); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | return $total; |
@@ -210,51 +210,51 @@ discard block |
||
| 210 | 210 | /** |
| 211 | 211 | * @deprecated |
| 212 | 212 | */ |
| 213 | -function wpinv_get_date_created( $invoice = 0, $format = '' ) { |
|
| 214 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 213 | +function wpinv_get_date_created($invoice = 0, $format = '') { |
|
| 214 | + $invoice = new WPInv_Invoice($invoice); |
|
| 215 | 215 | |
| 216 | - $format = ! empty( $format ) ? $format : get_option( 'date_format' ); |
|
| 216 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
| 217 | 217 | $date_created = $invoice->get_created_date(); |
| 218 | 218 | |
| 219 | - return empty( $date_created ) ? date_i18n( $format, strtotime( $date_created ) ) : ''; |
|
| 219 | + return empty($date_created) ? date_i18n($format, strtotime($date_created)) : ''; |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
| 223 | 223 | * @deprecated |
| 224 | 224 | */ |
| 225 | -function wpinv_get_invoice_date( $invoice = 0, $format = '' ) { |
|
| 226 | - wpinv_get_date_created( $invoice, $format ); |
|
| 225 | +function wpinv_get_invoice_date($invoice = 0, $format = '') { |
|
| 226 | + wpinv_get_date_created($invoice, $format); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /** |
| 230 | 230 | * @deprecated |
| 231 | 231 | */ |
| 232 | -function wpinv_get_invoice_vat_number( $invoice = 0 ) { |
|
| 233 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 232 | +function wpinv_get_invoice_vat_number($invoice = 0) { |
|
| 233 | + $invoice = new WPInv_Invoice($invoice); |
|
| 234 | 234 | return $invoice->get_vat_number(); |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
| 238 | 238 | * @deprecated |
| 239 | 239 | */ |
| 240 | -function wpinv_insert_payment_note( $invoice = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) { |
|
| 241 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 242 | - return $invoice->add_note( $note, $user_type, $added_by_user, $system ); |
|
| 240 | +function wpinv_insert_payment_note($invoice = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) { |
|
| 241 | + $invoice = new WPInv_Invoice($invoice); |
|
| 242 | + return $invoice->add_note($note, $user_type, $added_by_user, $system); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
| 246 | 246 | * @deprecated |
| 247 | 247 | */ |
| 248 | -function wpinv_get_payment_key( $invoice = 0 ) { |
|
| 249 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 248 | +function wpinv_get_payment_key($invoice = 0) { |
|
| 249 | + $invoice = new WPInv_Invoice($invoice); |
|
| 250 | 250 | return $invoice->get_key(); |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
| 254 | 254 | * @deprecated |
| 255 | 255 | */ |
| 256 | -function wpinv_get_invoice_number( $invoice = 0 ) { |
|
| 257 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 256 | +function wpinv_get_invoice_number($invoice = 0) { |
|
| 257 | + $invoice = new WPInv_Invoice($invoice); |
|
| 258 | 258 | return $invoice->get_number(); |
| 259 | 259 | } |
| 260 | 260 | |
@@ -401,9 +401,9 @@ discard block |
||
| 401 | 401 | /** |
| 402 | 402 | * @deprecated |
| 403 | 403 | */ |
| 404 | -function wpinv_update_payment_status( $invoice, $new_status = 'publish' ) { |
|
| 405 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 406 | - return $invoice->update_status( $new_status ); |
|
| 404 | +function wpinv_update_payment_status($invoice, $new_status = 'publish') { |
|
| 405 | + $invoice = new WPInv_Invoice($invoice); |
|
| 406 | + return $invoice->update_status($new_status); |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | /** |
@@ -456,22 +456,22 @@ discard block |
||
| 456 | 456 | /** |
| 457 | 457 | * @deprecated |
| 458 | 458 | */ |
| 459 | -function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) { |
|
| 459 | +function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') { |
|
| 460 | 460 | |
| 461 | 461 | // Fetch the invoice. |
| 462 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 462 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 463 | 463 | |
| 464 | - if ( 0 == $invoice->get_id() ) { |
|
| 464 | + if (0 == $invoice->get_id()) { |
|
| 465 | 465 | return false; |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | // Prepare the transaction id. |
| 469 | - if ( empty( $transaction_id ) ) { |
|
| 469 | + if (empty($transaction_id)) { |
|
| 470 | 470 | $transaction_id = $invoice_id; |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | // Set the transaction id; |
| 474 | - $invoice->set_transaction_id( apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice ) ); |
|
| 474 | + $invoice->set_transaction_id(apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice)); |
|
| 475 | 475 | |
| 476 | 476 | // Save the invoice. |
| 477 | 477 | return $invoice->save(); |
@@ -484,12 +484,12 @@ discard block |
||
| 484 | 484 | * @param WPInv_Invoice $invoice |
| 485 | 485 | * @param string $gateway |
| 486 | 486 | */ |
| 487 | -function wpinv_send_to_gateway( $gateway, $invoice ) { |
|
| 487 | +function wpinv_send_to_gateway($gateway, $invoice) { |
|
| 488 | 488 | |
| 489 | 489 | $payment_data = array( |
| 490 | 490 | 'invoice_id' => $invoice->get_id(), |
| 491 | 491 | 'items' => $invoice->get_cart_details(), |
| 492 | - 'cart_discounts' => array( $invoice->get_discount_code() ), |
|
| 492 | + 'cart_discounts' => array($invoice->get_discount_code()), |
|
| 493 | 493 | 'fees' => $invoice->get_total_fees(), |
| 494 | 494 | 'subtotal' => $invoice->get_subtotal(), |
| 495 | 495 | 'discount' => $invoice->get_total_discount(), |
@@ -497,16 +497,16 @@ discard block |
||
| 497 | 497 | 'price' => $invoice->get_total(), |
| 498 | 498 | 'invoice_key' => $invoice->get_key(), |
| 499 | 499 | 'user_email' => $invoice->get_email(), |
| 500 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
| 500 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
| 501 | 501 | 'user_info' => $invoice->get_user_info(), |
| 502 | - 'post_data' => stripslashes_deep( $_POST ), |
|
| 502 | + 'post_data' => stripslashes_deep($_POST), |
|
| 503 | 503 | 'cart_details' => $invoice->get_cart_details(), |
| 504 | 504 | 'gateway' => $gateway, |
| 505 | 505 | 'card_info' => array(), |
| 506 | 506 | 'gateway_nonce' => wp_create_nonce('wpi-gateway'), |
| 507 | 507 | ); |
| 508 | 508 | |
| 509 | - do_action( 'wpinv_gateway_' . $gateway, $payment_data ); |
|
| 509 | + do_action('wpinv_gateway_' . $gateway, $payment_data); |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | /** |
@@ -519,10 +519,10 @@ discard block |
||
| 519 | 519 | /** |
| 520 | 520 | * @deprecated |
| 521 | 521 | */ |
| 522 | -function wpinv_die( $message = '', $title = '', $status = 400 ) { |
|
| 523 | - add_filter( 'wp_die_ajax_handler', 'wpinv_die_handler', 10, 3 ); |
|
| 524 | - add_filter( 'wp_die_handler', 'wpinv_die_handler', 10, 3 ); |
|
| 525 | - wp_die( $message, $title, array( 'response' => $status )); |
|
| 522 | +function wpinv_die($message = '', $title = '', $status = 400) { |
|
| 523 | + add_filter('wp_die_ajax_handler', 'wpinv_die_handler', 10, 3); |
|
| 524 | + add_filter('wp_die_handler', 'wpinv_die_handler', 10, 3); |
|
| 525 | + wp_die($message, $title, array('response' => $status)); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | /** |
@@ -640,14 +640,14 @@ discard block |
||
| 640 | 640 | /** |
| 641 | 641 | * @deprecated |
| 642 | 642 | */ |
| 643 | -function wpinv_invoice_status_label( $status, $status_display = '' ) { |
|
| 644 | - return empty( $status_display ) ? sanitize_text_field( $status ) : sanitize_text_field( $status_display ); |
|
| 643 | +function wpinv_invoice_status_label($status, $status_display = '') { |
|
| 644 | + return empty($status_display) ? sanitize_text_field($status) : sanitize_text_field($status_display); |
|
| 645 | 645 | } |
| 646 | 646 | |
| 647 | 647 | /** |
| 648 | 648 | * @deprecated |
| 649 | 649 | */ |
| 650 | -function wpinv_clean_invoice_number( $number ) { |
|
| 650 | +function wpinv_clean_invoice_number($number) { |
|
| 651 | 651 | return $number; |
| 652 | 652 | } |
| 653 | 653 | |
@@ -852,12 +852,12 @@ discard block |
||
| 852 | 852 | /** |
| 853 | 853 | * @deprecated |
| 854 | 854 | */ |
| 855 | -function wpinv_item_show_price( $item_id = 0, $echo = true ) { |
|
| 855 | +function wpinv_item_show_price($item_id = 0, $echo = true) { |
|
| 856 | 856 | |
| 857 | - if ( $echo ) { |
|
| 858 | - echo wpinv_item_price( $item_id ); |
|
| 857 | + if ($echo) { |
|
| 858 | + echo wpinv_item_price($item_id); |
|
| 859 | 859 | } else { |
| 860 | - return wpinv_item_price( $item_id ); |
|
| 860 | + return wpinv_item_price($item_id); |
|
| 861 | 861 | } |
| 862 | 862 | |
| 863 | 863 | } |
@@ -1272,6 +1272,6 @@ discard block |
||
| 1272 | 1272 | * @return WPInv_Subscription|bool |
| 1273 | 1273 | * @deprecated |
| 1274 | 1274 | */ |
| 1275 | -function wpinv_get_subscription( $invoice ) { |
|
| 1276 | - return wpinv_get_invoice_subscription( $invoice ); |
|
| 1275 | +function wpinv_get_subscription($invoice) { |
|
| 1276 | + return wpinv_get_invoice_subscription($invoice); |
|
| 1277 | 1277 | } |