/**
  * Constructor.
  */
 public function __construct()
 {
     $includes_path = wc_gateway_ppec()->includes_path;
     require_once $includes_path . 'class-wc-gateway-ppec-refund.php';
     require_once $includes_path . 'abstracts/abstract-wc-gateway-ppec.php';
     require_once $includes_path . 'class-wc-gateway-ppec-with-paypal.php';
     add_filter('woocommerce_payment_gateways', array($this, 'payment_gateways'));
 }
 public function __construct()
 {
     $this->id = 'ppec_paypal_credit';
     parent::__construct();
     $settings = wc_gateway_ppec()->settings->loadSettings();
     $this->icon = 'https://www.paypalobjects.com/webstatic/en_US/i/buttons/ppc-acceptance-' . $settings->markSize . '.png';
     $this->enabled = $settings->ppcEnabled ? 'yes' : 'no';
     $this->title = __('PayPal Credit', 'woocommerce-gateway-paypal-express-checkout');
     $this->description = __('Make checkout quick and easy for your buyers, and give them an easy way to finance their purchases at the same time.', 'woocommerce-gateway-paypal-express-checkout');
 }
Beispiel #3
0
/**
 * Log a message via WC_Logger.
 *
 * @param string $message Message to log
 */
function wc_gateway_ppec_log($message)
{
    static $wc_ppec_logger;
    // No need to write to log file if logging is disabled.
    if (!wc_gateway_ppec()->settings->is_logging_enabled()) {
        return false;
    }
    if (!isset($wc_ppec_logger)) {
        $wc_ppec_logger = new WC_Logger();
    }
    $wc_ppec_logger->add('wc_gateway_ppec', $message);
    if (defined('WP_DEBUG') && WP_DEBUG) {
        error_log($message);
    }
}
 /**
  * Refund an order.
  *
  * @throws \PayPal_API_Exception
  *
  * @param WC_Order $order      Order to refund
  * @param float    $amount     Amount to refund
  * @param string   $refundType Type of refund (Partial or Full)
  * @param string   $reason     Reason to refund
  * @param string   $current    Currency of refund
  *
  * @return null|string If exception is thrown, null is returned. Otherwise
  *                     ID of refund transaction is returned.
  */
 public static function refund_order($order, $amount, $refundType, $reason, $currency)
 {
     // add refund params
     $params['TRANSACTIONID'] = $order->get_transaction_id();
     $params['REFUNDTYPE'] = $refundType;
     $params['AMT'] = $amount;
     $params['CURRENCYCODE'] = $currency;
     $params['NOTE'] = $reason;
     // do API call
     $response = wc_gateway_ppec()->client->refund_transaction($params);
     // look at ACK to see if success or failure
     // if success return the transaction ID of the refund
     // if failure then do 'throw new PayPal_API_Exception( $response );'
     if ('Success' == $response['ACK'] || 'SuccessWithWarning' == $response['ACK']) {
         return $response['REFUNDTRANSACTIONID'];
     } else {
         throw new PayPal_API_Exception($response);
     }
 }
 public function loadOrderDetails($order_id)
 {
     $order = wc_get_order($order_id);
     $this->totalItemAmount = 0;
     $this->items = array();
     // load all cart items into an array
     $roundedPayPalTotal = 0;
     $is_zdp_currency = in_array(get_woocommerce_currency(), $this->zdp_currencies);
     if ($is_zdp_currency) {
         $decimals = 0;
     } else {
         $decimals = 2;
     }
     $discounts = round($order->get_total_discount(), $decimals);
     foreach ($order->get_items() as $cart_item_key => $values) {
         $amount = round($values['line_subtotal'] / $values['qty'], $decimals);
         $item = array('name' => $values['name'], 'quantity' => $values['qty'], 'amount' => $amount);
         $this->items[] = $item;
         $roundedPayPalTotal += round($amount * $values['qty'], $decimals);
     }
     $this->orderTax = round($order->get_total_tax(), $decimals);
     $this->shipping = round($order->get_total_shipping(), $decimals);
     // if ( $order->get_shipping_tax() != 0 ) {
     // 	$this->shipping += round( $order->get_shipping_tax(), $decimals );
     // }
     $this->totalItemAmount = round($order->get_subtotal(), $decimals);
     $this->orderTotal = round($this->totalItemAmount + $this->orderTax + $this->shipping, $decimals);
     // need to compare WC totals with what PayPal will calculate to see if they match
     // if they do not match, check to see what the merchant would like to do
     // options are to remove line items or add a line item to adjust for the difference
     if ($this->totalItemAmount != $roundedPayPalTotal) {
         if ('add' === wc_gateway_ppec()->settings->get_subtotal_mismatch_behavior()) {
             // ...
             // Add line item to make up different between WooCommerce calculations and PayPal calculations
             $cartItemAmountDifference = $this->totalItemAmount - $roundedPayPalTotal;
             $modifyLineItem = array('name' => 'Line Item Amount Offset', 'description' => 'Adjust cart calculation discrepancy', 'quantity' => 1, 'amount' => round($cartItemAmountDifference, $decimals));
             $this->items[] = $modifyLineItem;
         } else {
             // ...
             // Omit line items altogether
             unset($this->items);
         }
     }
     // enter discount shenanigans. item total cannot be 0 so make modifications accordingly
     if ($this->totalItemAmount == $discounts) {
         // Omit line items altogether
         unset($this->items);
         $this->shipDiscountAmount = 0;
         $this->totalItemAmount -= $discounts;
         $this->orderTotal -= $discounts;
     } else {
         // Build PayPal_Cart object as normal
         if ($discounts > 0) {
             $discLineItem = array('name' => 'Discount', 'description' => 'Discount Amount', 'quantity' => 1, 'amount' => '-' . $discounts);
             $this->items[] = $discLineItem;
             $this->totalItemAmount -= $discounts;
             $this->orderTotal -= $discounts;
         }
         $this->shipDiscountAmount = 0;
     }
     // If the totals don't line up, adjust the tax to make it work (cause it's probably a tax mismatch).
     $wooOrderTotal = round($order->get_total(), $decimals);
     if ($wooOrderTotal != $this->orderTotal) {
         $this->orderTax += $wooOrderTotal - $this->orderTotal;
         $this->orderTotal = $wooOrderTotal;
     }
     $this->orderTax = round($this->orderTax, $decimals);
     // after all of the discount shenanigans, load up the other standard variables
     $this->insurance = 0;
     $this->handling = 0;
     $this->currency = get_woocommerce_currency();
     $this->custom = '';
     $this->invoiceNumber = '';
     if (!is_numeric($this->shipping)) {
         $this->shipping = 0;
     }
 }
 /**
  * Complete a payment that has been authorized via PPEC.
  */
 public function do_payment($order, $token, $payerID)
 {
     $settings = wc_gateway_ppec()->settings;
     $session_data = WC()->session->get('paypal', null);
     if (!$order || null === $session_data || $this->session_has_expired($token) || empty($payerID)) {
         throw new PayPal_Missing_Session_Exception();
     }
     // Ensure details are set
     wc_gateway_ppec()->cart->loadOrderDetails($order->id);
     // Generate params to send to paypal, then do request
     $response = wc_gateway_ppec()->client->do_express_checkout_payment(array_merge($this->getDoExpressCheckoutParameters($token, $payerID), $settings->get_do_express_checkout_params($order)));
     if ($this->is_success($response)) {
         $payment_details = new PayPal_Payment_Details();
         $payment_details->loadFromDoECResponse($response);
         $meta = get_post_meta($order->id, '_woo_pp_txnData', true);
         if (!empty($meta)) {
             $txnData = $meta;
         } else {
             $txnData = array('refundable_txns' => array());
         }
         $paymentAction = $settings->get_paymentaction();
         if ('sale' == $paymentAction) {
             $txn = array('txnID' => $payment_details->payments[0]->transaction_id, 'amount' => $order->get_total(), 'refunded_amount' => 0);
             if ('Completed' == $payment_details->payments[0]->payment_status) {
                 $txn['status'] = 'Completed';
             } else {
                 $txn['status'] = $payment_details->payments[0]->payment_status . '_' . $payment_details->payments[0]->pending_reason;
             }
             $txnData['refundable_txns'][] = $txn;
         } elseif ('authorization' == $paymentAction) {
             $txnData['auth_status'] = 'NotCompleted';
         }
         $txnData['txn_type'] = $paymentAction;
         update_post_meta($order->id, '_woo_pp_txnData', $txnData);
         // Payment was taken so clear session
         $this->maybe_clear_session_data();
         // Handle order
         $this->handle_payment_response($order, $payment_details->payments[0]);
     } else {
         throw new PayPal_API_Exception($response);
     }
 }
 /**
  * Maybe received credentials after successfully returned from IPS flow.
  *
  * @return mixed
  */
 public function maybe_received_credentials()
 {
     if (!is_admin() || !is_user_logged_in()) {
         return false;
     }
     // Require the nonce.
     if (empty($_GET['wc_ppec_ips_admin_nonce']) || empty($_GET['env'])) {
         return false;
     }
     $env = in_array($_GET['env'], array('live', 'sandbox')) ? $_GET['env'] : 'live';
     // Verify the nonce.
     if (!wp_verify_nonce($_GET['wc_ppec_ips_admin_nonce'], 'wc_ppec_ips')) {
         wp_die(__('Invalid connection request', 'woocommerce-gateway-paypal-express-checkout'));
     }
     wc_gateway_ppec_log(sprintf('%s: returned back from IPS flow with parameters: %s', __METHOD__, print_r($_GET, true)));
     // Check if error.
     if (!empty($_GET['error'])) {
         $error_message = !empty($_GET['error_message']) ? $_GET['error_message'] : '';
         wc_gateway_ppec_log(sprintf('%s: returned back from IPS flow with error: %s', __METHOD__, $error_message));
         $this->_redirect_with_messages(__('Sorry, Easy Setup encountered an error.  Please try again.', 'woocommerce-gateway-paypal-express-checkout'));
     }
     // Make sure credentials present in query string.
     foreach (array('api_style', 'api_username', 'api_password', 'signature') as $param) {
         if (empty($_GET[$param])) {
             wc_gateway_ppec_log(sprintf('%s: returned back from IPS flow but missing parameter %s', __METHOD__, $param));
             $this->_redirect_with_messages(__('Sorry, Easy Setup encountered an error.  Please try again.', 'woocommerce-gateway-paypal-express-checkout'));
         }
     }
     $creds = new WC_Gateway_PPEC_Client_Credential_Signature($_GET['api_username'], $_GET['api_password'], $_GET['signature']);
     $error_msgs = array();
     try {
         $payer_id = wc_gateway_ppec()->client->test_api_credentials($creds, $env);
         if (!$payer_id) {
             $this->_redirect_with_messages(__('Easy Setup was able to obtain your API credentials, but was unable to verify that they work correctly.  Please make sure your PayPal account is set up properly and try Easy Setup again.', 'woocommerce-gateway-paypal-express-checkout'));
         }
     } catch (PayPal_API_Exception $ex) {
         $error_msgs[] = array('warning' => __('Easy Setup was able to obtain your API credentials, but an error occurred while trying to verify that they work correctly.  Please try Easy Setup again.', 'woocommerce-gateway-paypal-express-checkout'));
     }
     $error_msgs[] = array('success' => __('Success!  Your PayPal account has been set up successfully.', 'woocommerce-gateway-paypal-express-checkout'));
     if (!empty($error_msgs)) {
         wc_gateway_ppec_log(sprintf('%s: returned back from IPS flow: %s', __METHOD__, print_r($error_msgs, true)));
     }
     // Save credentials to settings API
     $settings_array = (array) get_option('woocommerce_ppec_paypal_settings', array());
     if ('live' === $env) {
         $settings_array['environment'] = 'live';
         $settings_array['api_username'] = $creds->get_username();
         $settings_array['api_password'] = $creds->get_password();
         $settings_array['api_signature'] = is_callable(array($creds, 'get_signature')) ? $creds->get_signature() : '';
         $settings_array['api_certificate'] = is_callable(array($creds, 'get_certificate')) ? $creds->get_certificate() : '';
         $settings_array['api_subject'] = $creds->get_subject();
     } else {
         $settings_array['environment'] = 'sandbox';
         $settings_array['sandbox_api_username'] = $creds->get_username();
         $settings_array['sandbox_api_password'] = $creds->get_password();
         $settings_array['sandbox_api_signature'] = is_callable(array($creds, 'get_signature')) ? $creds->get_signature() : '';
         $settings_array['sandbox_api_certificate'] = is_callable(array($creds, 'get_certificate')) ? $creds->get_certificate() : '';
         $settings_array['sandbox_api_subject'] = $creds->get_subject();
     }
     update_option('woocommerce_ppec_paypal_settings', $settings_array);
     $this->_redirect_with_messages($error_msgs);
 }
