我正在尝试将电子邮件从 Stripe Checkout 传递到收费.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>
充电.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 结账页面获取电子邮件地址?我以为使用"条纹电子邮件"可以很好地工作,但事实证明并非如此......
"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})