Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I get at the values in the element? #9

Open
jrdn91 opened this issue Jun 27, 2017 · 10 comments
Open

How do I get at the values in the element? #9

jrdn91 opened this issue Jun 27, 2017 · 10 comments
Labels

Comments

@jrdn91
Copy link

jrdn91 commented Jun 27, 2017

I'm just a bit confused as to how I get the values entered in the stripe-card element. I don't want to use the block form because I have a submit button outside of this element that will send along some other data to a server endpoint that creates a paysource in the customers stripe account. Can I have the values bound to some sort of controller / component property so I can get at those later when the user hits the submit button I have outside of the element?

@joshsmith
Copy link
Contributor

@joshsmith
Copy link
Contributor

And actually, the really relevant stuff is found here: https://github.com/code-corps/code-corps-ember/blob/develop/app/controllers/project/checkout.js#L36-L46

@joshsmith
Copy link
Contributor

In particular, you want to notice doing something like this:

  async _createStripeToken(stripeElement) {
    let stripe = get(this, 'stripev3');

    return await stripe.createToken(stripeElement).then(({ error, token }) => {
      if (error) {
        return this._handleCreditCardTokenError(error);
      } else if (token) {
        return RSVP.resolve(token);
      }
    });
  }

...will allow you to get at the token that Stripe provides you, without necessarily using the block element to provide this. Instead, you're really using the Stripe v3 JS library (aka Elements) with this element to do a createToken.

Does that make sense and do you what you want? If so, how can we improve this in the docs?

@jrdn91
Copy link
Author

jrdn91 commented Jun 27, 2017

Yes this gets me something I can use, thanks!

@jrdn91 jrdn91 closed this as completed Jun 27, 2017
@cmetro
Copy link

cmetro commented Dec 28, 2017

Hi. I still have the same question that is described in this thread. I have a form to collect name, billing address and I'm trying to drop in the stripe elements credit card widget. When the user "submits" the entire form, how do I get to the stripe elements to create the token in my component action? Is there an example anywhere of the "onBlur" action?

@cmetro
Copy link

cmetro commented Dec 28, 2017

I was able to figure this out by using an "onBlur" action to save a reference to the "stripe element" in my component. Then in the forms' "submit" action, the stripe element could be combined with the rest of the form data. I'm not sure if this was the best way to do this, but it works at this point.

@kimek
Copy link

kimek commented Jan 23, 2018

Hi John
I have 'partly' similar question:
How to pass stripElement after {{stripe-card-number}} and {{stripe-card-expiry}} is filled up ? o.O ?

@kimek
Copy link

kimek commented Jan 25, 2018

I only know that Stripes createToken needs cardNumber elements to be pass. I've use stripe.elements instead of components and mounted them to component as I still don't know how to use those components except card one.

@caltabid
Copy link

caltabid commented Feb 4, 2018

I have a similar question: can you please provide an example without {{stripe-card}} but exploiting {{stripe-card-number}} and {{stripe-card-expiry}}?
I tried this:
[template]
{{#stripe-card-number class="input" as |element|}}
{{stripe-card-expiry class="input"}}
{{stripe-card-cvc class="input"}}
<button {{action "stripeSubmit" element}}>Submit
{{/stripe-card-number}}
{{#if stripeToken}}
stripeToken is: {{stripeToken.id}}
{{/if}}
[controller]
stripeToken: null,
actions: {
stripeSubmit(el) {
let stripe = this.get('stripev3');
stripe.createToken(el).then(({token}) => {
this.set('stripeToken', token);
});
},
}
In this case createToken only sends the card number thus getting back a "Missing required param: card[exp_month].".
In stripe documentation for createToken: "https://stripe.com/docs/stripe-js/reference#stripe-create-token" they say: "...The Element pulls data from other Elements you’ve created on the same instance of elements to tokenize...", but this seems not happening.
I also tried to put the elements in a form:
<form {{action 'stripeSubmit' elements}}>
{{stripe-card-number}}
{{stripe-card-expiry }}
{{stripe-card-cvc}}
Pay

but when I press the button Pay, calling "stripeSubmit" function, "elements" is "undefined" and I don't know what else I can use.
Can you help?

@lrdiv
Copy link

lrdiv commented Feb 5, 2018

I had the most luck doing the following:

{{stripe-card options=options change=(action (mut stripeElement))}}

Then I was able to access the stripeElement that was set in my component/controller

I think the change event is available to all inputs, so setting individual inputs may need to set multiple properties

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants