2020-08-18 09:04:58 +03:00
|
|
|
|
<?php
|
2020-08-28 08:13:45 +03:00
|
|
|
|
/**
|
|
|
|
|
* The Credit card gateway.
|
|
|
|
|
*
|
2020-09-11 14:11:10 +03:00
|
|
|
|
* @package WooCommerce\PayPalCommerce\WcGateway\Gateway
|
2020-08-28 08:13:45 +03:00
|
|
|
|
*/
|
2020-08-19 05:39:45 +03:00
|
|
|
|
|
2020-08-18 09:04:58 +03:00
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2020-09-11 14:11:10 +03:00
|
|
|
|
namespace WooCommerce\PayPalCommerce\WcGateway\Gateway;
|
2020-08-18 09:04:58 +03:00
|
|
|
|
|
2020-09-11 14:11:10 +03:00
|
|
|
|
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
|
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice;
|
|
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
|
|
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderProcessor;
|
|
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsRenderer;
|
2020-08-18 09:04:58 +03:00
|
|
|
|
use Psr\Container\ContainerInterface;
|
|
|
|
|
|
2020-08-28 08:13:45 +03:00
|
|
|
|
/**
|
|
|
|
|
* Class CreditCardGateway
|
|
|
|
|
*/
|
2020-09-14 14:17:39 +03:00
|
|
|
|
class CreditCardGateway extends \WC_Payment_Gateway_CC {
|
|
|
|
|
|
|
|
|
|
use ProcessPaymentTrait;
|
2020-08-27 11:08:36 +03:00
|
|
|
|
|
2020-09-11 13:38:02 +03:00
|
|
|
|
const ID = 'ppcp-credit-card-gateway';
|
2020-08-27 11:08:36 +03:00
|
|
|
|
|
2020-08-28 08:13:45 +03:00
|
|
|
|
/**
|
|
|
|
|
* The URL to the module.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
private $module_url;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* CreditCardGateway constructor.
|
|
|
|
|
*
|
|
|
|
|
* @param SettingsRenderer $settings_renderer The Settings Renderer.
|
|
|
|
|
* @param OrderProcessor $order_processor The Order processor.
|
|
|
|
|
* @param AuthorizedPaymentsProcessor $authorized_payments_processor The Authorized Payments processor.
|
|
|
|
|
* @param AuthorizeOrderActionNotice $notice The Notices.
|
|
|
|
|
* @param ContainerInterface $config The settings.
|
|
|
|
|
* @param string $module_url The URL to the module.
|
|
|
|
|
* @param SessionHandler $session_handler The Session Handler.
|
|
|
|
|
*/
|
2020-08-27 11:08:36 +03:00
|
|
|
|
public function __construct(
|
2020-08-28 08:13:45 +03:00
|
|
|
|
SettingsRenderer $settings_renderer,
|
|
|
|
|
OrderProcessor $order_processor,
|
|
|
|
|
AuthorizedPaymentsProcessor $authorized_payments_processor,
|
2020-08-27 11:08:36 +03:00
|
|
|
|
AuthorizeOrderActionNotice $notice,
|
|
|
|
|
ContainerInterface $config,
|
2020-08-28 08:13:45 +03:00
|
|
|
|
string $module_url,
|
|
|
|
|
SessionHandler $session_handler
|
2020-08-27 11:08:36 +03:00
|
|
|
|
) {
|
|
|
|
|
|
2020-08-28 08:13:45 +03:00
|
|
|
|
$this->id = self::ID;
|
|
|
|
|
$this->order_processor = $order_processor;
|
|
|
|
|
$this->authorized_payments = $authorized_payments_processor;
|
|
|
|
|
$this->notice = $notice;
|
|
|
|
|
$this->settings_renderer = $settings_renderer;
|
|
|
|
|
$this->config = $config;
|
|
|
|
|
$this->session_handler = $session_handler;
|
2020-08-27 11:08:36 +03:00
|
|
|
|
if (
|
|
|
|
|
defined( 'PPCP_FLAG_SUBSCRIPTION' )
|
|
|
|
|
&& PPCP_FLAG_SUBSCRIPTION
|
|
|
|
|
&& $this->config->has( 'vault_enabled' )
|
|
|
|
|
&& $this->config->get( 'vault_enabled' )
|
|
|
|
|
) {
|
|
|
|
|
$this->supports = array(
|
|
|
|
|
'products',
|
|
|
|
|
'subscriptions',
|
|
|
|
|
'subscription_cancellation',
|
|
|
|
|
'subscription_suspension',
|
|
|
|
|
'subscription_reactivation',
|
|
|
|
|
'subscription_amount_changes',
|
|
|
|
|
'subscription_date_changes',
|
|
|
|
|
'subscription_payment_method_change',
|
|
|
|
|
'subscription_payment_method_change_customer',
|
|
|
|
|
'subscription_payment_method_change_admin',
|
|
|
|
|
'multiple_subscriptions',
|
2020-09-14 14:17:39 +03:00
|
|
|
|
'credit_card_form_cvc_on_saved_method',
|
2020-08-27 11:08:36 +03:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->method_title = __(
|
2020-09-02 12:21:37 +03:00
|
|
|
|
'PayPal Card Processing',
|
2020-09-11 10:20:12 +03:00
|
|
|
|
'paypal-payments-for-woocommerce'
|
2020-08-27 11:08:36 +03:00
|
|
|
|
);
|
|
|
|
|
$this->method_description = __(
|
2020-09-02 12:21:37 +03:00
|
|
|
|
'Accept debit and credit cards, and local payment methods with PayPal’s latest solution.',
|
2020-09-11 10:20:12 +03:00
|
|
|
|
'paypal-payments-for-woocommerce'
|
2020-08-27 11:08:36 +03:00
|
|
|
|
);
|
|
|
|
|
$this->title = $this->config->has( 'dcc_gateway_title' ) ?
|
|
|
|
|
$this->config->get( 'dcc_gateway_title' ) : $this->method_title;
|
|
|
|
|
$this->description = $this->config->has( 'dcc_gateway_description' ) ?
|
|
|
|
|
$this->config->get( 'dcc_gateway_description' ) : $this->method_description;
|
|
|
|
|
|
|
|
|
|
$this->init_form_fields();
|
|
|
|
|
$this->init_settings();
|
|
|
|
|
|
|
|
|
|
add_action(
|
|
|
|
|
'woocommerce_update_options_payment_gateways_' . $this->id,
|
|
|
|
|
array(
|
|
|
|
|
$this,
|
|
|
|
|
'process_admin_options',
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
2020-08-28 08:13:45 +03:00
|
|
|
|
$this->module_url = $module_url;
|
2020-08-27 11:08:36 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-28 08:13:45 +03:00
|
|
|
|
/**
|
|
|
|
|
* Initialize the form fields.
|
|
|
|
|
*/
|
2020-08-27 11:08:36 +03:00
|
|
|
|
public function init_form_fields() {
|
|
|
|
|
$this->form_fields = array(
|
|
|
|
|
'enabled' => array(
|
2020-09-11 10:20:12 +03:00
|
|
|
|
'title' => __( 'Enable/Disable', 'paypal-payments-for-woocommerce' ),
|
2020-08-27 11:08:36 +03:00
|
|
|
|
'type' => 'checkbox',
|
2020-09-11 10:20:12 +03:00
|
|
|
|
'label' => __( 'Enable Credit Card Payments', 'paypal-payments-for-woocommerce' ),
|
2020-08-27 11:08:36 +03:00
|
|
|
|
'default' => 'no',
|
|
|
|
|
),
|
|
|
|
|
'ppcp' => array(
|
|
|
|
|
'type' => 'ppcp',
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-28 08:13:45 +03:00
|
|
|
|
/**
|
|
|
|
|
* Returns the title of the gateway.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2020-08-27 11:08:36 +03:00
|
|
|
|
public function get_title() {
|
|
|
|
|
|
|
|
|
|
if ( is_admin() ) {
|
|
|
|
|
return parent::get_title();
|
|
|
|
|
}
|
|
|
|
|
$title = parent::get_title();
|
|
|
|
|
$icons = $this->config->has( 'card_icons' ) ? (array) $this->config->get( 'card_icons' ) : array();
|
|
|
|
|
if ( empty( $icons ) ) {
|
|
|
|
|
return $title;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-28 08:13:45 +03:00
|
|
|
|
$title_options = $this->card_labels();
|
|
|
|
|
$images = array_map(
|
|
|
|
|
function ( string $type ) use ( $title_options ): string {
|
2020-08-27 11:08:36 +03:00
|
|
|
|
return '<img
|
2020-08-28 08:13:45 +03:00
|
|
|
|
title="' . esc_attr( $title_options[ $type ] ) . '"
|
|
|
|
|
src="' . esc_url( $this->module_url ) . '/assets/images/' . esc_attr( $type ) . '.svg"
|
2020-08-21 09:53:32 +03:00
|
|
|
|
class="ppcp-card-icon"
|
|
|
|
|
> ';
|
2020-08-27 11:08:36 +03:00
|
|
|
|
},
|
|
|
|
|
$icons
|
|
|
|
|
);
|
|
|
|
|
return $title . implode( '', $images );
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-28 08:13:45 +03:00
|
|
|
|
/**
|
|
|
|
|
* Returns an array of credit card names.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
private function card_labels(): array {
|
2020-08-27 11:08:36 +03:00
|
|
|
|
return array(
|
|
|
|
|
'visa' => _x(
|
|
|
|
|
'Visa',
|
|
|
|
|
'Name of credit card',
|
2020-09-11 10:20:12 +03:00
|
|
|
|
'paypal-payments-for-woocommerce'
|
2020-08-27 11:08:36 +03:00
|
|
|
|
),
|
|
|
|
|
'mastercard' => _x(
|
|
|
|
|
'Mastercard',
|
|
|
|
|
'Name of credit card',
|
2020-09-11 10:20:12 +03:00
|
|
|
|
'paypal-payments-for-woocommerce'
|
2020-08-27 11:08:36 +03:00
|
|
|
|
),
|
|
|
|
|
'amex' => _x(
|
|
|
|
|
'American Express',
|
|
|
|
|
'Name of credit card',
|
2020-09-11 10:20:12 +03:00
|
|
|
|
'paypal-payments-for-woocommerce'
|
2020-08-27 11:08:36 +03:00
|
|
|
|
),
|
|
|
|
|
'discover' => _x(
|
|
|
|
|
'Discover',
|
|
|
|
|
'Name of credit card',
|
2020-09-11 10:20:12 +03:00
|
|
|
|
'paypal-payments-for-woocommerce'
|
2020-08-27 11:08:36 +03:00
|
|
|
|
),
|
|
|
|
|
'jcb' => _x(
|
|
|
|
|
'JCB',
|
|
|
|
|
'Name of credit card',
|
2020-09-11 10:20:12 +03:00
|
|
|
|
'paypal-payments-for-woocommerce'
|
2020-08-27 11:08:36 +03:00
|
|
|
|
),
|
|
|
|
|
'elo' => _x(
|
|
|
|
|
'Elo',
|
|
|
|
|
'Name of credit card',
|
2020-09-11 10:20:12 +03:00
|
|
|
|
'paypal-payments-for-woocommerce'
|
2020-08-27 11:08:36 +03:00
|
|
|
|
),
|
|
|
|
|
'hiper' => _x(
|
|
|
|
|
'Hiper',
|
|
|
|
|
'Name of credit card',
|
2020-09-11 10:20:12 +03:00
|
|
|
|
'paypal-payments-for-woocommerce'
|
2020-08-27 11:08:36 +03:00
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-09-02 13:52:40 +03:00
|
|
|
|
|
2020-09-02 14:53:30 +03:00
|
|
|
|
/**
|
|
|
|
|
* Whether the gateway is available or not.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2020-09-02 13:52:40 +03:00
|
|
|
|
public function is_available() : bool {
|
2020-09-02 14:53:30 +03:00
|
|
|
|
return $this->config->has( 'dcc_enabled' ) && $this->config->get( 'dcc_enabled' );
|
2020-09-02 13:52:40 +03:00
|
|
|
|
}
|
2020-08-19 05:39:45 +03:00
|
|
|
|
}
|