Skip to content

Commit

Permalink
Added dispute api (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitdas13 authored Mar 19, 2024
1 parent 3320a23 commit ec997c6
Show file tree
Hide file tree
Showing 10 changed files with 555 additions and 2 deletions.
286 changes: 286 additions & 0 deletions documents/dispute.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
## Document

### Fetch All Disputes

```py
client.dispute.all()
```

**Response:**
```json
{
"entity": "collection",
"count": 1,
"items": [
{
"id": "disp_Esz7KAitoYM7PJ",
"entity": "dispute",
"payment_id": "pay_EsyWjHrfzb59eR",
"amount": 10000,
"currency": "INR",
"amount_deducted": 0,
"reason_code": "pre_arbitration",
"respond_by": 1590604200,
"status": "open",
"phase": "pre_arbitration",
"created_at": 1590059211,
"evidence": {
"amount": 10000,
"summary": null,
"shipping_proof": null,
"billing_proof": null,
"cancellation_proof": null,
"customer_communication": null,
"proof_of_service": null,
"explanation_letter": null,
"refund_confirmation": null,
"access_activity_log": null,
"refund_cancellation_policy": null,
"term_and_conditions": null,
"others": null,
"submitted_at": null
}
}
]
}
```
-------------------------------------------------------------------------------------------------------

### Fetch a Dispute

```py
disputeId = "disp_0000000000000";

client.dispute.fetch(disputeId);
```

**Parameters:**

| Name | Type | Description |
|-------|-----------|--------------------------------------------------|
| disputeId* | string | The unique identifier of the dispute. |

**Response:**
```json
{
"id": "disp_AHfqOvkldwsbqt",
"entity": "dispute",
"payment_id": "pay_EsyWjHrfzb59eR",
"amount": 10000,
"currency": "INR",
"amount_deducted": 0,
"reason_code": "pre_arbitration",
"respond_by": 1590604200,
"status": "open",
"phase": "pre_arbitration",
"created_at": 1590059211,
"evidence": {
"amount": 10000,
"summary": "goods delivered",
"shipping_proof": null,
"billing_proof": null,
"cancellation_proof": null,
"customer_communication": null,
"proof_of_service": null,
"explanation_letter": null,
"refund_confirmation": null,
"access_activity_log": null,
"refund_cancellation_policy": null,
"term_and_conditions": null,
"others": null,
"submitted_at": null
}
}
```
-------------------------------------------------------------------------------------------------------

### Fetch a Dispute

```py
disputeId = "disp_0000000000000";

client.dispute.accept(disputeId);
```

**Parameters:**

| Name | Type | Description |
|-------|-----------|--------------------------------------------------|
| disputeId* | string | The unique identifier of the dispute. |

**Response:**
```json
{
"id": "disp_AHfqOvkldwsbqt",
"entity": "dispute",
"payment_id": "pay_EsyWjHrfzb59eR",
"amount": 10000,
"currency": "INR",
"amount_deducted": 10000,
"reason_code": "pre_arbitration",
"respond_by": 1590604200,
"status": "lost",
"phase": "pre_arbitration",
"created_at": 1590059211,
"evidence": {
"amount": 10000,
"summary": null,
"shipping_proof": null,
"billing_proof": null,
"cancellation_proof": null,
"customer_communication": null,
"proof_of_service": null,
"explanation_letter": null,
"refund_confirmation": null,
"access_activity_log": null,
"refund_cancellation_policy": null,
"term_and_conditions": null,
"others": null,
"submitted_at": null
}
}
```
-------------------------------------------------------------------------------------------------------
### Contest a Dispute

```py
# Use this API sample code for draft

disputeId = "disp_0000000000000";

client.dispute.contest(disputeId,{
"amount": 5000,
"summary": "goods delivered",
"shipping_proof": [
"doc_EFtmUsbwpXwBH9",
"doc_EFtmUsbwpXwBH8"
],
"others": [
{
"type": "receipt_signed_by_customer",
"document_ids": [
"doc_EFtmUsbwpXwBH1",
"doc_EFtmUsbwpXwBH7"
]
}
],
"action": "draft"
})
```

**Parameters:**

| Name | Type | Description |
|-------|-----------|--------------------------------------------------|
| disputeId* | string | The unique identifier of the dispute. |
| amount | integer | The amount being contested. If the contest amount is not mentioned, we will assume it to be a full dispute contest. |
| summary | string | The explanation provided by you for contesting the dispute. It can have a maximum length of 1000 characters. |
| shipping_proof | array | List of document ids which serves as proof that the product was shipped to the customer at their provided address. It should show their complete shipping address, if possible. |
| others | array | All keys listed [here](https://razorpay.com/docs/api/disputes/contest) are supported |

```py
# Use this API sample code for submit

client.dispute.contest(disputeId,{
"billing_proof": [
"doc_EFtmUsbwpXwBG9",
"doc_EFtmUsbwpXwBG8"
],
"action": "submit"
})
```

**Response:**
```json
// Draft
{
"id": "disp_AHfqOvkldwsbqt",
"entity": "dispute",
"payment_id": "pay_EsyWjHrfzb59eR",
"amount": 10000,
"currency": "INR",
"amount_deducted": 0,
"reason_code": "chargeback",
"respond_by": 1590604200,
"status": "open",
"phase": "chargeback",
"created_at": 1590059211,
"evidence": {
"amount": 5000,
"summary": "goods delivered",
"shipping_proof": [
"doc_EFtmUsbwpXwBH9",
"doc_EFtmUsbwpXwBH8"
],
"billing_proof": null,
"cancellation_proof": null,
"customer_communication": null,
"proof_of_service": null,
"explanation_letter": null,
"refund_confirmation": null,
"access_activity_log": null,
"refund_cancellation_policy": null,
"term_and_conditions": null,
"others": [
{
"type": "receipt_signed_by_customer",
"document_ids": [
"doc_EFtmUsbwpXwBH1",
"doc_EFtmUsbwpXwBH7"
]
}
],
"submitted_at": null
}
}

//Submit
{
"id": "disp_AHfqOvkldwsbqt",
"entity": "dispute",
"payment_id": "pay_EsyWjHrfzb59eR",
"amount": 10000,
"currency": "INR",
"amount_deducted": 0,
"reason_code": "chargeback",
"respond_by": 1590604200,
"status": "under_review",
"phase": "chargeback",
"created_at": 1590059211,
"evidence": {
"amount": 5000,
"summary": "goods delivered",
"shipping_proof": [
"doc_EFtmUsbwpXwBH9",
"doc_EFtmUsbwpXwBH8"
],
"billing_proof": [
"doc_EFtmUsbwpXwBG9",
"doc_EFtmUsbwpXwBG8"
],
"cancellation_proof": null,
"customer_communication": null,
"proof_of_service": null,
"explanation_letter": null,
"refund_confirmation": null,
"access_activity_log": null,
"refund_cancellation_policy": null,
"term_and_conditions": null,
"others": [
{
"type": "receipt_signed_by_customer",
"document_ids": [
"doc_EFtmUsbwpXwBH1",
"doc_EFtmUsbwpXwBH7"
]
}
],
"submitted_at": 1590603200
}
}
```
-------------------------------------------------------------------------------------------------------
**PN: * indicates mandatory fields**
<br>
<br>
**For reference click [here](https://razorpay.com/docs/api/documents)**
4 changes: 3 additions & 1 deletion razorpay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from .resources import Product
from .resources import Iin
from .resources import Webhook
from .resources import Dispute

__all__ = [
'Payment',
Expand Down Expand Up @@ -53,5 +54,6 @@
'Stakeholder',
'Product',
'Iin',
'Webhook'
'Webhook',
'Dispute',
]
1 change: 1 addition & 0 deletions razorpay/constants/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ class URL(object):
TOKEN = "/tokens"
IIN = "/iins"
WEBHOOK = "/webhooks"
DISPUTE= "/disputes"
4 changes: 3 additions & 1 deletion razorpay/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .product import Product
from .iin import Iin
from .webhook import Webhook
from .dispute import Dispute

__all__ = [
'Payment',
Expand All @@ -45,5 +46,6 @@
'Stakeholder',
'Product',
'Iin',
'Webhook'
'Webhook',
'Dispute',
]
46 changes: 46 additions & 0 deletions razorpay/resources/dispute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from .base import Resource
from ..constants.url import URL


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

def fetch(self, dispute_id, data={}, **kwargs):
"""
Fetch dispute for given Id
Returns:
dispute dict for given dispute Id
"""
return super(Dispute, self).fetch(dispute_id, data, **kwargs)

def accept(self, dispute_id, data={}, **kwargs):
"""
Accept a dispute
Returns:
Dictionary of disputes
"""
url = f"{self.base_url}/{dispute_id}/accept"
return self.post_url(url, data, **kwargs)

def contest(self, dispute_id, data={}, **kwargs):
"""
Contest a Dispute
Returns:
Dictionary of disputes
"""
url = f"{self.base_url}/{dispute_id}/contest"
return self.patch_url(url, data, **kwargs)

def all(self, data={}, **kwargs):
"""
Fetch all disputes
Returns:
Dictionary of disputes
"""
return super(Dispute, self).all(data, **kwargs)
15 changes: 15 additions & 0 deletions tests/mocks/dispute.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"id": "disp_9GTZ2XXXXXXXXX",
"entity": "dispute",
"payment_id": "pay_9GMNcXXXXXXXXX",
"amount": 5000,
"currency": "INR",
"amount_deducted": 0,
"gateway_dispute_id": "test",
"reason_code": "goods_or_services_not_received_or_partially_received",
"respond_by": 1514658600,
"status": "under_review",
"phase": "chargeback",
"comments": null,
"created_at": 1513965738
}
Loading

0 comments on commit ec997c6

Please sign in to comment.