<?php

if (!defined('ABSPATH')) {
    exit;
}
$api_username = $this->get_option('api_username');
$sandbox_api_username = $this->get_option('sandbox_api_username');
$needs_creds = empty($api_username);
$needs_sandbox_creds = empty($sandbox_api_username);
$enable_ips = wc_gateway_ppec()->ips->is_supported();
if ($enable_ips && $needs_creds) {
    $ips_button = '<a href="' . esc_url(wc_gateway_ppec()->ips->get_signup_url('live')) . '" class="button button-primary">' . __('Setup or link an existing PayPal account', 'woocommerce-gateway-paypal-express-checkout') . '</a>';
    $api_creds_text = sprintf(__('%s or <a href="#" class="ppec-toggle-settings">click here to toggle manual API credential input</a>.', 'woocommerce-gateway-paypal-express-checkout'), $ips_button);
} else {
    $api_creds_text = '';
}
if ($enable_ips && $needs_sandbox_creds) {
    $sandbox_ips_button = '<a href="' . esc_url(wc_gateway_ppec()->ips->get_signup_url('sandbox')) . '" class="button button-primary">' . __('Setup or link an existing PayPal Sandbox account', 'woocommerce-gateway-paypal-express-checkout') . '</a>';
    $sandbox_api_creds_text = sprintf(__('%s or <a href="#" class="ppec-toggle-sandbox-settings">click here to toggle manual API credential input</a>.', 'woocommerce-gateway-paypal-express-checkout'), $sandbox_ips_button);
} else {
    $sandbox_api_creds_text = '';
}
wc_enqueue_js("\n\tjQuery( function( \$ ) {\n\t\tvar ppec_mark_fields      = '#woocommerce_ppec_paypal_title, #woocommerce_ppec_paypal_description';\n\t\tvar ppec_live_fields      = '#woocommerce_ppec_paypal_api_username, #woocommerce_ppec_paypal_api_password, #woocommerce_ppec_paypal_api_signature, #woocommerce_ppec_paypal_api_certificate, #woocommerce_ppec_paypal_api_subject';\n\t\tvar ppec_sandbox_fields   = '#woocommerce_ppec_paypal_sandbox_api_username, #woocommerce_ppec_paypal_sandbox_api_password, #woocommerce_ppec_paypal_sandbox_api_signature, #woocommerce_ppec_paypal_sandbox_api_certificate, #woocommerce_ppec_paypal_sandbox_api_subject';\n\n\t\tvar enable_toggle         = \$( 'a.ppec-toggle-settings' ).length > 0;\n\t\tvar enable_sandbox_toggle = \$( 'a.ppec-toggle-sandbox-settings' ).length > 0;\n\n\t\t\$( '#woocommerce_ppec_paypal_environment' ).change(function(){\n\t\t\t\$( ppec_sandbox_fields + ',' + ppec_live_fields ).closest( 'tr' ).hide();\n\n\t\t\tif ( 'live' === \$( this ).val() ) {\n\t\t\t\t\$( '#woocommerce_ppec_paypal_api_credentials, #woocommerce_ppec_paypal_api_credentials + p' ).show();\n\t\t\t\t\$( '#woocommerce_ppec_paypal_sandbox_api_credentials, #woocommerce_ppec_paypal_sandbox_api_credentials + p' ).hide();\n\n\t\t\t\tif ( ! enable_toggle ) {\n\t\t\t\t\t\$( ppec_live_fields ).closest( 'tr' ).show();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t\$( '#woocommerce_ppec_paypal_api_credentials, #woocommerce_ppec_paypal_api_credentials + p' ).hide();\n\t\t\t\t\$( '#woocommerce_ppec_paypal_sandbox_api_credentials, #woocommerce_ppec_paypal_sandbox_api_credentials + p' ).show();\n\n\t\t\t\tif ( ! enable_sandbox_toggle ) {\n\t\t\t\t\t\$( ppec_sandbox_fields ).closest( 'tr' ).show();\n\t\t\t\t}\n\t\t\t}\n\t\t}).change();\n\n\t\t\$( '#woocommerce_ppec_paypal_mark_enabled' ).change(function(){\n\t\t\tif ( \$( this ).is( ':checked' ) ) {\n\t\t\t\t\$( ppec_mark_fields ).closest( 'tr' ).show();\n\t\t\t} else {\n\t\t\t\t\$( ppec_mark_fields ).closest( 'tr' ).hide();\n\t\t\t}\n\t\t}).change();\n\n\t\t\$( '#woocommerce_ppec_paypal_paymentaction' ).change(function(){\n\t\t\tif ( 'sale' === \$( this ).val() ) {\n\t\t\t\t\$( '#woocommerce_ppec_paypal_instant_payments' ).closest( 'tr' ).show();\n\t\t\t} else {\n\t\t\t\t\$( '#woocommerce_ppec_paypal_instant_payments' ).closest( 'tr' ).hide();\n\t\t\t}\n\t\t}).change();\n\n\t\tif ( enable_toggle ) {\n\t\t\t\$( document ).on( 'click', '.ppec-toggle-settings', function() {\n\t\t\t\t\$( ppec_live_fields ).closest( 'tr' ).toggle();\n\t\t\t} );\n\t\t}\n\t\tif ( enable_sandbox_toggle ) {\n\t\t\t\$( document ).on( 'click', '.ppec-toggle-sandbox-settings', function() {\n\t\t\t\t\$( ppec_sandbox_fields ).closest( 'tr' ).toggle();\n\t\t\t} );\n\t\t}\n\t});\n");
/**
 * Settings for PayPal Gateway.
 */
