Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/ApiResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ var mapCrudToMethods = {
method: require('./Methods/DeleteMethod'),
static: false
}
],
cancel: [
{
method: require('./Methods/CancelByIdMethod'),
static: true
},
]
};

Expand Down
2 changes: 1 addition & 1 deletion lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ module.exports = (function (DEFAULT_API_KEY, DEFAULT_BASE_API_URL, DEFAULT_API_V
var options = generateReqOptions(fullUrl, {}, 'DELETE', headers);

makeRequest(options, callback);
}
},
};
}

Expand Down
41 changes: 41 additions & 0 deletions lib/Methods/CancelByIdMethod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

var Promise = require('promise'),
client = require('../Client'),
utils = require('../Utils');

module.exports = {
cancelById: function (id, callback) {
var self = this;

return new Promise(function (resolve, reject) {

utils.validateCallback(callback);

if (!id) {
throw new Error(this.constructor.primaryKeyProp + ' is not set');
}

var clientObj = client.getInstance();
var path = self.resourcePath + '/' + id + '/cancel';

clientObj.postHttp(path, {},function (error) {
if (error) {
if (callback) {
callback(error);
}

return reject(error);
}

var resourceObj = new self();

if (callback) {
callback(null, resourceObj);
}

return resolve(resourceObj);
});
});
}
};
2 changes: 1 addition & 1 deletion lib/Resources/Charge.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function Charge(data) {

createResource(Charge, {
resourcePath: 'charges',
crudMethods: ['create', 'read']
crudMethods: ['create', 'read', 'cancel']
});

module.exports = Charge;
Loading