From 778cf73ad1c6a17d8d7c11a5cf563265e0cf248e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 14 Sep 2021 22:01:28 +1000 Subject: [PATCH] Fixes for Sofort --- app/Mail/SupportMessageSent.php | 4 +-- app/PaymentDrivers/Stripe/SOFORT.php | 4 +-- app/PaymentDrivers/StripePaymentDriver.php | 35 +++++++++++++++++++++- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/app/Mail/SupportMessageSent.php b/app/Mail/SupportMessageSent.php index 7ea23586ef73..ec371fc919e1 100644 --- a/app/Mail/SupportMessageSent.php +++ b/app/Mail/SupportMessageSent.php @@ -62,10 +62,10 @@ class SupportMessageSent extends Mailable $company = auth()->user()->company(); $user = auth()->user(); $db = str_replace("db-ninja-", "", $company->db); - $is_large = $company->is_large ? "L" : ""; + $is_large = $company->is_large ? "L" : "S"; if(Ninja::isHosted()) - $subject = "{$priority}Hosted-{$db}{$is_large} :: {$plan} :: ".date('M jS, g:ia'); + $subject = "{$priority}Hosted-{$db}-{$is_large} :: {$plan} :: ".date('M jS, g:ia'); else $subject = "{$priority}Self Hosted :: {$plan} :: ".date('M jS, g:ia'); diff --git a/app/PaymentDrivers/Stripe/SOFORT.php b/app/PaymentDrivers/Stripe/SOFORT.php index 16e046c50d1b..6f7d5d33c4d0 100644 --- a/app/PaymentDrivers/Stripe/SOFORT.php +++ b/app/PaymentDrivers/Stripe/SOFORT.php @@ -85,7 +85,7 @@ class SOFORT 'gateway_type_id' => GatewayType::SOFORT, ]; - $payment = $this->stripe->createPayment($data, Payment::STATUS_PENDING); + // $payment = $this->stripe->createPayment($data, Payment::STATUS_PENDING); SystemLogger::dispatch( ['response' => $this->stripe->payment_hash->data, 'data' => $data], @@ -96,7 +96,7 @@ class SOFORT $this->stripe->client->company, ); - return redirect()->route('client.payments.show', ['payment' => $this->stripe->encodePrimaryKey($payment->id)]); + return redirect()->route('client.payments.index'); } public function processUnsuccessfulPayment() diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 891bb9697a80..40e1e202bba5 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -22,6 +22,7 @@ use App\Models\ClientGatewayToken; use App\Models\GatewayType; use App\Models\Payment; use App\Models\PaymentHash; +use App\Models\PaymentType; use App\Models\SystemLog; use App\PaymentDrivers\Stripe\ACH; use App\PaymentDrivers\Stripe\Alipay; @@ -422,7 +423,7 @@ class StripePaymentDriver extends BaseDriver // Allow app to catch up with webhook request. sleep(2); - if ($request->type === 'charge.succeeded' || $request->type === 'source.chargeable') { + if ($request->type === 'charge.succeeded') { foreach ($request->data as $transaction) { $payment = Payment::query() ->where('transaction_reference', $transaction['id']) @@ -435,6 +436,33 @@ class StripePaymentDriver extends BaseDriver } } } + elseif($request->type === 'source.chargeable'){ + + $this->init(); + + $charge = \Stripe\Charge::create([ + 'amount' => $request->amount, + 'currency' => $request->currency, + 'source' => $request->id, + ], $this->stripe_connect_auth); + + if($charge->captured) + { + $this->setClientFromCustomer($request->customer); + + $data = [ + 'payment_method' => $request->id, + 'payment_type' => PaymentType::SOFORT, + 'amount' => $this->convertFromStripeAmount($request->amount, $this->client->currency()->precision, $this->client->currency()), + 'transaction_reference' => $charge->id, + 'gateway_type_id' => GatewayType::SOFORT, + ]; + + $payment = $this->createPayment($data, Payment::STATUS_COMPLETED); + + } + + } return response()->json([], 200); } @@ -540,6 +568,11 @@ class StripePaymentDriver extends BaseDriver return Account::all(); } + public function setClientFromCustomer($customer) + { + $this->client = ClientGatewayToken::where('gateway_customer_reference', $customer)->client; + } + /** * Pull all client payment methods and update * the respective tokens in the system.