Skip to content

Commit

Permalink
refactor hostUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitdas13 committed Aug 1, 2023
1 parent fd20e89 commit 282d7ef
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
18 changes: 1 addition & 17 deletions e2e/razorpay.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
'use strict';

const Razorpay = require("../dist/razorpay");
let request = require('request-promise');

class RazorpayTest extends Razorpay {
constructor(options) {
super(options)
this.api.rq = request.defaults({
baseUrl: hostUrl,
json: true,
auth: {
user: options.key_id,
pass: options.key_secret
}
})
}
}


module.exports = new RazorpayTest({
module.exports = new Razorpay({
key_id: process.env.API_KEY || "",
key_secret: process.env.API_SECRET || "",
hostUrl : "https://api-web.dev.razorpay.in"
Expand Down
1 change: 1 addition & 0 deletions lib/razorpay.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface IRazorpayConfig {
key_id: string;
key_secret?: string;
headers?: RazorpayHeaders;
hostUrl? : string;
}

declare class Razorpay {
Expand Down
8 changes: 6 additions & 2 deletions lib/razorpay.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ class Razorpay {
}

constructor(options = {}) {
let { key_id, key_secret, headers } = options
let { key_id, key_secret, headers, hostUrl } = options

if (!key_id) {
throw new Error('`key_id` is mandatory')
}

if(!hostUrl){
hostUrl = 'https://api.razorpay.com'
}

this.key_id = key_id
this.key_secret = key_secret

this.api = new API({
hostUrl: 'https://api.razorpay.com',
hostUrl,
ua: `razorpay-node@${Razorpay.VERSION}`,
key_id,
key_secret,
Expand Down

0 comments on commit 282d7ef

Please sign in to comment.