From bce0d00556f2260f77f0de6bef562870436e85e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 21 Jun 2021 14:21:44 +0200 Subject: [PATCH] Bank account: Javascript --- .../payment_methods/wepay-bank-account.js | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 resources/js/clients/payment_methods/wepay-bank-account.js diff --git a/resources/js/clients/payment_methods/wepay-bank-account.js b/resources/js/clients/payment_methods/wepay-bank-account.js new file mode 100644 index 000000000000..d15b51e6e81e --- /dev/null +++ b/resources/js/clients/payment_methods/wepay-bank-account.js @@ -0,0 +1,52 @@ +/** + * Invoice Ninja (https://invoiceninja.com). + * + * @link https://github.com/invoiceninja/invoiceninja source repository + * + * @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com) + * + * @license https://www.elastic.co/licensing/elastic-license + */ + +class WePayBank { + initializeWePay() { + let environment = document.querySelector('meta[name="wepay-environment"]')?.content; + + WePay.set_endpoint(environment === 'staging' ? 'stage' : 'production'); + + return this; + } + + showBankPopup() { + WePay.bank_account.create({ + client_id: document.querySelector('meta[name=wepay-client-id]')?.content, + email: document.querySelector('meta[name=contact-email]')?.content + }, function (data) { + if (data.error) { + errors.textContent = ''; + errors.textContent = data.error_description; + errors.hidden = false; + } else { + document.querySelector('input[name="bank_account_id"]').value = data.bank_account_id; + document.getElementById('server_response').submit(); + } + }, function (data) { + if (data.error) { + errors.textContent = ''; + errors.textContent = data.error_description; + errors.hidden = false; + } + } + ); + } + + handle() { + this + .initializeWePay() + .showBankPopup(); + } +} + +document.addEventListener('DOMContentLoaded', () => { + new WePayBank().handle(); +});