1

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?

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
Mohammad Sharaf Ali
  • 569
  • 1
  • 4
  • 19
  • What do you mean "the sample code doesn't seem to be working"? Is there an error message? – Moshe Katz Jan 06 '16 at 01:19
  • Yes php gives Fatal error and the message says to provide the returnURL. How can I provide it in the above example? Further more it also asked to provide the transactionId. I don't know where to find it and provide. And yes the sample code was taken from github. – Mohammad Sharaf Ali Jan 06 '16 at 10:21
  • I wouldn't use the $response->redirect() method. How you do a redirect depends on what framework you are using -- some of them prefer you create a redirect object and return that from your controller, some others implement it very differently. What I would do instead is to get the redirect URL using $response->getRedirectUrl() and redirect to that using your framework's usual method. – delatbabel Jan 07 '16 at 04:02
  • The question I have asked it that the code is not executing as it asks to provide the returnURL and transactionId. Can you provide any working sample of it? – Mohammad Sharaf Ali Jan 07 '16 at 06:02
  • No one here to help on this? – Mohammad Sharaf Ali Jan 10 '16 at 05:36

3 Answers3

1
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.');
}
Mohammad Sharaf Ali
  • 569
  • 1
  • 4
  • 19
1

I had the same question, what is the returnURL about? The answer is the difference between the Migs_TwoParty and Migs_ThreeParty methods.

The Migs_ThreeParty passes control to the payment provider and when the payment is processed control is passed back to your website. The documentation puts it this way:

The cardholder's Internet browser is redirected to take the Transaction Request to the Payment Server to process the transaction. After processing the transaction, the cardholder's Internet browser is returned to a web page that you nominate in the transaction together with a Transaction Response. The Transaction Response processing of the receipt information completes the transaction.

If you want to do all of the interfacing with the Gateway yourself you should use the Migs_TwoParty method. The returnURL is then not required.

Cheers Murray

muz the axe
  • 418
  • 2
  • 17
  • I agree. The code I have posted works in the case of 2 party where you need to provide returnUrl and transactionId. After struggling for lot of hours I managed to make the code work as expected. Thanks :-) – Mohammad Sharaf Ali Aug 16 '16 at 05:34
  • @MohammadSharafAli Can you share with us the final code result ... thnx – Ahmed Mohamed Jul 01 '20 at 10:15
  • I only ever implemented the MIGS_TwoParty, and that code has now been replaced as we moved to Payway a few years back. – muz the axe Jul 02 '20 at 11:45
0

Mohammad Sharaf Ali had resolved my all problem regarding the MiGS. Thank you Mohammad Sharaf Ali.

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/34533289) – Second2None Jun 15 '23 at 01:54