Skip to content

PaypalProvider: allow to make also get requests#439

Open
PetrDlouhy wants to merge 4 commits intojazzband:mainfrom
PetrDlouhy:pr/paypal_get
Open

PaypalProvider: allow to make also get requests#439
PetrDlouhy wants to merge 4 commits intojazzband:mainfrom
PetrDlouhy:pr/paypal_get

Conversation

@PetrDlouhy
Copy link
Copy Markdown
Contributor

PaypalProvider: Add also get() method to be able to use the provider to create also GET request to PayPal API.

Copy link
Copy Markdown
Member

@WhyNotHugo WhyNotHugo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, only one minor detail.

def post(self, payment, *args, **kwargs):
return self.http_request(payment, *args, http_method=requests.post, **kwargs)

def get(self, payment, *args, **kwargs):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a short docstring for this, so folks can find it and use it.

@WhyNotHugo
Copy link
Copy Markdown
Member

CI is now green, so rebasing.

Add get() method to complement the existing post() method, and refactor
to support making API requests that are not tied to a specific payment
instance.

Changes:
- Add http_request() helper method that accepts http_method parameter
- Refactor post() to use http_request() with requests.post
- Add new get() method that uses http_request() with requests.get
- Update http_request() to handle payment=None by skipping payment-specific
  operations (set_error_data, change_status, set_response_data)
- Update get_access_token() to handle payment=None for token caching
- Add comprehensive docstrings to both get() and post() methods

This enables making GET requests to PayPal API and allows use cases where
API calls are not associated with a payment (e.g., fetching account info,
checking subscription status).
Add comprehensive test to verify that get() method works correctly when
called with payment=None, which is needed for API calls not tied to a
specific payment instance.

The test verifies:
- OAuth token acquisition happens correctly
- GET request is made with proper headers
- Response data is returned correctly
Fix critical bug where @authorize decorator would crash on 401 errors when
payment=None, preventing proper token refresh for API calls not tied to a
payment instance.

Changes:
- Add payment=None check in @authorize decorator before accessing payment attrs
- Extract expires_in variable to fix line length linting error (line 198)
- Add test for 401 error handling with payment=None

This enables reliable use of get()/post() with payment=None for operations
like subscription management that don't have an associated Payment instance.
@PetrDlouhy PetrDlouhy force-pushed the pr/paypal_get branch 4 times, most recently from 9cca3b7 to fefb798 Compare December 18, 2025 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants