Surcharge Coding error (maybe php8 related)? Caused fatal errors
-
We noticed on our website that purchases were being correctly transacted into Stripe, however, they were reaching a fatal error on the WordPress side. So although Stripe was capturing the payment, WordPress was showing the user a fatal error, and not re-directing them to the thank-you page. And the orders were not being captured/shown in the WP-admin backend “orders” section.
I did some digging in the error logs and it seemed to be related to “Surchage” coding.
I was getting this error:Fatal error: Uncaught Error: Cannot use object of type stdClass as array in /public_html/wp-content/plugins/stripe-payments/includes/class-asp-payment-data.php:58
For the moment I have manually updated the code of the plugin myself, editing this file:/includes/class-asp-payment-data.php
FROM:public function get_surcharge_data( string $key ) {
if ( empty($this->surcharge_data) ) {
$metadata = isset($this->obj->charges->data[0]->metadata) ? $this->obj->charges->data[0]->metadata : array();
if (isset($metadata['Surcharge Amount'])){
$this->surcharge_data['amount'] = $metadata['Surcharge Amount'];
}
if (isset($metadata['Surcharge Label'])){
$this->surcharge_data['label'] = $metadata['Surcharge Label'];
}
}
return isset($this->surcharge_data[$key]) ? (string) $this->surcharge_data[$key] : '';
}TO:
public function get_surcharge_data( string $key ) {
// Ensure surcharge_data is initialized as an array if not already
if (!is_array($this->surcharge_data)) {
$this->surcharge_data = array();
}
if ( empty($this->surcharge_data) ) {
// Check if metadata exists and is an object
$metadata = isset($this->obj->charges->data[0]->metadata) ? (array) $this->obj->charges->data[0]->metadata : array();
if (isset($metadata['Surcharge Amount'])) {
$this->surcharge_data['amount'] = $metadata['Surcharge Amount'];
}
if (isset($metadata['Surcharge Label'])) {
$this->surcharge_data['label'] = $metadata['Surcharge Label'];
}
}
return isset($this->surcharge_data[$key]) ? (string) $this->surcharge_data[$key] : '';
}I hope that helps, can you double check if your plugin is setup correctly to handle PHP8 in this regard, or if any other tweaks are necessary?
The topic ‘Surcharge Coding error (maybe php8 related)? Caused fatal errors’ is closed to new replies.