【问题标题】:Wordpress custom page template Stripe integration showing - "PHP Fatal error: Uncaught Error: Class 'Stripe\Stripe' not found" ERROR"Wordpress 自定义页面模板 Stripe 集成显示 - “PHP 致命错误:未捕获的错误:找不到类 'Stripe\Stripe'”错误”
【发布时间】:2020-02-16 10:38:30
【问题描述】:

我在payment.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 的根文件夹中...

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

谢谢你..

【问题讨论】:

  • 我的回答还没有解决你的问题吗?如果您已解决,请关闭问题并将解决方案提供给其他用户

标签: php wordpress stripe-payments


【解决方案1】:

这两行代码应该先出现:

// 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( 

.... 

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

【讨论】:

    猜你喜欢
    • 2019-05-14
    • 1970-01-01
    • 2015-05-27
    • 1970-01-01
    • 1970-01-01
    • 2021-06-22
    • 1970-01-01
    • 2019-07-12
    • 2017-01-18
    相关资源
    最近更新 更多