mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Added SEPA-Payment
This commit is contained in:
parent
36a6211146
commit
fc9dcd135d
@ -12,22 +12,20 @@
|
|||||||
|
|
||||||
namespace App\PaymentDrivers\Stripe;
|
namespace App\PaymentDrivers\Stripe;
|
||||||
|
|
||||||
use App\Exceptions\PaymentFailed;
|
|
||||||
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
|
|
||||||
use App\Jobs\Mail\PaymentFailureMailer;
|
|
||||||
use App\Jobs\Util\SystemLogger;
|
|
||||||
use App\Models\GatewayType;
|
use App\Models\GatewayType;
|
||||||
use App\Models\Payment;
|
|
||||||
use App\Models\PaymentType;
|
|
||||||
use App\Models\SystemLog;
|
use App\Models\SystemLog;
|
||||||
use App\PaymentDrivers\StripePaymentDriver;
|
use App\PaymentDrivers\StripePaymentDriver;
|
||||||
use App\PaymentDrivers\Stripe\CreditCard;
|
use Stripe\PaymentMethod;
|
||||||
use App\Utils\Ninja;
|
use App\Exceptions\PaymentFailed;
|
||||||
|
use App\Jobs\Mail\PaymentFailureMailer;
|
||||||
|
use App\Jobs\Util\SystemLogger;
|
||||||
|
use App\Models\Payment;
|
||||||
|
use Stripe\PaymentIntent;
|
||||||
|
|
||||||
class SEPA
|
class SEPA
|
||||||
{
|
{
|
||||||
/** @var StripePaymentDriver */
|
/** @var StripePaymentDriver */
|
||||||
public $stripe_driver;
|
public StripePaymentDriver $stripe;
|
||||||
|
|
||||||
public function __construct(StripePaymentDriver $stripe_driver)
|
public function __construct(StripePaymentDriver $stripe_driver)
|
||||||
{
|
{
|
||||||
@ -46,18 +44,18 @@ class SEPA
|
|||||||
$client_secret = $setup_intent->client_secret;
|
$client_secret = $setup_intent->client_secret;
|
||||||
// Pass the client secret to the client
|
// Pass the client secret to the client
|
||||||
|
|
||||||
|
|
||||||
$data['gateway'] = $this->stripe;
|
$data['gateway'] = $this->stripe;
|
||||||
|
|
||||||
return render('gateways.stripe.sepa.authorize', array_merge($data));
|
return render('gateways.stripe.sepa.authorize', array_merge($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function paymentView(array $data)
|
||||||
public function paymentResponse(PaymentResponseRequest $request)
|
|
||||||
{
|
{
|
||||||
|
// TODO: implement paymentView
|
||||||
|
}
|
||||||
|
|
||||||
$this->stripe_driver->init();
|
public function paymentResponse($request)
|
||||||
|
{
|
||||||
$state = [
|
$state = [
|
||||||
'server_response' => json_decode($request->gateway_response),
|
'server_response' => json_decode($request->gateway_response),
|
||||||
'payment_hash' => $request->payment_hash,
|
'payment_hash' => $request->payment_hash,
|
||||||
@ -72,38 +70,76 @@ class SEPA
|
|||||||
|
|
||||||
$server_response = $this->stripe_driver->payment_hash->data->server_response;
|
$server_response = $this->stripe_driver->payment_hash->data->server_response;
|
||||||
|
|
||||||
$response_handler = new SEPAAccount($this->stripe_driver);
|
$response_handler = new SEPA($this->stripe_driver);
|
||||||
|
|
||||||
if ($server_response->status == 'succeeded') {
|
if ($server_response->status == 'succeeded') {
|
||||||
|
|
||||||
$this->stripe_driver->logSuccessfulGatewayResponse(['response' => json_decode($request->gateway_response), 'data' => $this->stripe_driver->payment_hash], SystemLog::TYPE_STRIPE);
|
$this->stripe_driver->logSuccessfulGatewayResponse(['response' => json_decode($request->gateway_response), 'data' => $this->stripe_driver->payment_hash], SystemLog::TYPE_STRIPE);
|
||||||
|
|
||||||
return $response_handler->processSuccessfulPayment();
|
return $response_handler->processSuccessfulPayment($state);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $response_handler->processUnsuccessfulPayment($server_response);
|
return $response_handler->processUnsuccessfulPayment($state);
|
||||||
|
}
|
||||||
|
public function processSuccessfulPayment($server_response)
|
||||||
|
{
|
||||||
|
$stripe_method = $this->stripe->getStripePaymentMethod($this->stripe->payment_hash->data->server_response->payment_method);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'payment_method' => $this->stripe->payment_hash->data->server_response->payment_method,
|
||||||
|
'amount' => $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->server_response->amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()),
|
||||||
|
'transaction_reference' => optional($this->stripe->payment_hash->data->payment_intent->charges->data[0])->id,
|
||||||
|
'gateway_type_id' => GatewayType::SEPA,
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['amount' => $data['amount']]);
|
||||||
|
$this->stripe->payment_hash->save();
|
||||||
|
|
||||||
|
$payment = $this->stripe->createPayment($data, Payment::STATUS_COMPLETED);
|
||||||
|
|
||||||
|
SystemLogger::dispatch(
|
||||||
|
['response' => $this->stripe->payment_hash->data->server_response, 'data' => $data],
|
||||||
|
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
||||||
|
SystemLog::EVENT_GATEWAY_SUCCESS,
|
||||||
|
SystemLog::TYPE_STRIPE,
|
||||||
|
$this->stripe->client,
|
||||||
|
$this->stripe->client->company,
|
||||||
|
);
|
||||||
|
|
||||||
|
return redirect()->route('client.payments.show', ['payment' => $this->stripe->encodePrimaryKey($payment->id)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Searches for a stripe customer by email
|
public function processUnsuccessfullyPayment($server_response)
|
||||||
otherwise searches by gateway tokens in StripePaymentdriver
|
|
||||||
finally creates a new customer if none found
|
|
||||||
*/
|
|
||||||
private function getCustomer()
|
|
||||||
{
|
{
|
||||||
$searchResults = \Stripe\Customer::all([
|
PaymentFailureMailer::dispatch($this->stripe->client, $server_response->cancellation_reason, $this->stripe->client->company, $server_response->amount);
|
||||||
"email" => $this->stripe_driver->client->present()->email(),
|
|
||||||
"limit" => 1,
|
|
||||||
"starting_after" => null
|
|
||||||
], $this->stripe_driver->stripe_connect_auth);
|
|
||||||
|
|
||||||
|
|
||||||
if(count($searchResults) >= 1)
|
PaymentFailureMailer::dispatch(
|
||||||
return $searchResults[0];
|
$this->stripe->client,
|
||||||
|
$server_response,
|
||||||
|
$this->stripe->client->company,
|
||||||
|
$server_response->amount
|
||||||
|
);
|
||||||
|
|
||||||
return $this->stripe_driver->findOrCreateCustomer();
|
$message = [
|
||||||
|
'server_response' => $server_response,
|
||||||
|
'data' => $this->stripe->payment_hash->data,
|
||||||
|
];
|
||||||
|
|
||||||
}
|
SystemLogger::dispatch(
|
||||||
|
$message,
|
||||||
|
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
||||||
|
SystemLog::EVENT_GATEWAY_FAILURE,
|
||||||
|
SystemLog::TYPE_STRIPE,
|
||||||
|
$this->stripe->client,
|
||||||
|
$this->stripe->client->company,
|
||||||
|
);
|
||||||
|
|
||||||
|
throw new PaymentFailed('Failed to process the payment.', 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function storePaymentMethod(PaymentMethod $method, $payment_method_id, $customer)
|
||||||
|
{
|
||||||
|
// TODO: implement storePaymentMethod
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user