Skip to content

Add Contact #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
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
5 changes: 2 additions & 3 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ on:

jobs:
deploy:

runs-on: ubuntu-latest
runs-on: ubuntu-latest # nosemgrep : semgrep.dev/s/swati31196:github_provided_runner
strategy:
max-parallel: 4
matrix:
Expand All @@ -30,4 +29,4 @@ jobs:
pip install responses
python3 setup.py install
- name: Run Tests
run: python3 -m unittest
run: python3 -m unittest
51 changes: 51 additions & 0 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: SecurityChecks
on:
pull_request: {}
push:
branches: ["master"]
schedule:
- cron: '30 20 * * *'
jobs:
semgrep:
name: Scan
runs-on: [ubuntu-latest] # nosemgrep : semgrep.dev/s/swati31196:github_provided_runner
steps:
- uses: actions/checkout@v2
- uses: returntocorp/semgrep-action@v1
with:
publishToken: ${{ secrets.SEMGREP_APP_TOKEN }}
publishDeployment: 339
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

workflow_status:
runs-on: [ ubuntu-latest ] # nosemgrep : semgrep.dev/s/swati31196:github_provided_runner
name: Update Status Check
needs: [ semgrep ]
if: always()
env:
githubCommit: ${{ github.event.pull_request.head.sha }}
steps:
- name: Set github commit id
run: |
if [ "${{ github.event_name }}" = "push" ] || [ "${{ github.event_name }}" = "schedule" ]; then
echo "githubCommit=${{ github.sha }}" >> $GITHUB_ENV
fi
exit 0
- name: Failed
id: failed
if: (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) && github.ref != 'refs/heads/master'
run: |
echo 'Failing the workflow for github security status check.'
curl -X POST -H "Content-Type: application/json" -H "Authorization: token ${{ github.token }}" \
-d '{ "state" : "failure" , "context" : "github/security-status-check" , "description" : "github/security-status-check", "target_url" : "https://github.com/${{ github.repository }}" }' \
https://api.github.com/repos/${{ github.repository }}/statuses/${{ env.githubCommit }}
exit 1
- name: Success
if: steps.failed.conclusion == 'skipped' || github.ref != 'refs/heads/master'
run: |
echo 'Status check has passed!'
curl -X POST -H "Content-Type: application/json" -H "Authorization: token ${{ github.token }}" \
-d '{ "state" : "success" , "context" : "github/security-status-check" , "description" : "github/security-status-check", "target_url" : "https://github.com/${{ github.repository }}" }' \
https://api.github.com/repos/${{ github.repository }}/statuses/${{ env.githubCommit }}
exit 0
56 changes: 56 additions & 0 deletions documents/contact.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
### Contacts

- Create a contact

```py
DATA={
"name":"Gaurav Kumar",
"email":"[email protected]",
"contact":"9123456789",
"type":"employee",
"reference_id":"Acme Contact ID 12345",
"notes":{
"notes_key_1":"Tea, Earl Grey, Hot",
"notes_key_2":"Tea, Earl Grey… decaf."
}
}
client.contact.create(data=DATA)
```

- Fetch a particular contact by id

```py
client.contact.fetch(contact_id = "<CONTACT_ID>")
```

- Fetch all contacts

```py
client.contact.fetch_all()
```

- Update contact details

```py
DATA={
"name": "Gaurav Kumar",
"email": "[email protected]",
"contact": "9123456789",
"type": "self",
"reference_id": "Acme Contact ID 12345",
"notes": {
"notes_key_1":"Tea, Earl Grey, Hot",
"notes_key_2":"Tea, Earl Grey… decaf."
}
}
client.contact.update(contact_id = "<CONTACT_ID>", data=DATA)
```

- Activate or Deactivate a contact

```py
DATA={
"active": false
}
client.contact.status(contact_id = "<CONTACT_ID>", data=DATA)
```
2 changes: 2 additions & 0 deletions razorpay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from .resources import Item
from .resources import Qrcode
from .resources import FundAccount
from .resources import Contact
from .utility import Utility
from .constants import ERROR_CODE
from .constants import HTTP_STATUS_CODE
Expand All @@ -39,6 +40,7 @@
'RegistrationLink',
'Plan',
'FundAccount',
'Contact',
'Settlement',
'Item',
'Qrcode',
Expand Down
4 changes: 2 additions & 2 deletions razorpay/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def _update_user_agent_header(self, options):

