Fix lint and tests

This commit is contained in:
Pedro Silva 2023-10-26 10:58:05 +01:00
parent 889df4d88c
commit 46b47dc97b
No known key found for this signature in database
GPG key ID: E2EE20C0669D24B3
8 changed files with 181 additions and 164 deletions

View file

@ -109,7 +109,7 @@ return array(
$container->get( 'applepay.data_to_scripts' ),
$container->get( 'wcgateway.settings.status' ),
$container->get( 'button.helper.cart-products' )
);
);
},
'applepay.blocks-payment-method' => static function ( ContainerInterface $container ): PaymentMethodTypeInterface {
return new BlocksPaymentMethod(

View file

@ -40,6 +40,7 @@ class ApplepayModule implements ModuleInterface {
* {@inheritDoc}
*/
public function run( ContainerInterface $c ): void {
$module = $this;
// Clears product status when appropriate.
add_action(
@ -51,38 +52,44 @@ class ApplepayModule implements ModuleInterface {
}
);
// Check if the module is applicable, correct country, currency, ... etc.
if ( ! $c->get( 'applepay.eligible' ) ) {
return;
}
add_action(
'init',
static function () use ( $c, $module ) {
// Load the button handler.
$apple_payment_method = $c->get( 'applepay.button' );
// add onboarding and referrals hooks.
assert( $apple_payment_method instanceof ApplepayButton );
$apple_payment_method->initialize();
// Check if the module is applicable, correct country, currency, ... etc.
if ( ! $c->get( 'applepay.eligible' ) ) {
return;
}
// Show notice if there are product availability issues.
$availability_notice = $c->get( 'applepay.availability_notice' );
assert( $availability_notice instanceof AvailabilityNotice );
$availability_notice->execute();
// Load the button handler.
$apple_payment_method = $c->get( 'applepay.button' );
// add onboarding and referrals hooks.
assert( $apple_payment_method instanceof ApplepayButton );
$apple_payment_method->initialize();
// Return if server not supported.
if ( ! $c->get( 'applepay.server_supported' ) ) {
return;
}
// Show notice if there are product availability issues.
$availability_notice = $c->get( 'applepay.availability_notice' );
assert( $availability_notice instanceof AvailabilityNotice );
$availability_notice->execute();
// Check if this merchant can activate / use the buttons.
// We allow non referral merchants as they can potentially still use ApplePay, we just have no way of checking the capability.
if ( ( ! $c->get( 'applepay.available' ) ) && $c->get( 'applepay.is_referral' ) ) {
return;
}
// Return if server not supported.
if ( ! $c->get( 'applepay.server_supported' ) ) {
return;
}
$this->load_assets( $c, $apple_payment_method );
$this->handle_validation_file( $c );
$this->render_buttons( $c, $apple_payment_method );
// Check if this merchant can activate / use the buttons.
// We allow non referral merchants as they can potentially still use ApplePay, we just have no way of checking the capability.
if ( ( ! $c->get( 'applepay.available' ) ) && $c->get( 'applepay.is_referral' ) ) {
return;
}
$apple_payment_method->bootstrap_ajax_request();
$module->load_assets( $c, $apple_payment_method );
$module->handle_validation_file( $c );
$module->render_buttons( $c, $apple_payment_method );
$apple_payment_method->bootstrap_ajax_request();
}
);
}
/**

View file

@ -62,21 +62,21 @@ class ApplePayDataObjectHttp {
/**
* The product variations.
*
* @var string
* @var array
*/
protected $product_variations = array();
/**
* The product extra.
*
* @var string
* @var array
*/
protected $product_extra = array();
/**
* The product booking.
*
* @var string
* @var array
*/
protected $product_booking = array();
@ -295,7 +295,7 @@ class ApplePayDataObjectHttp {
/**
* Pre-processes request data to transform it to a standard format.
*
* @param array $data
* @param array $data The data.
* @return array
*/
protected function preprocess_request_data( array $data ): array {
@ -602,7 +602,7 @@ class ApplePayDataObjectHttp {
/**
* Returns the product variations.
*
* @return string
* @return array
*/
public function product_variations(): array {
return $this->product_variations;
@ -611,7 +611,7 @@ class ApplePayDataObjectHttp {
/**
* Returns the product extra.
*
* @return string
* @return array
*/
public function product_extra(): array {
return $this->product_extra;
@ -620,7 +620,7 @@ class ApplePayDataObjectHttp {
/**
* Returns the product booking.
*
* @return string
* @return array
*/
public function product_booking(): array {
return $this->product_booking;
@ -698,6 +698,10 @@ class ApplePayDataObjectHttp {
)
);
if ( ! $data ) {
return false;
}
return $this->append_products_to_data( $data, $_POST );
}