return array('enabled' => array('title' => __('Enable/Disable', 'woocommerce-gateway-paypal-express-checkout'), 'type' => 'checkbox', 'label' => __('Enable PayPal Express Checkout', 'woocommerce-gateway-paypal-express-checkout'), 'description' => __('This enables PayPal Express Checkout which allows customers to checkout directly via PayPal from your cart page.', 'woocommerce-gateway-paypal-express-checkout'), 'desc_tip' => true, 'default' => 'yes'), 'button_size' => array('title' => __('Button Size', 'woocommerce-gateway-paypal-express-checkout'), 'type' => 'select', 'class' => 'wc-enhanced-select', 'description' => __('PayPal offers different sizes of the "PayPal Checkout" buttons, allowing you to select a size that best fits your site\'s theme. This setting will allow you to choose which size button(s) appear on your cart page.', 'woocommerce-gateway-paypal-express-checkout'), 'default' => 'large', 'desc_tip' => true, 'options' => array('small' => __('Small', 'woocommerce-gateway-paypal-express-checkout'), 'medium' => __('Medium', 'woocommerce-gateway-paypal-express-checkout'), 'large' => __('Large', 'woocommerce-gateway-paypal-express-checkout'))), 'environment' => array('title' => __('Environment', 'woocommerce-gateway-paypal-express-checkout'), 'type' => 'select', 'class' => 'wc-enhanced-select', 'description' => __('This setting specifies whether you will process live transactions, or whether you will process simulated transactions using the PayPal Sandbox.', 'woocommerce-gateway-paypal-express-checkout'), 'default' => 'live', 'desc_tip' => true, 'options' => array('live' => __('Live', 'woocommerce-gateway-paypal-express-checkout'), 'sandbox' => __('Sandbox', 'woocommerce-gateway-paypal-express-checkout'))), 'mark_enabled' => array('title' => __('PayPal Mark', 'woocommerce-gateway-paypal-express-checkout'), 'type' => 'checkbox', 'label' => __('Enable the PayPal Mark on regular checkout', 'woocommerce-gateway-paypal-express-checkout'), 'description' => __('This enables the PayPal mark, which can be shown on regular WooCommerce checkout to use PayPal Express Checkout like a regular WooCommerce gateway.', 'woocommerce-gateway-paypal-express-checkout'), 'desc_tip' => true, 'default' => 'no'), 'title' => array('title' => __('Title', 'woocommerce-gateway-paypal-express-checkout'), 'type' => 'text', 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-paypal-express-checkout'), 'default' => __('PayPal Express Checkout', 'woocommerce-gateway-paypal-express-checkout'), 'desc_tip' => true), 'description' => array('title' => __('Description', 'woocommerce-gateway-paypal-express-checkout'), 'type' => 'text', 'desc_tip' => true, 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-paypal-express-checkout'), 'default' => __('Pay using either your PayPal account or credit card. All credit card payments will be processed by PayPal.', 'woocommerce-gateway-paypal-express-checkout')), 'api_credentials' => array('title' => __('API Credentials', 'woocommerce-gateway-paypal-express-checkout'), 'type' => 'title', 'description' => $api_creds_text), 'api_username' => array('title' => __('Live API Username', 'woocommerce-gateway-paypal-express-checkout'), 'type' => 'text', 'description' => __('Get your API credentials from PayPal.', 'woocommerce-gateway-paypal-express-checkout'), 'default' => '', 'desc_tip' => true), 'api_password' => array('title' => __('Live API Password', 'woocommerce-gateway-paypal-express-checkout'), 'type' => 'password', 'description' => __('Get your API credentials from PayPal.', 'woocommerce-gateway-paypal-express-checkout'), 'default' => '', 'desc_tip' => true), 'api_signature' => array('title' => __('Live API Signature', 'woocommerce-gateway-paypal-express-checkout'), 'type' => 'text', 'description' => __('Get your API credentials from PayPal.', 'woocommerce-gateway-paypal-express-checkout'), 'default' => '', 'desc_tip' => true, 'placeholder' => __('Optional if you provide a certificate below', 'woocommerce-gateway-paypal-express-checkout')), 'api_certificate' => array('title' => __('Live API Certificate', 'woocommerce-gateway-paypal-express-checkout'), 'type' => 'file', 'description' => $this->get_certificate_info($this->get_option('api_certificate')), 'default' => ''), 'api_subject' => array('title' => __('Live API Subject', 'woocommerce-gateway-paypal-express-checkout'), 'type' => 'text', 'description' => __('If you\'re processing transactions on behalf of someone else\'s PayPal account, enter their email address or Secure Merchant Account ID (also known as a Payer ID) here. Generally, you must have API permissions in place with the other account in order to process anything other than "sale" transactions for them.', 'woocommerce-gateway-paypal-express-checkout'), 'default' => '', 'desc_tip' => true, 'placeholder' => __('Optional', 'woocommerce-gateway-paypal-express-checkout')), 'sandbox_api_credentials' => array('title' => __('Sandbox API Credentials', 'woocommerce-gateway-paypal-express-checkout'), 'type' => 'title', 'description' => $sandbox_api_creds_text), 'sandbox_api_username' => array('title' => __('Sandbox API Username', 'woocommerce-gateway-paypal-express-checkout'), 'type' => 'text', 'description' => __('Get your API credentials from PayPal.', 'woocommerce-gateway-paypal-express-checkout'), 'default' => '', 'desc_tip' => true), 'sandbox_api_password' => array('title' => __('Sandbox API Password', 'woocommerce-gateway-paypal-express-checkout'), 'type' => 'password', 'description' => __('Get your API credentials from PayPal.', 'woocommerce-gateway-paypal-express-checkout'), 'default' => '', 'desc_tip' => true), 'sandbox_api_signature' => array('title' => __('Sandbox API Signature', 'woocommerce-gateway-paypal-express-checkout'), 'type' => 'text', 'description' => __('Get your API credentials from PayPal.', 'woocommerce-gateway-paypal-express-checkout'), 'default' => '', 'desc_tip' => true), 'sandbox_api_certificate' => array('title' => __('Sandbox API Certificate', 'woocommerce-gateway-paypal-express-checkout'), 'type' => 'file', 'description' => __('Get your API credentials from PayPal.', 'woocommerce-gateway-paypal-express-checkout'), 'default' => '', 'desc_tip' => true), 'sandbox_api_subject' => array('title' => __('Sandbox API Subject', 'woocommerce-gateway-paypal-express-checkout'), 'type' => 'text', 'description' => __('If you\'re processing transactions on behalf of someone else\'s PayPal account, enter their email address or Secure Merchant Account ID (also known as a Payer ID) here. Generally, you must have API permissions in place with the other account in order to process anything other than "sale" transactions for them.', 'woocommerce-gateway-paypal-express-checkout'), 'default' => '', 'desc_tip' => true, 'placeholder' => __('Optional', 'woocommerce-gateway-paypal-express-checkout')), 'advanced' => array('title' => __('Advanced Settings', 'woocommerce-gateway-paypal-express-checkout'), 'type' => 'title', 'description' => ''), 'debug' => array('title' => __('Debug Log', 'woocommerce-gateway-paypal-express-checkout'), 'type' => 'checkbox', 'label' => __('Enable Logging', 'woocommerce-gateway-paypal-express-checkout'), 'default' => 'no', 'desc_tip' => true, 'description' => __('Log PayPal events, such as IPN requests.', 'woocommerce-gateway-paypal-express-checkout')), 'invoice_prefix' => array('title' => __('Invoice Prefix', 'woocommerce-gateway-paypal-express-checkout'), 'type' => 'text', 'description' => __('Please enter a prefix for your invoice numbers. If you use your PayPal account for multiple stores ensure this prefix is unique as PayPal will not allow orders with the same invoice number.', 'woocommerce-gateway-paypal-express-checkout'), 'default' => 'WC-', 'desc_tip' => true), 'require_billing' => array('title' => __('Billing Addresses', 'woocommerce-gateway-paypal-express-checkout'), 'type' => 'checkbox', 'label' => __('Require Billing Address', 'woocommerce-gateway-paypal-express-checkout'), 'default' => 'no', 'desc_tip' => true, 'description' => __('PayPal does not share buyer billing details with you. However, there are times when you must collect the buyer billing address to fulfill an essential business function (such as determining whether you must charge the buyer tax). Enable this function to collect the address before payment is taken.', 'woocommerce-gateway-paypal-express-checkout')), 'paymentaction' => array('title' => __('Payment Action', 'woocommerce-gateway-paypal-express-checkout'), 'type' => 'select', 'class' => 'wc-enhanced-select', 'description' => __('Choose whether you wish to capture funds immediately or authorize payment only.', 'woocommerce-gateway-paypal-express-checkout'), 'default' => 'sale', 'desc_tip' => true, 'options' => array('sale' => __('Sale', 'woocommerce-gateway-paypal-express-checkout'), 'authorization' => __('Authorize', 'woocommerce-gateway-paypal-express-checkout'))), 'instant_payments' => array('title' => __('Instant Payments', 'woocommerce-gateway-paypal-express-checkout'), 'type' => 'checkbox', 'label' => __('Require Instant Payment', 'woocommerce-gateway-paypal-express-checkout'), 'default' => 'no', 'desc_tip' => true, 'description' => __('If you enable this setting, PayPal will be instructed not to allow the buyer to use funding sources that take additional time to complete (for example, eChecks). Instead, the buyer will be required to use an instant funding source, such as an instant transfer, a credit/debit card, or PayPal Credit.', 'woocommerce-gateway-paypal-express-checkout')), 'logo_image_url' => array('title' => __('Logo Image URL', 'woocommerce-gateway-paypal-express-checkout'), 'type' => 'text', 'description' => __('If you want PayPal to co-brand the checkout page with your logo, enter the URL of your logo image here.<br/>The image must be no larger than 190x60, GIF, PNG, or JPG format, and should be served over HTTPS.', 'woocommerce-gateway-paypal-express-checkout'), 'default' => '', 'desc_tip' => true, 'placeholder' => __('Optional', 'woocommerce-gateway-paypal-express-checkout')), 'subtotal_mismatch_behavior' => array('title' => __('Subtotal Mismatch Behavior', 'woocommerce-gateway-paypal-express-checkout'), 'type' => 'select', 'class' => 'wc-enhanced-select', 'description' => __('Internally, WC calculates line item prices and taxes out to four decimal places; however, PayPal can only handle amounts out to two decimal places (or, depending on the currency, no decimal places at all). Occasionally, this can cause discrepancies between the way WooCommerce calculates prices versus the way PayPal calculates them. If a mismatch occurs, this option controls how the order is dealt with so payment can still be taken.', 'woocommerce-gateway-paypal-express-checkout'), 'default' => 'add', 'desc_tip' => true, 'options' => array('add' => __('Add another line item', 'woocommerce-gateway-paypal-express-checkout'), 'drop' => __('Do not send line items to PayPal', 'woocommerce-gateway-paypal-express-checkout'))));
					<option value="<?php 
