mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 16:34:35 -04:00
Stripe use SDK to refund
This commit is contained in:
parent
083e834400
commit
94ebf95caa
@ -49,10 +49,14 @@ class StripePaymentDriver extends BasePaymentDriver
|
|||||||
|
|
||||||
public $can_authorise_credit_card = true;
|
public $can_authorise_credit_card = true;
|
||||||
|
|
||||||
|
/** @var \Stripe\StripeClient */
|
||||||
|
protected $stripe;
|
||||||
|
|
||||||
protected $customer_reference = 'customerReferenceParam';
|
protected $customer_reference = 'customerReferenceParam';
|
||||||
|
|
||||||
protected $payment_method;
|
protected $payment_method;
|
||||||
|
|
||||||
|
|
||||||
public static $methods = [
|
public static $methods = [
|
||||||
GatewayType::CREDIT_CARD => CreditCard::class,
|
GatewayType::CREDIT_CARD => CreditCard::class,
|
||||||
GatewayType::BANK_TRANSFER => ACH::class,
|
GatewayType::BANK_TRANSFER => ACH::class,
|
||||||
@ -81,6 +85,10 @@ class StripePaymentDriver extends BasePaymentDriver
|
|||||||
*/
|
*/
|
||||||
public function init(): void
|
public function init(): void
|
||||||
{
|
{
|
||||||
|
$this->stripe = new \Stripe\StripeClient(
|
||||||
|
$this->company_gateway->getConfigField('apiKey')
|
||||||
|
);
|
||||||
|
|
||||||
Stripe::setApiKey($this->company_gateway->getConfigField('apiKey'));
|
Stripe::setApiKey($this->company_gateway->getConfigField('apiKey'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,36 +321,40 @@ class StripePaymentDriver extends BasePaymentDriver
|
|||||||
|
|
||||||
public function refund(Payment $payment, $amount)
|
public function refund(Payment $payment, $amount)
|
||||||
{
|
{
|
||||||
$this->gateway();
|
$this->init();
|
||||||
|
|
||||||
$response = $this->gateway
|
$response = $this->stripe
|
||||||
->refund(['transactionReference' => $payment->transaction_reference, 'amount' => $amount, 'currency' => $payment->client->getCurrencyCode()])
|
->refunds
|
||||||
->send();
|
->create(['charge' => $payment->transaction_reference, 'amount' => $amount]);
|
||||||
|
|
||||||
if ($response->isSuccessful()) {
|
// $response = $this->gateway
|
||||||
SystemLogger::dispatch([
|
// ->refund(['transactionReference' => $payment->transaction_reference, 'amount' => $amount, 'currency' => $payment->client->getCurrencyCode()])
|
||||||
'server_response' => $response->getMessage(), 'data' => request()->all(),
|
// ->send();
|
||||||
|
|
||||||
|
info($response);
|
||||||
|
|
||||||
|
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);
|
], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_STRIPE, $this->client);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'transaction_reference' => $response->getData()['id'],
|
'transaction_reference' => $response->charge,
|
||||||
'transaction_response' => json_encode($response->getData()),
|
'transaction_response' => json_encode($response),
|
||||||
'success' => $response->getData()['refunded'],
|
'success' => $response->status == $response::STATUS_SUCCEEDED ? true : false,
|
||||||
'description' => $response->getData()['description'],
|
'description' => $response->metadata,
|
||||||
'code' => $response->getCode(),
|
'code' => $response,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemLogger::dispatch([
|
SystemLogger::dispatch(['server_response' => $response, 'data' => request()->all(),
|
||||||
'server_response' => $response->getMessage(), 'data' => request()->all(),
|
|
||||||
], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->client);
|
], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->client);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'transaction_reference' => null,
|
'transaction_reference' => null,
|
||||||
'transaction_response' => json_encode($response->getData()),
|
'transaction_response' => json_encode($response),
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'description' => $response->getData()['error']['message'],
|
'description' => $response->failure_reason,
|
||||||
'code' => $response->getData()['error']['code'],
|
'code' => 422,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user