Payment.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import { appApi } from 'src/boot/axios.js'
  2. import APIRepository from '../classes/APIRepository.js'
  3. import { Payment, PaymentList } from 'src/models/Payment.js'
  4. export default class PaymentAPI extends APIRepository {
  5. constructor() {
  6. super('invoice', appApi)
  7. this.APIAdresses = {
  8. base: '/accounting/payments',
  9. requestWithdraw: '/accounting/payments/request_withdraw',
  10. confirmWithdraw: (id) => '/accounting/payments/' + id + '/confirm_withdraw',
  11. rejectWithdraw: (id) => '/accounting/payments/' + id + '/reject_withdraw',
  12. byId: (id) => '/accounting/payments/' + id,
  13. exportPaymentReport: '/accounting/payments/export_report'
  14. }
  15. this.CacheList = {
  16. base: this.name + this.APIAdresses.base
  17. }
  18. this.restUrl = (id) => this.APIAdresses.base + '/' + id
  19. /* Setting the callback functions for the CRUD operations. */
  20. this.setCrudCallbacks({
  21. get: (response) => { return new Payment(response.data) },
  22. post: (response) => { return new Payment(response.data) },
  23. put: (response) => { return new Payment(response.data) },
  24. delete: (response) => { return response.data }
  25. })
  26. }
  27. index(data) {
  28. return this.sendRequest({
  29. apiMethod: 'get',
  30. api: this.api,
  31. request: this.APIAdresses.base,
  32. data: this.getNormalizedSendData({
  33. page: 1 // Number
  34. }, data),
  35. resolveCallback: (response) => {
  36. const paginate = response.data
  37. const results = response.data.results
  38. delete paginate.results
  39. return {
  40. list: new PaymentList(results),
  41. paginate
  42. // {
  43. // "count": 1,
  44. // "num_pages": 1,
  45. // "per_page": 10,
  46. // "current": 1,
  47. // "next": null,
  48. // "previous": null,
  49. // }
  50. }
  51. },
  52. rejectCallback: (error) => {
  53. return error
  54. }
  55. })
  56. }
  57. requestWithdraw(data) {
  58. return this.sendRequest({
  59. apiMethod: 'put',
  60. api: this.api,
  61. request: this.APIAdresses.requestWithdraw,
  62. data: this.getNormalizedSendData({
  63. IBAN: null, // String
  64. amount: null // Number
  65. }, data),
  66. resolveCallback: (response) => {
  67. return new Payment(response.data)
  68. },
  69. rejectCallback: (error) => {
  70. return error
  71. }
  72. })
  73. }
  74. confirmWithdraw(paymentId, data) {
  75. return this.sendRequest({
  76. apiMethod: 'put',
  77. api: this.api,
  78. request: this.APIAdresses.confirmWithdraw(paymentId),
  79. data,
  80. // receipt: null, // File
  81. // description: null // String
  82. resolveCallback: (response) => {
  83. return new Payment(response.data)
  84. },
  85. rejectCallback: (error) => {
  86. return error
  87. }
  88. })
  89. }
  90. rejectWithdraw(data) {
  91. return this.sendRequest({
  92. apiMethod: 'put',
  93. api: this.api,
  94. request: this.APIAdresses.rejectWithdraw(data.paymentId),
  95. data: this.getNormalizedSendData({
  96. description: null // String
  97. }, data),
  98. resolveCallback: (response) => {
  99. return new Payment(response.data)
  100. },
  101. rejectCallback: (error) => {
  102. return error
  103. }
  104. })
  105. }
  106. exportPaymentReport(data) {
  107. return this.sendRequest({
  108. apiMethod: 'get',
  109. api: this.api,
  110. request: this.APIAdresses.exportPaymentReport,
  111. data: this.getNormalizedSendData({
  112. report_type: null // String
  113. }, data),
  114. responseType: 'blob',
  115. resolveCallback: (response) => {
  116. return response.data // xlsxData
  117. },
  118. rejectCallback: (error) => {
  119. return error
  120. }
  121. })
  122. }
  123. }