我在网站上销售产品。我有条纹设置,并已接受订单。我添加了一个电子邮件字段,但它没有保存到Stripe。
如果有人可以提供帮助,我不确定我做错了什么。电子邮件字段位于代码的底部。
popup_html.php
<div class="modal fade" id="model_stripe" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Credit Card Information</h4>
</div>
<div class="modal-body">
<div id="submit_card_info"></div>
<form class="form-horizontal te-ajax-form" id="upgrade_form" action="upgrade/payment" role="form">
<div class="form-group">
<label class="col-sm-3 control-label" for="">Card Number</label>
<div class="col-sm-9">
<input class="form-control required" name="cardnumber" id="cardnumber" type="text" placeholder="Card Number" value=""/>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="">CVC</label>
<div class="col-sm-9">
<input class="form-control required" name="cvc" id="cvc" type="text" placeholder="CVC" value="" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="">Expiration</label>
<div class="col-sm-9">
<div class="row">
<div class="col-xs-6">
<select id="expMonth" style="width:100%;padding:5px;">
<?php
$year = date('Y');
for ($i=1; $i < 13; $i++) {
?>
<option value="<?php echo $i ?>"><?php echo $i ?></option>
<?php
}
?>
</select>
</div>
<div class="col-xs-6">
<select id="expYear" name="year" style="width:100%;padding:5px;">
<?php
$year = date('Y');
for ($i=1; $i < 21; $i++) {
?>
<option value="<?php echo $year+$i ?>"><?php echo $year+$i ?></option>
<?php
}
?>
</select>
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="">E-mail Address</label>
<div class="col-sm-9">
<input class="form-control required" name="email" id="email" type="text" placeholder="Your E-mail Address" value=""/>
</div>
</div>
</form>
<form id="upgrade_form_token" class="te-ajax-form" action="inc/stripe_charge.php">
Stripe_handler.php:
<?php
require_once ('stripe/lib/Stripe.php');
define('PRICE',9.99);
$stripe = array(
'secret_key' => ' sk_test_665545656565656 ',
'publishable_key' => 'pk_test_35845754785784578'
);
Stripe::setApiKey($stripe['secret_key']);
?>
<script type="text/javascript" src="https://js.stripe.com/v1/"></script>
<script type="text/javascript">
Stripe.setPublishableKey("<?php echo $stripe['publishable_key']; ?>");
jQuery(document).ready(function() {
jQuery('#model_stripe .extra_items input').change(function(){
if( jQuery(this).attr('name')=='info[addon3]' ){
if( jQuery(this).is(':checked') ) {
jQuery('#saNotes').show();
} else {
jQuery('#saNotes').hide();
}
}
var extra_for_stripe = 0;
jQuery('#model_stripe .extra_items input:checked').each(function(){
extra_for_stripe += Number(jQuery(this).val());
});
var notes = false;
var total_charges = extra_for_stripe+(<?php echo PRICE ?>);
jQuery('#upgrade_form_token').find('[name="amount"]').val(total_charges);
jQuery('#model_stripe .total_charges').text('$'+total_charges)
});
jQuery("#proceed_stripe").click(function(event) {
jQuery('#submit_card_info .payment-message').remove();
var card_no = jQuery('#cardnumber').val();
var cvc = jQuery('#cvc').val();
if(card_no.length==0){
var errorHTML = '<div class="payment-message alert alert-danger alert-dismissable fade in"><button class="close" data-dismiss="alert">×</button ><p>Card Number is required.</p></div>';
jQuery("#submit_card_info").prepend(errorHTML);
return false;
}
if(cvc.length==0){
var errorHTML = '<div class="payment-message alert alert-danger alert-dismissable fade in"><button class="close" data-dismiss="alert">×</button ><p>CVS is required.</p></div>';
jQuery("#submit_card_info").prepend(errorHTML);
return false;
}
// jQuery('#model_stripe .modal-footer button ').attr('disabled',true);
Stripe.createToken({
number: card_no,
cvc: cvc,
exp_month: jQuery('#expMonth').val(),
exp_year: jQuery('#expYear').val(),
}, stripeResponseHandler);
return false; // submit from callback
});
});
function stripeResponseHandler(status, response) {
if (response.error) {
jQuery('#upgrade_button').removeAttr("disabled");
// show the errors on the form
var errorHTML = '<div class="payment-message alert alert-danger alert-dismissable fade in"><button class="close" data-dismiss="alert">×</button ><p>'+response.error.message+'</p></div>';
jQuery("#submit_card_info").prepend(errorHTML);
}
else {
var form = jQuery("#proceed_stripe");
// token contains id, last4, and card type
var token = response['id'];
// insert the token into the form so it gets submitted to the server
jQuery('#upgrade_form_token input[name="stripeToken"]').val(token);
jQuery('#footer-form input[type="text"], #footer-form select').each(function(){
var h = '<input value="'+jQuery(this).val()+'" name="info['+jQuery(this).attr('name')+']" type="hidden">';
jQuery('#upgrade_form_token').append(h);
});
jQuery('#upgrade_form_token').submit();
}
}
function upgrade_form_token_success(form,resp){
jQuery('#submit_card_info .payment-message').remove();
if( resp.type=='success'){
var h = '<div style="display: block;font-size: 16px;padding-bottom: 10px;font-weight: bold;">Thanks for buying. <a href="index.php" title="products">Buy More</a></div>';
jQuery("#model_stripe .modal-body").html(h);
jQuery("#model_stripe .modal-footer").remove();
jQuery("#model_stripe .modal-backdrop").css({
'opacity':1,
'background-color':'#fff',
});
} else {
jQuery("#submit_card_info").append(bs_alert('danger',resp.msg ) );
}
}
</script>
答案 0 :(得分:0)
Stripe有一些很好的文档可以将现有表单转换为条带形式@ https://stripe.com/docs/stripe.js/switching。
(1)请注意,您从所有敏感输入字段中删除了name属性(如上面michael所述)除非您运行的是PCI兼容服务器,否则这很重要。
(2)当您解析表单并尝试最后尝试从卡中收费时,您希望将电子邮件地址作为receipt_email传递:customer@email.com(请参阅https://stripe.com/docs/api#create_charge)
希望这有帮助!