mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
Support Stripe webhook
This commit is contained in:
parent
1e4e482801
commit
f68465d602
@ -13,6 +13,8 @@
|
|||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Http\Requests\Payments\PaymentWebhookRequest;
|
use App\Http\Requests\Payments\PaymentWebhookRequest;
|
||||||
|
use App\Models\Payment;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
class PaymentWebhookController extends Controller
|
class PaymentWebhookController extends Controller
|
||||||
{
|
{
|
||||||
@ -23,6 +25,27 @@ class PaymentWebhookController extends Controller
|
|||||||
|
|
||||||
public function __invoke(PaymentWebhookRequest $request, string $company_key, string $gateway_key)
|
public function __invoke(PaymentWebhookRequest $request, string $company_key, string $gateway_key)
|
||||||
{
|
{
|
||||||
return response([], 200);
|
$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.. */
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,10 @@ class PaymentWebhookRequest extends FormRequest
|
|||||||
|
|
||||||
public function company()
|
public function company()
|
||||||
{
|
{
|
||||||
|
if (!$this->company_key) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return Company::query()
|
return Company::query()
|
||||||
->where('company_key', $this->company_key)
|
->where('company_key', $this->company_key)
|
||||||
->firstOrFail();
|
->firstOrFail();
|
||||||
@ -29,6 +33,10 @@ class PaymentWebhookRequest extends FormRequest
|
|||||||
|
|
||||||
public function companyGateway()
|
public function companyGateway()
|
||||||
{
|
{
|
||||||
|
if (!$this->gateway_key || !$this->company_key) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$company = $this->company();
|
$company = $this->company();
|
||||||
|
|
||||||
return CompanyGateway::query()
|
return CompanyGateway::query()
|
||||||
|
@ -185,6 +185,7 @@ class ACH
|
|||||||
'payment_method' => $state['charge_id'],
|
'payment_method' => $state['charge_id'],
|
||||||
'payment_type' => $state['payment_type'],
|
'payment_type' => $state['payment_type'],
|
||||||
'amount' => $state['charge']->amount,
|
'amount' => $state['charge']->amount,
|
||||||
|
'gateway_type_id' => GatewayType::BANK_TRANSFER,
|
||||||
];
|
];
|
||||||
|
|
||||||
$payment = $this->stripe->createPayment($data, Payment::STATUS_PENDING);
|
$payment = $this->stripe->createPayment($data, Payment::STATUS_PENDING);
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
namespace App\PaymentDrivers\Stripe;
|
namespace App\PaymentDrivers\Stripe;
|
||||||
|
|
||||||
use App\Events\Payment\PaymentWasCreated;
|
use App\Events\Payment\PaymentWasCreated;
|
||||||
|
use App\Http\Requests\Payments\PaymentWebhookRequest;
|
||||||
use App\Jobs\Mail\PaymentFailureMailer;
|
use App\Jobs\Mail\PaymentFailureMailer;
|
||||||
use App\Jobs\Util\SystemLogger;
|
use App\Jobs\Util\SystemLogger;
|
||||||
use App\Models\GatewayType;
|
use App\Models\GatewayType;
|
||||||
|
@ -175,6 +175,7 @@ class CreditCard
|
|||||||
'payment_method' => $state['charge_id'],
|
'payment_method' => $state['charge_id'],
|
||||||
'payment_type' => $state['payment_type'],
|
'payment_type' => $state['payment_type'],
|
||||||
'amount' => $state['server_response']->amount,
|
'amount' => $state['server_response']->amount,
|
||||||
|
'gateway_type_id' => GatewayType::CREDIT_CARD,
|
||||||
];
|
];
|
||||||
|
|
||||||
$payment = $this->stripe->createPayment($data, $status = Payment::STATUS_COMPLETED);
|
$payment = $this->stripe->createPayment($data, $status = Payment::STATUS_COMPLETED);
|
||||||
|
@ -14,6 +14,7 @@ namespace App\PaymentDrivers\Stripe;
|
|||||||
|
|
||||||
use App\Events\Payment\PaymentWasCreated;
|
use App\Events\Payment\PaymentWasCreated;
|
||||||
use App\Jobs\Util\SystemLogger;
|
use App\Jobs\Util\SystemLogger;
|
||||||
|
use App\Models\Gateway;
|
||||||
use App\Models\GatewayType;
|
use App\Models\GatewayType;
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
use App\Models\PaymentType;
|
use App\Models\PaymentType;
|
||||||
@ -77,6 +78,7 @@ class SOFORT
|
|||||||
'payment_method' => $state['charge_id'],
|
'payment_method' => $state['charge_id'],
|
||||||
'payment_type' => $state['payment_type'],
|
'payment_type' => $state['payment_type'],
|
||||||
'amount' => $state['amount'],
|
'amount' => $state['amount'],
|
||||||
|
'gateway_type_id' => GatewayType::SOFORT,
|
||||||
];
|
];
|
||||||
|
|
||||||
$payment = $this->stripe->createPayment($data, Payment::STATUS_PENDING);
|
$payment = $this->stripe->createPayment($data, Payment::STATUS_PENDING);
|
||||||
|
@ -14,9 +14,12 @@ namespace App\PaymentDrivers;
|
|||||||
|
|
||||||
use App\Events\Payment\PaymentWasCreated;
|
use App\Events\Payment\PaymentWasCreated;
|
||||||
use App\Factory\PaymentFactory;
|
use App\Factory\PaymentFactory;
|
||||||
|
use App\Http\Requests\Payments\PaymentWebhookRequest;
|
||||||
use App\Jobs\Mail\PaymentFailureMailer;
|
use App\Jobs\Mail\PaymentFailureMailer;
|
||||||
use App\Jobs\Util\SystemLogger;
|
use App\Jobs\Util\SystemLogger;
|
||||||
use App\Models\ClientGatewayToken;
|
use App\Models\ClientGatewayToken;
|
||||||
|
use App\Models\Company;
|
||||||
|
use App\Models\CompanyGateway;
|
||||||
use App\Models\GatewayType;
|
use App\Models\GatewayType;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
@ -233,6 +236,7 @@ class StripePaymentDriver extends BasePaymentDriver
|
|||||||
$payment->type_id = $data['payment_type'];
|
$payment->type_id = $data['payment_type'];
|
||||||
$payment->transaction_reference = $data['payment_method'];
|
$payment->transaction_reference = $data['payment_method'];
|
||||||
$payment->client_contact_id = $client_contact_id;
|
$payment->client_contact_id = $client_contact_id;
|
||||||
|
$payment->gateway_type_id = GatewayType::ALIPAY;
|
||||||
$payment->save();
|
$payment->save();
|
||||||
|
|
||||||
return $payment;
|
return $payment;
|
||||||
@ -352,5 +356,15 @@ class StripePaymentDriver extends BasePaymentDriver
|
|||||||
return $this->payment_method->processVerification($payment_method);
|
return $this->payment_method->processVerification($payment_method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function processWebhookRequest(PaymentWebhookRequest $request, Company $company, CompanyGateway $company_gateway, Payment $payment)
|
||||||
|
{
|
||||||
|
if ($request->type == 'source.chargable') {
|
||||||
|
$payment->status_id = Payment::STATUS_COMPLETED;
|
||||||
|
$payment->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
return response([], 200);
|
||||||
|
}
|
||||||
|
|
||||||
/************************************** Omnipay API methods **********************************************************/
|
/************************************** Omnipay API methods **********************************************************/
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user