PHP code example of dahromy / mvola-bundle

1. Go to this page and download the library: Download dahromy/mvola-bundle 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/ */

    

dahromy / mvola-bundle example snippets


use DahRomy\MVola\Service\MVolaService;
use DahRomy\MVola\Model\TransactionRequest;

class PaymentController extends AbstractController
{
    private $mvolaService;

    public function __construct(MVolaService $mvolaService)
    {
        $this->mvolaService = $mvolaService;
    }

    public function initiatePayment()
    {
        $transactionRequest = new TransactionRequest();
        $transactionRequest->setAmount(1000)
            ->setCurrency('Ar')
            ->setDescriptionText('Payment for order #123')
            ->setRequestingOrganisationTransactionReference('123456')
            ->setRequestDate(new \DateTime())
            ->setOriginalTransactionReference('123456')
            ->setDebitParty([['key' => 'msisdn', 'value' => '0343500003']])
            ->setCreditParty([['key' => 'msisdn', 'value' => '0343500004']])
            ->setMetadata([
                ['key' => 'partnerName', 'value' => 'Partner Name'],
                ['key' => 'fc', 'value' => 'USD'],
                ['key' => 'amountFc', 'value' => '1']
            ])
            ->setCallbackData([
                'userId' => '123456',
                // ... other callback data
            ]);

        $result = $this->mvolaService->initiateTransaction($transactionRequest);

        // Handle the result
    }
}

$status = $this->mvolaService->getTransactionStatus($serverCorrelationId);

$details = $this->mvolaService->getTransactionDetails($transactionId);

use DahRomy\MVola\Event\MVolaCallbackEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class MVolaCallbackSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            MVolaCallbackEvent::NAME => 'onMVolaCallback',
        ];
    }

    public function onMVolaCallback(MVolaCallbackEvent $event): void
    {
        // Response data from MVola
        $mvolaData = $event->getMVolaData();
        
        // Callback data sent with the transaction request
        $callbackData = $event->getCallbackData();

        // Process the callback data
        // For example, update the transaction status in your database
        // or trigger any necessary business logic
    }
}

$transactionRequest = new TransactionRequest();
// ... set other transaction details ...
$transactionRequest->setCallbackData([
    'orderId' => '123456',
    'customerId' => '789',
]);

$result = $this->mvolaService->initiateTransaction($transactionRequest);

$transactionRequest->setCallbackUrl('https://example.com/mvola/callback');