mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 10:55:00 +08:00
Merge branch 'trunk' into PCP-860-apm
This commit is contained in:
commit
2b566fcf44
14 changed files with 292 additions and 43 deletions
|
@ -102,6 +102,9 @@ class CheckoutActionHandler {
|
|||
} else {
|
||||
errorHandler.message(data.data.message);
|
||||
}
|
||||
|
||||
// fire WC event for other plugins
|
||||
jQuery( document.body ).trigger( 'checkout_error' , [ errorHandler.currentHtml() ] );
|
||||
}
|
||||
|
||||
throw {type: 'create-order-error', data: data.data};
|
||||
|
|
|
@ -40,6 +40,10 @@ class FreeTrialHandler {
|
|||
if (errors.length > 0) {
|
||||
this.spinner.unblock();
|
||||
this.errorHandler.messages(errors);
|
||||
|
||||
// fire WC event for other plugins
|
||||
jQuery( document.body ).trigger( 'checkout_error' , [ this.errorHandler.currentHtml() ] );
|
||||
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
|
|
|
@ -40,6 +40,15 @@ class ErrorHandler {
|
|||
this._scrollToMessages();
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {String}
|
||||
*/
|
||||
currentHtml()
|
||||
{
|
||||
const messageContainer = this._getMessageContainer();
|
||||
return messageContainer.outerHTML;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {String} text
|
||||
|
|
|
@ -10,6 +10,7 @@ class CreditCardRenderer {
|
|||
this.spinner = spinner;
|
||||
this.cardValid = false;
|
||||
this.formValid = false;
|
||||
this.emptyFields = new Set(['number', 'cvv', 'expirationDate']);
|
||||
this.currentHostedFieldsInstance = null;
|
||||
}
|
||||
|
||||
|
@ -130,7 +131,7 @@ class CreditCardRenderer {
|
|||
return event.fields[key].isValid;
|
||||
});
|
||||
|
||||
const className = this._cardNumberFiledCLassNameByCardType(event.cards[0].type);
|
||||
const className = event.cards.length ? this._cardNumberFiledCLassNameByCardType(event.cards[0].type) : '';
|
||||
event.fields.number.isValid
|
||||
? cardNumber.classList.add(className)
|
||||
: this._recreateElementClassAttribute(cardNumber, cardNumberField.className);
|
||||
|
@ -138,6 +139,12 @@ class CreditCardRenderer {
|
|||
this.formValid = formValid;
|
||||
|
||||
});
|
||||
hostedFields.on('empty', (event) => {
|
||||
this.emptyFields.add(event.emittedBy);
|
||||
});
|
||||
hostedFields.on('notEmpty', (event) => {
|
||||
this.emptyFields.delete(event.emittedBy);
|
||||
});
|
||||
|
||||
show(buttonSelector);
|
||||
|
||||
|
@ -249,7 +256,16 @@ class CreditCardRenderer {
|
|||
});
|
||||
} else {
|
||||
this.spinner.unblock();
|
||||
const message = ! this.cardValid ? this.defaultConfig.hosted_fields.labels.card_not_supported : this.defaultConfig.hosted_fields.labels.fields_not_valid;
|
||||
|
||||
let message = this.defaultConfig.labels.error.generic;
|
||||
if (this.emptyFields.size > 0) {
|
||||
message = this.defaultConfig.hosted_fields.labels.fields_empty;
|
||||
} else if (!this.cardValid) {
|
||||
message = this.defaultConfig.hosted_fields.labels.card_not_supported;
|
||||
} else if (!this.formValid) {
|
||||
message = this.defaultConfig.hosted_fields.labels.fields_not_valid;
|
||||
}
|
||||
|
||||
this.errorHandler.message(message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\Button\Assets;
|
|||
|
||||
use Exception;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use WC_Order;
|
||||
use WC_Product;
|
||||
use WC_Product_Variation;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken;
|
||||
|
@ -806,8 +807,6 @@ class SmartButton implements SmartButtonInterface {
|
|||
* @return array
|
||||
*/
|
||||
public function script_data(): array {
|
||||
global $wp;
|
||||
|
||||
$is_free_trial_cart = $this->is_free_trial_cart();
|
||||
|
||||
$url_params = $this->url_params();
|
||||
|
@ -903,6 +902,10 @@ class SmartButton implements SmartButtonInterface {
|
|||
'credit_card_number' => '',
|
||||
'cvv' => '',
|
||||
'mm_yy' => __( 'MM/YY', 'woocommerce-paypal-payments' ),
|
||||
'fields_empty' => __(
|
||||
'Card payment details are missing. Please fill in all required fields.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'fields_not_valid' => __(
|
||||
'Unfortunately, your credit card details are not valid.',
|
||||
'woocommerce-paypal-payments'
|
||||
|
@ -944,7 +947,7 @@ class SmartButton implements SmartButtonInterface {
|
|||
// phpcs:ignore WordPress.WP.I18n
|
||||
'shipping_field' => _x( 'Shipping %s', 'checkout-validation', 'woocommerce' ),
|
||||
),
|
||||
'order_id' => 'pay-now' === $this->context() ? absint( $wp->query_vars['order-pay'] ) : 0,
|
||||
'order_id' => 'pay-now' === $this->context() ? $this->get_order_pay_id() : 0,
|
||||
'single_product_buttons_enabled' => $this->settings_status->is_smart_button_enabled_for_location( 'product' ),
|
||||
'mini_cart_buttons_enabled' => $this->settings_status->is_smart_button_enabled_for_location( 'mini-cart' ),
|
||||
'basic_checkout_validation_enabled' => $this->basic_checkout_validation_enabled,
|
||||
|
@ -1018,6 +1021,19 @@ class SmartButton implements SmartButtonInterface {
|
|||
$params['buyer-country'] = WC()->customer->get_billing_country();
|
||||
}
|
||||
|
||||
if ( 'pay-now' === $this->context() ) {
|
||||
$wc_order_id = $this->get_order_pay_id();
|
||||
if ( $wc_order_id ) {
|
||||
$wc_order = wc_get_order( $wc_order_id );
|
||||
if ( $wc_order instanceof WC_Order ) {
|
||||
$currency = $wc_order->get_currency();
|
||||
if ( $currency ) {
|
||||
$params['currency'] = $currency;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$disable_funding = $this->settings->has( 'disable_funding' )
|
||||
? $this->settings->get( 'disable_funding' )
|
||||
: array();
|
||||
|
@ -1444,4 +1460,19 @@ class SmartButton implements SmartButtonInterface {
|
|||
|
||||
return $this->context() === 'product' ? $product_intent : $other_context_intent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID of WC order on the order-pay page, or 0.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function get_order_pay_id(): int {
|
||||
global $wp;
|
||||
|
||||
if ( ! isset( $wp->query_vars['order-pay'] ) ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return absint( $wp->query_vars['order-pay'] );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue