Fixes AXO module.

This commit is contained in:
Pedro Silva 2024-04-11 12:03:31 +01:00
parent 995621ba21
commit 2f1c36af40
No known key found for this signature in database
GPG key ID: E2EE20C0669D24B3
7 changed files with 55 additions and 22 deletions

View file

@ -587,9 +587,6 @@ class AxoManager {
cardComponentData() {
return {
fields: {
phoneNumber: {
prefill: this.billingView.inputValue('phone')
},
cardholderName: {} // optionally pass this to show the card holder name
}
}

View file

@ -22,6 +22,10 @@ class FormFieldGroup {
return '';
}
if (typeof this.fields[fieldKey].valueCallback === 'function') {
return this.fields[fieldKey].valueCallback(this.data);
}
const path = this.fields[fieldKey].valuePath;
if (!path) {
@ -64,7 +68,7 @@ class FormFieldGroup {
Object.keys(this.fields).forEach((key) => {
const field = this.fields[key];
if (this.active) {
if (this.active && !field.showInput) {
this.hideField(field.selector);
} else {
this.showField(field.selector);
@ -106,6 +110,7 @@ class FormFieldGroup {
}
inputElement(name) {
console.log('inputElement', name);
const baseSelector = this.fields[name].selector;
const select = document.querySelector(baseSelector + ' select');

View file

@ -14,6 +14,11 @@ class BillingView {
return '';
}
const selectElement = document.querySelector(selectSelector);
if (!selectElement) {
return ${key};
}
const option = selectElement.querySelector(`option[value="${key}"]`);
return option ? option.textContent : key;
}
@ -37,7 +42,6 @@ class BillingView {
<div>${data.value('postCode')} ${data.value('city')}</div>
<div>${valueOfSelect('#billing_state', data.value('stateCode'))}</div>
<div>${valueOfSelect('#billing_country', data.value('countryCode'))}</div>
<div>${data.value('phone')}</div>
</div>
`;
},
@ -80,11 +84,7 @@ class BillingView {
company: {
'selector': '#billing_company_field',
'valuePath': null,
},
// phone: {
// 'selector': '#billing_phone_field',
// 'valuePath': null,
// },
}
}
});
}

View file

@ -14,6 +14,11 @@ class ShippingView {
return '';
}
const selectElement = document.querySelector(selectSelector);
if (!selectElement) {
return ${key};
}
const option = selectElement.querySelector(`option[value="${key}"]`);
return option ? option.textContent : key;
}
@ -36,6 +41,7 @@ class ShippingView {
<div>${data.value('postCode')} ${data.value('city')}</div>
<div>${valueOfSelect('#shipping_state', data.value('stateCode'))}</div>
<div>${valueOfSelect('#shipping_country', data.value('countryCode'))}</div>
<div>${data.value('phone')}</div>
</div>
`;
},
@ -80,6 +86,20 @@ class ShippingView {
shipDifferentAddress: {
'selector': '#ship-to-different-address',
'valuePath': null,
},
phone: {
'selector': '#billing_phone_field', // There is no shipping phone field.
'valueCallback': function (data) {
let phone = '';
const cc = data?.shipping?.phoneNumber?.countryCode;
const number = data?.shipping?.phoneNumber?.nationalNumber;
if (cc) {
phone = `+${cc} `;
}
phone += number;
return phone;
}
}
}
});

View file

@ -21,7 +21,7 @@ return array(
$apm_applies = $container->get( 'axo.helpers.apm-applies' );
assert( $apm_applies instanceof ApmApplies );
return $apm_applies->for_country_currency();
return $apm_applies->for_country_currency() && $apm_applies->for_settings();
},
'axo.helpers.apm-applies' => static function ( ContainerInterface $container ) : ApmApplies {

View file

@ -35,24 +35,21 @@ class AxoModule implements ModuleInterface {
* {@inheritDoc}
*/
public function run( ContainerInterface $c ): void {
add_filter(
'woocommerce_payment_gateways',
function ( $methods ) use ( $c ): array {
$gateway = $c->get( 'axo.gateway' );
// Add the gateway in admin area.
if ( is_admin() ) {
$methods[] = $gateway;
return $methods;
}
// Check if the module is applicable, correct country, currency, ... etc.
if ( ! $c->get( 'axo.eligible' ) ) {
return $methods;
}
// TODO: check product status eligibility.
// Add the gateway in admin area.
if ( is_admin() ) {
$methods[] = $gateway;
return $methods;
}
if ( is_user_logged_in() ) {
return $methods;

View file

@ -16,7 +16,7 @@ namespace WooCommerce\PayPalCommerce\Axo\Helper;
class ApmApplies {
/**
* The matrix which countries and currency combinations can be used for GooglePay.
* The matrix which countries and currency combinations can be used for AXO.
*
* @var array
*/
@ -39,7 +39,7 @@ class ApmApplies {
/**
* DccApplies constructor.
*
* @param array $allowed_country_currency_matrix The matrix which countries and currency combinations can be used for GooglePay.
* @param array $allowed_country_currency_matrix The matrix which countries and currency combinations can be used for AXO.
* @param string $currency 3-letter currency code of the shop.
* @param string $country 2-letter country code of the shop.
*/
@ -54,7 +54,7 @@ class ApmApplies {
}
/**
* Returns whether GooglePay can be used in the current country and the current currency used.
* Returns whether AXO can be used in the current country and the current currency used.
*
* @return bool
*/
@ -65,4 +65,18 @@ class ApmApplies {
return in_array( $this->currency, $this->allowed_country_currency_matrix[ $this->country ], true );
}
/**
* Returns whether the settings are compatible with AXO.
*
* @return bool
*/
public function for_settings(): bool {
if ( get_option('woocommerce_ship_to_destination') === 'billing_only' ) { // Force shipping to the customer billing address
return false;
}
return true;
}
}