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/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( 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/Stripe/CreditCard.php b/app/PaymentDrivers/Stripe/CreditCard.php index 565b038207b7..7925846a7a2f 100644 --- a/app/PaymentDrivers/Stripe/CreditCard.php +++ b/app/PaymentDrivers/Stripe/CreditCard.php @@ -120,14 +120,6 @@ class CreditCard { $stripe_method = $this->stripe->getStripePaymentMethod($this->stripe->payment_hash->data->server_response->payment_method); - if ($this->stripe->payment_hash->data->store_card) { - $customer = $this->stripe->findOrCreateCustomer(); - - $this->stripe->attach($this->stripe->payment_hash->data->server_response->payment_method, $customer); - - $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)), @@ -135,6 +127,20 @@ class CreditCard '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 = 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); + } + $payment = $this->stripe->createPayment($data, \App\Models\Payment::STATUS_COMPLETED); SystemLogger::dispatch( 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