diff --git a/app/Http/Controllers/PaymentWebhookController.php b/app/Http/Controllers/PaymentWebhookController.php index 23e8184ec141..e1884e7af149 100644 --- a/app/Http/Controllers/PaymentWebhookController.php +++ b/app/Http/Controllers/PaymentWebhookController.php @@ -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 } } } diff --git a/app/PaymentDrivers/CheckoutCom/Utilities.php b/app/PaymentDrivers/CheckoutCom/Utilities.php index 75115fe0fa69..455bc838a895 100644 --- a/app/PaymentDrivers/CheckoutCom/Utilities.php +++ b/app/PaymentDrivers/CheckoutCom/Utilities.php @@ -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); diff --git a/resources/views/portal/ninja2020/components/livewire/payments-table.blade.php b/resources/views/portal/ninja2020/components/livewire/payments-table.blade.php index 9554995a3b06..aff8fdc01ec0 100644 --- a/resources/views/portal/ninja2020/components/livewire/payments-table.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/payments-table.blade.php @@ -55,7 +55,7 @@ {!! \App\Utils\Number::formatMoney($payment->amount, $payment->client) !!} - {{ $payment->transaction_reference }} + {{ \Illuminate\Support\Str::limit($payment->transaction_reference, 35) }} {!! \App\Models\Payment::badgeForStatus($payment->status_id) !!} diff --git a/routes/api.php b/routes/api.php index 76c4fff3b51b..8291c7185c75 100644 --- a/routes/api.php +++ b/routes/api.php @@ -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');