PHP code example of tltc / momovn

1. Go to this page and download the library: Download tltc/momovn library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tltc / momovn example snippets

sh
php artisan vendor:publish --tag=config
sh
        $momoService = new MomovnService();
        $orderId = 'M'.rand(1, 20000);
        $amount = (string)rand(1000000, 2000000);
        $orderInfo = "Momo API testing";
        $requestId = 'M'.rand(1,200000);
        $returnUrl = route('home');
        $notifyUrl = route('home');
        $extraData = "merchantName=;merchantId=";
        $response = $momoService->requestMomoPayment($requestId, $amount, $orderId, $orderInfo, $returnUrl, $notifyUrl, $extraData);
        if ($response && !empty($response->payUrl)) {
            return redirect($response->payUrl); // Redirect to Momo payment
        } else {
            dd($response); // Check error code in Momo document
        }