1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 08:21:34 +02:00

Redirect after payment

This commit is contained in:
Lars Kusch 2022-12-17 14:22:03 +01:00
parent d67fc2d493
commit f897df733a
4 changed files with 15 additions and 94 deletions

View File

@ -42,12 +42,12 @@ class BACS
'payment_method_types' => ['bacs_debit'],
'mode' => 'setup',
'customer' => $customer->id,
'success_url' => str_replace("%7B", "{", str_replace("%7D", "}", $this->buildReturnUrl())),
'success_url' => str_replace("%7B", "{", str_replace("%7D", "}", $this->buildAuthorizeUrl())),
'cancel_url' => route('client.payment_methods.index'),
]);
return render('gateways.stripe.bacs.authorize', $data);
}
private function buildReturnUrl(): string
private function buildAuthorizeUrl(): string
{
return route('client.payment_methods.confirm', [
'method' => GatewayType::BACS,
@ -68,6 +68,13 @@ class BACS
}
return redirect()->route('client.payment_methods.index');
}
private function buildPaymentUrl(): string
{
return route('client.payments.response', [
'method' => GatewayType::BACS,
'session_id' => "{CHECKOUT_SESSION_ID}",
]);
}
public function paymentView(array $data)
{
@ -90,13 +97,14 @@ class BACS
$data['intent'] = $this->stripe->createPaymentIntent($payment_intent_data);
$data['gateway'] = $this->stripe;
$data['payment_url'] = $this->buildPaymentUrl();
return render('gateways.stripe.bacs.pay', $data);
}
public function paymentResponse(PaymentResponseRequest $request)
{
$this->stripe->init();
nlog($request);
$state = [
'server_response' => json_decode($request->gateway_response),
'payment_hash' => $request->payment_hash,

View File

@ -1,79 +1,2 @@
/**
* 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 ProcessBACS {
constructor(key, stripeConnect) {
this.key = key;
this.errors = document.getElementById('errors');
this.stripeConnect = stripeConnect;
this.onlyAuthorization = onlyAuthorization;
}
setupStripe = () => {
if (this.stripeConnect){
// this.stripe.stripeAccount = this.stripeConnect;
this.stripe = Stripe(this.key, {
stripeAccount: this.stripeConnect,
});
}
else {
this.stripe = Stripe(this.key);
}
return this;
};
handle = () => {
if (this.onlyAuthorization) {
document.getElementById('authorize-bacs').addEventListener('click', (e) => {
document.getElementById('authorize-bacs').disabled = true;
document.querySelector('#authorize-bacs > svg').classList.remove('hidden');
document.querySelector('#authorize-bacs > span').classList.add('hidden');
location.href=document.querySelector('meta[name=stripe-redirect-url').content;
});}
else{
document.getElementById('pay-now').addEventListener('click', (e) => {
let token = document.querySelector('input[name=token]').value;
let payNowButton = document.getElementById('pay-now');
this.payNowButton = payNowButton;
this.payNowButton.disabled = true;
this.payNowButton.querySelector('svg').classList.remove('hidden');
this.payNowButton.querySelector('span').classList.add('hidden');
this.stripe.confirmBecsDebitPayment(
document.querySelector('meta[name=stripe-secret')
.content,
{}
).then((result) => {
if (result.error) {
return this.handleFailure(result.error.message);
}
return this.handleSuccess(result);
});
});
}
};
}
const publishableKey = document.querySelector(
'meta[name="stripe-publishable-key"]'
)?.content ?? '';
const stripeConnect =
document.querySelector('meta[name="stripe-account-id"]')?.content ?? '';
const onlyAuthorization =
document.querySelector('meta[name="only-authorization"]')?.content ?? '';
new ProcessBACS(publishableKey, stripeConnect).setupStripe().handle();
/*! For license information please see stripe-bacs.js.LICENSE.txt */
(()=>{var e,t,n,o,r,i;function a(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function c(e,t,n){return t&&a(e.prototype,t),n&&a(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function u(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var l=c((function e(t,n){var o=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),u(this,"setupStripe",(function(){return o.stripeConnect?o.stripe=Stripe(o.key,{stripeAccount:o.stripeConnect}):o.stripe=Stripe(o.key),o})),u(this,"handle",(function(){o.onlyAuthorization?document.getElementById("authorize-bacs").addEventListener("click",(function(e){document.getElementById("authorize-bacs").disabled=!0,document.querySelector("#authorize-bacs > svg").classList.remove("hidden"),document.querySelector("#authorize-bacs > span").classList.add("hidden"),location.href=document.querySelector("meta[name=stripe-redirect-url").content})):document.getElementById("pay-now").addEventListener("click",(function(e){var t=document.querySelector("input[name=token]").value,n=document.getElementById("pay-now");o.payNowButton=n,o.payNowButton.disabled=!0,o.payNowButton.querySelector("svg").classList.remove("hidden"),o.payNowButton.querySelector("span").classList.add("hidden"),location.href=document.querySelector("meta[name=redirect-url").content+"&payment_id="+t}))})),this.key=t,this.errors=document.getElementById("errors"),this.stripeConnect=n,this.onlyAuthorization=y})),d=null!==(e=null===(t=document.querySelector('meta[name="stripe-publishable-key"]'))||void 0===t?void 0:t.content)&&void 0!==e?e:"",s=null!==(n=null===(o=document.querySelector('meta[name="stripe-account-id"]'))||void 0===o?void 0:o.content)&&void 0!==n?n:"",y=null!==(r=null===(i=document.querySelector('meta[name="only-authorization"]'))||void 0===i?void 0:i.content)&&void 0!==r?r:"";new l(d,s).setupStripe().handle()})();

View File

@ -50,18 +50,7 @@ class ProcessBACS {
this.payNowButton.disabled = true;
this.payNowButton.querySelector('svg').classList.remove('hidden');
this.payNowButton.querySelector('span').classList.add('hidden');
this.stripe.confirmBecsDebitPayment(
document.querySelector('meta[name=stripe-secret')
.content,
{}
).then((result) => {
if (result.error) {
return this.handleFailure(result.error.message);
}
return this.handleSuccess(result);
});
location.href=document.querySelector('meta[name=redirect-url').content + "&payment_id=" + token;
});
}
};

View File

@ -9,6 +9,7 @@
@endif
<meta name="only-authorization" content="">
<meta name="stripe-secret" content="{{ $intent->client_secret }}">
<meta name="redirect-url" content="{{ $payment_url }}">
@endsection
@section('gateway_content')