#sxe-token

1 messages · Page 1 of 1 (latest)

ebon imp
#

Hi there! Can you tell me more about what you mean by that?

misty ruin
#

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>
ebon imp
#

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)

misty ruin
#

Which is the newer version?

#

Ok

ebon imp
#

But there are a few different flows you could utilize depending on your use-case.

misty ruin
#

Which folders do I need from github?

#

To transfer it to my server's folder?

#

data / lib ?

#

I assume lib.

ebon imp
#

Yeah those samples will be a good starting point but definitely aren't meant for production.

misty ruin
#

For production should I use composer?

ebon imp
#

Yes we recommend composer

misty ruin
#

Can you guide me throught composer?

#

i've never used it.

#

I just ran it on terminal.

ebon imp
#

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

misty ruin
#

oh awesome

#

Should I look for accept a payment

#

Or for Invoicing?

ebon imp
#

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!

misty ruin
#

I'm trying to accept payments for checkout.

#

Invoicing are made server-side.

ebon imp
#

You want to use Stripe Checkout or build your own checkout?

misty ruin
#

I want to build my own.

#

Insert your card number, ccv, month/year then press okay

#

and I will withdraw a fixed sum

ebon imp
misty ruin
#

from the customers' card

ebon imp
#

So you mount the Payment Element which will collect all the card details in a PCI compliant way