douzhi3776 2015-02-26 03:31
浏览 17

如何在网页上设置条带

I uploaded the code Stripe instructed in Step 1: Embed the Checkout on my PHP webpage:

<form action="" method="POST">
  <script
    src="https://checkout.stripe.com/checkout.js" class="stripe-button"
    data-key="pk_test_ghkfasasgipnDFA6fAB"
    data-amount="2000"
    data-name="Demo Site"
    data-description="2 widgets ($20.00)"
    data-image="/128x128.png">
  </script>
</form>

Then I uploaded the PHP code on the same web page below the code mentioned above:

// Set your secret key: remember to change this to your live secret key in               production
// See your keys here https://dashboard.stripe.com/account
\Stripe\Stripe::setApiKey("sk_test_ghkfasasgipnDFA6fAB");

    // Get the credit card details submitted by the form
$token = $_POST['stripeToken'];

// Create the charge on Stripe's servers - this will charge the user's card
try {
$charge = \Stripe\Charge::create(array(
  "amount" => 1000, // amount in cents, again
  "currency" => "usd",
  "source" => $token,
  "description" => "payinguser@example.com")
);
} catch(\Stripe\Error\Card $e) {
  // The card has been declined
}

After bringing the web page onto my FTP server the first code worked but the second did not. If anyone may know why any help would be greatly appreciated. Thank you.

  • 写回答

1条回答 默认 最新

  • duanhao4909 2015-02-26 06:13
    关注

    Try adding the second code in <?php ?> tags so your page would be.

    somepage.php

     <form action="" method="POST">
      <script
        src="https://checkout.stripe.com/checkout.js" class="stripe-button"
        data-key="pk_test_ghkfasasgipnDFA6fAB"
        data-amount="2000"
        data-name="Demo Site"
        data-description="2 widgets ($20.00)"
        data-image="/128x128.png">
      </script>
    </form>
    
    <?php
        // Set your secret key: remember to change this to your live secret key in               production
        // See your keys here https://dashboard.stripe.com/account
        \Stripe\Stripe::setApiKey("sk_test_ghkfasasgipnDFA6fAB");
    
            // Get the credit card details submitted by the form
        $token = $_POST['stripeToken'];
    
        // Create the charge on Stripe's servers - this will charge the user's card
        try {
        $charge = \Stripe\Charge::create(array(
          "amount" => 1000, // amount in cents, again
          "currency" => "usd",
          "source" => $token,
          "description" => "payinguser@example.com")
        );
        } catch(\Stripe\Error\Card $e) {
          // The card has been declined
        }
     ?>
    

    The thing is, the line \Stripe\Stripe::setApiKey("...") is referring to a PHP Class, that is not in the script above. This means there is some other code some where, that should be included in the page as well. Do you have the stripe php library installed as well? https://stripe.com/docs/checkout/guides/php

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大