AddFundsGateway.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <!--
  2. Copyright 2019 Hackware SpA <human@hackware.cl>
  3. This file is part of "Hackware Userland" and licensed under the terms
  4. of the GNU Affero General Public License version 3, or (at your option)
  5. a later version. You should have received a copy of this license along
  6. with the software. If not, see <https://www.gnu.org/licenses/>.
  7. -->
  8. <template>
  9. <div class="add-funds-gateway">
  10. <VAlert
  11. v-show="error"
  12. context="danger"
  13. >
  14. <i class="fas fa-exclamation-triangle" />
  15. Ha ocurrido un <strong>error</strong>, por favor verifica
  16. que los campos estén llenados correctamente o contáctanos.
  17. </VAlert>
  18. <h2>Añadir fondos</h2>
  19. <form @submit.prevent="submitAddFunds">
  20. <SchemaForm
  21. :json-schema="jsonSchema"
  22. />
  23. <div class="text-right">
  24. <button
  25. id="btnAddFunds"
  26. type="submit"
  27. class="btn btn-primary btn-lg"
  28. >
  29. <i class="far fa-handshake" />
  30. Proceder
  31. </button>
  32. </div>
  33. </form>
  34. </div>
  35. </template>
  36. <script>
  37. import SchemaForm from '@/components/SchemaForm.vue';
  38. import VAlert from '@/components/VAlert.vue';
  39. export default {
  40. name: 'AddFundsGateway',
  41. components: {
  42. SchemaForm,
  43. VAlert,
  44. },
  45. data() {
  46. return {
  47. jsonSchema: {},
  48. error: false,
  49. };
  50. },
  51. beforeCreate() {
  52. this.$fetcher.haweseGet(`/gateways/${this.$route.params.gateway}/schemas/purchase`)
  53. .then((body) => { this.jsonSchema = this.setDefaults(body); });
  54. },
  55. methods: {
  56. setDefaults(jsonSchema) {
  57. const jsonSchemaCopy = jsonSchema;
  58. Object.entries(this.$route.query).forEach((tuple) => {
  59. const [key, value] = tuple;
  60. jsonSchemaCopy.properties[key].default = value;
  61. });
  62. return jsonSchemaCopy;
  63. },
  64. submitAddFunds(event) {
  65. const btnAddFunds = document.getElementById('btnAddFunds');
  66. this.error = false;
  67. btnAddFunds.setAttribute('disabled', true);
  68. this.$fetcher.hawesePost(
  69. `/gateways/${this.$route.params.gateway}/purchase`,
  70. event.target,
  71. ).then((body) => {
  72. if ('error' in body) {
  73. btnAddFunds.removeAttribute('disabled');
  74. this.error = true;
  75. } else {
  76. window.location.href = body.redirect_url;
  77. }
  78. });
  79. },
  80. },
  81. };
  82. </script>