woocommerce / woocommerce-blocks

(Deprecated) This plugin has been merged into woocommerce/woocommerce
https://wordpress.org/plugins/woo-gutenberg-products-block/
GNU General Public License v3.0
405 stars 218 forks source link

Payment documentation shouldn't suggest deprecated `onPaymentProcessing` and `shippingData` `billingData` #10690

Closed Sidsector9 closed 1 year ago

Sidsector9 commented 1 year ago

Describe the bug

I am implementing an express payment method (digital wallet) where the shipping address needs to be set from the info returned by the wallet.

Setting billingData works but shippingAddress does not work. This causes the woocommerce_rest_invalid_address error and the only way to resolve this is to set the shipping address fields in the Block Checkout form.

May be related to issue woocommerce/woocommerce-blocks#8785

To reproduce

Steps to reproduce the behavior:

Return shipping address in the observer foronPaymentProcessing() in the following format:

onPaymentProcessing( () => {
    //
    // some logic...
    //
    const response = {
        meta: {
            paymentMethodData: {
                key1: 'value1',
                key2: 'value2',
            }
        },
        billingData: {
            email: 'user@example.com',
            first_name: 'John',
            last_name: 'Doe',
            company: 'Billing, INC.',
            address_1: 'Billing Apt.',
            address_2: '',
            city: 'LA',
            state: 'CA',
            postcode: '90001',
            country: 'US',
            phone: '8888899999',
        },
        shippingAddress: {
            first_name: 'Emily',
            last_name: 'Dawson',
            company: 'Shipping, INC.',
            address_1: 'Shipping Apt.',
            address_2: '',
            city: 'LA',
            state: 'NY',
            postcode: '10001',
            country: 'US',
        },
    };
    return response;
} );

So far, I have also tried the older response shapes for shipping data:

const response = {
    meta: {
        paymentMethodData: {}
    },
    billingData: {},
    shippingData: {},
};

and

const response = {
    meta: {
        paymentMethodData: {}
    },
    billingData: {},
    shippingData: {
        address: {}
    },
};

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

Environment

WordPress (please complete the following information):

Additional context

Add any other context about the problem here.

senadir commented 1 year ago

First of all onPaymentProcessing is deprecated, you should use onPaymentSetup instead.

Using billingData and shippingData is also depricated, and you should use billingAddress and shippingAddress.

As for your problem, validation seems to fail silently for you, but your shipping address is failing at isShippingAddress because it's missing the phone attribute.

You should pass it even if it's empty

'first_name',
'last_name',
'company',
'address_1',
'address_2',
'city',
'state',
'postcode',
'country',
'phone',

We can probably make this check more vocal.

Sidsector9 commented 1 year ago

Thanks @senadir that worked.

I referred to these documentation pages:

Please correct me if I am referring to an outdated documentation. If not, I wish to contribute to the Wiki pages.

senadir commented 1 year ago

Those tutorials are outdated indeed, sorry for that! I will rename this issue to address that.

ralucaStan commented 1 year ago

Added this to https://github.com/woocommerce/woocommerce/issues/42264; cc @opr