chargebee / chargebee-ruby

Ruby library for the Chargebee API.

Home Page:https://apidocs.chargebee.com/docs/api?lang=ruby

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create subscription with Stripe token raising exception

mrrooijen opened this issue · comments

I'm trying to leverage both the Stripe and Chargebee APIs to create subscriptions and I'm running into an issue with the card parameters.

According to the documentation, if the card[tmp_token] is set, there is no need to provide additional parameters.

If this value is specified, there is no need to specify other card details (like number, cvv, etc).

Here's a simplified version of the code I'm sandboxing at the moment:

require "stripe"
require "chargebee"

Stripe.api_key = "sk_test_************************"

ChargeBee.configure(
  site: "******-test",
  api_key: "test_********************************"
)

token = Stripe::Token.create(
  card: {
    number: "4242424242424242",
    exp_month: 8,
    exp_year: 2018,
    cvc: "314",
  },
)

result = ChargeBee::Subscription.create(
  {
    plan_id: "standard",
    customer: {}, # ...
    billing_address: {}, # ...
    card: {
      tmp_token: token.id, # tok_************************
    },
  }
)

The Stripe-part will later be replaced with Stripe.js for PCI compliance reasons, but I'm using it here to sandbox and prepare working code for my development environment.

By the time the Ruby interpreter calls ChargeBee::Subscription.create, it raises the following exception:

/Users/michael/.gem/ruby/2.4.0/gems/chargebee-2.3.3/lib/chargebee/rest.rb:78:in `handle_for_error': card[billing_addr1] : cannot be blank (ChargeBee::PaymentError)

It's complaining that it wants the billing_addr1 property, while the documentation states it isn't required. But, even if I, in addition to the tmp_token add the billing_addr1 property, it still continues to raise the same exception.

Any idea why this is happening? Thanks!

Hi @mrrooijen , We see that you've enabled Card Address Verification(Setting -> Billing rules -> Card Address Verification) in Chargebee, the card billing address fields that you pass will be validated only while accepting "card" details.

On the other hand, in the case where "tmp_token" is created in Stripe and passed to Chargebee, we check for address given at the time of creation of the tmp_token. So you might have to provide the address at the time of token creation itself. Hope this helps.