echo WC_Gateway_PPEC_Settings::subtotalMismatchBehaviorAddLineItem;
?>
"<?php 
selected($subtotal_mismatch_behavior, WC_Gateway_PPEC_Settings::subtotalMismatchBehaviorAddLineItem);
?>
><?php 
_e('Add another line item', 'woocommerce-gateway-paypal-express-checkout');
?>
</option>
					<option value="<?php 
echo WC_Gateway_PPEC_Settings::subtotalMismatchBehaviorDropLineItems;
?>
"<?php 
selected($subtotal_mismatch_behavior, WC_Gateway_PPEC_Settings::subtotalMismatchBehaviorDropLineItems);
?>
><?php 
_e('Don\'t send line items to PayPal', 'woocommerce-gateway-paypal-express-checkout');
?>
'</option>
				</select>
			</fieldset>
		</td>
	</tr>
</table>

<script type="text/javascript" src="<?php 
echo esc_url(wc_gateway_ppec()->plugin_url . 'assets/js/wc-gateway-ppec-admin-settings.js');
?>
"></script>
<?php

/**
 * TODO: Move each class into its own file and group them under one dir, checkout-details.
 */
if (!defined('ABSPATH')) {
    exit;
    // Exit if accessed directly
}
$includes_path = wc_gateway_ppec()->includes_path;
require_once $includes_path . 'class-wc-gateway-ppec-address.php';
class PayPal_Checkout_Details
{
    public $token = false;
    public $custom = false;
    public $invnum = false;
    public $phone_number = false;
    public $billing_agreement_accepted = false;
    const BillingAgreementNotAccepted = '0';
    const BillingAgreementAccepted = '1';
    public $paypal_adjustment = false;
    public $redirect_required_after_payment = false;
    public $checkout_status = false;
    const PaymentNotAttempted = 'PaymentActionNotInitiated';
    const PaymentFailed = 'PaymentActionFailed';
    const PaymentInProgress = 'PaymentActionInProgress';
    const PaymentCompleted = 'PaymentActionCompleted';
    public $gift_details = false;
    public $buyer_marketing_email = false;
    public $survey_question = false;
    public $survey_choice_selected = false;
 /**
  * Validate the provided credentials.
  */
 protected function validate_active_credentials()
 {
     $settings = wc_gateway_ppec()->settings->load_settings(true);
     $creds = $settings->get_active_api_credentials();
     $username = $creds->get_username();
     $password = $creds->get_password();
     if (!empty($username)) {
         if (empty($password)) {
             WC_Admin_Settings::add_error(__('Error: You must enter API password.', 'woocommerce-gateway-paypal-express-checkout'));
             return false;
         }
         if (is_a($creds, 'WC_Gateway_PPEC_Client_Credential_Signature') && $creds->get_signature()) {
             try {
                 $payer_id = wc_gateway_ppec()->client->test_api_credentials($creds, $settings->get_environment());
                 if (!$payer_id) {
                     WC_Admin_Settings::add_error(sprintf(__('Error: The %s credentials you provided are not valid.  Please double-check that you entered them correctly and try again.', 'woocommerce-gateway-paypal-express-checkout'), __($settings->get_environment(), 'woocommerce-gateway-paypal-express-checkout')));
                     return false;
                 }
             } catch (PayPal_API_Exception $ex) {
                 WC_Admin_Settings::add_error(sprintf(__('An error occurred while trying to validate your %s API credentials.  Unable to verify that your API credentials are correct.', 'woocommerce-gateway-paypal-express-checkout'), __($settings->get_environment(), 'woocommerce-gateway-paypal-express-checkout')));
             }
         } elseif (is_a($creds, 'WC_Gateway_PPEC_Client_Credential_Certificate') && $creds->get_certificate()) {
             $cert = @openssl_x509_read($creds->get_certificate());
             if (false === $cert) {
                 WC_Admin_Settings::add_error(sprintf(__('Error: The %s API certificate is not valid.', 'woocommerce-gateway-paypal-express-checkout'), __($settings->get_environment(), 'woocommerce-gateway-paypal-express-checkout')));
                 return false;
             }
             $cert_info = openssl_x509_parse($cert);
             $valid_until = $cert_info['validTo_time_t'];
             if ($valid_until < time()) {
                 WC_Admin_Settings::add_error(sprintf(__('Error: The %s API certificate has expired.', 'woocommerce-gateway-paypal-express-checkout'), __($settings->get_environment(), 'woocommerce-gateway-paypal-express-checkout')));
                 return false;
             }
             if ($cert_info['subject']['CN'] != $creds->get_username()) {
                 WC_Admin_Settings::add_error(__('Error: The API username does not match the name in the API certificate.  Make sure that you have the correct API certificate.', 'woocommerce-gateway-paypal-express-checkout'));
                 return false;
             }
             try {
                 $payer_id = wc_gateway_ppec()->client->test_api_credentials($creds, $settings->get_environment());
                 if (!$payer_id) {
                     WC_Admin_Settings::add_error(sprintf(__('Error: The %s credentials you provided are not valid.  Please double-check that you entered them correctly and try again.', 'woocommerce-gateway-paypal-express-checkout'), __($settings->get_environment(), 'woocommerce-gateway-paypal-express-checkout')));
                     return false;
                 }
             } catch (PayPal_API_Exception $ex) {
                 WC_Admin_Settings::add_error(sprintf(__('An error occurred while trying to validate your %s API credentials.  Unable to verify that your API credentials are correct.', 'woocommerce-gateway-paypal-express-checkout'), __($settings->get_environment(), 'woocommerce-gateway-paypal-express-checkout')));
             }
         } else {
             WC_Admin_Settings::add_error(sprintf(__('Error: You must provide a %s API signature or certificate.', 'woocommerce-gateway-paypal-express-checkout'), __($settings->get_environment(), 'woocommerce-gateway-paypal-express-checkout')));
             return false;
         }
         $settings_array = (array) get_option('woocommerce_ppec_paypal_settings', array());
         if ('yes' === $settings_array['require_billing']) {
             $is_account_enabled_for_billing_address = false;
             try {
                 $is_account_enabled_for_billing_address = wc_gateway_ppec()->client->test_for_billing_address_enabled($creds, $settings->get_environment());
             } catch (PayPal_API_Exception $ex) {
                 $is_account_enabled_for_billing_address = false;
             }
             if (!$is_account_enabled_for_billing_address) {
                 $settings_array['require_billing'] = 'no';
                 update_option('woocommerce_ppec_paypal_settings', $settings_array);
                 WC_Admin_Settings::add_error(__('The "require billing address" option is not enabled by your account and has been disabled.', 'woocommerce-gateway-paypal-express-checkout'));
             }
         }
     }
 }
 /**
  * Allow certificate-based credential to configure cURL, especially
  * to set CURLOPT_SSLCERT and CURLOPT_SSLCERTPASSWD.
  *
  * @throws Exception
  *
  * @param resource &$handle The cURL handle returned by curl_init().
  * @param array    $r       The HTTP request arguments.
  * @param string   $url     The request URL.
  *
  * @return void
  */
 public function configure_curl($handle, $r, $url)
 {
     curl_setopt($handle, CURLOPT_CAINFO, wc_gateway_ppec()->includes_path . 'pem/bundle.pem');
 }
 * Text Domain: woocommerce-gateway-paypal-express-checkout
 * Domain Path: /languages
 */
/**
 * Copyright (c) 2015 PayPal, Inc.
 *
 * The name of the PayPal may not be used to endorse or promote products derived from this
 * software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND
 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */
if (!defined('ABSPATH')) {
    exit;
    // Exit if accessed directly
}
/**
 * Return instance of WC_Gateway_PPEC_Plugin.
 *
 * @return WC_Gateway_PPEC_Plugin
 */
function wc_gateway_ppec()
{
    static $plugin;
    if (!isset($plugin)) {
        require_once 'includes/class-wc-gateway-ppec-plugin.php';
        $plugin = new WC_Gateway_PPEC_Plugin(__FILE__, '1.1.2');
    }
    return $plugin;
}
wc_gateway_ppec()->maybe_run();
 /**
  * Maybe redirect to wc_gateway_ppec_with_paypal from PayPal standard
  * checkout settings.
  *
  * @return void
  */
 public function maybe_redirect_to_ppec_settings()
 {
     if (!wc_gateway_ppec()->settings->enabled) {
         return;
     }
     if (empty($_GET['tab']) || empty($_GET['section'])) {
         return;
     }
     if ('checkout' === $_GET['tab'] && 'wc_gateway_paypal' === $_GET['section']) {
         $redirect = add_query_arg(array('section' => 'wc_gateway_ppec_with_paypal'));
         wp_safe_redirect($redirect);
     }
 }