mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Show notice if validation fails
This commit is contained in:
parent
22809839d1
commit
f227713f6c
4 changed files with 42 additions and 25 deletions
|
@ -43,15 +43,8 @@ class ApplepayButton {
|
|||
this.onButtonClick()
|
||||
})
|
||||
}
|
||||
jQuery.ajax({
|
||||
url: this.buttonConfig.ajax_url,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'ppcp_validate',
|
||||
validation: true,
|
||||
nonce: this.nonce,
|
||||
}
|
||||
})
|
||||
console.log('[ApplePayButton] init done', this.buttonConfig.ajax_url);
|
||||
|
||||
}
|
||||
|
||||
buildReadyToPayRequest(allowedPaymentMethods, baseRequest) {
|
||||
|
@ -182,7 +175,15 @@ class ApplepayButton {
|
|||
.then(validateResult => {
|
||||
session.completeMerchantValidation(validateResult.merchantSession);
|
||||
//call backend to update validation to true
|
||||
|
||||
jQuery.ajax({
|
||||
url: this.buttonConfig.ajax_url,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'ppcp_validate',
|
||||
validation: true,
|
||||
'woocommerce-process-checkout-nonce': this.nonce,
|
||||
}
|
||||
})
|
||||
console.log('validated')
|
||||
})
|
||||
.catch(validateError => {
|
||||
|
@ -194,7 +195,7 @@ class ApplepayButton {
|
|||
data: {
|
||||
action: 'ppcp_validate',
|
||||
validation: false,
|
||||
nonce: this.nonce,
|
||||
'woocommerce-process-checkout-nonce': this.nonce,
|
||||
}
|
||||
})
|
||||
session.abort();
|
||||
|
|
|
@ -37,16 +37,6 @@ return array(
|
|||
'applepay.server_supported' => static function ( ContainerInterface $container ): bool {
|
||||
return ! empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] !== 'off';
|
||||
},
|
||||
'applepay.merchant_validated' => static function ( ContainerInterface $container ): bool {
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
assert( $settings instanceof Settings );
|
||||
try {
|
||||
$settings->get( 'applepay_validated' );
|
||||
} catch ( \Exception $e ) {
|
||||
return false;
|
||||
}
|
||||
return $settings->get( 'applepay_validated' ) === true;
|
||||
},
|
||||
'applepay.url' => static function ( ContainerInterface $container ): string {
|
||||
$path = realpath( __FILE__ );
|
||||
if ( false === $path ) {
|
||||
|
|
|
@ -47,7 +47,7 @@ class ApplepayModule implements ModuleInterface {
|
|||
'admin_notices',
|
||||
static function () {
|
||||
?>
|
||||
<div class="notice notice-error">
|
||||
<div class="notice notice-error is-dismissible">
|
||||
<p>
|
||||
<?php
|
||||
echo wp_kses_post(
|
||||
|
@ -62,12 +62,14 @@ class ApplepayModule implements ModuleInterface {
|
|||
|
||||
return;
|
||||
}
|
||||
if ( ! $c->get( 'applepay.merchant_validated' ) ) {
|
||||
$settings = $c->get( 'wcgateway.settings' );
|
||||
$merchant_validated = $settings->has( 'applepay_validated' ) ? $settings->get( 'applepay_validated' ) === true : false;
|
||||
if ( ! $merchant_validated ) {
|
||||
add_action(
|
||||
'admin_notices',
|
||||
static function () {
|
||||
?>
|
||||
<div class="notice notice-error">
|
||||
<div class="notice notice-error is-dismissible">
|
||||
<p>
|
||||
<?php
|
||||
echo wp_kses_post(
|
||||
|
@ -83,7 +85,7 @@ class ApplepayModule implements ModuleInterface {
|
|||
$this->load_assets( $c );
|
||||
$this->handle_validation_file($c);
|
||||
$this->render_buttons( $c );
|
||||
|
||||
assert( $apple_payment_method instanceof ButtonInterface );
|
||||
$apple_payment_method->bootstrap_ajax_request();
|
||||
/*add_action(
|
||||
'woocommerce_blocks_payment_method_type_registration',
|
||||
|
|
|
@ -85,6 +85,12 @@ class ApplePayDataObjectHttp {
|
|||
* @var Logger
|
||||
*/
|
||||
protected $logger;
|
||||
/**
|
||||
* The validation flag.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $validation_flag = false;
|
||||
|
||||
/**
|
||||
* ApplePayDataObjectHttp constructor.
|
||||
|
@ -119,6 +125,14 @@ class ApplePayDataObjectHttp {
|
|||
return $this->errors;
|
||||
}
|
||||
|
||||
public function validation_data() {
|
||||
$data = filter_input( INPUT_POST, 'validation', FILTER_VALIDATE_BOOL );
|
||||
if ( ! $data ) {
|
||||
return;
|
||||
}
|
||||
$this->validation_flag = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the object with the data relevant to ApplePay on update shipping contact
|
||||
* Required data depends on callerPage
|
||||
|
@ -512,6 +526,16 @@ class ApplePayDataObjectHttp {
|
|||
return $this->simplified_contact;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the validated flag.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validated_flag()
|
||||
{
|
||||
return $this->validation_flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filtered request data.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue