#Abdul Shakoor
1 messages ยท Page 1 of 1 (latest)
Hi ๐
You are creating a Token from raw card numbers? Are you using Stripe.js?
Quoting your message:
here is my code
Stripe.setPublishableKey($form.data('stripe-publishable-key'));
Stripe.createToken({
number: $('.card-number').val(),
cvc: $('.card-cvc').val(),
exp_month: $('.card-expiry-month').val(),
exp_year: $('.card-expiry-year').val()
}, stripeResponseHandler);
This code looks like it is a server-side language
I am using this https://js.stripe.com/v3/ api version
That isn't an API version. That is our JavaScript library
yes its is server side
Which is not server side
Your code looks like PHP to me
Wait...no because your createToken parameters aren't using PHP
Do you have an example API request ID I can review?
Here's how you can find a request ID: https://support.stripe.com/questions/finding-the-id-for-an-api-request
i have used this code in javascript .blade file but want to tell one thing same code working using v2 library
Do you have request IDs I can review?
no i dont have a request id
can you please tell me where can i find so i can share with you
The link I provided tells you how to find your API requests and their IDs
Thanks
The parameters passed in the card element is empty. here
Requests to create a Token need to follow this pattern: https://stripe.com/docs/api/tokens/create_card
but the error i am getting is on creating token: TypeError: Stripe.setPublishableKey is not a function
I think that is because we initialize Stripe.js differently. Can you try using this approach? https://stripe.com/docs/js/initializing
i have already tried this approach lemme try again
this is the form i am using and when tried initializing approach getting some different error:
You must provide a Stripe Element or a valid token type to create a Token.
Okay that form ins't anything Stripe controls. Can you show me your JavaScript code that is throwing the error?
one more thing its working with v2 library why its not working with v3
What code are you referring to?
What is the exact code and what is the entire contents of the error message
var stripe = Stripe($form.data('stripe-publishable-key'));
stripe.createToken({
number: $('.card-number').val(),
cvc: $('.card-cvc').val(),
exp_month: $('.card-expiry-month').val(),
exp_year: $('.card-expiry-year').val()
}, stripeResponseHandler);
And what throws the error?
Right, you need to pass everything in the .createToken inside a ({card:{}}) object
So that it matches the signature of the method described here: https://stripe.com/docs/api/tokens/create_card
ok updating to that
is this correct now:
var stripe = Stripe($form.data('stripe-publishable-key'));
stripe.createToken({
card: {
number: $('.card-number').val(),
cvc: $('.card-cvc').val(),
exp_month: $('.card-expiry-month').val(),
exp_year: $('.card-expiry-year').val()
}
}).then(function(result) {
if (result.error) {
// Handle token creation error
console.error(result.error.message);
} else {
// Token created successfully, send it to your server for further processing
var token = result.token.id;
stripeResponseHandler(token);
}
});
tried this code and getting new error :
๐ catching up and stepping in for my teammate!
Just taking a step back. If your goal is to accept card payments only, I strongly recommend moving to the Card Element to create the token instead of using your own form: https://stripe.com/docs/js/tokens_sources/create_token?type=cardElement#stripe_create_token-tokenType
If you eventually want to accept other payment methods (ACH, other bank debits, buy now pay later methods), I recommend moving over to using the PaymentElement instead
can i create all these fields in card elemnt lik country etc.?
The card element will only collect card number, expiration date, and cvc. If you want to collect other billing details, you can but you'd need to use your own custom input fields for those.
If you want to save the values you collected through your own fields within Stripe, you can submit those when you confirm the card payment: https://stripe.com/docs/js/payment_intents/confirm_card_payment
ok thanks for your time, I have a last question in library version 2 its working directly why its not working in version 3 ?
I'm not sure without digging deeper but honestly, I recommend using the Card Element instead since that's a more secure route overall
ok @floral ether