Drop token billing

This commit is contained in:
Benjamin Beganović 2021-11-02 16:30:37 +01:00
parent 697300750a
commit 25e448e31a
6 changed files with 5 additions and 163 deletions

View File

@ -100,15 +100,6 @@ class BrowserPay implements MethodInterface
*/ */
public function paymentResponse(PaymentResponseRequest $request) public function paymentResponse(PaymentResponseRequest $request)
{ {
// if ($request->shouldUseToken()) {
// $charge = \Stripe\Charge::create([
// 'amount' => $this->stripe->convertToStripeAmount($this->stripe->payment_hash->data->amount_with_fee, $this->stripe->client->currency()->precision, $this->stripe->client->currency()),
// 'currency' => $this->stripe->client->getCurrencyCode(),
// 'customer' => $this->stripe->findOrCreateCustomer()->id,
// 'source' => $request->token,
// ], $this->stripe->stripe_connect_auth);
// }
$gateway_response = json_decode($request->gateway_response); $gateway_response = json_decode($request->gateway_response);
$this->stripe->payment_hash $this->stripe->payment_hash
@ -116,46 +107,11 @@ class BrowserPay implements MethodInterface
->withData('payment_intent', PaymentIntent::retrieve($gateway_response->id, $this->stripe->stripe_connect_auth)); ->withData('payment_intent', PaymentIntent::retrieve($gateway_response->id, $this->stripe->stripe_connect_auth));
if ($gateway_response->status === 'succeeded') { if ($gateway_response->status === 'succeeded') {
if ($request->shouldStoreToken()) {
// $this->storePaymentMethod();
}
return $this->processSuccessfulPayment(); return $this->processSuccessfulPayment();
} }
return $this->processUnsuccessfulPayment(); return $this->processUnsuccessfulPayment();
} }
protected function storePaymentMethod()
{
$customer = new \stdClass;
$customer->id = $this->stripe->findOrCreateCustomer()->id;
$payment_method = $this->stripe->payment_hash->data->gateway_response->payment_method;
$this->stripe->attach($payment_method, $customer);
$method = $this->stripe->getStripePaymentMethod($payment_method);
try {
$payment_meta = new \stdClass;
$payment_meta->exp_month = (string) $method->card->exp_month;
$payment_meta->exp_year = (string) $method->card->exp_year;
$payment_meta->brand = (string) $method->card->brand;
$payment_meta->last4 = (string) $method->card->last4;
$payment_meta->type = GatewayType::APPLE_PAY;
$data = [
'payment_meta' => $payment_meta,
'token' => $method->id,
'payment_method_id' => GatewayType::APPLE_PAY,
];
$this->stripe->storeGatewayToken($data, ['gateway_customer_reference' => $customer->id]);
} catch (\Exception $e) {
return $this->stripe->processInternallyFailedPayment($this->stripe, $e);
}
}
/** /**
* Handle successful payment for browser pay. * Handle successful payment for browser pay.

View File

@ -224,7 +224,7 @@ class StripePaymentDriver extends BaseDriver
&& isset($this->client->country) && isset($this->client->country)
&& in_array($this->client->country->iso_3166_2, ['AE', 'AT', 'AU', 'BE', 'BG', 'BR', 'CA', 'CH', 'CI', 'CR', 'CY', 'CZ', 'DE', 'DK', 'DO', 'EE', 'ES', 'FI', 'FR', 'GB', 'GI', 'GR', 'GT', 'HK', 'HU', 'ID', 'IE', 'IN', 'IT', 'JP', 'LI', 'LT', 'LU', 'LV', 'MT', 'MX', 'MY', 'NL', 'NO', 'NZ', 'PE', 'PH', 'PL', 'PT', 'RO', 'SE', 'SG', 'SI', 'SK', 'SN', 'TH', 'TT', 'US', 'UY']) && in_array($this->client->country->iso_3166_2, ['AE', 'AT', 'AU', 'BE', 'BG', 'BR', 'CA', 'CH', 'CI', 'CR', 'CY', 'CZ', 'DE', 'DK', 'DO', 'EE', 'ES', 'FI', 'FR', 'GB', 'GI', 'GR', 'GT', 'HK', 'HU', 'ID', 'IE', 'IN', 'IT', 'JP', 'LI', 'LT', 'LU', 'LV', 'MT', 'MX', 'MY', 'NL', 'NO', 'NZ', 'PE', 'PH', 'PL', 'PT', 'RO', 'SE', 'SG', 'SI', 'SK', 'SN', 'TH', 'TT', 'US', 'UY'])
) { ) {
$types[] = GatewayType::SOFORT; $types[] = GatewayType::APPLE_PAY;
} }
return $types; return $types;

View File

@ -1,2 +1,2 @@
/*! For license information please see stripe-browserpay.js.LICENSE.txt */ /*! For license information please see stripe-browserpay.js.LICENSE.txt */
(()=>{function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(new(function(){function t(){var e;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),this.clientSecret=null===(e=document.querySelector("meta[name=stripe-pi-client-secret]"))||void 0===e?void 0:e.content}var n,r,o;return n=t,(r=[{key:"init",value:function(){var e,t,n={};return document.querySelector("meta[name=stripe-account-id]")&&(n.apiVersion="2020-08-27",n.stripeAccount=null===(t=document.querySelector("meta[name=stripe-account-id]"))||void 0===t?void 0:t.content),console.log(n),this.stripe=Stripe(null===(e=document.querySelector("meta[name=stripe-publishable-key]"))||void 0===e?void 0:e.content,n),this.elements=this.stripe.elements(),this}},{key:"createPaymentRequest",value:function(){return this.paymentRequest=this.stripe.paymentRequest(JSON.parse(document.querySelector("meta[name=payment-request-data").content)),this}},{key:"createPaymentRequestButton",value:function(){this.paymentRequestButton=this.elements.create("paymentRequestButton",{paymentRequest:this.paymentRequest})}},{key:"handlePaymentRequestEvents",value:function(e,t){document.querySelector("#errors").hidden=!0,this.paymentRequest.on("paymentmethod",(function(n){e.confirmCardPayment(t,{payment_method:n.paymentMethod.id},{handleActions:!1}).then((function(r){if(console.log("confirmResult",r),r.error)n.complete("fail"),document.querySelector("#errors").innerText=r.error.message,document.querySelector("#errors").hidden=!1;else if(n.complete("success"),"requires_action"===r.paymentIntent.status)e.confirmCardPayment(t).then((function(e){if(e.error)n.complete("fail"),document.querySelector("#errors").innerText=e.error.message,document.querySelector("#errors").hidden=!1;else{document.querySelector('input[name="gateway_response"]').value=JSON.stringify(e.paymentIntent);var t=document.querySelector('input[name="token-billing-checkbox"]:checked');t&&(document.querySelector('input[name="store_card"]').value=t.value),document.getElementById("server-response").submit()}}));else{document.querySelector('input[name="gateway_response"]').value=JSON.stringify(r.paymentIntent);var o=document.querySelector('input[name="token-billing-checkbox"]:checked');o&&(document.querySelector('input[name="store_card"]').value=o.value),document.getElementById("server-response").submit()}}))}))}},{key:"handleSuccess",value:function(e){document.querySelector('input[name="gateway_response"]').value=JSON.stringify(e.paymentIntent);var t=document.querySelector('input[name="token-billing-checkbox"]:checked');t&&(document.querySelector('input[name="store_card"]').value=t.value),document.getElementById("server-response").submit()}},{key:"handle",value:function(){var e=this;this.init().createPaymentRequest().createPaymentRequestButton(),this.paymentRequest.canMakePayment().then((function(t){var n;if(t)return e.paymentRequestButton.mount("#payment-request-button");document.querySelector("#errors").innerHTML=JSON.parse(null===(n=document.querySelector("meta[name=no-available-methods]"))||void 0===n?void 0:n.content),document.querySelector("#errors").hidden=!1})),this.handlePaymentRequestEvents(this.stripe,this.clientSecret),Array.from(document.getElementsByClassName("toggle-payment-with-token")).forEach((function(e){return e.addEventListener("click",(function(e){document.getElementById("payment-request-button").classList.add("hidden"),document.getElementById("save-card--container").style.display="none",document.querySelector("input[name=token]").value=e.target.dataset.token,document.querySelector(".pay-now-button-container").style.display="block"}))})),document.getElementById("toggle-payment-with-credit-card").addEventListener("click",(function(e){document.getElementById("payment-request-button").classList.remove("hidden"),document.getElementById("save-card--container").style.display="grid",document.querySelector("input[name=token]").value="",document.querySelector(".pay-now-button-container").style.display="none"})),document.getElementById("pay-now").addEventListener("click",(function(e){e.target.parentElement.disabled=!0,document.querySelector("#server-response").submit()})),document.querySelector(".pay-now-button-container").style.display="none"}}])&&e(n.prototype,r),o&&e(n,o),t}())).handle()})(); (()=>{function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(new(function(){function t(){var e;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),this.clientSecret=null===(e=document.querySelector("meta[name=stripe-pi-client-secret]"))||void 0===e?void 0:e.content}var n,r,o;return n=t,(r=[{key:"init",value:function(){var e,t,n={};return document.querySelector("meta[name=stripe-account-id]")&&(n.apiVersion="2020-08-27",n.stripeAccount=null===(t=document.querySelector("meta[name=stripe-account-id]"))||void 0===t?void 0:t.content),this.stripe=Stripe(null===(e=document.querySelector("meta[name=stripe-publishable-key]"))||void 0===e?void 0:e.content,n),this.elements=this.stripe.elements(),this}},{key:"createPaymentRequest",value:function(){return this.paymentRequest=this.stripe.paymentRequest(JSON.parse(document.querySelector("meta[name=payment-request-data").content)),this}},{key:"createPaymentRequestButton",value:function(){this.paymentRequestButton=this.elements.create("paymentRequestButton",{paymentRequest:this.paymentRequest})}},{key:"handlePaymentRequestEvents",value:function(e,t){document.querySelector("#errors").hidden=!0,this.paymentRequest.on("paymentmethod",(function(n){e.confirmCardPayment(t,{payment_method:n.paymentMethod.id},{handleActions:!1}).then((function(r){r.error?(n.complete("fail"),document.querySelector("#errors").innerText=r.error.message,document.querySelector("#errors").hidden=!1):(n.complete("success"),"requires_action"===r.paymentIntent.status?e.confirmCardPayment(t).then((function(e){e.error?(n.complete("fail"),document.querySelector("#errors").innerText=e.error.message,document.querySelector("#errors").hidden=!1):(document.querySelector('input[name="gateway_response"]').value=JSON.stringify(e.paymentIntent),document.getElementById("server-response").submit())})):(document.querySelector('input[name="gateway_response"]').value=JSON.stringify(r.paymentIntent),document.getElementById("server-response").submit()))}))}))}},{key:"handle",value:function(){var e=this;this.init().createPaymentRequest().createPaymentRequestButton(),this.paymentRequest.canMakePayment().then((function(t){var n;if(t)return e.paymentRequestButton.mount("#payment-request-button");document.querySelector("#errors").innerHTML=JSON.parse(null===(n=document.querySelector("meta[name=no-available-methods]"))||void 0===n?void 0:n.content),document.querySelector("#errors").hidden=!1})),this.handlePaymentRequestEvents(this.stripe,this.clientSecret)}}])&&e(n.prototype,r),o&&e(n,o),t}())).handle()})();

