How can I create m3u8 file and ts files from the uploaded mp4 by php?

I have a php web application (Using code igniter).
I want to build such features.

  1. User upload the mp4 file to the admin dashboard.
  2. On the backend (PHP), we convert the mp4 file to m3u8 and ts files.
  3. The backend save the m3u8 and ts files on the digitalocean’s Spaces.
  4. On the client side, we use “hls.js” to show the video.

I think I need to use PHP-FFMpeg, but I am not quite sure how to make it.

PHPUnit – assertCount() not returning same result

I am using assertCount() method within my Symfony project and PHPUnit Functional tests. I was refactoring a method, and suddenly I does not work any more. But I am not sure what could be a problem.

I wanted to move my method that I am using multiple times from one class:

public function testPostSuccessful(): void
{
    ... 
    // rest of the request code //

    $response = $this->client->getResponse();
    $responseBody = json_decode($response->getContent(), true);

    $this->assertArraySimilar($this->expected, $responseBody["data"][0]);

    $this->assertEquals(200, $response->getStatusCode());
}

And in my other method:

protected function assertArraySimilar(array $expected, array $array)
{
    // expected amount of key - value pairs are returned
    $this->assertCount(6, $array);
    
    ...
    // rest of the code //
}

This is throwing an error:

Failed asserting that actual size 2 matches expected size 6.

But when I dump the result like:

var_dump(count($array));die;

I get: int(6)

What could be the problem here?

Problem with fetching value out of foreach loop in php

I am having trouble fetching values from foreach loop. I always get NULL values when I try to send request in postman. Here is my code and what I have tried.

php code

$symbol = $request->symbol;
$ticker = $api->prices();

foreach ($symbol as $ticker => $pairname)
{
    echo $pairname;
}

in postman I send request like this

{
   "symbol":"BTCUSDT"
}

When I var_dump $ticker variable the response I get is as follows

array(147) {
["XRPBUSD"]=>
string(6) "0.5881"
["MKRUSDT"]=>
string(7) "2003.70"
["SRMUSDT"]=>
string(6) "2.2300"
["BTCUSDT"]=>
string(6) "37173.34" ... } and etc.

I need when I send symbol value in postman that it prints that value in foreach loop from that $ticker variable. Currently I get NULL value.

WordPress Hosting

I have one personal website(shukriyasongs). But I’II is not happy with my current hosting at more traffic my website go in down, that is more affect my business. Please help me give good hosting in mu budget 200-500RS Per months

I have no knowledge about the best hosting for WordPress websites.
shukriyasongs

Woocommerce Payment Callback not returning the receipt page after successfull transaction

I want to develop a BharatX payment gateway plugin with the help of API documentation provided here: https://developer.bharatx.tech/docs/web/

My plugin after a successful transaction returns the checkout page with an unsuccessful message shown on the checkout page.
The code for pay-in-3_feature_gateway-plugin.php is mentioned below.
Can anyone tell me why is payment callback working like that and how can I use the Webhook callback function inside this?

<?php
/**
 * The paymentgateway-specific functionality of the plugin.
 *
 * @since      1.0.0
 *
 * @package    Bharatx_Pay_In_3_Feature_Plugin
 * @subpackage Bharatx_Pay_In_3_Feature_Plugin/admin
 */

/**
 * The admin-specific functionality of the plugin.
 *
 * Defines the plugin name, version, and two examples hooks for how to
 * enqueue the admin-specific stylesheet and JavaScript.
 *
 * @package    Bharatx_Pay_In_3_Feature_Plugin
 * @subpackage Bharatx_Pay_In_3_Feature_Plugin/admin
 * @author     BharatX <[email protected]>
 */
class Bharatx_Pay_In_3_Feature_Gateway extends WC_Payment_Gateway {

    /**
     * Initialize the class and set its properties.
     *
     * @since    1.0.0
     */
    public function __construct() {

        $this->id                 = BHARATX_PAY_IN_3_FEATURE_SLUG; // payment gateway plugin ID.

        // URL of the icon that will be displayed on checkout page near your gateway name.
        if ( $this->get_option('checkout_page_payment_method_logo_image') ) {
            $this->icon               = $this->get_option('checkout_page_payment_method_logo_image');
        } else {
            $this->icon               = plugin_dir_url( BHARATX_PAY_IN_3_FEATURE_FILE ) . 'public/images/brand.svg';
        }


        $this->has_fields         = true; // in case you need a custom credit card form.
        $this->method_title       = esc_html__( 'Bharatx', 'bharatx-pay-in-3-for-woocommerce' );
        $this->method_description = esc_html__( 'Enables the user to pay in 3 interest free payments.', 'Bharatx_Pay_In_3_Feature_Plugin' );
        $this->log                = new WC_Logger();

        $this->supports = array(
            'products',
          //'refunds',
        );

        $this->init_form_fields();

        $this->init_settings();
        $this->title                  = 'Bharatx';
        $this->description            = 'Pay In 3';
        $this->enabled                = $this->get_option( 'enabled' );
        $this->testmode               = 'yes' === $this->get_option( 'testmode' );
        $this->merchant_partner_id     = $this->get_option( 'merchant_partner_id' );
        $this->merchant_private_key = $this->get_option( 'merchant_private_key' );
        $this->checkout_logo        = $this->get_option('checkout_page_payment_method_logo_image');
        

        add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );

