amazon-php / sp-api-sdk

Amazon Selling Partner SPI - PHP SDKs
129 stars 52 forks source link

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

Closed PaulFerreira-BHO closed 2 months ago

PaulFerreira-BHO commented 6 months ago

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;
    }
jasonhebert commented 2 months ago

The IdType should be initialized as such: 'id_type' => new IdType(IdType::ASIN),