Merge pull request #4087 from beganovich/v2-1809-remove-omnipay-from-stripe

Stripe use SDK to refund
This commit is contained in:
David Bomba 2020-09-24 21:00:03 +10:00 committed by GitHub
commit 5ca9dae789
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 23 deletions

View File

@ -49,10 +49,14 @@ class StripePaymentDriver extends BasePaymentDriver
public $can_authorise_credit_card = true;
/** @var \Stripe\StripeClient */
protected $stripe;
protected $customer_reference = 'customerReferenceParam';
protected $payment_method;
public static $methods = [
GatewayType::CREDIT_CARD => CreditCard::class,
GatewayType::BANK_TRANSFER => ACH::class,
@ -81,6 +85,10 @@ class StripePaymentDriver extends BasePaymentDriver
*/
public function init(): void
{
$this->stripe = new \Stripe\StripeClient(
$this->company_gateway->getConfigField('apiKey')
);
Stripe::setApiKey($this->company_gateway->getConfigField('apiKey'));
}
@ -313,36 +321,38 @@ class StripePaymentDriver extends BasePaymentDriver
public function refund(Payment $payment, $amount)
{
$this->gateway();
$this->init();
$response = $this->gateway
->refund(['transactionReference' => $payment->transaction_reference, 'amount' => $amount, 'currency' => $payment->client->getCurrencyCode()])
->send();
$response = $this->stripe
->refunds
->create(['charge' => $payment->transaction_reference, 'amount' => $amount]);
if ($response->isSuccessful()) {
SystemLogger::dispatch([
'server_response' => $response->getMessage(), 'data' => request()->all(),
// $response = $this->gateway
// ->refund(['transactionReference' => $payment->transaction_reference, 'amount' => $amount, 'currency' => $payment->client->getCurrencyCode()])
// ->send();
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);
return [
'transaction_reference' => $response->getData()['id'],
'transaction_response' => json_encode($response->getData()),
'success' => $response->getData()['refunded'],
'description' => $response->getData()['description'],
'code' => $response->getCode(),
'transaction_reference' => $response->charge,
'transaction_response' => json_encode($response),
'success' => $response->status == $response::STATUS_SUCCEEDED ? true : false,
'description' => $response->metadata,
'code' => $response,
];
}
SystemLogger::dispatch([
'server_response' => $response->getMessage(), 'data' => request()->all(),
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,
'transaction_response' => json_encode($response->getData()),
'transaction_response' => json_encode($response),
'success' => false,
'description' => $response->getData()['error']['message'],
'code' => $response->getData()['error']['code'],
'description' => $response->failure_reason,
'code' => 422,
];
}

View File

@ -72,17 +72,15 @@ class RefundPayment
{
if ($this->refund_data['gateway_refund'] !== false && $this->total_refund > 0) {
if ($this->payment->company_gateway) {
$response = $gateway->driver($this->payment->client)->refund($this->payment, $this->total_refund);
$response = $this->payment->company_gateway->driver($this->payment->client)->refund($this->payment, $this->total_refund);
if ($response['success']) {
if ($response['success'] == false) {
throw new PaymentRefundFailed();
}
$this->payment->refunded += $this->total_refund;
$this
->createActivity($gateway)
->updateCreditNoteBalance();
$this->createActivity($this->payment);
}
} else {
$this->payment->refunded += $this->total_refund;
@ -106,7 +104,7 @@ class RefundPayment
$fields->user_id = $this->payment->user_id;
$fields->company_id = $this->payment->company_id;
$fields->activity_type_id = Activity::REFUNDED_PAYMENT;
$fields->credit_id = $this->credit_note->id;
// $fields->credit_id = $this->credit_note->id; // TODO
$fields->notes = json_encode($notes);
if (isset($this->refund_data['invoices'])) {