<commit_before>package controllers

import models.User
import com.mohiva.play.silhouette.core.{ LogoutEvent, Environment, Silhouette }
import com.mohiva.play.silhouette.contrib.services.CachedCookieAuthenticator
import scala.concurrent.Future
import javax.inject.Inject
import models.daos.ProductDAO
import models.daos.ChargeDAO
import forms._
import play.api.Play
import play.api.Logger
import com.conekta.Plan
import utils.ConektaCurrencyMatcher

/**
 * The basic application controller.
 *
 * @param env The Silhouette environment.
 */
class PlansController @Inject() (implicit val env: Environment[User, CachedCookieAuthenticator])
  extends Silhouette[User, CachedCookieAuthenticator] {

  /**
   * Handles the index action.
   *
   * @return The result to display.
   */
  def index = SecuredAction.async { implicit request =>
    val plans = Plan.all
    Future.successful(Ok(views.html.plans.index(request.identity, plans)))
  }

  def add = SecuredAction.async { implicit request =>
    Future.successful(Ok(views.html.plans.add(request.identity, PlanForm.form)))
  }

  def delete(id: String) = SecuredAction.async{ implicit request =>
    
    val retreivedPlan = Plan.find(id)
    retreivedPlan.delete()
    
    Future.successful(Redirect(routes.PlansController.index))
    
  } 
  
  def create = SecuredAction.async { implicit request =>

    PlanForm.form.bindFromRequest.fold(

      formWithErrors => {
        Future.successful(BadRequest(views.html.plans.add(request.identity, PlanForm.form)))
      },
      plan => {

        val conektaAmount = ConektaCurrencyMatcher.convertToConektaAmount(plan._3)
        val planMap = Map("name" -> plan._1, "trial_period_days" -> plan._2, "amount" -> conektaAmount, "currency" -> "MXN")

        Plan.create(planMap)
        Future.successful(Redirect(routes.PlansController.index))
        
      })

  }

}<commit_msg>Subscribe action added to plan controller.<commit_after>package controllers

import models.User
import com.mohiva.play.silhouette.core.{ LogoutEvent, Environment, Silhouette }
import com.mohiva.play.silhouette.contrib.services.CachedCookieAuthenticator
import scala.concurrent.Future
import javax.inject.Inject
import models.daos.ProductDAO
import models.daos.ChargeDAO
import forms._
import play.api.Play
import play.api.Logger
import com.conekta.Plan
import utils.ConektaCurrencyMatcher

/**
 * The basic application controller.
 *
 * @param env The Silhouette environment.
 */
class PlansController @Inject() (implicit val env: Environment[User, CachedCookieAuthenticator])
  extends Silhouette[User, CachedCookieAuthenticator] {

  def index = SecuredAction.async { implicit request =>
    val plans = Plan.all
    Future.successful(Ok(views.html.plans.index(request.identity, plans)))
  }

  def add = SecuredAction.async { implicit request =>
    Future.successful(Ok(views.html.plans.add(request.identity, PlanForm.form)))
  }

  def delete(id: String) = SecuredAction.async { implicit request =>

    val retreivedPlan = Plan.find(id)
    retreivedPlan.delete()

    Future.successful(Redirect(routes.PlansController.index))

  }

  def create = SecuredAction.async { implicit request =>

    PlanForm.form.bindFromRequest.fold(

      formWithErrors => {
        Future.successful(BadRequest(views.html.plans.add(request.identity, PlanForm.form)))
      },
      plan => {

        val conektaAmount = ConektaCurrencyMatcher.convertToConektaAmount(plan._3)
        val planMap = Map("name" -> plan._1, "trial_period_days" -> plan._2, "amount" -> conektaAmount, "currency" -> "MXN")

        Plan.create(planMap)
        Future.successful(Redirect(routes.PlansController.index))

      })

  }

  def subscribe(id: String) = SecuredAction.async { implicit request =>

    val plan = Plan.find(id)

    val user = request.identity
    user.createSubscription(plan.id)

    Future.successful(Redirect(routes.PlansController.index).flashing(
      "success" -> "Suscripción creada"))

  }

}
{'fraction_non_alphanumeric': 0.11038471209454363, 'fraction_numerical': 0.0015086748805632386, 'mean_word_length': 3.899014778325123, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7133720', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1222, 'n_words': 235}