View File

@ -36,7 +36,7 @@
"/js/clients/payments/stripe-eps.js": "/js/clients/payments/stripe-eps.js?id=1ed972f879869de66c8a", "/js/clients/payments/stripe-eps.js": "/js/clients/payments/stripe-eps.js?id=1ed972f879869de66c8a",
"/js/clients/payments/stripe-ideal.js": "/js/clients/payments/stripe-ideal.js?id=73ce56676f9252b0cecf", "/js/clients/payments/stripe-ideal.js": "/js/clients/payments/stripe-ideal.js?id=73ce56676f9252b0cecf",
"/js/clients/payments/stripe-przelewy24.js": "/js/clients/payments/stripe-przelewy24.js?id=f3a14f78bec8209c30ba", "/js/clients/payments/stripe-przelewy24.js": "/js/clients/payments/stripe-przelewy24.js?id=f3a14f78bec8209c30ba",
"/js/clients/payments/stripe-browserpay.js": "/js/clients/payments/stripe-browserpay.js?id=77aa2fbcc375c0f569a1", "/js/clients/payments/stripe-browserpay.js": "/js/clients/payments/stripe-browserpay.js?id=71e49866d66a6d85b88a",
"/css/app.css": "/css/app.css?id=317a907834a0db9f8d41", "/css/app.css": "/css/app.css?id=317a907834a0db9f8d41",
"/css/card-js.min.css": "/css/card-js.min.css?id=62afeb675235451543ad" "/css/card-js.min.css": "/css/card-js.min.css?id=62afeb675235451543ad"
} }

