andrewculver / koudoku

Robust subscription support for Rails with Stripe.
MIT License
1.16k stars 188 forks source link

Is stripeResponseHandler out of date? #84

Open george-carlin opened 10 years ago

george-carlin commented 10 years ago

In app/views/koudoku/subscriptions/_card.html.erb we have the JS function stripeResponseHandler which contains the following lines:

      form$.append("<input type='hidden' name='subscription[credit_card_token]' value='" + response['id'] + "'/>");
      form$.append("<input type='hidden' name='subscription[last_four]' value='" + response['last4'] + "'/>");
      form$.append("<input type='hidden' name='subscription[card_type]' value='" + response['card_type'] + "'/>");

Note that it's looking for keys called id, last4, and card_type in the response object.

Problem is, the response object I'm getting back from the Stripe server looks like this:

{
    id: "...",
    livemode: false,
    created: 1415803250,
    used: false,
    type: "card",
    object: "token"…}

    card: {
        address_city: ...,
        address_country: ...,
        address_line1: ...,
        address_line2: ...,
        address_state: ...,
        address_zip: ...,
        brand: "Visa",
        country: "US",
        customer: ...,
        dynamic_last4: ...,
        exp_month: 4,
        exp_year: 2015,
        fingerprint: ...,
        funding: "credit"
        id: "card_xxxxxxxxxxxxxxxxxxxx"
        last4: "XXXX",
        name: ...,
        object: "card",
    }
}

Note that last4 and card_type aren't in there, although we do have card.last4 and type.

Is this due to a breaking change in the Stripe API?

If I'm going to fix this, should subscription[credit_card_token]' be set to response.id or response.card.id? And what should subscription[card_type] be set to? response.type? response.card.brand?

yas4891 commented 9 years ago

Hi @georgemillo

I've now control of RubyGems as well. So if you want to deliver a fix, I can get it into the gem properly. Are you interested in fixing this for sources ?