PHP code example of fm-labs / cakephp-mpay24

1. Go to this page and download the library: Download fm-labs/cakephp-mpay24 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/ */

    

fm-labs / cakephp-mpay24 example snippets


// src/Application.php

class Application extends \Cake\Application {
    public bootstrap($configDir) {
        // ... your bootstrap code ...
        $this->addPlugin('FmLabs/Mpay24')
    }
}

// config/mpay24.php


return [
    'Mpay24' => [
        'production' => [
            'merchantId' => '',
            'merchantPassword' => '',
            'useTestSystem' => false,
            'debug' => true,
        ],

        'testing' => [
            'merchantId' => '',
            'merchantPassword' => '',
            'useTestSystem' => true,
            'debug' => true,
        ]
    ]
];

try {
    $mpay24 = new \FmLabs\Mpay24\Lib\Mpay24Client('testing');
    
    $mdxi = new \FmLabs\Mpay24\Lib\Mpay24Order()
    // ... setup mdxi order ...

    if (!$mdxi->validate()) {
        throw new \RuntimeException('Failed to validate MDXI.');
    }

    $mpay24Response = $mpay24->paymentPage($mdxi);
    $paymentPageURL = $mpay24Response->getLocation(); // get redirect location to the payment page
    if ($paymentPageURL) {
        // ... redirect user to payment page ... 
    }
} catch (\Exception $ex) {
    debug("Something went wrong: " . $ex->getMessage());
}