Stripe refunds

This commit is contained in:
Benjamin Beganović 2020-06-24 16:07:12 +02:00
parent 4d2d41123b
commit f6f999b801

View File

@ -1,4 +1,5 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
@ -73,7 +74,7 @@ class StripePaymentDriver extends BasePaymentDriver
* Initializes the Stripe API
* @return void
*/
public function init() :void
public function init(): void
{
Stripe::setApiKey($this->company_gateway->getConfigField('apiKey'));
}
@ -90,7 +91,7 @@ class StripePaymentDriver extends BasePaymentDriver
/**
* Returns the gateway types
*/
public function gatewayTypes() :array
public function gatewayTypes(): array
{
$types = [
GatewayType::CREDIT_CARD,
@ -221,7 +222,7 @@ class StripePaymentDriver extends BasePaymentDriver
return $this->payment_method->paymentResponse($request);
}
public function createPayment($data, $status = Payment::STATUS_COMPLETED) :Payment
public function createPayment($data, $status = Payment::STATUS_COMPLETED): Payment
{
$payment = parent::createPayment($data, $status);
@ -243,7 +244,7 @@ class StripePaymentDriver extends BasePaymentDriver
* @param array $data The data array to be passed to Stripe
* @return PaymentIntent The Stripe payment intent object
*/
public function createPaymentIntent($data) :?\Stripe\PaymentIntent
public function createPaymentIntent($data): ?\Stripe\PaymentIntent
{
$this->init();
@ -256,7 +257,7 @@ class StripePaymentDriver extends BasePaymentDriver
*
* @return \Stripe\SetupIntent
*/
public function getSetupIntent() :\Stripe\SetupIntent
public function getSetupIntent(): \Stripe\SetupIntent
{
$this->init();
@ -268,7 +269,7 @@ class StripePaymentDriver extends BasePaymentDriver
* Returns the Stripe publishable key
* @return NULL|string The stripe publishable key
*/
public function getPublishableKey() :?string
public function getPublishableKey(): ?string
{
return $this->company_gateway->getPublishableKey();
}
@ -278,7 +279,7 @@ class StripePaymentDriver extends BasePaymentDriver
*
* @return NULL|\Stripe\Customer A Stripe customer object
*/
public function findOrCreateCustomer() :?\Stripe\Customer
public function findOrCreateCustomer(): ?\Stripe\Customer
{
$customer = null;
@ -311,36 +312,34 @@ class StripePaymentDriver extends BasePaymentDriver
$this->gateway();
$response = $this->gateway
->refund(['transactionReference'=>$payment->transaction_reference, 'amount' => $amount, 'currency' => $payment->client->getCurrencyCode()])
->refund(['transactionReference' => $payment->transaction_reference, 'amount' => $amount, 'currency' => $payment->client->getCurrencyCode()])
->send();
if ($response->isSuccessful()) {
SystemLogger::dispatch(
[
'server_response' => $response->getMessage(),
'data' => request()->all(),
],
SystemLog::CATEGORY_GATEWAY_RESPONSE,
SystemLog::EVENT_GATEWAY_SUCCESS,
SystemLog::TYPE_PAYPAL,
$this->client
);
SystemLogger::dispatch([
'server_response' => $response->getMessage(), 'data' => request()->all(),
], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_STRIPE, $this->client);
return true;
return [
'transaction_reference' => $response->getData()['id'],
'transaction_response' => json_encode($response->getData()),
'success' => $response->getData()['refunded'],
'description' => $response->getData()['description'],
'code' => $response->getCode(),
];
}
SystemLogger::dispatch(
[
'server_response' => $response->getMessage(),
'data' => request()->all(),
],
SystemLog::CATEGORY_GATEWAY_RESPONSE,
SystemLog::EVENT_GATEWAY_FAILURE,
SystemLog::TYPE_PAYPAL,
$this->client
);
SystemLogger::dispatch([
'server_response' => $response->getMessage(), 'data' => request()->all(),
], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->client);
return false;
return [
'transaction_reference' => null,
'transaction_response' => json_encode($response->getData()),
'success' => false,
'description' => $response->getData()['error']['message'],
'code' => $response->getData()['error']['code'],
];
}
public function verificationView(ClientGatewayToken $payment_method)