/**
  * Store a newly created resource in storage.
  *
  * @param  Request $request string $cardId
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function store(Request $request, $customerId, $cardId)
 {
     try {
         $chargeData = json_decode($request->get('parameters'), true);
         $openpayReference = OpenpayReferenceModel::where('user_id', $customerId)->first();
         if ($openpayReference == null) {
             return response()->json(array("response" => "error", "class" => "CustomerControllerError", "error" => array("code" => 101, "message" => "Customer doesn't exist")));
         }
         $customer = $this->openpay->customers->get($openpayReference->openpay_id);
         $charge = $customer->charges->create($chargeData);
         return response()->json(array("response" => "result", "result" => $charge->serializableData));
     } catch (\OpenpayApiError $e) {
         return response()->json(array("response" => "error", "class" => get_class($e), "error" => array("code" => $e->getErrorCode(), "message" => $e->getMessage(), "http_code" => $e->getHttpCode(), "category" => $e->getCategory())));
     } catch (\Exception $e) {
         return response()->json(array("response" => "error", "class" => get_class($e), "error" => array("code" => $e->getCode(), "message" => $e->getMessage())));
     }
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  string $customerId
  * @return \Illuminate\Http\JsonResponse
  */
 public function destroy($customerId)
 {
     try {
         $customer = $this->openpay->customers->get($customerId);
         $customer->delete();
         //Delete data to our server
         $openpayReference = OpenpayReferenceModel::where('openpay_id', $customerId)->first();
         if ($openpayReference == null) {
             return response()->json(array("response" => "error", "class" => "CustomerControllerError", "error" => array("code" => 101, "message" => "Customer doesn't exist")));
         } else {
             $openpayReference->delete();
             return response()->json(array("response" => "ok"));
         }
     } catch (\OpenpayApiError $e) {
         return response()->json(array("response" => "error", "class" => get_class($e), "error" => array("code" => $e->getErrorCode(), "message" => $e->getMessage(), "http_code" => $e->getHttpCode(), "category" => $e->getCategory())));
     } catch (\Exception $e) {
         return response()->json(array("response" => "error", "class" => get_class($e), "error" => array("code" => $e->getCode(), "message" => $e->getMessage())));
     }
 }