mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Merge pull request #4419 from beganovich/v5-checkout-frames
(v5) Checkout.com migration to Frames
This commit is contained in:
commit
8ad5d14659
@ -23,14 +23,17 @@ class PaymentWebhookController extends Controller
|
||||
$this->middleware('guest');
|
||||
}
|
||||
|
||||
public function __invoke(PaymentWebhookRequest $request, string $company_key, string $gateway_key)
|
||||
public function __invoke(PaymentWebhookRequest $request, string $company_key = null, string $gateway_key = null)
|
||||
{
|
||||
$transaction_reference = $this->getTransactionReference($request->all());
|
||||
$transaction_reference = $this->getTransactionReference($request->all(), $request);
|
||||
|
||||
$payment = Payment::where('transaction_reference', $transaction_reference)->first();
|
||||
|
||||
if (is_null($payment)) {
|
||||
return response([], 404); /* Record event, throw an exception.. */
|
||||
return response([
|
||||
'message' => 'Sorry, we couldn\'t find requested payment.',
|
||||
'status_code' => 404,
|
||||
], 404); /* Record event, throw an exception.. */
|
||||
}
|
||||
|
||||
return $request
|
||||
@ -40,12 +43,16 @@ class PaymentWebhookController extends Controller
|
||||
->processWebhookRequest($request->all(), $request->company(), $request->companyGateway(), $payment);
|
||||
}
|
||||
|
||||
public function getTransactionReference(array $data)
|
||||
public function getTransactionReference(array $data, PaymentWebhookRequest $request)
|
||||
{
|
||||
$flatten = Arr::dot($data);
|
||||
|
||||
if (isset($flatten['data.object.id'])) {
|
||||
return $flatten['data.object.id']; // Request from Stripe
|
||||
return $flatten['data.object.id']; // stripe.com
|
||||
}
|
||||
|
||||
if ($request->has('cko-session-id')) {
|
||||
// checkout.com
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -105,11 +105,11 @@ class CreditCard
|
||||
}
|
||||
|
||||
private function attemptPaymentUsingCreditCard(PaymentResponseRequest $request)
|
||||
{
|
||||
{
|
||||
$checkout_response = $this->checkout->payment_hash->data->server_response;
|
||||
|
||||
$method = new TokenSource(
|
||||
$checkout_response->cardToken
|
||||
$checkout_response->token
|
||||
);
|
||||
|
||||
return $this->completePayment($method, $request);
|
||||
|
@ -60,7 +60,7 @@ trait Utilities
|
||||
'payment_method' => $_payment->source['id'],
|
||||
'payment_type' => PaymentType::parseCardType(strtolower($_payment->source['scheme'])),
|
||||
'amount' => $this->checkout->payment_hash->data->raw_value,
|
||||
'transaction_reference' => $_payment->reference,
|
||||
'transaction_reference' => $_payment->id,
|
||||
];
|
||||
|
||||
$payment = $this->checkout->createPayment($data, \App\Models\Payment::STATUS_COMPLETED);
|
||||
@ -104,9 +104,10 @@ trait Utilities
|
||||
private function processPendingPayment(Payment $_payment)
|
||||
{
|
||||
$data = [
|
||||
'payment_method' => $_payment->source['id'],
|
||||
'payment_type' => PaymentType::parseCardType(strtolower($_payment->source['scheme'])),
|
||||
'payment_method' => $_payment->source->id,
|
||||
'payment_type' => PaymentType::CREDIT_CARD_OTHER,
|
||||
'amount' => $this->checkout->payment_hash->data->value,
|
||||
'transaction_reference' => $_payment->id,
|
||||
];
|
||||
|
||||
$payment = $this->checkout->createPayment($data, \App\Models\Payment::STATUS_PENDING);
|
||||
|
2
public/js/clients/payments/checkout.com.js
vendored
2
public/js/clients/payments/checkout.com.js
vendored
@ -1,2 +1,2 @@
|
||||
/*! For license information please see checkout.com.js.LICENSE.txt */
|
||||
!function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/",n(n.s=8)}({8:function(e,t,n){e.exports=n("XYrq")},XYrq:function(e,t){document.getElementById("toggle-payment-with-token").addEventListener("click",(function(){document.getElementById("save-card--container").style.display="none",document.getElementById("checkout--container").style.display="none",document.getElementById("pay-now-with-token--container").style.display="block",document.querySelector("input[name=pay_with_token]").value=!0})),document.getElementById("toggle-payment-with-credit-card").addEventListener("click",(function(){document.getElementById("save-card--container").style.display="grid",document.getElementById("checkout--container").style.display="block",document.getElementById("pay-now-with-token--container").style.display="none",document.querySelector("input[name=pay_with_token]").value=!1}));var n=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;e&&(document.querySelector('input[name="gateway_response"]').value=JSON.stringify(e.data)),document.querySelector('input[name="store_card"]').value=document.querySelector("input[name=token-billing-checkbox]:checked").value,document.getElementById("server-response").submit()};document.getElementById("pay-now-with-token").addEventListener("click",n),window.CKOConfig={publicKey:document.querySelector('meta[name="public-key"]').content,customerEmail:document.querySelector('meta[name="customer-email"]').content,value:document.querySelector('meta[name="value"]').content,currency:document.querySelector('meta[name="currency"]').content,paymentMode:"cards",cardFormMode:"cardTokenisation",cardTokenised:function(e){n(e)}}}});
|
||||
!function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/",n(n.s=8)}({8:function(e,t,n){e.exports=n("XYrq")},XYrq:function(e,t){var n,o=document.getElementById("toggle-payment-with-token"),r=document.getElementById("toggle-payment-with-credit-card"),u=document.getElementById("pay-button"),a=document.getElementById("payment-form"),c=null!==(n=document.querySelector('meta[name="public-key"]').content)&&void 0!==n?n:"";o&&o.addEventListener("click",(function(){document.getElementById("save-card--container").style.display="none",document.getElementById("checkout--container").style.display="none",document.getElementById("pay-now-with-token--container").style.display="block",document.querySelector("input[name=pay_with_token]").value=!0})),r&&r.addEventListener("click",(function(){document.getElementById("save-card--container").style.display="grid",document.getElementById("checkout--container").style.display="block",document.getElementById("pay-now-with-token--container").style.display="none",document.querySelector("input[name=pay_with_token]").value=!1}));var d=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;e&&(document.querySelector('input[name="gateway_response"]').value=JSON.stringify(e)),document.querySelector('input[name="store_card"]').value=document.querySelector("input[name=token-billing-checkbox]:checked").value,document.getElementById("server-response").submit()};document.getElementById("pay-now-with-token")&&document.getElementById("pay-now-with-token").addEventListener("click",d),Frames.init(c),Frames.addEventHandler(Frames.Events.CARD_VALIDATION_CHANGED,(function(e){u.disabled=!Frames.isCardValid()})),Frames.addEventHandler(Frames.Events.CARD_TOKENIZED,(function(e){d(e)})),a.addEventListener("submit",(function(e){e.preventDefault(),Frames.submitCard()}))}});
|
@ -6,7 +6,7 @@
|
||||
"/js/clients/payment_methods/authorize-authorize-card.js": "/js/clients/payment_methods/authorize-authorize-card.js?id=cddcd46c630c71737bda",
|
||||
"/js/clients/payments/authorize-credit-card-payment.js": "/js/clients/payments/authorize-credit-card-payment.js?id=caff3774673a6c683e74",
|
||||
"/js/clients/payments/card-js.min.js": "/js/clients/payments/card-js.min.js?id=5469146cd629ea1b5c20",
|
||||
"/js/clients/payments/checkout.com.js": "/js/clients/payments/checkout.com.js?id=4d5d992da65a0c422291",
|
||||
"/js/clients/payments/checkout.com.js": "/js/clients/payments/checkout.com.js?id=ce184db42e52d403c21b",
|
||||
"/js/clients/payments/stripe-ach.js": "/js/clients/payments/stripe-ach.js?id=c4012ad90f17d60432ad",
|
||||
"/js/clients/payments/stripe-alipay.js": "/js/clients/payments/stripe-alipay.js?id=6dbe9316b98deea55421",
|
||||
"/js/clients/payments/stripe-credit-card.js": "/js/clients/payments/stripe-credit-card.js?id=f4659d26a26d2f408397",
|
||||
|
70
resources/js/clients/payments/checkout.com.js
vendored
70
resources/js/clients/payments/checkout.com.js
vendored
@ -8,9 +8,17 @@
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
document
|
||||
.getElementById('toggle-payment-with-token')
|
||||
.addEventListener('click', () => {
|
||||
const paymentWithToken = document.getElementById('toggle-payment-with-token');
|
||||
const paymentWithCreditCard = document.getElementById(
|
||||
'toggle-payment-with-credit-card'
|
||||
);
|
||||
const payButton = document.getElementById('pay-button');
|
||||
const form = document.getElementById('payment-form');
|
||||
const publicKey =
|
||||
document.querySelector('meta[name="public-key"]').content ?? '';
|
||||
|
||||
if (paymentWithToken) {
|
||||
paymentWithToken.addEventListener('click', () => {
|
||||
document.getElementById('save-card--container').style.display = 'none';
|
||||
document.getElementById('checkout--container').style.display = 'none';
|
||||
document.getElementById('pay-now-with-token--container').style.display =
|
||||
@ -18,10 +26,10 @@ document
|
||||
|
||||
document.querySelector('input[name=pay_with_token]').value = true;
|
||||
});
|
||||
}
|
||||
|
||||
document
|
||||
.getElementById('toggle-payment-with-credit-card')
|
||||
.addEventListener('click', () => {
|
||||
if (paymentWithCreditCard) {
|
||||
paymentWithCreditCard.addEventListener('click', () => {
|
||||
document.getElementById('save-card--container').style.display = 'grid';
|
||||
document.getElementById('checkout--container').style.display = 'block';
|
||||
document.getElementById('pay-now-with-token--container').style.display =
|
||||
@ -29,12 +37,13 @@ document
|
||||
|
||||
document.querySelector('input[name=pay_with_token]').value = false;
|
||||
});
|
||||
}
|
||||
|
||||
const completePayment = (data = null) => {
|
||||
if (data) {
|
||||
document.querySelector(
|
||||
'input[name="gateway_response"]'
|
||||
).value = JSON.stringify(data.data);
|
||||
).value = JSON.stringify(data);
|
||||
}
|
||||
|
||||
document.querySelector(
|
||||
@ -46,19 +55,36 @@ const completePayment = (data = null) => {
|
||||
document.getElementById('server-response').submit();
|
||||
};
|
||||
|
||||
document
|
||||
.getElementById('pay-now-with-token')
|
||||
.addEventListener('click', completePayment);
|
||||
if (document.getElementById('pay-now-with-token')) {
|
||||
document
|
||||
.getElementById('pay-now-with-token')
|
||||
.addEventListener('click', completePayment);
|
||||
}
|
||||
|
||||
window.CKOConfig = {
|
||||
publicKey: document.querySelector('meta[name="public-key"]').content,
|
||||
customerEmail: document.querySelector('meta[name="customer-email"]')
|
||||
.content,
|
||||
value: document.querySelector('meta[name="value"]').content,
|
||||
currency: document.querySelector('meta[name="currency"]').content,
|
||||
paymentMode: 'cards',
|
||||
cardFormMode: 'cardTokenisation',
|
||||
cardTokenised: function(event) {
|
||||
completePayment(event);
|
||||
},
|
||||
};
|
||||
// window.CKOConfig = {
|
||||
// publicKey: document.querySelector('meta[name="public-key"]').content,
|
||||
// customerEmail: document.querySelector('meta[name="customer-email"]')
|
||||
// .content,
|
||||
// value: document.querySelector('meta[name="value"]').content,
|
||||
// currency: document.querySelector('meta[name="currency"]').content,
|
||||
// paymentMode: 'cards',
|
||||
// cardFormMode: 'cardTokenisation',
|
||||
// cardTokenised: function(event) {
|
||||
// completePayment(event);
|
||||
// },
|
||||
// };
|
||||
|
||||
Frames.init(publicKey);
|
||||
|
||||
Frames.addEventHandler(Frames.Events.CARD_VALIDATION_CHANGED, function(event) {
|
||||
payButton.disabled = !Frames.isCardValid();
|
||||
});
|
||||
|
||||
Frames.addEventHandler(Frames.Events.CARD_TOKENIZED, function(event) {
|
||||
completePayment(event)
|
||||
});
|
||||
|
||||
form.addEventListener('submit', function(event) {
|
||||
event.preventDefault();
|
||||
Frames.submitCard();
|
||||
});
|
||||
|
@ -3313,4 +3313,5 @@ return [
|
||||
'shipping_country' => 'Shipping Country',
|
||||
|
||||
'service' => 'Service',
|
||||
'pay' => 'Pay',
|
||||
];
|
||||
|
@ -55,7 +55,7 @@
|
||||
{!! \App\Utils\Number::formatMoney($payment->amount, $payment->client) !!}
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500">
|
||||
{{ $payment->transaction_reference }}
|
||||
{{ \Illuminate\Support\Str::limit($payment->transaction_reference, 35) }}
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500">
|
||||
{!! \App\Models\Payment::badgeForStatus($payment->status_id) !!}
|
||||
|
@ -6,6 +6,9 @@
|
||||
<meta name="value" content="{{ $value }}">
|
||||
<meta name="currency" content="{{ $currency }}">
|
||||
<meta name="reference" content="{{ $payment_hash }}">
|
||||
|
||||
<style>*,*::after,*::before{box-sizing:border-box}html{background-color:#FFF;font-family:-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif}#payment-form{width:31.5rem;margin:0 auto}iframe{width:100%}.one-liner{display:flex;flex-direction:column}#pay-button{border:none;border-radius:3px;color:#FFF;font-weight:500;height:40px;width:100%;background-color:#13395E;box-shadow:0 1px 3px 0 rgba(19,57,94,0.4)}#pay-button:active{background-color:#0B2A49;box-shadow:0 1px 3px 0 rgba(19,57,94,0.4)}#pay-button:hover{background-color:#15406B;box-shadow:0 2px 5px 0 rgba(19,57,94,0.4)}#pay-button:disabled{background-color:#697887;box-shadow:none}#pay-button:not(:disabled){cursor:pointer}.card-frame{border:solid 1px #13395E;border-radius:3px;width:100%;margin-bottom:8px;height:40px;box-shadow:0 1px 3px 0 rgba(19,57,94,0.2)}.card-frame.frame--rendered{opacity:1}.card-frame.frame--rendered.frame--focus{border:solid 1px #13395E;box-shadow:0 2px 5px 0 rgba(19,57,94,0.15)}.card-frame.frame--rendered.frame--invalid{border:solid 1px #D96830;box-shadow:0 2px 5px 0 rgba(217,104,48,0.15)}.success-payment-message{color:#13395E;line-height:1.4}.token{color:#b35e14;font-size:0.9rem;font-family:monospace}@media screen and (min-width: 31rem){.one-liner{flex-direction:row}.card-frame{width:318px;margin-bottom:0}#pay-button{width:175px;margin-left:8px}}</style>
|
||||
<script src="https://cdn.checkout.com/js/framesv2.min.js"></script>
|
||||
@endsection
|
||||
|
||||
@section('gateway_content')
|
||||
@ -34,13 +37,16 @@
|
||||
@include('portal.ninja2020.gateways.includes.payment_details')
|
||||
|
||||
@component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.pay_with')])
|
||||
<label class="mr-4">
|
||||
<input
|
||||
type="radio"
|
||||
id="toggle-payment-with-token"
|
||||
class="form-radio cursor-pointer" name="payment-type" />
|
||||
<span class="ml-1 cursor-pointer">**** {{ $token->meta->last4 }}</span>
|
||||
</label>
|
||||
@isset($token)
|
||||
<label class="mr-4">
|
||||
<input
|
||||
type="radio"
|
||||
id="toggle-payment-with-token"
|
||||
class="form-radio cursor-pointer" name="payment-type" />
|
||||
<span class="ml-1 cursor-pointer">**** {{ $token->meta->last4 }}</span>
|
||||
</label>
|
||||
@endisset
|
||||
|
||||
<label>
|
||||
<input
|
||||
type="radio"
|
||||
@ -55,13 +61,20 @@
|
||||
@include('portal.ninja2020.gateways.includes.save_card')
|
||||
|
||||
@component('portal.ninja2020.components.general.card-element-single')
|
||||
<form class="payment-form" method="POST" action="#" id="checkout--container">
|
||||
@if(app()->environment() == 'production')
|
||||
<script async src="https://cdn.checkout.com/js/checkout.js"></script>
|
||||
@else
|
||||
<script async src="https://cdn.checkout.com/sandbox/js/checkout.js"></script>
|
||||
@endif
|
||||
</form>
|
||||
<div id="checkout--container">
|
||||
<form id="payment-form" method="POST" action="#">
|
||||
<div class="one-liner">
|
||||
<div class="card-frame">
|
||||
<!-- form will be added here -->
|
||||
</div>
|
||||
<!-- add submit button -->
|
||||
<button id="pay-button" disabled>
|
||||
{{ ctrans('texts.pay') }} {{ App\Utils\Number::formatMoney($total['amount_with_fee'], $client) }}
|
||||
</button>
|
||||
</div>
|
||||
<p class="success-payment-message"></p>
|
||||
</form>
|
||||
</div>
|
||||
@endcomponent
|
||||
|
||||
@component('portal.ninja2020.components.general.card-element-single')
|
||||
|
@ -180,6 +180,6 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a
|
||||
Route::post('support/messages/send', 'Support\Messages\SendingController');
|
||||
});
|
||||
|
||||
Route::match(['get', 'post'], 'payment_webhook/{company_key}/{gateway_key}', 'PaymentWebhookController');
|
||||
Route::match(['get', 'post'], 'payment_webhook/{company_key?}/{gateway_key?}', 'PaymentWebhookController');
|
||||
|
||||
Route::fallback('BaseController@notFound');
|
||||
|
Loading…
x
Reference in New Issue
Block a user