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

时间:2016-03-07 04:16:01

标签: php html-email stripe-payments

我正在尝试将电子邮件从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, // $15.00 this time
  "currency" => "usd",
  "customer" => $customerId
  ));

?>

如何从Stripe Checkout页面抓取电子邮件地址?我认为使用&#34; stripeEmail&#34;会很好用。但事实证明并非如此......

1 个答案:

答案 0 :(得分:2)

'令牌'包含电子邮件,请替换为:

precision

由此

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