mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-15 07:33:04 +01:00
10 lines
5.6 KiB
JavaScript
10 lines
5.6 KiB
JavaScript
|
/**
|
||
|
* 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
|
||
|
*/var r;let n=(r=document.querySelector('meta[name="wepay-action"]'))==null?void 0:r.content;class d{constructor(e="payment"){this.action=e,this.errors=document.getElementById("errors")}initializeWePay(){var t;let e=(t=document.querySelector('meta[name="wepay-environment"]'))==null?void 0:t.content;return WePay.set_endpoint(e==="staging"?"stage":"production"),this}validateCreditCardFields(){if(this.myCard=$("#my-card"),document.getElementById("cardholder_name")===""){document.getElementById("cardholder_name").focus(),this.errors.textContent="Cardholder name required.",this.errors.hidden=!1;return}else if(this.myCard.CardJs("cardNumber").replace(/[^\d]/g,"")===""){document.getElementById("card_number").focus(),this.errors.textContent="Card number required.",this.errors.hidden=!1;return}else if(this.myCard.CardJs("cvc").replace(/[^\d]/g,"")===""){document.getElementById("cvv").focus(),this.errors.textContent="CVV number required.",this.errors.hidden=!1;return}else if(this.myCard.CardJs("expiryMonth").replace(/[^\d]/g,"")===""){this.errors.textContent="Expiry Month number required.",this.errors.hidden=!1;return}else if(this.myCard.CardJs("expiryYear").replace(/[^\d]/g,"")===""){this.errors.textContent="Expiry Year number required.",this.errors.hidden=!1;return}return!0}handleAuthorization(){if(!this.validateCreditCardFields())return;let e=document.getElementById("card_button");e.disabled=!0,e.querySelector("svg").classList.remove("hidden"),e.querySelector("span").classList.add("hidden"),WePay.credit_card.create({client_id:document.querySelector("meta[name=wepay-client-id]").content,user_name:document.getElementById("cardholder_name").value,email:document.querySelector("meta[name=contact-email]").content,cc_number:this.myCard.CardJs("cardNumber").replace(/[^\d]/g,""),cvv:this.myCard.CardJs("cvc").replace(/[^\d]/g,""),expiration_month:this.myCard.CardJs("expiryMonth").replace(/[^\d]/g,""),expiration_year:this.myCard.CardJs("expiryYear").replace(/[^\d]/g,""),address:{country:document.querySelector(["meta[name=country_code"]).content,postal_code:document.querySelector(["meta[name=client-postal-code"]).content}},t=>{t.error?(e=document.getElementById("card_button"),e.disabled=!1,e.querySelector("svg").classList.add("hidden"),e.querySelector("span").classList.remove("hidden"),this.errors.textContent="",this.errors.textContent=t.error_description,this.errors.hidden=!1):(document.querySelector('input[name="credit_card_id"]').value=t.credit_card_id,document.getElementById("server_response").submit())})}completePaymentUsingToken(e){document.querySelector('input[name="credit_card_id"]').value=null,document.querySelector('input[name="token"]').value=e,document.getElementById("server-response").submit()}completePaymentWithoutToken(){if(!this.validateCreditCardFields()){this.payNowButton=document.getElementById("pay-now"),this.payNowButton.disabled=!1,this.payNowButton.querySelector("svg").classList.add("hidden"),this.payNowButton.querySelector("span").classList.remove("hidden");return}WePay.credit_card.create({client_id:document.querySelector("meta[name=wepay-client-id]").content,user_name:document.getElementById("cardholder_name").value,email:document.querySelector("meta[name=contact-email]").content,cc_number:this.myCard.CardJs("cardNumber").replace(/[^\d]/g,""),cvv:this.myCard.CardJs("cvc").replace(/[^\d]/g,""),expiration_month:this.myCard.CardJs("expiryMonth").replace(/[^\d]/g,""),expiration_year:this.myCard.CardJs("expiryYear").replace(/[^\d]/g,""),address:{country:document.querySelector(["meta[name=country_code"]).content,postal_code:document.querySelector(["meta[name=client-postal-code"]).content}},e=>{e.error?(this.payNowButton.disabled=!1,this.payNowButton.querySelector("svg").classList.add("hidden"),this.payNowButton.querySelector("span").classList.remove("hidden"),this.errors.textContent="",this.errors.textContent=e.error_description,this.errors.hidden=!1):(document.querySelector('input[name="credit_card_id"]').value=e.credit_card_id,document.querySelector('input[name="token"]').value=null,document.getElementById("server-re
|