Skip to content

Exception when process checkout through API without passing an address #12

@emastyle

Description

@emastyle

When try to process an order via API during checkout, if no address is set an exception error occurred:

PHP message: PHP Fatal error: Uncaught TypeError: Argument 4 passed to Experius\ExtraCheckoutAddressFields\Plugin\Magento\Checkout\Model\PaymentInformationManagement::beforeSavePaymentInformation() must implement interface Magento\Quote\Api\Data\AddressInterface, null given ...

This happen because no default null value is set of fourth parameter, and also check if address is null.

The code method beforeSavePaymentInformation in Experius\ExtraCheckoutAddressFields\Plugin\Magento\Checkout\Model\PaymentInformationManagement should be modified as:

public function beforeSavePaymentInformation(
        \Magento\Checkout\Model\PaymentInformationManagement $subject,
        $cartId,
        \Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
        \Magento\Quote\Api\Data\AddressInterface $address = null
    ) {
        
if (is_null($address))
            return;
        $extAttributes = $address->getExtensionAttributes();
        if (!empty($extAttributes)) {
            $this->helper->transportFieldsFromExtensionAttributesToObject(
                $extAttributes,
                $address,
                'extra_checkout_billing_address_fields'
            );
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions