PaddleHQ / paddle-python-sdk

Python SDK for working with the Paddle API in server-side apps.
https://developer.paddle.com/
Apache License 2.0
11 stars 2 forks source link

Paddle error is not returned in the exception message #10

Open lmscloud-io opened 1 month ago

lmscloud-io commented 1 month ago

Describe the bug

I created a customer with an address in Spain and did not specify the region in the address.

Then I sent a request:

operation = CreateTransaction(
    customer_id=customer.id,
    address_id=address.id,
    business_id=business.id,
    collection_mode=CollectionMode.Manual,
    items=items,
    billing_details= BillingDetails(
        enable_checkout=False,
        purchase_order_number='',
        additional_information='',
        payment_terms=TimePeriod(interval=Interval.Day, frequency=30)))
paddle.transactions.create(operation)

It fails with an extremely uninformative error 400 Client Error: Bad Request for url: https://sandbox-api.paddle.com/transactions

If I send a request directly:

payload = FiltersUndefined.filter_undefined_values(operation.get_parameters())
url = paddle.transactions.client.options.environment.base_url + "/transactions"
res = paddle.transactions.client.client.request('POST', url, json=payload)

I get a response

{"error":
{"type":"request_error",
"code":"transaction_address_not_suitable_for_collection_mode",
"detail":"Address entity must be suitable for the transactions current collection mode",
"documentation_url":"https://developer.paddle'.com/v1/errors/transactions/transaction_address_not_suitable_for_collection_mode"},
"meta":{"request_id":"d50354fb-62a2-4314-8021-ea23ae83ac01"}}

Needless to say that I just wasted several days trying to figure out what was wrong before I tried to send a request directly to paddle. Extremely disappointed :(

Steps to reproduce

see above

Expected behavior

I would like to see what actually went wrong in the exception message

Code snippets

No response

Python version

3.11

SDK version

1.0.1

API version

1

Additional context

No response

vijayasingam-paddle commented 1 month ago

Hi @lmscloud-io, Thank you for reporting this issue.

I am sorry that are facing this problem. We will look into this issue and get back to you with an update.

Thank you.

lmscloud-io commented 1 month ago

Here is even an easier way to reproduce it

  1. Create a customer
  2. Create an address for this customer
operation = CreateAddress(country_code='US', postal_code='1')
paddle.addresses.create(customer_id, operation)

error message:

Request failed: 400 Client Error: Bad Request for url: https://sandbox-api.paddle.com/customers/ctm_01hzmk2j4rkdfea9qs28w4d10q/addresses

  1. Do the same directly with Paddle API:
payload = FiltersUndefined.filter_undefined_values(operation.get_parameters())
url = paddle.transactions.client.options.environment.base_url + f"/customers/{customer_id}/addresses"
res = paddle.transactions.client.client.request("POST", url, json=payload)

you get a MEANINGFUL response:

{"error":{"type":"request_error","code":"bad_request","detail":"Invalid requ
est","documentation_url":"https://developer.paddle.com/v1/errors/shared/bad_
request","errors":[{"field":"postal_code","message":"US postal_code must be 
5 digits only"}]},"meta":{"request_id":"7117f662-7acb-44d1-8e5a-922e86f33723
"}}
davidgrayston-paddle commented 2 weeks ago

Hi @lmscloud-io

We have released a fix in 0.1.3 https://github.com/PaddleHQ/paddle-python-sdk/pull/11 to raise an ApiError that provides more details with the following properties:

Please note that the string representation of this error will be the detail string, e.g. Invalid request. To get a full representation of the error, you can use repr(e).