成功支付Stripe API后输出成功消息

时间:2018-06-14 19:30:36

标签: php stripe-payments

目前使用Stripe处理付款但是我想执行一条SQL语句,当条带风险评估最高时,该语句会禁止用户。

我有下面的代码但是当我在测试模式下使用条带并使用输出highest风险等级的卡时,似乎显示的是异常消息而不是禁止消息,因此用户没有&#39被禁止我仍然希望保留通用异常消息,因为它可以输出其他消息,例如当卡被拒绝等时,但是对于这种情况,我希望highest风险级if语句优先。< / p>

代码:

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

if ($_POST) {
  Stripe::setApiKey($stripeSecretKey);
  $error = '';
  $success = '';

  try {
    if (empty($_POST['street']) || empty($_POST['city']) || empty($_POST['zip']))
      throw new Exception("Fill out all required fields.");
    if (!isset($_POST['stripeToken']))
      throw new Exception("The Stripe Token was not generated correctly");
    $response = Stripe_Charge::create(array("amount" => $price * 100,
                                "currency" => "gbp",
                                "card" => $_POST['stripeToken'],
                                "description" => "User: " . $userUsername . " - " . $userEmail,
                                "receipt_email" => $userEmail));

    if($response->paid == true){
    $success = '<div class="alert alert-success">
                <strong>Success:</strong> Your payment was successful, Redirecting...
                </div>';
                header('Refresh: 3; URL=https://example.com/profile');
                $txid = generateTxid();

                $SQL = $odb -> prepare("INSERT INTO `payments` VALUES(NULL, :price, :planid, :userid, :payer, :transactionid, UNIX_TIMESTAMP())");
                $SQL -> execute(array(':price' => $price, ':planid' => $planID, ':userid' => $userID, ':payer' => $userEmail, ':transactionid' => $txid));


                $string = generateRandomString();

                $SQL = $odb -> prepare("INSERT INTO `users_api` VALUES(NULL, :userID, :key, :attacks,");
                $SQL -> execute(array(':userID' => $userID, ':key' => $string, ':attacks' => '0'));

                $unit = $plan['unit'];
                $length = $plan['length'];
                $newExpire = strtotime("+{$length} {$unit}");
                $updateSQL = $odb -> prepare("UPDATE `users` SET `expire` = :expire, `membership` = :plan WHERE `ID` = :id");
                $updateSQL -> execute(array(':expire' => $newExpire, ':plan' => (int)$planID, ':id' => (int)$userID));
    }
    elseif($response->outcome->risk_level == "highest"){
        $error = '<div class="alert alert-danger">
              <strong>Error:</strong> Banned. Reason: Fraudulent payment.
              </div>';
        $SQLUpdate = $odb -> prepare("UPDATE `users` SET `status` = 1 WHERE `username` = :username");
        $SQLUpdate -> execute(array(':username' => $userUsername));
        $SQL = $odb -> prepare("UPDATE `users` SET `ban_reason` = 'Fraudulent payment.' WHERE `username` = :username");
        $SQL -> execute(array(':username' => $userUsername));
        header('Refresh: 3; URL=https://example.com/logout');
    }

  }
  catch (Exception $e) {
    $error = '<div class="alert alert-danger">
              <strong>Error:</strong> '.$e->getMessage().'
              </div>';
  }
}

if(!(empty($success))){


}
?>

0 个答案:

没有答案
相关问题