def _get_version(self):
version = ""
try:
try: # nosemgrep : gitlab.bandit.B110
version = pkg_resources.require("razorpay")[0].version
except DistributionNotFound: # pragma: no cover
pass
Expand Down Expand Up @@ -137,7 +137,7 @@ def request(self, method, path, **options):
raise BadRequestError(msg)
elif str.upper(code) == ERROR_CODE.GATEWAY_ERROR:
raise GatewayError(msg)
elif str.upper(code) == ERROR_CODE.SERVER_ERROR:
elif str.upper(code) == ERROR_CODE.SERVER_ERROR: # nosemgrep : python.lang.maintainability.useless-ifelse.useless-if-body
raise ServerError(msg)
else:
raise ServerError(msg)
Expand Down
1 change: 1 addition & 0 deletions razorpay/constants/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ class URL(object):
QRCODE_URL = "/payments/qr_codes"
REGISTRATION_LINK_URL = "/subscription_registration"
FUND_ACCOUNT_URL = "/fund_accounts"
CONTACTS_URL = "/contacts"
4 changes: 3 additions & 1 deletion razorpay/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .settlement import Settlement
from .item import Item
from .fund_account import FundAccount
from .contact import Contact

__all__ = [
'Payment',
Expand All @@ -35,5 +36,6 @@
'Settlement',
'Item',
'QrCode',
'FundAccount'
'FundAccount',
'Contact'
]
59 changes: 59 additions & 0 deletions razorpay/resources/contact.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import warnings

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


class Contact(Resource):
def __init__(self, client=None):
super(Contact, self).__init__(client)
self.base_url = URL.CONTACTS_URL

def create(self, data={}, **kwargs):
""""
Create Contact from given dict

Returns:
Contact Dict which was created
"""
url = self.base_url
return self.post_url(url, data, **kwargs)

def fetch(self, contact_id, data={}, **kwargs):
""""
Fetch Contact for given Id

Args:
contact_id : Id for which contact object has to be retrieved

Returns:
contact dict
"""
return super(Contact, self).fetch(contact_id, data, **kwargs)

def fetch_all(self, data={}, **kwargs): # pragma: no cover
warnings.warn("Will be Deprecated in next release, use all",
DeprecationWarning)
return self.all(data, **kwargs)

def update(self, contact_id, data={}, **kwargs):
""""
Update Contact information from given dict

Returns:
Contact Dict which was edited
"""
url = '{}/{}'.format(self.base_url, contact_id)

return self.patch_url(url, data, **kwargs)

def status(self, contact_id, data={}, **kwargs):
""""
Update the status of Contact from given dict (ACTIVE/INACTIVE)

Returns:
Contact dict which was edited
"""
url = '{}/{}'.format(self.base_url, contact_id)

return self.patch_url(url, data, **kwargs)
4 changes: 2 additions & 2 deletions razorpay/resources/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def fetch(self, payment_id, data={}, **kwargs):
"""
return super(Payment, self).fetch(payment_id, data, **kwargs)

def capture(self, payment_id, amount, data={}, **kwargs):
def capture(self, payment_id, amount, data={}, **kwargs): # nosemgrep : python.lang.correctness.common-mistakes.default-mutable-dict.default-mutable-dict
""""
Capture Payment for given Id

Expand All @@ -49,7 +49,7 @@ def capture(self, payment_id, amount, data={}, **kwargs):
data['amount'] = amount
return self.post_url(url, data, **kwargs)

def refund(self, payment_id, amount, data={}, **kwargs): # pragma: no cover
def refund(self, payment_id, amount, data={}, **kwargs): # pragma: no cover # nosemgrep : python.lang.correctness.common-mistakes.default-mutable-dict.default-mutable-dict
""""
Refund Payment for given Id

Expand Down