How can i get a stripe token on my controller with checkout?












0














i'm trying to get a stripe token when i use checkout, but when i submit the embeded form i don't have a POST method and i don't know how i can have the token on my php controller too.
Here is my code :



<script>
var handler = StripeCheckout.configure({
key: 'pk_test_WWlLRtqEY2yfJUlfA4TRRcyf',
image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
locale: 'auto',
token: function(token) {
console.log(token.id);
}
});

document.getElementById('customButton').addEventListener('click', function(e) {
// Open Checkout with further options:
handler.open({
name: 'Musée du Louvre',
description: 'Biletterie en ligne',
currency: 'eur',
amount: '{{ price }}' * 100,
email: '{{ mail }}',
allowRememberMe: false,
});
e.preventDefault();
});

// Close Checkout on page navigation:
window.addEventListener('popstate', function() {
handler.close();
});




i tried with this :



<form post="" method="post">
my script code
</form>


but when i click on pay the page don't resfresh.



Someone can help me?










share|improve this question






















  • Update a hidden field(s) with your token data and then submit the form to your back end and use Stripe php sdk to process the charges
    – charlietfl
    Nov 22 at 19:27


















0














i'm trying to get a stripe token when i use checkout, but when i submit the embeded form i don't have a POST method and i don't know how i can have the token on my php controller too.
Here is my code :



<script>
var handler = StripeCheckout.configure({
key: 'pk_test_WWlLRtqEY2yfJUlfA4TRRcyf',
image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
locale: 'auto',
token: function(token) {
console.log(token.id);
}
});

document.getElementById('customButton').addEventListener('click', function(e) {
// Open Checkout with further options:
handler.open({
name: 'Musée du Louvre',
description: 'Biletterie en ligne',
currency: 'eur',
amount: '{{ price }}' * 100,
email: '{{ mail }}',
allowRememberMe: false,
});
e.preventDefault();
});

// Close Checkout on page navigation:
window.addEventListener('popstate', function() {
handler.close();
});




i tried with this :



<form post="" method="post">
my script code
</form>


but when i click on pay the page don't resfresh.



Someone can help me?










share|improve this question






















  • Update a hidden field(s) with your token data and then submit the form to your back end and use Stripe php sdk to process the charges
    – charlietfl
    Nov 22 at 19:27
















0












0








0







i'm trying to get a stripe token when i use checkout, but when i submit the embeded form i don't have a POST method and i don't know how i can have the token on my php controller too.
Here is my code :



<script>
var handler = StripeCheckout.configure({
key: 'pk_test_WWlLRtqEY2yfJUlfA4TRRcyf',
image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
locale: 'auto',
token: function(token) {
console.log(token.id);
}
});

document.getElementById('customButton').addEventListener('click', function(e) {
// Open Checkout with further options:
handler.open({
name: 'Musée du Louvre',
description: 'Biletterie en ligne',
currency: 'eur',
amount: '{{ price }}' * 100,
email: '{{ mail }}',
allowRememberMe: false,
});
e.preventDefault();
});

// Close Checkout on page navigation:
window.addEventListener('popstate', function() {
handler.close();
});




i tried with this :



<form post="" method="post">
my script code
</form>


but when i click on pay the page don't resfresh.



Someone can help me?










share|improve this question













i'm trying to get a stripe token when i use checkout, but when i submit the embeded form i don't have a POST method and i don't know how i can have the token on my php controller too.
Here is my code :



<script>
var handler = StripeCheckout.configure({
key: 'pk_test_WWlLRtqEY2yfJUlfA4TRRcyf',
image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
locale: 'auto',
token: function(token) {
console.log(token.id);
}
});

document.getElementById('customButton').addEventListener('click', function(e) {
// Open Checkout with further options:
handler.open({
name: 'Musée du Louvre',
description: 'Biletterie en ligne',
currency: 'eur',
amount: '{{ price }}' * 100,
email: '{{ mail }}',
allowRememberMe: false,
});
e.preventDefault();
});

// Close Checkout on page navigation:
window.addEventListener('popstate', function() {
handler.close();
});




i tried with this :



<form post="" method="post">
my script code
</form>


but when i click on pay the page don't resfresh.



Someone can help me?







javascript php forms symfony stripe-payments






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 at 19:20









mohasalim

155




