diff --git a/README.md b/README.md index f6ccb19..4652214 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/package.json b/package.json index 92c73e0..6cda24d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/PayU.ts b/src/PayU.ts index b76fade..5848bd2 100644 --- a/src/PayU.ts +++ b/src/PayU.ts @@ -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} + * @memberof PayU + */ + public async refundOrder (orderId: string, description: string): Promise { + 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 response.data; + } catch (error) { + console.log(error) + const resp = 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 *