From f966a2b8467ff0120871cf2b7926af30fd19fbee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 9 Aug 2024 01:09:04 +0200 Subject: [PATCH] BTCPay: New payment flow (#76) * pass livewirePaymentView & processPaymentView thru base driver * add paymentData to the interface * btcpay --- app/PaymentDrivers/BTCPay/BTCPay.php | 27 ++++++++++++++++--- .../authorize-credit-card-payment-9071bd46.js | 9 +++++++ .../gateways/btcpay/pay_livewire.blade.php | 27 +++++++++++++++++++ 3 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 public/build/assets/authorize-credit-card-payment-9071bd46.js create mode 100644 resources/views/portal/ninja2020/gateways/btcpay/pay_livewire.blade.php diff --git a/app/PaymentDrivers/BTCPay/BTCPay.php b/app/PaymentDrivers/BTCPay/BTCPay.php index 8b5b3a07af..99d35c729f 100644 --- a/app/PaymentDrivers/BTCPay/BTCPay.php +++ b/app/PaymentDrivers/BTCPay/BTCPay.php @@ -14,6 +14,7 @@ namespace App\PaymentDrivers\BTCPay; use App\Models\Payment; use App\PaymentDrivers\BTCPayPaymentDriver; +use App\PaymentDrivers\Common\LivewireMethodInterface; use App\Utils\Traits\MakesHash; use App\PaymentDrivers\Common\MethodInterface; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; @@ -24,7 +25,7 @@ use App\Services\Email\EmailObject; use App\Services\Email\Email; use Illuminate\Support\Facades\App; -class BTCPay implements MethodInterface +class BTCPay implements MethodInterface, LivewireMethodInterface { use MakesHash; @@ -49,9 +50,7 @@ class BTCPay implements MethodInterface public function paymentView($data) { - $data['gateway'] = $this->driver_class; - $data['amount'] = $data['total']['amount_with_fee']; - $data['currency'] = $this->driver_class->client->getCurrencyCode(); + $data = $this->paymentData($data); return render('gateways.btcpay.pay', $data); } @@ -176,4 +175,24 @@ class BTCPay implements MethodInterface throw new PaymentFailed('Error during BTCPay refund : ' . $e->getMessage()); } } + + /** + * @inheritDoc + */ + public function livewirePaymentView(array $data): string + { + return 'gateways.btcpay.pay_livewire'; + } + + /** + * @inheritDoc + */ + public function paymentData(array $data): array + { + $data['gateway'] = $this->driver_class; + $data['amount'] = $data['total']['amount_with_fee']; + $data['currency'] = $this->driver_class->client->getCurrencyCode(); + + return $data; + } } diff --git a/public/build/assets/authorize-credit-card-payment-9071bd46.js b/public/build/assets/authorize-credit-card-payment-9071bd46.js new file mode 100644 index 0000000000..b091e94d96 --- /dev/null +++ b/public/build/assets/authorize-credit-card-payment-9071bd46.js @@ -0,0 +1,9 @@ +var l=Object.defineProperty;var s=(n,e,t)=>e in n?l(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var o=(n,e,t)=>(s(n,typeof e!="symbol"?e+"":e,t),t);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) 2021. Invoice Ninja LLC (https://invoiceninja.com) + * + * @license https://www.elastic.co/licensing/elastic-license + */class m{constructor(e,t){o(this,"handleAuthorization",()=>{if(cvvRequired=="1"&&document.getElementById("cvv").value.length<3){var e=$("#errors");e.show().html("

CVV is required

"),document.getElementById("pay-now").disabled=!1,document.querySelector("#pay-now > svg").classList.add("hidden"),document.querySelector("#pay-now > span").classList.remove("hidden");return}var t=$("#my-card"),d={};d.clientKey=this.publicKey,d.apiLoginID=this.loginId;var a={};a.cardNumber=t.CardJs("cardNumber").replace(/[^\d]/g,""),a.month=t.CardJs("expiryMonth").replace(/[^\d]/g,""),a.year=t.CardJs("expiryYear").replace(/[^\d]/g,""),a.cardCode=document.getElementById("cvv").value.replace(/[^\d]/g,"");var r={};return r.authData=d,r.cardData=a,document.getElementById("pay-now")&&(document.getElementById("pay-now").disabled=!0,document.querySelector("#pay-now > svg").classList.remove("hidden"),document.querySelector("#pay-now > span").classList.add("hidden")),Accept.dispatchData(r,this.responseHandler),!1});o(this,"responseHandler",e=>{if(e.messages.resultCode==="Error"){var t=0,d=$("#errors");d.show().html("

"+e.messages.message[t].code+": "+e.messages.message[t].text+"

"),document.getElementById("pay-now").disabled=!1,document.querySelector("#pay-now > svg").classList.add("hidden"),document.querySelector("#pay-now > span").classList.remove("hidden")}else if(e.messages.resultCode==="Ok"){document.getElementById("dataDescriptor").value=e.opaqueData.dataDescriptor,document.getElementById("dataValue").value=e.opaqueData.dataValue;let a=document.querySelector("input[name=token-billing-checkbox]:checked");a&&(document.getElementById("store_card").value=a.value),document.getElementById("server_response").submit()}return!1});o(this,"handle",()=>{Array.from(document.getElementsByClassName("toggle-payment-with-token")).forEach(d=>d.addEventListener("click",a=>{document.getElementById("save-card--container").style.display="none",document.getElementById("authorize--credit-card-container").style.display="none",document.getElementById("token").value=a.target.dataset.token}));let e=document.getElementById("toggle-payment-with-credit-card");e&&e.addEventListener("click",()=>{document.getElementById("save-card--container").style.display="grid",document.getElementById("authorize--credit-card-container").style.display="flex",document.getElementById("token").value=null});let t=document.getElementById("pay-now");return t&&t.addEventListener("click",d=>{let a=document.getElementById("token");a.value?this.handlePayNowAction(a.value):this.handleAuthorization()}),this});this.publicKey=e,this.loginId=t,this.cardHolderName=document.getElementById("cardholder_name")}handlePayNowAction(e){document.getElementById("pay-now").disabled=!0,document.querySelector("#pay-now > svg").classList.remove("hidden"),document.querySelector("#pay-now > span").classList.add("hidden"),document.getElementById("token").value=e,document.getElementById("server_response").submit()}}function c(){const n=document.querySelector('meta[name="authorize-public-key"]').content,e=document.querySelector('meta[name="authorize-login-id"]').content;document.querySelector('meta[name="authnet-require-cvv"]').content,new m(n,e).handle()}i()?c():u("#authorize-net-credit-card-payment").then(()=>c()); diff --git a/resources/views/portal/ninja2020/gateways/btcpay/pay_livewire.blade.php b/resources/views/portal/ninja2020/gateways/btcpay/pay_livewire.blade.php new file mode 100644 index 0000000000..ec3194be42 --- /dev/null +++ b/resources/views/portal/ninja2020/gateways/btcpay/pay_livewire.blade.php @@ -0,0 +1,27 @@ +
+ + + @include('portal.ninja2020.gateways.includes.payment_details') + +
+ @csrf + + + + + + + +
+ + @include('portal.ninja2020.gateways.includes.pay_now') +
+ +@script + +@endscript