PHP code example of hopsey / blue-media-connector

1. Go to this page and download the library: Download hopsey/blue-media-connector 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/ */

    

hopsey / blue-media-connector example snippets


use BlueMediaConnector\Transaction\RedirectMode;

$bmService = BlueMediaConnector\Factory::build("http://url.bm.pl/url", 123456, "verySecretString");
$bmService->makeTransaction(
    new RedirectMode(), // typ wywolania: RedirectMode - przekierowanie, jest jeszcze wywołanie w tle, niezaimplemenotwane
    1.50,       // float - kwota
    "Wplata",   // opis
    1,          // gatewayId
    "PLN",      // currency
    "[email protected]"   // customer email
);

use BlueMediaConnector\Event\PreTransactionEvent;

$bmService->getEventManager()->attach(PreTransactionEvent::EVENT_PRE_TRANSACTION, function (PreTransactionEvent $event) {
    /** @var BlueMediaConnector\Message\InitTransactionMessage */
    $message = $event->getParam('message');
    $message->amount; // 1.50
    $message->currency; // PLN
    
    // ... do stuff here. np zapis do bazy, etc.
});

use BlueMediaConnector\Event\MessageReceivedEvent;

$transactionContent = base64_decode($_GET['transactions']);

$bmService->getEventManager()->attach(MessageReceivedEvent::EVENT_MESSAGE_RECEIVED, function (MessageReceivedEvent $event) {
    /** @var BlueMediaConnector\Message\ItnMessage */
    $message = $event->getParam('message');
    $messageArray = $message->toArray();
    $messageArray['transactions'][0]['status'] // pending, success, failure ...
    // ...
});

$bmService->receiveItnResult($transactionContent);

// PHP7
$bmService->getHashFactory()->setAlgo(new class implements AlgoInterface {
    public function hash($string)
    {
        return md5($string);
    }
});


// PHP7
use BlueMediaConnector\Transport\TransportInterface;

$bmService->setTransport(new class implements TransportInterface {
    public function parse($content)
    {
        return json_decode($content);
    }
})