🔀 Merge branch 'PCP-3644’

# Conflicts:
#	modules/ppcp-applepay/resources/js/ApplepayButton.js
This commit is contained in:
Philipp Stracker 2024-11-04 17:36:17 +01:00
commit 73cc6b177e
No known key found for this signature in database
16 changed files with 910 additions and 720 deletions

View file

@ -215,45 +215,31 @@ class GooglepayButton extends PaymentButton {
/**
* @inheritDoc
*/
validateConfiguration( silent = false ) {
const validEnvs = [ 'PRODUCTION', 'TEST' ];
registerValidationRules( invalidIf, validIf ) {
invalidIf(
() =>
! [ 'TEST', 'PRODUCTION' ].includes(
this.buttonConfig.environment
),
`Invalid environment: ${ this.buttonConfig.environment }`
);
const isInvalid = ( ...args ) => {
if ( ! silent ) {
this.error( ...args );
}
return false;
};
validIf( () => this.isPreview );
if ( ! validEnvs.includes( this.buttonConfig.environment ) ) {
return isInvalid(
'Invalid environment:',
this.buttonConfig.environment
);
}
invalidIf(
() => ! this.googlePayConfig,
'No API configuration - missing configure() call?'
);
// Preview buttons only need a valid environment.
if ( this.isPreview ) {
return true;
}
invalidIf(
() => ! this.transactionInfo,
'No transactionInfo - missing configure() call?'
);
if ( ! this.googlePayConfig ) {
return isInvalid(
'No API configuration - missing configure() call?'
);
}
if ( ! this.transactionInfo ) {
return isInvalid(
'No transactionInfo - missing configure() call?'
);
}
if ( ! typeof this.contextHandler?.validateContext() ) {
return isInvalid( 'Invalid context handler.', this.contextHandler );
}
return true;
invalidIf(
() => ! this.contextHandler?.validateContext(),
`Invalid context handler.`
);
}
/**