View File

@ -26,10 +26,9 @@ class StripeBrowserPay {
)?.content; )?.content;
} }
console.log(config);
this.stripe = Stripe( this.stripe = Stripe(
document.querySelector('meta[name=stripe-publishable-key]')?.content, document.querySelector('meta[name=stripe-publishable-key]')
?.content,
config config
); );
@ -68,8 +67,6 @@ class StripeBrowserPay {
{ handleActions: false } { handleActions: false }
) )
.then(function (confirmResult) { .then(function (confirmResult) {
console.log('confirmResult', confirmResult);
if (confirmResult.error) { if (confirmResult.error) {
ev.complete('fail'); ev.complete('fail');
@ -104,18 +101,6 @@ class StripeBrowserPay {
result.paymentIntent result.paymentIntent
); );
let tokenBillingCheckbox =
document.querySelector(
'input[name="token-billing-checkbox"]:checked'
);
if (tokenBillingCheckbox) {
document.querySelector(
'input[name="store_card"]'
).value =
tokenBillingCheckbox.value;
}
document document
.getElementById('server-response') .getElementById('server-response')
.submit(); .submit();
@ -128,16 +113,6 @@ class StripeBrowserPay {
confirmResult.paymentIntent confirmResult.paymentIntent
); );
let tokenBillingCheckbox = document.querySelector(
'input[name="token-billing-checkbox"]:checked'
);
if (tokenBillingCheckbox) {
document.querySelector(
'input[name="store_card"]'
).value = tokenBillingCheckbox.value;
}
document.getElementById('server-response').submit(); document.getElementById('server-response').submit();
} }
} }
@ -145,22 +120,6 @@ class StripeBrowserPay {
}); });
} }
handleSuccess(result) {
document.querySelector('input[name="gateway_response"]').value =
JSON.stringify(result.paymentIntent);
let tokenBillingCheckbox = document.querySelector(
'input[name="token-billing-checkbox"]:checked'
);
if (tokenBillingCheckbox) {
document.querySelector('input[name="store_card"]').value =
tokenBillingCheckbox.value;
}
document.getElementById('server-response').submit();
}
handle() { handle() {
this.init().createPaymentRequest().createPaymentRequestButton(); this.init().createPaymentRequest().createPaymentRequestButton();
@ -180,50 +139,6 @@ class StripeBrowserPay {
}); });
this.handlePaymentRequestEvents(this.stripe, this.clientSecret); this.handlePaymentRequestEvents(this.stripe, this.clientSecret);
Array.from(
document.getElementsByClassName('toggle-payment-with-token')
).forEach((element) =>
element.addEventListener('click', (element) => {
document
.getElementById('payment-request-button')
.classList.add('hidden');
document.getElementById('save-card--container').style.display =
'none';
document.querySelector('input[name=token]').value =
element.target.dataset.token;
document.querySelector(
'.pay-now-button-container'
).style.display = 'block';
})
);
document
.getElementById('toggle-payment-with-credit-card')
.addEventListener('click', (element) => {
document
.getElementById('payment-request-button')
.classList.remove('hidden');
document.getElementById('save-card--container').style.display =
'grid';
document.querySelector('input[name=token]').value = '';
document.querySelector(
'.pay-now-button-container'
).style.display = 'none';
});
document
.getElementById('pay-now')
.addEventListener('click', (event) => {
event.target.parentElement.disabled = true;
document.querySelector('#server-response').submit();
});
document.querySelector('.pay-now-button-container').style.display =
'none';
} }
} }

View File

@ -28,38 +28,9 @@
@include('portal.ninja2020.gateways.includes.payment_details') @include('portal.ninja2020.gateways.includes.payment_details')
@component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.pay_with')])
@if(count($tokens) > 0)
@foreach($tokens as $token)
<label class="mr-4">
<input
type="radio"
data-token="{{ $token->token }}"
name="payment-type"
class="form-radio cursor-pointer toggle-payment-with-token"/>
<span class="ml-1 cursor-pointer">**** {{ optional($token->meta)->last4 }}</span>
</label>
@endforeach
@endisset
<label>
<input
type="radio"
id="toggle-payment-with-credit-card"
class="form-radio cursor-pointer"
name="payment-type"
checked/>
<span class="ml-1 cursor-pointer">{{ __('texts.new_card') }}</span>
</label>
@endcomponent
@component('portal.ninja2020.components.general.card-element-single') @component('portal.ninja2020.components.general.card-element-single')
<div id="payment-request-button"></div> <div id="payment-request-button"></div>
@endcomponent @endcomponent
<div class="pay-now-button-container">
@include('portal.ninja2020.gateways.includes.pay_now')
</div>
@endsection @endsection
@section('gateway_footer') @section('gateway_footer')