| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | /** * @name Balance Operations * @description This module exposes functions * related to the `/balance/operations` path. * * @module balanceOperations **/ import { T, both, cond, curry, dissoc, has, pick, when, complement, isEmpty, applySpec, prop, pipe, } from 'ramda' import routes from '../routes' import request from '../request' const findOne = curry((opts, body) => request.get(opts, routes.balanceOperations.details(body.id), {}) ) const findAll = curry((opts, body) => request.get(opts, routes.balanceOperations.base, body || {}) ) const findRecipients = curry((opts, body) => request.get( opts, routes.balanceOperations.recipients.findAll(body.recipientId), dissoc('recipientId', body) ) ) const findRecipientsWithBalanceId = curry((opts, body) => request.get(opts, routes.balanceOperations.recipients.find(body.id, body.recipientId), {}) ) const pickQueryProps = pick(['startDate', 'endDate']) const renameKeys = when( complement(isEmpty), applySpec({ end_date: prop('endDate'), start_date: prop('startDate'), }) ) const buildQuery = pipe( pickQueryProps, renameKeys ) const findRecipientsWithFormat = curry((opts, body) => { const { recipientId, format } = body return request.get( opts, routes.balanceOperations.recipients.findWithFormat(recipientId, format), buildQuery(body) ) }) /** * `GET /balance/operations` * Makes a request to /balance/operations, * /balance/operations/:id, * /recipients/:recipient_id/balance/operations/ or * /recipients/:recipient_id/balance/operations/:id * and returns company's balanceOperations or returns a specif company's balanceOperation * * @param {Object} opts An options params which * is usually already bound * by `connect` functions. * * @param {Object} body The payload for the request. * {@link https://pagarme.readme.io/v1/reference#histórico-específico-de-uma-operação|API Reference for this payload} * @param {Number} [body.id] The operations's ID. If not sent a * operations list will be returned instead. * @param {Number} [body.recipientId] The recipient's ID. * @param {String} [body.format] The file extension. * @param {Number} [body.count] Pagination option to get a list of operations. * Number of operations in a page * @param {Number} [body.page] Pagination option for a list of operations. * The page index. */ const find = (opts, body) => cond([ [both(has('id'), has('recipientId')), findRecipientsWithBalanceId(opts)], [both(has('recipientId'), has('format')), findRecipientsWithFormat(opts)], [has('recipientId'), findRecipients(opts)], [has('id'), findOne(opts)], [T, findAll(opts)], ])(body) /** * `GET /balance/operations` * Returns company's balanceOperations * * @param {Object} opts An options params which * is usually already bound * by `connect` functions. * * @param {Object} body The payload for the request. * {@link https://pagarme.readme.io/v1/reference#histórico-das-operações|API Reference for this payload} * @param {Number} [body.count] Pagination option to get a list of operations. * Number of operations in a page * @param {Number} [body.page] Pagination option for a list of operations. * The page index. */ const all = (opts, pagination) => findAll(opts, pagination) /** * `GET /balance/operations/days` * Returns a company's balanceOperations aggregated by day * * @param {Object} opts An options params which * is usually already bound * by `connect` functions. */ const days = (opts, body) => request.get(opts, routes.balanceOperations.days, body || {}) export default { find, all, days, } |