diff --git a/lib/main.js b/lib/main.js index 872f375..36e3b97 100644 --- a/lib/main.js +++ b/lib/main.js @@ -46,6 +46,8 @@ var ERROR_MESSAGES = { 50600: 'Duplicate transaction.' }; +const api_version = '/v2.1' + function get_error_message_from_response(response) { var response_code = response.data && response.data.response_code; var error_message = 'Undefined Error. This should not happen!'; @@ -139,7 +141,7 @@ module.exports = function (api_key) { var request_options = { host: 'api.paymill.de', port: '443', - path: path, + path: api_version + path, method: method, headers: { 'Authorization': auth, @@ -176,177 +178,177 @@ module.exports = function (api_key) { return { payments: { create: function(payment, cb) { - post('/v2/payments', payment, cb); + post('/payments', payment, cb); }, details: function(payment_id, cb) { if (typeof payment_id !== 'string') { throw new TypeError('payment_id must be a string'); } - get('/v2/payments/' + payment_id, {}, cb); + get('/payments/' + payment_id, {}, cb); }, list: function(data, cb) { - get('/v2/payments', data, cb); + get('/payments', data, cb); }, remove: function(payment_id, cb) { if (typeof payment_id !== 'string') { throw new TypeError('payment_id must be a string'); } - del('/v2/payments/' + payment_id, {}, cb); + del('/payments/' + payment_id, {}, cb); } }, preauthorizations: { create: function(preauthorization, cb) { - post('/v2/preauthorizations', preauthorization, cb); + post('/preauthorizations', preauthorization, cb); }, details: function(preauthorization_id, cb) { if (typeof preauthorization_id !== 'string') { throw new TypeError('preauthorization_id must be a string'); } - get('/v2/preauthorizations/' + preauthorization_id, {}, cb); + get('/preauthorizations/' + preauthorization_id, {}, cb); }, list: function(data, cb) { - get('/v2/preauthorizations', data, cb); + get('/preauthorizations', data, cb); }, remove: function(preauthorization_id, cb) { if (typeof preauthorization_id !== 'string') { throw new TypeError('preauthorization_id must be a string'); } - del('/v2/preauthorizations/' + preauthorization_id, {}, cb); + del('/preauthorizations/' + preauthorization_id, {}, cb); } }, transactions: { create: function(transaction, cb) { - post('/v2/transactions', transaction, cb); + post('/transactions', transaction, cb); }, details: function(transaction_id, cb) { if (typeof transaction_id !== 'string') { throw new TypeError('transaction_id must be a string'); } - get('/v2/transactions/' + transaction_id, {}, cb); + get('/transactions/' + transaction_id, {}, cb); }, update: function(transaction_id, data, cb) { - put("/v2/transactions/" + transaction_id, data, cb); + put("/transactions/" + transaction_id, data, cb); }, list: function(data, cb) { - get('/v2/transactions', data, cb); + get('/transactions', data, cb); } }, refunds: { refund: function(transaction_id, amount, description, cb) { - post('/v2/refunds/' + transaction_id, {amount: amount, description: description}, cb); + post('/refunds/' + transaction_id, {amount: amount, description: description}, cb); }, details: function(refund_id, cb) { if (typeof refund_id !== 'string') { throw new TypeError('refund_id must be a string'); } - get('/v2/refunds/' + refund_id, {}, cb); + get('/refunds/' + refund_id, {}, cb); }, list: function(data, cb) { - get('/v2/refunds', data, cb); + get('/refunds', data, cb); } }, clients: { create: function(client, cb) { - post('/v2/clients', client, cb); + post('/clients', client, cb); }, details: function(client_id, cb) { if (typeof client_id !== 'string') { throw new TypeError('client_id must be a string'); } - get('/v2/clients/' + client_id, {}, cb); + get('/clients/' + client_id, {}, cb); }, update: function(client_id, data, cb) { if (typeof client_id !== 'string') { throw new TypeError('client_id must be a string'); } - put('/v2/clients/' + client_id, data, cb); + put('/clients/' + client_id, data, cb); }, remove: function(client_id, cb) { if (typeof client_id !== 'string') { throw new TypeError('client_id must be a string'); } - del('/v2/clients/' + client_id, {}, cb); + del('/clients/' + client_id, {}, cb); }, list: function(data, cb) { - get('/v2/clients', data, cb); + get('/clients', data, cb); } }, offers: { create: function(offer, cb) { - post('/v2/offers', offer, cb); + post('/offers', offer, cb); }, details: function(offer_id, cb) { if (typeof offer_id !== 'string') { throw new TypeError('offer_id must be a string'); } - get('/v2/offers/' + offer_id, {}, cb); + get('/offers/' + offer_id, {}, cb); }, update: function(offer_id, data, cb) { if (typeof offer_id !== 'string') { throw new TypeError('offer_id must be a string'); } - put('/v2/offers/' + offer_id, data, cb); + put('/offers/' + offer_id, data, cb); }, remove: function(offer_id, cb) { if (typeof offer_id !== 'string') { throw new TypeError('offer_id must be a string'); } - del('/v2/offers/' + offer_id, {}, cb); + del('/offers/' + offer_id, {}, cb); }, list: function(data, cb) { - get('/v2/offers', data, cb); + get('/offers', data, cb); } }, subscriptions: { create: function(subscription, cb) { - post('/v2/subscriptions', subscription, cb); + post('/subscriptions', subscription, cb); }, details: function(subscription_id, cb) { if (typeof subscription_id !== 'string') { throw new TypeError('subscription_id must be a string'); } - get('/v2/subscriptions/' + subscription_id, {}, cb); + get('/subscriptions/' + subscription_id, {}, cb); }, update: function(subscription_id, data, cb) { if (typeof subscription_id !== 'string') { throw new TypeError('subscription_id must be a string'); } - put('/v2/subscriptions/' + subscription_id, data, cb); + put('/subscriptions/' + subscription_id, data, cb); }, remove: function(subscription_id, cb) { if (typeof subscription_id !== 'string') { throw new TypeError('subscription_id must be a string'); } - del('/v2/subscriptions/' + subscription_id, {}, cb); + del('/subscriptions/' + subscription_id, {}, cb); }, list: function(data, cb) { - get('/v2/subscriptions', data, cb); + get('/subscriptions', data, cb); } }, webhooks: { create: function(webhook, cb) { - post('/v2/webhooks', webhook, cb); + post('/webhooks', webhook, cb); }, details: function(webhook_id, cb) { if (typeof webhook_id !== 'string') { throw new TypeError('webhook_id must be a string'); } - get('/v2/webhooks/' + webhook_id, {}, cb); + get('/webhooks/' + webhook_id, {}, cb); }, update: function(webhook_id, data, cb) { if (typeof webhook_id !== 'string') { throw new TypeError('webhook_id must be a string'); } - put('/v2/webhooks/' + webhook_id, data, cb); + put('/webhooks/' + webhook_id, data, cb); }, remove: function(webhook_id, cb) { if (typeof webhook_id !== 'string') { throw new TypeError('webhook_id must be a string'); } - del('/v2/webhooks/' + webhook_id, {}, cb); + del('/webhooks/' + webhook_id, {}, cb); }, list: function(data, cb) { - get('/v2/webhooks', data, cb); + get('/webhooks', data, cb); } } };