Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 64 additions & 37 deletions razorpay/resources/payment_link.py
Original file line number Diff line number Diff line change
@@ -1,89 +1,116 @@
import warnings
from typing import Dict, Any, Union, Optional

from .base import Resource
from ..constants.url import URL
import warnings


class PaymentLink(Resource):
def __init__(self, client=None):
super(PaymentLink, self).__init__(client)
self.base_url = URL.V1 + URL.PAYMENT_LINK_URL

def fetch_all(self, data={}, **kwargs): # pragma: no cover
def fetch_all(self, data: Optional[Dict[str, Any]] = None, **kwargs) -> Dict[str, Any]: # pragma: no cover
"""
Fetch all Payment Link entities (Deprecated)
"""
warnings.warn("Will be Deprecated in next release", DeprecationWarning)
return self.all(data, **kwargs)

def all(self, data={}, **kwargs):
def all(self, data: Optional[Dict[str, Any]] = None, **kwargs) -> Dict[str, Any]:
"""
Fetch all Payment link entities
Fetch all Payment Link entities

Args:
data: Dictionary of filters

Returns:
Dictionary of Payment link data
Dictionary of Payment Link data
"""
return super(PaymentLink, self).all(data, **kwargs)

def fetch(self, payment_link_id, data={}, **kwargs):
def fetch(self, payment_link_id: str, data: Optional[Dict[str, Any]] = None, **kwargs) -> Dict[str, Any]:
"""
Fetch Payment link for given Id
Fetch Payment Link for given ID

Args:
payment_link_id : Id for which Payment link object has to be retrieved
payment_link_id : Unique identifier for the Payment Link

Returns:
Payment link dict for given payment_link_id Id
Payment Link dictionary
"""
return super(PaymentLink, self).fetch(payment_link_id, data, **kwargs)

def create(self, data={}, **kwargs):
def create(self, data: Dict[str, Any], **kwargs) -> Dict[str, Any]:
"""
Create Payment link from given dict
Create Payment Link from given dict

Args:
data : Dictionary having keys using which Payment link have to be created
data : Dictionary containing Payment Link details

Returns:
Payment link Dict which was created
Payment Link Dict which was created

"""
# Fix for Issue #321: Intercept and fix "string boolean" mistakes
# If user passes "true"/"false" strings, convert them to 1/0 integers
if 'options' in data:
checkout = data['options'].get('checkout', {})
if 'method' in checkout:
for key, value in checkout['method'].items():
if isinstance(value, str):
if value.lower() == 'true':
checkout['method'][key] = 1
elif value.lower() == 'false':
checkout['method'][key] = 0

url = self.base_url
return self.post_url(url, data, **kwargs)

def cancel(self, payment_link_id, **kwargs):
def cancel(self, payment_link_id: str, **kwargs) -> Dict[str, Any]:
"""
Cancel an unpaid Payment link with given ID via API
It can only be called on an Payment link that is not in the paid state.
Cancel an unpaid Payment Link with given ID via API.
It can only be called on a Payment Link that is not in the paid state.

Args:
payment_link_id : Id for cancel the Payment link
payment_link_id : Unique identifier for the Payment Link

Returns:
The response for the API will be the Payment link entity, similar to create/update API response, with status attribute's value as cancelled
Payment Link entity with status attribute as 'cancelled'
"""
url = "{}/{}/cancel".format(self.base_url, payment_link_id)
url = f"{self.base_url}/{payment_link_id}/cancel"
return self.post_url(url, {}, **kwargs)
def edit(self, payment_link_id, data={}, **kwargs):

def edit(self, payment_link_id: str, data: Optional[Dict[str, Any]] = None, **kwargs) -> Dict[str, Any]:
"""
Edit the Payment link
Args:
data : Dictionary having keys using which order have to be edited
reference_id : Adds a unique reference number to an existing link.
Edit the Payment Link

expire_by : Timestamp, in Unix format, when the payment links should expire.
Args:
payment_link_id: Unique identifier for the Payment Link
data : Dictionary having keys to update:
- reference_id : Adds a unique reference number
- expire_by : Timestamp (Unix) when the link should expire
- notes : Key-value pair as notes

notes : key value pair as notes

Returns:
Returns:
Payment Link Dict which was edited
"""
url = '{}/{}'.format(self.base_url, payment_link_id)
url = f"{self.base_url}/{payment_link_id}"
return self.patch_url(url, data, **kwargs)

def notifyBy(self, payment_link_id, medium, **kwargs):
def notifyBy(self, payment_link_id: str, medium: str, **kwargs) -> Dict[str, Any]:
"""
Send notification
Send notification for the Payment Link

Args:
payment_link_id : Unique identifier of the Payment Link that should be resent.

medium : sms/email
payment_link_id : Unique identifier of the Payment Link
medium : The medium to send notification (sms/email)

Returns:
API response dictionary
"""
url = "{}/{}/notify_by/{}".format(self.base_url, payment_link_id, medium)
return self.post_url(url, {}, **kwargs)
url = f"{self.base_url}/{payment_link_id}/notify_by/{medium}"
return self.post_url(url, {}, **kwargs)

# Alias to fix camelCase naming violation (PEP 8)
notify_by = notifyBy
7 changes: 5 additions & 2 deletions razorpay/resources/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def edit(self, subscription_id, data={}, **kwargs):
Update particular subscription

Args:
subscription_id : Id for which subscription has to be edited
subscription_id : Id for which subscription has to be edited
Returns:
Subscription dict for given subscription id
"""
Expand Down Expand Up @@ -143,4 +143,7 @@ def delete_offer(self, subscription_id, offer_id, data={}, **kwargs):
Subscription Dict for given subscription id
"""
url = "{}/{}/{}".format(self.base_url, subscription_id, offer_id)
return self.delete_url(url, data, **kwargs)
return self.delete_url(url, data, **kwargs)

# Alias update to edit to match documentation (Fixes Issue #282)
update = edit