Skip to content

Commit

Permalink
Merge pull request #225 from razorpay/paymentlink_sdk
Browse files Browse the repository at this point in the history
Node-sdk PaymentLink
  • Loading branch information
ankitdas13 authored Nov 10, 2021
2 parents 0aa1650 + cb5500f commit 2cb2ff2
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 7 deletions.
51 changes: 45 additions & 6 deletions dist/resources/paymentLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = function paymentLinkApi(api) {
MISSING_ID_ERROR = "Payment Link ID is mandatory";

return {
create: function() {
create: function create() {
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var callback = arguments[1];

Expand All @@ -45,7 +45,7 @@ module.exports = function paymentLinkApi(api) {
data: data
}, callback, true);
},
cancel: function(paymentLinkId, callback) {
cancel: function cancel(paymentLinkId, callback) {

/*
* Cancels issued paymentLink
Expand All @@ -61,13 +61,13 @@ module.exports = function paymentLinkApi(api) {
return Promise.reject(MISSING_ID_ERROR);
}

var url = `${BASE_URL}/${paymentLinkId}/cancel`;
var url = BASE_URL + "/" + paymentLinkId + "/cancel";

return api.post({
url: url
}, callback);
},
fetch: function(paymentLinkId, callback) {
fetch: function fetch(paymentLinkId, callback) {

/*
* Fetches paymentLink entity with given id
Expand All @@ -83,13 +83,13 @@ module.exports = function paymentLinkApi(api) {
return Promise.reject(MISSING_ID_ERROR);
}

var url = `${BASE_URL}/${paymentLinkId}`;
var url = BASE_URL + "/" + paymentLinkId;

return api.get({
url: url
}, callback);
},
all: function() {
all: function all() {
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var callback = arguments[1];

Expand Down Expand Up @@ -130,6 +130,45 @@ module.exports = function paymentLinkApi(api) {
skip: skip
})
}, callback);
},
edit: function edit(paymentLinkId, params, callback) {
var notes = params.notes,
rest = _objectWithoutProperties(params, ["notes"]);

var data = Object.assign(rest, normalizeNotes(notes));

return api.patch({
url: BASE_URL + "/" + paymentLinkId,
data: data
}, callback);
},
notifyBy: function notifyBy(paymentLinkId, medium, callback) {

/*
* Send/re-send notification for invoice by given medium
*
* @param {String} paymentLinkId
* @param {String} medium
* @param {Function} callback
*
* @return {Promise}
*/

if (!paymentLinkId) {

return Promise.reject(MISSING_ID_ERROR);
}

if (!medium) {

return Promise.reject("`medium` is required");
}

var url = BASE_URL + "/" + paymentLinkId + "/notify_by/" + medium;

return api.post({
url: url
}, callback);
}
};
};
41 changes: 40 additions & 1 deletion lib/resources/paymentLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ module.exports = function paymentLinkApi (api) {
url
}, callback);
},

all (params={}, callback) {

/*
Expand Down Expand Up @@ -115,6 +115,45 @@ module.exports = function paymentLinkApi (api) {
skip
}
}, callback);
},

edit(paymentLinkId, params, callback) {
let { notes, ...rest } = params
let data = Object.assign(rest, normalizeNotes(notes));

return api.patch({
url: `${BASE_URL}/${paymentLinkId}`,
data
}, callback)
},

notifyBy (paymentLinkId, medium, callback) {

/*
* Send/re-send notification for invoice by given medium
*
* @param {String} paymentLinkId
* @param {String} medium
* @param {Function} callback
*
* @return {Promise}
*/

if (!paymentLinkId) {

return Promise.reject(MISSING_ID_ERROR);
}

if (!medium) {

return Promise.reject("`medium` is required");
}

let url = `${BASE_URL}/${paymentLinkId}/notify_by/${medium}`;

return api.post({
url
}, callback);
}
};
};
71 changes: 71 additions & 0 deletions test/resources/paymentLink.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,30 @@ describe("PAYMENTLINK", () => {
})
});

describe("Update PaymentLink",() => {
it('Update Payment Link', (done) => {

let params= {
"param1": "something",
"param2": "something else",
"notes[something]": "something else"
};
mocker.mock({
url: `/payment_links/${TEST_PAYMENTLINK_ID}`,
method: 'PATCH',
})

rzpInstance.paymentLink.edit(TEST_PAYMENTLINK_ID,params).then((response) => {
assert.equal(
response.__JUST_FOR_TESTS__.url,
`/v1/payment_links/${TEST_PAYMENTLINK_ID}`,
'edit request url formed'
)
done()
})
})
})

describe("Cancel PaymentLink", () => {

let expectedUrl = `${FULL_PATH}/${TEST_PAYMENTLINK_ID}/cancel`,
Expand Down Expand Up @@ -198,4 +222,51 @@ describe("PAYMENTLINK", () => {
methodArgs
});
});

describe("Notify By", () => {

let medium = "email",
expectedUrl = `${FULL_PATH}/${TEST_PAYMENTLINK_ID}/notify_by/${medium}`,
methodName = "notifyBy",
methodArgs = [TEST_PAYMENTLINK_ID, medium],
mockerParams = {
"url": `${SUB_PATH}/${TEST_PAYMENTLINK_ID}/notify_by/${medium}`,
"method": "POST"
};

runIDRequiredTest({
apiObj,
methodName,
methodArgs: [undefined, medium],
mockerParams: {
"url": `${SUB_PATH}/${undefined}/notify_by/${medium}`,
"method": "POST"
}
});

it ("notify method checks for `medium` parameter", (done) => {

mocker.mock({
url: `${SUB_PATH}/${TEST_PAYMENTLINK_ID}/notify_by/${undefined}`,
method: "POST"
});

apiObj[methodName](TEST_PAYMENTLINK_ID, undefined).then(() => {

done(new Error("medium parameter is not checked for"));
}).catch(() => {

assert.ok("medium parameter is checked");
done();
});
});

runCommonTests({
apiObj,
methodName,
methodArgs,
mockerParams,
expectedUrl
});
});
});

0 comments on commit 2cb2ff2

Please sign in to comment.