1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 17:01:33 +02:00
invoiceninja/resources/js/clients/payment_methods/authorize-stripe-card.js
Benjamin Beganović ac5525c9ac
[V2] Client portal rework (#3516)
* Client login, reset and update password page

* Client dashboard, sidebar, PortalComposer.php

* wip

* Personal page & update for details

* Invoices, paying & pagination.blade.php

* Invoices, recurring invoice & buttons

* Payments, link component

* Payment methods

* Breadcrums, clean up & wrap up

* Remove format_date() method to formatDate on object

* Payments
- $this->render is now proxy for render()
- Removed logic from Controller.php to ClientPortal.php
- Added MakesDates to ClientGatewayToken.php
- StripePaymentDriver.php now returns correct views
- Refactor of adding new payment method
- Ignoring all local builds for public/js/clients/*

* Signature, wip

* Fix "Pay now" on single invoice

* Payments:
- Added ProcessInvoicesInBulk request class
- Refactor InvoiceController::bulk()
- Displaying terms & payments
- New signature.blade.php
- Removed comment from webpack.mix.js

* Quotes:
- Refactor ProcessInvoicesInBulk.php to ProcessInvoicesInBulkRequest.php
- Add new 'Quotes' field inside of PortalComposer.php
- Added MakesDates to Quote.php
- Added Quote::badgeForStatus()
- Cleanup payment.blade.php
- Quote showing and approving
- New resource 'quotes' in client.php
- New image for quotes, align-left.svg

* Credits:
- New 'credits' resource in client.php
- Fixes for client.php typo

* Breadcrumbs:
- Quotes
- Credits

* Placeholder for translations.

* Restore whereIn & client scope

Co-authored-by: David Bomba <turbo124@gmail.com>
2020-03-24 04:10:42 +11:00

91 lines
2.3 KiB
JavaScript
Vendored

/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
class AuthorizeStripeCard {
constructor(key) {
this.key = key;
this.cardHolderName = document.getElementById("cardholder-name");
this.cardButton = document.getElementById("card-button");
this.clientSecret = this.cardButton.dataset.secret;
}
setupStripe() {
this.stripe = Stripe(this.key);
this.elements = this.stripe.elements();
return this;
}
createElement() {
this.cardElement = this.elements.create("card");
return this;
}
mountCardElement() {
this.cardElement.mount("#card-element");
return this;
}
handleStripe(stripe, cardHolderName) {
stripe
.handleCardSetup(this.clientSecret, this.cardElement, {
payment_method_data: {
billing_details: { name: cardHolderName.value }
}
})
.then(result => {
if (result.error) {
return this.handleFailure(result);
}
return this.handleSuccess(result);
});
}
handleFailure(result) {
let errors = document.getElementById("errors");
errors.textContent = "";
errors.textContent = result.error.message;
errors.hidden = false;
}
handleSuccess(result) {
document.getElementById("gateway_response").value = JSON.stringify(
result.setupIntent
);
document.getElementById("is_default").value = document.getElementById(
"proxy_is_default"
).checked;
document.getElementById("server_response").submit();
}
handle() {
this.setupStripe()
.createElement()
.mountCardElement();
this.cardButton.addEventListener("click", () => {
this.handleStripe(this.stripe, this.cardHolderName);
});
return this;
}
}
const publishableKey = document.querySelector(
'meta[name="stripe-publishable-key"]'
).content;
/** @handle */
new AuthorizeStripeCard(publishableKey).handle();