Rails 4 - strong parameters with Stripe, my attributes are not getting set

119 Views Asked by At

I'm making an app where I use Stripe as my payment solution. To manage events I use the gem stripe_event. In my config/initializers/stripe.rb class I want to create different objects when different events occurs. Like a new Subscription.rb object when new subscriptions gets created, and then assign the Subscription to a Team.

This is how I currently create Subscriptions:

def create_subscription_for_team(team, subscription)

  team.build_subscription(
    current_period_start: subscription.current_period_start, current_period_end: subscription.current_period_end,
    status: subscription.status, started_at: subscription.start
  )
  team.stripe_subscription_id = subscription.id
  team.save!

end

The params in this method is an existing local Team and subscription is a JSON dictionary from the Stripe api.

The data is correct, my objects gets saved and created, but the properties does not get set (they remain nil). So I suspect that it has something to do with Rails 4 Strong Parameters.

So, how and where should I whitelist the parameters I get from the Stripe API to be able to set the attributes?

Or, do you think it's something else that is the cause?

Update

The subscription object looks like this:

object: {
  "application_fee_percent": null,
  "id": "[id]",
  "start": 1417208073,
  "metadata": {}
  "plan":  
    {"id":"medium","interval":"month","name":"[name]","created":1416859741,"amount":    [amount],"currency":"usd","object":"plan","livemode":false,"interval_count":1,"metadata":   {},"statement_description":null},
    "discount": null,
    "object": "subscription",
  }
  "customer": "[id]",
  "status": "active",
  "current_period_start": 1416865643,
  Parameters: {"id"=>"2"}
0

There are 0 best solutions below