PHP code example of samyan / omnipay-ecopayz

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

    

samyan / omnipay-ecopayz example snippets


$gateway = Omnipay::create('Ecopayz');

// You code
// { . . . }

$params = array(
	'customerIdAtMerchant' => $customerIdAtMerchant,
	'transactionId' => $transactionId,
	'amount' => $amount,
	'currency' => $currency,
	'notifyUrl' => $notifyUrl,
	'returnUrl' => $returnUrl,
	'cancelUrl' => $cancelUrl
);

$request = $gateway->purchase($params);
$response = $request->send();

if ($response->isRedirect() === true) {
	echo $response->getRedirectUrl();
}

// You code
// { . . . }

$request = $gateway->completePurchase();
$response = $request->send();

// Check if ok
if (!$response->isSuccessful()) {
	return false;
}

// Get XML object
$xml = $response->getData();

$resultCode = (string)$xml->TransactionResult->Code;

// Check transaction status
switch ($resultCode) {
	case '0':
		$state = 'success';
		break;
	case '1':
		$state = 'failed';
		break;
	case '2':
		$state = 'cancelled';
		break;
	case '3':
		$state = 'failed';
		break;
	case '4':
		$state = 'pending';
		break;
	case '5':
		$state = 'cancelled';
}

// You code
// { . . . }

// At the end print the response to Ecopayz  (obligatory for completation of purchase)
echo $response->getXmlData();