sanjayacloud's avatar

Need a help with "require(./app/Libraries/mpgClasses.php): failed to open stream: No such file or directory" error

Hi,

I am going to integrate "https://github.com/Moneris/eCommerce-Unified-API-PHP" payment gateway to my e-commerce website. When I trying to do a transaction. It's getting below error.

"require(./app/Libraries/mpgClasses.php): failed to open stream: No such file or directory" 

Here is my code

   public function paymentCheck(Request $request)
    {
        require "./app/Libraries/mpgClasses.php";
        $store_id='gwca053715';
        $api_token='irvDSjeybrg9mgnYte4r';
        /************************* Transactional Variables ****************************/
        $type='purchase';
        $cust_id='cust id';
        $order_id='ord-'.date("dmy-G:i:s");
        $amount='1.00';
        $pan='4242424242424242';
        $expiry_date='2011';
        $crypt='7';
        $dynamic_descriptor='123';
        $status_check = 'false';

        /*********************** Transactional Associative Array **********************/
        $txnArray=array('type'=>$type,
            'order_id'=>$order_id,
            'cust_id'=>$cust_id,
            'amount'=>$amount,
            'pan'=>$pan,
            'expdate'=>$expiry_date,
            'crypt_type'=>$crypt,
            'dynamic_descriptor'=>$dynamic_descriptor
            //,'wallet_indicator' => '' //Refer to documentation for details
            //,'cm_id' => '8nAK8712sGaAkls56' //set only for usage with Offlinx - Unique max 50 alphanumeric characters transaction id generated by merchant
        );
        /**************************** Transaction Object *****************************/

        $mpgTxn = new \mpgTransaction($txnArray);
        /******************* Credential on File **********************************/
        $cof = new \CofInfo();
        $cof->setPaymentIndicator("U");
        $cof->setPaymentInformation("2");
        $cof->setIssuerId("168451306048014");
        $mpgTxn->setCofInfo($cof);
        /****************************** Request Object *******************************/
        $mpgRequest = new \mpgRequest($mpgTxn);
        $mpgRequest->setProcCountryCode("CA"); //"US" for sending transaction to US environment
        $mpgRequest->setTestMode(true); //false or comment out this line for production transactions
        /***************************** HTTPS Post Object *****************************/
        /* Status Check Example
        $mpgHttpPost  =new mpgHttpsPostStatus($store_id,$api_token,$status_check,$mpgRequest);
        */
        $mpgHttpPost = new \mpgHttpsPost($store_id,$api_token,$mpgRequest);
        /******************************* Response ************************************/
        $mpgResponse=$mpgHttpPost->getMpgResponse();
        print("\nCardType = " . $mpgResponse->getCardType());
        print("\nTransAmount = " . $mpgResponse->getTransAmount());
        print("\nTxnNumber = " . $mpgResponse->getTxnNumber());
        print("\nReceiptId = " . $mpgResponse->getReceiptId());
        print("\nTransType = " . $mpgResponse->getTransType());
        print("\nReferenceNum = " . $mpgResponse->getReferenceNum());
        print("\nResponseCode = " . $mpgResponse->getResponseCode());
        print("\nISO = " . $mpgResponse->getISO());
        print("\nMessage = " . $mpgResponse->getMessage());
        print("\nIsVisaDebit = " . $mpgResponse->getIsVisaDebit());
        print("\nAuthCode = " . $mpgResponse->getAuthCode());
        print("\nComplete = " . $mpgResponse->getComplete());
        print("\nTransDate = " . $mpgResponse->getTransDate());
        print("\nTransTime = " . $mpgResponse->getTransTime());
        print("\nTicket = " . $mpgResponse->getTicket());
        print("\nTimedOut = " . $mpgResponse->getTimedOut());
        print("\nStatusCode = " . $mpgResponse->getStatusCode());
        print("\nStatusMessage = " . $mpgResponse->getStatusMessage());
        print("\nHostId = " . $mpgResponse->getHostId());
        print("\nIssuerId = " . $mpgResponse->getIssuerId());
    }

0 likes
3 replies
siangboon's avatar

in your code you specify the require file, however system can find it....

require "./app/Libraries/mpgClasses.php"

please double check the file exist and no typo error

drashtantnayak's avatar

@sanjayacloud I know you posted this months ago, but I recently started work on moneis and I found very interesting way of solving this problem.

In order to use moneris classes I am doing following,

STEP 1: download mpgClasses.php from https://github.com/Moneris/eCommerce-Unified-API-PHP

STEP 2: create new folder in root directory and add mentioned file

libs/mpgClasses.php

STEP 3: Add following in composer.json file (in autoload section),

"classmap": ["libs"],

composer.json autoload section will look like following,

 "autoload": {
        "classmap": ["libs"],
        "psr-4": {
            "App\": "app/",
            "Database\Factories\": "database/factories/",
            "Database\Seeders\": "database/seeders/"
        }
    },

STEP 4: now run following command,

composer install
// sometimes composer throws error because of dependency errors so you can run following as well
composer install --ignore-platform-reqs

STEP 5: all done, now you can use any class from the mentioned file by doing following anywhere in project,

use mpgTransaction;

I've added custom helper class so I am doing something as this,

<?php

namespace App\Services;
use mpgTransaction;
use CofInfo;
use mpgRequest;
use mpgHttpsPost;
class MonerisPaymentService
{
			//your code goes here....
}

Please or to participate in this conversation.