1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-19 17:42:44 +01:00
invoiceninja/app/Http/Controllers/PaymentWebhookController.php

52 lines
1.4 KiB
PHP
Raw Normal View History

2020-06-27 15:53:12 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
2020-06-27 15:53:12 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Controllers;
use App\Http\Requests\Payments\PaymentWebhookRequest;
2020-06-27 17:39:28 +02:00
use App\Models\Payment;
use Illuminate\Support\Arr;
2020-06-27 15:53:12 +02:00
class PaymentWebhookController extends Controller
{
public function __construct()
{
$this->middleware('guest');
}
public function __invoke(PaymentWebhookRequest $request, string $company_key, string $gateway_key)
{
2020-06-27 17:39:28 +02:00
$transaction_reference = $this->getTransactionReference($request->all());
$payment = Payment::where('transaction_reference', $transaction_reference)->first();
if (is_null($payment)) {
return response([], 404); /* Record event, throw an exception.. */
2020-06-27 17:39:28 +02:00
}
return $request
->companyGateway()
->driver($payment->client)
->setPaymentMethod($payment->gateway_type_id)
->processWebhookRequest($request->all(), $request->company(), $request->companyGateway(), $payment);
}
public function getTransactionReference(array $data)
{
$flatten = Arr::dot($data);
if (isset($flatten['data.object.id'])) {
return $flatten['data.object.id']; // Request from Stripe
}
2020-06-27 15:53:12 +02:00
}
}