mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Merge branch 'PCP-30-add-dcc-wc-gateway' into PCP-27-add-messages
This commit is contained in:
commit
3a675f657b
24 changed files with 369 additions and 187 deletions
|
@ -1,22 +1,31 @@
|
|||
#ppcp-hosted-fields,
|
||||
#ppcp-hosted-fields-mini-cart {
|
||||
#ppcp-hosted-fields {
|
||||
|
||||
.ppcp-dcc-credit-card-wrapper {
|
||||
width: 100%;
|
||||
display: table !important;
|
||||
|
||||
div {
|
||||
display: table-row;
|
||||
}
|
||||
display: grid;
|
||||
grid-template-columns: 55% 1fr 1fr;
|
||||
grid-template-rows: 1fr 1fr;
|
||||
grid-column-gap: 15px;
|
||||
margin-bottom: 15px;
|
||||
|
||||
label, span {
|
||||
display: table-cell;
|
||||
height: 30px;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
vertical-align: bottom;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
label {
|
||||
grid-row: 1/2;
|
||||
}
|
||||
span {
|
||||
grid-row: 2/3;
|
||||
background:white;
|
||||
border: 1px #666;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
label {
|
||||
|
|
|
@ -12,7 +12,6 @@ const bootstrap = () => {
|
|||
const creditCardRenderer = new CreditCardRenderer(PayPalCommerceGateway, errorHandler);
|
||||
const renderer = new Renderer(creditCardRenderer, PayPalCommerceGateway);
|
||||
const context = PayPalCommerceGateway.context;
|
||||
|
||||
if (context === 'mini-cart' || context === 'product') {
|
||||
const miniCartBootstrap = new MiniCartBootstap(
|
||||
PayPalCommerceGateway,
|
||||
|
|
|
@ -50,15 +50,21 @@ class CheckoutBootstap {
|
|||
const currentPaymentMethod = jQuery(
|
||||
'input[name="payment_method"]:checked').val();
|
||||
|
||||
if (currentPaymentMethod !== 'ppcp-gateway') {
|
||||
if (currentPaymentMethod !== 'ppcp-gateway' && currentPaymentMethod !== 'ppcp-credit-card-gateway') {
|
||||
this.renderer.hideButtons(this.gateway.button.wrapper);
|
||||
this.renderer.hideButtons(this.gateway.hosted_fields.wrapper);
|
||||
jQuery('#place_order').show();
|
||||
}
|
||||
else {
|
||||
this.renderer.showButtons(this.gateway.button.wrapper);
|
||||
this.renderer.showButtons(this.gateway.hosted_fields.wrapper);
|
||||
jQuery('#place_order').hide();
|
||||
if (currentPaymentMethod === 'ppcp-gateway') {
|
||||
this.renderer.showButtons(this.gateway.button.wrapper);
|
||||
this.renderer.hideButtons(this.gateway.hosted_fields.wrapper);
|
||||
}
|
||||
if (currentPaymentMethod === 'ppcp-credit-card-gateway') {
|
||||
this.renderer.hideButtons(this.gateway.button.wrapper);
|
||||
this.renderer.showButtons(this.gateway.hosted_fields.wrapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,8 @@ class CreditCardRenderer {
|
|||
render(wrapper, contextConfig) {
|
||||
|
||||
if (
|
||||
wrapper === null
|
||||
this.defaultConfig.context !== 'checkout'
|
||||
|| wrapper === null
|
||||
|| document.querySelector(wrapper) === null
|
||||
) {
|
||||
return;
|
||||
|
|
|
@ -48,7 +48,9 @@ return [
|
|||
return new DisabledSmartButton();
|
||||
}
|
||||
$settings = $container->get('wcgateway.settings');
|
||||
if (!$settings->has('enabled') || ! $settings->get('enabled')) {
|
||||
$paypalDisabled = !$settings->has('enabled') || ! $settings->get('enabled');
|
||||
$creditCardDisabled = !$settings->has('dcc_gateway_enabled') || ! $settings->get('dcc_gateway_enabled');
|
||||
if ($paypalDisabled && $creditCardDisabled) {
|
||||
return new DisabledSmartButton();
|
||||
}
|
||||
$payeeRepository = $container->get('api.repository.payee');
|
||||
|
|
|
@ -84,20 +84,6 @@ class SmartButton implements SmartButtonInterface
|
|||
20
|
||||
);
|
||||
}
|
||||
if (
|
||||
is_cart()
|
||||
&& $this->settings->has('dcc_cart_enabled')
|
||||
&& $this->settings->get('dcc_cart_enabled')
|
||||
) {
|
||||
add_action(
|
||||
'woocommerce_proceed_to_checkout',
|
||||
[
|
||||
$this,
|
||||
'dccRenderer',
|
||||
],
|
||||
20
|
||||
);
|
||||
}
|
||||
|
||||
$notEnabledOnProductPage = $this->settings->has('button_single_product_enabled') &&
|
||||
!$this->settings->get('button_single_product_enabled');
|
||||
|
@ -114,23 +100,9 @@ class SmartButton implements SmartButtonInterface
|
|||
31
|
||||
);
|
||||
}
|
||||
$dccNotEnabledOnProductPage = $this->settings->has('dcc_single_product_enabled') &&
|
||||
!$this->settings->get('dcc_single_product_enabled');
|
||||
if (
|
||||
(is_product() || wc_post_content_has_shortcode('product_page'))
|
||||
&& ! $dccNotEnabledOnProductPage
|
||||
) {
|
||||
add_action(
|
||||
'woocommerce_single_product_summary',
|
||||
[
|
||||
$this,
|
||||
'dccRenderer',
|
||||
],
|
||||
31
|
||||
);
|
||||
}
|
||||
$notEnabledOnMiniCart = $this->settings->has('button_mini-cart_enabled') &&
|
||||
!$this->settings->get('button_mini-cart_enabled');
|
||||
|
||||
$notEnabledOnMiniCart = $this->settings->has('button_mini_cart_enabled') &&
|
||||
!$this->settings->get('button_mini_cart_enabled');
|
||||
if (
|
||||
! $notEnabledOnMiniCart
|
||||
) {
|
||||
|
@ -142,18 +114,7 @@ class SmartButton implements SmartButtonInterface
|
|||
30
|
||||
);
|
||||
}
|
||||
if (
|
||||
$this->settings->has('dcc_mini_cart_enabled')
|
||||
&& $this->settings->get('dcc_mini_cart_enabled')
|
||||
) {
|
||||
add_action(
|
||||
'woocommerce_widget_shopping_cart_after_buttons',
|
||||
function () {
|
||||
$this->dccRenderer(true);
|
||||
},
|
||||
31
|
||||
);
|
||||
}
|
||||
|
||||
add_action(
|
||||
'woocommerce_review_order_after_submit',
|
||||
[
|
||||
|
@ -244,10 +205,10 @@ class SmartButton implements SmartButtonInterface
|
|||
);
|
||||
}
|
||||
// phpcs:disable Inpsyde.CodeQuality.FunctionLength.TooLong
|
||||
public function dccRenderer(bool $miniCart = false)
|
||||
public function dccRenderer()
|
||||
{
|
||||
|
||||
$id = ($miniCart) ? 'ppcp-hosted-fields-mini-cart' : 'ppcp-hosted-fields';
|
||||
$id = 'ppcp-hosted-fields';
|
||||
$canRenderDcc = $this->dccApplies->forCountryCurrency()
|
||||
&& $this->settings->has('client_id')
|
||||
&& $this->settings->get('client_id');
|
||||
|
@ -255,16 +216,6 @@ class SmartButton implements SmartButtonInterface
|
|||
return;
|
||||
}
|
||||
|
||||
$product = wc_get_product();
|
||||
if (
|
||||
! $miniCart && !is_checkout() && is_a($product, \WC_Product::class)
|
||||
&& (
|
||||
$product->is_type(['external', 'grouped'])
|
||||
|| !$product->is_in_stock()
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
$saveCard = $this->canSaveVaultToken() ? sprintf(
|
||||
'<div>
|
||||
|
||||
|
@ -283,27 +234,23 @@ class SmartButton implements SmartButtonInterface
|
|||
printf(
|
||||
'<form id="%1$s">
|
||||
<div class="ppcp-dcc-credit-card-wrapper">
|
||||
<div>
|
||||
<label for="ppcp-credit-card-%1$s">%2$s</label>
|
||||
<span id="ppcp-credit-card-%1$s" class="ppcp-credit-card"></span>
|
||||
</div><div>
|
||||
<label for="ppcp-expiration-date-%1$s">%3$s</label>
|
||||
<span id="ppcp-expiration-date-%1$s" class="ppcp-expiration-date"></span>
|
||||
</div><div>
|
||||
<label for="ppcp-cvv-%1$s">%4$s</label>
|
||||
<span id="ppcp-cvv-%1$s" class="ppcp-cvv"></span>
|
||||
<label for="ppcp-credit-card-%1$s">%2$s</label>
|
||||
<span id="ppcp-credit-card-%1$s" class="ppcp-credit-card"></span>
|
||||
<label for="ppcp-expiration-date-%1$s">%3$s</label>
|
||||
<span id="ppcp-expiration-date-%1$s" class="ppcp-expiration-date"></span>
|
||||
<label for="ppcp-cvv-%1$s">%4$s</label>
|
||||
<span id="ppcp-cvv-%1$s" class="ppcp-cvv"></span>
|
||||
</div>
|
||||
%5$s
|
||||
</div>
|
||||
<button>%6$s</button>
|
||||
<button class="button alt">%6$s</button>
|
||||
</form><div id="payments-sdk__contingency-lightbox"></div>',
|
||||
esc_attr($id),
|
||||
esc_html__('Card number', 'woocommerce-paypal-commerce-gateway'),
|
||||
esc_html__('Expiration Date', 'woocommerce-paypal-commerce-gateway'),
|
||||
esc_html__('Credit Card number', 'woocommerce-paypal-commerce-gateway'),
|
||||
esc_html__('Expiration', 'woocommerce-paypal-commerce-gateway'),
|
||||
esc_html__('CVV', 'woocommerce-paypal-commerce-gateway'),
|
||||
//phpcs:ignore
|
||||
$saveCard,
|
||||
esc_html__('Pay with Card', 'woocommerce-paypal-commerce-gateway')
|
||||
esc_html__('Place order', 'woocommerce')
|
||||
);
|
||||
}
|
||||
// phpcs:enable Inpsyde.CodeQuality.FunctionLength.TooLong
|
||||
|
@ -338,7 +285,7 @@ class SmartButton implements SmartButtonInterface
|
|||
$localize = [
|
||||
'script_attributes' => $this->attributes(),
|
||||
'data_client_id' => [
|
||||
'set_attribute' => $this->dccIsEnabled() || $this->canSaveVaultToken(),
|
||||
'set_attribute' => (is_checkout() && $this->dccIsEnabled()) || $this->canSaveVaultToken(),
|
||||
'endpoint' => home_url(\WC_AJAX::get_endpoint(DataClientIdEndpoint::ENDPOINT)),
|
||||
'nonce' => wp_create_nonce(DataClientIdEndpoint::nonce()),
|
||||
'user' => get_current_user_id(),
|
||||
|
@ -386,8 +333,8 @@ class SmartButton implements SmartButtonInterface
|
|||
'wrapper' => '#ppcp-hosted-fields',
|
||||
'mini_cart_wrapper' => '#ppcp-hosted-fields-mini-cart',
|
||||
'labels' => [
|
||||
'credit_card_number' => __('Credit Card Number', 'woocommerce-paypal-commerce-gateway'),
|
||||
'cvv' => __('CVV', 'woocommerce-paypal-commerce-gateway'),
|
||||
'credit_card_number' => '',
|
||||
'cvv' => '',
|
||||
'mm_yyyy' => __('MM/YYYY', 'woocommerce-paypal-commerce-gateway'),
|
||||
'fields_not_valid' => __(
|
||||
'Unfortunatly, your credit card details are not valid.',
|
||||
|
@ -437,7 +384,7 @@ class SmartButton implements SmartButtonInterface
|
|||
//ToDo: Update date on releases.
|
||||
'integration-date' => date('Y-m-d'),
|
||||
'components' => implode(',', $this->components()),
|
||||
'vault' => $this->dccIsEnabled() || $this->canSaveVaultToken() ? 'true' : 'false',
|
||||
'vault' => (is_checkout() && $this->dccIsEnabled()) || $this->canSaveVaultToken() ? 'true' : 'false',
|
||||
'commit' => is_checkout() ? 'true' : 'false',
|
||||
'intent' => ($this->settings->has('intent')) ? $this->settings->get('intent') : 'capture',
|
||||
];
|
||||
|
|
|
@ -11,7 +11,7 @@ use Inpsyde\PayPalCommerce\ApiClient\Entity\PaymentToken;
|
|||
use Inpsyde\PayPalCommerce\ApiClient\Factory\PayerFactory;
|
||||
use Inpsyde\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
||||
use Inpsyde\PayPalCommerce\Subscription\Repository\PaymentTokenRepository;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class RenewalHandler
|
||||
|
@ -141,7 +141,7 @@ class RenewalHandler
|
|||
|
||||
if ($order->intent() === 'AUTHORIZE') {
|
||||
$this->orderEndpoint->authorize($order);
|
||||
$wcOrder->update_meta_data(WcGateway::CAPTURED_META_KEY, 'false');
|
||||
$wcOrder->update_meta_data(PayPalGateway::CAPTURED_META_KEY, 'false');
|
||||
\WC_Subscriptions_Manager::process_subscription_payments_on_order($wcOrder);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace Inpsyde\PayPalCommerce\Subscription;
|
|||
|
||||
use Dhii\Container\ServiceProvider;
|
||||
use Dhii\Modular\Module\ModuleInterface;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use Interop\Container\ServiceProviderInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
|
@ -27,7 +27,7 @@ class SubscriptionModule implements ModuleInterface
|
|||
public function run(ContainerInterface $container)
|
||||
{
|
||||
add_action(
|
||||
'woocommerce_scheduled_subscription_payment_' . WcGateway::ID,
|
||||
'woocommerce_scheduled_subscription_payment_' . PayPalGateway::ID,
|
||||
static function ($amount, $order) use ($container) {
|
||||
if (! is_a($order, \WC_Order::class)) {
|
||||
return;
|
||||
|
|
|
@ -11,7 +11,8 @@ use Inpsyde\PayPalCommerce\WcGateway\Admin\OrderTablePaymentStatusColumn;
|
|||
use Inpsyde\PayPalCommerce\WcGateway\Admin\PaymentStatusOrderDetail;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Checkout\CheckoutPayPalAddressPreset;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Checkout\DisableGateways;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
|
||||
|
@ -22,14 +23,29 @@ use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsRenderer;
|
|||
use WpOop\TransientCache\CachePoolFactory;
|
||||
|
||||
return [
|
||||
'wcgateway.gateway' => static function (ContainerInterface $container): WcGateway {
|
||||
'wcgateway.paypal-gateway' => static function (ContainerInterface $container): PayPalGateway {
|
||||
$orderProcessor = $container->get('wcgateway.order-processor');
|
||||
$settingsRenderer = $container->get('wcgateway.settings.render');
|
||||
$authorizedPayments = $container->get('wcgateway.processor.authorized-payments');
|
||||
$notice = $container->get('wcgateway.notice.authorize-order-action');
|
||||
$settings = $container->get('wcgateway.settings');
|
||||
|
||||
return new WcGateway(
|
||||
return new PayPalGateway(
|
||||
$settingsRenderer,
|
||||
$orderProcessor,
|
||||
$authorizedPayments,
|
||||
$notice,
|
||||
$settings
|
||||
);
|
||||
},
|
||||
'wcgateway.credit-card-gateway' => static function (ContainerInterface $container): CreditCardGateway {
|
||||
$orderProcessor = $container->get('wcgateway.order-processor');
|
||||
$settingsRenderer = $container->get('wcgateway.settings.render');
|
||||
$authorizedPayments = $container->get('wcgateway.processor.authorized-payments');
|
||||
$notice = $container->get('wcgateway.notice.authorize-order-action');
|
||||
$settings = $container->get('wcgateway.settings');
|
||||
|
||||
return new CreditCardGateway(
|
||||
$settingsRenderer,
|
||||
$orderProcessor,
|
||||
$authorizedPayments,
|
||||
|
@ -136,6 +152,7 @@ return [
|
|||
State::STATE_PROGRESSIVE,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'all',
|
||||
],
|
||||
'sandbox_on' => [
|
||||
'title' => __('Sandbox', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -146,6 +163,7 @@ return [
|
|||
State::STATE_START,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'all',
|
||||
],
|
||||
'sandbox_on_info' => [
|
||||
'title' => __('Sandbox', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -157,6 +175,7 @@ return [
|
|||
],
|
||||
'hidden' => 'sandbox_on',
|
||||
'requirements' => [],
|
||||
'gateway' => 'all',
|
||||
],
|
||||
'merchant_email' => [
|
||||
'title' => __('Email address', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -169,6 +188,7 @@ return [
|
|||
State::STATE_START,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'all',
|
||||
],
|
||||
'merchant_email_info' => [
|
||||
'title' => __('Email address', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -180,6 +200,7 @@ return [
|
|||
],
|
||||
'hidden' => 'merchant_email',
|
||||
'requirements' => [],
|
||||
'gateway' => 'all',
|
||||
],
|
||||
'toggle_manual_input' => [
|
||||
'type' => 'ppcp-text',
|
||||
|
@ -191,6 +212,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'all',
|
||||
],
|
||||
'client_id' => [
|
||||
'title' => __('Client Id', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -204,6 +226,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'all',
|
||||
],
|
||||
'client_secret' => [
|
||||
'title' => __('Secret Key', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -217,6 +240,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'all',
|
||||
],
|
||||
'title' => [
|
||||
'title' => __('Title', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -232,6 +256,23 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'dcc_gateway_title' => [
|
||||
'title' => __('Title', 'woocommerce-paypal-commerce-gateway'),
|
||||
'type' => 'text',
|
||||
'description' => __(
|
||||
'This controls the title which the user sees during checkout.',
|
||||
'woocommerce-paypal-commerce-gateway'
|
||||
),
|
||||
'default' => __('PayPal', 'woocommerce-paypal-commerce-gateway'),
|
||||
'desc_tip' => true,
|
||||
'screens' => [
|
||||
State::STATE_PROGRESSIVE,
|
||||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'dcc',
|
||||
],
|
||||
'description' => [
|
||||
'title' => __('Description', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -250,6 +291,26 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'dcc_gateway_description' => [
|
||||
'title' => __('Description', 'woocommerce-paypal-commerce-gateway'),
|
||||
'type' => 'text',
|
||||
'desc_tip' => true,
|
||||
'description' => __(
|
||||
'This controls the description which the user sees during checkout.',
|
||||
'woocommerce-paypal-commerce-gateway'
|
||||
),
|
||||
'default' => __(
|
||||
'Pay via PayPal; you can pay with your credit card if you don\'t have a PayPal account.',
|
||||
'woocommerce-paypal-commerce-gateway'
|
||||
),
|
||||
'screens' => [
|
||||
State::STATE_PROGRESSIVE,
|
||||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'dcc',
|
||||
],
|
||||
'intent' => [
|
||||
'title' => __('Intent', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -269,6 +330,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'brand_name' => [
|
||||
'title' => __('Brand Name', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -284,6 +346,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'landing_page' => [
|
||||
'title' => __('Landing Page', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -304,6 +367,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'disable_funding' => [
|
||||
'title' => __('Disable funding sources', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -332,6 +396,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'vault_enabled' => [
|
||||
'title' => __('Vaulting', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -344,6 +409,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
|
||||
//General button styles
|
||||
|
@ -355,6 +421,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'button_layout' => [
|
||||
'title' => __('Button Layout', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -375,6 +442,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'button_tagline' => [
|
||||
'title' => __('Tagline', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -391,6 +459,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'button_label' => [
|
||||
'title' => __('Button Label', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -413,6 +482,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'button_color' => [
|
||||
'title' => __('Color', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -435,6 +505,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'button_shape' => [
|
||||
'title' => __('Shape', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -455,6 +526,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
|
||||
//Single product page
|
||||
|
@ -466,6 +538,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'button_product_enabled' => [
|
||||
'title' => __('Enable buttons on Single Product', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -477,6 +550,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'button_product_layout' => [
|
||||
'title' => __('Button Layout', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -497,6 +571,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'button_product_tagline' => [
|
||||
'title' => __('Tagline', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -513,6 +588,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'button_product_label' => [
|
||||
'title' => __('Button Label', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -535,6 +611,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'button_product_color' => [
|
||||
'title' => __('Color', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -557,6 +634,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'button_product_shape' => [
|
||||
'title' => __('Shape', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -577,6 +655,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
|
||||
//Mini cart settings
|
||||
|
@ -588,6 +667,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'button_mini-cart_enabled' => [
|
||||
'title' => __('Buttons on Mini Cart', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -599,6 +679,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'button_mini-cart_layout' => [
|
||||
'title' => __('Button Layout', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -619,6 +700,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'button_mini-cart_tagline' => [
|
||||
'title' => __('Tagline', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -635,6 +717,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'button_mini-cart_label' => [
|
||||
'title' => __('Button Label', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -657,6 +740,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'button_mini-cart_color' => [
|
||||
'title' => __('Color', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -679,6 +763,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'button_mini-cart_shape' => [
|
||||
'title' => __('Shape', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -699,6 +784,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
|
||||
//Cart settings
|
||||
|
@ -710,6 +796,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'button_cart_enabled' => [
|
||||
'title' => __('Buttons on Cart', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -721,6 +808,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'button_cart_layout' => [
|
||||
'title' => __('Button Layout', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -741,6 +829,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'button_cart_tagline' => [
|
||||
'title' => __('Tagline', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -757,6 +846,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'button_cart_label' => [
|
||||
'title' => __('Button Label', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -779,6 +869,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'button_cart_color' => [
|
||||
'title' => __('Color', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -801,6 +892,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
'button_cart_shape' => [
|
||||
'title' => __('Shape', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -821,32 +913,9 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'paypal',
|
||||
],
|
||||
|
||||
'dcc_cart_enabled' => [
|
||||
'title' => __('Enable credit card on cart', 'woocommerce-paypal-commerce-gateway'),
|
||||
'type' => 'checkbox',
|
||||
'label' => __('Allow your customers to pay with credit card directly in your cart.', 'woocommerce-paypal-commerce-gateway'),
|
||||
'default' => true,
|
||||
'screens' => [
|
||||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [
|
||||
'dcc',
|
||||
],
|
||||
],
|
||||
'dcc_mini_cart_enabled' => [
|
||||
'title' => __('Enable credit card on mini cart', 'woocommerce-paypal-commerce-gateway'),
|
||||
'type' => 'checkbox',
|
||||
'label' => __('Allow your customers to pay with credit card directly in your mini cart.', 'woocommerce-paypal-commerce-gateway'),
|
||||
'default' => true,
|
||||
'screens' => [
|
||||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [
|
||||
'dcc',
|
||||
],
|
||||
],
|
||||
'dcc_checkout_enabled' => [
|
||||
'title' => __('Enable credit card on checkout', 'woocommerce-paypal-commerce-gateway'),
|
||||
'type' => 'checkbox',
|
||||
|
@ -858,18 +927,7 @@ return [
|
|||
'requirements' => [
|
||||
'dcc',
|
||||
],
|
||||
],
|
||||
'dcc_single_product_enabled' => [
|
||||
'title' => __('Enable credit card on products', 'woocommerce-paypal-commerce-gateway'),
|
||||
'type' => 'checkbox',
|
||||
'label' => __('Allow your customers to pay with credit card instantly on the product page.', 'woocommerce-paypal-commerce-gateway'),
|
||||
'default' => true,
|
||||
'screens' => [
|
||||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [
|
||||
'dcc',
|
||||
],
|
||||
'gateway' => 'dcc',
|
||||
],
|
||||
'disable_cards' => [
|
||||
'title' => __('Disable specific credit cards', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -896,6 +954,7 @@ return [
|
|||
'requirements' => [
|
||||
'dcc',
|
||||
],
|
||||
'gateway' => 'dcc',
|
||||
],
|
||||
'logging_enabled' => [
|
||||
'title' => __('Logging', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -910,6 +969,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'all',
|
||||
],
|
||||
'prefix' => [
|
||||
'title' => __('Installation prefix', 'woocommerce-paypal-commerce-gateway'),
|
||||
|
@ -923,6 +983,7 @@ return [
|
|||
State::STATE_ONBOARDED,
|
||||
],
|
||||
'requirements' => [],
|
||||
'gateway' => 'all',
|
||||
],
|
||||
];
|
||||
},
|
||||
|
|
|
@ -4,7 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Inpsyde\PayPalCommerce\WcGateway\Admin;
|
||||
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
class OrderTablePaymentStatusColumn
|
||||
|
@ -65,12 +65,12 @@ class OrderTablePaymentStatusColumn
|
|||
|
||||
private function renderForOrder(\WC_Order $order): bool
|
||||
{
|
||||
return !empty($order->get_meta(WcGateway::CAPTURED_META_KEY));
|
||||
return !empty($order->get_meta(PayPalGateway::CAPTURED_META_KEY));
|
||||
}
|
||||
|
||||
private function isCaptured(\WC_Order $wcOrder): bool
|
||||
{
|
||||
$captured = $wcOrder->get_meta(WcGateway::CAPTURED_META_KEY);
|
||||
$captured = $wcOrder->get_meta(PayPalGateway::CAPTURED_META_KEY);
|
||||
return wc_string_to_bool($captured);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,15 +4,15 @@ declare(strict_types=1);
|
|||
|
||||
namespace Inpsyde\PayPalCommerce\WcGateway\Admin;
|
||||
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
|
||||
class PaymentStatusOrderDetail
|
||||
{
|
||||
public function render(int $wcOrderId)
|
||||
{
|
||||
$wcOrder = new \WC_Order($wcOrderId);
|
||||
$intent = $wcOrder->get_meta(WcGateway::INTENT_META_KEY);
|
||||
$captured = $wcOrder->get_meta(WcGateway::CAPTURED_META_KEY);
|
||||
$intent = $wcOrder->get_meta(PayPalGateway::INTENT_META_KEY);
|
||||
$captured = $wcOrder->get_meta(PayPalGateway::CAPTURED_META_KEY);
|
||||
|
||||
if (strcasecmp($intent, 'AUTHORIZE') !== 0) {
|
||||
return;
|
||||
|
|
|
@ -5,7 +5,8 @@ declare(strict_types=1);
|
|||
namespace Inpsyde\PayPalCommerce\WcGateway\Checkout;
|
||||
|
||||
use Inpsyde\PayPalCommerce\Session\SessionHandler;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class DisableGateways
|
||||
|
@ -24,26 +25,47 @@ class DisableGateways
|
|||
|
||||
public function handler(array $methods): array
|
||||
{
|
||||
if (! isset($methods[WcGateway::ID])) {
|
||||
if (! isset($methods[PayPalGateway::ID])) {
|
||||
return $methods;
|
||||
}
|
||||
if (
|
||||
! $this->settings->has('merchant_email')
|
||||
|| ! is_email($this->settings->get('merchant_email'))
|
||||
) {
|
||||
unset($methods[WcGateway::ID]);
|
||||
unset($methods[PayPalGateway::ID]);
|
||||
unset($methods[CreditCardGateway::ID]);
|
||||
return $methods;
|
||||
}
|
||||
|
||||
if (! $this->settings->has('client_id') || empty($this->settings->get('client_id'))) {
|
||||
unset($methods[CreditCardGateway::ID]);
|
||||
}
|
||||
|
||||
|
||||
if (! $this->needsToDisableGateways()) {
|
||||
return $methods;
|
||||
}
|
||||
|
||||
return [WcGateway::ID => $methods[WcGateway::ID]];
|
||||
if ($this->isCreditCard()) {
|
||||
return [CreditCardGateway::ID => $methods[CreditCardGateway::ID]];
|
||||
}
|
||||
return [PayPalGateway::ID => $methods[PayPalGateway::ID]];
|
||||
}
|
||||
|
||||
private function needsToDisableGateways(): bool
|
||||
{
|
||||
return $this->sessionHandler->order() !== null;
|
||||
}
|
||||
|
||||
private function isCreditCard() : bool
|
||||
{
|
||||
$order =$this->sessionHandler->order();
|
||||
if (! $order) {
|
||||
return false;
|
||||
}
|
||||
if ( ! $order->paymentSource() || ! $order->paymentSource()->card()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
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;
|
||||
|
||||
class CreditCardGateway extends PayPalGateway
|
||||
{
|
||||
public const ID = 'ppcp-credit-card-gateway';
|
||||
|
||||
|
||||
public function __construct(
|
||||
SettingsRenderer $settingsRenderer,
|
||||
OrderProcessor $orderProcessor,
|
||||
AuthorizedPaymentsProcessor $authorizedPayments,
|
||||
AuthorizeOrderActionNotice $notice,
|
||||
ContainerInterface $config
|
||||
) {
|
||||
|
||||
$this->id = self::ID;
|
||||
$this->orderProcessor = $orderProcessor;
|
||||
$this->authorizedPayments = $authorizedPayments;
|
||||
$this->notice = $notice;
|
||||
$this->settingsRenderer = $settingsRenderer;
|
||||
$this->config = $config;
|
||||
if ($this->config->has('vault_enabled') && $this->config->get('vault_enabled')) {
|
||||
$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',
|
||||
];
|
||||
}
|
||||
|
||||
$this->method_title = __('PayPal Credit Card', 'woocommerce-paypal-commerce-gateway');
|
||||
$this->method_description = __(
|
||||
'Provide your customers with the option to pay with credit card.',
|
||||
'woocommerce-paypal-commerce-gateway'
|
||||
);
|
||||
$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,
|
||||
[
|
||||
$this,
|
||||
'process_admin_options',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
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'),
|
||||
'default' => 'yes',
|
||||
],
|
||||
'ppcp' => [
|
||||
'type' => 'ppcp',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function generate_ppcp_html(): string
|
||||
{
|
||||
|
||||
ob_start();
|
||||
$this->settingsRenderer->render(true);
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
return $content;
|
||||
}
|
||||
|
||||
}
|
|
@ -22,7 +22,7 @@ use Psr\Container\ContainerInterface;
|
|||
|
||||
//phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
|
||||
//phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType
|
||||
class WcGateway extends \WC_Payment_Gateway
|
||||
class PayPalGateway extends \WC_Payment_Gateway
|
||||
{
|
||||
|
||||
public const ID = 'ppcp-gateway';
|
||||
|
@ -30,11 +30,11 @@ class WcGateway extends \WC_Payment_Gateway
|
|||
public const INTENT_META_KEY = '_ppcp_paypal_intent';
|
||||
public const ORDER_ID_META_KEY = '_ppcp_paypal_order_id';
|
||||
|
||||
private $settingsRenderer;
|
||||
private $authorizedPayments;
|
||||
private $notice;
|
||||
private $orderProcessor;
|
||||
private $config;
|
||||
protected $settingsRenderer;
|
||||
protected $authorizedPayments;
|
||||
protected $notice;
|
||||
protected $orderProcessor;
|
||||
protected $config;
|
||||
|
||||
public function __construct(
|
||||
SettingsRenderer $settingsRenderer,
|
||||
|
@ -178,7 +178,7 @@ class WcGateway extends \WC_Payment_Gateway
|
|||
{
|
||||
|
||||
ob_start();
|
||||
$this->settingsRenderer->render();
|
||||
$this->settingsRenderer->render(false);
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
return $content;
|
|
@ -10,7 +10,7 @@ use Inpsyde\PayPalCommerce\ApiClient\Endpoint\PaymentsEndpoint;
|
|||
use Inpsyde\PayPalCommerce\ApiClient\Entity\Authorization;
|
||||
use Inpsyde\PayPalCommerce\ApiClient\Entity\AuthorizationStatus;
|
||||
use Inpsyde\PayPalCommerce\ApiClient\Entity\Order;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
|
||||
class AuthorizedPaymentsProcessor
|
||||
{
|
||||
|
@ -71,7 +71,7 @@ class AuthorizedPaymentsProcessor
|
|||
|
||||
private function payPalOrderFromWcOrder(\WC_Order $wcOrder): Order
|
||||
{
|
||||
$orderId = $wcOrder->get_meta(WcGateway::ORDER_ID_META_KEY);
|
||||
$orderId = $wcOrder->get_meta(PayPalGateway::ORDER_ID_META_KEY);
|
||||
return $this->orderEndpoint->order($orderId);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ use Inpsyde\PayPalCommerce\ApiClient\Factory\OrderFactory;
|
|||
use Inpsyde\PayPalCommerce\ApiClient\Repository\CartRepository;
|
||||
use Inpsyde\PayPalCommerce\Button\Helper\ThreeDSecure;
|
||||
use Inpsyde\PayPalCommerce\Session\SessionHandler;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
|
||||
class OrderProcessor
|
||||
{
|
||||
|
@ -45,8 +45,8 @@ class OrderProcessor
|
|||
public function process(\WC_Order $wcOrder, \WooCommerce $woocommerce): bool
|
||||
{
|
||||
$order = $this->sessionHandler->order();
|
||||
$wcOrder->update_meta_data(WcGateway::ORDER_ID_META_KEY, $order->id());
|
||||
$wcOrder->update_meta_data(WcGateway::INTENT_META_KEY, $order->intent());
|
||||
$wcOrder->update_meta_data(PayPalGateway::ORDER_ID_META_KEY, $order->id());
|
||||
$wcOrder->update_meta_data(PayPalGateway::INTENT_META_KEY, $order->intent());
|
||||
|
||||
$errorMessage = null;
|
||||
if (!$order || ! $this->orderIsApproved($order)) {
|
||||
|
@ -71,7 +71,7 @@ class OrderProcessor
|
|||
|
||||
if ($order->intent() === 'AUTHORIZE') {
|
||||
$order = $this->orderEndpoint->authorize($order);
|
||||
$wcOrder->update_meta_data(WcGateway::CAPTURED_META_KEY, 'false');
|
||||
$wcOrder->update_meta_data(PayPalGateway::CAPTURED_META_KEY, 'false');
|
||||
}
|
||||
|
||||
$wcOrder->update_status(
|
||||
|
|
|
@ -50,6 +50,7 @@ class Settings implements ContainerInterface
|
|||
$this->load();
|
||||
$fieldsToReset = [
|
||||
'enabled',
|
||||
'dcc_gateway_enabled',
|
||||
'intent',
|
||||
'client_id',
|
||||
'client_secret',
|
||||
|
|
|
@ -6,6 +6,8 @@ namespace Inpsyde\PayPalCommerce\WcGateway\Settings;
|
|||
|
||||
use Inpsyde\PayPalCommerce\ApiClient\Authentication\PayPalBearer;
|
||||
use Inpsyde\PayPalCommerce\Onboarding\State;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use Inpsyde\PayPalCommerce\Webhooks\WebhookRegistrar;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
|
@ -60,8 +62,14 @@ class SettingsListener
|
|||
*/
|
||||
$rawData = (isset($_POST['ppcp'])) ? (array) wp_unslash($_POST['ppcp']) : [];
|
||||
$settings = $this->retrieveSettingsFromRawData($rawData);
|
||||
$settings['enabled'] = isset($_POST['woocommerce_ppcp-gateway_enabled'])
|
||||
&& absint($_POST['woocommerce_ppcp-gateway_enabled']) === 1;
|
||||
if ($_GET['section'] === PayPalGateway::ID) {
|
||||
$settings['enabled'] = isset($_POST['woocommerce_ppcp-gateway_enabled'])
|
||||
&& absint($_POST['woocommerce_ppcp-gateway_enabled']) === 1;
|
||||
}
|
||||
if ($_GET['section'] === CreditCardGateway::ID) {
|
||||
$settings['dcc_gateway_enabled'] = isset($_POST['woocommerce_ppcp-credit-card-gateway_enabled'])
|
||||
&& absint($_POST['woocommerce_ppcp-credit-card-gateway_enabled']) === 1;
|
||||
}
|
||||
foreach ($settings as $id => $value) {
|
||||
$this->settings->set($id, $value);
|
||||
}
|
||||
|
@ -80,11 +88,19 @@ class SettingsListener
|
|||
if (! in_array($this->state->currentState(), $config['screens'], true)) {
|
||||
continue;
|
||||
}
|
||||
if ($config['gateway'] === 'dcc' && wp_unslash(sanitize_text_field($_GET['section'])) !== 'ppcp-credit-card-gateway') {
|
||||
continue;
|
||||
}
|
||||
if ($config['gateway'] === 'paypal' && wp_unslash(sanitize_text_field($_GET['section'])) !== 'ppcp-gateway') {
|
||||
continue;
|
||||
}
|
||||
switch ($config['type']) {
|
||||
case 'checkbox':
|
||||
$settings[$key] = isset($rawData[$key]);
|
||||
break;
|
||||
case 'text':
|
||||
case 'ppcp-text-input':
|
||||
case 'ppcp-password':
|
||||
$settings[$key] = isset($rawData[$key]) ? sanitize_text_field($rawData[$key]) : '';
|
||||
break;
|
||||
case 'password':
|
||||
|
@ -125,7 +141,7 @@ class SettingsListener
|
|||
|
||||
if (
|
||||
! isset($_REQUEST['section'])
|
||||
|| sanitize_text_field(wp_unslash($_REQUEST['section'])) !== 'ppcp-gateway'
|
||||
|| ! in_array(sanitize_text_field(wp_unslash($_REQUEST['section'])), ['ppcp-gateway', 'ppcp-credit-card-gateway'],true)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ class SettingsRenderer
|
|||
//phpcs:enable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType
|
||||
|
||||
//phpcs:disable Inpsyde.CodeQuality.NestingLevel.High
|
||||
public function render()
|
||||
public function render(bool $isDcc)
|
||||
{
|
||||
|
||||
$nonce = wp_create_nonce(SettingsListener::NONCE);
|
||||
|
@ -134,6 +134,12 @@ class SettingsRenderer
|
|||
if (! in_array($this->state->currentState(), $config['screens'], true)) {
|
||||
continue;
|
||||
}
|
||||
if ($isDcc && ! in_array($config['gateway'], ['all', 'dcc'],true)) {
|
||||
continue;
|
||||
}
|
||||
if (! $isDcc && ! in_array($config['gateway'], ['all', 'paypal'],true)) {
|
||||
continue;
|
||||
}
|
||||
if (in_array('dcc', $config['requirements'], true) && ! $this->dccApplies->forCountryCurrency()) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -7,12 +7,14 @@ namespace Inpsyde\PayPalCommerce\WcGateway;
|
|||
use Dhii\Container\ServiceProvider;
|
||||
use Dhii\Modular\Module\ModuleInterface;
|
||||
use Inpsyde\PayPalCommerce\AdminNotices\Repository\Repository;
|
||||
use Inpsyde\PayPalCommerce\ApiClient\Helper\DccApplies;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Admin\OrderDetail;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Admin\OrderTablePaymentStatusColumn;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Admin\PaymentStatusOrderDetail;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Checkout\CheckoutPayPalAddressPreset;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Checkout\DisableGateways;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsRenderer;
|
||||
|
@ -75,11 +77,18 @@ class WcGatewayModule implements ModuleInterface
|
|||
* @var Settings $settings
|
||||
*/
|
||||
$settings = $container->get('wcgateway.settings');
|
||||
$enabled = $settings->has('enabled') ? $settings->get('enabled') : false;
|
||||
$key = $_POST['gateway_id'] === PayPalGateway::ID ? 'enabled' : '';
|
||||
if ($_POST['gateway_id'] === CreditCardGateway::ID ) {
|
||||
$key = 'dcc_gateway_enabled';
|
||||
}
|
||||
if (! $key) {
|
||||
return;
|
||||
}
|
||||
$enabled = $settings->has($key) ? $settings->get($key) : false;
|
||||
if (! $enabled) {
|
||||
return;
|
||||
}
|
||||
$settings->set('enabled', false);
|
||||
$settings->set($key, false);
|
||||
$settings->persist();
|
||||
},
|
||||
9
|
||||
|
@ -98,7 +107,14 @@ class WcGatewayModule implements ModuleInterface
|
|||
add_filter(
|
||||
'woocommerce_payment_gateways',
|
||||
static function ($methods) use ($container): array {
|
||||
$methods[] = $container->get('wcgateway.gateway');
|
||||
$methods[] = $container->get('wcgateway.paypal-gateway');
|
||||
$dccApplies = $container->get('api.helpers.dccapplies');
|
||||
/**
|
||||
* @var DccApplies $dccApplies
|
||||
*/
|
||||
if ($dccApplies->forCountryCurrency()) {
|
||||
$methods[] = $container->get('wcgateway.credit-card-gateway');
|
||||
}
|
||||
return (array)$methods;
|
||||
}
|
||||
);
|
||||
|
@ -157,9 +173,9 @@ class WcGatewayModule implements ModuleInterface
|
|||
'woocommerce_order_action_ppcp_authorize_order',
|
||||
static function (\WC_Order $wcOrder) use ($container) {
|
||||
/**
|
||||
* @var WcGateway $gateway
|
||||
* @var PayPalGateway $gateway
|
||||
*/
|
||||
$gateway = $container->get('wcgateway.gateway');
|
||||
$gateway = $container->get('wcgateway.paypal-gateway');
|
||||
$gateway->captureAuthorizedPayment($wcOrder);
|
||||
}
|
||||
);
|
||||
|
|
|
@ -4,7 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Inpsyde\PayPalCommerce\Webhooks\Handler;
|
||||
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class PaymentCaptureCompleted implements RequestHandler
|
||||
|
@ -78,7 +78,7 @@ class PaymentCaptureCompleted implements RequestHandler
|
|||
);
|
||||
|
||||
$wcOrder->set_status('processing');
|
||||
$wcOrder->update_meta_data(WcGateway::CAPTURED_META_KEY, 'true');
|
||||
$wcOrder->update_meta_data(PayPalGateway::CAPTURED_META_KEY, 'true');
|
||||
$wcOrder->save();
|
||||
$this->logger->log(
|
||||
'info',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue