From fca1d94afe02c43bef5d7bfa05966c65652400de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 16 Nov 2020 13:36:29 +0100 Subject: [PATCH 1/4] Support for SYSTEM_LOG_TYPE in: - Authorize.net - Stripe - PayPal --- app/PaymentDrivers/AuthorizePaymentDriver.php | 3 +++ app/PaymentDrivers/PayPalExpressPaymentDriver.php | 2 ++ app/PaymentDrivers/StripePaymentDriver.php | 2 ++ 3 files changed, 7 insertions(+) diff --git a/app/PaymentDrivers/AuthorizePaymentDriver.php b/app/PaymentDrivers/AuthorizePaymentDriver.php index ec40bcaae3b7..b505d3e4e3fa 100644 --- a/app/PaymentDrivers/AuthorizePaymentDriver.php +++ b/app/PaymentDrivers/AuthorizePaymentDriver.php @@ -17,6 +17,7 @@ use App\Models\GatewayType; use App\Models\Invoice; use App\Models\Payment; use App\Models\PaymentHash; +use App\Models\SystemLog; use App\PaymentDrivers\Authorize\AuthorizeCreditCard; use App\PaymentDrivers\Authorize\AuthorizePaymentMethod; use App\PaymentDrivers\Authorize\ChargePaymentProfile; @@ -43,6 +44,8 @@ class AuthorizePaymentDriver extends BaseDriver GatewayType::CREDIT_CARD => AuthorizeCreditCard::class, ]; + const SYSTEM_LOG_TYPE = SystemLog::TYPE_AUTHORIZE; + public function setPaymentMethod($payment_method_id) { $class = self::$methods[$payment_method_id]; diff --git a/app/PaymentDrivers/PayPalExpressPaymentDriver.php b/app/PaymentDrivers/PayPalExpressPaymentDriver.php index c36b63e0b758..78e7a69ab01a 100644 --- a/app/PaymentDrivers/PayPalExpressPaymentDriver.php +++ b/app/PaymentDrivers/PayPalExpressPaymentDriver.php @@ -84,6 +84,8 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver ]; } + const SYSTEM_LOG_TYPE = SystemLog::TYPE_PAYPAL; + /** * Processes the payment with this gateway. * diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 13d761a5f26c..764fc91c2e7d 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -68,6 +68,8 @@ class StripePaymentDriver extends BaseDriver GatewayType::SEPA => 1, // TODO ]; + const SYSTEM_LOG_TYPE = SystemLog::TYPE_STRIPE; + /** * Initializes the Stripe API. * @return void From 1ab8d1322b849ae9c4c45c2b271ee9f7f5f65cdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 16 Nov 2020 13:36:47 +0100 Subject: [PATCH 2/4] Logic for getting amount in internallyFailedPayments --- app/PaymentDrivers/BaseDriver.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 1ae24f09aeeb..91539b9a5766 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -308,11 +308,13 @@ class BaseDriver extends AbstractPaymentDriver $error = $e->getBody(); } + $amount = optional($this->payment_hash->data)->value ?? optional($this->payment_hash->data)->amount; + PaymentFailureMailer::dispatch( $gateway->client, $error, $gateway->client->company, - $this->payment_hash->data->value + $amount ); SystemLogger::dispatch( From 5457838c4d6991f54ccf9412516a535ee026f705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 16 Nov 2020 13:37:13 +0100 Subject: [PATCH 3/4] Store 'amount' in payment hash (Stripe/CC) --- app/PaymentDrivers/Stripe/CreditCard.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/PaymentDrivers/Stripe/CreditCard.php b/app/PaymentDrivers/Stripe/CreditCard.php index 565b038207b7..6b72bee7107b 100644 --- a/app/PaymentDrivers/Stripe/CreditCard.php +++ b/app/PaymentDrivers/Stripe/CreditCard.php @@ -120,6 +120,16 @@ class CreditCard { $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, + 'payment_type' => PaymentType::parseCardType(strtolower($stripe_method->card->brand)), + 'amount' => $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->server_response->amount, $this->stripe->client->currency()->precision), + 'transaction_reference' => $this->stripe->payment_hash->data->server_response->id, + ]; + + $this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['amount' => $data['amount']]); + $this->stripe->payment_hash->save(); + if ($this->stripe->payment_hash->data->store_card) { $customer = $this->stripe->findOrCreateCustomer(); @@ -128,13 +138,6 @@ class CreditCard $this->storePaymentMethod($stripe_method, $this->stripe->payment_hash->data->payment_method_id, $customer); } - $data = [ - 'payment_method' => $this->stripe->payment_hash->data->server_response->payment_method, - 'payment_type' => PaymentType::parseCardType(strtolower($stripe_method->card->brand)), - 'amount' => $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->server_response->amount, $this->stripe->client->currency()->precision), - 'transaction_reference' => $this->stripe->payment_hash->data->server_response->id, - ]; - $payment = $this->stripe->createPayment($data, \App\Models\Payment::STATUS_COMPLETED); SystemLogger::dispatch( From 54014d93ee72ef885ef42a1644207e4278075ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 16 Nov 2020 14:10:45 +0100 Subject: [PATCH 4/4] pass correct $customer->id --- app/PaymentDrivers/Stripe/CreditCard.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/PaymentDrivers/Stripe/CreditCard.php b/app/PaymentDrivers/Stripe/CreditCard.php index 6b72bee7107b..7925846a7a2f 100644 --- a/app/PaymentDrivers/Stripe/CreditCard.php +++ b/app/PaymentDrivers/Stripe/CreditCard.php @@ -131,10 +131,13 @@ class CreditCard $this->stripe->payment_hash->save(); if ($this->stripe->payment_hash->data->store_card) { - $customer = $this->stripe->findOrCreateCustomer(); + $customer = new \stdClass; + $customer->id = $this->stripe->payment_hash->data->customer; $this->stripe->attach($this->stripe->payment_hash->data->server_response->payment_method, $customer); - + + $stripe_method = $this->stripe->getStripePaymentMethod($this->stripe->payment_hash->data->server_response->payment_method); + $this->storePaymentMethod($stripe_method, $this->stripe->payment_hash->data->payment_method_id, $customer); }