        add_action( 'woocommerce_receipt_' . $this->id, array( $this, 'receipt_page' ) );

        add_action( 'woocommerce_api_' . strtolower( 'BharatX_Pay_In_3_Feature_Gateway' ), array( $this, 'payment_callback' ) );
        
        add_action( 'woocommerce_api_' . strtolower( 'BharatX_Pay_In_3_Feature_Gateway_Webhook' ), array( $this, 'webhook_callback' ) );
    }

    /**
     * Plugin options
     *
     * @since    1.0.0
     */


    

    public function init_form_fields() {
        $this->form_fields = array(
            'enabled'                => array(
                'title'       => esc_html__( 'Enable/Disable', 'Bharatx_Pay_In_3_Feature_Plugin' ),
                'label'       => esc_html__( 'Enable BharatX', 'Bharatx_Pay_In_3_Feature_Plugin' ),
                'type'        => 'checkbox',
                'description' => '',
                'default'     => 'no',
            ),
            'testmode'               => array(
                'title'       => esc_html__( 'Test mode', 'Bharatx_Pay_In_3_Feature_Plugin' ),
                'label'       => esc_html__( 'Enable Test Mode', 'Bharatx_Pay_In_3_Feature_Plugin' ),
                'type'        => 'checkbox',
                'description' => esc_html__( 'Place the payment gateway in test mode using test API keys.', 'Bharatx_Pay_In_3_Feature_Plugin' ),
                'default'     => 'yes',
                'desc_tip'    => true,
            ),
            'merchant_partner_id'     => array(
                'title' => esc_html__( 'Merchant Partner ID', 'Bharatx_Pay_In_3_Feature_Plugin' ),
                'type'  => 'text',
            ),
            'merchant_private_key' => array(
                'title' => esc_html__( 'Merchant Private Key', 'Bharatx_Pay_In_3_Feature_Plugin' ),
                'type'  => 'password',
            ),

            'merchant_popup_image'   => array(
                'title' => esc_html__( 'Price Breakdown Popup Image Path', 'Bharatx_Pay_In_3_Feature_Plugin' ),
                'placeholder' => __( 'Optional', 'Bharatx_Pay_In_3_Feature_Plugin' ),
                'type'  => 'text',
            ),

            'pay_in_3_note_bharatx_logo_image' => array(
                'title' => esc_html__( 'Price Breakdown Description BharatX Logo Image Path', 'Bharatx_Pay_In_3_Feature_Plugin' ),
                'placeholder' => __( 'Optional', 'Bharatx_Pay_In_3_Feature_Plugin' ),
                'type'  => 'text',
            ),

            'checkout_page_payment_method_title' => array(
                'title' => esc_html__( 'Payment Method Title', 'Bharatx_Pay_In_3_Feature_Plugin' ),
                'placeholder' => __( 'Optional', 'Bharatx_Pay_In_3_Feature_Plugin' ),
                'type'  => 'text',
            ),

            'checkout_page_payment_method_description' => array(
                'title' => esc_html__( 'Payment Method Description', 'Bharatx_Pay_In_3_Feature_Plugin' ),
                'placeholder' => __( 'Optional', 'Bharatx_Pay_In_3_Feature_Plugin' ),
                'type'  => 'text',
            ),

            'checkout_page_payment_method_logo_image' => array(
                'title' => esc_html__( 'Payment Method Logo Image Path', 'Bharatx_Pay_In_3_Feature_Plugin' ),
                'placeholder' => __( 'Optional', 'Bharatx_Pay_In_3_Feature_Plugin' ),
                'type'  => 'text',
            ),

            'logging'                => array(
                'title'   => __( 'Enable Logging', 'Bharatx_Pay_In_3_Feature_Plugin' ),
                'type'    => 'checkbox',
                'label'   => __( 'Enable Logging', 'Bharatx_Pay_In_3_Feature_Plugin' ),
                'default' => 'yes',
            ),
        );
    }

    /**
     * Process Payment.
     *
     * @since    1.0.0
     * @param      int $order_id       The Order ID.
     * @return  string $url Redirect URL.
     */
    public function process_payment( $order_id ) {
        try {
            if ( function_exists( 'wc_get_order' ) ) {
                $order = wc_get_order( $order_id );
            } else {
                $order = new WC_Order( $order_id );
            }
            return $this->get_redirect_url( $order );
        } catch(Exception $e) {
            print "something went wrong, caught yah! n";
        }
    }

    /**
     * Returns Initiate URL.
     *
     * @since    1.0.0
     * @return  string $url Initiate URL.
     */
    public function get_initiate_url() {
            return 'https://web.bharatx.tech/api/transaction';
    }


    /**
     * Returns Transaction status URL.
     *
     * @since    1.0.0
     * @param int $order_id The Order Id.
     * @return  string $url Transaction status URL.
     */
    public function get_transaction_status_url( $transaction_id ) {
        $url = 'https://web.bharatx.tech/api/transaction?id={transaction_id}';
        $url = str_replace( '{transaction_id}', $transaction_id, $url );
        return $url;
    }

    /**
     * Returns refund URL.
     *
     * @since    1.0.0
     * @return  string $url refund URL.
     */

    /*
     public function get_refund_url() {
        if ( $this->testmode ) {
            return '';
        } else {
            return '';
        }
    }
    */

    /**
     * Returns Redirect URL.
     *
     * @since    1.0.0
     * @param Object $order Order.
     * @return  array $url redirect URL.
     */
    public function get_redirect_url( $order ) {
        $uniq_order_id = $this->get_unique_order_id($order->get_id());
        $transaction_id = wp_generate_uuid4();

        update_post_meta( $order->get_id(), '_bharatx_order_id', $uniq_order_id );


        $body = array(
            'merchant_partner_id'                 => $this->merchant_partner_id,
            'transaction_status_redirection_url'  => get_site_url() . '/?wc-api=Bharatx_Pay_In_3_Feature_Gateway&key=' . $order->get_order_key(),
            'transaction_status_webhook_url'      => get_site_url() . '/?wc-api=Bharatx_Pay_In_3_Feature_Gateway_Webhook&key=' . $order->get_order_key(),
            'order_id'                            => (string) $uniq_order_id,
            'amount_in_paise'                     => (int) ( $order->calculate_totals() * 100 ),
            'journey_id'                          => WC()->session->get( 'bharatx_journey_id' ),
        );

        $body['user'] = array(
            'first_name'   => $order->get_billing_first_name(),
            'last_name'    => $order->get_billing_last_name(),
            'phone_number' => $order->get_billing_phone(),
            'email'        => $order->get_billing_email(),
        );

        $body['user_details'] = array(
            'id'              => $transaction_id,
            'amount'          => $body['amount_in_paise'],
            'user'            => array(
                'name'            => $order->get_billing_first_name() . $order->get_billing_last_name(),
                'phoneNumber'    => $order->get_billing_phone(),
                'email'           => $order->get_billing_email(),
            ),
            'redirect'        =>array(
                'url'            => $body['transaction_status_redirection_url'],
                'logoOverride?'  => '',
                'colorOverride?' => '',
            )
            
        );

        $body['billing_address'] = array(
            'line1'   => $order->get_billing_address_1(),
            'line2'   => $order->get_billing_address_2(),
            'city'    => $order->get_billing_city(),
            'pincode' => $order->get_billing_postcode(),
        );

        if ( ! empty( $order->get_billing_address_2() ) ) {
            $body['billing_address']['line1'] = $order->get_billing_address_2();
            $body['billing_address']['line2'] = $order->get_billing_address_1();
        }

        $body['shipping_address'] = array(
            'line1'   => $order->get_shipping_address_1(),
            'line2'   => $order->get_shipping_address_2(),
            'city'    => $order->get_shipping_city(),
            'pincode' => $order->get_shipping_postcode(),
        );

        $body['items'] = array();
        if ( count( $order->get_items() ) ) {
            foreach ( $order->get_items() as $item ) {
                if ( $item['variation_id'] ) {
                    if ( function_exists( 'wc_get_product' ) ) {
                        $product = wc_get_product( $item['variation_id'] );
                    } else {
                        $product = new WC_Product( $item['variation_id'] );
                    }
                } else {
                    if ( function_exists( 'wc_get_product' ) ) {
                        $product = wc_get_product( $item['product_id'] );
                    } else {
                        $product = new WC_Product( $item['product_id'] );
                    }
                }
                $item_data = array(
                    'sku'           => $item['name'],
                    'quantity'      => $item['qty'],
                    'rate_per_item' => (int) ( round( ( $item['line_subtotal'] / $item['qty'] ), 2 ) * 100 ),
                );
                array_push( $body['items'], $item_data );
            }
        }


        $this->log( 'BharatX redirecting' );

        $php_string = json_encode($body['user_details'] );
        $msg_hash = $php_string . '/api/transaction' . $this->merchant_private_key;
        $shasignature = hash('sha256',$msg_hash,true);
        $signature = base64_encode($shasignature);

        $args                 = array(
            'method'      => "POST",
            'headers'     => array(
                'Content-Type'  => 'application/json',
                'X-Partner-Id'  => $this->merchant_partner_id,
                'X-Signature'   => $signature,
            ),
            'body' => $php_string
        );
        $initiate_url         = $this->get_initiate_url();
        $response             = wp_remote_post( $initiate_url, $args);
        $encode_response_body = wp_remote_retrieve_body( $response );
        $response_code        = wp_remote_retrieve_response_code( $response );
        $this->dump_api_actions( $initiate_url, $args, $encode_response_body, $response_code );
        if ( 200 === $response_code ) {
            echo($response_code . $encode_response_body);
            $response_body = json_decode($encode_response_body);
            
            update_post_meta( $order->get_id(), '_bharatx_redirect_url', $response_body->redirectUrl );
            return array(
                'result'   => 'success',
                'redirect' =>$order->get_checkout_payment_url( true ),
            );
        } else{
            echo($response_code . $encode_response_body);
            $order->add_order_note( esc_html__( 'Unable to generate the transaction ID. Payment couldn't proceed.', 'Bharatx_Pay_In_3_Feature_Plugin' ) );
            wc_add_notice( esc_html__( 'Sorry, there was a problem with your payment.', 'Bharatx_Pay_In_3_Feature_Plugin' ), 'error' );
            return array(
                'result'   => 'failure',
                'redirect' => $order->get_checkout_payment_url( true ),
            );
        }

    }

    /**
     * Generates unique BharatX order id.
     *
     * @since    1.0.0
     * @param string $order_id Order ID.
     * @return  string $uniq_order_id Unique Order ID.
     */
    public function get_unique_order_id( $order_id ) {
        $random_bytes = random_bytes(13);
        return $order_id . '-' . bin2hex($random_bytes);
    }

    /**
     * Log Messages.
     *
     * @since    1.0.0
     * @param string $message Log Message.
     */
    public function log( $message ) {
        if ( $this->get_option( 'logging' ) === 'no' ) {
            return;
        }
        if ( empty( $this->log ) ) {
            $this->log = new WC_Logger();
        }
        $this->log->add( 'BharatX', $message );
    }

    /**
     * Dump API Actions.
     *
     * @since    1.0.0
     * @param string $url URL.
     * @param Array  $request Request.
     * @param Array  $response Response.
     * @param Int    $status_code Status Code.
     */
    public function dump_api_actions( $url, $request = null, $response = null, $status_code = null ) {
        ob_start();
        echo esc_url( $url );
        echo '<br>';
        echo 'Request Body : ';
        echo '<br>';
        print_r( $request );
        echo '<br>';
        echo 'Response Body : ';
        echo '<br>';
        print_r( $response );
        echo '<br>';
        echo 'Status Code : ';
        echo esc_html( $status_code );
        $data = ob_get_clean();
        $this->log( $data );
    }


    /**
     * Receipt Page.
     *
     * @since    1.0.0
     * @param  int $order_id Order Id.
     */
    public function receipt_page( $order_id ) {
        echo '<p>' . esc_html__( 'Thank you for your order, please wait as your transaction is initiated on the BharatX', 'Bharatx_Pay_In_3_Feature_Plugin' ) . '</p>';
        $redirect_url = get_post_meta( $order_id, '_bharatx_redirect_url', true );
        ?>
        <script>
            var redirect_url = <?php echo json_encode( $redirect_url ); ?>;
            window.location.replace(redirect_url);
        </script>
        <?php
    }

    /**
     * Payment Callback check.
     *
     * @since    1.0.0
     */

     public function payment_callback() {
        $_GET = stripslashes_deep( wc_clean( $_GET ) );
        $this->dump_api_actions( 'paymenturl', '', $_GET );

        $order_key = ( isset( $_GET['key'] ) ) ? sanitize_text_field( wp_unslash( $_GET['key'] ) ) : '';

        $order_id = wc_get_order_id_by_order_key( $order_key );

        try {
            if ( function_exists( 'wc_get_order' ) ) {
                $order = wc_get_order( $order_id );
            } else {
                $order = new WC_Order( $order_id );
            }

            if ( isset( $_GET['status'] ) && 'SUCCESS' === sanitize_text_field( wp_unslash( $_GET['status'] ) ) ) {

                $_order_id           = ( isset( $_GET['order_id'] ) ) ? sanitize_text_field( wp_unslash( $_GET['order_id'] ) ) : '';
                $status              = ( isset( $_GET['status'] ) ) ? sanitize_text_field( wp_unslash( $_GET['status'] ) ) : '';
                $signature           = ( isset( $_GET['signature'] ) ) ? sanitize_text_field( wp_unslash( $_GET['signature'] ) ) : '';
                $signature_algorithm = ( isset( $_GET['signature_algorithm'] ) ) ? sanitize_text_field( wp_unslash( $_GET['signature_algorithm'] ) ) : '';
                $nonce               = ( isset( $_GET['nonce'] ) ) ? sanitize_text_field( wp_unslash( $_GET['nonce'] ) ) : '';
                $transaction_id      = ( isset( $_GET['transaction_id'] ) ) ? sanitize_text_field( wp_unslash( $_GET['transaction_id'] ) ) : '';

                $data = array();
                if ( ! empty( $nonce ) ) {
                    $data['nonce'] = $nonce;
                }
                if ( ! empty( $_order_id ) ) {
                    $data['order_id'] = $_order_id;
                }
                if ( ! empty( $status ) ) {
                    $data['status'] = $status;
                }
                if ( ! empty( $transaction_id ) ) {
                    $data['transaction_id'] = $transaction_id;
                    $order->set_transaction_id( $transaction_id );
                    $order->save();
                }

                $data       = build_query( $data );
                $_signature = hash_hmac( 'sha256', $data, $this->merchant_private_key );

                if ( $signature === $_signature ) {
                    $url = $this->get_transaction_status_url( $transaction_id );
                    $this->log( 'BharatX Transaction Status Check' );
                    $args                 = array(
                        'headers'     => array(
                            'Content-Type'  => 'application/json',
                            'X-Partner-Id' => $this->merchant_partner_id,
                        ),
                    );
                    $response             = wp_remote_get( $url, $args);
                    $encode_response_body = wp_remote_retrieve_body( $response );
                    $response_code        = wp_remote_retrieve_response_code( $response );
                    $this->dump_api_actions( $url, $args, $encode_response_body, $response_code );
                    if ( 200 === $response_code ) {
                        $response_body  = json_decode( $encode_response_body );
                        $status           = $response_body->status;
                        $transaction_id = $order->get_transaction_id();
                        if ( 200 === $response_body->$response_code) {
                            if ( 'SUCCESS' === $response_body->status ) {
                                $order->add_order_note( esc_html__( 'Payment approved by BharatX successfully.', 'Bharatx_Pay_In_3_Feature_Plugin' ) );
                                $order->payment_complete( $data->id );
                                WC()->cart->empty_cart();
                                $redirect_url = $this->get_return_url( $order );
                            } else {
                                $message = esc_html__( 'Your payment via BharatX was unsuccessful. Please try again.', 'Bharatx_Pay_In_3_Feature_Plugin' );
                                $order->update_status( 'failed', $message );
                                $this->add_order_notice( $message );
                                $redirect_url = wc_get_checkout_url();
                            }
                        } else {
                            $data          = $response_body->error;
                            $error_code    = $data->code;
                            $error_message = $data->message;
                            $message       = esc_html__( 'Your payment via BharatX was unsuccessful. Please try again.', 'pcss-woo-order-notifications' );
                            $order->update_status( 'failed', $message );
                            $this->add_order_notice( $message );
                            $redirect_url = wc_get_checkout_url();
                        }
                    } else {
                        $message = esc_html__( 'Your payment via BharatX was unsuccessful. Please try again.', 'Bharatx_Pay_In_3_Feature_Plugin' );
                        $order->update_status( 'failed', $message );
                        $this->add_order_notice( $message );
                        $redirect_url = wc_get_checkout_url();
                    }
                } else {
                    $message = esc_html__( 'Your payment via BharatX was unsuccessful. Please try again.', 'Bharatx_Pay_In_3_Feature_Plugin' );
                    $order->update_status( 'failed', $message );
                    $this->add_order_notice( $message );
                    $redirect_url = wc_get_checkout_url();
                }
            } else {
                $error   = isset( $_GET['error_code'] ) ? sanitize_text_field( wp_unslash( $_GET['error_code'] ) ) : '';
                $message = esc_html__( 'Your payment via BharatX was unsuccessful5. Please try again.', 'Bharatx_Pay_In_3_Feature_Plugin' );
                $order->update_status( 'failed', $message );
                $this->add_order_notice( $message );
                $redirect_url = wc_get_checkout_url();
            }
            wp_redirect( $redirect_url );
            exit();
        } catch(Exception $e) {
            print "something went wrong, caught yah! n";
        }
    }

    /**
     * Webhook Callback check.
     *
     * @since    1.0.0
     */
    
    
    public function webhook_callback() {
        $_GET = stripslashes_deep( wc_clean( $_GET ) );
        $this->dump_api_actions( 'webhook', '', $_GET );
        
        $order_key = ( isset( $_GET['key'] ) ) ? sanitize_text_field( wp_unslash( $_GET['key'] ) ) : '';

        $order_id = wc_get_order_id_by_order_key( $order_key );
        
        try {
            if ( function_exists( 'wc_get_order' ) ) {
                $order = wc_get_order( $order_id );
            } else {
                $order = new WC_Order( $order_id );
            }
            
            if( 'pending' != $order->get_status() ) return;
            
            if ( isset( $_GET['status'] ) && 'SUCCESS' === sanitize_text_field( wp_unslash( $_GET['status'] ) ) ) {
                $_order_id           = ( isset( $_GET['order_id'] ) ) ? sanitize_text_field( wp_unslash( $_GET['order_id'] ) ) : '';
                $status              = ( isset( $_GET['status'] ) ) ? sanitize_text_field( wp_unslash( $_GET['status'] ) ) : '';
                $nonce               = ( isset( $_GET['nonce'] ) ) ? sanitize_text_field( wp_unslash( $_GET['nonce'] ) ) : '';
                $transaction_id      = ( isset( $_GET['transaction_id'] ) ) ? sanitize_text_field( wp_unslash( $_GET['transaction_id'] ) ) : '';
                
                $data = array();
                if ( ! empty( $nonce ) ) {
                    $data['nonce'] = $nonce;
                }
                if ( ! empty( $_order_id ) ) {
                    $data['order_id'] = $_order_id;
                }
                if ( ! empty( $status ) ) {
                    $data['status'] = $status;
                }
                if ( ! empty( $transaction_id ) ) {
                    $data['transaction_id'] = $transaction_id;
                    $order->set_transaction_id( $transaction_id );
                    $order->save();
                }
                
                
                $data       = build_query( $data );
                $_signature = hash( 'sha256', $data, $this->merchant_private_key );
                
                if ( $signature === $_signature ) {
                    $url = $this->get_transaction_status_url( $transaction_id );
                    $this->log( 'BharatX Transaction Status Check' );
                    $args                 = array(
                        'headers'     => array(
                            'Content-Type'  => 'application/json',
                            'X-Partner-Id' => $this->merchant_partner_id,
                        )
                    );
                    $response             = wp_remote_get( $url, $args );
                    $encode_response_body = wp_remote_retrieve_body( $response );
                    $response_code        = wp_remote_retrieve_response_code( $response );
                    $this->dump_api_actions( $$url, $args, $encode_response_body, $response_code );
                    if ( 200 === $response_code ) {
                        $response_body  = json_decode( $encode_response_body );
                        $data           = $response_body->status;
                        $transaction_id = $order->get_transaction_id();
                        if ( empty( $transaction_id ) && ! empty( $data->id ) ) {
                            $order->set_transaction_id( $data->id );
                        }
                        if ( true === $response_body->success ) {
                            if ( 'SUCCESS' === $data->status ) {
                                $order->add_order_note( esc_html__( 'Payment approved by BharatX successfully.', 'Bharatx_Pay_In_3_Feature_Plugin' ) );
                                $order->payment_complete( $data->id );
                            } else {
                                $message = esc_html__( 'Your payment via BharatX was unsuccessful. Please try again.', 'Bharatx_Pay_In_3_Feature_Plugin' );
                                $order->update_status( 'failed', $message );
                                $this->add_order_notice( $message );
                            }
                        } else {
                            $data          = $response_body->error;
                            $error_code    = $data->code;
                            $error_message = $data->message;
                            $message       = esc_html__( 'Your payment via BharatX was unsuccessful. Please try again.', 'pcss-woo-order-notifications' );
                            $order->update_status( 'failed', $message );
                            $this->add_order_notice( $message );
                        }
                    } else {
                        $message = esc_html__( 'Your payment via BharatX was unsuccessful. Please try again.', 'Bharatx_Pay_In_3_Feature_Plugin' );
                        $order->update_status( 'failed', $message );
                        $this->add_order_notice( $message );
                    }
                } else {
                    $message = esc_html__( 'Your payment via BharatX was unsuccessful. Please try again.', 'Bharatx_Pay_In_3_Feature_Plugin' );
                    $order->update_status( 'failed', $message );
                    $this->add_order_notice( $message );
                }   
            }
            else {
                $error   = isset( $_GET['error_code'] ) ? sanitize_text_field( wp_unslash( $_GET['error_code'] ) ) : '';
                $message = esc_html__( 'Your payment via BharatX was unsuccessful. Please try again.', 'Bharatx_Pay_In_3_Feature_Plugin' );
                $order->update_status( 'failed', $message );
                $this->add_order_notice( $message );
            }
            
        }catch(Exception $e) {
            print "something went wrong, caught yah! n";
        }
    }

    /**
     * Add notice to order.
     *
     * @since    1.0.0
     * @param  string $message Message.
     */
    public function add_order_notice( $message ) {
        wc_add_notice( $message, 'error' );
    }
}

One php5.6 page doesn’t display well

I’ve got a task to put a website written in php 5.6 on a server. I used Centos 7, Apache and Mariadb. The site displays correctly but one of the pages shows only half way through no matter what I try.
So, the same page exists in a different language: the exact same code, the exact same css and js files are imported and apache shows exact same warnings about a few unidentified variables – but it shows that on every single working page because of the old php 5.6 and 5.5 functions (my guess).

Has anyone experienced anything similar?

Do I need a different server or additional php libraries?
I followed this guide https://computingforgeeks.com/how-to-install-php-on-centos-fedora/ for installing old php.

It is a bit vague, but I have to start from somewhere.

Thank you!

How to fix zsh:command not found : php while installing composer?

I want to install composer in my macbook pro ( MacOS Monterey version 12.1 , chip M1 pro). How I install it (below):
1.first I open the terminal in macbook and paste these :

Mac@Mine-MacBook-Pro ~ % php -r “copy(‘https://getcomposer.org/installer’, ‘composer-setup.php’);”
php -r “if (hash_file(‘sha384’, ‘composer-setup.php’) === ‘906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8’) { echo ‘Installer verified’; } else { echo ‘Installer corrupt’; unlink(‘composer-setup.php’); } echo PHP_EOL;”
php composer-setup.php
php -r “unlink(‘composer-setup.php’);”

I got the command line from this website :Composer Download

  1. press Enter
  2. Then not success with show message on my terminal :

zsh: command not found: php
zsh: command not found: php
zsh: command not found: php
zsh: command not found: php

  1. please help fix it for me. I need to install composer and install laravel for my laptop.

big thanks,

Login With Google customer login data Database table Management

My website is a small business listing website. People can register with their email id and post their business in my website. I gave a customer id to people at the time of registration which is an auto AUTO INCREMENT key in my “user table”. The same key is given to userId column of “business” table at the time for business posting for knowing which customer upload data and for future editing of business listing of that registered person. Now I am trying to implement “Login with Google” feature in my website for easy customer registration. But I have no idea to manage user who coming from “Login with Google” feature.
I have an idea but which is good or Not , i am not knowing. Keeping separate SQL table “user_google”, where also an AUTO INCREMENT key starting from 10000000 to manage multiple customer id problem. When I saw userId>10000000, I can understand which is coming from “Login with Google”.
In my old table “user” there is also a column for “password”. But i think there is no such column in “user_google” table as I think.
Also one doubt is there, if already one customer login with google feature , and uploaded his business, in future if he trying to register through registration form in my website, how can I handle this?. How many customers can use login with google feature in my website per day? My website is PHP and SQL website.

PHP: search array(A) value in array(B) and get 2nd “column” value

I have Array(A) = ('red','green')

and

Array(B) 
( array('colour' => "red", 'name_cz' =>"cervena"),
array('colour' => "green", 'name_cz' =>"zelena"),
array('colour' => "blue", 'name_cz' =>"modra"),
array('colour' => "yellow", 'name_cz' =>"zluta")
)

I need to take every value of Array(A), compare it with Array(B) colour values and if it finds get its name_cz value…

so the output of the example should be like $result = (array("cervena", "zelena");

Thanks for help, subii

How to route every API request through own proxy?

On my LAMP server, I have a Javascript, JQuery based app, which makes requests to a remote API and displays its responses. As long as only I use the app, everything is OK. But now I must open this app to multiple users, and if the API gets multiple requests from the same IP, it bans the IP.

What is the way to route each request through its own proxy address? I have many working proxies as a list, and a proxy gateway, which can route multiple requests.

A simple example or just a correct keyword to search would be enough as an answer.

Ajax doesn’t call javascript function correctly

php) that via ajax calls a table from another page (temp2.php).
If I execute temp2.php via browser directly it works so the function works. Infact the function validate the input number be assign red or green colour.

temp2.php is here:
https://jsfiddle.net/cg3Lhstz/

if i all temp2.php from temp1.php via ajax, I can see the input field, but when i type inside it doesn’t validate so the function is not correctly executed and in the browser console i have the following error:

temp1.php:1 Uncaught ReferenceError: checkValid is not defined
    at HTMLInputElement.onkeyup (temp1.php:1:1)

temp1.php has the following code:

<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <script src="plugins/jQuery/jquery-2.2.3.min.js"></script>
</head>
<body>
    <div id="trc"></div>
</body>
    
<script>
$("#trkview").show();

  if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  } else { // code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function() {
    if (this.readyState==4 && this.status==200) {
      document.getElementById("trc").innerHTML=this.responseText;
    }
  }
  xmlhttp.open("POST","cc_temp2.php");
  xmlhttp.send();

any help ? thanks a lot

Shinyproxy – redirect loop after login by oauth openid

after upgrade ShinyProxy I have login problem.

I use OIDC with my own auth server to login to shiny. Everythink work well on 2.3.1, after update to 2.6.1 I have redirection loop. In my shinyproxy.log I can see:

Using generated security password: 6b5a0b37-7d15-441b-82c2-7b521390f98c
…
2022-01-28 11:10:53.561 WARN 1617 — [main] org.thymeleaf.templatemode.TemplateMode : [THYMELEAF][main] Template Mode ‘HTML5’ is deprecated. Using Template Mode ‘HTML’ instead.
2022-01-28 11:10:53.566 INFO 1617 — [main] e.o.c.stat.StatCollectorFactory : Enabled. Sending usage statistics to jdbc:mysql://xx.xxx.xx.xxx:3306/admdev_test.
2022-01-28 11:10:53.875 INFO 1617 — [main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService
2022-01-28 11:10:53.876 INFO 1617 — [main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService ‘taskExecutor’
2022-01-28 11:10:54.198 INFO 1617 — [main] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page template: index
2022-01-28 11:10:54.727 INFO 1617 — [main] o.s.l.c.support.AbstractContextSource : Property ‘userDn’ not set - anonymous context will be used for read-write operations
2022-01-28 11:10:54.983 INFO 1617 — [main] io.undertow : starting server: Undertow - 2.2.8.Final
2022-01-28 11:10:55.007 INFO 1617 — [main] org.xnio : XNIO version 3.8.4.Final
2022-01-28 11:10:55.033 INFO 1617 — [main] org.xnio.nio : XNIO NIO Implementation Version 3.8.4.Final
2022-01-28 11:10:55.145 INFO 1617 — [main] org.jboss.threads : JBoss Threads version 3.1.0.Final
2022-01-28 11:10:55.231 INFO 1617 — [main] o.s.b.w.e.undertow.UndertowWebServer : Undertow started on port(s) 8080 (http)
2022-01-28 11:10:55.378 INFO 1617 — [main] io.undertow.servlet : Initializing Spring embedded WebApplicationContext
2022-01-28 11:10:55.378 INFO 1617 — [main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 141 ms
2022-01-28 11:10:55.397 INFO 1617 — [main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 1 endpoint(s) beneath base path ‘/actuator’
2022-01-28 11:10:55.471 INFO 1617 — [main] io.undertow : starting server: Undertow - 2.2.8.Final
2022-01-28 11:10:55.517 INFO 1617 — [main] o.s.b.w.e.undertow.UndertowWebServer : Undertow started on port(s) 9090 (http)
2022-01-28 11:10:55.537 INFO 1617 — [main] e.o.c.util.StartupEventListener : Started ShinyProxy 2.6.0 (ContainerProxy 0.8.10)
2022-01-28 11:10:55.537 INFO 1617 — [main] e.o.c.service.AppRecoveryService : Recovery of running apps disabled
2022-01-28 11:11:19.442 INFO 1617 — [XNIO-1 task-1] io.undertow.servlet : Initializing Spring DispatcherServlet ‘dispatcherServlet’
2022-01-28 11:11:19.443 INFO 1617 — [XNIO-1 task-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet ‘dispatcherServlet’
2022-01-28 11:11:19.451 INFO 1617 — [XNIO-1 task-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 8 ms
2022-01-28 11:11:42.879 INFO 1617 — [XNIO-1 task-1] e.o.containerproxy.service.UserService : User logged in [user: [email protected]]
2022-01-28 11:11:42.880 INFO 1617 — [XNIO-1 task-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting…
2022-01-28 11:11:44.122 ERROR 1617 — [XNIO-1 task-1] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.

java.sql.SQLException: Access denied for user ‘admdev’@‘Debian-95-stretch-64-LAMP’ (using password: YES)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) ~[mysql-connector-java-8.0.25.jar!/:8.0.25]

2022-01-28 11:11:44.127 ERROR 1617 — [XNIO-1 task-1] io.undertow.request : UT005023: Exception handling request to /login/oauth2/code/shinyproxy

java.lang.reflect.UndeclaredThrowableException: Failed to invoke event listener method
HandlerMethod details:
Bean [eu.openanalytics.containerproxy.stat.impl.JDBCCollector]
Method [public void eu.openanalytics.containerproxy.stat.impl.AbstractDbCollector.onUserLoginEvent(eu.openanalytics.containerproxy.event.UserLoginEvent) throws java.io.IOException]
Resolved arguments:
[0] [type=eu.openanalytics.containerproxy.event.UserLoginEvent] [value=eu.openanalytics.containerproxy.event.UserLoginEvent[source=eu.openanalytics.containerproxy.service.UserService@751817d9]]

at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:322) ~[spring-context-5.2.15.RELEASE.jar!/:5.2.15.RELEASE]

information about mysql user (admdev) i have only in m server side. Settings for my mysql is ok so firstly i have info about successful login. I dont know why it show this error then. Also everything work ok when I downgrade to 2.3.1 i dont need to change anything in my server side.
Maybe anyone know what can i do to fix it?

PHP SSH2 echo to file for stop session

I want to create a stop.sh file for stopping screen session.

$test = "screen_name";

This is the command:
kill -15 $(screen -ls | grep '[0-9]*.$test' | sed -E 's/s+([0-9]+)..*/1/')

And i want to create this file with php ssh2_exec like this:

ssh2_exec($connection, "echo 'kill -15 $(screen -ls | grep '[0-9]*.$test' | sed -E 's/s+([0-9]+)..*/1/')' > /home/test/stop.sh");

But i got this:

sh: 1: Syntax error: "(" unexpected

I tried:

kill -15 $(screen -ls | grep '[0-9]*.$test' | sed -E 's/s+([0-9]+)..*/1/')

but not working..