mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Show "Save card" option for credit card
This commit is contained in:
parent
d4c51871ef
commit
6cab52fc9f
@ -96,6 +96,10 @@ class CreditCard
|
||||
if ($result->success) {
|
||||
$this->braintree->logSuccessfulGatewayResponse(['response' => $request->server_response, 'data' => $this->braintree->payment_hash], SystemLog::TYPE_BRAINTREE);
|
||||
|
||||
if ($request->store_card) {
|
||||
$this->storePaymentMethod();
|
||||
}
|
||||
|
||||
return $this->processSuccessfulPayment($result);
|
||||
}
|
||||
|
||||
@ -155,4 +159,30 @@ class CreditCard
|
||||
|
||||
throw new PaymentFailed($response->transaction->additionalProcessorResponse, $response->transaction->processorResponseCode);
|
||||
}
|
||||
|
||||
private function storePaymentMethod()
|
||||
{
|
||||
return;
|
||||
|
||||
$method = $this->braintree->payment_hash->data->server_response->details;
|
||||
|
||||
try {
|
||||
$payment_meta = new \stdClass;
|
||||
$payment_meta->exp_month = (string) $method->expirationMonth;
|
||||
$payment_meta->exp_year = (string) $method->expirationYear;
|
||||
$payment_meta->brand = (string) $method->cardType;
|
||||
$payment_meta->last4 = (string) $method->lastFour;
|
||||
$payment_meta->type = GatewayType::CREDIT_CARD;
|
||||
|
||||
$data = [
|
||||
'payment_meta' => $payment_meta,
|
||||
'token' => $method->id,
|
||||
'payment_method_id' => $this->braintree->payment_hash->data->payment_method_id,
|
||||
];
|
||||
|
||||
$this->braintree->storeGatewayToken($data, ['gateway_customer_reference' => $customer->id]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->braintree->processInternallyFailedPayment($this->braintree, $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,6 +59,8 @@
|
||||
</label>
|
||||
@endcomponent
|
||||
|
||||
@include('portal.ninja2020.gateways.includes.save_card')
|
||||
|
||||
@component('portal.ninja2020.components.general.card-element-single')
|
||||
<div id="dropin-container"></div>
|
||||
@endcomponent
|
||||
@ -100,6 +102,15 @@
|
||||
document.querySelector('input[name=token]').value = payload.nonce;
|
||||
document.querySelector('input[name=gateway_response]').value = JSON.stringify(payload);
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
@ -16,12 +16,12 @@
|
||||
value="true"/>
|
||||
<span class="ml-1 cursor-pointer">{{ ctrans('texts.yes') }}</span>
|
||||
</label>
|
||||
<label>
|
||||
<labecoml>
|
||||
<input type="radio" class="form-radio cursor-pointer" name="token-billing-checkbox"
|
||||
id="proxy_is_default"
|
||||
value="false" checked />
|
||||
<span class="ml-1 cursor-pointer">{{ ctrans('texts.no') }}</span>
|
||||
</label>
|
||||
</labecoml>
|
||||
</dd>
|
||||
</div>
|
||||
@else
|
||||
|
Loading…
x
Reference in New Issue
Block a user