Freemius / freemius-php-sdk

https://freemius.com
22 stars 13 forks source link

Calls to Pricing API with a PUT request fail the the optional "licenses" argument is not specified #15

Open daigo75 opened 3 years ago

daigo75 commented 3 years ago

The documentation (https://freemius.docs.apiary.io/#reference/pricing/plans-pricing/update-pricing) indicates the following:

Request Body JSON Data Key Required Description
monthly_price No  
annual_price No  
lifetime_price No  
licenses No The number of license activation supported by the license. E.g. when the value is 1, the premium license can only be activated on single site.

Based on the above, I made a call as follows:

Expected result: the annual price for pricing 789 would be changed to 10. Actual result:

 'error' =>
    object(stdClass)[4452]
      public 'type' => string 'ObjectExist' (length=11)
      public 'message' => string 'There's already another pricing configured for  installs license.' (length=65)
      public 'code' => string 'pricing_exist' (length=13)
      public 'http' => int 401

Notice that the message says "There's already another pricing configured for installs license". There are two spaces between "for" and "installs", which leads me to think that the response was generated by a sprintf() call which tried to embed the "licenses" argument (not passed with the call) into the message.

Hypothesis about the cause, and possible solution

The "PUT" call should update the attributes of the pricing, based on the ID. It should not try to create another pricing. My speculation is that the "licenses" argument is being used to identify the pricing together with the ID. That could make sense with a POST call, to avoid creating a duplicate pricing, but the PUT call should only use the pricing ID, as it's unique.