Skip to content

Commit

Permalink
Merge pull request #106 from jsertx/feat/add-missing-merchang-endpoints
Browse files Browse the repository at this point in the history
feat: add several Bitfinex pay merchant related endpoints
  • Loading branch information
vigan-abd authored Jun 15, 2023
2 parents c91d58f + 15ffd78 commit ddd5062
Show file tree
Hide file tree
Showing 10 changed files with 6,091 additions and 769 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# 5.2.0
- RESTv2: add payCurrencyConversionList method
- RESTv2: add payAddCurrencyConversion method
- RESTv2: add payRemoveCurrencyConversion method
- RESTv2: add payMerchantDailyLimit method
- RESTv2: add payMerchantSettingsWrite method
- RESTv2: add payMerchantSettingsWriteBatch method
- RESTv2: add payMerchantSettingsRead method
- RESTv2: add payMerchantSettingsList method

# 5.1.1
- dep: upgraded bfx-api-node-models to 1.7.1 for compatibility

Expand Down
4 changes: 2 additions & 2 deletions docs/RESTv1.html

Large diffs are not rendered by default.

6,336 changes: 5,603 additions & 733 deletions docs/RESTv2.html

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions docs/global.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/index.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/rest1.js.html

Large diffs are not rendered by default.

242 changes: 231 additions & 11 deletions docs/rest2.js.html

Large diffs are not rendered by default.

