条纹支付条纹费用问题

时间:2015-07-11 16:39:14

标签: php html

我正在做的很简单,使用条纹JS代码向客户收费,如此

<form method="post" action="?p=charge">
    <script 
    src="https://checkout.stripe.com/checkout.js" class="stripe-button"
    data-key="pk_test_ngaGkIg8PowWzIh5GRS18tRO"
    data-image="img/logo.png"
    data-name="Wine Glass Transport"
    data-description="Transport Case (65.00/each + Shipping)"
    data-amount="<?php echo $FinalTotal*100; ?>">                   </script>
<input type="hidden" name="final" value="<?php echo $FinalTotal*100; ?>"

从那里它被发送到收费脚本,如此

require_once ('inc/stripe/lib/Stripe.php');
try {

var_dump($_POST);
    Stripe::setApiKey("sk_test_");

    $charge = Stripe_Charge::create(array(
  "amount" => $_POST['final']/100,
  "currency" => "usd",
  "card" => $_POST['stripeToken'],
  "description" => "Wine Glass Transport Case"
));

    echo '<h1>Your payment has been completed. Thank You,<br><br>Click <a href="https://www.wineglasstransport.com/index.php">Here</a></h1>';

  //users email.
  echo $_POST['stripeEmail'];
}

catch(Stripe_CardError $e) {
    echo 'There was an error with your card!<br><br>';
    echo $e;

}

//catch the errors in any way you like

 catch (Stripe_InvalidRequestError $e)
 {
     echo 'We can not process your order there was something wrong with the information submitted, please go back and correct this error,if the error persists please contact the administrator<br><br>';
     echo $e;
  // Invalid parameters were supplied to stripe's API

}
catch (Stripe_AuthenticationError $e)
{
    echo 'Sorry, we can not connect to stripe, please contact Administrator.';
  // Authentication with stripe's API failed
  // (maybe you changed API keys recently)

}
catch (Stripe_ApiConnectionError $e)
{
  // Network communication with stripe failed
    echo 'sorry we cant connect to stripe please contact website administrator.';
}
catch (Stripe_Error $e)
{
  // Display a very generic error to the user, and maybe send
  // yourself an email
}
catch (Exception $e)
{
echo 'UH OH, something Really went wrong here, Contact the system administrator ASAP!';
  // Something else happened, completely unrelated to stripe
}
?>

此时我不知道发生了什么,我得到了这个错误

  

例外&#39; Stripe_InvalidRequestError&#39;消息&#39;无法识别   请求URL(POST:/ v1 / stripecharges)。请参阅   https://stripe.com/docs或者我们可以提供帮助   https://support.stripe.com/&#39。在   /home/arthmael/PhpstormProjects/Vino/inc/stripe/lib/Stripe/ApiRequestor.php:147   堆栈跟踪:#0   /home/arthmael/PhpstormProjects/Vino/inc/stripe/lib/Stripe/ApiRequestor.php(268):   Stripe_ApiRequestor-&gt; handleApiError(&#39; {\ n&#34;错误&#34;:{\ n ...&#39;,404,数组)

     

1 /home/arthmael/PhpstormProjects/Vino/inc/stripe/lib/Stripe/ApiRequestor.php(109):

     

Stripe_ApiRequestor-&gt; _interpretResponse(&#39; {\ n&#34;错误&#34;:{\ n ...&#39;,404)#2   /home/arthmael/PhpstormProjects/Vino/inc/stripe/lib/Stripe/ApiResource.php(143):   Stripe_ApiRequestor-&gt; request(&#39; post&#39;,&#39; / v1 / stripecharg ...&#39;,Array,   数组)#3   /home/arthmael/PhpstormProjects/Vino/inc/stripe/lib/Stripe/Charge.php(38):   Stripe_ApiResource :: _ scopedCreate(&#39; Stripe_Charge&#39;,Array,NULL)#4   /home/arthmael/PhpstormProjects/Vino/pages/charge.php(21):   Stripe_Charge :: create(Array)#5   /home/arthmael/PhpstormProjects/Vino/inc/content.php(6):   包括(&#39; / home / arthmael /...')#6   /home/arthmael/PhpstormProjects/Vino/index.php(6):   包括(&#39; / home / arthmael /...')#7 {main}

提前致谢

编辑: 我在跳过条纹irc之后意识到我使用的是过时的api,所以我更新到了这里,现在这是我的代码

2 个答案:

答案 0 :(得分:1)

删除阵列。

试试这个:

 $charge = Stripe_Charge::create(
  "amount" => $_POST['final']/100,
  "currency" => "usd",
  "card" => $_POST['stripeToken'],
  "description" => "Wine Glass Transport Case"
);

答案 1 :(得分:1)

我的问题是3折

  1. 我有一个过时的API:P

  2. 我的隐藏的金额输入没有被发布,因为它是在嵌入式脚本之后。像这样...

    <form action="?p=charge" method="post" >
                            <script
                                src="https://checkout.stripe.com/checkout.js" class="stripe-button"
                                data-key="pk_test_ngaGkIg8PowWzIh5GRS18tRO"
                                data-amount="<?php echo $FinalTotal*100; ?>"
                                data-name="Wine Glass Transport"
                                data-description="Transport Case (65.00/each + Shipping)"
                                data-image="img/logo.png">
                            </script>
    

    &#34;&GT;                         

  3. 所以我只是把它打开了

    <form action="?p=charge" method="post" >
                            <input type="hidden" name="amount" value="<?php echo $FinalTotal; ?>">
                            <script
                                src="https://checkout.stripe.com/checkout.js" class="stripe-button"
                                data-key="pk_test_ngaGkIg8PowWzIh5GRS18tRO"
                                data-amount="<?php echo $FinalTotal*100; ?>"
                                data-name="Wine Glass Transport"
                                data-description="Transport Case (65.00/each + Shipping)"
                                data-image="img/logo.png">
                            </script>
                        </form>
    
    1. 我的charge.php页面上也没有$ _POST [&#39; stripeToken&#39;]变量。
    2. 感谢你们的帮助!