/** * Clear necessary caches after top off purchase */ private function clearTopOffCache() { //Bust this cache so we see the new cap Cache::tags("usage_based_billing_policy_details")->forget(get_user()->account_id); $billingController = new BillingController(); $billingController->clearBillingCache(); }
/** * Complete the PayPal payment * @param Request $request * @param $temporaryToken * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function completePayment(Request $request, $temporaryToken) { $token = PaypalTemporaryToken::where('token', '=', $temporaryToken)->where('account_id', '=', get_user()->account_id)->first(); if ($token === null) { $error = trans("errors.paypalTokenInvalid"); return view("pages.paypal.error", compact('error')); } $token->delete(); if ($request->input('paymentId') === null || $request->input('PayerID') === null) { $error = trans("errors.missingPaypalInformation"); return view("pages.paypal.error", compact('error')); } $payment = Payment::get($request->input('paymentId'), $this->apiContext); $execution = new PaymentExecution(); $execution->setPayerId($request->input('PayerID')); try { $payment->execute($execution, $this->apiContext); $payment = Payment::get($request->input('paymentId'), $this->apiContext); } catch (Exception $e) { $error = trans("errors.paypalGenericError"); return view("pages.paypal.error", compact('error')); } if (strtolower($payment->getState() != 'approved')) { $error = trans("errors.paymentNotApproved"); return view("pages.paypal.error", compact('error')); } //POST the payment back into Sonar for storage try { $accountBillingController = new AccountBillingController(); $transaction = $payment->getTransactions()[0]; $accountBillingController->storePayPalPayment(get_user()->account_id, $transaction->related_resources[0]->sale->amount->total, $transaction->related_resources[0]->sale->id); } catch (Exception $e) { $error = trans("errors.failedToApplyPaypalPayment"); return view("pages.paypal.error", compact('error')); } $billingController = new BillingController(); $billingController->clearBillingCache(); return view("pages.paypal.success"); }