223 changes: 214 additions & 9 deletions lib/rest2.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ class RESTv2 {
* @private
*/
async _makePublicRequest (path, cb, transformer) {
if ((cb !== null && cb !== undefined) && typeof cb !== 'function') {
throw new Error('_makePublicRequest cb param must be a function')
}
const url = `${this._url}/v2${path}`

debug('GET %s', url)
Expand Down Expand Up @@ -1924,6 +1927,7 @@ class RESTv2 {
* @param {string} [params.customerInfo.residBuildingNo] - optional, customer's residential building number/name
* @param {string} params.customerInfo.fullName - customer's full name
* @param {string} params.customerInfo.email - customer's email address
* @param {string} [params.customerInfo.ip] - customer's ip
* @param {object} [params.meta] - metadata
* @param {string} [params.meta.env] - merchant environment, allowed values: production, test,
* staging, development
Expand All @@ -1937,6 +1941,76 @@ class RESTv2 {
return this._makeAuthRequest('/auth/w/ext/pay/invoice/create', params, cb)
}

/**
* @param {object} params - invoice parameters
* @param {string} params.amount - invoice amount in currency
* @param {string} params.currency - invoice currency
* @param {string[]} params.payCurrencies - currencies in which invoice accepts the payments
* @param {number} [params.duration] - optional, invoice expire time in seconds, minimal duration
* is 5 mins and maximal duration is 3 days.
* Default value is 15 minutes
* @param {string} params.orderId - reference order identifier in merchant's platform
* @param {string} [params.webhook] - the endpoint that will be called once the payment is
* completed or expired
* @param {string} [params.redirectUrl] - merchant redirect URL, this one is used in UI to redirect
* @param {object} [params.meta] - metadata
* @param {string} [params.meta.env] - merchant environment, allowed values: production, test,
* staging, development
* @param {string[]} [params.meta.tags] - invoice tags, max number of tags is 5 and max length of
* tag is 5 characters
* @param {Function} [cb] - legacy callback
* @returns {Promise} p
*/
payInvoiceCreatePos (params, cb = null) {
return this._makeAuthRequest('/auth/w/ext/pay/invoice/create/pos', params, cb)
}

/**
* @param {Object} params - An object containing the following properties:
* @param {Object} params.id - The id property.
* @param {Object} params.fields
* @param {Object} params.fields.customerInfo
* @param {Object} params.fields.customerInfo.tosAccepted - TOS Accepted by customer
* @param {Object} params.privateNote - Private note
*
* @param {Function} [cb] - legacy callback
* @returns {Promise} p
*/
payInvoiceUpdate (params, cb = null) {
return this._makeAuthRequest('/auth/w/ext/pay/invoice/update', params, cb)
}

/**
* @param {object} params - list of feedbacks
* @param {boolean} params.detailed - detailed
* @param {Function} [cb] - legacy callback
* @returns {Promise} p
*/
payPublicInvoiceCurrencyDetailed (params = {}, cb = null) {
return this._makePublicRequest('/ext/pay/invoice/currency/detailed', cb)
}

/**
* @param {object} params - list of feedbacks
* @param {boolean} params.detailed - detailed
* @param {Function} [cb] - legacy callback
* @returns {Promise} p
*/
payInvoiceCurrencyDetailed (params, cb = null) {
return this._makePublicPostRequest('/auth/r/ext/pay/currency/detailed', params, cb)
}

/**
* @param {object} parameters - list of feedbacks
* @param {boolean} params.detailed - detailed
* @param {string?} params.id - invoice id
* @param {Function} [cb] - legacy callback
* @returns {Promise} p
*/
payCurrencyList (params, cb = null) {
return this._makeAuthRequest('/auth/r/ext/pay/currency/list', params, cb)
}

/**
* @param {object} [params] - query parameters
* @param {string} [params.id] - unique invoice identifier
Expand Down Expand Up @@ -1972,21 +2046,60 @@ class RESTv2 {
}

/**
* @param {object} params - query parameters
* @param {string} params.id - unique invoice identifier
* @param {string} params.payCcy - paid invoice currency, should be one of values under payCurrencies field
* on invoice
* @param {number} [params.depositId] - movement/deposit Id linked to invoice as payment
* @param {number} [params.ledgerId] - ledger entry Id linked to invoice as payment, use either depositId
* or ledgerId
* @param {Function} [cb] - legacy callback
* @param {object} [params] - query parameters
* @param {string} [params.id] - invoice id of which events will be returned
*
* @returns {Promise} p
* @see https://docs.bitfinex.com/reference#complete-invoice
*/
payInvoiceEvents (params = {}, cb = null) {
return this._makeAuthRequest('/auth/r/ext/pay/invoice/events', params, cb)
}

/**
* @param {object} params - query parameters
* @param {string} params.id - unique invoice identifier
* @param {string} params.payCcy - paid invoice currency, should be one of values under payCurrencies field
* on invoice
* @param {number} [params.depositId] - movement/deposit Id linked to invoice as payment
* @param {number[]} [params.depositIds] - movement/deposit ids list linked to invoice as payment
* @param {number} [params.ledgerId] - ledger entry Id linked to invoice as payment, use either depositId
* or ledgerId
* @param {Function} [cb] - legacy callback
* @returns {Promise} p
* @see https://docs.bitfinex.com/reference/complete-invoice
*/
payInvoiceComplete (params, cb = null) {
return this._makeAuthRequest('/auth/w/ext/pay/invoice/complete', params, cb)
}

/**
* @param {object} params - query parameters
* @param {string} params.id - unique invoice identifier
* @param {string} params.ccy - currency to be refunded
* @param {string} params.amount - amount to be refunded
* @param {object} params.address - address of refund
* @param {object} params.address.address - address of the wallet
* @param {object} params.address.payment_id - tag memo
* @param {Function} [cb] - legacy callback
* @returns {Promise} p
*/
payRefundInvoice (params, cb = null) {
return this._makeAuthRequest('/auth/w/ext/pay/invoice/refund', params, cb)
}

/**
* @param {object} params - query parameters
* @param {string} params.id - unique invoice identifier
* @param {string} params.refundId - id of the refund
* @param {Function} [cb] - legacy callback
* @returns {Promise} p
*/
payInvoiceMarkRefunded (params, cb = null) {
return this._makeAuthRequest('/auth/w/ext/pay/invoice/mark/refunded', params, cb)
}

/**
* @param {object} params - query parameters
* @param {string} params.id - unique invoice identifier
Expand All @@ -1998,6 +2111,98 @@ class RESTv2 {
return this._makeAuthRequest('/auth/w/ext/pay/invoice/expire', params, cb)
}

/**
* List bitfinex pay currency conversions
* @param {Function} [cb] - legacy callback
* @returns {Promise} p
* @see https://docs.bitfinex.com/reference/conversion-list
*/
payCurrencyConversionList (cb = null) {
return this._makeAuthRequest('/auth/r/ext/pay/settings/convert/list', {}, cb)
}

/**
* Add bitfinex pay currency conversions
* @param {number} params.baseCcy - Base currency that will be converted, could be bfx pay currency symbol (e.g. UST-ETH) or global api symbol (UST), result is stored as global api symbol!
* @param {number} params.convertCcy - Currency to which base currency will be converted, could be bfx pay currency symbol (e.g. UST-ETH) or global api symbol (UST), result is stored as global api symbol!
* @param {Function} [cb] - legacy callback
* @returns {Promise} p
* @see https://docs.bitfinex.com/reference/add-conversion
*/
payAddCurrencyConversion (params, cb = null) {
return this._makeAuthRequest('/auth/w/ext/pay/settings/convert/create', params, cb)
}

/**
* Remove bitfinex pay currency conversions
* @param {number} params.baseCcy - Base currency that will be converted, could be bfx pay currency symbol (e.g. UST-ETH) or global api symbol (UST), result is stored as global api symbol!
* @param {number} params.convertCcy - Currency to which base currency will be converted, could be bfx pay currency symbol (e.g. UST-ETH) or global api symbol (UST), result is stored as global api symbol!
* @param {Function} [cb] - legacy callback
* @returns {Promise} p
* @see https://docs.bitfinex.com/reference/remove-conversion
*/
payRemoveCurrencyConversion (params, cb = null) {
return this._makeAuthRequest('/auth/w/ext/pay/settings/convert/remove', params, cb)
}

/**
* Returns the daily limits for merchant
* @param {string[]} [params.customerEmails] - Optional, customer emails for e-commerce usage
* @param {Function} [cb] - legacy callback
* @returns {Promise} p
* @see https://docs.bitfinex.com/reference/merchant-limits
*/
payMerchantDailyLimit (params, cb = null) {
return this._makeAuthRequest('/auth/r/ext/pay/settings/daily/limit', params, cb)
}

/**
* Sets merchant settings
* @param {string} params.key - Setting key. Check doc link for possible values
* @param {string} params.value - Setting value, if null it means unset
* @param {Function} [cb] - legacy callback
* @returns {Promise} p
* @see https://docs.bitfinex.com/reference/merchant-settings-write
*/
payMerchantSettingsWrite (params, cb = null) {
return this._makeAuthRequest('/auth/w/ext/pay/settings/set', params, cb)
}

/**
* Sets merchant settings
* @param {string} params.settings - Setting keys and values
* @param {string} params.settings[].key - Setting key. Check doc link for possible values
* @param {string} params.settings[].value - Setting value, if null it means unset
* @param {Function} [cb] - legacy callback
* @returns {Promise} p
* @see https://docs.bitfinex.com/reference/merchant-settings-write-batch
*/
payMerchantSettingsWriteBatch (params, cb = null) {
return this._makeAuthRequest('/auth/w/ext/pay/settings/set/batch', params, cb)
}

/**
* Reads merchant settings
* @param {string} params.key - Setting key. Check doc link for possible values
* @param {Function} [cb] - legacy callback
* @returns {Promise} p
* @see https://docs.bitfinex.com/reference/merchant-settings-read
*/
payMerchantSettingsRead (params, cb = null) {
return this._makeAuthRequest('/auth/r/ext/pay/settings/get', params, cb)
}

/**
* Reads multiple merchant settings
* @param {string[]} params.keys - Setting keys, if empty array all settings will be returned
* @param {Function} [cb] - legacy callback
* @returns {Promise} p
* @see https://docs.bitfinex.com/reference/merchant-settings-list
*/
payMerchantSettingsList (params, cb = null) {
return this._makeAuthRequest('/auth/r/ext/pay/settings/list', params, cb)
}

/**
* @param {object} params - query parameters
* @param {string} params.ccy - pay currency to search deposits for
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bfx-api-node-rest",
"version": "5.1.1",
"version": "5.2.0",
"description": "Official Bitfinex REST v1 & v2 API interfaces",
"engines": {
"node": ">=8.3.0"
Expand Down Expand Up @@ -37,14 +37,15 @@
"Paolo Ardoino <[email protected]> (https://www.bitfinex.com)",
"Jacob Plaster <[email protected]> (https://www.bitfinex.com)",
"Abhishek Shrestha <[email protected]> (https://www.bitfinex.com)",
"Vigan Abdurrahmani <[email protected]> (https://www.bitfinex.com)"
"Vigan Abdurrahmani <[email protected]> (https://www.bitfinex.com)",
"Sergio López <[email protected]> (https://www.bitfinex.com)"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/bitfinexcom/bfx-api-node-rest/issues"
},
"devDependencies": {
"bfx-api-mock-srv": "^1.2.0",
"bfx-api-mock-srv": "^1.5.0",
"chai": "^4.3.7",
"chai-as-promised": "^7.1.1",
"docdash": "^1.2.0",
Expand Down
20 changes: 18 additions & 2 deletions test/lib/rest-2-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,26 @@ describe('RESTv2 integration (mock server) tests', () => {
['payInvoiceCreate', 'invoice_submit', [{}]],
['payInvoiceList', 'invoice_list', [{}]],
['payInvoiceComplete', 'invoice_complete', [{}]],
['payCurrencyConversionList', 'pay_settings_convert_list', []],
['payAddCurrencyConversion', 'pay_settings_convert_create', [{}]],
['payRemoveCurrencyConversion', 'pay_settings_convert_remove', [{}]],
['payMerchantDailyLimit', 'pay_settings_daily_limit', [{}]],
['payMerchantSettingsWrite', 'pay_settings_set', [{}]],
['payMerchantSettingsWriteBatch', 'pay_settings_set_batch', [{}]],
['payMerchantSettingsRead', 'pay_settings_get', [{}]],
['payMerchantSettingsList', 'pay_settings_list', [{}]],
['getCoreSettings', 'core_settings', [[]]],
['invalidateAuthToken', 'delete_token', [[]]],
['invalidateAuthToken', 'delete_token', [[{}]]],
['payDepositsUnlinked', 'deposits_unlinked', [{}]],
['movementInfo', 'movement_info.id', [{ id: 'id' }]]
['movementInfo', 'movement_info.id', [{ id: 'id' }]],
['payRefundInvoice','pay_invoice_refund', [{}]],
['payInvoiceMarkRefunded','pay_invoice_mark_refunded', [{}]],
['payInvoiceEvents','pay_invoice_events', [{}]],
['payPublicInvoiceCurrencyDetailed','pay_public_invoice_currency_detailed', [{}]],
['payInvoiceCurrencyDetailed','pay_currency_detailed', [{}]],
['payCurrencyList','pay_currency_list', [{}]],
['payInvoiceUpdate','pay_invoice_update', [{}]],
['payInvoiceCreatePos','pay_invoice_create_pos', [{}]],
]

methods.forEach((m) => {
Expand Down

0 comments on commit ddd5062

Please sign in to comment.