From 55b38a217248defb032a46ce15f347c0de76b76a Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 25 Sep 2024 12:03:33 +1000 Subject: [PATCH] Updates for powerboard --- app/Livewire/Flow2/PaymentMethod.php | 1 - app/Livewire/Flow2/ProcessPayment.php | 10 +++++----- app/Livewire/Flow2/RequiredFields.php | 8 ++++++++ app/PaymentDrivers/CBAPowerBoard/CreditCard.php | 10 ++++------ .../assets/powerboard-credit-card-481ce439.js | 13 ------------- .../assets/powerboard-credit-card-f5f23291.js | 13 +++++++++++++ public/build/manifest.json | 2 +- .../js/clients/payments/powerboard-credit-card.js | 15 +++++++++++++++ 8 files changed, 46 insertions(+), 26 deletions(-) delete mode 100644 public/build/assets/powerboard-credit-card-481ce439.js create mode 100644 public/build/assets/powerboard-credit-card-f5f23291.js diff --git a/app/Livewire/Flow2/PaymentMethod.php b/app/Livewire/Flow2/PaymentMethod.php index 19986f73676f..780c51023c8c 100644 --- a/app/Livewire/Flow2/PaymentMethod.php +++ b/app/Livewire/Flow2/PaymentMethod.php @@ -80,7 +80,6 @@ class PaymentMethod extends Component { nlog($e->getMessage()); - $stopPropagation(); } diff --git a/app/Livewire/Flow2/ProcessPayment.php b/app/Livewire/Flow2/ProcessPayment.php index c162ba1ee14f..172614d31bd8 100644 --- a/app/Livewire/Flow2/ProcessPayment.php +++ b/app/Livewire/Flow2/ProcessPayment.php @@ -91,11 +91,11 @@ class ProcessPayment extends Component $bag = new \Illuminate\Support\MessageBag(); $bag->add('gateway_error', $e->getMessage()); - - session()->put('errors', $errors->put('default', $bag)); - - $invoice_id = $this->getContext()['payable_invoices'][0]['invoice_id']; - $this->redirectRoute('client.invoice.show', ['invoice' => $invoice_id]); + session()->flash('errors', $errors->put('default', $bag)); + + // $this->redirectRoute('client.invoices.index'); + // $invoice_id = $this->getContext()['payable_invoices'][0]['invoice_id']; + // // $this->redirectRoute('client.invoice.show', ['invoice' => $invoice_id]); $stopPropagation(); } diff --git a/app/Livewire/Flow2/RequiredFields.php b/app/Livewire/Flow2/RequiredFields.php index 9460aaeeaafe..4f8fa23ba7ee 100644 --- a/app/Livewire/Flow2/RequiredFields.php +++ b/app/Livewire/Flow2/RequiredFields.php @@ -136,4 +136,12 @@ class RequiredFields extends Component ]); } + public function exception($e, $stopPropagation) + { + + nlog($e->getMessage()); + + $stopPropagation(); + + } } diff --git a/app/PaymentDrivers/CBAPowerBoard/CreditCard.php b/app/PaymentDrivers/CBAPowerBoard/CreditCard.php index 50008d983f7b..512e7cb2f6c6 100644 --- a/app/PaymentDrivers/CBAPowerBoard/CreditCard.php +++ b/app/PaymentDrivers/CBAPowerBoard/CreditCard.php @@ -29,7 +29,7 @@ use App\PaymentDrivers\CBAPowerBoard\Models\Gateway; class CreditCard implements LivewireMethodInterface { - private Gateway $cba_gateway; + private ?Gateway $cba_gateway; public function __construct(public CBAPowerBoardPaymentDriver $powerboard) { @@ -50,8 +50,6 @@ class CreditCard implements LivewireMethodInterface { $payment_source = $this->storePaymentSource($request); - nlog($payment_source); - $browser_details = json_decode($request->browser_details, true); $payload = [ @@ -220,15 +218,15 @@ class CreditCard implements LivewireMethodInterface { $this->powerboard->init(); - if($this->cba_gateway->verification_status != "completed") - throw new PaymentFailed("This payment method is not configured as yet. Reference Powerboard portal for further information", 400); + // if(!isset($this->cba_gateway->verification_status) || $this->cba_gateway->verification_status != "completed") + // throw new PaymentFailed("This payment method is not configured as yet. Reference Powerboard portal for further information", 400); $merge = [ 'public_key' => $this->powerboard->company_gateway->getConfigField('publicKey'), 'widget_endpoint' => $this->powerboard->widget_endpoint, 'gateway' => $this->powerboard, 'environment' => $this->powerboard->environment, - 'gateway_id' => $this->cba_gateway->_id, + 'gateway_id' => $this->cba_gateway->_id ?? false, ]; return array_merge($data, $merge); diff --git a/public/build/assets/powerboard-credit-card-481ce439.js b/public/build/assets/powerboard-credit-card-481ce439.js deleted file mode 100644 index cac6f7c197d6..000000000000 --- a/public/build/assets/powerboard-credit-card-481ce439.js +++ /dev/null @@ -1,13 +0,0 @@ -import{i,w as u}from"./wait-8f4ae121.js";/** - * Invoice Ninja (https://invoiceninja.com). - * - * @link https://github.com/invoiceninja/invoiceninja source repository - * - * @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com) - * - * @license https://www.elastic.co/licensing/elastic-license - */let c=!1;function l(){const e=document.querySelector("meta[name=public_key]"),t=document.querySelector("meta[name=gateway_id]"),o=document.querySelector("meta[name=environment]"),n=new cba.HtmlWidget("#widget",e==null?void 0:e.content,t==null?void 0:t.content);n.setEnv(o==null?void 0:o.content),n.useAutoResize(),n.interceptSubmitForm("#stepone"),n.onFinishInsert('#server-response input[name="gateway_response"]',"payment_source"),n.setFormFields(["card_name*"]),n.reload();let r=document.getElementById("pay-now");return r.disabled=!1,r.querySelector("svg").classList.add("hidden"),r.querySelector("span").classList.remove("hidden"),document.querySelector('#server-response input[name="gateway_response"]').value="",n}function m(){var e,t,o;(e=document.querySelector("#widget"))==null||e.replaceChildren(),(t=document.querySelector("#widget"))==null||t.classList.remove("hidden"),(o=document.querySelector("#widget-3dsecure"))==null||o.replaceChildren()}function a(){var n;m();const e=l();e.on("finish",()=>{document.getElementById("errors").hidden=!0,y()}),e.on("submit",function(r){document.getElementById("errors").hidden=!0});let t=document.getElementById("pay-now");t.addEventListener("click",()=>{const r=document.getElementById("widget");if(e.getValidationState(),!e.isValidForm()&&r.offsetParent!==null){t.disabled=!1,t.querySelector("svg").classList.add("hidden"),t.querySelector("span").classList.remove("hidden");return}t.disabled=!0,t.querySelector("svg").classList.remove("hidden"),t.querySelector("span").classList.add("hidden");let d=document.querySelector("input[name=token-billing-checkbox]:checked");d&&(document.getElementById("store_card").value=d.value),r.offsetParent!==null?document.getElementById("stepone_submit").click():document.getElementById("server-response").submit()}),document.getElementById("toggle-payment-with-credit-card").addEventListener("click",r=>{var s;document.getElementById("widget").classList.remove("hidden"),document.getElementById("save-card--container").style.display="grid",document.querySelector("input[name=token]").value="",(s=document.querySelector("#powerboard-payment-container"))==null||s.classList.remove("hidden")}),Array.from(document.getElementsByClassName("toggle-payment-with-token")).forEach(r=>r.addEventListener("click",d=>{var s;document.getElementById("widget").classList.add("hidden"),document.getElementById("save-card--container").style.display="none",document.querySelector("input[name=token]").value=d.target.dataset.token,(s=document.querySelector("#powerboard-payment-container"))==null||s.classList.add("hidden")}));const o=document.querySelector('input[name="payment-type"]');o&&o.click(),c&&((n=document.getElementById("toggle-payment-with-credit-card"))==null||n.click())}async function y(){try{const e=await g();if(!e||!e.status||e.status==="not_authenticated"||e==="not_authenticated")throw c=!0,a(),new Error("There was an issue authenticating this payment method.");if(e.status==="authentication_not_supported"){document.querySelector('input[name="browser_details"]').value=null,document.querySelector('input[name="charge"]').value=JSON.stringify(e);let n=document.querySelector("input[name=token-billing-checkbox]:checked");return n&&(document.getElementById("store_card").value=n.value),document.getElementById("server-response").submit()}const t=new cba.Canvas3ds("#widget-3dsecure",e._3ds.token);t.load(),document.getElementById("widget").classList.add("hidden"),t.on("chargeAuthSuccess",function(n){document.querySelector('input[name="browser_details"]').value=null,document.querySelector('input[name="charge"]').value=JSON.stringify(n);let r=document.querySelector("input[name=token-billing-checkbox]:checked");r&&(document.getElementById("store_card").value=r.value),document.getElementById("server-response").submit()}),t.on("chargeAuthReject",function(n){document.getElementById("errors").textContent="Sorry, your transaction could not be processed...",document.getElementById("errors").hidden=!1,c=!0,a()}),t.load()}catch(e){const t=e.message??"Unknown error.";document.getElementById("errors").textContent=`Sorry, your transaction could not be processed... - -${t}`,document.getElementById("errors").hidden=!1,c=!0,a()}}async function g(){const e={name:navigator.userAgent.substring(0,100),java_enabled:navigator.javaEnabled()?"true":"false",language:navigator.language||navigator.userLanguage,screen_height:window.screen.height.toString(),screen_width:window.screen.width.toString(),time_zone:(new Date().getTimezoneOffset()*-1).toString(),color_depth:window.screen.colorDepth.toString()};document.querySelector('input[name="browser_details"]').value=JSON.stringify(e);const t=JSON.stringify(Object.fromEntries(new FormData(document.getElementById("server-response")))),o=document.querySelector("meta[name=payments_route]");try{const n=await fetch(o.content,{method:"POST",headers:{"Content-Type":"application/json","X-Requested-With":"XMLHttpRequest",Accept:"application/json","X-CSRF-Token":document.querySelector('meta[name="csrf-token"]').content},body:t});return n.ok?await n.json():await n.json().then(r=>{throw new Error(r.message??"Unknown error.")})}catch(n){document.getElementById("errors").textContent=`Sorry, your transaction could not be processed... - -${n.message}`,document.getElementById("errors").hidden=!1,c=!0,a()}}i()?a():u("#powerboard-credit-card-payment").then(()=>a()); diff --git a/public/build/assets/powerboard-credit-card-f5f23291.js b/public/build/assets/powerboard-credit-card-f5f23291.js new file mode 100644 index 000000000000..4bfbe65ceab5 --- /dev/null +++ b/public/build/assets/powerboard-credit-card-f5f23291.js @@ -0,0 +1,13 @@ +import{i as l,w as m}from"./wait-8f4ae121.js";/** + * Invoice Ninja (https://invoiceninja.com). + * + * @link https://github.com/invoiceninja/invoiceninja source repository + * + * @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com) + * + * @license https://www.elastic.co/licensing/elastic-license + */let i=!1;function y(){const n=document.querySelector("meta[name=public_key]"),t=document.querySelector("meta[name=gateway_id]"),r=document.querySelector("meta[name=environment]"),e=new cba.HtmlWidget("#widget",n==null?void 0:n.content,t==null?void 0:t.content);e.setEnv(r==null?void 0:r.content),e.useAutoResize(),e.interceptSubmitForm("#stepone"),e.onFinishInsert('#server-response input[name="gateway_response"]',"payment_source"),e.setFormFields(["card_name*"]),e.reload();let o=document.getElementById("pay-now");return o.disabled=!1,o.querySelector("svg").classList.add("hidden"),o.querySelector("span").classList.remove("hidden"),document.querySelector('#server-response input[name="gateway_response"]').value="",e}function g(){var n,t,r;(n=document.querySelector("#widget"))==null||n.replaceChildren(),(t=document.querySelector("#widget"))==null||t.classList.remove("hidden"),(r=document.querySelector("#widget-3dsecure"))==null||r.replaceChildren()}function a(){var o,u;if(g(),!((o=document.querySelector("meta[name=gateway_id]"))==null?void 0:o.content)){let d=document.getElementById("pay-now");d.disabled=!0,d.querySelector("svg").classList.remove("hidden"),d.querySelector("span").classList.add("hidden"),document.getElementById("errors").textContent="Gateway not found or verified",document.getElementById("errors").hidden=!1}const t=y();t.on("finish",()=>{document.getElementById("errors").hidden=!0,p()}),t.on("submit",function(d){document.getElementById("errors").hidden=!0});let r=document.getElementById("pay-now");r.addEventListener("click",()=>{const d=document.getElementById("widget");if(t.getValidationState(),!t.isValidForm()&&d.offsetParent!==null){r.disabled=!1,r.querySelector("svg").classList.add("hidden"),r.querySelector("span").classList.remove("hidden");return}r.disabled=!0,r.querySelector("svg").classList.remove("hidden"),r.querySelector("span").classList.add("hidden");let s=document.querySelector("input[name=token-billing-checkbox]:checked");s&&(document.getElementById("store_card").value=s.value),d.offsetParent!==null?document.getElementById("stepone_submit").click():document.getElementById("server-response").submit()}),document.getElementById("toggle-payment-with-credit-card").addEventListener("click",d=>{var c;document.getElementById("widget").classList.remove("hidden"),document.getElementById("save-card--container").style.display="grid",document.querySelector("input[name=token]").value="",(c=document.querySelector("#powerboard-payment-container"))==null||c.classList.remove("hidden")}),Array.from(document.getElementsByClassName("toggle-payment-with-token")).forEach(d=>d.addEventListener("click",s=>{var c;document.getElementById("widget").classList.add("hidden"),document.getElementById("save-card--container").style.display="none",document.querySelector("input[name=token]").value=s.target.dataset.token,(c=document.querySelector("#powerboard-payment-container"))==null||c.classList.add("hidden")}));const e=document.querySelector('input[name="payment-type"]');e&&e.click(),i&&((u=document.getElementById("toggle-payment-with-credit-card"))==null||u.click())}async function p(){try{const n=await h();if(!n||!n.status||n.status==="not_authenticated"||n==="not_authenticated")throw i=!0,a(),new Error("There was an issue authenticating this payment method.");if(n.status==="authentication_not_supported"){document.querySelector('input[name="browser_details"]').value=null,document.querySelector('input[name="charge"]').value=JSON.stringify(n);let e=document.querySelector("input[name=token-billing-checkbox]:checked");return e&&(document.getElementById("store_card").value=e.value),document.getElementById("server-response").submit()}const t=new cba.Canvas3ds("#widget-3dsecure",n._3ds.token);t.load(),document.getElementById("widget").classList.add("hidden"),t.on("chargeAuthSuccess",function(e){document.querySelector('input[name="browser_details"]').value=null,document.querySelector('input[name="charge"]').value=JSON.stringify(e);let o=document.querySelector("input[name=token-billing-checkbox]:checked");o&&(document.getElementById("store_card").value=o.value),document.getElementById("server-response").submit()}),t.on("chargeAuthReject",function(e){document.getElementById("errors").textContent="Sorry, your transaction could not be processed...",document.getElementById("errors").hidden=!1,i=!0,a()}),t.load()}catch(n){const t=n.message??"Unknown error.";document.getElementById("errors").textContent=`Sorry, your transaction could not be processed... + +${t}`,document.getElementById("errors").hidden=!1,i=!0,a()}}async function h(){const n={name:navigator.userAgent.substring(0,100),java_enabled:navigator.javaEnabled()?"true":"false",language:navigator.language||navigator.userLanguage,screen_height:window.screen.height.toString(),screen_width:window.screen.width.toString(),time_zone:(new Date().getTimezoneOffset()*-1).toString(),color_depth:window.screen.colorDepth.toString()};document.querySelector('input[name="browser_details"]').value=JSON.stringify(n);const t=JSON.stringify(Object.fromEntries(new FormData(document.getElementById("server-response")))),r=document.querySelector("meta[name=payments_route]");try{const e=await fetch(r.content,{method:"POST",headers:{"Content-Type":"application/json","X-Requested-With":"XMLHttpRequest",Accept:"application/json","X-CSRF-Token":document.querySelector('meta[name="csrf-token"]').content},body:t});return e.ok?await e.json():await e.json().then(o=>{throw new Error(o.message??"Unknown error.")})}catch(e){document.getElementById("errors").textContent=`Sorry, your transaction could not be processed... + +${e.message}`,document.getElementById("errors").hidden=!1,i=!0,a()}}l()?a():m("#powerboard-credit-card-payment").then(()=>a()); diff --git a/public/build/manifest.json b/public/build/manifest.json index ef2dc1190af4..971803657672 100644 --- a/public/build/manifest.json +++ b/public/build/manifest.json @@ -158,7 +158,7 @@ "src": "resources/js/clients/payments/paytrace-credit-card.js" }, "resources/js/clients/payments/powerboard-credit-card.js": { - "file": "assets/powerboard-credit-card-481ce439.js", + "file": "assets/powerboard-credit-card-f5f23291.js", "imports": [ "_wait-8f4ae121.js" ], diff --git a/resources/js/clients/payments/powerboard-credit-card.js b/resources/js/clients/payments/powerboard-credit-card.js index a06d26fb17cf..f18bd63b8813 100644 --- a/resources/js/clients/payments/powerboard-credit-card.js +++ b/resources/js/clients/payments/powerboard-credit-card.js @@ -57,6 +57,21 @@ function reload() { function pay() { reload(); + const gatewayId = document.querySelector('meta[name=gateway_id]')?.content; + + if(!gatewayId) { + + let payNow = document.getElementById('pay-now'); + payNow.disabled = true; + payNow.querySelector('svg').classList.remove('hidden'); + payNow.querySelector('span').classList.add('hidden'); + document.getElementById( + 'errors' + ).textContent = 'Gateway not found or verified'; + document.getElementById('errors').hidden = false; + + } + const widget = setup(); widget.on('finish', () => {