diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 28d88ec3b7..abb88ef002 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -181,9 +181,10 @@ class AccountController extends BaseController $account->company->pending_plan = null; $account->company->pending_term = null; - if ($account->company->payment) { - $payment = $account->company->payment; - $this->paymentService->refund($payment); + if ($payment = $account->company->payment) { + $ninjaAccount = $this->accountRepo->getNinjaAccount(); + $paymentDriver = $ninjaAccount->paymentDriver(); + $paymentDriver->refundPayment($payment); Session::flash('message', trans('texts.plan_refunded')); \Log::info("Refunded Plan Payment: {$account->name} - {$user->email}"); } else { diff --git a/app/Ninja/PaymentDrivers/BasePaymentDriver.php b/app/Ninja/PaymentDrivers/BasePaymentDriver.php index 34c70cdbd0..54f2f36a2a 100644 --- a/app/Ninja/PaymentDrivers/BasePaymentDriver.php +++ b/app/Ninja/PaymentDrivers/BasePaymentDriver.php @@ -6,7 +6,9 @@ use Request; use Omnipay; use Exception; use CreditCard; +use DateTime; use App\Models\AccountGatewayToken; +use App\Models\Account; use App\Models\Payment; use App\Models\PaymentMethod; use App\Models\Country; @@ -628,9 +630,13 @@ class BasePaymentDriver return $payment; } - public function refundPayment($payment, $amount) + public function refundPayment($payment, $amount = 0) { - $amount = min($amount, $payment->getCompletedAmount()); + if ($amount) { + $amount = min($amount, $payment->getCompletedAmount()); + } else { + $amount = $payment->getCompletedAmount(); + } if ( ! $amount) { return false; diff --git a/app/Ninja/PaymentDrivers/StripePaymentDriver.php b/app/Ninja/PaymentDrivers/StripePaymentDriver.php index 58aa77ea92..241e0da4d4 100644 --- a/app/Ninja/PaymentDrivers/StripePaymentDriver.php +++ b/app/Ninja/PaymentDrivers/StripePaymentDriver.php @@ -76,6 +76,9 @@ class StripePaymentDriver extends BasePaymentDriver return $data; } + // Stripe complains if the email field is set + unset($data['email']); + if ( ! empty($this->input['sourceToken'])) { $data['token'] = $this->input['sourceToken']; unset($data['card']); @@ -387,13 +390,9 @@ class StripePaymentDriver extends BasePaymentDriver if ($eventType == 'customer.source.deleted' || $eventType == 'customer.bank_account.deleted') { $paymentMethod->delete(); - } - - /* } elseif ($eventType == 'customer.source.updated') { - $this->paymentService->convertPaymentMethodFromStripe($source, null, $paymentMethod)->save(); + //$this->paymentService->convertPaymentMethodFromStripe($source, null, $paymentMethod)->save(); } - */ } return 'Processed successfully'; diff --git a/app/Ninja/PaymentDrivers/WePayPaymentDriver.php b/app/Ninja/PaymentDrivers/WePayPaymentDriver.php index 096172cfd7..0405237270 100644 --- a/app/Ninja/PaymentDrivers/WePayPaymentDriver.php +++ b/app/Ninja/PaymentDrivers/WePayPaymentDriver.php @@ -249,7 +249,7 @@ class WePayPaymentDriver extends BasePaymentDriver if ($source->state == 'deleted') { $paymentMethod->delete(); } else { - $this->paymentService->convertPaymentMethodFromWePay($source, null, $paymentMethod)->save(); + //$this->paymentService->convertPaymentMethodFromWePay($source, null, $paymentMethod)->save(); } return 'Processed successfully';