Skip to content

Commit

Permalink
Merge pull request #3 from ingameltd/feature/refunds
Browse files Browse the repository at this point in the history
Feature/refunds
  • Loading branch information
kasvith authored Nov 24, 2020
2 parents 6fee84a + 4678191 commit 8f0bc4f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ To cancel an order before completed call this method.
const result = await payU.cancelOrder("payU order Id from notification");
```

### Refund order

To refund an order after completed call this method.

```typescript
const result = await payU.refundOrder("payU order Id from notification", "reason");
```

### Verify notification

To verify notification are valid cryptogrpically this method can be used.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ingameltd/payu",
"version": "1.0.1",
"version": "1.0.2",
"description": "PayU client for NodeJS",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
35 changes: 35 additions & 0 deletions src/PayU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,41 @@ export class PayU {
}
}

/**
* Refunds a PayU order
*
* @param {string} orderId - payu order id
* @param {string} description - description for refund
* @returns {Promise<OrderStatusResponse>}
* @memberof PayU
*/
public async refundOrder (orderId: string, description: string): Promise<OrderStatusResponse> {
const token = await this.oAuth.getAccessToken();
const headers = {
'Authorization': `Bearer ${token}`,
};

try {
const response = await this.client.post(
`${OrderEndpoint}/${orderId}/refund`,
{
refund: {
description
}
},
{
headers: headers
}
);

return <OrderStatusResponse>response.data;
} catch (error) {
console.log(error)
const resp = <OrderStatusResponse>error.response.data;
throw new PayUError(resp.status.statusCode, resp.status.code || '', resp.status.codeLiteral, resp.status.statusDesc);
}
}

/**
* Convert a key=value; list to json
*
Expand Down

0 comments on commit 8f0bc4f

Please sign in to comment.