2
votes

I have created a function in firebase to create a stripe subscription on the creation of a user. This was all working great however when I switched to another stripe account (switched api keys for front and backend and changed plan_id)

I am getting the following error: Received unknown parameter: source.

I have one stripe account where the code works and another account that handles the code differently. I can switch api keys and watch it go from failing to succeeding and vice versa.

This is the part of my code that creates the subscription

return stripe.subscriptions.create({
      customer: customerId,
      source: collectedToken,
      coupon: couponId,
      items: [{plan: 'plan_xxxxxxxx'}],
});

Checked all API keys are correct for backend and frontend for the stripe account. Frontend during testing was exactly the same except for using different stripe api keys. I tried Switching firebase accounts to see if that was the issue but got the same result.

What is working is creating a customer and token which matches the data being logged on that stripe account but it all fails when creating a subscription. This made me think that it was a config error in my stripe account. I have gone through both stripe accounts making them as identical as possible.

This is a failed post/response:

Request POST body
{
  "customer": "cus_EWLxBmoZgtdVKQ",
  "source": "tok_1E3JFsJUEng1Y6esS4bme82U",
  "coupon": "",
  "items": {
    "0": {
      "plan": "plan_EUshZMWWubOprv"
    }
  }
}

Response body
{
  "error": {
    "code": "parameter_unknown",
    "doc_url": "https://stripe.com/docs/error-codes/parameter-unknown",
    "message": "Received unknown parameter: source",
    "param": "source",
    "type": "invalid_request_error"
  }
}

This is a successful post/response:

{
  "customer": "cus_EW3IIVqlBt9fFD",
  "source": "tok_1E31BZLdCGsF9mmTflmDjd0x",
  "coupon": "",
  "items": {
    "0": {
      "plan": "plan_ESdEWggGYJ89FB"
    }
  }
}

{
  "id": "sub_EW3IWD0NCyDVUi",
  "object": "subscription",
  "application_fee_percent": null,
  "billing": "charge_automatically",
  "billing_cycle_anchor": 1549977641,
  "billing_thresholds": null,
  "cancel_at": null,
.................

I would expect if the plan, customer, token were valid it should work on another stripe account if that stripe account was set up the same way.

1

1 Answers

2
votes

It's probably due to the fact that the new API Key you're using is running on a newer version of the Stripe API. You can check the version(s) under your developers section of the dashboard.

In the updated subscriptions API you only need a customer and a plan (within a list of items) in order to create a new subscription. Source was removed completely and the API now is relying on the default source for the customer.