sp-api-sdk icon indicating copy to clipboard operation
sp-api-sdk copied to clipboard

FeeEstimateByIdRequest expects id_type to be of type IdType, IdType always returns string

Open PaulFerreira-BHO opened this issue 1 year ago • 0 comments

I've been working with the getMyFeesEstimate function and have been receiving a type error for the id_type parameter. My request looks like:

$body1 =
new FeesEstimateByIdRequest([
        'fees_estimate_request' => new FeesEstimateRequest([
            "marketplace_id" => Marketplace::US()->id(),
            "is_amazon_fulfilled" => false,
            "price_to_estimate_fees" => new PriceToEstimateFees([
                'listing_price' => new MoneyType([
                    "currency_code" => "USD",
                    "amount" => 559
                ])
            ]),
            'identifier' => uniqid("TR-", true)
        ]),
        'id_type' => IdType::ASIN,
        'id_value' => 'B09CXSW9XL'
    ]);

When run, I receive the error:

PHP Fatal error: Uncaught TypeError: AmazonPHP\SellingPartner\Model\ProductFees\FeesEstimateByIdRequest::getIdType(): Return value must be of type AmazonPHP\SellingPartner\Model\ProductFees\IdType, string returned in \vendor\amazon-php\sp-api-sdk\src\AmazonPHP\SellingPartner\Model\ProductFees\FeesEstimateByIdRequest.php:222

The issue is that IdType has no constructor nor getter/setter functions so the only way to use it correctly is to statically refer to the the ASIN enum via IdType::ASIN. This will always return a string however, thus meaning it's impossible to correctly call this function.

I corrected it by editing the getIdType and setIdType functions in FeeEstimateByIdRequest.php to:

    public function getIdType() : string
    {
        return $this->container['id_type'];
    }

    public function setIdType(string $id_type) : self
    {
        $this->container['id_type'] = $id_type;

        return $this;
    }

PaulFerreira-BHO avatar Mar 09 '24 19:03 PaulFerreira-BHO