PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, November 11, 2022

[FIXED] How to implementing EasyPay Pakistan Payment gateway in WordPress?

 November 11, 2022     javascript, payment-gateway, php, plugins, wordpress     No comments   

Issue

Hi Everyone I am trying to implement the EasyPay Pakistan payment gateway for my website but i am getting this error Parameter Authentication failed my code is below which is in plugin they provided:

<?php 
require '../../../wp-config.php';

    $storeId = get_option('storeId');
    $daysToExpire = get_option('daysToExpire');
    
    $live = get_option('live');
    $liveVal = $live['menu'];
    $easypayIndexPage = '';
    if ($liveVal == 'no') {
        $easypayIndexPage = 'https://easypaystg.easypaisa.com.pk/easypay/Index.jsf';
    } else {
        $easypayIndexPage = 'https://easypay.easypaisa.com.pk/easypay/Index.jsf';
    }

    $merchantConfirmPage = home_url().'/wp-content/plugins/Easypay/confirmEasypay.php';

    $options = get_option('autoRedirect');
    //$autoRedirect = checked( isset( $options['autoRedirectCb'] ) );
    $autoRedirect = checked( isset( $options['autoRedirectCb'] ),1,false ); 
    if($autoRedirect) {
        $autoRedirect = 1;
    } else {
        $autoRedirect = 0;
    }   
    
    $orderId = $_GET['orderId'];
    if (strpos($_GET['amount'], '.') !== false) {
        $amount = $_GET['amount'];
    } else {
        $amount = sprintf("%0.1f",$_GET['amount']);
    }
    
    $custEmail = $_GET['custEmail'];
    $custCell = $_GET['custCell'];
    $hashKey = get_option('hashKey');
    date_default_timezone_set('Asia/Karachi');
    $expiryDate = '';
    $currentDate = new DateTime();
    if($daysToExpire != null) {
        $currentDate->modify('+'.$daysToExpire.'day');
        $expiryDate = $currentDate->format('Ymd His');
    }
    
    $paymentMethods = get_option('paymentMethod');
    $paymentMethodVal = $paymentMethods['methods'];
    
    $hashRequest = '';
    if(strlen($hashKey) > 0 && (strlen($hashKey) == 16 || strlen($hashKey) == 24 || strlen($hashKey) == 32 )) {
        // Create Parameter map
        $paramMap = array();
        $paramMap['amount']  = $amount ;
        $paramMap['autoRedirect']  = $autoRedirect ;
        if($custEmail != null && $custEmail != '') {
            $paramMap['emailAddr']  = $custEmail ;
        }
        if($expiryDate != null && $expiryDate != '') {
            $paramMap['expiryDate'] = $expiryDate;
        }
        if($custCell != null && $custCell != '') {
            $paramMap['mobileNum'] = $custCell;
        }
        $paramMap['orderRefNum']  = $orderId ;
        
        if($paymentMethodVal != null && $paymentMethodVal != '') {
            $paramMap['paymentMethod']  = $paymentMethodVal ;
        }       
        $paramMap['postBackURL'] = $merchantConfirmPage;
        $paramMap['storeId']  = $storeId ;
        
        //Creating string to be encoded
        $mapString = '';
        foreach ($paramMap as $key => $val) {
            $mapString .=  $key.'='.$val.'&';
        }
        $mapString  = substr($mapString , 0, -1);
        

        // Encrypting mapString
    $ivlen = openssl_cipher_iv_length($cipher="AES-128-ECB");
    $iv = openssl_random_pseudo_bytes($ivlen);
    $crypttext = openssl_encrypt($mapString, $cipher, $hashKey,OPENSSL_RAW_DATA, $iv);
    $hashRequest = base64_encode($crypttext);
    
    }
    
    $con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if (!$con) {
            die('Could not connect: ' . mysqli_errno());    
    }     
    mysqli_select_db($con, DB_NAME);
    global $wpdb;
    $table_name = $wpdb->prefix . 'easypay_order';
    
    // mysql inserting an order with pending status
    $query = "INSERT INTO ".$table_name."( easypay_order_id, easypay_order_info, easypay_order_status, ipn_attr ) VALUES ('$orderId' ,'null',  'pending',  'null')";
    try {
        mysqli_query($con, $query);
    } catch (Exception $ex) {            
        error_log($ex->getMessage());
    }
// echo $easypayIndexPage;
 //echo "\r\n".$storeId;
 // echo $amount;
  //echo $merchantConfirmPage;
  //echo $orderId;
 // echo $hashRequest;
 //<?php  header("Location: $easypayIndexPage") ?>


<form name="easypayform" method="post" action="<?php echo $easypayIndexPage;  ?>"> 
    <input name="storeId" value="<?php echo $storeId ?>" hidden = "true" readOnly="true" />
    <input name="amount" value="<?php echo $amount ?>" hidden = "true"/>
    <input name="postBackURL" value="<?php echo $merchantConfirmPage ?>" hidden = "true" readOnly="true" />
    <input name="orderRefNum" value="<?php echo $orderId ?>" hidden = "true" readOnly="true" />
    <?php if ($expiryDate != '' && $expiryDate != null) { ?>
        <input name="expiryDate" value="<?php echo $expiryDate ?>" hidden = "false"/>
    <?php } ?>  
    <input name="autoRedirect" value="<?php echo $autoRedirect ?>" hidden = "true"/>
    <input name="emailAddr" value="<?php echo $custEmail ?>" hidden = "true"/>
    <input name="mobileNum" value="<?php echo $custCell ?>" hidden = "true"/>
    <input name="merchantHashedReq" value="<?php echo $hashRequest ?>" hidden = "true"/>
    <input name="paymentMethod" value="<?php echo $paymentMethodVal ?>" hidden = "true"/>
    
</form>

<script data-cfasync="false" type="text/javascript">
   document.easypayform.submit();
</script>

When I click on Proceed to easypay nothing appears on the page and just white black page appears, so after research I came to know that this below written code is not working:

<script data-cfasync="false" type="text/javascript">
   document.easypayform.submit();
</script>

Therefore I added this line of code into my form so that I can manually click the button so redirect to EasyPay page.

<input type = "submit" value="Submit">

Now, when clicking on the submit button it is redirecting to EasyPay page but this error occurs saying Parameter Authentication failed.

enter image description here

So, is there anyone who can help me out in this implementation because there support team is not helpful. I will be very thankful for your help.


Solution

This EasyPay plugin can't accept payment values greater than 2 decimals, so, by going in Woo-Commerce plugin in the currency's setting and changing number of decimals to 1 the EasyPay plugin issue will be resolve.



Answered By - Tariq Mehmood
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing