mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 16:24:33 +08:00
Merge branch 'trunk' into PCP-624-pay-later-messaging-displayed-when-variation-is-not-selected
# Conflicts: # modules/ppcp-button/resources/js/modules/ContextBootstrap/SingleProductBootstap.js
This commit is contained in:
commit
2fded7dd69
21 changed files with 170 additions and 57 deletions
|
@ -31,6 +31,19 @@ const bootstrap = () => {
|
|||
const onSmartButtonClick = (data, actions) => {
|
||||
window.ppcpFundingSource = data.fundingSource;
|
||||
|
||||
// TODO: quick fix to get the error about empty form before attempting PayPal order
|
||||
// it should solve #513 for most of the users, but proper solution should be implemented later.
|
||||
const requiredFields = jQuery('form.woocommerce-checkout .validate-required:visible :input');
|
||||
requiredFields.each((i, input) => {
|
||||
jQuery(input).trigger('validate');
|
||||
});
|
||||
if (jQuery('form.woocommerce-checkout .woocommerce-invalid').length) {
|
||||
errorHandler.clear();
|
||||
errorHandler.message(PayPalCommerceGateway.labels.error.js_validation);
|
||||
|
||||
return actions.reject();
|
||||
}
|
||||
|
||||
const form = document.querySelector('form.woocommerce-checkout');
|
||||
if (form) {
|
||||
jQuery('#ppcp-funding-source-form-input').remove();
|
||||
|
|
|
@ -20,7 +20,9 @@ class CheckoutActionHandler {
|
|||
const errorHandler = this.errorHandler;
|
||||
|
||||
const formSelector = this.config.context === 'checkout' ? 'form.checkout' : 'form#order_review';
|
||||
const formValues = jQuery(formSelector).serialize();
|
||||
const formData = new FormData(document.querySelector(formSelector));
|
||||
// will not handle fields with multiple values (checkboxes, <select multiple>), but we do not care about this here
|
||||
const formJsonObj = Object.fromEntries(formData);
|
||||
|
||||
const createaccount = jQuery('#createaccount').is(":checked") ? true : false;
|
||||
|
||||
|
@ -34,7 +36,7 @@ class CheckoutActionHandler {
|
|||
order_id:this.config.order_id,
|
||||
payment_method: getCurrentPaymentMethod(),
|
||||
funding_source: window.ppcpFundingSource,
|
||||
form:formValues,
|
||||
form: formJsonObj,
|
||||
createaccount: createaccount
|
||||
})
|
||||
}).then(function (res) {
|
||||
|
@ -59,7 +61,7 @@ class CheckoutActionHandler {
|
|||
}
|
||||
}
|
||||
|
||||
return;
|
||||
throw new Error(data.data.message);
|
||||
}
|
||||
const input = document.createElement('input');
|
||||
input.setAttribute('type', 'hidden');
|
||||
|
|
|
@ -54,6 +54,8 @@ class SingleProductBootstap {
|
|||
priceText = document.querySelector('.product .woocommerce-Price-amount').innerText;
|
||||
}
|
||||
|
||||
priceText = priceText.replace(/,/g, '.');
|
||||
|
||||
return parseFloat(priceText.replace(/([^\d,\.\s]*)/g, ''));
|
||||
}
|
||||
|
||||
|
|
|
@ -151,6 +151,7 @@ return array(
|
|||
$three_d_secure = $container->get( 'button.helper.three-d-secure' );
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
$dcc_applies = $container->get( 'api.helpers.dccapplies' );
|
||||
$order_helper = $container->get( 'api.order-helper' );
|
||||
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
||||
return new ApproveOrderEndpoint(
|
||||
$request_data,
|
||||
|
@ -159,6 +160,7 @@ return array(
|
|||
$three_d_secure,
|
||||
$settings,
|
||||
$dcc_applies,
|
||||
$order_helper,
|
||||
$logger
|
||||
);
|
||||
},
|
||||
|
|
|
@ -844,6 +844,10 @@ class SmartButton implements SmartButtonInterface {
|
|||
'Something went wrong. Please try again or choose another payment source.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'js_validation' => __(
|
||||
'Required form fields are not filled or invalid.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
),
|
||||
),
|
||||
'order_id' => 'pay-now' === $this->context() ? absint( $wp->query_vars['order-pay'] ) : 0,
|
||||
|
@ -923,9 +927,9 @@ class SmartButton implements SmartButtonInterface {
|
|||
}
|
||||
|
||||
if ( $this->is_free_trial_cart() ) {
|
||||
$all_sources = $this->all_funding_sources;
|
||||
$all_sources = array_keys( $this->all_funding_sources );
|
||||
if ( $is_dcc_enabled ) {
|
||||
$all_sources = array_keys( array_diff_key( $all_sources, array( 'card' => '' ) ) );
|
||||
$all_sources = array_diff( $all_sources, array( 'card' ) );
|
||||
}
|
||||
$disable_funding = $all_sources;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\OrderHelper;
|
||||
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
|
||||
use WooCommerce\PayPalCommerce\Button\Helper\ThreeDSecure;
|
||||
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
||||
|
@ -26,7 +27,6 @@ use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
|||
*/
|
||||
class ApproveOrderEndpoint implements EndpointInterface {
|
||||
|
||||
|
||||
const ENDPOINT = 'ppc-approve-order';
|
||||
|
||||
/**
|
||||
|
@ -71,6 +71,13 @@ class ApproveOrderEndpoint implements EndpointInterface {
|
|||
*/
|
||||
private $dcc_applies;
|
||||
|
||||
/**
|
||||
* The order helper.
|
||||
*
|
||||
* @var OrderHelper
|
||||
*/
|
||||
protected $order_helper;
|
||||
|
||||
/**
|
||||
* The logger.
|
||||
*
|
||||
|
@ -87,6 +94,7 @@ class ApproveOrderEndpoint implements EndpointInterface {
|
|||
* @param ThreeDSecure $three_d_secure The 3d secure helper object.
|
||||
* @param Settings $settings The settings.
|
||||
* @param DccApplies $dcc_applies The DCC applies object.
|
||||
* @param OrderHelper $order_helper The order helper.
|
||||
* @param LoggerInterface $logger The logger.
|
||||
*/
|
||||
public function __construct(
|
||||
|
@ -96,6 +104,7 @@ class ApproveOrderEndpoint implements EndpointInterface {
|
|||
ThreeDSecure $three_d_secure,
|
||||
Settings $settings,
|
||||
DccApplies $dcc_applies,
|
||||
OrderHelper $order_helper,
|
||||
LoggerInterface $logger
|
||||
) {
|
||||
|
||||
|
@ -105,6 +114,7 @@ class ApproveOrderEndpoint implements EndpointInterface {
|
|||
$this->threed_secure = $three_d_secure;
|
||||
$this->settings = $settings;
|
||||
$this->dcc_applies = $dcc_applies;
|
||||
$this->order_helper = $order_helper;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
|
@ -173,10 +183,10 @@ class ApproveOrderEndpoint implements EndpointInterface {
|
|||
wp_send_json_success( $order );
|
||||
}
|
||||
|
||||
if ( ! $order->status()->is( OrderStatus::APPROVED ) ) {
|
||||
if ( $this->order_helper->contains_physical_goods( $order ) && ! $order->status()->is( OrderStatus::APPROVED ) && ! $order->status()->is( OrderStatus::CREATED ) ) {
|
||||
$message = sprintf(
|
||||
// translators: %s is the id of the order.
|
||||
__( 'Order %s is not approved yet.', 'woocommerce-paypal-payments' ),
|
||||
__( 'Order %s is not ready for processing yet.', 'woocommerce-paypal-payments' ),
|
||||
$data['order_id']
|
||||
);
|
||||
|
||||
|
|
|
@ -403,9 +403,9 @@ class CreateOrderEndpoint implements EndpointInterface {
|
|||
}
|
||||
|
||||
if ( ! $payer && isset( $data['form'] ) ) {
|
||||
parse_str( $data['form'], $form_fields );
|
||||
$form_fields = $data['form'];
|
||||
|
||||
if ( isset( $form_fields['billing_email'] ) && '' !== $form_fields['billing_email'] ) {
|
||||
if ( is_array( $form_fields ) && isset( $form_fields['billing_email'] ) && '' !== $form_fields['billing_email'] ) {
|
||||
return $this->payer_factory->from_checkout_form( $form_fields );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,15 +81,9 @@ class RequestData {
|
|||
$data = array();
|
||||
foreach ( (array) $assoc_array as $raw_key => $raw_value ) {
|
||||
if ( ! is_array( $raw_value ) ) {
|
||||
/**
|
||||
* The 'form' key is preserved for url encoded data and needs different
|
||||
* sanitization.
|
||||
*/
|
||||
if ( 'form' !== $raw_key ) {
|
||||
$data[ sanitize_text_field( (string) $raw_key ) ] = sanitize_text_field( (string) $raw_value );
|
||||
} else {
|
||||
$data[ sanitize_text_field( (string) $raw_key ) ] = sanitize_text_field( urldecode( (string) $raw_value ) );
|
||||
}
|
||||
// Not sure if it is a good idea to sanitize everything at this level,
|
||||
// but should be fine for now since we do not send any HTML or multi-line texts via ajax.
|
||||
$data[ sanitize_text_field( (string) $raw_key ) ] = sanitize_text_field( (string) $raw_value );
|
||||
continue;
|
||||
}
|
||||
$data[ sanitize_text_field( (string) $raw_key ) ] = $this->sanitize( $raw_value );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue