PHP code example of mobilly / mpay
1. Go to this page and download the library: Download mobilly/mpay 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/ */
mobilly / mpay example snippets
namespace MpayTest;
use Mobilly\Mpay\Connector;
use Mobilly\Mpay\Request;
use Mobilly\Mpay\SecurityContext;
use Mobilly\Mpay\SuccessResponse;
ndpoint = 'https://mpay-test.mobilly.lv'; // In production: "https://mpay.mobilly.lv"
$context = new SecurityContext($mpayUser, $privateKey, $privateKeySecret, $publicKey);
$request = new Request($context);
$request
->setAmount(250)
->setSummary('Test transaction')
->setServiceId(100)
->setResultUrl('https://mydomain.com/result')
->setReturnUrl('https://mydomain.com/return')
->setContacts('John', 'Doe', '[email protected]')
->setLanguage('en');
$connector = new Connector($context, $endpoint . '/transaction');
$response = $connector->send($request);
if ( ! $response instanceof SuccessResponse) {
die("Error.");
}
$transactionId = $response->getTransactionId();
header("Location: " . $endpoint . "?transid=" . $transactionId);
exit();