Skip to content

Commit 305f731

Browse files
authored
Merge pull request #145 from razorpay/payment_link
add new end point to create paymentlink
2 parents 8482c5c + 80dd879 commit 305f731

File tree

4 files changed

+79
-14
lines changed

4 files changed

+79
-14
lines changed

razorpay/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from .resources import Payment
44
from .resources import Refund
55
from .resources import Invoice
6+
from .resources import PaymentLink
67
from .resources import Customer
78
from .resources import Card
89
from .resources import Token
@@ -22,6 +23,7 @@
2223
'Order',
2324
'Client',
2425
'Invoice',
26+
'PaymentLink',
2527
'Utility',
2628
'Customer',
2729
'Card',

razorpay/constants/url.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ class URL(object):
22
BASE_URL = 'https://api.razorpay.com/v1'
33
ORDER_URL = "/orders"
44
INVOICE_URL = "/invoices"
5+
PAYMENT_LINK_URL = "/payment_links"
56
PAYMENTS_URL = "/payments"
67
REFUNDS_URL = "/refunds"
78
CARD_URL = "/cards"

razorpay/resources/__init__.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from .refund import Refund
33
from .order import Order
44
from .invoice import Invoice
5+
from .payment_link import PaymentLink
56
from .customer import Customer
67
from .card import Card
78
from .token import Token
@@ -12,19 +13,19 @@
1213
from .subscription import Subscription
1314
from .settlement import Settlement
1415

15-
1616
__all__ = [
17-
'Payment',
18-
'Refund',
19-
'Order',
20-
'Invoice',
21-
'Customer',
22-
'Card',
23-
'Token',
24-
'Transfer',
25-
'VirtualAccount',
26-
'Addon',
27-
'Plan',
28-
'Subscription',
29-
'Settlement',
17+
'Payment',
18+
'Refund',
19+
'Order',
20+
'Invoice',
21+
'PaymentLink',
22+
'Customer',
23+
'Card',
24+
'Token',
25+
'Transfer',
26+
'VirtualAccount',
27+
'Addon',
28+
'Plan',
29+
'Subscription',
30+
'Settlement',
3031
]

razorpay/resources/payment_link.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from .base import Resource
2+
from ..constants.url import URL
3+
import warnings
4+
5+
6+
class PaymentLink(Resource):
7+
def __init__(self, client=None):
8+
super(PaymentLink, self).__init__(client)
9+
self.base_url = URL.PAYMENT_LINK_URL
10+
11+
def fetch_all(self, data={}, **kwargs): # pragma: no cover
12+
warnings.warn("Will be Deprecated in next release", DeprecationWarning)
13+
return self.all(data, **kwargs)
14+
15+
def all(self, data={}, **kwargs):
16+
""""
17+
Fetch all Payment link entities
18+
19+
Returns:
20+
Dictionary of Payment link data
21+
"""
22+
return super(PaymentLink, self).all(data, **kwargs)
23+
24+
def fetch(self, payment_link_id, data={}, **kwargs):
25+
""""
26+
Fetch Payment link for given Id
27+
28+
Args:
29+
payment_link_id : Id for which Payment link object has to be retrieved
30+
31+
Returns:
32+
Payment link dict for given payment_link_id Id
33+
"""
34+
return super(PaymentLink, self).fetch(payment_link_id, data, **kwargs)
35+
36+
def create(self, data={}, **kwargs):
37+
""""
38+
Create Payment link from given dict
39+
40+
Args:
41+
data : Dictionary having keys using which Payment link have to be created
42+
43+
Returns:
44+
Payment link Dict which was created
45+
"""
46+
url = self.base_url
47+
return self.post_url(url, data, **kwargs)
48+
49+
def cancel(self, payment_link_id, **kwargs):
50+
""""
51+
Cancel an unpaid Payment link with given ID via API
52+
It can only be called on an Payment link that is not in the paid state.
53+
54+
Args:
55+
payment_link_id : Id for cancel the Payment link
56+
Returns:
57+
The response for the API will be the Payment link entity, similar to create/update API response, with status attribute's value as cancelled
58+
"""
59+
url = "{}/{}/cancel".format(self.base_url, payment_link_id)
60+
return self.post_url(url, {}, **kwargs)
61+

0 commit comments

Comments
 (0)