Skip to content

Commit

Permalink
Merge pull request #98 from sharhan-alhassan/feat/send-update-subscri…
Browse files Browse the repository at this point in the history
…ption-link

Feat:Subscription --> Email a customer a link for updating the card on their subscription
  • Loading branch information
andela-sjames authored Aug 7, 2024
2 parents dddad42 + 1fcc6a7 commit c5af9d3
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
32 changes: 32 additions & 0 deletions docs/subscription.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,35 @@ response = Subscription.enable(code="SUB_vsyqdmlzble3uii",
*Returns*

JSON data from paystack API.

##### `Subscription.generate_update_subscription_link(subscription_code)` - Generate a link for updating the card on a subscription
```python
from paystackapi.subscription import Subscription
response = Subscription.generate_update_subscription_link(
subscription_code='SUB_vsyqdmlzble3uii'
)
```

*Arguments*
- `subscription_code`: subscription code

*Returns*

JSON data from paystack API.


##### `Subscription.send_update_subscription_link(subscription_code)` - Email a customer a link for updating the card on their subscription

```python
from paystackapi.subscription import Subscription
response = Subscription.send_update_subscription_link(
subscription_code='SUB_vsyqdmlzble3uii'
)
```

*Arguments*
- `subscription_code`: subscription code

*Returns*

JSON data from paystack API.
26 changes: 26 additions & 0 deletions paystackapi/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,29 @@ def fetch(cls, subscription_id):
Json data from paystack API.
"""
return cls().requests.get(f"subscription/{subscription_id}")

@classmethod
def generate_update_subscription_link(cls, subscription_code):
"""
Generate a link for updating the card on a subscription
Args:
subscription_code: subscription code.
Returns:
Json data from paystack API.
"""
return cls().requests.get(f"subscription/{subscription_code}/manage/link")

@classmethod
def send_update_subscription_link(cls, subscription_code):
"""
Email a customer a link for updating the card on their subscription
Args:
subscription_code: subscription code.
Returns:
Json data from paystack API.
"""
return cls().requests.post(f"subscription/{subscription_code}/manage/email")
26 changes: 26 additions & 0 deletions paystackapi/tests/test_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,29 @@ def test_enable(self):

response = Subscription.enable(code="SUB_vsyqdmlzble3uii", token="d7gofp6yppn3qz7")
self.assertEqual(response['status'], True)

@httpretty.activate
def test_generate_update_subscription_link(self):
"""Function defined to test generation of a link for updating the card on a subscription"""
httpretty.register_uri(
httpretty.GET,
self.endpoint_url("/subscription/SUB_vsyqdmlzble3uii/manage/link"),
content_type='text/json',
status=200,
)

response = Subscription.generate_update_subscription_link(subscription_code='SUB_vsyqdmlzble3uii')
self.assertEqual(response['status'], True)

@httpretty.activate
def test_send_update_subscription_link(self):
"""Function defined to test emailing a customer a link for updating the card on their subscription"""
httpretty.register_uri(
httpretty.POST,
self.endpoint_url("/subscription/SUB_vsyqdmlzble3uii/manage/email"),
content_type='text/json',
status=200,
)

response = Subscription.send_update_subscription_link(subscription_code='SUB_vsyqdmlzble3uii')
self.assertEqual(response['status'], True)

0 comments on commit c5af9d3

Please sign in to comment.