Merge pull request #4311 from beganovich/v5-stripe-failure

(v5) Fix bug with Stripe saving credit card
This commit is contained in:
Benjamin Beganović 2020-11-16 22:19:38 +01:00 committed by GitHub
commit b886ceac4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 9 deletions

View File

@ -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];

View File

@ -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(

View File

@ -84,6 +84,8 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver
];
}
const SYSTEM_LOG_TYPE = SystemLog::TYPE_PAYPAL;
/**
* Processes the payment with this gateway.
*

View File

@ -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(

View File

@ -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