php - How can an email be returned from Stripe Checkout? -


using stripe, want store customer email address email supplied in checkout. unfortunately, posting stripeemail in charge.php file returns null.

how can return email checkout can use send receipt?

here's form code:

<script src="https://checkout.stripe.com/v2/checkout.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script> <form action="charge.php" method="post">   <input type="hidden" id="amount" name="chargeamount"/>   <button data-charge-amount="300000" data-charge-name="name" data-charge-description="description">select pledge level</button>   <button data-charge-amount="123123" data-charge-name="name2" data-charge-description="description2">donate</button> </form> <script>   $('button').click(function(){     var token = function(res){       var $thetoken = $('<input type=hidden name=stripetoken />').val(res.id);       $('form').append($thetoken).submit();     };     var amount = $(this).data("chargeamount");     var name = $(this).data("chargename");     var description = $(this).data("chargedescription");     $('input#amount').val(amount);     stripecheckout.open({       key:         'pk_test_xxxxxxxxxxxxxxxxxxxxxxxx',       address:     true,       amount:      amount,       currency:    'usd',       name:        name,       description: description,       panellabel:  'pledge',       token:       token,     });     return false;   }); </script> 

here charge.php code:

<?php require_once('./config.php'); $token  = $_post['stripetoken']; $amount = $_post['chargeamount']; $customer = \stripe\customer::create(array(     'email' => $email,     'card'  => $token, )); $charge = \stripe\charge::create(array(   'customer' => $customer->id,   'amount'   => $amount,   'currency' => 'usd', )); ?>  

here config.php code:

<?php require_once('./stripe-php-2.1.2/init.php');  $stripe = array(   "secret_key"      => "sk_test_xxxxxxxxxxxxxxxxxxxxxxxx",   "publishable_key" => "pk_test_xxxxxxxxxxxxxxxxxxxxxxxx" );  \stripe\stripe::setapikey($stripe['secret_key']); ?> 

any appreciated.

thanks!

i spent night on problem! @koopajah helped ton, here's entire solution in case else happens run across this.

here's form:

    <form action="/charge.php" method="post">       <input              type="submit"             id="payme"                       class="btn btn-default btn-lg btn-success"             value="&nbsp;&nbsp; pay &nbsp;&nbsp;"             data-key="xxxxxxx"             data-amount="199"             data-currency="usd"             data-name="stuff"             data-description="20 whozits ($19.99)"     data-image="images/image.jpg"     data-bitcoin="true"         />          <script src="https://checkout.stripe.com/v2/checkout.js"></script>         <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>         <script>         $(document).ready(function() {             $('#payme').on('click', function(event) {                 event.preventdefault();                  var $button = $(this),                     $form = $button.parents('form');                  var opts = $.extend({}, $button.data(), {                     token: function(result) {                          var $thetoken = $('<input>').attr({ type: 'hidden', name: 'stripetoken', value: result.id })                         var $theemail = $('<input>').attr({ type: 'hidden', name: 'stripeemail', value: result.email })                         $form.append($thetoken).append($theemail).submit();                     }                 });                  stripecheckout.open(opts);             });         });         </script> </form> 

and here's charge.php:

<?php require_once('vendor/autoload.php');  $stripe = array(   "secret_key"      => "xxxx",   "publishable_key" => "xxxx" );  \stripe\stripe::setapikey($stripe['secret_key']); $token = $_post['stripetoken']; $email = $_post['stripeemail'];   \stripe\customer::create(array(       "source"  => $token,       "email" => $email,       "description" => "it worked!"   ));    try { $charge = \stripe\charge::create(array(   "amount" => 199, // amount in cents, again   "currency" => "usd",   "source" => $_post['stripetoken'],   "description" => "cat facts")); } catch(\stripe\error\card $e) {   $error = $e->getmessage(); } ?> 

Comments

Popular posts from this blog

SQL php on different pages to Insert (mysqli) -

sql - Partition elimination in Greenplum -