#codename-mid9it_error
1 messages · Page 1 of 1 (latest)
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- codename-mid9it_code, 1 day ago, 76 messages
👋 Welcome to your new thread!
⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1219909359354511410
📝 Have more to share? Add more details, code, screenshots, videos, etc. below.
<!-- Stripe JavaScript Lib V3 -->
<script src="https://js.stripe.com/v3/"></script>
<script>
// Set your publishable key
var stripe = Stripe('pk_test_5...................................................c');
$(document).ready(function(){
// On form submit
$("#payment-form").submit(function(event){
event.preventDefault(); // Prevent the form from submitting normally
// Disable the submit button to prevent repeated clicks
$('#payBtn').attr("disabled", "disabled");
// Create token
stripe.createToken('card', {
number: $('#crad_number').val(),
exp_month: $('#month').val(),
exp_year: $('#year').val(),
cvc: $('#cvv').val()
}).then(function(result) {
if (result.error) {
// Enable the submit button
$('#payBtn').removeAttr("disabled");
// Display the errors on the form
$(".payment-status").html('<p>' + result.error.message + '</p>');
} else {
if (result.token && result.token.card && result.token.card.three_d_secure === 'required') {
// Perform 3D Secure authentication
stripe.handleCardAction(result.token.id).then(function(response) {
if (response.error) {
// Enable the submit button
$('#payBtn').removeAttr("disabled");
// Display the errors on the form
$(".payment-status").html('<p>' + response.error.message + '</p>');
} else {
// Insert the token into the form
var form$ = $("#payment-form");
form$.append("<input type='hidden' name='stripeToken' value='" + response.paymentIntent.id + "' />");
// Submit form to the server
form$.get(0).submit();
}
});
} else {
// Insert the token into the form
var form$ = $("#payment-form");
form$.append("<input type='hidden' name='stripeToken' value='" + result.token.id + "' />");
// Submit form to the server
form$.get(0).submit();
}
}
});
// Prevent the form from submitting normally
return false;
});
});
</script>
-----My code on the frontend--------------------
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['fetchClientSecret'])){
set_value($_POST);
$token = (isset($_POST['stripeToken'])) ? $_POST['stripeToken'] : null;
$crad_number = (isset($_POST['crad_number'])) ? $_POST['crad_number'] : null;
$month = (isset($_POST['month'])) ? $_POST['month'] : null;
$year = (isset($_POST['year'])) ? $_POST['year'] : null;
$cvv = (isset($_POST['cvv'])) ? $_POST['cvv'] : null;
// Validation
$errors = array();
if(empty($token)){
$errors[] = 'Token is required';
}
if(empty($crad_number)){
$errors[] = 'Crad Number is required';
}
if(empty($month)){
$errors[] = 'MONTH name is required';
}
if(empty($year)){
$errors[] = 'YEAR is required';
}
if(empty($cvv)){
$errors[] = 'CVV is required';
}
if(empty($errors)){
try{
$stripe = new \Stripe\StripeClient('sk_test_.............................m');
// Creat Customer In Stripe
// "source" => "tok_mastercard"
$customer = \Stripe\Customer::create(array(
"email" => $email,
"name" => $membernamedata,
'source' => $token,
));
$finalamount = $amount*100;
$paydesc = "Members Online Directory";
// Create the subscription with the found product ID
$subscription = $stripe->subscriptions->create([
'customer' => $customer,
'items' => [['price' => $product_id]],
"currency" => $_currency,
"description" => $paydesc,
//'amount' => $finalamount,
]);
// Create a PaymentIntent, which can handle 3DS:
$paymentIntent = \Stripe\PaymentIntent::create([
'amount' => $finalamount,
'currency' => $_currency,
'customer' => $customer->id, // Customer created earlier
'setup_future_usage' => 'off_session', // For subscriptions
'confirmation_method' => 'manual',
'confirm' => true, // Initially confirm
// Provide a return URL :
'return_url' => 'https://example/confirm.php',
]);
// Pass client secret to frontend
echo json_encode(['clientSecret' => $paymentIntent->client_secret]);
hello! Tokens are a legacy API. You should be creating PaymentMethods instead
hi, alex
the project was using Stripe.JS v2 before now, i just upgraded to v3. is that why i'm having the current error?
give me a while to get back to you
alright. thanks!
so there's some difficulties with migrating to stripe.js v3 with the way you've laid out above right now for your account. We don't support creating the PaymentMethod / Token with stripe.js v3 in that manner.
What I actually suggest you do, is to use stripe.js v3 with the Card (or split Card) element to collect the card details and confirm the corresponding PaymentIntent. Some examples that you can refer to https://glitch.com/edit/#!/stripe-php-sca-example or https://glitch.com/edit/#!/pi-split-elements