向 Stripe 上的客户信息发送电子邮件

Send Email to Customer Information on Stripe

我正在尝试将电子邮件从 Stripe Checkout 传递到 charge.php 页面,然后该页面会将其发送到仪表板,以便用户收到一封确认电子邮件。

这是我的工作代码:

<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 by <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 is where I am sending the custom amount, works great. Thought I could do the same with email. 
       $.post( "charge.php", { stripeToken: token.id, amount:$("#custom-donation-amount").val()})
           // log when it works
          .done(function( data ) {
            console.log( "Card charged: " + data );
          });
    }
});

$('#customButton').on('click', function(e) {
  // Open Checkout with 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 a Customer
$customer = \Stripe\Customer::create(array(
  "source" => $token,
  "description" => "Here's the description", 
  "email" => $email)
);

// Charge the Customer instead of the card
\Stripe\Charge::create(array(
  "amount" => $finalamount, // amount in cents, again
  "currency" => "usd",
  "customer" => $customer->id)
);

// YOUR CODE: Save the customer ID and other info in a database for later!

// YOUR CODE: When it's time to charge the customer again, retrieve the customer ID!

\Stripe\Charge::create(array(
  "amount"   => 1500, // .00 this time
  "currency" => "usd",
  "customer" => $customerId
  ));

?>

如何从 Stripe Checkout 页面获取电子邮件地址?我认为使用 "stripeEmail" 会很好地工作,但事实并非如此......

'token' 包含电子邮件,替换为:

 $.post( "charge.php", { stripeToken: token.id, amount:$("#custom-donation-amount").val()})

由此

 $.post( "charge.php", { stripeToken: token.id, amount:$("#custom-donation-amount").val(),stripeEmail:token.email})