2020-04-02 08:38:00 +03:00
|
|
|
<?php
|
2020-08-28 08:13:45 +03:00
|
|
|
/**
|
|
|
|
* The Gateway module.
|
|
|
|
*
|
2020-09-11 14:11:10 +03:00
|
|
|
* @package WooCommerce\PayPalCommerce\WcGateway
|
2020-08-28 08:13:45 +03:00
|
|
|
*/
|
2020-04-13 22:30:57 +03:00
|
|
|
|
2020-04-02 08:38:00 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-09-11 14:11:10 +03:00
|
|
|
namespace WooCommerce\PayPalCommerce\WcGateway;
|
2020-04-02 08:38:00 +03:00
|
|
|
|
2022-11-09 10:11:31 +02:00
|
|
|
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
|
|
|
|
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
|
2022-02-14 13:53:37 +02:00
|
|
|
use WC_Order;
|
2020-09-11 14:11:10 +03:00
|
|
|
use WooCommerce\PayPalCommerce\AdminNotices\Repository\Repository;
|
2022-02-14 13:53:37 +02:00
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\Capture;
|
2022-06-23 11:13:41 +02:00
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
|
2020-09-11 14:11:10 +03:00
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Repository\PayPalRequestIdRepository;
|
2022-08-17 15:05:36 +03:00
|
|
|
use WooCommerce\PayPalCommerce\Onboarding\State;
|
2022-02-14 13:54:13 +02:00
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Admin\FeesRenderer;
|
2020-09-11 14:11:10 +03:00
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Admin\OrderTablePaymentStatusColumn;
|
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Admin\PaymentStatusOrderDetail;
|
2020-09-30 08:18:17 +03:00
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Admin\RenderAuthorizeAction;
|
2021-03-25 10:21:28 +02:00
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Assets\SettingsPageAssets;
|
2020-09-11 14:11:10 +03:00
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Checkout\CheckoutPayPalAddressPreset;
|
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Checkout\DisableGateways;
|
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Endpoint\ReturnUrlEndpoint;
|
2022-02-07 11:07:06 +01:00
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
|
2020-09-11 14:11:10 +03:00
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
2022-08-17 16:16:50 +03:00
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCProductStatus;
|
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceProductStatus;
|
2022-11-02 17:36:08 +04:00
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus;
|
2020-09-11 14:11:10 +03:00
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice;
|
2022-07-26 15:28:15 +03:00
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Notice\GatewayWithoutPayPalAdminNotice;
|
2021-10-14 15:45:57 +02:00
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor;
|
2022-08-16 10:20:47 +03:00
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Settings\HeaderRenderer;
|
2020-09-11 14:11:10 +03:00
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Settings\SectionsRenderer;
|
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
2020-09-16 10:00:28 +03:00
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsListener;
|
2020-09-11 14:11:10 +03:00
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsRenderer;
|
2022-11-09 10:11:31 +02:00
|
|
|
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
|
|
|
|
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
2020-04-02 08:38:00 +03:00
|
|
|
|
2020-08-28 08:13:45 +03:00
|
|
|
/**
|
|
|
|
* Class WcGatewayModule
|
|
|
|
*/
|
2021-09-13 16:33:41 +02:00
|
|
|
class WCGatewayModule implements ModuleInterface {
|
2020-08-27 11:08:36 +03:00
|
|
|
|
2020-08-28 08:13:45 +03:00
|
|
|
/**
|
2021-08-30 08:08:41 +02:00
|
|
|
* {@inheritDoc}
|
2020-08-28 08:13:45 +03:00
|
|
|
*/
|
2020-08-27 11:08:36 +03:00
|
|
|
public function setup(): ServiceProviderInterface {
|
|
|
|
return new ServiceProvider(
|
|
|
|
require __DIR__ . '/../services.php',
|
|
|
|
require __DIR__ . '/../extensions.php'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:13:45 +03:00
|
|
|
/**
|
2021-08-30 08:08:41 +02:00
|
|
|
* {@inheritDoc}
|
2020-08-28 08:13:45 +03:00
|
|
|
*/
|
2021-08-30 08:10:43 +02:00
|
|
|
public function run( ContainerInterface $c ): void {
|
|
|
|
$this->register_payment_gateways( $c );
|
|
|
|
$this->register_order_functionality( $c );
|
|
|
|
$this->register_columns( $c );
|
|
|
|
$this->register_checkout_paypal_address_preset( $c );
|
2020-08-27 11:08:36 +03:00
|
|
|
|
2020-09-02 09:56:04 +03:00
|
|
|
add_action(
|
|
|
|
'woocommerce_sections_checkout',
|
2021-08-30 08:10:43 +02:00
|
|
|
function() use ( $c ) {
|
2022-08-16 10:20:47 +03:00
|
|
|
$header_renderer = $c->get( 'wcgateway.settings.header-renderer' );
|
|
|
|
assert( $header_renderer instanceof HeaderRenderer );
|
|
|
|
|
2021-08-30 08:10:43 +02:00
|
|
|
$section_renderer = $c->get( 'wcgateway.settings.sections-renderer' );
|
2022-08-08 09:55:04 +03:00
|
|
|
assert( $section_renderer instanceof SectionsRenderer );
|
|
|
|
|
|
|
|
// phpcs:ignore WordPress.Security.EscapeOutput
|
2022-08-16 10:20:47 +03:00
|
|
|
echo $header_renderer->render() . $section_renderer->render();
|
2022-08-10 09:10:38 +02:00
|
|
|
},
|
|
|
|
20
|
2020-09-02 09:56:04 +03:00
|
|
|
);
|
|
|
|
|
2022-02-14 13:53:37 +02:00
|
|
|
add_action(
|
|
|
|
'woocommerce_paypal_payments_order_captured',
|
|
|
|
function ( WC_Order $wc_order, Capture $capture ) {
|
|
|
|
$breakdown = $capture->seller_receivable_breakdown();
|
|
|
|
if ( $breakdown ) {
|
|
|
|
$wc_order->update_meta_data( PayPalGateway::FEES_META_KEY, $breakdown->to_array() );
|
2022-04-20 19:51:26 +04:00
|
|
|
$paypal_fee = $breakdown->paypal_fee();
|
|
|
|
if ( $paypal_fee ) {
|
2022-10-10 15:17:05 +02:00
|
|
|
$wc_order->update_meta_data( 'PayPal Transaction Fee', (string) $paypal_fee->value() );
|
2022-04-20 19:51:26 +04:00
|
|
|
}
|
2022-10-10 15:14:34 +02:00
|
|
|
|
|
|
|
$wc_order->save_meta_data();
|
2022-02-14 13:53:37 +02:00
|
|
|
}
|
2022-04-25 19:17:13 +04:00
|
|
|
|
|
|
|
$fraud = $capture->fraud_processor_response();
|
|
|
|
if ( $fraud ) {
|
|
|
|
$fraud_responses = $fraud->to_array();
|
|
|
|
$avs_response_order_note_title = __( 'Address Verification Result', 'woocommerce-paypal-payments' );
|
|
|
|
/* translators: %1$s is AVS order note title, %2$s is AVS order note result markup */
|
|
|
|
$avs_response_order_note_format = __( '%1$s %2$s', 'woocommerce-paypal-payments' );
|
|
|
|
$avs_response_order_note_result_format = '<ul class="ppcp_avs_result">
|
|
|
|
<li>%1$s</li>
|
|
|
|
<ul class="ppcp_avs_result_inner">
|
|
|
|
<li>%2$s</li>
|
|
|
|
<li>%3$s</li>
|
|
|
|
</ul>
|
|
|
|
</ul>';
|
|
|
|
$avs_response_order_note_result = sprintf(
|
|
|
|
$avs_response_order_note_result_format,
|
|
|
|
/* translators: %s is fraud AVS code */
|
|
|
|
sprintf( __( 'AVS: %s', 'woocommerce-paypal-payments' ), esc_html( $fraud_responses['avs_code'] ) ),
|
|
|
|
/* translators: %s is fraud AVS address match */
|
|
|
|
sprintf( __( 'Address Match: %s', 'woocommerce-paypal-payments' ), esc_html( $fraud_responses['address_match'] ) ),
|
|
|
|
/* translators: %s is fraud AVS postal match */
|
|
|
|
sprintf( __( 'Postal Match: %s', 'woocommerce-paypal-payments' ), esc_html( $fraud_responses['postal_match'] ) )
|
|
|
|
);
|
|
|
|
$avs_response_order_note = sprintf(
|
|
|
|
$avs_response_order_note_format,
|
|
|
|
esc_html( $avs_response_order_note_title ),
|
|
|
|
wp_kses_post( $avs_response_order_note_result )
|
|
|
|
);
|
|
|
|
$wc_order->add_order_note( $avs_response_order_note );
|
|
|
|
|
|
|
|
$cvv_response_order_note_format = '<ul class="ppcp_cvv_result"><li>%1$s</li></ul>';
|
|
|
|
$cvv_response_order_note = sprintf(
|
|
|
|
$cvv_response_order_note_format,
|
|
|
|
/* translators: %s is fraud CVV match */
|
|
|
|
sprintf( __( 'CVV2 Match: %s', 'woocommerce-paypal-payments' ), esc_html( $fraud_responses['cvv_match'] ) )
|
|
|
|
);
|
|
|
|
$wc_order->add_order_note( $cvv_response_order_note );
|
2022-02-14 13:53:37 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
10,
|
|
|
|
2
|
|
|
|
);
|
|
|
|
|
2022-02-14 13:54:13 +02:00
|
|
|
$fees_renderer = $c->get( 'wcgateway.admin.fees-renderer' );
|
|
|
|
assert( $fees_renderer instanceof FeesRenderer );
|
|
|
|
|
|
|
|
add_action(
|
|
|
|
'woocommerce_admin_order_totals_after_total',
|
|
|
|
function ( int $order_id ) use ( $fees_renderer ) {
|
|
|
|
$wc_order = wc_get_order( $order_id );
|
|
|
|
if ( ! $wc_order instanceof WC_Order ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
|
|
|
echo $fees_renderer->render( $wc_order );
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-08-30 08:10:43 +02:00
|
|
|
if ( $c->has( 'wcgateway.url' ) ) {
|
2022-11-02 17:36:08 +04:00
|
|
|
$settings_status = $c->get( 'wcgateway.settings.status' );
|
|
|
|
assert( $settings_status instanceof SettingsStatus );
|
|
|
|
|
2022-11-10 15:16:35 +04:00
|
|
|
$settings = $c->get( 'wcgateway.settings' );
|
|
|
|
assert( $settings instanceof Settings );
|
|
|
|
|
2021-03-25 14:29:56 +02:00
|
|
|
$assets = new SettingsPageAssets(
|
2021-08-30 08:10:43 +02:00
|
|
|
$c->get( 'wcgateway.url' ),
|
2022-09-02 12:59:53 +02:00
|
|
|
$c->get( 'ppcp.asset-version' ),
|
2022-10-19 11:38:49 +03:00
|
|
|
$c->get( 'subscription.helper' ),
|
2022-11-09 17:57:52 +04:00
|
|
|
$c->get( 'button.client_id_for_admin' ),
|
2022-10-19 11:38:49 +03:00
|
|
|
$c->get( 'api.shop.currency' ),
|
2022-11-02 17:36:08 +04:00
|
|
|
$c->get( 'api.shop.country' ),
|
2022-11-10 15:16:35 +04:00
|
|
|
$settings_status->is_pay_later_button_enabled(),
|
|
|
|
$settings->has( 'disable_funding' ) ? $settings->get( 'disable_funding' ) : array()
|
2021-03-25 14:29:56 +02:00
|
|
|
);
|
2021-03-25 10:21:28 +02:00
|
|
|
$assets->register_assets();
|
|
|
|
}
|
|
|
|
|
2020-08-27 11:08:36 +03:00
|
|
|
add_filter(
|
|
|
|
Repository::NOTICES_FILTER,
|
2021-08-30 08:10:43 +02:00
|
|
|
static function ( $notices ) use ( $c ): array {
|
|
|
|
$notice = $c->get( 'wcgateway.notice.connect' );
|
2021-08-31 10:20:34 +03:00
|
|
|
assert( $notice instanceof ConnectAdminNotice );
|
2020-08-28 08:13:45 +03:00
|
|
|
$connect_message = $notice->connect_message();
|
|
|
|
if ( $connect_message ) {
|
|
|
|
$notices[] = $connect_message;
|
2020-08-27 11:08:36 +03:00
|
|
|
}
|
2021-08-31 10:20:11 +03:00
|
|
|
|
2022-07-26 15:28:15 +03:00
|
|
|
foreach ( array(
|
|
|
|
$c->get( 'wcgateway.notice.dcc-without-paypal' ),
|
|
|
|
$c->get( 'wcgateway.notice.card-button-without-paypal' ),
|
|
|
|
) as $gateway_without_paypal_notice ) {
|
|
|
|
assert( $gateway_without_paypal_notice instanceof GatewayWithoutPayPalAdminNotice );
|
|
|
|
$message = $gateway_without_paypal_notice->message();
|
|
|
|
if ( $message ) {
|
|
|
|
$notices[] = $message;
|
|
|
|
}
|
2021-08-31 10:20:11 +03:00
|
|
|
}
|
|
|
|
|
2021-08-30 08:10:43 +02:00
|
|
|
$authorize_order_action = $c->get( 'wcgateway.notice.authorize-order-action' );
|
2020-08-28 08:13:45 +03:00
|
|
|
$authorized_message = $authorize_order_action->message();
|
|
|
|
if ( $authorized_message ) {
|
|
|
|
$notices[] = $authorized_message;
|
2020-08-27 11:08:36 +03:00
|
|
|
}
|
|
|
|
|
2021-08-30 08:10:43 +02:00
|
|
|
$settings_renderer = $c->get( 'wcgateway.settings.render' );
|
2021-08-31 10:20:34 +03:00
|
|
|
assert( $settings_renderer instanceof SettingsRenderer );
|
2020-10-02 12:09:23 +03:00
|
|
|
$messages = $settings_renderer->messages();
|
|
|
|
$notices = array_merge( $notices, $messages );
|
|
|
|
|
2020-08-27 11:08:36 +03:00
|
|
|
return $notices;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
add_action(
|
2020-09-17 16:50:04 -03:00
|
|
|
'woocommerce_paypal_commerce_gateway_deactivate',
|
2021-08-30 08:10:43 +02:00
|
|
|
static function () use ( $c ) {
|
2020-08-27 11:08:36 +03:00
|
|
|
delete_option( Settings::KEY );
|
|
|
|
delete_option( PayPalRequestIdRepository::KEY );
|
|
|
|
delete_option( 'woocommerce_' . PayPalGateway::ID . '_settings' );
|
|
|
|
delete_option( 'woocommerce_' . CreditCardGateway::ID . '_settings' );
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
add_action(
|
|
|
|
'wc_ajax_' . ReturnUrlEndpoint::ENDPOINT,
|
2021-08-30 08:10:43 +02:00
|
|
|
static function () use ( $c ) {
|
|
|
|
$endpoint = $c->get( 'wcgateway.endpoint.return-url' );
|
2020-08-27 11:08:36 +03:00
|
|
|
/**
|
2020-08-28 08:13:45 +03:00
|
|
|
* The Endpoint.
|
|
|
|
*
|
2020-08-27 11:08:36 +03:00
|
|
|
* @var ReturnUrlEndpoint $endpoint
|
|
|
|
*/
|
2020-08-28 08:13:45 +03:00
|
|
|
$endpoint->handle_request();
|
2020-08-27 11:08:36 +03:00
|
|
|
}
|
|
|
|
);
|
2022-02-03 16:23:23 +01:00
|
|
|
|
|
|
|
add_action(
|
|
|
|
'woocommerce_paypal_payments_gateway_migrate',
|
|
|
|
static function () use ( $c ) {
|
|
|
|
$settings = $c->get( 'wcgateway.settings' );
|
2022-02-03 16:30:37 +01:00
|
|
|
assert( $settings instanceof Settings );
|
|
|
|
|
2022-02-07 11:07:06 +01:00
|
|
|
try {
|
2022-03-29 11:37:22 +02:00
|
|
|
if ( $settings->has( '3d_secure_contingency' ) && $settings->get( '3d_secure_contingency' ) === '3D_SECURE' ) {
|
2022-02-07 11:07:06 +01:00
|
|
|
$settings->set( '3d_secure_contingency', 'SCA_ALWAYS' );
|
|
|
|
$settings->persist();
|
|
|
|
}
|
|
|
|
} catch ( NotFoundException $exception ) {
|
|
|
|
return;
|
2022-02-03 16:23:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2022-03-09 12:01:27 +01:00
|
|
|
|
2022-03-09 12:51:11 +01:00
|
|
|
add_action(
|
|
|
|
'init',
|
2022-03-09 17:22:17 +01:00
|
|
|
function () use ( $c ) {
|
2022-08-10 10:44:36 +02:00
|
|
|
if ( 'DE' === $c->get( 'api.shop.country' ) ) {
|
2022-03-09 17:22:17 +01:00
|
|
|
( $c->get( 'wcgateway.pay-upon-invoice' ) )->init();
|
2022-03-09 12:01:27 +01:00
|
|
|
}
|
2022-07-05 11:30:20 +02:00
|
|
|
|
2022-11-02 12:27:03 +01:00
|
|
|
( $c->get( 'wcgateway.oxxo' ) )->init();
|
2022-03-09 12:51:11 +01:00
|
|
|
}
|
|
|
|
);
|
2022-05-04 09:44:15 +02:00
|
|
|
|
|
|
|
add_action(
|
|
|
|
'woocommerce_paypal_payments_check_pui_payment_captured',
|
2022-06-22 11:11:16 +02:00
|
|
|
function ( int $wc_order_id, string $order_id ) use ( $c ) {
|
|
|
|
$order_endpoint = $c->get( 'api.endpoint.order' );
|
|
|
|
$logger = $c->get( 'woocommerce.logger.woocommerce' );
|
|
|
|
$order = $order_endpoint->order( $order_id );
|
2022-06-23 11:13:41 +02:00
|
|
|
$order_status = $order->status();
|
|
|
|
$logger->info( "Checking payment captured webhook for WC order #{$wc_order_id}, PayPal order status: " . $order_status->name() );
|
2022-06-22 11:11:16 +02:00
|
|
|
|
|
|
|
$wc_order = wc_get_order( $wc_order_id );
|
2022-05-04 09:44:15 +02:00
|
|
|
if ( ! is_a( $wc_order, WC_Order::class ) || $wc_order->get_status() !== 'on-hold' ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-23 11:13:41 +02:00
|
|
|
if ( $order_status->name() !== OrderStatus::COMPLETED ) {
|
|
|
|
$message = __(
|
|
|
|
'Could not process WC order because PAYMENT.CAPTURE.COMPLETED webhook not received.',
|
|
|
|
'woocommerce-paypal-payments'
|
|
|
|
);
|
|
|
|
$logger->error( $message );
|
|
|
|
$wc_order->update_status( 'failed', $message );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
10,
|
|
|
|
2
|
2022-05-04 09:44:15 +02:00
|
|
|
);
|
2022-07-13 16:11:33 +02:00
|
|
|
|
|
|
|
add_action(
|
|
|
|
'wc_ajax_ppc-oxxo',
|
|
|
|
static function () use ( $c ) {
|
|
|
|
$endpoint = $c->get( 'wcgateway.endpoint.oxxo' );
|
|
|
|
$endpoint->handle_request();
|
|
|
|
}
|
|
|
|
);
|
2020-08-27 11:08:36 +03:00
|
|
|
}
|
|
|
|
|
2020-08-28 08:13:45 +03:00
|
|
|
/**
|
|
|
|
* Registers the payment gateways.
|
|
|
|
*
|
2021-10-13 16:28:40 +03:00
|
|
|
* @param ContainerInterface $container The container.
|
2020-08-28 08:13:45 +03:00
|
|
|
*/
|
2021-10-13 16:28:40 +03:00
|
|
|
private function register_payment_gateways( ContainerInterface $container ) {
|
2020-08-27 11:08:36 +03:00
|
|
|
|
|
|
|
add_filter(
|
|
|
|
'woocommerce_payment_gateways',
|
|
|
|
static function ( $methods ) use ( $container ): array {
|
2022-08-03 09:37:40 +03:00
|
|
|
$paypal_gateway = $container->get( 'wcgateway.paypal-gateway' );
|
|
|
|
assert( $paypal_gateway instanceof \WC_Payment_Gateway );
|
|
|
|
|
|
|
|
$paypal_gateway_enabled = wc_string_to_bool( $paypal_gateway->get_option( 'enabled' ) );
|
|
|
|
|
2022-08-17 15:05:36 +03:00
|
|
|
$methods[] = $paypal_gateway;
|
2020-09-02 09:55:20 +03:00
|
|
|
|
2022-08-17 15:05:36 +03:00
|
|
|
$onboarding_state = $container->get( 'onboarding.state' );
|
|
|
|
assert( $onboarding_state instanceof State );
|
|
|
|
|
|
|
|
$settings = $container->get( 'wcgateway.settings' );
|
|
|
|
assert( $settings instanceof ContainerInterface );
|
|
|
|
|
2022-08-17 16:16:50 +03:00
|
|
|
$is_our_page = $container->get( 'wcgateway.is-ppcp-settings-page' );
|
|
|
|
$is_gateways_list_page = $container->get( 'wcgateway.is-wc-gateways-list-page' );
|
2022-08-17 15:05:36 +03:00
|
|
|
|
|
|
|
if ( $onboarding_state->current_state() !== State::STATE_ONBOARDED ) {
|
|
|
|
return $methods;
|
|
|
|
}
|
|
|
|
|
|
|
|
$dcc_applies = $container->get( 'api.helpers.dccapplies' );
|
|
|
|
assert( $dcc_applies instanceof DccApplies );
|
|
|
|
|
2022-08-17 16:16:50 +03:00
|
|
|
$dcc_product_status = $container->get( 'wcgateway.helper.dcc-product-status' );
|
|
|
|
assert( $dcc_product_status instanceof DCCProductStatus );
|
|
|
|
|
2022-08-17 15:05:36 +03:00
|
|
|
if ( $dcc_applies->for_country_currency() &&
|
|
|
|
// Show only if allowed in PayPal account, except when on our settings pages.
|
2022-08-17 16:16:50 +03:00
|
|
|
// Performing the full DCCProductStatus check only when on the gateway list page
|
|
|
|
// to avoid sending the API requests all the time.
|
|
|
|
( $is_our_page ||
|
|
|
|
( $is_gateways_list_page && $dcc_product_status->dcc_is_active() ) ||
|
|
|
|
( $settings->has( 'products_dcc_enabled' ) && $settings->get( 'products_dcc_enabled' ) )
|
|
|
|
)
|
2022-08-17 15:05:36 +03:00
|
|
|
) {
|
2020-08-27 11:08:36 +03:00
|
|
|
$methods[] = $container->get( 'wcgateway.credit-card-gateway' );
|
|
|
|
}
|
2022-03-07 12:54:02 +01:00
|
|
|
|
2022-08-03 09:37:40 +03:00
|
|
|
if ( $paypal_gateway_enabled && $container->get( 'wcgateway.settings.allow_card_button_gateway' ) ) {
|
2022-07-26 10:58:21 +03:00
|
|
|
$methods[] = $container->get( 'wcgateway.card-button-gateway' );
|
|
|
|
}
|
2022-07-19 09:20:26 +03:00
|
|
|
|
2022-08-17 16:16:50 +03:00
|
|
|
$pui_product_status = $container->get( 'wcgateway.pay-upon-invoice-product-status' );
|
|
|
|
assert( $pui_product_status instanceof PayUponInvoiceProductStatus );
|
|
|
|
|
2022-08-17 15:05:36 +03:00
|
|
|
$shop_country = $container->get( 'api.shop.country' );
|
|
|
|
|
|
|
|
if ( 'DE' === $shop_country &&
|
2022-08-17 16:16:50 +03:00
|
|
|
( $is_our_page ||
|
|
|
|
( $is_gateways_list_page && $pui_product_status->pui_is_active() ) ||
|
|
|
|
( $settings->has( 'products_pui_enabled' ) && $settings->get( 'products_pui_enabled' ) )
|
|
|
|
)
|
2022-08-17 15:05:36 +03:00
|
|
|
) {
|
2022-03-08 12:33:59 +01:00
|
|
|
$methods[] = $container->get( 'wcgateway.pay-upon-invoice-gateway' );
|
|
|
|
}
|
2022-03-07 12:54:02 +01:00
|
|
|
|
2022-11-02 12:27:03 +01:00
|
|
|
if ( 'MX' === $shop_country ) {
|
2022-08-02 12:11:18 +02:00
|
|
|
$methods[] = $container->get( 'wcgateway.oxxo-gateway' );
|
|
|
|
}
|
2022-07-05 11:30:20 +02:00
|
|
|
|
2020-08-27 11:08:36 +03:00
|
|
|
return (array) $methods;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
add_action(
|
|
|
|
'woocommerce_settings_save_checkout',
|
|
|
|
static function () use ( $container ) {
|
|
|
|
$listener = $container->get( 'wcgateway.settings.listener' );
|
2020-09-16 10:00:28 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The settings listener.
|
|
|
|
*
|
|
|
|
* @var SettingsListener $listener
|
|
|
|
*/
|
2020-08-27 11:08:36 +03:00
|
|
|
$listener->listen();
|
|
|
|
}
|
|
|
|
);
|
2020-09-16 10:00:28 +03:00
|
|
|
add_action(
|
|
|
|
'admin_init',
|
|
|
|
static function () use ( $container ) {
|
|
|
|
$listener = $container->get( 'wcgateway.settings.listener' );
|
|
|
|
/**
|
|
|
|
* The settings listener.
|
|
|
|
*
|
|
|
|
* @var SettingsListener $listener
|
|
|
|
*/
|
|
|
|
$listener->listen_for_merchant_id();
|
2021-03-19 17:37:01 +01:00
|
|
|
$listener->listen_for_vaulting_enabled();
|
2022-08-17 16:25:23 +04:00
|
|
|
$listener->listen_for_tracking_enabled();
|
2020-09-16 10:00:28 +03:00
|
|
|
}
|
|
|
|
);
|
2020-08-27 11:08:36 +03:00
|
|
|
|
|
|
|
add_filter(
|
|
|
|
'woocommerce_form_field',
|
|
|
|
static function ( $field, $key, $args, $value ) use ( $container ) {
|
|
|
|
$renderer = $container->get( 'wcgateway.settings.render' );
|
|
|
|
/**
|
2020-08-28 08:13:45 +03:00
|
|
|
* The Settings Renderer object.
|
|
|
|
*
|
2020-08-27 11:08:36 +03:00
|
|
|
* @var SettingsRenderer $renderer
|
|
|
|
*/
|
2020-08-28 08:13:45 +03:00
|
|
|
$field = $renderer->render_multiselect( $field, $key, $args, $value );
|
|
|
|
$field = $renderer->render_password( $field, $key, $args, $value );
|
|
|
|
$field = $renderer->render_text_input( $field, $key, $args, $value );
|
|
|
|
$field = $renderer->render_heading( $field, $key, $args, $value );
|
2021-09-16 12:41:08 +03:00
|
|
|
$field = $renderer->render_table( $field, $key, $args, $value );
|
2020-08-27 11:08:36 +03:00
|
|
|
return $field;
|
|
|
|
},
|
|
|
|
10,
|
|
|
|
4
|
|
|
|
);
|
|
|
|
|
|
|
|
add_filter(
|
|
|
|
'woocommerce_available_payment_gateways',
|
|
|
|
static function ( $methods ) use ( $container ): array {
|
|
|
|
$disabler = $container->get( 'wcgateway.disabler' );
|
|
|
|
/**
|
2020-08-28 08:13:45 +03:00
|
|
|
* The Gateay disabler.
|
|
|
|
*
|
2020-08-27 11:08:36 +03:00
|
|
|
* @var DisableGateways $disabler
|
|
|
|
*/
|
|
|
|
return $disabler->handler( (array) $methods );
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:13:45 +03:00
|
|
|
/**
|
|
|
|
* Registers the authorize order functionality.
|
|
|
|
*
|
|
|
|
* @param ContainerInterface $container The container.
|
|
|
|
*/
|
|
|
|
private function register_order_functionality( ContainerInterface $container ) {
|
2020-08-27 11:08:36 +03:00
|
|
|
add_filter(
|
|
|
|
'woocommerce_order_actions',
|
2020-09-30 08:18:17 +03:00
|
|
|
static function ( $order_actions ) use ( $container ): array {
|
|
|
|
global $theorder;
|
|
|
|
|
2022-02-14 13:53:37 +02:00
|
|
|
if ( ! is_a( $theorder, WC_Order::class ) ) {
|
2020-09-30 08:18:17 +03:00
|
|
|
return $order_actions;
|
|
|
|
}
|
|
|
|
|
|
|
|
$render = $container->get( 'wcgateway.admin.render-authorize-action' );
|
|
|
|
/**
|
|
|
|
* Renders the authorize action in the select field.
|
|
|
|
*
|
|
|
|
* @var RenderAuthorizeAction $render
|
|
|
|
*/
|
|
|
|
return $render->render( $order_actions, $theorder );
|
2020-08-27 11:08:36 +03:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
add_action(
|
|
|
|
'woocommerce_order_action_ppcp_authorize_order',
|
2022-02-14 13:53:37 +02:00
|
|
|
static function ( WC_Order $wc_order ) use ( $container ) {
|
2021-10-14 15:45:57 +02:00
|
|
|
|
2020-08-27 11:08:36 +03:00
|
|
|
/**
|
2021-10-14 15:45:57 +02:00
|
|
|
* The authorized payments processor.
|
2020-08-28 08:13:45 +03:00
|
|
|
*
|
2021-10-14 15:45:57 +02:00
|
|
|
* @var AuthorizedPaymentsProcessor $authorized_payments_processor
|
2020-08-27 11:08:36 +03:00
|
|
|
*/
|
2021-10-14 15:45:57 +02:00
|
|
|
$authorized_payments_processor = $container->get( 'wcgateway.processor.authorized-payments' );
|
|
|
|
$authorized_payments_processor->capture_authorized_payment( $wc_order );
|
2020-08-27 11:08:36 +03:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:13:45 +03:00
|
|
|
/**
|
|
|
|
* Registers the additional columns on the order list page.
|
|
|
|
*
|
|
|
|
* @param ContainerInterface $container The container.
|
|
|
|
*/
|
|
|
|
private function register_columns( ContainerInterface $container ) {
|
2020-08-27 11:08:36 +03:00
|
|
|
add_action(
|
|
|
|
'woocommerce_order_actions_start',
|
2020-08-28 08:13:45 +03:00
|
|
|
static function ( $wc_order_id ) use ( $container ) {
|
2020-08-27 11:08:36 +03:00
|
|
|
/**
|
2020-08-28 08:13:45 +03:00
|
|
|
* The Payment Status Order Detail.
|
|
|
|
*
|
2020-08-27 11:08:36 +03:00
|
|
|
* @var PaymentStatusOrderDetail $class
|
|
|
|
*/
|
|
|
|
$class = $container->get( 'wcgateway.admin.order-payment-status' );
|
2020-08-28 08:13:45 +03:00
|
|
|
$class->render( intval( $wc_order_id ) );
|
2020-08-27 11:08:36 +03:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
add_filter(
|
|
|
|
'manage_edit-shop_order_columns',
|
|
|
|
static function ( $columns ) use ( $container ) {
|
|
|
|
/**
|
2020-08-28 08:13:45 +03:00
|
|
|
* The Order Table Payment Status object.
|
|
|
|
*
|
|
|
|
* @var OrderTablePaymentStatusColumn $payment_status_column
|
2020-08-27 11:08:36 +03:00
|
|
|
*/
|
2020-08-28 08:13:45 +03:00
|
|
|
$payment_status_column = $container->get( 'wcgateway.admin.orders-payment-status-column' );
|
|
|
|
return $payment_status_column->register( $columns );
|
2020-08-27 11:08:36 +03:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
add_action(
|
|
|
|
'manage_shop_order_posts_custom_column',
|
2020-08-28 08:13:45 +03:00
|
|
|
static function ( $column, $wc_order_id ) use ( $container ) {
|
2020-08-27 11:08:36 +03:00
|
|
|
/**
|
2020-08-28 08:13:45 +03:00
|
|
|
* The column object.
|
|
|
|
*
|
|
|
|
* @var OrderTablePaymentStatusColumn $payment_status_column
|
2020-08-27 11:08:36 +03:00
|
|
|
*/
|
2020-08-28 08:13:45 +03:00
|
|
|
$payment_status_column = $container->get( 'wcgateway.admin.orders-payment-status-column' );
|
|
|
|
$payment_status_column->render( $column, intval( $wc_order_id ) );
|
2020-08-27 11:08:36 +03:00
|
|
|
},
|
|
|
|
10,
|
|
|
|
2
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:13:45 +03:00
|
|
|
/**
|
|
|
|
* Registers the PayPal Address preset to overwrite Shipping in checkout.
|
|
|
|
*
|
|
|
|
* @param ContainerInterface $container The container.
|
|
|
|
*/
|
2020-09-11 13:38:02 +03:00
|
|
|
private function register_checkout_paypal_address_preset( ContainerInterface $container ) {
|
2020-08-27 11:08:36 +03:00
|
|
|
add_filter(
|
|
|
|
'woocommerce_checkout_get_value',
|
|
|
|
static function ( ...$args ) use ( $container ) {
|
|
|
|
|
2020-08-28 08:13:45 +03:00
|
|
|
/**
|
|
|
|
* Its important to not instantiate the service too early as it
|
|
|
|
* depends on SessionHandler and WooCommerce Session.
|
|
|
|
*/
|
2020-08-27 11:08:36 +03:00
|
|
|
|
|
|
|
/**
|
2020-08-28 08:13:45 +03:00
|
|
|
* The CheckoutPayPalAddressPreset object.
|
|
|
|
*
|
2020-08-27 11:08:36 +03:00
|
|
|
* @var CheckoutPayPalAddressPreset $service
|
|
|
|
*/
|
|
|
|
$service = $container->get( 'wcgateway.checkout.address-preset' );
|
|
|
|
|
2020-08-28 08:13:45 +03:00
|
|
|
return $service->filter_checkout_field( ...$args );
|
2020-08-27 11:08:36 +03:00
|
|
|
},
|
|
|
|
10,
|
|
|
|
2
|
|
|
|
);
|
|
|
|
}
|
2020-09-16 10:18:45 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the key for the module.
|
|
|
|
*
|
|
|
|
* @return string|void
|
|
|
|
*/
|
|
|
|
public function getKey() {
|
|
|
|
}
|
2020-04-06 11:16:18 +03:00
|
|
|
}
|