1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00

Storing payment method

This commit is contained in:
Benjamin Beganović 2021-11-01 14:58:10 +01:00
parent dcfc3fd827
commit 69e12dbdb9
3 changed files with 78 additions and 1 deletions

View File

@ -112,7 +112,7 @@ class BrowserPay implements MethodInterface
if ($gateway_response->status === 'succeeded') {
if ($request->shouldStoreToken()) {
//
$this->storePaymentMethod();
}
return $this->processSuccessfulPayment();
@ -120,6 +120,37 @@ class BrowserPay implements MethodInterface
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.

View File

@ -91,6 +91,15 @@ class StripeBrowserPay {
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();
@ -103,6 +112,15 @@ class StripeBrowserPay {
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();
}
}

View File

@ -20,12 +20,40 @@
<input type="hidden" name="payment_hash" value="{{ $payment_hash }}">
<input type="hidden" name="company_gateway_id" value="{{ $gateway->getCompanyGatewayId() }}">
<input type="hidden" name="payment_method_id" value="{{ $payment_method_id }}">
<input type="hidden" name="store_card">
</form>
<div class="alert alert-failure mb-4" hidden id="errors"></div>
@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
@include('portal.ninja2020.gateways.includes.save_card')
@component('portal.ninja2020.components.general.card-element-single')
<div id="payment-request-button"></div>
@endcomponent