#sxe-token
1 messages · Page 1 of 1 (latest)
I'm sending my form with ajax.
And I have included the php script inside the main file with a include.
if(isset($_POST['stripeToken'])){
this is the if statement
But when I'm sending the ajax, I don't receive any kind of informations from stripe.
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<script type="text/javascript">
Stripe.setPublishableKey('<?php print $publishable_key; ?>');
$(function() {
var $form = $('#form');
$form.submit(function(event) {
// Disable the submit button to prevent repeated clicks:
$form.find('.submit').prop('disabled', true);
// Request a token from Stripe:
Stripe.card.createToken($form, stripeResponseHandler);
// Prevent the form from being submitted:
return false;
});
});
function stripeResponseHandler(status, response) {
// Grab the form:
var $form = $('#form');
if (response.error) { // Problem!
// Show the errors on the form:
$form.find('.payment-errors').text(response.error.message);
$form.find('.submit').prop('disabled', false); // Re-enable submission
} else { // Token was created!
// Get the token ID:
var token = response.id;
// Insert the token ID into the form so it gets submitted to the server:
$form.append($('<input type="hidden" name="stripeToken">').val(token));
// Submit the form:
$form.get(0).submit();
}
};
</script>
Hmm looking
Alright so first
This is using Stripe.js v2
Which is our older JS library and not recommended to use since it isn't PCI compliant.
I strongly recommend that you don't use this code and instead you integrate Elements (Stripe.js v3)
Here is a good place to start: https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements
But there are a few different flows you could utilize depending on your use-case.
Which folders do I need from github?
To transfer it to my server's folder?
data / lib ?
I assume lib.
Yeah those samples will be a good starting point but definitely aren't meant for production.
For production should I use composer?
Yes we recommend composer
You basically just use it to install the Stripe PHP library for your server.
Then you can require 'vendor/autoload.php'; in your PHP files to call the Stripe PHP library
Depends on what you are trying to do
What's your model?
If you want to use invoices, then yes you should look at the invoices guide!
You want to use Stripe Checkout or build your own checkout?
I want to build my own.
Insert your card number, ccv, month/year then press okay
and I will withdraw a fixed sum
Gotcha, then the custom payment flow here: https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements is what we recommend.
from the customers' card
So you mount the Payment Element which will collect all the card details in a PCI compliant way