Updates for powerboard

This commit is contained in:
David Bomba 2024-09-25 12:03:33 +10:00
parent aca1f3c413
commit 55b38a2172
8 changed files with 46 additions and 26 deletions

View File

@ -80,7 +80,6 @@ class PaymentMethod extends Component
{
nlog($e->getMessage());
$stopPropagation();
}

View File

@ -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();
}

View File

@ -136,4 +136,12 @@ class RequiredFields extends Component
]);
}
public function exception($e, $stopPropagation)
{
nlog($e->getMessage());
$stopPropagation();
}
}

View File

@ -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);

View File

@ -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());

View File

@ -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());

View File

@ -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"
],

View File

@ -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', () => {