@@ -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 | |
@@ -12,60 +12,60 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | <form method="post" class="text-center card-body"> |
| 14 | 14 | <div class="gp-wizard-payments"> |
| 15 | - <h2 class="gd-settings-title h3 "><?php _e( 'Gateway Setup', 'invoicing' ); ?></h2> |
|
| 16 | - <p><?php _e( 'Below are a few gateways that can be setup in a few seconds.', 'invoicing' ); ?> |
|
| 15 | + <h2 class="gd-settings-title h3 "><?php _e('Gateway Setup', 'invoicing'); ?></h2> |
|
| 16 | + <p><?php _e('Below are a few gateways that can be setup in a few seconds.', 'invoicing'); ?> |
|
| 17 | 17 | <br> |
| 18 | - <?php _e( 'We have 20+ Gateways that can be setup later.', 'invoicing' ); ?> |
|
| 18 | + <?php _e('We have 20+ Gateways that can be setup later.', 'invoicing'); ?> |
|
| 19 | 19 | </p> |
| 20 | 20 | |
| 21 | 21 | <ul class="list-group"> |
| 22 | 22 | |
| 23 | 23 | <li class="list-group-item d-flex justify-content-between align-items-center"> |
| 24 | - <span class="mr-auto"><img src="<?php echo esc_url( WPINV_PLUGIN_URL . 'assets/images/stripe-verified.svg' );?>" class="ml-n2" alt="Stripe"></span> |
|
| 25 | - <?php if ( false === wpinv_get_option( 'stripe_live_connect_account_id' ) ) : ?> |
|
| 24 | + <span class="mr-auto"><img src="<?php echo esc_url(WPINV_PLUGIN_URL . 'assets/images/stripe-verified.svg'); ?>" class="ml-n2" alt="Stripe"></span> |
|
| 25 | + <?php if (false === wpinv_get_option('stripe_live_connect_account_id')) : ?> |
|
| 26 | 26 | <a href="<?php echo wp_nonce_url( |
| 27 | 27 | add_query_arg( |
| 28 | 28 | array( |
| 29 | 29 | 'getpaid-admin-action' => 'connect_gateway', |
| 30 | 30 | 'plugin' => 'stripe', |
| 31 | - 'redirect' => urlencode( add_query_arg( 'step', 'payments' ) ), |
|
| 31 | + 'redirect' => urlencode(add_query_arg('step', 'payments')), |
|
| 32 | 32 | ), |
| 33 | 33 | admin_url() |
| 34 | 34 | ), |
| 35 | 35 | 'getpaid-nonce', |
| 36 | 36 | 'getpaid-nonce' |
| 37 | 37 | ); ?>" |
| 38 | - class="btn btn-sm btn-outline-primary"><?php _e( 'Connect', 'invoicing' ); ?></a> |
|
| 38 | + class="btn btn-sm btn-outline-primary"><?php _e('Connect', 'invoicing'); ?></a> |
|
| 39 | 39 | <?php else: ?> |
| 40 | - <span class="btn btn-sm btn-success"><?php _e( 'Connected', 'invoicing' ); ?></span> |
|
| 40 | + <span class="btn btn-sm btn-success"><?php _e('Connected', 'invoicing'); ?></span> |
|
| 41 | 41 | <?php endif; ?> |
| 42 | 42 | </li> |
| 43 | 43 | |
| 44 | 44 | <li class="list-group-item d-flex justify-content-between align-items-center"> |
| 45 | - <span class="mr-auto"><img src="<?php echo esc_url( WPINV_PLUGIN_URL . 'assets/images/pp-logo-150px.webp' );?>" class="" alt="PayPal" height="25"></span> |
|
| 46 | - <?php if ( false === get_transient( 'getpaid_paypal_access_token' ) ) : ?> |
|
| 45 | + <span class="mr-auto"><img src="<?php echo esc_url(WPINV_PLUGIN_URL . 'assets/images/pp-logo-150px.webp'); ?>" class="" alt="PayPal" height="25"></span> |
|
| 46 | + <?php if (false === get_transient('getpaid_paypal_access_token')) : ?> |
|
| 47 | 47 | <a href="<?php echo wp_nonce_url( |
| 48 | 48 | add_query_arg( |
| 49 | 49 | array( |
| 50 | 50 | 'getpaid-admin-action' => 'connect_gateway', |
| 51 | 51 | 'plugin' => 'paypal', |
| 52 | - 'redirect' => urlencode( add_query_arg( 'step', 'payments' ) ), |
|
| 52 | + 'redirect' => urlencode(add_query_arg('step', 'payments')), |
|
| 53 | 53 | ), |
| 54 | 54 | admin_url() |
| 55 | 55 | ), |
| 56 | 56 | 'getpaid-nonce', |
| 57 | 57 | 'getpaid-nonce' |
| 58 | 58 | ); ?>" |
| 59 | - class="btn btn-sm btn-outline-primary"><?php _e( 'Connect', 'invoicing' ); ?></a> |
|
| 59 | + class="btn btn-sm btn-outline-primary"><?php _e('Connect', 'invoicing'); ?></a> |
|
| 60 | 60 | <?php else: ?> |
| 61 | - <span class="btn btn-sm btn-success"><?php _e( 'Connected', 'invoicing' ); ?></span> |
|
| 61 | + <span class="btn btn-sm btn-success"><?php _e('Connected', 'invoicing'); ?></span> |
|
| 62 | 62 | <?php endif; ?> |
| 63 | 63 | </li> |
| 64 | 64 | |
| 65 | 65 | <li class="list-group-item d-flex justify-content-between align-items-center"> |
| 66 | - <span class="mr-auto"><?php _e( 'Test Getway', 'invoicing' ); ?></span> |
|
| 66 | + <span class="mr-auto"><?php _e('Test Getway', 'invoicing'); ?></span> |
|
| 67 | 67 | <div class="custom-control custom-switch"> |
| 68 | - <input type="checkbox" name="enable-manual-gateway" class="custom-control-input" id="enable-manual-gateway" <?php checked( wpinv_is_gateway_active( 'manual' ) ); ?>> |
|
| 68 | + <input type="checkbox" name="enable-manual-gateway" class="custom-control-input" id="enable-manual-gateway" <?php checked(wpinv_is_gateway_active('manual')); ?>> |
|
| 69 | 69 | <label class="custom-control-label" for="enable-manual-gateway"></label> |
| 70 | 70 | </div> |
| 71 | 71 | </li> |
@@ -74,10 +74,10 @@ discard block |
||
| 74 | 74 | </div> |
| 75 | 75 | |
| 76 | 76 | <p class="gp-setup-actions step text-center mt-4"> |
| 77 | - <input type="submit" class="btn btn-primary" value="<?php esc_attr_e( 'Continue', 'invoicing' ); ?>" /> |
|
| 77 | + <input type="submit" class="btn btn-primary" value="<?php esc_attr_e('Continue', 'invoicing'); ?>" /> |
|
| 78 | 78 | </p> |
| 79 | 79 | |
| 80 | - <?php getpaid_hidden_field( 'save_step', 1 ); ?> |
|
| 81 | - <?php wp_nonce_field( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); ?> |
|
| 80 | + <?php getpaid_hidden_field('save_step', 1); ?> |
|
| 81 | + <?php wp_nonce_field('getpaid-setup-wizard', 'getpaid-setup-wizard'); ?> |
|
| 82 | 82 | </form> |
| 83 | 83 | </div> |
@@ -36,8 +36,11 @@ discard block |
||
| 36 | 36 | 'getpaid-nonce' |
| 37 | 37 | ); ?>" |
| 38 | 38 | class="btn btn-sm btn-outline-primary"><?php _e( 'Connect', 'invoicing' ); ?></a> |
| 39 | - <?php else: ?> |
|
| 40 | - <span class="btn btn-sm btn-success"><?php _e( 'Connected', 'invoicing' ); ?></span> |
|
| 39 | + <?php else { |
|
| 40 | + : ?> |
|
| 41 | + <span class="btn btn-sm btn-success"><?php _e( 'Connected', 'invoicing' ); |
|
| 42 | +} |
|
| 43 | +?></span> |
|
| 41 | 44 | <?php endif; ?> |
| 42 | 45 | </li> |
| 43 | 46 | |
@@ -57,8 +60,11 @@ discard block |
||
| 57 | 60 | 'getpaid-nonce' |
| 58 | 61 | ); ?>" |
| 59 | 62 | class="btn btn-sm btn-outline-primary"><?php _e( 'Connect', 'invoicing' ); ?></a> |
| 60 | - <?php else: ?> |
|
| 61 | - <span class="btn btn-sm btn-success"><?php _e( 'Connected', 'invoicing' ); ?></span> |
|
| 63 | + <?php else { |
|
| 64 | + : ?> |
|
| 65 | + <span class="btn btn-sm btn-success"><?php _e( 'Connected', 'invoicing' ); |
|
| 66 | +} |
|
| 67 | +?></span> |
|
| 62 | 68 | <?php endif; ?> |
| 63 | 69 | </li> |
| 64 | 70 | |
@@ -13,96 +13,96 @@ discard block |
||
| 13 | 13 | class GetPaid_Paypal_Gateway extends GetPaid_Payment_Gateway { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Payment method id. |
|
| 17 | - * |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 16 | + * Payment method id. |
|
| 17 | + * |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | 20 | public $id = 'paypal'; |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * An array of features that this gateway supports. |
|
| 24 | - * |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 23 | + * An array of features that this gateway supports. |
|
| 24 | + * |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | 27 | protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' ); |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Payment method order. |
|
| 31 | - * |
|
| 32 | - * @var int |
|
| 33 | - */ |
|
| 30 | + * Payment method order. |
|
| 31 | + * |
|
| 32 | + * @var int |
|
| 33 | + */ |
|
| 34 | 34 | public $order = 1; |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | - * Stores line items to send to PayPal. |
|
| 38 | - * |
|
| 39 | - * @var array |
|
| 40 | - */ |
|
| 37 | + * Stores line items to send to PayPal. |
|
| 38 | + * |
|
| 39 | + * @var array |
|
| 40 | + */ |
|
| 41 | 41 | protected $line_items = array(); |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | - * Endpoint for requests from PayPal. |
|
| 45 | - * |
|
| 46 | - * @var string |
|
| 47 | - */ |
|
| 48 | - protected $notify_url; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Endpoint for requests to PayPal. |
|
| 52 | - * |
|
| 53 | - * @var string |
|
| 54 | - */ |
|
| 44 | + * Endpoint for requests from PayPal. |
|
| 45 | + * |
|
| 46 | + * @var string |
|
| 47 | + */ |
|
| 48 | + protected $notify_url; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Endpoint for requests to PayPal. |
|
| 52 | + * |
|
| 53 | + * @var string |
|
| 54 | + */ |
|
| 55 | 55 | protected $endpoint; |
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | - * Currencies this gateway is allowed for. |
|
| 59 | - * |
|
| 60 | - * @var array |
|
| 61 | - */ |
|
| 62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
| 58 | + * Currencies this gateway is allowed for. |
|
| 59 | + * |
|
| 60 | + * @var array |
|
| 61 | + */ |
|
| 62 | + public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | - * URL to view a transaction. |
|
| 66 | - * |
|
| 67 | - * @var string |
|
| 68 | - */ |
|
| 65 | + * URL to view a transaction. |
|
| 66 | + * |
|
| 67 | + * @var string |
|
| 68 | + */ |
|
| 69 | 69 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | - * URL to view a subscription. |
|
| 73 | - * |
|
| 74 | - * @var string |
|
| 75 | - */ |
|
| 76 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
| 72 | + * URL to view a subscription. |
|
| 73 | + * |
|
| 74 | + * @var string |
|
| 75 | + */ |
|
| 76 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | - * Class constructor. |
|
| 80 | - */ |
|
| 81 | - public function __construct() { |
|
| 79 | + * Class constructor. |
|
| 80 | + */ |
|
| 81 | + public function __construct() { |
|
| 82 | 82 | |
| 83 | 83 | $this->title = __( 'PayPal Standard', 'invoicing' ); |
| 84 | 84 | $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
| 85 | 85 | $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
| 86 | 86 | $this->notify_url = wpinv_get_ipn_url( $this->id ); |
| 87 | 87 | |
| 88 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
| 88 | + add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
| 89 | 89 | add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
| 90 | - add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
| 91 | - add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
| 90 | + add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
| 91 | + add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
| 92 | 92 | |
| 93 | 93 | parent::__construct(); |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
| 97 | - * Process Payment. |
|
| 98 | - * |
|
| 99 | - * |
|
| 100 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 101 | - * @param array $submission_data Posted checkout fields. |
|
| 102 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 103 | - * @return array |
|
| 104 | - */ |
|
| 105 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 97 | + * Process Payment. |
|
| 98 | + * |
|
| 99 | + * |
|
| 100 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 101 | + * @param array $submission_data Posted checkout fields. |
|
| 102 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 103 | + * @return array |
|
| 104 | + */ |
|
| 105 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 106 | 106 | |
| 107 | 107 | // Get redirect url. |
| 108 | 108 | $paypal_redirect = $this->get_request_url( $invoice ); |
@@ -125,15 +125,15 @@ discard block |
||
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
| 128 | - * Get the PayPal request URL for an invoice. |
|
| 129 | - * |
|
| 130 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 131 | - * @return string |
|
| 132 | - */ |
|
| 133 | - public function get_request_url( $invoice ) { |
|
| 128 | + * Get the PayPal request URL for an invoice. |
|
| 129 | + * |
|
| 130 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 131 | + * @return string |
|
| 132 | + */ |
|
| 133 | + public function get_request_url( $invoice ) { |
|
| 134 | 134 | |
| 135 | 135 | // Endpoint for this request |
| 136 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
| 136 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
| 137 | 137 | |
| 138 | 138 | // Retrieve paypal args. |
| 139 | 139 | $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
@@ -146,44 +146,44 @@ 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 | - 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 | + return array( |
|
| 187 | 187 | 'cmd' => '_cart', |
| 188 | 188 | 'business' => wpinv_get_option( 'paypal_email', false ), |
| 189 | 189 | 'no_shipping' => '1', |
@@ -208,16 +208,16 @@ discard block |
||
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
| 211 | - * Get line item args for paypal request. |
|
| 212 | - * |
|
| 213 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 214 | - * @param bool $force_one_line_item Create only one item for this invoice. |
|
| 215 | - * @return array |
|
| 216 | - */ |
|
| 217 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
| 211 | + * Get line item args for paypal request. |
|
| 212 | + * |
|
| 213 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 214 | + * @param bool $force_one_line_item Create only one item for this invoice. |
|
| 215 | + * @return array |
|
| 216 | + */ |
|
| 217 | + protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
| 218 | 218 | |
| 219 | 219 | // Maybe send invoice as a single item. |
| 220 | - if ( $force_one_line_item ) { |
|
| 220 | + if ( $force_one_line_item ) { |
|
| 221 | 221 | return $this->get_line_item_args_single_item( $invoice ); |
| 222 | 222 | } |
| 223 | 223 | |
@@ -237,129 +237,129 @@ discard block |
||
| 237 | 237 | $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
| 240 | + return array_merge( $line_item_args, $this->get_line_items() ); |
|
| 241 | 241 | |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
| 245 | - * Get line item args for paypal request as a single line item. |
|
| 246 | - * |
|
| 247 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 248 | - * @return array |
|
| 249 | - */ |
|
| 250 | - protected function get_line_item_args_single_item( $invoice ) { |
|
| 251 | - $this->delete_line_items(); |
|
| 245 | + * Get line item args for paypal request as a single line item. |
|
| 246 | + * |
|
| 247 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 248 | + * @return array |
|
| 249 | + */ |
|
| 250 | + protected function get_line_item_args_single_item( $invoice ) { |
|
| 251 | + $this->delete_line_items(); |
|
| 252 | 252 | |
| 253 | 253 | $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
| 254 | - $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
| 254 | + $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
| 255 | 255 | |
| 256 | - return $this->get_line_items(); |
|
| 256 | + return $this->get_line_items(); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
| 260 | - * Return all line items. |
|
| 261 | - */ |
|
| 262 | - protected function get_line_items() { |
|
| 263 | - return $this->line_items; |
|
| 264 | - } |
|
| 260 | + * Return all line items. |
|
| 261 | + */ |
|
| 262 | + protected function get_line_items() { |
|
| 263 | + return $this->line_items; |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | 266 | /** |
| 267 | - * Remove all line items. |
|
| 268 | - */ |
|
| 269 | - protected function delete_line_items() { |
|
| 270 | - $this->line_items = array(); |
|
| 267 | + * Remove all line items. |
|
| 268 | + */ |
|
| 269 | + protected function delete_line_items() { |
|
| 270 | + $this->line_items = array(); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
| 274 | - * Prepare line items to send to paypal. |
|
| 275 | - * |
|
| 276 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 277 | - */ |
|
| 278 | - protected function prepare_line_items( $invoice ) { |
|
| 279 | - $this->delete_line_items(); |
|
| 280 | - |
|
| 281 | - // Items. |
|
| 282 | - foreach ( $invoice->get_items() as $item ) { |
|
| 283 | - $amount = $item->get_price(); |
|
| 284 | - $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
| 285 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
| 274 | + * Prepare line items to send to paypal. |
|
| 275 | + * |
|
| 276 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 277 | + */ |
|
| 278 | + protected function prepare_line_items( $invoice ) { |
|
| 279 | + $this->delete_line_items(); |
|
| 280 | + |
|
| 281 | + // Items. |
|
| 282 | + foreach ( $invoice->get_items() as $item ) { |
|
| 283 | + $amount = $item->get_price(); |
|
| 284 | + $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
| 285 | + $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | // Fees. |
| 289 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
| 289 | + foreach ( $invoice->get_fees() as $fee => $data ) { |
|
| 290 | 290 | $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | /** |
| 296 | - * Add PayPal Line Item. |
|
| 297 | - * |
|
| 298 | - * @param string $item_name Item name. |
|
| 299 | - * @param float $quantity Item quantity. |
|
| 300 | - * @param float $amount Amount. |
|
| 301 | - * @param string $item_number Item number. |
|
| 302 | - */ |
|
| 303 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
| 304 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
| 305 | - |
|
| 306 | - $item = apply_filters( |
|
| 307 | - 'getpaid_paypal_line_item', |
|
| 308 | - array( |
|
| 309 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
| 310 | - 'quantity' => (float) $quantity, |
|
| 311 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
| 312 | - 'item_number' => $item_number, |
|
| 313 | - ), |
|
| 314 | - $item_name, |
|
| 315 | - $quantity, |
|
| 316 | - $amount, |
|
| 317 | - $item_number |
|
| 318 | - ); |
|
| 319 | - |
|
| 320 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
| 296 | + * Add PayPal Line Item. |
|
| 297 | + * |
|
| 298 | + * @param string $item_name Item name. |
|
| 299 | + * @param float $quantity Item quantity. |
|
| 300 | + * @param float $amount Amount. |
|
| 301 | + * @param string $item_number Item number. |
|
| 302 | + */ |
|
| 303 | + protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
| 304 | + $index = ( count( $this->line_items ) / 4 ) + 1; |
|
| 305 | + |
|
| 306 | + $item = apply_filters( |
|
| 307 | + 'getpaid_paypal_line_item', |
|
| 308 | + array( |
|
| 309 | + 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
| 310 | + 'quantity' => (float) $quantity, |
|
| 311 | + 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
| 312 | + 'item_number' => $item_number, |
|
| 313 | + ), |
|
| 314 | + $item_name, |
|
| 315 | + $quantity, |
|
| 316 | + $amount, |
|
| 317 | + $item_number |
|
| 318 | + ); |
|
| 319 | + |
|
| 320 | + $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
| 321 | 321 | $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
| 322 | 322 | |
| 323 | 323 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
| 324 | - $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
| 325 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
| 324 | + $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
| 325 | + $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | /** |
| 329 | - * If the default request with line items is too long, generate a new one with only one line item. |
|
| 330 | - * |
|
| 331 | - * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
| 332 | - * |
|
| 333 | - * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
| 334 | - * @param array $paypal_args Arguments sent to Paypal in the request. |
|
| 335 | - * @return array |
|
| 336 | - */ |
|
| 337 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
| 338 | - $max_paypal_length = 2083; |
|
| 339 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
| 340 | - |
|
| 341 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
| 342 | - return $paypal_args; |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - return apply_filters( |
|
| 346 | - 'getpaid_paypal_args', |
|
| 347 | - array_merge( |
|
| 348 | - $this->get_transaction_args( $invoice ), |
|
| 349 | - $this->get_line_item_args( $invoice, true ) |
|
| 350 | - ), |
|
| 351 | - $invoice |
|
| 352 | - ); |
|
| 329 | + * If the default request with line items is too long, generate a new one with only one line item. |
|
| 330 | + * |
|
| 331 | + * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
| 332 | + * |
|
| 333 | + * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
| 334 | + * @param array $paypal_args Arguments sent to Paypal in the request. |
|
| 335 | + * @return array |
|
| 336 | + */ |
|
| 337 | + protected function fix_request_length( $invoice, $paypal_args ) { |
|
| 338 | + $max_paypal_length = 2083; |
|
| 339 | + $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
| 340 | + |
|
| 341 | + if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
| 342 | + return $paypal_args; |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + return apply_filters( |
|
| 346 | + 'getpaid_paypal_args', |
|
| 347 | + array_merge( |
|
| 348 | + $this->get_transaction_args( $invoice ), |
|
| 349 | + $this->get_line_item_args( $invoice, true ) |
|
| 350 | + ), |
|
| 351 | + $invoice |
|
| 352 | + ); |
|
| 353 | 353 | |
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | /** |
| 357 | - * Processes recurring invoices. |
|
| 358 | - * |
|
| 359 | - * @param array $paypal_args PayPal args. |
|
| 360 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 361 | - */ |
|
| 362 | - public function process_subscription( $paypal_args, $invoice ) { |
|
| 357 | + * Processes recurring invoices. |
|
| 358 | + * |
|
| 359 | + * @param array $paypal_args PayPal args. |
|
| 360 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 361 | + */ |
|
| 362 | + public function process_subscription( $paypal_args, $invoice ) { |
|
| 363 | 363 | |
| 364 | 364 | // Make sure this is a subscription. |
| 365 | 365 | if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) { |
@@ -384,11 +384,11 @@ discard block |
||
| 384 | 384 | |
| 385 | 385 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
| 386 | 386 | |
| 387 | - // Trial period length. |
|
| 388 | - $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
| 387 | + // Trial period length. |
|
| 388 | + $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
| 389 | 389 | |
| 390 | - // Trial period. |
|
| 391 | - $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
| 390 | + // Trial period. |
|
| 391 | + $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
| 392 | 392 | |
| 393 | 393 | } else if ( $initial_amount != $recurring_amount ) { |
| 394 | 394 | |
@@ -411,40 +411,40 @@ discard block |
||
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | // We have a recurring payment |
| 414 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
| 414 | + if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
| 415 | 415 | |
| 416 | - // Subscription price |
|
| 417 | - $paypal_args['a3'] = $recurring_amount; |
|
| 416 | + // Subscription price |
|
| 417 | + $paypal_args['a3'] = $recurring_amount; |
|
| 418 | 418 | |
| 419 | - // Subscription duration |
|
| 420 | - $paypal_args['p3'] = $interval; |
|
| 419 | + // Subscription duration |
|
| 420 | + $paypal_args['p3'] = $interval; |
|
| 421 | 421 | |
| 422 | - // Subscription period |
|
| 423 | - $paypal_args['t3'] = $period; |
|
| 422 | + // Subscription period |
|
| 423 | + $paypal_args['t3'] = $period; |
|
| 424 | 424 | |
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | // Recurring payments |
| 428 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
| 428 | + if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
| 429 | 429 | |
| 430 | - // Non-recurring payments |
|
| 431 | - $paypal_args['src'] = 0; |
|
| 430 | + // Non-recurring payments |
|
| 431 | + $paypal_args['src'] = 0; |
|
| 432 | 432 | |
| 433 | - } else { |
|
| 433 | + } else { |
|
| 434 | 434 | |
| 435 | - $paypal_args['src'] = 1; |
|
| 435 | + $paypal_args['src'] = 1; |
|
| 436 | 436 | |
| 437 | - if ( $bill_times > 0 ) { |
|
| 437 | + if ( $bill_times > 0 ) { |
|
| 438 | 438 | |
| 439 | - // An initial period is being used to charge a sign-up fee |
|
| 440 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
| 441 | - $bill_times--; |
|
| 442 | - } |
|
| 439 | + // An initial period is being used to charge a sign-up fee |
|
| 440 | + if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
| 441 | + $bill_times--; |
|
| 442 | + } |
|
| 443 | 443 | |
| 444 | 444 | // Make sure it's not over the max of 52 |
| 445 | 445 | $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
| 446 | 446 | |
| 447 | - } |
|
| 447 | + } |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | // Force return URL so that order description & instructions display |
@@ -460,19 +460,19 @@ discard block |
||
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | return apply_filters( |
| 463 | - 'getpaid_paypal_subscription_args', |
|
| 464 | - $paypal_args, |
|
| 465 | - $invoice |
|
| 463 | + 'getpaid_paypal_subscription_args', |
|
| 464 | + $paypal_args, |
|
| 465 | + $invoice |
|
| 466 | 466 | ); |
| 467 | 467 | |
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | /** |
| 471 | - * Processes ipns and marks payments as complete. |
|
| 472 | - * |
|
| 473 | - * @return void |
|
| 474 | - */ |
|
| 475 | - public function verify_ipn() { |
|
| 471 | + * Processes ipns and marks payments as complete. |
|
| 472 | + * |
|
| 473 | + * @return void |
|
| 474 | + */ |
|
| 475 | + public function verify_ipn() { |
|
| 476 | 476 | new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
| 477 | 477 | } |
| 478 | 478 | |
@@ -482,19 +482,19 @@ discard block |
||
| 482 | 482 | public function sandbox_notice() { |
| 483 | 483 | |
| 484 | 484 | return sprintf( |
| 485 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
| 486 | - '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
| 487 | - '</a>' |
|
| 488 | - ); |
|
| 485 | + __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
| 486 | + '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
| 487 | + '</a>' |
|
| 488 | + ); |
|
| 489 | 489 | |
| 490 | 490 | } |
| 491 | 491 | |
| 492 | - /** |
|
| 493 | - * Filters the gateway settings. |
|
| 494 | - * |
|
| 495 | - * @param array $admin_settings |
|
| 496 | - */ |
|
| 497 | - public function admin_settings( $admin_settings ) { |
|
| 492 | + /** |
|
| 493 | + * Filters the gateway settings. |
|
| 494 | + * |
|
| 495 | + * @param array $admin_settings |
|
| 496 | + */ |
|
| 497 | + public function admin_settings( $admin_settings ) { |
|
| 498 | 498 | |
| 499 | 499 | $currencies = sprintf( |
| 500 | 500 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -504,89 +504,89 @@ discard block |
||
| 504 | 504 | $admin_settings['paypal_active']['desc'] .= " ($currencies)"; |
| 505 | 505 | $admin_settings['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
| 506 | 506 | |
| 507 | - // Access tokens. |
|
| 507 | + // Access tokens. |
|
| 508 | 508 | $live_account = wpinv_get_option( 'paypal_live_access_token' ); |
| 509 | 509 | $sandbox_account = wpinv_get_option( 'paypal_test_access_token' ); |
| 510 | 510 | |
| 511 | - $admin_settings['paypal_connect'] = array( |
|
| 512 | - 'type' => 'raw_html', |
|
| 513 | - 'id' => 'paypal_connect', |
|
| 514 | - 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
| 515 | - 'desc' => sprintf( |
|
| 516 | - '<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a><br><strong style="color: green">%s</strong></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a><br><strong style="color: green">%s</strong></div>%s', |
|
| 517 | - esc_url( self::get_connect_url( false ) ), |
|
| 518 | - __( 'Connect to PayPal', 'invoicing' ), |
|
| 519 | - __( 'Connected', 'invoicing' ), |
|
| 520 | - esc_url( self::get_connect_url( true ) ), |
|
| 521 | - __( 'Connect to PayPal Sandox', 'invoicing' ), |
|
| 522 | - __( 'Connected', 'invoicing' ), |
|
| 523 | - $this->get_js() |
|
| 524 | - ), |
|
| 525 | - ); |
|
| 526 | - |
|
| 527 | - $admin_settings['disable_paypal_connect'] = array( |
|
| 528 | - 'type' => 'checkbox', |
|
| 529 | - 'id' => 'disable_paypal_connect', |
|
| 530 | - 'name' => __( 'Manual Mode', 'invoicing' ), |
|
| 531 | - 'desc' => __( 'Manually enter your credentials', 'invoicing' ), |
|
| 532 | - 'std' => false, |
|
| 533 | - ); |
|
| 511 | + $admin_settings['paypal_connect'] = array( |
|
| 512 | + 'type' => 'raw_html', |
|
| 513 | + 'id' => 'paypal_connect', |
|
| 514 | + 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
| 515 | + 'desc' => sprintf( |
|
| 516 | + '<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a><br><strong style="color: green">%s</strong></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a><br><strong style="color: green">%s</strong></div>%s', |
|
| 517 | + esc_url( self::get_connect_url( false ) ), |
|
| 518 | + __( 'Connect to PayPal', 'invoicing' ), |
|
| 519 | + __( 'Connected', 'invoicing' ), |
|
| 520 | + esc_url( self::get_connect_url( true ) ), |
|
| 521 | + __( 'Connect to PayPal Sandox', 'invoicing' ), |
|
| 522 | + __( 'Connected', 'invoicing' ), |
|
| 523 | + $this->get_js() |
|
| 524 | + ), |
|
| 525 | + ); |
|
| 526 | + |
|
| 527 | + $admin_settings['disable_paypal_connect'] = array( |
|
| 528 | + 'type' => 'checkbox', |
|
| 529 | + 'id' => 'disable_paypal_connect', |
|
| 530 | + 'name' => __( 'Manual Mode', 'invoicing' ), |
|
| 531 | + 'desc' => __( 'Manually enter your credentials', 'invoicing' ), |
|
| 532 | + 'std' => false, |
|
| 533 | + ); |
|
| 534 | 534 | |
| 535 | 535 | $admin_settings['paypal_email'] = array( |
| 536 | 536 | 'type' => 'text', |
| 537 | - 'class' => 'live-auth-data', |
|
| 537 | + 'class' => 'live-auth-data', |
|
| 538 | 538 | 'id' => 'paypal_email', |
| 539 | 539 | 'name' => __( 'Live Email Address', 'invoicing' ), |
| 540 | 540 | 'desc' => __( 'The email address of your PayPal account.', 'invoicing' ), |
| 541 | 541 | ); |
| 542 | 542 | |
| 543 | - $admin_settings['paypal_merchant_id'] = array( |
|
| 543 | + $admin_settings['paypal_merchant_id'] = array( |
|
| 544 | 544 | 'type' => 'text', |
| 545 | - 'class' => 'live-auth-data', |
|
| 545 | + 'class' => 'live-auth-data', |
|
| 546 | 546 | 'id' => 'paypal_merchant_id', |
| 547 | 547 | 'name' => __( 'Live Merchant ID', 'invoicing' ), |
| 548 | 548 | ); |
| 549 | 549 | |
| 550 | - $admin_settings['paypal_client_id'] = array( |
|
| 550 | + $admin_settings['paypal_client_id'] = array( |
|
| 551 | 551 | 'type' => 'text', |
| 552 | - 'class' => 'live-auth-data', |
|
| 552 | + 'class' => 'live-auth-data', |
|
| 553 | 553 | 'id' => 'paypal_client_id', |
| 554 | 554 | 'name' => __( 'Live Client ID', 'invoicing' ), |
| 555 | 555 | ); |
| 556 | 556 | |
| 557 | - $admin_settings['paypal_client_secret'] = array( |
|
| 557 | + $admin_settings['paypal_client_secret'] = array( |
|
| 558 | 558 | 'type' => 'text', |
| 559 | - 'class' => 'live-auth-data', |
|
| 559 | + 'class' => 'live-auth-data', |
|
| 560 | 560 | 'id' => 'paypal_client_secret', |
| 561 | 561 | 'name' => __( 'Live Client Secret', 'invoicing' ), |
| 562 | 562 | ); |
| 563 | 563 | |
| 564 | - $admin_settings['paypal_sandbox_email'] = array( |
|
| 564 | + $admin_settings['paypal_sandbox_email'] = array( |
|
| 565 | 565 | 'type' => 'text', |
| 566 | - 'class' => 'sandbox-auth-data', |
|
| 566 | + 'class' => 'sandbox-auth-data', |
|
| 567 | 567 | 'id' => 'paypal_sandbox_email', |
| 568 | 568 | 'name' => __( 'Sandbox Email Address', 'invoicing' ), |
| 569 | 569 | 'desc' => __( 'The email address of your sandbox PayPal account.', 'invoicing' ), |
| 570 | - 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
| 570 | + 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
| 571 | 571 | ); |
| 572 | 572 | |
| 573 | - $admin_settings['paypal_sandbox_merchant_id'] = array( |
|
| 573 | + $admin_settings['paypal_sandbox_merchant_id'] = array( |
|
| 574 | 574 | 'type' => 'text', |
| 575 | - 'class' => 'sandbox-auth-data', |
|
| 575 | + 'class' => 'sandbox-auth-data', |
|
| 576 | 576 | 'id' => 'paypal_sandbox_merchant_id', |
| 577 | 577 | 'name' => __( 'Sandbox Merchant ID', 'invoicing' ), |
| 578 | 578 | ); |
| 579 | 579 | |
| 580 | - $admin_settings['paypal_sandbox_client_id'] = array( |
|
| 580 | + $admin_settings['paypal_sandbox_client_id'] = array( |
|
| 581 | 581 | 'type' => 'text', |
| 582 | - 'class' => 'sandbox-auth-data', |
|
| 582 | + 'class' => 'sandbox-auth-data', |
|
| 583 | 583 | 'id' => 'paypal_sandbox_client_id', |
| 584 | 584 | 'name' => __( 'Sandbox Client ID', 'invoicing' ), |
| 585 | 585 | ); |
| 586 | 586 | |
| 587 | - $admin_settings['paypal_sandbox_client_secret'] = array( |
|
| 587 | + $admin_settings['paypal_sandbox_client_secret'] = array( |
|
| 588 | 588 | 'type' => 'text', |
| 589 | - 'class' => 'sandbox-auth-data', |
|
| 589 | + 'class' => 'sandbox-auth-data', |
|
| 590 | 590 | 'id' => 'paypal_sandbox_client_secret', |
| 591 | 591 | 'name' => __( 'Sandbox Client Secret', 'invoicing' ), |
| 592 | 592 | ); |
@@ -600,29 +600,29 @@ discard block |
||
| 600 | 600 | 'readonly' => true, |
| 601 | 601 | ); |
| 602 | 602 | |
| 603 | - return $admin_settings; |
|
| 604 | - } |
|
| 603 | + return $admin_settings; |
|
| 604 | + } |
|
| 605 | 605 | |
| 606 | - /** |
|
| 607 | - * Retrieves the PayPal connect URL when using the setup wizzard. |
|
| 608 | - * |
|
| 609 | - * |
|
| 606 | + /** |
|
| 607 | + * Retrieves the PayPal connect URL when using the setup wizzard. |
|
| 608 | + * |
|
| 609 | + * |
|
| 610 | 610 | * @param array $data |
| 611 | 611 | * @return string |
| 612 | - */ |
|
| 613 | - public static function maybe_get_connect_url( $url = '', $data ) { |
|
| 614 | - return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - /** |
|
| 618 | - * Retrieves the PayPal connect URL. |
|
| 619 | - * |
|
| 620 | - * |
|
| 612 | + */ |
|
| 613 | + public static function maybe_get_connect_url( $url = '', $data ) { |
|
| 614 | + return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + /** |
|
| 618 | + * Retrieves the PayPal connect URL. |
|
| 619 | + * |
|
| 620 | + * |
|
| 621 | 621 | * @param bool $is_sandbox |
| 622 | - * @param string $redirect |
|
| 622 | + * @param string $redirect |
|
| 623 | 623 | * @return string |
| 624 | - */ |
|
| 625 | - public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
| 624 | + */ |
|
| 625 | + public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
| 626 | 626 | |
| 627 | 627 | $redirect_url = add_query_arg( |
| 628 | 628 | array( |
@@ -632,7 +632,7 @@ discard block |
||
| 632 | 632 | 'tab' => 'gateways', |
| 633 | 633 | 'section' => 'paypal', |
| 634 | 634 | 'getpaid-nonce' => wp_create_nonce( 'getpaid-nonce' ), |
| 635 | - 'redirect' => urlencode( $redirect ), |
|
| 635 | + 'redirect' => urlencode( $redirect ), |
|
| 636 | 636 | ), |
| 637 | 637 | admin_url( 'admin.php' ) |
| 638 | 638 | ); |
@@ -647,12 +647,12 @@ discard block |
||
| 647 | 647 | |
| 648 | 648 | } |
| 649 | 649 | |
| 650 | - /** |
|
| 651 | - * Generates settings page js. |
|
| 652 | - * |
|
| 650 | + /** |
|
| 651 | + * Generates settings page js. |
|
| 652 | + * |
|
| 653 | 653 | * @return void |
| 654 | - */ |
|
| 655 | - public static function get_js() { |
|
| 654 | + */ |
|
| 655 | + public static function get_js() { |
|
| 656 | 656 | ob_start(); |
| 657 | 657 | ?> |
| 658 | 658 | <script> |
@@ -698,109 +698,109 @@ discard block |
||
| 698 | 698 | return ob_get_clean(); |
| 699 | 699 | } |
| 700 | 700 | |
| 701 | - /** |
|
| 702 | - * Connects to PayPal. |
|
| 703 | - * |
|
| 704 | - * @param array $data Connection data. |
|
| 705 | - * @return void |
|
| 706 | - */ |
|
| 707 | - public function connect_paypal( $data ) { |
|
| 708 | - |
|
| 709 | - $sandbox = $this->is_sandbox(); |
|
| 710 | - $data = wp_unslash( $data ); |
|
| 711 | - $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
| 712 | - |
|
| 713 | - if ( isset( $data['live_mode'] ) ) { |
|
| 714 | - $sandbox = empty( $data['live_mode'] ); |
|
| 715 | - } |
|
| 716 | - |
|
| 717 | - wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
| 718 | - wpinv_update_option( 'paypal_active', 1 ); |
|
| 719 | - |
|
| 720 | - if ( ! empty( $data['error_description'] ) ) { |
|
| 721 | - getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
| 722 | - } else { |
|
| 723 | - |
|
| 724 | - // Retrieve the user info. |
|
| 725 | - $user_info = wp_remote_get( |
|
| 726 | - ! $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', |
|
| 727 | - array( |
|
| 728 | - |
|
| 729 | - 'headers' => array( |
|
| 730 | - 'Authorization' => 'Bearer ' . $access_token, |
|
| 731 | - 'Content-type' => 'application/json', |
|
| 732 | - ) |
|
| 733 | - |
|
| 734 | - ) |
|
| 735 | - ); |
|
| 736 | - |
|
| 737 | - if ( is_wp_error( $user_info ) ) { |
|
| 738 | - getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
| 739 | - } else { |
|
| 740 | - |
|
| 741 | - // Create application. |
|
| 742 | - $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
| 743 | - $app = wp_remote_post( |
|
| 744 | - ! $sandbox ? 'https://api-m.paypal.com/v1/identity/applications' : 'https://api-m.sandbox.paypal.com/v1/identity/applications', |
|
| 745 | - array( |
|
| 746 | - |
|
| 747 | - 'body' => array( |
|
| 748 | - 'application_type' => 'web', |
|
| 749 | - 'redirect_uris' => array( |
|
| 750 | - add_query_arg( 'getpaid_oauth', 'paypal', home_url() ), |
|
| 751 | - ), |
|
| 752 | - 'client_name' => 'GetPaid', |
|
| 753 | - 'contacts' => array( $user_info->emails[0]->value ), |
|
| 754 | - 'payer_id' => $user_info->payer_id, |
|
| 755 | - 'migrated_app' => '', |
|
| 756 | - ), |
|
| 757 | - 'headers' => array( |
|
| 758 | - 'Authorization' => 'Bearer ' . $access_token, |
|
| 759 | - 'Content-type' => 'application/json', |
|
| 760 | - ) |
|
| 761 | - |
|
| 762 | - ) |
|
| 763 | - ); |
|
| 764 | - |
|
| 765 | - if ( is_wp_error( $app ) ) { |
|
| 766 | - getpaid_admin()->show_error( wp_kses_post( $app->get_error_message() ) ); |
|
| 767 | - } else { |
|
| 768 | - |
|
| 769 | - $app = json_decode( wp_remote_retrieve_body( $app ) ); |
|
| 770 | - wpinv_error_log( $app ); |
|
| 771 | - if ( $sandbox ) { |
|
| 772 | - wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
| 773 | - wpinv_update_option( 'paypal_sandbox_merchant_id', '' ); |
|
| 774 | - wpinv_update_option( 'paypal_sandbox_client_id', sanitize_text_field( '' ) ); |
|
| 775 | - wpinv_update_option( 'paypal_sandbox_client_secret', sanitize_text_field( '' ) ); |
|
| 776 | - wpinv_update_option( 'paypal_sandbox_client_secret_expires_at', sanitize_text_field( '' ) ); |
|
| 777 | - wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
| 778 | - set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
| 779 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
| 780 | - } else { |
|
| 781 | - wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
| 782 | - wpinv_update_option( 'paypal_merchant_id', '' ); |
|
| 783 | - wpinv_update_option( 'paypal_client_id', sanitize_text_field( '' ) ); |
|
| 784 | - wpinv_update_option( 'paypal_client_secret', sanitize_text_field( '' ) ); |
|
| 785 | - wpinv_update_option( 'paypal_client_secret_expires_at', sanitize_text_field( '' ) ); |
|
| 786 | - wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
| 787 | - set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
| 788 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
| 789 | - } |
|
| 701 | + /** |
|
| 702 | + * Connects to PayPal. |
|
| 703 | + * |
|
| 704 | + * @param array $data Connection data. |
|
| 705 | + * @return void |
|
| 706 | + */ |
|
| 707 | + public function connect_paypal( $data ) { |
|
| 790 | 708 | |
| 791 | - } |
|
| 709 | + $sandbox = $this->is_sandbox(); |
|
| 710 | + $data = wp_unslash( $data ); |
|
| 711 | + $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
| 792 | 712 | |
| 793 | - } |
|
| 713 | + if ( isset( $data['live_mode'] ) ) { |
|
| 714 | + $sandbox = empty( $data['live_mode'] ); |
|
| 715 | + } |
|
| 794 | 716 | |
| 795 | - } |
|
| 717 | + wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
| 718 | + wpinv_update_option( 'paypal_active', 1 ); |
|
| 796 | 719 | |
| 797 | - $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
| 720 | + if ( ! empty( $data['error_description'] ) ) { |
|
| 721 | + getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
| 722 | + } else { |
|
| 723 | + |
|
| 724 | + // Retrieve the user info. |
|
| 725 | + $user_info = wp_remote_get( |
|
| 726 | + ! $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', |
|
| 727 | + array( |
|
| 728 | + |
|
| 729 | + 'headers' => array( |
|
| 730 | + 'Authorization' => 'Bearer ' . $access_token, |
|
| 731 | + 'Content-type' => 'application/json', |
|
| 732 | + ) |
|
| 798 | 733 | |
| 799 | - if ( isset( $data['step'] ) ) { |
|
| 800 | - $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
| 801 | - } |
|
| 802 | - wp_redirect( $redirect ); |
|
| 803 | - exit; |
|
| 804 | - } |
|
| 734 | + ) |
|
| 735 | + ); |
|
| 736 | + |
|
| 737 | + if ( is_wp_error( $user_info ) ) { |
|
| 738 | + getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
| 739 | + } else { |
|
| 740 | + |
|
| 741 | + // Create application. |
|
| 742 | + $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
| 743 | + $app = wp_remote_post( |
|
| 744 | + ! $sandbox ? 'https://api-m.paypal.com/v1/identity/applications' : 'https://api-m.sandbox.paypal.com/v1/identity/applications', |
|
| 745 | + array( |
|
| 746 | + |
|
| 747 | + 'body' => array( |
|
| 748 | + 'application_type' => 'web', |
|
| 749 | + 'redirect_uris' => array( |
|
| 750 | + add_query_arg( 'getpaid_oauth', 'paypal', home_url() ), |
|
| 751 | + ), |
|
| 752 | + 'client_name' => 'GetPaid', |
|
| 753 | + 'contacts' => array( $user_info->emails[0]->value ), |
|
| 754 | + 'payer_id' => $user_info->payer_id, |
|
| 755 | + 'migrated_app' => '', |
|
| 756 | + ), |
|
| 757 | + 'headers' => array( |
|
| 758 | + 'Authorization' => 'Bearer ' . $access_token, |
|
| 759 | + 'Content-type' => 'application/json', |
|
| 760 | + ) |
|
| 761 | + |
|
| 762 | + ) |
|
| 763 | + ); |
|
| 764 | + |
|
| 765 | + if ( is_wp_error( $app ) ) { |
|
| 766 | + getpaid_admin()->show_error( wp_kses_post( $app->get_error_message() ) ); |
|
| 767 | + } else { |
|
| 768 | + |
|
| 769 | + $app = json_decode( wp_remote_retrieve_body( $app ) ); |
|
| 770 | + wpinv_error_log( $app ); |
|
| 771 | + if ( $sandbox ) { |
|
| 772 | + wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
| 773 | + wpinv_update_option( 'paypal_sandbox_merchant_id', '' ); |
|
| 774 | + wpinv_update_option( 'paypal_sandbox_client_id', sanitize_text_field( '' ) ); |
|
| 775 | + wpinv_update_option( 'paypal_sandbox_client_secret', sanitize_text_field( '' ) ); |
|
| 776 | + wpinv_update_option( 'paypal_sandbox_client_secret_expires_at', sanitize_text_field( '' ) ); |
|
| 777 | + wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
| 778 | + set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
| 779 | + getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
| 780 | + } else { |
|
| 781 | + wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
| 782 | + wpinv_update_option( 'paypal_merchant_id', '' ); |
|
| 783 | + wpinv_update_option( 'paypal_client_id', sanitize_text_field( '' ) ); |
|
| 784 | + wpinv_update_option( 'paypal_client_secret', sanitize_text_field( '' ) ); |
|
| 785 | + wpinv_update_option( 'paypal_client_secret_expires_at', sanitize_text_field( '' ) ); |
|
| 786 | + wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
| 787 | + set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
| 788 | + getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + } |
|
| 794 | + |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
| 798 | + |
|
| 799 | + if ( isset( $data['step'] ) ) { |
|
| 800 | + $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
| 801 | + } |
|
| 802 | + wp_redirect( $redirect ); |
|
| 803 | + exit; |
|
| 804 | + } |
|
| 805 | 805 | |
| 806 | 806 | } |
@@ -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,11 +181,11 @@ 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 | 186 | return array( |
| 187 | 187 | 'cmd' => '_cart', |
| 188 | - 'business' => wpinv_get_option( 'paypal_email', false ), |
|
| 188 | + 'business' => wpinv_get_option('paypal_email', false), |
|
| 189 | 189 | 'no_shipping' => '1', |
| 190 | 190 | 'shipping' => '0', |
| 191 | 191 | 'no_note' => '1', |
@@ -193,16 +193,16 @@ discard block |
||
| 193 | 193 | 'rm' => is_ssl() ? 2 : 1, |
| 194 | 194 | 'upload' => 1, |
| 195 | 195 | 'currency_code' => $invoice->get_currency(), // https://developer.paypal.com/docs/nvp-soap-api/currency-codes/#paypal |
| 196 | - 'return' => esc_url_raw( $this->get_return_url( $invoice ) ), |
|
| 197 | - 'cancel_return' => esc_url_raw( $invoice->get_checkout_payment_url() ), |
|
| 198 | - 'notify_url' => getpaid_limit_length( $this->notify_url, 255 ), |
|
| 199 | - 'invoice' => getpaid_limit_length( $invoice->get_number(), 127 ), |
|
| 196 | + 'return' => esc_url_raw($this->get_return_url($invoice)), |
|
| 197 | + 'cancel_return' => esc_url_raw($invoice->get_checkout_payment_url()), |
|
| 198 | + 'notify_url' => getpaid_limit_length($this->notify_url, 255), |
|
| 199 | + 'invoice' => getpaid_limit_length($invoice->get_number(), 127), |
|
| 200 | 200 | 'custom' => $invoice->get_id(), |
| 201 | - 'first_name' => getpaid_limit_length( $invoice->get_first_name(), 32 ), |
|
| 202 | - 'last_name' => getpaid_limit_length( $invoice->get_last_name(), 64 ), |
|
| 203 | - 'country' => getpaid_limit_length( $invoice->get_country(), 2 ), |
|
| 204 | - 'email' => getpaid_limit_length( $invoice->get_email(), 127 ), |
|
| 205 | - 'cbt' => get_bloginfo( 'name' ) |
|
| 201 | + 'first_name' => getpaid_limit_length($invoice->get_first_name(), 32), |
|
| 202 | + 'last_name' => getpaid_limit_length($invoice->get_last_name(), 64), |
|
| 203 | + 'country' => getpaid_limit_length($invoice->get_country(), 2), |
|
| 204 | + 'email' => getpaid_limit_length($invoice->get_email(), 127), |
|
| 205 | + 'cbt' => get_bloginfo('name') |
|
| 206 | 206 | ); |
| 207 | 207 | |
| 208 | 208 | } |
@@ -214,30 +214,30 @@ discard block |
||
| 214 | 214 | * @param bool $force_one_line_item Create only one item for this invoice. |
| 215 | 215 | * @return array |
| 216 | 216 | */ |
| 217 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
| 217 | + protected function get_line_item_args($invoice, $force_one_line_item = false) { |
|
| 218 | 218 | |
| 219 | 219 | // Maybe send invoice as a single item. |
| 220 | - if ( $force_one_line_item ) { |
|
| 221 | - return $this->get_line_item_args_single_item( $invoice ); |
|
| 220 | + if ($force_one_line_item) { |
|
| 221 | + return $this->get_line_item_args_single_item($invoice); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | // Send each line item individually. |
| 225 | 225 | $line_item_args = array(); |
| 226 | 226 | |
| 227 | 227 | // Prepare line items. |
| 228 | - $this->prepare_line_items( $invoice ); |
|
| 228 | + $this->prepare_line_items($invoice); |
|
| 229 | 229 | |
| 230 | 230 | // Add taxes to the cart |
| 231 | - if ( wpinv_use_taxes() && $invoice->is_taxable() ) { |
|
| 232 | - $line_item_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_tax(), 2 ); |
|
| 231 | + if (wpinv_use_taxes() && $invoice->is_taxable()) { |
|
| 232 | + $line_item_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_tax(), 2); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | // Add discount. |
| 236 | - if ( $invoice->get_total_discount() > 0 ) { |
|
| 237 | - $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
|
| 236 | + if ($invoice->get_total_discount() > 0) { |
|
| 237 | + $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_discount(), 2); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
| 240 | + return array_merge($line_item_args, $this->get_line_items()); |
|
| 241 | 241 | |
| 242 | 242 | } |
| 243 | 243 | |
@@ -247,11 +247,11 @@ discard block |
||
| 247 | 247 | * @param WPInv_Invoice $invoice Invoice object. |
| 248 | 248 | * @return array |
| 249 | 249 | */ |
| 250 | - protected function get_line_item_args_single_item( $invoice ) { |
|
| 250 | + protected function get_line_item_args_single_item($invoice) { |
|
| 251 | 251 | $this->delete_line_items(); |
| 252 | 252 | |
| 253 | - $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
|
| 254 | - $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
| 253 | + $item_name = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number()); |
|
| 254 | + $this->add_line_item($item_name, 1, wpinv_round_amount((float) $invoice->get_total(), 2, true), $invoice->get_id()); |
|
| 255 | 255 | |
| 256 | 256 | return $this->get_line_items(); |
| 257 | 257 | } |
@@ -275,19 +275,19 @@ discard block |
||
| 275 | 275 | * |
| 276 | 276 | * @param WPInv_Invoice $invoice Invoice object. |
| 277 | 277 | */ |
| 278 | - protected function prepare_line_items( $invoice ) { |
|
| 278 | + protected function prepare_line_items($invoice) { |
|
| 279 | 279 | $this->delete_line_items(); |
| 280 | 280 | |
| 281 | 281 | // Items. |
| 282 | - foreach ( $invoice->get_items() as $item ) { |
|
| 282 | + foreach ($invoice->get_items() as $item) { |
|
| 283 | 283 | $amount = $item->get_price(); |
| 284 | 284 | $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
| 285 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
| 285 | + $this->add_line_item($item->get_raw_name(), $quantity, $amount, $item->get_id()); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | // Fees. |
| 289 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
| 290 | - $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
|
| 289 | + foreach ($invoice->get_fees() as $fee => $data) { |
|
| 290 | + $this->add_line_item($fee, 1, wpinv_sanitize_amount($data['initial_fee'])); |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | } |
@@ -300,15 +300,15 @@ discard block |
||
| 300 | 300 | * @param float $amount Amount. |
| 301 | 301 | * @param string $item_number Item number. |
| 302 | 302 | */ |
| 303 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
| 304 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
| 303 | + protected function add_line_item($item_name, $quantity = 1, $amount = 0.0, $item_number = '') { |
|
| 304 | + $index = (count($this->line_items) / 4) + 1; |
|
| 305 | 305 | |
| 306 | 306 | $item = apply_filters( |
| 307 | 307 | 'getpaid_paypal_line_item', |
| 308 | 308 | array( |
| 309 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
| 309 | + 'item_name' => html_entity_decode(getpaid_limit_length($item_name ? wp_strip_all_tags($item_name) : __('Item', 'invoicing'), 127), ENT_NOQUOTES, 'UTF-8'), |
|
| 310 | 310 | 'quantity' => (float) $quantity, |
| 311 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
| 311 | + 'amount' => wpinv_sanitize_amount((float) $amount, 2), |
|
| 312 | 312 | 'item_number' => $item_number, |
| 313 | 313 | ), |
| 314 | 314 | $item_name, |
@@ -317,12 +317,12 @@ discard block |
||
| 317 | 317 | $item_number |
| 318 | 318 | ); |
| 319 | 319 | |
| 320 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
| 321 | - $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
|
| 320 | + $this->line_items['item_name_' . $index] = getpaid_limit_length($item['item_name'], 127); |
|
| 321 | + $this->line_items['quantity_' . $index] = $item['quantity']; |
|
| 322 | 322 | |
| 323 | 323 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
| 324 | - $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
| 325 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
| 324 | + $this->line_items['amount_' . $index] = $item['amount'] * $item['quantity']; |
|
| 325 | + $this->line_items['item_number_' . $index] = getpaid_limit_length($item['item_number'], 127); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | /** |
@@ -334,19 +334,19 @@ discard block |
||
| 334 | 334 | * @param array $paypal_args Arguments sent to Paypal in the request. |
| 335 | 335 | * @return array |
| 336 | 336 | */ |
| 337 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
| 337 | + protected function fix_request_length($invoice, $paypal_args) { |
|
| 338 | 338 | $max_paypal_length = 2083; |
| 339 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
| 339 | + $query_candidate = http_build_query($paypal_args, '', '&'); |
|
| 340 | 340 | |
| 341 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
| 341 | + if (strlen($this->endpoint . $query_candidate) <= $max_paypal_length) { |
|
| 342 | 342 | return $paypal_args; |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | return apply_filters( |
| 346 | 346 | 'getpaid_paypal_args', |
| 347 | 347 | array_merge( |
| 348 | - $this->get_transaction_args( $invoice ), |
|
| 349 | - $this->get_line_item_args( $invoice, true ) |
|
| 348 | + $this->get_transaction_args($invoice), |
|
| 349 | + $this->get_line_item_args($invoice, true) |
|
| 350 | 350 | ), |
| 351 | 351 | $invoice |
| 352 | 352 | ); |
@@ -359,10 +359,10 @@ discard block |
||
| 359 | 359 | * @param array $paypal_args PayPal args. |
| 360 | 360 | * @param WPInv_Invoice $invoice Invoice object. |
| 361 | 361 | */ |
| 362 | - public function process_subscription( $paypal_args, $invoice ) { |
|
| 362 | + public function process_subscription($paypal_args, $invoice) { |
|
| 363 | 363 | |
| 364 | 364 | // Make sure this is a subscription. |
| 365 | - if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) { |
|
| 365 | + if (!$invoice->is_recurring() || !$subscription = getpaid_get_invoice_subscription($invoice)) { |
|
| 366 | 366 | return $paypal_args; |
| 367 | 367 | } |
| 368 | 368 | |
@@ -370,17 +370,17 @@ discard block |
||
| 370 | 370 | $paypal_args['cmd'] = '_xclick-subscriptions'; |
| 371 | 371 | |
| 372 | 372 | // Subscription name. |
| 373 | - $paypal_args['item_name'] = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
|
| 373 | + $paypal_args['item_name'] = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number()); |
|
| 374 | 374 | |
| 375 | 375 | // Get subscription args. |
| 376 | - $period = strtoupper( substr( $subscription->get_period(), 0, 1) ); |
|
| 376 | + $period = strtoupper(substr($subscription->get_period(), 0, 1)); |
|
| 377 | 377 | $interval = (int) $subscription->get_frequency(); |
| 378 | 378 | $bill_times = (int) $subscription->get_bill_times(); |
| 379 | - $initial_amount = (float) wpinv_sanitize_amount( $invoice->get_initial_total(), 2 ); |
|
| 380 | - $recurring_amount = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 ); |
|
| 381 | - $subscription_item = $invoice->get_recurring( true ); |
|
| 379 | + $initial_amount = (float) wpinv_sanitize_amount($invoice->get_initial_total(), 2); |
|
| 380 | + $recurring_amount = (float) wpinv_sanitize_amount($invoice->get_recurring_total(), 2); |
|
| 381 | + $subscription_item = $invoice->get_recurring(true); |
|
| 382 | 382 | |
| 383 | - if ( $subscription_item->has_free_trial() ) { |
|
| 383 | + if ($subscription_item->has_free_trial()) { |
|
| 384 | 384 | |
| 385 | 385 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
| 386 | 386 | |
@@ -390,28 +390,28 @@ discard block |
||
| 390 | 390 | // Trial period. |
| 391 | 391 | $paypal_args['t1'] = $subscription_item->get_trial_period(); |
| 392 | 392 | |
| 393 | - } else if ( $initial_amount != $recurring_amount ) { |
|
| 393 | + } else if ($initial_amount != $recurring_amount) { |
|
| 394 | 394 | |
| 395 | 395 | // No trial period, but initial amount includes a sign-up fee and/or other items, so charge it as a separate period. |
| 396 | 396 | |
| 397 | - if ( 1 == $bill_times ) { |
|
| 397 | + if (1 == $bill_times) { |
|
| 398 | 398 | $param_number = 3; |
| 399 | 399 | } else { |
| 400 | 400 | $param_number = 1; |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | - $paypal_args[ 'a' . $param_number ] = $initial_amount ? $initial_amount : 0; |
|
| 403 | + $paypal_args['a' . $param_number] = $initial_amount ? $initial_amount : 0; |
|
| 404 | 404 | |
| 405 | 405 | // Sign Up interval |
| 406 | - $paypal_args[ 'p' . $param_number ] = $interval; |
|
| 406 | + $paypal_args['p' . $param_number] = $interval; |
|
| 407 | 407 | |
| 408 | 408 | // Sign Up unit of duration |
| 409 | - $paypal_args[ 't' . $param_number ] = $period; |
|
| 409 | + $paypal_args['t' . $param_number] = $period; |
|
| 410 | 410 | |
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | // We have a recurring payment |
| 414 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
| 414 | + if (!isset($param_number) || 1 == $param_number) { |
|
| 415 | 415 | |
| 416 | 416 | // Subscription price |
| 417 | 417 | $paypal_args['a3'] = $recurring_amount; |
@@ -425,7 +425,7 @@ discard block |
||
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | // Recurring payments |
| 428 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
| 428 | + if (1 == $bill_times || ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial() && 2 == $bill_times)) { |
|
| 429 | 429 | |
| 430 | 430 | // Non-recurring payments |
| 431 | 431 | $paypal_args['src'] = 0; |
@@ -434,15 +434,15 @@ discard block |
||
| 434 | 434 | |
| 435 | 435 | $paypal_args['src'] = 1; |
| 436 | 436 | |
| 437 | - if ( $bill_times > 0 ) { |
|
| 437 | + if ($bill_times > 0) { |
|
| 438 | 438 | |
| 439 | 439 | // An initial period is being used to charge a sign-up fee |
| 440 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
| 440 | + if ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial()) { |
|
| 441 | 441 | $bill_times--; |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | // Make sure it's not over the max of 52 |
| 445 | - $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
|
| 445 | + $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52); |
|
| 446 | 446 | |
| 447 | 447 | } |
| 448 | 448 | } |
@@ -451,10 +451,10 @@ discard block |
||
| 451 | 451 | $paypal_args['rm'] = 2; |
| 452 | 452 | |
| 453 | 453 | // Get rid of redudant items. |
| 454 | - foreach ( array( 'item_name_1', 'quantity_1', 'amount_1', 'item_number_1' ) as $arg ) { |
|
| 454 | + foreach (array('item_name_1', 'quantity_1', 'amount_1', 'item_number_1') as $arg) { |
|
| 455 | 455 | |
| 456 | - if ( isset( $paypal_args[ $arg ] ) ) { |
|
| 457 | - unset( $paypal_args[ $arg ] ); |
|
| 456 | + if (isset($paypal_args[$arg])) { |
|
| 457 | + unset($paypal_args[$arg]); |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | } |
@@ -473,7 +473,7 @@ discard block |
||
| 473 | 473 | * @return void |
| 474 | 474 | */ |
| 475 | 475 | public function verify_ipn() { |
| 476 | - new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
|
| 476 | + new GetPaid_Paypal_Gateway_IPN_Handler($this); |
|
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | /** |
@@ -482,7 +482,7 @@ discard block |
||
| 482 | 482 | public function sandbox_notice() { |
| 483 | 483 | |
| 484 | 484 | return sprintf( |
| 485 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
| 485 | + __('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing'), |
|
| 486 | 486 | '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
| 487 | 487 | '</a>' |
| 488 | 488 | ); |
@@ -494,32 +494,32 @@ discard block |
||
| 494 | 494 | * |
| 495 | 495 | * @param array $admin_settings |
| 496 | 496 | */ |
| 497 | - public function admin_settings( $admin_settings ) { |
|
| 497 | + public function admin_settings($admin_settings) { |
|
| 498 | 498 | |
| 499 | 499 | $currencies = sprintf( |
| 500 | - __( 'Supported Currencies: %s', 'invoicing' ), |
|
| 501 | - implode( ', ', $this->currencies ) |
|
| 500 | + __('Supported Currencies: %s', 'invoicing'), |
|
| 501 | + implode(', ', $this->currencies) |
|
| 502 | 502 | ); |
| 503 | 503 | |
| 504 | 504 | $admin_settings['paypal_active']['desc'] .= " ($currencies)"; |
| 505 | - $admin_settings['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
|
| 505 | + $admin_settings['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing'); |
|
| 506 | 506 | |
| 507 | 507 | // Access tokens. |
| 508 | - $live_account = wpinv_get_option( 'paypal_live_access_token' ); |
|
| 509 | - $sandbox_account = wpinv_get_option( 'paypal_test_access_token' ); |
|
| 508 | + $live_account = wpinv_get_option('paypal_live_access_token'); |
|
| 509 | + $sandbox_account = wpinv_get_option('paypal_test_access_token'); |
|
| 510 | 510 | |
| 511 | 511 | $admin_settings['paypal_connect'] = array( |
| 512 | 512 | 'type' => 'raw_html', |
| 513 | 513 | 'id' => 'paypal_connect', |
| 514 | - 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
| 514 | + 'name' => __('Connect to PayPal', 'invoicing'), |
|
| 515 | 515 | 'desc' => sprintf( |
| 516 | 516 | '<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a><br><strong style="color: green">%s</strong></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a><br><strong style="color: green">%s</strong></div>%s', |
| 517 | - esc_url( self::get_connect_url( false ) ), |
|
| 518 | - __( 'Connect to PayPal', 'invoicing' ), |
|
| 519 | - __( 'Connected', 'invoicing' ), |
|
| 520 | - esc_url( self::get_connect_url( true ) ), |
|
| 521 | - __( 'Connect to PayPal Sandox', 'invoicing' ), |
|
| 522 | - __( 'Connected', 'invoicing' ), |
|
| 517 | + esc_url(self::get_connect_url(false)), |
|
| 518 | + __('Connect to PayPal', 'invoicing'), |
|
| 519 | + __('Connected', 'invoicing'), |
|
| 520 | + esc_url(self::get_connect_url(true)), |
|
| 521 | + __('Connect to PayPal Sandox', 'invoicing'), |
|
| 522 | + __('Connected', 'invoicing'), |
|
| 523 | 523 | $this->get_js() |
| 524 | 524 | ), |
| 525 | 525 | ); |
@@ -527,8 +527,8 @@ discard block |
||
| 527 | 527 | $admin_settings['disable_paypal_connect'] = array( |
| 528 | 528 | 'type' => 'checkbox', |
| 529 | 529 | 'id' => 'disable_paypal_connect', |
| 530 | - 'name' => __( 'Manual Mode', 'invoicing' ), |
|
| 531 | - 'desc' => __( 'Manually enter your credentials', 'invoicing' ), |
|
| 530 | + 'name' => __('Manual Mode', 'invoicing'), |
|
| 531 | + 'desc' => __('Manually enter your credentials', 'invoicing'), |
|
| 532 | 532 | 'std' => false, |
| 533 | 533 | ); |
| 534 | 534 | |
@@ -536,67 +536,67 @@ discard block |
||
| 536 | 536 | 'type' => 'text', |
| 537 | 537 | 'class' => 'live-auth-data', |
| 538 | 538 | 'id' => 'paypal_email', |
| 539 | - 'name' => __( 'Live Email Address', 'invoicing' ), |
|
| 540 | - 'desc' => __( 'The email address of your PayPal account.', 'invoicing' ), |
|
| 539 | + 'name' => __('Live Email Address', 'invoicing'), |
|
| 540 | + 'desc' => __('The email address of your PayPal account.', 'invoicing'), |
|
| 541 | 541 | ); |
| 542 | 542 | |
| 543 | 543 | $admin_settings['paypal_merchant_id'] = array( |
| 544 | 544 | 'type' => 'text', |
| 545 | 545 | 'class' => 'live-auth-data', |
| 546 | 546 | 'id' => 'paypal_merchant_id', |
| 547 | - 'name' => __( 'Live Merchant ID', 'invoicing' ), |
|
| 547 | + 'name' => __('Live Merchant ID', 'invoicing'), |
|
| 548 | 548 | ); |
| 549 | 549 | |
| 550 | 550 | $admin_settings['paypal_client_id'] = array( |
| 551 | 551 | 'type' => 'text', |
| 552 | 552 | 'class' => 'live-auth-data', |
| 553 | 553 | 'id' => 'paypal_client_id', |
| 554 | - 'name' => __( 'Live Client ID', 'invoicing' ), |
|
| 554 | + 'name' => __('Live Client ID', 'invoicing'), |
|
| 555 | 555 | ); |
| 556 | 556 | |
| 557 | 557 | $admin_settings['paypal_client_secret'] = array( |
| 558 | 558 | 'type' => 'text', |
| 559 | 559 | 'class' => 'live-auth-data', |
| 560 | 560 | 'id' => 'paypal_client_secret', |
| 561 | - 'name' => __( 'Live Client Secret', 'invoicing' ), |
|
| 561 | + 'name' => __('Live Client Secret', 'invoicing'), |
|
| 562 | 562 | ); |
| 563 | 563 | |
| 564 | 564 | $admin_settings['paypal_sandbox_email'] = array( |
| 565 | 565 | 'type' => 'text', |
| 566 | 566 | 'class' => 'sandbox-auth-data', |
| 567 | 567 | 'id' => 'paypal_sandbox_email', |
| 568 | - 'name' => __( 'Sandbox Email Address', 'invoicing' ), |
|
| 569 | - 'desc' => __( 'The email address of your sandbox PayPal account.', 'invoicing' ), |
|
| 570 | - 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
| 568 | + 'name' => __('Sandbox Email Address', 'invoicing'), |
|
| 569 | + 'desc' => __('The email address of your sandbox PayPal account.', 'invoicing'), |
|
| 570 | + 'std' => wpinv_get_option('paypal_email', ''), |
|
| 571 | 571 | ); |
| 572 | 572 | |
| 573 | 573 | $admin_settings['paypal_sandbox_merchant_id'] = array( |
| 574 | 574 | 'type' => 'text', |
| 575 | 575 | 'class' => 'sandbox-auth-data', |
| 576 | 576 | 'id' => 'paypal_sandbox_merchant_id', |
| 577 | - 'name' => __( 'Sandbox Merchant ID', 'invoicing' ), |
|
| 577 | + 'name' => __('Sandbox Merchant ID', 'invoicing'), |
|
| 578 | 578 | ); |
| 579 | 579 | |
| 580 | 580 | $admin_settings['paypal_sandbox_client_id'] = array( |
| 581 | 581 | 'type' => 'text', |
| 582 | 582 | 'class' => 'sandbox-auth-data', |
| 583 | 583 | 'id' => 'paypal_sandbox_client_id', |
| 584 | - 'name' => __( 'Sandbox Client ID', 'invoicing' ), |
|
| 584 | + 'name' => __('Sandbox Client ID', 'invoicing'), |
|
| 585 | 585 | ); |
| 586 | 586 | |
| 587 | 587 | $admin_settings['paypal_sandbox_client_secret'] = array( |
| 588 | 588 | 'type' => 'text', |
| 589 | 589 | 'class' => 'sandbox-auth-data', |
| 590 | 590 | 'id' => 'paypal_sandbox_client_secret', |
| 591 | - 'name' => __( 'Sandbox Client Secret', 'invoicing' ), |
|
| 591 | + 'name' => __('Sandbox Client Secret', 'invoicing'), |
|
| 592 | 592 | ); |
| 593 | 593 | |
| 594 | 594 | $admin_settings['paypal_ipn_url'] = array( |
| 595 | 595 | 'type' => 'ipn_url', |
| 596 | 596 | 'id' => 'paypal_ipn_url', |
| 597 | - 'name' => __( 'IPN Url', 'invoicing' ), |
|
| 597 | + 'name' => __('IPN Url', 'invoicing'), |
|
| 598 | 598 | 'std' => $this->notify_url, |
| 599 | - '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>', |
|
| 599 | + '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>', |
|
| 600 | 600 | 'readonly' => true, |
| 601 | 601 | ); |
| 602 | 602 | |
@@ -610,8 +610,8 @@ discard block |
||
| 610 | 610 | * @param array $data |
| 611 | 611 | * @return string |
| 612 | 612 | */ |
| 613 | - public static function maybe_get_connect_url( $url = '', $data ) { |
|
| 614 | - return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
| 613 | + public static function maybe_get_connect_url($url = '', $data) { |
|
| 614 | + return self::get_connect_url(false, urldecode($data['redirect'])); |
|
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | /** |
@@ -622,25 +622,25 @@ discard block |
||
| 622 | 622 | * @param string $redirect |
| 623 | 623 | * @return string |
| 624 | 624 | */ |
| 625 | - public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
| 625 | + public static function get_connect_url($is_sandbox, $redirect = '') { |
|
| 626 | 626 | |
| 627 | 627 | $redirect_url = add_query_arg( |
| 628 | 628 | array( |
| 629 | 629 | 'getpaid-admin-action' => 'connect_paypal', |
| 630 | 630 | 'page' => 'wpinv-settings', |
| 631 | - 'live_mode' => (int) empty( $is_sandbox ), |
|
| 631 | + 'live_mode' => (int) empty($is_sandbox), |
|
| 632 | 632 | 'tab' => 'gateways', |
| 633 | 633 | 'section' => 'paypal', |
| 634 | - 'getpaid-nonce' => wp_create_nonce( 'getpaid-nonce' ), |
|
| 635 | - 'redirect' => urlencode( $redirect ), |
|
| 634 | + 'getpaid-nonce' => wp_create_nonce('getpaid-nonce'), |
|
| 635 | + 'redirect' => urlencode($redirect), |
|
| 636 | 636 | ), |
| 637 | - admin_url( 'admin.php' ) |
|
| 637 | + admin_url('admin.php') |
|
| 638 | 638 | ); |
| 639 | 639 | |
| 640 | 640 | return add_query_arg( |
| 641 | 641 | array( |
| 642 | - 'live_mode' => (int) empty( $is_sandbox ), |
|
| 643 | - 'redirect_url' => urlencode( str_replace( '&', '&', $redirect_url ) ) |
|
| 642 | + 'live_mode' => (int) empty($is_sandbox), |
|
| 643 | + 'redirect_url' => urlencode(str_replace('&', '&', $redirect_url)) |
|
| 644 | 644 | ), |
| 645 | 645 | 'https://ayecode.io/oauth/paypal' |
| 646 | 646 | ); |
@@ -704,26 +704,26 @@ discard block |
||
| 704 | 704 | * @param array $data Connection data. |
| 705 | 705 | * @return void |
| 706 | 706 | */ |
| 707 | - public function connect_paypal( $data ) { |
|
| 707 | + public function connect_paypal($data) { |
|
| 708 | 708 | |
| 709 | 709 | $sandbox = $this->is_sandbox(); |
| 710 | - $data = wp_unslash( $data ); |
|
| 711 | - $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
| 710 | + $data = wp_unslash($data); |
|
| 711 | + $access_token = empty($data['access_token']) ? '' : sanitize_text_field($data['access_token']); |
|
| 712 | 712 | |
| 713 | - if ( isset( $data['live_mode'] ) ) { |
|
| 714 | - $sandbox = empty( $data['live_mode'] ); |
|
| 713 | + if (isset($data['live_mode'])) { |
|
| 714 | + $sandbox = empty($data['live_mode']); |
|
| 715 | 715 | } |
| 716 | 716 | |
| 717 | - wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
| 718 | - wpinv_update_option( 'paypal_active', 1 ); |
|
| 717 | + wpinv_update_option('paypal_sandbox', (int) $sandbox); |
|
| 718 | + wpinv_update_option('paypal_active', 1); |
|
| 719 | 719 | |
| 720 | - if ( ! empty( $data['error_description'] ) ) { |
|
| 721 | - getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
| 720 | + if (!empty($data['error_description'])) { |
|
| 721 | + getpaid_admin()->show_error(wp_kses_post(urldecode($data['error_description']))); |
|
| 722 | 722 | } else { |
| 723 | 723 | |
| 724 | 724 | // Retrieve the user info. |
| 725 | 725 | $user_info = wp_remote_get( |
| 726 | - ! $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', |
|
| 726 | + !$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', |
|
| 727 | 727 | array( |
| 728 | 728 | |
| 729 | 729 | 'headers' => array( |
@@ -734,23 +734,23 @@ discard block |
||
| 734 | 734 | ) |
| 735 | 735 | ); |
| 736 | 736 | |
| 737 | - if ( is_wp_error( $user_info ) ) { |
|
| 738 | - getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
| 737 | + if (is_wp_error($user_info)) { |
|
| 738 | + getpaid_admin()->show_error(wp_kses_post($user_info->get_error_message())); |
|
| 739 | 739 | } else { |
| 740 | 740 | |
| 741 | 741 | // Create application. |
| 742 | - $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
| 742 | + $user_info = json_decode(wp_remote_retrieve_body($user_info)); |
|
| 743 | 743 | $app = wp_remote_post( |
| 744 | - ! $sandbox ? 'https://api-m.paypal.com/v1/identity/applications' : 'https://api-m.sandbox.paypal.com/v1/identity/applications', |
|
| 744 | + !$sandbox ? 'https://api-m.paypal.com/v1/identity/applications' : 'https://api-m.sandbox.paypal.com/v1/identity/applications', |
|
| 745 | 745 | array( |
| 746 | 746 | |
| 747 | 747 | 'body' => array( |
| 748 | 748 | 'application_type' => 'web', |
| 749 | 749 | 'redirect_uris' => array( |
| 750 | - add_query_arg( 'getpaid_oauth', 'paypal', home_url() ), |
|
| 750 | + add_query_arg('getpaid_oauth', 'paypal', home_url()), |
|
| 751 | 751 | ), |
| 752 | 752 | 'client_name' => 'GetPaid', |
| 753 | - 'contacts' => array( $user_info->emails[0]->value ), |
|
| 753 | + 'contacts' => array($user_info->emails[0]->value), |
|
| 754 | 754 | 'payer_id' => $user_info->payer_id, |
| 755 | 755 | 'migrated_app' => '', |
| 756 | 756 | ), |
@@ -762,30 +762,30 @@ discard block |
||
| 762 | 762 | ) |
| 763 | 763 | ); |
| 764 | 764 | |
| 765 | - if ( is_wp_error( $app ) ) { |
|
| 766 | - getpaid_admin()->show_error( wp_kses_post( $app->get_error_message() ) ); |
|
| 765 | + if (is_wp_error($app)) { |
|
| 766 | + getpaid_admin()->show_error(wp_kses_post($app->get_error_message())); |
|
| 767 | 767 | } else { |
| 768 | 768 | |
| 769 | - $app = json_decode( wp_remote_retrieve_body( $app ) ); |
|
| 770 | - wpinv_error_log( $app ); |
|
| 771 | - if ( $sandbox ) { |
|
| 772 | - wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
| 773 | - wpinv_update_option( 'paypal_sandbox_merchant_id', '' ); |
|
| 774 | - wpinv_update_option( 'paypal_sandbox_client_id', sanitize_text_field( '' ) ); |
|
| 775 | - wpinv_update_option( 'paypal_sandbox_client_secret', sanitize_text_field( '' ) ); |
|
| 776 | - wpinv_update_option( 'paypal_sandbox_client_secret_expires_at', sanitize_text_field( '' ) ); |
|
| 777 | - wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
| 778 | - set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
| 779 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
| 769 | + $app = json_decode(wp_remote_retrieve_body($app)); |
|
| 770 | + wpinv_error_log($app); |
|
| 771 | + if ($sandbox) { |
|
| 772 | + wpinv_update_option('paypal_sandbox_email', sanitize_email($user_info->emails[0]->value)); |
|
| 773 | + wpinv_update_option('paypal_sandbox_merchant_id', ''); |
|
| 774 | + wpinv_update_option('paypal_sandbox_client_id', sanitize_text_field('')); |
|
| 775 | + wpinv_update_option('paypal_sandbox_client_secret', sanitize_text_field('')); |
|
| 776 | + wpinv_update_option('paypal_sandbox_client_secret_expires_at', sanitize_text_field('')); |
|
| 777 | + wpinv_update_option('paypal_sandbox_refresh_token', sanitize_text_field(urldecode($data['refresh_token']))); |
|
| 778 | + set_transient('getpaid_paypal_sandbox_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']); |
|
| 779 | + getpaid_admin()->show_success(__('Successfully connected your PayPal sandbox account', 'invoicing')); |
|
| 780 | 780 | } else { |
| 781 | - wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
| 782 | - wpinv_update_option( 'paypal_merchant_id', '' ); |
|
| 783 | - wpinv_update_option( 'paypal_client_id', sanitize_text_field( '' ) ); |
|
| 784 | - wpinv_update_option( 'paypal_client_secret', sanitize_text_field( '' ) ); |
|
| 785 | - wpinv_update_option( 'paypal_client_secret_expires_at', sanitize_text_field( '' ) ); |
|
| 786 | - wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
| 787 | - set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
| 788 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
| 781 | + wpinv_update_option('paypal_email', sanitize_email($user_info->emails[0]->value)); |
|
| 782 | + wpinv_update_option('paypal_merchant_id', ''); |
|
| 783 | + wpinv_update_option('paypal_client_id', sanitize_text_field('')); |
|
| 784 | + wpinv_update_option('paypal_client_secret', sanitize_text_field('')); |
|
| 785 | + wpinv_update_option('paypal_client_secret_expires_at', sanitize_text_field('')); |
|
| 786 | + wpinv_update_option('paypal_refresh_token', sanitize_text_field(urldecode($data['refresh_token']))); |
|
| 787 | + set_transient('getpaid_paypal_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']); |
|
| 788 | + getpaid_admin()->show_success(__('Successfully connected your PayPal account', 'invoicing')); |
|
| 789 | 789 | } |
| 790 | 790 | |
| 791 | 791 | } |
@@ -794,12 +794,12 @@ discard block |
||
| 794 | 794 | |
| 795 | 795 | } |
| 796 | 796 | |
| 797 | - $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
| 797 | + $redirect = empty($data['redirect']) ? admin_url('admin.php?page=wpinv-settings&tab=gateways§ion=paypal') : urldecode($data['redirect']); |
|
| 798 | 798 | |
| 799 | - if ( isset( $data['step'] ) ) { |
|
| 800 | - $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
| 799 | + if (isset($data['step'])) { |
|
| 800 | + $redirect = add_query_arg('step', $data['step'], $redirect); |
|
| 801 | 801 | } |
| 802 | - wp_redirect( $redirect ); |
|
| 802 | + wp_redirect($redirect); |
|
| 803 | 803 | exit; |
| 804 | 804 | } |
| 805 | 805 | |