Home > Software design >  I can't ridirect to stripe checkout from WooCommerce
I can't ridirect to stripe checkout from WooCommerce

Time:08-11

I have an e-commerce website made using WordPress and WooCommerce and for the payment gateway, I am working with stripe. I tried a lot of plugins like WooCommerce Stripe Payment Gateway when I click on the payment buttons it takes me to the WooCommerce checkout page and the payment will be there and WooCommerce will take care of everything but I want to redirect to the stripe checkout page. I found this plugin Stripe Payment Plugin for WooCommerce .

this plugin will allow me to redirect to stripe checkout but unfortunately I guess it has a bug in the code I get this error :

You cannot use line_items.amount, line_items.currency, line_items.name, line_items.description, or line_items.images in this API version. Please use line_items.price or line_items.price_data.

I tried to fix it by myself but I couldn't this is parts of its PHP file

 $session_data['line_items'] = array(
                    [
                        'name'     => esc_html( __( 'Total', 'payment-gateway-stripe-and-woocommerce-integration' ) ),
                        'amount'   => $total,
                        'currency' => strtolower(get_woocommerce_currency()),
                        'quantity' => 1,
                        'images'   => array($images),
                    ]
                );

if (empty($customer_id)) { 

            $customer = $this->create_stripe_customer( $order, $user);

            $customer_id = $customer->id;
            //saved stripe customer for charging  cards later
            update_user_meta($logged_in_userid, "_stripe_ch_customer_id", $customer_id);
        }
        $session_data['customer'] = $customer_id;
        
        $session_data['payment_intent_data']['setup_future_usage'] = 'off_session';

        $session_data['locale'] = $this->stripe_checkout_page_locale;
        $session_data = apply_filters('wt_stripe_alter_checkout_request_params', $session_data, $order);
        $session = \Stripe\Checkout\Session::create($session_data);
        
        return  array(
            'result'   => 'success',
            'redirect' => $this->get_payment_session_checkout_url( $session->id, $order ),
        );

CodePudding user response:

This appears to be related to recent change to the new API version 2022-08-01.

These parameters have been moved into the line_items.price_data object. In order to pass in the data in the new shape that is required you will need to pass something like the following:

$session_data['line_items'] = array(['price_data' => 
                    [
                        'name'     => esc_html( __( 'Total', 'payment-gateway-stripe-and-woocommerce-integration' ) ),
                        'amount'   => $total,
                        'currency' => strtolower(get_woocommerce_currency()),
                        'quantity' => 1,
                        'images'   => array($images),
                    ]
                ]);

You can review the updated API reference doc for more information

  • Related