2020-08-18 09:04:58 +03:00
|
|
|
<?php
|
2020-08-19 05:39:45 +03:00
|
|
|
|
2020-08-18 09:04:58 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Inpsyde\PayPalCommerce\WcGateway\Gateway;
|
|
|
|
|
|
|
|
use Inpsyde\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice;
|
|
|
|
use Inpsyde\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
|
|
|
|
use Inpsyde\PayPalCommerce\WcGateway\Processor\OrderProcessor;
|
|
|
|
use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsRenderer;
|
|
|
|
use Psr\Container\ContainerInterface;
|
|
|
|
|
2020-08-19 05:39:45 +03:00
|
|
|
//phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
|
|
|
|
//phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType
|
2020-08-21 09:41:12 +03:00
|
|
|
//phpcs:disable Inpsyde.CodeQuality.NoAccessors.NoGetter
|
|
|
|
//phpcs:disable Inpsyde.CodeQuality.ReturnTypeDeclaration.NoReturnType
|
2020-08-18 09:04:58 +03:00
|
|
|
class CreditCardGateway extends PayPalGateway
|
|
|
|
{
|
|
|
|
public const ID = 'ppcp-credit-card-gateway';
|
|
|
|
|
2020-08-19 13:03:57 +03:00
|
|
|
private $moduleUrl;
|
2020-08-18 09:04:58 +03:00
|
|
|
public function __construct(
|
|
|
|
SettingsRenderer $settingsRenderer,
|
|
|
|
OrderProcessor $orderProcessor,
|
|
|
|
AuthorizedPaymentsProcessor $authorizedPayments,
|
|
|
|
AuthorizeOrderActionNotice $notice,
|
2020-08-19 13:03:57 +03:00
|
|
|
ContainerInterface $config,
|
|
|
|
string $moduleUrl
|
2020-08-18 09:04:58 +03:00
|
|
|
) {
|
|
|
|
|
|
|
|
$this->id = self::ID;
|
|
|
|
$this->orderProcessor = $orderProcessor;
|
|
|
|
$this->authorizedPayments = $authorizedPayments;
|
|
|
|
$this->notice = $notice;
|
|
|
|
$this->settingsRenderer = $settingsRenderer;
|
|
|
|
$this->config = $config;
|
2020-08-21 09:41:12 +03:00
|
|
|
if (
|
|
|
|
defined('PPCP_FLAG_SUBSCRIPTION')
|
|
|
|
&& PPCP_FLAG_SUBSCRIPTION
|
|
|
|
&& $this->config->has('vault_enabled')
|
|
|
|
&& $this->config->get('vault_enabled')
|
|
|
|
) {
|
2020-08-18 09:04:58 +03:00
|
|
|
$this->supports = [
|
|
|
|
'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-08-20 08:38:42 +03:00
|
|
|
$this->method_title = __('PayPal Credit Card Processing', 'woocommerce-paypal-commerce-gateway');
|
2020-08-18 09:04:58 +03:00
|
|
|
$this->method_description = __(
|
|
|
|
'Provide your customers with the option to pay with credit card.',
|
|
|
|
'woocommerce-paypal-commerce-gateway'
|
|
|
|
);
|
2020-08-18 09:23:41 +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;
|
2020-08-18 09:04:58 +03:00
|
|
|
|
|
|
|
$this->init_form_fields();
|
|
|
|
$this->init_settings();
|
|
|
|
|
|
|
|
add_action(
|
|
|
|
'woocommerce_update_options_payment_gateways_' . $this->id,
|
|
|
|
[
|
|
|
|
$this,
|
|
|
|
'process_admin_options',
|
|
|
|
]
|
|
|
|
);
|
2020-08-19 13:03:57 +03:00
|
|
|
|
|
|
|
$this->moduleUrl = $moduleUrl;
|
2020-08-18 09:04:58 +03:00
|
|
|
}
|
2020-08-18 09:23:41 +03:00
|
|
|
|
2020-08-18 09:24:15 +03:00
|
|
|
public function init_form_fields()
|
|
|
|
{
|
|
|
|
$this->form_fields = [
|
|
|
|
'enabled' => [
|
|
|
|
'title' => __('Enable/Disable', 'woocommerce-paypal-commerce-gateway'),
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'label' => __('Enable Credit Card Payments', 'woocommerce-paypal-commerce-gateway'),
|
2020-08-20 07:31:16 +03:00
|
|
|
'default' => 'no',
|
2020-08-18 09:24:15 +03:00
|
|
|
],
|
|
|
|
'ppcp' => [
|
|
|
|
'type' => 'ppcp',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-08-18 09:04:58 +03:00
|
|
|
public function generate_ppcp_html(): string
|
|
|
|
{
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$this->settingsRenderer->render(true);
|
|
|
|
$content = ob_get_contents();
|
|
|
|
ob_end_clean();
|
|
|
|
return $content;
|
|
|
|
}
|
2020-08-19 13:03:57 +03:00
|
|
|
|
2020-08-21 09:41:12 +03:00
|
|
|
public function get_title()
|
|
|
|
{
|
|
|
|
|
2020-08-21 09:12:16 +03:00
|
|
|
if (is_admin()) {
|
|
|
|
return parent::get_title();
|
|
|
|
}
|
2020-08-19 13:03:57 +03:00
|
|
|
$title = parent::get_title();
|
|
|
|
$icons = $this->config->has('card_icons') ? (array) $this->config->get('card_icons') : [];
|
|
|
|
if (empty($icons)) {
|
|
|
|
return $title;
|
|
|
|
}
|
|
|
|
|
|
|
|
$titleOptions = [
|
2020-08-21 09:46:46 +03:00
|
|
|
'visa' => _x(
|
|
|
|
'Visa',
|
|
|
|
'Name of credit card',
|
|
|
|
'woocommerce-paypal-commerce-gateway'
|
|
|
|
),
|
|
|
|
'mastercard' => _x(
|
|
|
|
'Mastercard',
|
|
|
|
'Name of credit card',
|
|
|
|
'woocommerce-paypal-commerce-gateway'
|
|
|
|
),
|
|
|
|
'amex' => _x(
|
|
|
|
'American Express',
|
|
|
|
'Name of credit card',
|
|
|
|
'woocommerce-paypal-commerce-gateway'
|
|
|
|
),
|
|
|
|
'discover' => _x(
|
|
|
|
'Discover',
|
|
|
|
'Name of credit card',
|
|
|
|
'woocommerce-paypal-commerce-gateway'
|
|
|
|
),
|
|
|
|
'jcb' => _x(
|
|
|
|
'JCB',
|
|
|
|
'Name of credit card',
|
|
|
|
'woocommerce-paypal-commerce-gateway'
|
|
|
|
),
|
|
|
|
'elo' => _x(
|
|
|
|
'Elo',
|
|
|
|
'Name of credit card',
|
|
|
|
'woocommerce-paypal-commerce-gateway'
|
|
|
|
),
|
|
|
|
'hiper' => _x(
|
|
|
|
'Hiper',
|
|
|
|
'Name of credit card',
|
|
|
|
'woocommerce-paypal-commerce-gateway'
|
|
|
|
),
|
2020-08-19 13:03:57 +03:00
|
|
|
];
|
|
|
|
$images = array_map(
|
2020-08-21 09:41:12 +03:00
|
|
|
function (string $type) use ($titleOptions): string {
|
2020-08-19 13:03:57 +03:00
|
|
|
return '<img
|
|
|
|
title="' . esc_attr($titleOptions[$type]) . '"
|
|
|
|
src="' . esc_url($this->moduleUrl) . '/assets/images/' . esc_attr($type) . '.svg"
|
|
|
|
class="ppcp-card-icon"
|
|
|
|
> ';
|
|
|
|
},
|
|
|
|
$icons
|
|
|
|
);
|
|
|
|
return $title . implode('', $images);
|
|
|
|
}
|
2020-08-19 05:39:45 +03:00
|
|
|
}
|