Split Form using *Elements and createPaymentMethod (lack of examples in documentation)
I can't figure out how to use createPaymentMethod with split form (separate elements) It works fine with the single cardElement, but I don't understand the documentation, and I'm unable to replicate the example (I'm using NextJS).
As in the documentation, I have Checkoutform.js
async getPaymentMethod() {
const { stripe } = this.props;
const cardElement = this.props.elements.getElement('card');
const { paymentMethod } = await stripe.createPaymentMethod({
type: 'card',
card: cardElement
});
...
SplitFieldForm.js
import React, { Component } from 'react';
import {
CardNumberElement,
CardExpiryElement,
CardCvcElement
} from 'react-stripe-elements';
class SplitFieldsForm extends Component {
render() {
return (
<>
<CardNumberElement id="card_number" />
<CardExpiryElement id="card_expiry" />
<CardCvcElement id="card_cvc" />
</>
);
}
}
export default SplitFieldsForm;
I have tried various ways to 'getElement' separately, but just can't figure out a way to make it work. Is there a similar example that I could follow or more explicit documentation ? Thanks.
As Stripe.js can pull in other elements, you just have to give the first one, in this case, the cardNumber. Documentation could mention it, it would save perhaps some time to other users.
async getPaymentMethod() {
const { stripe } = this.props;
const cardElement = this.props.elements.getElement('cardNumber');
const { paymentMethod } = await stripe.createPaymentMethod({
type: 'card',
card: cardElement
});
This should be added into the docs for sure.
This defo should be explained, wasted hours on this issue
Thanks for this ! I was also trying to figure this out. As we stand today the docs does not seems to be updated yet. The new Git repo sample works this way, but its not explicit that the others data (CVC, Expiry) are automatically pulled along with the number behind the scene
This defo should be explained, wasted hours on this issue
My support 🙌🏻
+1 on this defo need to be explained on the documentation
Why hasn't this been documented yet? Principle of Least Astonishment
Hi all, sounds like we reached a resolution here. We'll definitely consider this as a docs improvement to make.
I will close the issue for now -- people will still be able to find it, but the project has moved to React Stripe.js. I'll make sure this is tracked internally as a docs improvement task.