【问题标题】:Charging card with Stripe带条纹的充电卡
【发布时间】:2016-12-21 23:34:10
【问题描述】:

在 Stripe 中一切正常 - 生成令牌,写入我仪表板的“日志”部分等。但是不收取任何费用。即使我完成了条带文档提供的所有错误处理,我也没有从 Stripe 或我的代码中得到任何错误。我该如何纠正这个问题?

require_once ("vendor/autoload.php");

if ($_POST) {
 echo "catch if";

 // Set your secret key: remember to change this to your live secret key in production
 // See your keys here: https://dashboard.stripe.com/account/apikeys

 StripeStripe::setApiKey("myApyKey");

 // Get the credit card details submitted by the form

 $token = $_POST['stripeToken'];

 // Create a charge: this will charge the user's card

 try {
  echo "charging";
  $charge = StripeCharge::create(array(
   "amount" => 1000, // Amount in cents
   "currency" => "eur",
   "source" => $token,
   "description" => "Example charge"
  ));
 }

 catch(StripeErrorCard $e) {

  // Since it's a decline, \Stripe\Error\Card will be caught

  $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");
 }

 catch(StripeErrorRateLimit $e) {

  // Too many requests made to the API too quickly

 }

 catch(StripeErrorInvalidRequest $e) {

  // Invalid parameters were supplied to Stripe's API

 }

 catch(StripeErrorAuthentication $e) {

  // Authentication with Stripe's API failed
  // (maybe you changed API keys recently)

 }

 catch(StripeErrorApiConnection $e) {

  // Network communication with Stripe failed

 }

 catch(StripeErrorBase $e) {

  // Display a very generic error to the user, and maybe send
  // yourself an email

 }

 catch(Exception $e) {

  // Something else happened, completely unrelated to Stripe

 }

【问题讨论】:

  • 您的捕获大多是默默地失败。要么删除它们,要么让它们做一些明显的事情,比如print "OH SHIT Stripe InvalidRequest";
  • 在此行之后尝试 $err = $body['error']; print_r($err);并查看错误。

标签: php stripe-payments


【解决方案1】:

您可能遇到了错误,并且您的代码正在正确处理该错误,但您的错误处理代码实际上并没有 在许多情况下执行任何操作。

您可能应该在每个 catch 块中添加一些内容(例如 print 调用),以准确查看返回的问题类型。

另外,您的 Stripe Dashboard 可以在https://dashboard.stripe.com/logs 上查看您的帐户实时模式和测试模式日志,其中将包含针对 Stripe 服务器的每个请求(成功与否)的条目。

【讨论】:

  • 我发现问题了!!
  • 实际上我的 API 不是最新的!显然 Stripe 不想告诉我这很重要 :)
  • 他们可能在告诉你。您的无所事事 catch 声明可能对您隐瞒了这一点。
【解决方案2】:

尝试使用下面的代码查找错误问题

try {
  echo "charging";
  $charge = StripeCharge::create(array(
   "amount" => 1000, // Amount in cents
   "currency" => "eur",
   "source" => $token,
   "description" => "Example charge"
  ));
 }

 catch(StripeErrorCard $e) {
    $error = $e->getJsonBody();
    <pre>print_r($error);</pre>
    //then you can handle like that 
    if($error == "Your card was declined."){
      echo "Your credit card was declined. Please try again with an alternate card.";
     }
 }

【讨论】:

    猜你喜欢
    • 2023-03-05
    • 1970-01-01
    • 2015-12-18
    • 2021-12-20
    • 2021-10-20
    • 1970-01-01
    • 2020-03-26
    • 2014-04-28
    • 2020-11-27
    相关资源
    最近更新 更多