phpomnipay

Omnipay migs integration


Hello I'm using omnipay github lib with migs integration in my project. The sample code isn't seems to be working. Can anyone help me with this?

require_once 'vendor/autoload.php';

use \Omnipay\Omnipay as omnipay;

$gateway = Omnipay::create('Migs_ThreeParty');
$gateway->setMerchantId('foo');
$gateway->setMerchantAccessCode('foo');
$gateway->setSecureHash('foo');

try {
    $response = $gateway->purchase(array('amount' => '0.00', 'currency' => 'AED', 'returnURL' => 'www.google.com.pk'))->send();

    if ($response->isRedirect()) {
        // redirect to offsite payment gateway
        $response->redirect();
        //$url = $response->getRedirectUrl();
        //$data = $response->getRedirectData();

    } else {
        // payment failed: display message to customer
        echo $response->getMessage();
    }
} catch (\Exception $e) {
    // internal error, log exception and display a generic message to the customer
    exit('Sorry, there was an error processing your payment. Please try again later.');
}

Does "$gateway->setSecureHash" == "$SECURE_SECRET" as shown in the example link http://integrate-payment-gateway.blogspot.in/2012/01/migs-payment-gateway-integration-php.html

The above code is asking for the redirectUrl and the transactionId. Where to specify it?


Solution

  • require_once 'vendor/autoload.php';
    
    use \Omnipay\Omnipay as omnipay;
    
    $gateway = Omnipay::create('Migs_ThreeParty');
    $gateway->setMerchantId('MerchantId');
    $gateway->setMerchantAccessCode('MerchantAccessCode');
    $gateway->setSecureHash('SecureHash');
    
    try {
        $response = $gateway->purchase(array(
            'amount' => '10.00', // amount should be greater than zero
            'currency' => 'AED',
            'transactionId' => 'refnodata', // replace this for your reference # such as invoice reference #
            'returnURL' => 'http://yourdomain.com/returnPage.php'))->send();
    
        if ($response->isRedirect()) {
            $url = $response->getRedirectUrl(); // do whatever with the return url
        } else {
            // payment failed: display message to customer
            echo $response->getMessage();
        }
    } catch (\Exception $e) {
        // internal error, log exception and display a generic message to the customer
        echo $e;
        exit('Sorry, there was an error processing your payment. Please try again later.');
    }