mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Fix merge conflict
This commit is contained in:
commit
f548c9dfd4
52 changed files with 1260 additions and 170 deletions
|
@ -11,6 +11,7 @@
|
|||
"Edge >= 14"
|
||||
],
|
||||
"dependencies": {
|
||||
"@paypal/paypal-js": "^5.1.1",
|
||||
"core-js": "^3.25.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
17
modules/ppcp-wc-gateway/resources/css/gateway-settings.scss
Normal file
17
modules/ppcp-wc-gateway/resources/css/gateway-settings.scss
Normal file
|
@ -0,0 +1,17 @@
|
|||
.ppcp-button-preview {
|
||||
width: 350px;
|
||||
padding: 15px;
|
||||
border: 1px solid lightgray;
|
||||
border-radius: 15px;
|
||||
box-shadow: 0 2px 10px 1px #ddd;
|
||||
|
||||
h4 {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
@media (min-width: 1200px) {
|
||||
position: absolute;
|
||||
left: 800px;
|
||||
margin-top: -400px;
|
||||
}
|
||||
}
|
|
@ -1,3 +1,7 @@
|
|||
import { loadScript } from "@paypal/paypal-js";
|
||||
import {debounce} from "./helper/debounce";
|
||||
import Renderer from '../../../ppcp-button/resources/js/modules/Renderer/Renderer'
|
||||
|
||||
;document.addEventListener(
|
||||
'DOMContentLoaded',
|
||||
() => {
|
||||
|
@ -65,9 +69,142 @@
|
|||
atLeastOneChecked(vaultingCheckboxes) ? disablePayLater() : enablePayLater()
|
||||
}
|
||||
|
||||
const form = jQuery('#mainform');
|
||||
|
||||
function createButtonPreview(settingsCallback) {
|
||||
const render = (settings) => {
|
||||
const wrapper = document.querySelector(settings.button.wrapper);
|
||||
if (!wrapper) {
|
||||
return;
|
||||
}
|
||||
wrapper.innerHTML = '';
|
||||
|
||||
const renderer = new Renderer(null, settings, (data, actions) => actions.reject(), null);
|
||||
|
||||
try {
|
||||
renderer.render({});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
};
|
||||
|
||||
let oldSettings = settingsCallback();
|
||||
|
||||
form.on('change', ':input', debounce(() => {
|
||||
const newSettings = settingsCallback();
|
||||
if (JSON.stringify(oldSettings) === JSON.stringify(newSettings)) {
|
||||
return;
|
||||
}
|
||||
|
||||
render(newSettings);
|
||||
|
||||
oldSettings = newSettings;
|
||||
}, 300));
|
||||
|
||||
jQuery(document).on('ppcp_paypal_script_loaded', () => {
|
||||
oldSettings = settingsCallback();
|
||||
|
||||
render(oldSettings);
|
||||
});
|
||||
|
||||
render(oldSettings);
|
||||
}
|
||||
|
||||
function getPaypalScriptSettings() {
|
||||
const disabledSources = jQuery('[name="ppcp[disable_funding][]"]').val();
|
||||
const settings = {
|
||||
'client-id': PayPalCommerceGatewaySettings.client_id,
|
||||
'currency': PayPalCommerceGatewaySettings.currency,
|
||||
'integration-date': PayPalCommerceGatewaySettings.integration_date,
|
||||
'components': ['buttons', 'funding-eligibility', 'messages'],
|
||||
'enable-funding': ['venmo'],
|
||||
'buyer-country': PayPalCommerceGatewaySettings.country,
|
||||
};
|
||||
if (disabledSources?.length) {
|
||||
settings['disable-funding'] = disabledSources;
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
function loadPaypalScript(settings, onLoaded = () => {}) {
|
||||
loadScript(JSON.parse(JSON.stringify(settings))) // clone the object to prevent modification
|
||||
.then(paypal => {
|
||||
document.dispatchEvent(new CustomEvent('ppcp_paypal_script_loaded'));
|
||||
|
||||
onLoaded(paypal);
|
||||
})
|
||||
.catch((error) => console.error('failed to load the PayPal JS SDK script', error));
|
||||
}
|
||||
|
||||
disableAll( disabledCheckboxes )
|
||||
togglePayLater()
|
||||
|
||||
vaultingCheckboxes.forEach(node => node.addEventListener('change', togglePayLater));
|
||||
|
||||
let oldScriptSettings = getPaypalScriptSettings();
|
||||
|
||||
form.on('change', ':input', debounce(() => {
|
||||
const newSettings = getPaypalScriptSettings();
|
||||
if (JSON.stringify(oldScriptSettings) === JSON.stringify(newSettings)) {
|
||||
return;
|
||||
}
|
||||
|
||||
loadPaypalScript(newSettings);
|
||||
|
||||
oldScriptSettings = newSettings;
|
||||
}, 1000));
|
||||
|
||||
function getButtonSettings(wrapperSelector, fields) {
|
||||
const layout = jQuery(fields['layout']).val();
|
||||
const style = {
|
||||
'color': jQuery(fields['color']).val(),
|
||||
'shape': jQuery(fields['shape']).val(),
|
||||
'label': jQuery(fields['label']).val(),
|
||||
'tagline': layout === 'horizontal' && jQuery(fields['tagline']).is(':checked'),
|
||||
'layout': layout,
|
||||
};
|
||||
if ('height' in fields) {
|
||||
style['height'] = parseInt(jQuery(fields['height']).val());
|
||||
}
|
||||
return {
|
||||
'button': {
|
||||
'wrapper': wrapperSelector,
|
||||
'style': style,
|
||||
},
|
||||
'separate_buttons': {},
|
||||
};
|
||||
}
|
||||
|
||||
loadPaypalScript(oldScriptSettings, () => {
|
||||
createButtonPreview(() => getButtonSettings('#ppcpCheckoutButtonPreview', {
|
||||
'color': '#ppcp-button_color',
|
||||
'shape': '#ppcp-button_shape',
|
||||
'label': '#ppcp-button_label',
|
||||
'tagline': '#ppcp-button_tagline',
|
||||
'layout': '#ppcp-button_layout',
|
||||
}));
|
||||
createButtonPreview(() => getButtonSettings('#ppcpProductButtonPreview', {
|
||||
'color': '#ppcp-button_product_color',
|
||||
'shape': '#ppcp-button_product_shape',
|
||||
'label': '#ppcp-button_product_label',
|
||||
'tagline': '#ppcp-button_product_tagline',
|
||||
'layout': '#ppcp-button_product_layout',
|
||||
}));
|
||||
createButtonPreview(() => getButtonSettings('#ppcpCartButtonPreview', {
|
||||
'color': '#ppcp-button_cart_color',
|
||||
'shape': '#ppcp-button_cart_shape',
|
||||
'label': '#ppcp-button_cart_label',
|
||||
'tagline': '#ppcp-button_cart_tagline',
|
||||
'layout': '#ppcp-button_cart_layout',
|
||||
}));
|
||||
createButtonPreview(() => getButtonSettings('#ppcpMiniCartButtonPreview', {
|
||||
'color': '#ppcp-button_mini-cart_color',
|
||||
'shape': '#ppcp-button_mini-cart_shape',
|
||||
'label': '#ppcp-button_mini-cart_label',
|
||||
'tagline': '#ppcp-button_mini-cart_tagline',
|
||||
'layout': '#ppcp-button_mini-cart_layout',
|
||||
'height': '#ppcp-button_mini-cart_height',
|
||||
}));
|
||||
});
|
||||
}
|
||||
);
|
||||
|
|
9
modules/ppcp-wc-gateway/resources/js/helper/debounce.js
Normal file
9
modules/ppcp-wc-gateway/resources/js/helper/debounce.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
export const debounce = (callback, delayMs) => {
|
||||
let timeoutId = null;
|
||||
return (...args) => {
|
||||
window.clearTimeout(timeoutId);
|
||||
timeoutId = window.setTimeout(() => {
|
||||
callback.apply(null, args);
|
||||
}, delayMs);
|
||||
};
|
||||
};
|
|
@ -402,6 +402,14 @@ return array(
|
|||
$onboarding_options_renderer = $container->get( 'onboarding.render-options' );
|
||||
assert( $onboarding_options_renderer instanceof OnboardingOptionsRenderer );
|
||||
|
||||
$render_preview_element = function ( string $id ): string {
|
||||
return '
|
||||
<div class="ppcp-button-preview">
|
||||
<h4>' . __( 'Preview', 'woocommerce-paypal-payments' ) . '</h4>
|
||||
<div id="' . $id . '" class="ppcp-button-preview-inner"></div>
|
||||
</div>';
|
||||
};
|
||||
|
||||
$subscription_helper = $container->get( 'subscription.helper' );
|
||||
assert( $subscription_helper instanceof SubscriptionHelper );
|
||||
|
||||
|
@ -811,6 +819,15 @@ return array(
|
|||
'requirements' => array(),
|
||||
'gateway' => 'paypal',
|
||||
),
|
||||
'button_preview' => array(
|
||||
'type' => 'ppcp-text',
|
||||
'text' => $render_preview_element( 'ppcpCheckoutButtonPreview' ),
|
||||
'screens' => array(
|
||||
State::STATE_ONBOARDED,
|
||||
),
|
||||
'requirements' => array(),
|
||||
'gateway' => 'paypal',
|
||||
),
|
||||
'message_heading' => array(
|
||||
'heading' => __( 'Pay Later messaging on Checkout', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'ppcp-heading',
|
||||
|
@ -1128,6 +1145,15 @@ return array(
|
|||
'requirements' => array(),
|
||||
'gateway' => 'paypal',
|
||||
),
|
||||
'button_product_preview' => array(
|
||||
'type' => 'ppcp-text',
|
||||
'text' => $render_preview_element( 'ppcpProductButtonPreview' ),
|
||||
'screens' => array(
|
||||
State::STATE_ONBOARDED,
|
||||
),
|
||||
'requirements' => array(),
|
||||
'gateway' => 'paypal',
|
||||
),
|
||||
|
||||
'message_product_heading' => array(
|
||||
'heading' => __( 'Pay Later messaging on Single Product Page', 'woocommerce-paypal-payments' ),
|
||||
|
@ -1446,6 +1472,15 @@ return array(
|
|||
'requirements' => array(),
|
||||
'gateway' => 'paypal',
|
||||
),
|
||||
'button_cart_preview' => array(
|
||||
'type' => 'ppcp-text',
|
||||
'text' => $render_preview_element( 'ppcpCartButtonPreview' ),
|
||||
'screens' => array(
|
||||
State::STATE_ONBOARDED,
|
||||
),
|
||||
'requirements' => array(),
|
||||
'gateway' => 'paypal',
|
||||
),
|
||||
|
||||
'message_cart_heading' => array(
|
||||
'heading' => __( 'Pay Later messaging on Cart', 'woocommerce-paypal-payments' ),
|
||||
|
@ -1777,6 +1812,15 @@ return array(
|
|||
'requirements' => array(),
|
||||
'gateway' => 'paypal',
|
||||
),
|
||||
'button_mini-cart_preview' => array(
|
||||
'type' => 'ppcp-text',
|
||||
'text' => $render_preview_element( 'ppcpMiniCartButtonPreview' ),
|
||||
'screens' => array(
|
||||
State::STATE_ONBOARDED,
|
||||
),
|
||||
'requirements' => array(),
|
||||
'gateway' => 'paypal',
|
||||
),
|
||||
|
||||
'disable_cards' => array(
|
||||
'title' => __( 'Disable specific credit cards', 'woocommerce-paypal-payments' ),
|
||||
|
@ -2035,7 +2079,9 @@ return array(
|
|||
$container->get( 'wcgateway.transaction-url-provider' ),
|
||||
$container->get( 'woocommerce.logger.woocommerce' ),
|
||||
$container->get( 'wcgateway.pay-upon-invoice-helper' ),
|
||||
$container->get( 'wcgateway.checkout-helper' )
|
||||
$container->get( 'wcgateway.checkout-helper' ),
|
||||
$container->get( 'onboarding.state' ),
|
||||
$container->get( 'wcgateway.processor.refunds' )
|
||||
);
|
||||
},
|
||||
'wcgateway.pay-upon-invoice-fraudnet-session-id' => static function ( ContainerInterface $container ): FraudNetSessionId {
|
||||
|
|
|
@ -9,6 +9,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Assets;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
|
||||
|
||||
/**
|
||||
* Class SettingsPageAssets
|
||||
*/
|
||||
|
@ -28,15 +30,58 @@ class SettingsPageAssets {
|
|||
*/
|
||||
private $version;
|
||||
|
||||
/**
|
||||
* The subscription helper.
|
||||
*
|
||||
* @var SubscriptionHelper
|
||||
*/
|
||||
protected $subscription_helper;
|
||||
|
||||
/**
|
||||
* The PayPal SDK client ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $client_id;
|
||||
|
||||
/**
|
||||
* 3-letter currency code of the shop.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $currency;
|
||||
|
||||
/**
|
||||
* 2-letter country code of the shop.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $country;
|
||||
|
||||
/**
|
||||
* Assets constructor.
|
||||
*
|
||||
* @param string $module_url The url of this module.
|
||||
* @param string $version The assets version.
|
||||
* @param string $module_url The url of this module.
|
||||
* @param string $version The assets version.
|
||||
* @param SubscriptionHelper $subscription_helper The subscription helper.
|
||||
* @param string $client_id The PayPal SDK client ID.
|
||||
* @param string $currency 3-letter currency code of the shop.
|
||||
* @param string $country 2-letter country code of the shop.
|
||||
*/
|
||||
public function __construct( string $module_url, string $version ) {
|
||||
$this->module_url = $module_url;
|
||||
$this->version = $version;
|
||||
public function __construct(
|
||||
string $module_url,
|
||||
string $version,
|
||||
SubscriptionHelper $subscription_helper,
|
||||
string $client_id,
|
||||
string $currency,
|
||||
string $country
|
||||
) {
|
||||
$this->module_url = $module_url;
|
||||
$this->version = $version;
|
||||
$this->subscription_helper = $subscription_helper;
|
||||
$this->client_id = $client_id;
|
||||
$this->currency = $currency;
|
||||
$this->country = $country;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,14 +117,15 @@ class SettingsPageAssets {
|
|||
}
|
||||
|
||||
$screen = get_current_screen();
|
||||
|
||||
$tab = filter_input( INPUT_GET, 'tab', FILTER_SANITIZE_STRING );
|
||||
$section = filter_input( INPUT_GET, 'section', FILTER_SANITIZE_STRING );
|
||||
|
||||
if ( ! 'woocommerce_page_wc-settings' === $screen->id ) {
|
||||
if ( $screen->id !== 'woocommerce_page_wc-settings' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||
$tab = wc_clean( wp_unslash( $_GET['tab'] ?? '' ) );
|
||||
$section = wc_clean( wp_unslash( $_GET['section'] ?? '' ) );
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Recommended
|
||||
|
||||
return 'checkout' === $tab && 'ppcp-gateway' === $section;
|
||||
}
|
||||
|
||||
|
@ -87,6 +133,13 @@ class SettingsPageAssets {
|
|||
* Register assets for admin pages.
|
||||
*/
|
||||
private function register_admin_assets() {
|
||||
wp_enqueue_style(
|
||||
'ppcp-gateway-settings',
|
||||
trailingslashit( $this->module_url ) . 'assets/css/gateway-settings.css',
|
||||
array(),
|
||||
$this->version
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'ppcp-gateway-settings',
|
||||
trailingslashit( $this->module_url ) . 'assets/js/gateway-settings.js',
|
||||
|
@ -95,11 +148,21 @@ class SettingsPageAssets {
|
|||
true
|
||||
);
|
||||
|
||||
// Intent is configured with Authorize and Capture Virtual-Only Orders is not set.
|
||||
/**
|
||||
* Psalm cannot find it for some reason.
|
||||
*
|
||||
* @psalm-suppress UndefinedConstant
|
||||
*/
|
||||
wp_localize_script(
|
||||
'ppcp-gateway-settings',
|
||||
'PayPalCommerceGatewaySettings',
|
||||
array()
|
||||
array(
|
||||
'is_subscriptions_plugin_active' => $this->subscription_helper->plugin_is_active(),
|
||||
'client_id' => $this->client_id,
|
||||
'currency' => $this->currency,
|
||||
'country' => $this->country,
|
||||
'integration_date' => PAYPAL_INTEGRATION_DATE,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -275,9 +275,11 @@ class CardButtonGateway extends \WC_Payment_Gateway {
|
|||
* If customer has chosen change Subscription payment.
|
||||
*/
|
||||
if ( $this->subscription_helper->has_subscription( $order_id ) && $this->subscription_helper->is_subscription_change_payment() ) {
|
||||
$saved_paypal_payment = filter_input( INPUT_POST, 'saved_paypal_payment', FILTER_SANITIZE_STRING );
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$saved_paypal_payment = wc_clean( wp_unslash( $_POST['saved_paypal_payment'] ?? '' ) );
|
||||
if ( $saved_paypal_payment ) {
|
||||
update_post_meta( $order_id, 'payment_token_id', $saved_paypal_payment );
|
||||
$wc_order->update_meta_data( 'payment_token_id', $saved_paypal_payment );
|
||||
$wc_order->save();
|
||||
|
||||
return $this->handle_payment_success( $wc_order );
|
||||
}
|
||||
|
|
|
@ -360,7 +360,8 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
|
|||
/**
|
||||
* If customer has chosen a saved credit card payment.
|
||||
*/
|
||||
$saved_credit_card = filter_input( INPUT_POST, 'saved_credit_card', FILTER_SANITIZE_STRING );
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$saved_credit_card = wc_clean( wp_unslash( $_POST['saved_credit_card'] ?? '' ) );
|
||||
if ( $saved_credit_card ) {
|
||||
try {
|
||||
$wc_order = $this->vaulted_credit_card_handler->handle_payment(
|
||||
|
|
|
@ -138,7 +138,8 @@ class OXXO {
|
|||
'add_meta_boxes',
|
||||
function( string $post_type ) {
|
||||
if ( $post_type === 'shop_order' ) {
|
||||
$post_id = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_STRING );
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
$post_id = wc_clean( wp_unslash( $_GET['post'] ?? '' ) );
|
||||
$order = wc_get_order( $post_id );
|
||||
if ( is_a( $order, WC_Order::class ) && $order->get_payment_method() === OXXOGateway::ID ) {
|
||||
$payer_action = $order->get_meta( 'ppcp_oxxo_payer_action' );
|
||||
|
@ -182,7 +183,8 @@ class OXXO {
|
|||
return false;
|
||||
}
|
||||
|
||||
$billing_country = filter_input( INPUT_POST, 'country', FILTER_SANITIZE_STRING ) ?? null;
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$billing_country = wc_clean( wp_unslash( $_POST['country'] ?? '' ) );
|
||||
if ( $billing_country && 'MX' !== $billing_country ) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -400,8 +400,8 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
);
|
||||
}
|
||||
|
||||
$funding_source = filter_input( INPUT_POST, 'ppcp-funding-source', FILTER_SANITIZE_STRING );
|
||||
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$funding_source = wc_clean( wp_unslash( $_POST['ppcp-funding-source'] ?? '' ) );
|
||||
if ( 'card' !== $funding_source && $this->is_free_trial_order( $wc_order ) ) {
|
||||
$user_id = (int) $wc_order->get_customer_id();
|
||||
$tokens = $this->payment_token_repository->all_for_user_id( $user_id );
|
||||
|
@ -423,9 +423,11 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
* If customer has chosen change Subscription payment.
|
||||
*/
|
||||
if ( $this->subscription_helper->has_subscription( $order_id ) && $this->subscription_helper->is_subscription_change_payment() ) {
|
||||
$saved_paypal_payment = filter_input( INPUT_POST, 'saved_paypal_payment', FILTER_SANITIZE_STRING );
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$saved_paypal_payment = wc_clean( wp_unslash( $_POST['saved_paypal_payment'] ?? '' ) );
|
||||
if ( $saved_paypal_payment ) {
|
||||
update_post_meta( $order_id, 'payment_token_id', $saved_paypal_payment );
|
||||
$wc_order->update_meta_data( 'payment_token_id', $saved_paypal_payment );
|
||||
$wc_order->save();
|
||||
|
||||
return $this->handle_payment_success( $wc_order );
|
||||
}
|
||||
|
|
|
@ -33,7 +33,8 @@ class FraudNetSessionId {
|
|||
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) {
|
||||
$pui_pay_for_order_session_id = filter_input( INPUT_POST, 'pui_pay_for_order_session_id', FILTER_SANITIZE_STRING );
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$pui_pay_for_order_session_id = wc_clean( wp_unslash( $_POST['pui_pay_for_order_session_id'] ?? '' ) );
|
||||
if ( $pui_pay_for_order_session_id && '' !== $pui_pay_for_order_session_id ) {
|
||||
return $pui_pay_for_order_session_id;
|
||||
}
|
||||
|
|
|
@ -251,16 +251,24 @@ class PayUponInvoice {
|
|||
|
||||
$order = $this->pui_order_endpoint->order( $order_id );
|
||||
|
||||
$payment_instructions = array(
|
||||
$order->payment_source->pay_upon_invoice->payment_reference,
|
||||
$order->payment_source->pay_upon_invoice->deposit_bank_details,
|
||||
);
|
||||
$wc_order->update_meta_data(
|
||||
'ppcp_ratepay_payment_instructions_payment_reference',
|
||||
$payment_instructions
|
||||
);
|
||||
$wc_order->save_meta_data();
|
||||
$this->logger->info( "Ratepay payment instructions added to order #{$wc_order->get_id()}." );
|
||||
if (
|
||||
property_exists( $order, 'payment_source' )
|
||||
&& property_exists( $order->payment_source, 'pay_upon_invoice' )
|
||||
&& property_exists( $order->payment_source->pay_upon_invoice, 'payment_reference' )
|
||||
&& property_exists( $order->payment_source->pay_upon_invoice, 'deposit_bank_details' )
|
||||
) {
|
||||
|
||||
$payment_instructions = array(
|
||||
$order->payment_source->pay_upon_invoice->payment_reference,
|
||||
$order->payment_source->pay_upon_invoice->deposit_bank_details,
|
||||
);
|
||||
$wc_order->update_meta_data(
|
||||
'ppcp_ratepay_payment_instructions_payment_reference',
|
||||
$payment_instructions
|
||||
);
|
||||
$wc_order->save_meta_data();
|
||||
$this->logger->info( "Ratepay payment instructions added to order #{$wc_order->get_id()}." );
|
||||
}
|
||||
|
||||
$capture = $this->capture_factory->from_paypal_response( $order->purchase_units[0]->payments->captures[0] );
|
||||
$breakdown = $capture->seller_receivable_breakdown();
|
||||
|
@ -409,7 +417,8 @@ class PayUponInvoice {
|
|||
add_action(
|
||||
'woocommerce_after_checkout_validation',
|
||||
function( array $fields, WP_Error $errors ) {
|
||||
$payment_method = filter_input( INPUT_POST, 'payment_method', FILTER_SANITIZE_STRING );
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$payment_method = wc_clean( wp_unslash( $_POST['payment_method'] ?? '' ) );
|
||||
if ( PayUponInvoiceGateway::ID !== $payment_method ) {
|
||||
return;
|
||||
}
|
||||
|
@ -418,12 +427,14 @@ class PayUponInvoice {
|
|||
$errors->add( 'validation', __( 'Billing country not available.', 'woocommerce-paypal-payments' ) );
|
||||
}
|
||||
|
||||
$birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING );
|
||||
if ( ( $birth_date && ! $this->checkout_helper->validate_birth_date( $birth_date ) ) || $birth_date === '' ) {
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$birth_date = wc_clean( wp_unslash( $_POST['billing_birth_date'] ?? '' ) );
|
||||
if ( ( $birth_date && is_string( $birth_date ) && ! $this->checkout_helper->validate_birth_date( $birth_date ) ) || $birth_date === '' ) {
|
||||
$errors->add( 'validation', __( 'Invalid birth date.', 'woocommerce-paypal-payments' ) );
|
||||
}
|
||||
|
||||
$national_number = filter_input( INPUT_POST, 'billing_phone', FILTER_SANITIZE_STRING );
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$national_number = wc_clean( wp_unslash( $_POST['billing_phone'] ?? '' ) );
|
||||
if ( ! $national_number ) {
|
||||
$errors->add( 'validation', __( 'Phone field cannot be empty.', 'woocommerce-paypal-payments' ) );
|
||||
}
|
||||
|
@ -484,18 +495,9 @@ class PayUponInvoice {
|
|||
add_action(
|
||||
'woocommerce_update_options_checkout_ppcp-pay-upon-invoice-gateway',
|
||||
function () {
|
||||
$customer_service_instructions = filter_input( INPUT_POST, 'woocommerce_ppcp-pay-upon-invoice-gateway_customer_service_instructions', FILTER_SANITIZE_STRING );
|
||||
if ( '' === $customer_service_instructions ) {
|
||||
$gateway_settings = get_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings' );
|
||||
$gateway_enabled = $gateway_settings['enabled'] ?? '';
|
||||
if ( 'yes' === $gateway_enabled ) {
|
||||
$gateway_settings['enabled'] = 'no';
|
||||
update_option( 'woocommerce_ppcp-pay-upon-invoice-gateway_settings', $gateway_settings );
|
||||
|
||||
$redirect_url = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-pay-upon-invoice-gateway' );
|
||||
wp_safe_redirect( $redirect_url );
|
||||
exit;
|
||||
}
|
||||
$gateway = WC()->payment_gateways()->payment_gateways()[ PayUponInvoiceGateway::ID ];
|
||||
if ( $gateway && $gateway->get_option( 'customer_service_instructions' ) === '' ) {
|
||||
$gateway->update_option( 'enabled', 'no' );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -509,13 +511,18 @@ class PayUponInvoice {
|
|||
) {
|
||||
$error_messages = array();
|
||||
$pui_gateway = WC()->payment_gateways->payment_gateways()[ PayUponInvoiceGateway::ID ];
|
||||
if ( $pui_gateway->get_option( 'brand_name' ) === '' ) {
|
||||
$error_messages[] = esc_html__( 'Could not enable gateway because "Brand name" field is empty.', 'woocommerce-paypal-payments' );
|
||||
}
|
||||
if ( $pui_gateway->get_option( 'logo_url' ) === '' ) {
|
||||
$error_messages[] = esc_html__( 'Could not enable gateway because "Logo URL" field is empty.', 'woocommerce-paypal-payments' );
|
||||
}
|
||||
if ( $pui_gateway->get_option( 'customer_service_instructions' ) === '' ) {
|
||||
$error_messages[] = esc_html__( 'Could not enable gateway because "Customer service instructions" field is empty.', 'woocommerce-paypal-payments' );
|
||||
}
|
||||
if ( count( $error_messages ) > 0 ) { ?>
|
||||
if ( count( $error_messages ) > 0 ) {
|
||||
$pui_gateway->update_option( 'enabled', 'no' );
|
||||
?>
|
||||
<div class="notice notice-error">
|
||||
<?php
|
||||
array_map(
|
||||
|
@ -537,7 +544,8 @@ class PayUponInvoice {
|
|||
'add_meta_boxes',
|
||||
function( string $post_type ) {
|
||||
if ( $post_type === 'shop_order' ) {
|
||||
$post_id = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_STRING );
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
$post_id = wc_clean( wp_unslash( $_GET['post'] ?? '' ) );
|
||||
$order = wc_get_order( $post_id );
|
||||
if ( is_a( $order, WC_Order::class ) && $order->get_payment_method() === PayUponInvoiceGateway::ID ) {
|
||||
$instructions = $order->get_meta( 'ppcp_ratepay_payment_instructions_payment_reference' );
|
||||
|
|
|
@ -17,10 +17,12 @@ use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\CheckoutHelper;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceHelper;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderMetaTrait;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
|
||||
|
||||
/**
|
||||
* Class PayUponInvoiceGateway.
|
||||
|
@ -87,6 +89,20 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
|||
*/
|
||||
protected $checkout_helper;
|
||||
|
||||
/**
|
||||
* The onboarding state.
|
||||
*
|
||||
* @var State
|
||||
*/
|
||||
protected $state;
|
||||
|
||||
/**
|
||||
* The refund processor.
|
||||
*
|
||||
* @var RefundProcessor
|
||||
*/
|
||||
protected $refund_processor;
|
||||
|
||||
/**
|
||||
* PayUponInvoiceGateway constructor.
|
||||
*
|
||||
|
@ -98,6 +114,8 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
|||
* @param LoggerInterface $logger The logger.
|
||||
* @param PayUponInvoiceHelper $pui_helper The PUI helper.
|
||||
* @param CheckoutHelper $checkout_helper The checkout helper.
|
||||
* @param State $state The onboarding state.
|
||||
* @param RefundProcessor $refund_processor The refund processor.
|
||||
*/
|
||||
public function __construct(
|
||||
PayUponInvoiceOrderEndpoint $order_endpoint,
|
||||
|
@ -107,7 +125,9 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
|||
TransactionUrlProvider $transaction_url_provider,
|
||||
LoggerInterface $logger,
|
||||
PayUponInvoiceHelper $pui_helper,
|
||||
CheckoutHelper $checkout_helper
|
||||
CheckoutHelper $checkout_helper,
|
||||
State $state,
|
||||
RefundProcessor $refund_processor
|
||||
) {
|
||||
$this->id = self::ID;
|
||||
|
||||
|
@ -137,6 +157,12 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
|||
$this->transaction_url_provider = $transaction_url_provider;
|
||||
$this->pui_helper = $pui_helper;
|
||||
$this->checkout_helper = $checkout_helper;
|
||||
|
||||
$this->state = $state;
|
||||
if ( $state->current_state() === State::STATE_ONBOARDED ) {
|
||||
$this->supports = array( 'refunds' );
|
||||
}
|
||||
$this->refund_processor = $refund_processor;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -202,10 +228,11 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
|||
* @return array
|
||||
*/
|
||||
public function process_payment( $order_id ) {
|
||||
$wc_order = wc_get_order( $order_id );
|
||||
$birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING ) ?? '';
|
||||
|
||||
$pay_for_order = filter_input( INPUT_GET, 'pay_for_order', FILTER_SANITIZE_STRING );
|
||||
$wc_order = wc_get_order( $order_id );
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Missing
|
||||
$birth_date = wc_clean( wp_unslash( $_POST['billing_birth_date'] ?? '' ) );
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||
$pay_for_order = wc_clean( wp_unslash( $_GET['pay_for_order'] ?? '' ) );
|
||||
if ( 'true' === $pay_for_order ) {
|
||||
if ( ! $this->checkout_helper->validate_birth_date( $birth_date ) ) {
|
||||
wc_add_notice( 'Invalid birth date.', 'error' );
|
||||
|
@ -215,7 +242,8 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
|||
}
|
||||
}
|
||||
|
||||
$phone_number = filter_input( INPUT_POST, 'billing_phone', FILTER_SANITIZE_STRING ) ?? '';
|
||||
$phone_number = wc_clean( wp_unslash( $_POST['billing_phone'] ?? '' ) );
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Missing
|
||||
if ( $phone_number ) {
|
||||
$wc_order->set_billing_phone( $phone_number );
|
||||
$wc_order->save();
|
||||
|
@ -274,6 +302,22 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process refund.
|
||||
*
|
||||
* @param int $order_id Order ID.
|
||||
* @param float $amount Refund amount.
|
||||
* @param string $reason Refund reason.
|
||||
* @return boolean True or false based on success, or a WP_Error object.
|
||||
*/
|
||||
public function process_refund( $order_id, $amount = null, $reason = '' ) {
|
||||
$order = wc_get_order( $order_id );
|
||||
if ( ! is_a( $order, \WC_Order::class ) ) {
|
||||
return false;
|
||||
}
|
||||
return $this->refund_processor->process( $order, (float) $amount, (string) $reason );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return transaction url for this gateway and given order.
|
||||
*
|
||||
|
|
|
@ -24,8 +24,12 @@ class PaymentSourceFactory {
|
|||
* @return PaymentSource
|
||||
*/
|
||||
public function from_wc_order( WC_Order $order, string $birth_date ) {
|
||||
$address = $order->get_address();
|
||||
$phone = filter_input( INPUT_POST, 'billing_phone', FILTER_SANITIZE_STRING ) ?? $address['phone'] ?: '';
|
||||
$address = $order->get_address();
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$phone = wc_clean( wp_unslash( $_POST['billing_phone'] ?? '' ) );
|
||||
if ( ! $phone ) {
|
||||
$phone = $address['phone'] ?? '';
|
||||
}
|
||||
$phone_country_code = WC()->countries->get_country_calling_code( $address['country'] );
|
||||
$phone_country_code = is_array( $phone_country_code ) && ! empty( $phone_country_code ) ? $phone_country_code[0] : $phone_country_code;
|
||||
if ( is_string( $phone_country_code ) && '' !== $phone_country_code ) {
|
||||
|
|
|
@ -55,11 +55,18 @@ class PayUponInvoiceHelper {
|
|||
return false;
|
||||
}
|
||||
|
||||
$billing_country = filter_input( INPUT_POST, 'country', FILTER_SANITIZE_STRING ) ?? null;
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$billing_country = wc_clean( wp_unslash( $_POST['country'] ?? '' ) );
|
||||
if ( $billing_country && 'DE' !== $billing_country ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
$shipping_country = wc_clean( wp_unslash( $_POST['s_country'] ?? '' ) );
|
||||
if ( $shipping_country && 'DE' !== $shipping_country ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
! $this->is_valid_product()
|
||||
|| ! $this->is_valid_currency()
|
||||
|
|
|
@ -156,7 +156,11 @@ class WCGatewayModule implements ModuleInterface {
|
|||
if ( $c->has( 'wcgateway.url' ) ) {
|
||||
$assets = new SettingsPageAssets(
|
||||
$c->get( 'wcgateway.url' ),
|
||||
$c->get( 'ppcp.asset-version' )
|
||||
$c->get( 'ppcp.asset-version' ),
|
||||
$c->get( 'subscription.helper' ),
|
||||
$c->get( 'button.client_id' ),
|
||||
$c->get( 'api.shop.currency' ),
|
||||
$c->get( 'api.shop.country' )
|
||||
);
|
||||
$assets->register_assets();
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ module.exports = {
|
|||
'gateway-settings': path.resolve('./resources/js/gateway-settings.js'),
|
||||
'pay-upon-invoice': path.resolve('./resources/js/pay-upon-invoice.js'),
|
||||
'oxxo': path.resolve('./resources/js/oxxo.js'),
|
||||
'gateway-settings-style': path.resolve('./resources/css/gateway-settings.scss'),
|
||||
},
|
||||
output: {
|
||||
path: path.resolve(__dirname, 'assets/'),
|
||||
|
@ -19,6 +20,19 @@ module.exports = {
|
|||
test: /\.js?$/,
|
||||
exclude: /node_modules/,
|
||||
loader: 'babel-loader',
|
||||
},
|
||||
{
|
||||
test: /\.scss$/,
|
||||
exclude: /node_modules/,
|
||||
use: [
|
||||
{
|
||||
loader: 'file-loader',
|
||||
options: {
|
||||
name: 'css/[name].css',
|
||||
}
|
||||
},
|
||||
{loader:'sass-loader'}
|
||||
]
|
||||
}]
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1005,6 +1005,13 @@
|
|||
"@jridgewell/resolve-uri" "^3.0.3"
|
||||
"@jridgewell/sourcemap-codec" "^1.4.10"
|
||||
|
||||
"@paypal/paypal-js@^5.1.1":
|
||||
version "5.1.1"
|
||||
resolved "https://registry.yarnpkg.com/@paypal/paypal-js/-/paypal-js-5.1.1.tgz#81ab1f78dd2001061a2472f561d20df687a1d295"
|
||||
integrity sha512-MMQ8TA048gTB43pzEOMzod8WY8hfzy+ahd7w29LtMvXduqzp7/29WxrTlsy4k6ARG6WGJ/uGqpc4+la4UZEQgw==
|
||||
dependencies:
|
||||
promise-polyfill "^8.2.3"
|
||||
|
||||
"@types/eslint-scope@^3.7.3":
|
||||
version "3.7.4"
|
||||
resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.4.tgz#37fc1223f0786c39627068a12e94d6e6fc61de16"
|
||||
|
@ -1933,6 +1940,11 @@ pkg-dir@^4.1.0, pkg-dir@^4.2.0:
|
|||
dependencies:
|
||||
find-up "^4.0.0"
|
||||
|
||||
promise-polyfill@^8.2.3:
|
||||
version "8.2.3"
|
||||
resolved "https://registry.yarnpkg.com/promise-polyfill/-/promise-polyfill-8.2.3.tgz#2edc7e4b81aff781c88a0d577e5fe9da822107c6"
|
||||
integrity sha512-Og0+jCRQetV84U8wVjMNccfGCnMQ9mGs9Hv78QFe+pSDD3gWTpz0y+1QCuxy5d/vBFuZ3iwP2eycAkvqIMPmWg==
|
||||
|
||||
punycode@^2.1.0:
|
||||
version "2.1.1"
|
||||
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue