当前位置: 首页 > 知识库问答 >
问题:

Wordpress自定义页面模板条带集成显示-“PHP致命错误:未捕获错误:未找到类'Stripe\Stripe'错误”

翟聪
2023-03-14

我在付款中使用了以下代码。php页面模板。。。

    <?php
/*
Template Name: Page: Donate Success
*/  
// Check whether stripe token is not empty

    if(!empty($_POST['stripeToken'])){ 

// Retrieve stripe token, card and user info from the submitted form data 
$token  = $_POST['stripeToken']; 
$name = $_POST['forename']." ". $_POST['surname']; 
$email = $_POST['email']; 
$card_number = $_POST['card_number']; 
$card_exp_month = $_POST['card_exp_month']; 
$card_exp_year = $_POST['card_exp_year']; 
$card_cvc = $_POST['card_cvc']; 

// Include Stripe PHP library 
require_once(site_url().'/stripe-php/init.php'); 

\Stripe\Stripe::setApiKey("sk_test_my_secret_key");    

// Add customer to stripe 
$customer = \Stripe\Customer::create(array( 
    'email' => $email, 
    'source'  => $token 
)); 

// Unique order ID 
$orderID = strtoupper(str_replace('.','',uniqid('', true))); 

// Convert price to cents 
$itemPrice = ($itemPrice*100); 

// Charge a credit or a debit card 
$charge = \Stripe\Charge::create(array( 
    'customer' => $customer->id, 
    'amount'   => $itemPrice, 
    'currency' => $currency, 
    'description' => $itemName, 
    'metadata' => array( 
        'order_id' => $orderID 
    ) 
)); 

// Retrieve charge details 
$chargeJson = $charge->jsonSerialize(); 

// Check whether the charge is successful 
if($chargeJson['amount_refunded'] == 0 && empty($chargeJson['failure_code']) && $chargeJson['paid'] == 1 && $chargeJson['captured'] == 1){ 
    // Order details  
    $transactionID = $chargeJson['balance_transaction']; 
    $paidAmount = $chargeJson['amount']; 
    $paidCurrency = $chargeJson['currency']; 
    $payment_status = $chargeJson['status'];  


    // If the order is successful 
    if($payment_status == 'succeeded'){ 
        $ordStatus = 'success'; 
        $statusMsg = 'Your Payment has been Successful!'; 
    }else{ 
        $statusMsg = "Your Payment has Failed!"; 
    } 
}else{ 

    $statusMsg = "Transaction has been failed!"; 
} 
}else{ 
$statusMsg = "Error on form submission."; 
} 
?>

<div class="container">
<div class="status">
        <h1 class="<?php echo $ordStatus; ?>"><?php echo $statusMsg; ?></h1>

        <h4>Payment Information</h4>
        <p><b>Reference Number:</b> <?php echo $payment_id; ?></p>
        <p><b>Transaction ID:</b> <?php echo $transactionID; ?></p>
        <p><b>Paid Amount:</b> <?php echo $paidAmount.' '.$paidCurrency; ?></p>
        <p><b>Payment Status:</b> <?php echo $payment_status; ?></p>

        <h4>Product Information</h4>
        <p><b>Name:</b> <?php echo $itemName; ?></p>
        <p><b>Price:</b> <?php echo $itemPrice.' '.$currency; ?></p>
    </div>
    <a href="index.php" class="btn-link">Back to Payment Page</a>
</div>

我将stripe sdk文件包含在Wordpress的根文件夹中。。。

令牌是从支付表单生成的,并在上述模板中找到,但我在下面的代码行\Stripe\Stripe::setApiKey(“sk_test_my_secret_key”)中发现了错误;称为“PHP致命错误:未捕获错误:未找到类'Stripe\Stripe'错误”。。。

非常感谢。

共有1个答案

岳正阳
2023-03-14

这两行代码应该放在第一位:

// Include Stripe PHP library 
require_once(site_url().'/stripe-php/init.php'); 

\Stripe\Stripe::setApiKey("sk_test_my_secret_key");    

示例:

<?php
// Include Stripe PHP library 
require_once(site_url().'/stripe-php/init.php'); 
\Stripe\Stripe::setApiKey("sk_test_my_secret_key");    


/*
Template Name: Page: Donate Success
*/  
// Check whether stripe token is not empty

    if(!empty($_POST['stripeToken'])){ 

// Retrieve stripe token, card and user info from the submitted form data 
$token  = $_POST['stripeToken']; 
$name = $_POST['forename']." ". $_POST['surname']; 
$email = $_POST['email']; 
$card_number = $_POST['card_number']; 
$card_exp_month = $_POST['card_exp_month']; 
$card_exp_year = $_POST['card_exp_year']; 
$card_cvc = $_POST['card_cvc']; 


// Add customer to stripe 
$customer = \Stripe\Customer::create(array( 

.... 

看看这是否解决了你的问题。

 类似资料:
  • 尝试在我的stripe帐户上提交测试付款时,我遇到以下错误: 致命错误:未捕获错误:在/home/dh#u y3rvc7/vvnow.dreamhosters.com/wp-content/plugins/wp-Stripe-integration/includes/process payment.php:25堆栈跟踪:#0/home/dh#uy3rvc7/vvnow.dreamhosters.c

  • 我收到了以下错误消息: 致命错误:未捕获错误:在F:\projects\websites\main\u website\app\Exceptions\Handler中找不到类“Auth”。php:65堆栈跟踪:#0 F:\projects\websites\main\u website\vendor\laravel\framework\src\illighted\Foundation\Http\K

  • 我现在必须学习通过fire base编写移动应用程序web服务。我点击了这个链接:https://firebase-php.readthedocs.io/en/stable/ 在我的核心网站中,我创建web服务文件夹,然后创建我的fire。php文件。这个文件代码在这里, 我得打电话给我的支持档案:https://github.com/kreait/firebase-php/ 但我还是得到了一个:

  • 问题内容: 我试图与XAMPP和MySQL服务器建立简单连接,但是每当我尝试输入数据或连接到数据库时,都会出现此错误。 致命错误:未捕获错误:在C:\ xampp \ htdocs \ register.php:22中调用未定义函数mysql_connect() 堆栈跟踪:#0 {main}在第22行的C:\ xampp \ htdocs \ register.php中抛出 第22行的示例: 问题

  • 我在尝试访问http://localhost/phpmyadmin/时收到以下错误: 在这里回顾了类似的主题后,我做了以下工作: null 我运行的是Windows10,Apache2.4-64bits、PHP7-64bits和mysqlserver5.7。Apache运行良好,PHP也运行良好(访问info.PHP无需担心) 谢了。

  • 我正在按照一个在线教程来创建一个迷你购物车,一切都很顺利,但现在我得到了这个错误: 致命错误:未捕获错误:调用未定义函数mysql_query()