2017-10-17 96 views
0

我想要使用自定义付款金额的条纹结帐工作。弹出的条纹表单将提交,但没有显示在我的条纹帐户。使用PHP/JS提交条纹结账,但不显示在条纹帐户

在我的实际代码中,我确实输入了我的api键。我也不使用作曲家。

<form action="charge.php" method="POST" id="payment-form"> 
    <input style="width: 100px; float: right;" class="form-control" type="number" id="custom-donation-amount" placeholder="$50.00" min="0" step="5.00"/> 
    <input class="donate-desc" style="width: 100%; float: right;" class="form-control" type="text" placeholder="What is this donation for?"/> 
    <button style="float: left; margin-right: 10px;" id="customButton" class="simpay-payment-btn stripe-button-el"><span>Make a Donation</span></button> 
    <script src="https://checkout.stripe.com/checkout.js"></script> 
    <script> 
    var handler = StripeCheckout.configure({ 
     key: 'test publishable key', 
     image: 'image.png', 
     token: function(token) { 
     var stripeToken = token.id; 
     } 
    }); 

    document.getElementById('customButton').addEventListener('click', function(e) { 
     // This line is the only real modification... 
     var amount = jQuery("#custom-donation-amount").val() * 100; 
     var desc = jQuery('.donate-desc').val(); 
     handler.open({ 
     name: 'name', 
     description: desc, 
     amount: Math.round(amount) 
     }); 
     e.preventDefault(); 
    }); 
    </script> 

这里是charge.php

<?php 
    require '/stripe/Stripe.php'; 

    $stripe = array(
     "secret_key"  => "test secret key", 
     "publishable_key" => "test publishable key" 
    ); 

    \Stripe\Stripe::setApiKey($stripe['secret_key']); 

    $token = $_POST['stripeToken']; 

    $charge = \Stripe\Charge::create(array(
     'amount' => $_POST['amount'], 
     'descrition' => $_POST['description'], 
     'currency' => 'usd', 
     'source' => $token 
    )); 

?> 

回答

0

在代码中,你只是设置一个变量stripeTokentoken.Id。您仍然需要将该变量传递给您的后端进行处理。

换句话说,在获得token.id值后,您应该向后端的某个端点发出一个新的请求(AJAX或其他)以进行处理。您的表单在您的脚本中的结构方式将无法工作。

您需要更多类似的东西:https://jsfiddle.net/osrLsc8m/