fix stripe refunding & apply php-cs-fixer

This commit is contained in:
Benjamin Beganović 2020-12-01 13:46:09 +01:00
parent 4368dc7272
commit b373a3df52
3 changed files with 46 additions and 34 deletions

View File

@ -116,9 +116,10 @@ class CreditCard
'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,
'transaction_reference' => optional($this->stripe->payment_hash->data->payment_intent->charges->data[0])->id,
];
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['amount' => $data['amount']]);
$this->stripe->payment_hash->save();

View File

@ -279,7 +279,7 @@ class StripePaymentDriver extends BaseDriver
}
if (!$customer) {
throw new Exception('Unable to create gateway customer');
throw new \Exception('Unable to create gateway customer');
}
return $customer;
@ -289,17 +289,16 @@ class StripePaymentDriver extends BaseDriver
{
$this->init();
/** Response from Stripe SDK/API. */
$response = null;
try {
$response = $this->stripe
->refunds
->create(['charge' => $payment->transaction_reference, 'amount' => $amount]);
// $response = $this->gateway
// ->refund(['transactionReference' => $payment->transaction_reference, 'amount' => $amount, 'currency' => $payment->client->getCurrencyCode()])
// ->send();
->create(['charge' => $payment->transaction_reference, 'amount' => $this->convertToStripeAmount($amount, $this->client->currency()->precision)]);
if ($response->status == $response::STATUS_SUCCEEDED) {
SystemLogger::dispatch(['server_response' => $response, 'data' => request()->all(),
], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_STRIPE, $this->client);
SystemLogger::dispatch(['server_response' => $response, 'data' => request()->all(),], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_STRIPE, $this->client);
return [
'transaction_reference' => $response->charge,
@ -310,8 +309,7 @@ class StripePaymentDriver extends BaseDriver
];
}
SystemLogger::dispatch(['server_response' => $response, 'data' => request()->all(),
], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->client);
SystemLogger::dispatch(['server_response' => $response, 'data' => request()->all(),], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->client);
return [
'transaction_reference' => null,
@ -320,6 +318,19 @@ class StripePaymentDriver extends BaseDriver
'description' => $response->failure_reason,
'code' => 422,
];
} catch (\Exception $e) {
SystemLogger::dispatch(['server_response' => $response, 'data' => request()->all(),], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->client);
info($e->getMessage());
return [
'transaction_reference' => null,
'transaction_response' => json_encode($response),
'success' => false,
'description' => $e->getMessage(),
'code' => 422,
];
}
}
public function verificationView(ClientGatewayToken $payment_method)