#Zigzag
1 messages ยท Page 1 of 1 (latest)
hi there ๐
Is there a specific use case you're trying to account for?
Hi, Thanks for looking up into my request
So I did implement stripe card element on my frontend
and from there I was creating payment method using stripe js
and my backend was making the charge using Laravel Cashier
It was totally fine
but now I decided to split my card element into pieces
like cardNumber, cardExpiry and cardCvc
and now I am not able to create payment method
on docs it says to pass cardNumberElement where i used to pass cardElement
What to do?
Thanks for all these details
First of all, I want to check with you, are you using this Stripejs function in order to create the split card elements ?
Yes I am using these functions properly and they are working fine, validation is also working correctly and their events as well
but createPaymentMethod which accepts card or cardNumber is throwing error that it needs card exp month etc. but I do have elements and don't know how to extract values out of these elements to pass into method if method needs it
Here docs say that I must pass cardNumberElement where I used to pass cardElement but its throwing error
OK I assume in your code you are doing something like this ?
let number = elements.getElement(CardNumberElement);
stripe.createPaymentMethod({
type: "card",
card: cardNumber
});
and you got error?
nope
I am passing the actual cardNumberElement where you have passed cardNumber in above code
like this
stripe.createPaymentMethod(
"card",
cardNumberElement
);
And its not working
{
type: "card",
card: cardNumberElement
});
Even using this
It says Missing required param: card[exp_month]
OK, give me couple of minutes while I test that
Thanks ๐
Thanks for your patience, I just finished the test and I created a PaymentMethod, here is what I did:
- HTML
<div id="split-payment-form">
<!--Stripe.js injects the Payment Element-->
<div id="card-number"></div>
<div id="card-expiry"></div>
<div id="card-cvc"></div>
<button id="submit-split-payment-element" class="Product-BuyButton">
<div class="spinner hidden" id="split-spinner"></div>
<span id="submit-button-text">Pay now</span>
</button>
</div>
- JS
var splitElements;
var cardNumberElement;
async function initializeSplitPaymentElement() {
splitElements = stripe.elements();
cardNumberElement = splitElements.create('cardNumber');
var cardCvcElement = splitElements.create('cardCvc');
var cardExpiryElement = splitElements.create('cardExpiry');
cardNumberElement.mount('#card-number');
cardCvcElement.mount('#card-cvc');
cardExpiryElement.mount('#card-expiry');
}
initializeSplitPaymentElement();
async function submitSplitPaymentElementFunction() {
//const cardNumber = splitElements.getElement(cardNumberElement)
stripe
.createPaymentMethod({
type: 'card',
card: cardNumberElement
})
.then(function(result) {
console.log(result);
// Handle result.error or result.paymentMethod
});
}
const submitSplitPaymentElement = document.getElementById("submit-split-payment-element");
submitSplitPaymentElement.addEventListener("click", submitSplitPaymentElementFunction);
Did it create paymentMethod for you successfully?