javascript - 我如何处理条纹错误 PHP

标签 javascript php

很抱歉在谈到 PHP 和 Stripe 时有点不知所措,但我想我们都必须从某个地方开始。

我已经设置了一个支付页面,当银行卡详细信息正确且已获得授权时,一切正常。我遇到的这个问题是卡被拒绝或细节有问题。我得到的只是一个空白的白色屏幕,我不知道如何处理这些错误。

所以我想会有人愿意帮忙。

感谢和下面的代码;

主Index.php页面

<!-- STRIPE -->


<div class="payment">

<div class="title">
  <div class="copy">
    <h2>Deposit Payment</h2>
    <p>Please fill out the following form.</p>
  </div>
</div>

  <?php require_once('inc/config.php'); ?>
  <form action="inc/charge.php" method="post">
  <input type="text" name="business" placeholder="Advertiser Name">
  <input type="text" name="email" placeholder="Advertiser Email">
  <input type="text" name="hotel" placeholder="Hotel Name">
  <div class="two-blocks">
  <select class="small" id="currency">
  <option value="gbp">Great British Pounds</option>
  </select>
  <input type="text" class="small" id="price" name="price" placeholder="£500.00">
  </div>
  <script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
        data-key="<?php echo $stripe['publishable_key']; ?>"
        data-currency="GBP"
        data-label="Submit"
        data-name="Guest Services Worldwide"
        data-image="http://www.itsjoeturner.com/pay/wallet.png"
        data-description="Advertising Deposit Payment"
        data-allow-remember-me="false">
  </script>
  </form>

</div>

<!-- // STRIPE -->

收费.php

<?php
  require_once('config.php');

  $token = $_POST['stripeToken'];
  $business = $_POST['business'];
  $email = $_POST['email'];
  $hotel = $_POST['hotel'];
  $currency = $_POST['currency'];
  $price =  $_POST['price'];

 $price .= "00";

  $customer = Stripe_Customer::create(array(
      'email' => $email,
      'card'  => $token,
      'description' => "Business Name: ".$business.""
  ));

  $charge = Stripe_Charge::create(array(
      'customer' => $customer->id,
      'amount'   => $price,
      'currency' => 'gbp',
  ));

  header( 'Location: http://gswportal.co.uk/payments/thanks.html' ) ;

?>

最佳答案

当银行卡被拒绝时,Stripe 会抛出一个 Stripe_CardError 异常。

try {
    $charge = Stripe_Charge::create(array(
      'customer' => $customer->id,
      'amount'   => $price,
      'currency' => 'gbp',
    ));
} catch (Stripe_CardError $e) {
    //card could not be charged
    $body = $e->getJsonBody();
    $err  = $body['error'];

    print('Status is:' . $e->getHttpStatus() . "\n");
    print('Type is:' . $err['type'] . "\n");
    print('Code is:' . $err['code'] . "\n");
    // param is '' in this case
    print('Param is:' . $err['param'] . "\n");
    print('Message is:' . $err['message'] . "\n");
}

参见 https://stripe.com/docs/api?lang=php#errors获取更多信息和可能抛出的异常的完整列表。

关于javascript - 我如何处理条纹错误 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25670237/

相关文章:

javascript - 删除 body 标签 Angular 应用程序的属性

javascript - 可以通过选项卡选择单选按钮吗?

php - simplexml_import_dom() : Invalid Nodetype to import - which DOMNode sub-types are supported?

javascript - 如何在 PHP 中将 MediaRecorder 流保存到 OGG 文件?包括元数据

php - 在cakephp中发布表单数据时出现404错误

javascript - 向 Instagram feed 添加分页或延迟加载

javascript - 尝试调用休息函数时,Angular dataService.init 不是函数

php - 用于下拉值问题的 Javascript onchange

PHP $_SESSION ['key' ] 被输入按钮值覆盖。为什么?

php - 如果 mysql 查询为空或不存在?