/**
  * Processes the return for old gocardless payments
  *
  * @param $userId
  * @return \Illuminate\Http\RedirectResponse
  * @throws \BB\Exceptions\AuthenticationException
  */
 public function handleManualReturn($userId)
 {
     $user = User::findWithPermission($userId);
     $confirm_params = array('resource_id' => $_GET['resource_id'], 'resource_type' => $_GET['resource_type'], 'resource_uri' => $_GET['resource_uri'], 'signature' => $_GET['signature']);
     // State is optional
     if (isset($_GET['state'])) {
         $confirm_params['state'] = $_GET['state'];
     }
     //Get the details, reason, reference and return url
     $details = explode(':', \Input::get('state'));
     $reason = 'unknown';
     $ref = null;
     $returnPath = route('account.show', [$user->id], false);
     if (is_array($details)) {
         if (isset($details[0])) {
             $reason = $details[0];
         }
         if (isset($details[1])) {
             $ref = $details[1];
         }
         if (isset($details[2])) {
             $returnPath = $details[2];
         }
     }
     //Confirm the resource
     try {
         $confirmed_resource = $this->goCardless->confirmResource($confirm_params);
     } catch (\Exception $e) {
         \Notification::error($e->getMessage());
         return \Redirect::to($returnPath);
     }
     //Store the payment
     $fee = $confirmed_resource->amount - $confirmed_resource->amount_minus_fees;
     $paymentSourceId = $confirmed_resource->id;
     $amount = $confirmed_resource->amount;
     $status = $confirmed_resource->status;
     //The record payment process will make the necessary record updates
     $this->paymentRepository->recordPayment($reason, $userId, 'gocardless', $paymentSourceId, $amount, $status, $fee, $ref);
     \Notification::success("Payment made");
     return \Redirect::to($returnPath);
 }