id = 'paypal'; $this->has_fields = false; $this->order_button_text = __( 'Proceed to PayPal', 'woocommerce' ); $this->method_title = __( 'PayPal', 'woocommerce' ); $this->method_description = sprintf( __( 'PayPal Standard sends customers to PayPal to enter their payment information. PayPal IPN requires fsockopen/cURL support to update order statuses after payment. Check the system status page for more details.', 'woocommerce' ), admin_url( 'admin.php?page=wc-status' ) ); $this->supports = array( 'products', 'refunds', ); // Load the settings. $this->init_form_fields(); $this->init_settings(); // Define user set variables. $this->title = $this->get_option( 'title' ); $this->description = $this->get_option( 'description' ); $this->testmode = 'yes' === $this->get_option( 'testmode', 'no' ); $this->debug = 'yes' === $this->get_option( 'debug', 'no' ); $this->email = $this->get_option( 'email' ); $this->receiver_email = $this->get_option( 'receiver_email', $this->email ); $this->identity_token = $this->get_option( 'identity_token' ); self::$log_enabled = $this->debug; add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) ); add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) ); if ( ! $this->is_valid_for_use() ) { $this->enabled = 'no'; } else { include_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-paypal-ipn-handler.php' ); new WC_Gateway_Paypal_IPN_Handler( $this->testmode, $this->receiver_email ); if ( $this->identity_token ) { include_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-paypal-pdt-handler.php' ); new WC_Gateway_Paypal_PDT_Handler( $this->testmode, $this->identity_token ); } } } /** * Logging method. * * @param string $message Log message. * @param string $level Optional. Default 'info'. * emergency|alert|critical|error|warning|notice|info|debug */ public static function log( $message, $level = 'info' ) { if ( self::$log_enabled ) { if ( empty( self::$log ) ) { self::$log = wc_get_logger(); } self::$log->log( $level, $message, array( 'source' => 'paypal' ) ); } } /** * Get gateway icon. * @return string */ public function get_icon() { $icon_html = ''; $icon = (array) $this->get_icon_image( WC()->countries->get_base_country() ); foreach ( $icon as $i ) { $icon_html .= ''; } $icon_html .= sprintf( '' . esc_attr__( 'What is PayPal?', 'woocommerce' ) . '', esc_url( $this->get_icon_url( WC()->countries->get_base_country() ) ) ); return apply_filters( 'woocommerce_gateway_icon', $icon_html, $this->id ); } /** * Get the link for an icon based on country. * @param string $country * @return string */ protected function get_icon_url( $country ) { $url = 'https://www.paypal.com/' . strtolower( $country ); $home_counties = array( 'BE', 'CZ', 'DK', 'HU', 'IT', 'JP', 'NL', 'NO', 'ES', 'SE', 'TR', 'IN' ); $countries = array( 'DZ', 'AU', 'BH', 'BQ', 'BW', 'CA', 'CN', 'CW', 'FI', 'FR', 'DE', 'GR', 'HK', 'ID', 'JO', 'KE', 'KW', 'LU', 'MY', 'MA', 'OM', 'PH', 'PL', 'PT', 'QA', 'IE', 'RU', 'BL', 'SX', 'MF', 'SA', 'SG', 'SK', 'KR', 'SS', 'TW', 'TH', 'AE', 'GB', 'US', 'VN' ); if ( in_array( $country, $home_counties ) ) { return $url . '/webapps/mpp/home'; } elseif ( in_array( $country, $countries ) ) { return $url . '/webapps/mpp/paypal-popup'; } else { return $url . '/cgi-bin/webscr?cmd=xpt/Marketing/general/WIPaypal-outside'; } } /** * Get PayPal images for a country. * * @param string $country Country code. * @return array of image URLs */ protected function get_icon_image( $country ) { switch ( $country ) { case 'US' : case 'NZ' : case 'CZ' : case 'HU' : case 'MY' : $icon = 'https://www.paypalobjects.com/webstatic/mktg/logo/AM_mc_vs_dc_ae.jpg'; break; case 'TR' : $icon = 'https://www.paypalobjects.com/webstatic/mktg/logo-center/logo_paypal_odeme_secenekleri.jpg'; break; case 'GB' : $icon = 'https://www.paypalobjects.com/webstatic/mktg/Logo/AM_mc_vs_ms_ae_UK.png'; break; case 'MX' : $icon = array( 'https://www.paypal.com/es_XC/Marketing/i/banner/paypal_visa_mastercard_amex.png', 'https://www.paypal.com/es_XC/Marketing/i/banner/paypal_debit_card_275x60.gif', ); break; case 'FR' : $icon = 'https://www.paypalobjects.com/webstatic/mktg/logo-center/logo_paypal_moyens_paiement_fr.jpg'; break; case 'AU' : $icon = 'https://www.paypalobjects.com/webstatic/en_AU/mktg/logo/Solutions-graphics-1-184x80.jpg'; break; case 'DK' : $icon = 'https://www.paypalobjects.com/webstatic/mktg/logo-center/logo_PayPal_betalingsmuligheder_dk.jpg'; break; case 'RU' : $icon = 'https://www.paypalobjects.com/webstatic/ru_RU/mktg/business/pages/logo-center/AM_mc_vs_dc_ae.jpg'; break; case 'NO' : $icon = 'https://www.paypalobjects.com/webstatic/mktg/logo-center/banner_pl_just_pp_319x110.jpg'; break; case 'CA' : $icon = 'https://www.paypalobjects.com/webstatic/en_CA/mktg/logo-image/AM_mc_vs_dc_ae.jpg'; break; case 'HK' : $icon = 'https://www.paypalobjects.com/webstatic/en_HK/mktg/logo/AM_mc_vs_dc_ae.jpg'; break; case 'SG' : $icon = 'https://www.paypalobjects.com/webstatic/en_SG/mktg/Logos/AM_mc_vs_dc_ae.jpg'; break; case 'TW' : $icon = 'https://www.paypalobjects.com/webstatic/en_TW/mktg/logos/AM_mc_vs_dc_ae.jpg'; break; case 'TH' : $icon = 'https://www.paypalobjects.com/webstatic/en_TH/mktg/Logos/AM_mc_vs_dc_ae.jpg'; break; case 'JP' : $icon = 'https://www.paypal.com/ja_JP/JP/i/bnr/horizontal_solution_4_jcb.gif'; break; case 'IN' : $icon = 'https://www.paypalobjects.com/webstatic/mktg/logo/AM_mc_vs_dc_ae.jpg'; break; default : $icon = WC_HTTPS::force_https_url( WC()->plugin_url() . '/includes/gateways/paypal/assets/images/paypal.png' ); break; } return apply_filters( 'woocommerce_paypal_icon', $icon ); } /** * Check if this gateway is enabled and available in the user's country. * @return bool */ public function is_valid_for_use() { return in_array( get_woocommerce_currency(), apply_filters( 'woocommerce_paypal_supported_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' ) ) ); } /** * Admin Panel Options. * - Options for bits like 'title' and availability on a country-by-country basis. * * @since 1.0.0 */ public function admin_options() { if ( $this->is_valid_for_use() ) { parent::admin_options(); } else { ?>
: