thephpleague / omnipay-migs

MIGS driver for the Omnipay PHP payment processing library
MIT License
21 stars 30 forks source link

Working example #1

Open stevenmc opened 9 years ago

stevenmc commented 9 years ago

Hi, I'm just wondering if you can provide one working example of this (preferrably Migs_ThreeParty), as I came across a SO post (http://stackoverflow.com/a/21069883/504617) but this didn't seem to work for me and it looks very different to the code in your unit tests. Any advice would be greatly appreciated. Thank you.

Ahmad-Zaky commented 4 years ago

@stevenmc try this one it did work with me

        // Setup payment gateway
        $gateway = Omnipay::create('Migs_ThreeParty');

        $gateway->setMerchantId('yourMerchentId');
        $gateway->setMerchantAccessCode('yourAccessCode');
        $gateway->setSecureHash('yourSecureHash');

        try {
            $response = $gateway->purchase([
                'amount' => 10.00, // amount should be greater than zero
                'currency' => 'AED',
                'transactionId' => 123456, // replace this for your reference # such as invoice reference #
                'returnURL' => route('paymentStatus'),
                'localeCode' => 'en'
            ])->send();

            if ($response->isRedirect()) {
                $url = $response->getRedirectUrl(); // do whatever with the return url

                return redirect($url);
            } else {
                echo 'error';
                // 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.');
        }