diff --git a/Charge/Traits/HasCustomers.php b/Charge/Traits/HasCustomers.php index 81c2917..3965116 100644 --- a/Charge/Traits/HasCustomers.php +++ b/Charge/Traits/HasCustomers.php @@ -33,9 +33,7 @@ public function patchCustomer($id) $customer->invoice_settings->default_payment_method = PaymentMethod::retrieve(request('payment_method'))->attach(['customer' => $id]); $customer->save(); - $redirect = request('redirect', false); - - return $redirect ? redirect($redirect) : back(); + return $this->updateSuccess($customer); } catch (ApiErrorException $e) { $error = $e->getError(); @@ -87,4 +85,24 @@ private function getCustomerId($email) return Arr::get($yaml, 'customer_id'); } + + /** + * @return Response|RedirectResponse + */ + private function updateSuccess(Customer $customer) + { + if (request()->ajax()) { + return response([ + 'status' => 'success', + 'details' => $customer->toArray(), + ]); + } + + $this->flash->put('success', true); + $this->flash->put('details', $customer->toArray()); + + $redirect = request('redirect', false); + + return $redirect ? redirect($redirect) : back(); + } }