php - Send Email to Customer Information on Stripe -
i trying pass email stripe checkout charge.php page send dashboard users confirmation email.
here working code:
<input class="form-control" type="number" id="custom-donation-amount" placeholder="50.00" min="0" value="50" step="10.00"/> <script src="https://checkout.stripe.com/checkout.js"></script> <button id="custombutton" class="pay-button"> <h4 class="donate-text button">donate <img src="http://#.com/testing/credit-card.png" ></h4> </button> <script> var handler = stripecheckout.configure({ key: 'pk_test_*************', image: 'assets/img/#.png', locale: 'auto', token: function(token) { //this sending custom amount, works great. thought same email. $.post( "charge.php", { stripetoken: token.id, amount:$("#custom-donation-amount").val()}) // log when works .done(function( data ) { console.log( "card charged: " + data ); }); } }); $('#custombutton').on('click', function(e) { // open checkout further options var amount = $("#custom-donation-amount").val() * 100; handler.open({ name: '*********', description: '*********', amount: amount }); e.preventdefault(); }); // close checkout on page navigation $(window).on('popstate', function() { handler.close(); }); </script>
charge.php
<?php require_once('init.php'); \stripe\stripe::setapikey("sk_test_***********"); $token = $_post['stripetoken']; $email = $_post['stripeemail']; $amount = $_post['amount']; $finalamount = $amount * 100; // create customer $customer = \stripe\customer::create(array( "source" => $token, "description" => "here's description", "email" => $email) ); // charge customer instead of card \stripe\charge::create(array( "amount" => $finalamount, // amount in cents, again "currency" => "usd", "customer" => $customer->id) ); // code: save customer id , other info in database later! // code: when it's time charge customer again, retrieve customer id! \stripe\charge::create(array( "amount" => 1500, // $15.00 time "currency" => "usd", "customer" => $customerid )); ?>
how go grabbing email address stripe checkout page? thought work nicely using "stripeemail" turns out isn't case...
the 'token' contains email, replace this:
$.post( "charge.php", { stripetoken: token.id, amount:$("#custom-donation-amount").val()})
by this
$.post( "charge.php", { stripetoken: token.id, amount:$("#custom-donation-amount").val(),stripeemail:token.email})
Comments
Post a Comment