-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: handle paypal payment recipt handle PayPal payment receipt URL SONIC-784 * feat: add auto refund feature for paypal * feat: working code * fix: fix test * fix: fix test * fix: linting errors * fix: linting errors * fix: fixed requirement files errors * fix: fixed tests * fix: fixed tests * fix: update payment object mock --------- Co-authored-by: Syed Sajjad Hussain Shah <[email protected]> Co-authored-by: Shafqat Farhan <[email protected]>
- Loading branch information
1 parent
9242856
commit e48d83f
Showing
20 changed files
with
417 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"""PayPal client""" | ||
import json | ||
|
||
from django.conf import settings | ||
from paypalserversdk.api_helper import ApiHelper | ||
from paypalserversdk.controllers.payments_controller import PaymentsController | ||
from paypalserversdk.http.auth.o_auth_2 import ClientCredentialsAuthCredentials | ||
from paypalserversdk.paypalserversdk_client import PaypalserversdkClient | ||
|
||
|
||
class PayPalClient: | ||
""" | ||
PayPal SDK client to call PayPal APIs. | ||
""" | ||
def __init__(self): | ||
self.paypal_client: PaypalserversdkClient = PaypalserversdkClient( | ||
client_credentials_auth_credentials=ClientCredentialsAuthCredentials( | ||
o_auth_client_id=settings.PAYMENT_PROCESSOR_CONFIG['edx']['paypal']['client_id'], | ||
o_auth_client_secret=settings.PAYMENT_PROCESSOR_CONFIG['edx']['paypal']['client_secret'], | ||
), | ||
) | ||
|
||
def refund_order(self, capture_id): | ||
""" | ||
Capture PayPal refund. | ||
Args: | ||
capture_id (str): The identifier of the PayPal order to capture refund. | ||
Returns: | ||
The response from PayPal. | ||
""" | ||
|
||
paypal_client = self.paypal_client | ||
payments_controller: PaymentsController = paypal_client.payments | ||
|
||
collect = {"capture_id": capture_id, "prefer": "return=representation"} | ||
refund_response = payments_controller.captures_refund(collect) | ||
|
||
if refund_response.body: | ||
response = json.loads(ApiHelper.json_serialize(refund_response.body)) | ||
return { | ||
"id": response.get("id"), | ||
"created": response.get("create_time"), | ||
"status": response.get("status"), | ||
"amount": response.get("amount").get("value"), | ||
"currency": response.get("amount").get("currency_code"), | ||
} | ||
|
||
return None |
Oops, something went wrong.