Fixes for Checkout.com refunding

This commit is contained in:
Benjamin Beganović 2020-12-03 13:38:57 +01:00
parent 00ab670d71
commit d84f5bc5bb
4 changed files with 18 additions and 10 deletions

View File

@ -23,14 +23,17 @@ class PaymentWebhookController extends Controller
$this->middleware('guest'); $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(); $payment = Payment::where('transaction_reference', $transaction_reference)->first();
if (is_null($payment)) { 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 return $request
@ -40,12 +43,16 @@ class PaymentWebhookController extends Controller
->processWebhookRequest($request->all(), $request->company(), $request->companyGateway(), $payment); ->processWebhookRequest($request->all(), $request->company(), $request->companyGateway(), $payment);
} }
public function getTransactionReference(array $data) public function getTransactionReference(array $data, PaymentWebhookRequest $request)
{ {
$flatten = Arr::dot($data); $flatten = Arr::dot($data);
if (isset($flatten['data.object.id'])) { 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
} }
} }
} }

View File

@ -60,7 +60,7 @@ trait Utilities
'payment_method' => $_payment->source['id'], 'payment_method' => $_payment->source['id'],
'payment_type' => PaymentType::parseCardType(strtolower($_payment->source['scheme'])), 'payment_type' => PaymentType::parseCardType(strtolower($_payment->source['scheme'])),
'amount' => $this->checkout->payment_hash->data->raw_value, '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); $payment = $this->checkout->createPayment($data, \App\Models\Payment::STATUS_COMPLETED);
@ -104,9 +104,10 @@ trait Utilities
private function processPendingPayment(Payment $_payment) private function processPendingPayment(Payment $_payment)
{ {
$data = [ $data = [
'payment_method' => $_payment->source['id'], 'payment_method' => $_payment->source->id,
'payment_type' => PaymentType::parseCardType(strtolower($_payment->source['scheme'])), 'payment_type' => PaymentType::CREDIT_CARD_OTHER,
'amount' => $this->checkout->payment_hash->data->value, 'amount' => $this->checkout->payment_hash->data->value,
'transaction_reference' => $_payment->id,
]; ];
$payment = $this->checkout->createPayment($data, \App\Models\Payment::STATUS_PENDING); $payment = $this->checkout->createPayment($data, \App\Models\Payment::STATUS_PENDING);

View File

@ -55,7 +55,7 @@
{!! \App\Utils\Number::formatMoney($payment->amount, $payment->client) !!} {!! \App\Utils\Number::formatMoney($payment->amount, $payment->client) !!}
</td> </td>
<td class="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500"> <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>
<td class="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500"> <td class="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500">
{!! \App\Models\Payment::badgeForStatus($payment->status_id) !!} {!! \App\Models\Payment::badgeForStatus($payment->status_id) !!}

View File

@ -180,6 +180,6 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a
Route::post('support/messages/send', 'Support\Messages\SendingController'); 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'); Route::fallback('BaseController@notFound');