PHP code example of bankette / omnipay-hipay

1. Go to this page and download the library: Download bankette/omnipay-hipay 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/ */

    

bankette / omnipay-hipay example snippets


use Bankette\OmnipayHipay\Gateway;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;

/**
 * Payment by hipay Action.
 *
 * @return Response
 */
    public function hipayPaymentAction(SymfonyRequest $request)
    {
        $data = [
            'orderid' => 'my-order-id',
            'amount' => 10,
            'currency' => 'EUR',
            'card' => [
                'number' => '4000000000000002',
                'expiryMonth' => '10',
                'expiryYear' => '2020',
                'cvv' => '123',
            ],
            'cardtype' => 'visa',
            'description' => 'description',
        ];

        $gateway = new Gateway();
        $gateway->setClientId($this->username);
        $gateway->setSecret($this->password);
        $gateway->setTestMode(true);
        $purchaseResponse = $gateway->purchase($data)->send();

        if (!$purchaseResponse->isSuccessful() && !$purchaseResponse->isRedirect()) {
            throw new BadRequestHttpException($purchaseResponse->getError());
        }

        if ($purchaseResponse->isSuccessful()) {
            // Payment validated
        }

        if ($purchaseResponse->isRedirect() && $purchaseResponse->getRedirectUrl()) {
            // Payment waiting for 3D secure validation
        }
        // ...
    }

    /**
     * @return Response
     *
     * @Route("/hipay/notify")
     *
     * @Method("POST")
     *
     * @View()
     *
     * @throws NotFoundHttpException
     */
    public function hipayNotifyAction(SymfonyRequest $request)
    {
        $gateway = new Gateway();

        $response = $gateway->completePurchase();

        switch ($response->getStatus()) {
            // Status "Cardholder Enrolled"
            case '103':
            // Status "Cardholder Not Enrolled"
            case '104':
            // Status "Authorized"
            case '116':
            // Status "Capture Requested"
            case '117':
                // do something
                break;

            // Status "Captured"
            case '118':
                // do something
                break;

            // Status "Could Not Authenticate"
            case '108':
            // Status "Authentication Failed"
            case '109':
            // Status "Refused"
            case '113':
            // Status "Expired"
            case '114':
                // do something
                break;

            default:
                // do something
                break;
        }

        return new Response();
    }