155












  • Update a hidden field(s) with your token data and then submit the form to your back end and use Stripe php sdk to process the charges
    – charlietfl
    Nov 22 at 19:27




















  • Update a hidden field(s) with your token data and then submit the form to your back end and use Stripe php sdk to process the charges
    – charlietfl
    Nov 22 at 19:27


















Update a hidden field(s) with your token data and then submit the form to your back end and use Stripe php sdk to process the charges
– charlietfl
Nov 22 at 19:27






Update a hidden field(s) with your token data and then submit the form to your back end and use Stripe php sdk to process the charges
– charlietfl
Nov 22 at 19:27














1 Answer
1






active

oldest

votes


















1














The idea is to change the code in the token callback to send the token to your server instead of logging it to the console.



Change your form to have a hidden field for the stripe token id and the email entered by the customer:



<form action="/your/route" method="POST" id="payment-form">
<input type="hidden" id="stripeToken" name="stripeToken" value="tok_XXX" />
<input type="hidden" id="stripeEmail" name="stripeEmail" value="email@example.com" />
</form>


And then change your JS to set those values and submit the form:



token: function(token) {
$("#stripeToken").val(token.id);
$("#stripeEmail").val(token.email);
$("#payment-form").submit();
}


This will submit your form and your route on the server will receive the stripeToken and the stripeEmail values in the POST parameters.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437002%2fhow-can-i-get-a-stripe-token-on-my-controller-with-checkout%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    The idea is to change the code in the token callback to send the token to your server instead of logging it to the console.



    Change your form to have a hidden field for the stripe token id and the email entered by the customer:



    <form action="/your/route" method="POST" id="payment-form">
    <input type="hidden" id="stripeToken" name="stripeToken" value="tok_XXX" />
    <input type="hidden" id="stripeEmail" name="stripeEmail" value="email@example.com" />
    </form>


    And then change your JS to set those values and submit the form:



    token: function(token) {
    $("#stripeToken").val(token.id);
    $("#stripeEmail").val(token.email);
    $("#payment-form").submit();
    }


    This will submit your form and your route on the server will receive the stripeToken and the stripeEmail values in the POST parameters.






    share|improve this answer


























      1














      The idea is to change the code in the token callback to send the token to your server instead of logging it to the console.



      Change your form to have a hidden field for the stripe token id and the email entered by the customer:



      <form action="/your/route" method="POST" id="payment-form">
      <input type="hidden" id="stripeToken" name="stripeToken" value="tok_XXX" />
      <input type="hidden" id="stripeEmail" name="stripeEmail" value="email@example.com" />
      </form>


      And then change your JS to set those values and submit the form:



      token: function(token) {
      $("#stripeToken").val(token.id);
      $("#stripeEmail").val(token.email);
      $("#payment-form").submit();
      }


      This will submit your form and your route on the server will receive the stripeToken and the stripeEmail values in the POST parameters.






      share|improve this answer
























        1












        1








        1






        The idea is to change the code in the token callback to send the token to your server instead of logging it to the console.



        Change your form to have a hidden field for the stripe token id and the email entered by the customer:



        <form action="/your/route" method="POST" id="payment-form">
        <input type="hidden" id="stripeToken" name="stripeToken" value="tok_XXX" />
        <input type="hidden" id="stripeEmail" name="stripeEmail" value="email@example.com" />
        </form>


        And then change your JS to set those values and submit the form:



        token: function(token) {
        $("#stripeToken").val(token.id);
        $("#stripeEmail").val(token.email);
        $("#payment-form").submit();
        }


        This will submit your form and your route on the server will receive the stripeToken and the stripeEmail values in the POST parameters.






        share|improve this answer












        The idea is to change the code in the token callback to send the token to your server instead of logging it to the console.



        Change your form to have a hidden field for the stripe token id and the email entered by the customer:



        <form action="/your/route" method="POST" id="payment-form">
        <input type="hidden" id="stripeToken" name="stripeToken" value="tok_XXX" />
        <input type="hidden" id="stripeEmail" name="stripeEmail" value="email@example.com" />
        </form>


        And then change your JS to set those values and submit the form:



        token: function(token) {
        $("#stripeToken").val(token.id);
        $("#stripeEmail").val(token.email);
        $("#payment-form").submit();
        }


        This will submit your form and your route on the server will receive the stripeToken and the stripeEmail values in the POST parameters.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 at 19:31









        koopajah

        14.2k74680




        14.2k74680






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437002%2fhow-can-i-get-a-stripe-token-on-my-controller-with-checkout%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Sphinx de Gizeh

            Dijon

            Langue