PHP code example of ixopay / ixopay-php-client

1. Go to this page and download the library: Download ixopay/ixopay-php-client 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/ */

    

ixopay / ixopay-php-client example snippets




use Ixopay\Client\Client;
use Ixopay\Client\Data\Customer;
use Ixopay\Client\Transaction\Debit;
use Ixopay\Client\Transaction\Result;

// Instantiate the "Ixopay\Client\Client" with your credentials
$api_user = "your_username";
$api_password = "your_username";
$connector_api_key = "your_chosen_connector_api_key";
$connector_shared_secret = "your_generated_connector_shared_secret";
$client = new Client($api_user, $api_password, $connector_api_key, $connector_shared_secret);



// define your transaction ID: e.g. 'myId-'.date('Y-m-d').'-'.uniqid()
$merchantTransactionId = 'your_transaction_id'; // must be unique

$customer = new Customer()
$customer = $customer
    ->setBillingCountry("AT")
    ->setEmail("[email protected]");

// after the payment flow the user is redirected to the $redirectUrl
$redirectUrl = 'https://example.org/success';
// all payment state changes trigger the $callbackUrl hook
$callbackUrl = 'https://api.example.org/payment-callback';

$debit = new Debit();
$debit = $debit->setTransactionId($merchantTransactionId)
    ->setSuccessUrl($redirectUrl)
    ->setCancelUrl($redirectUrl)
    ->setCallbackUrl($callbackUrl)
    ->setAmount(10.00)
    ->setCurrency('EUR')
    ->setCustomer($customer);

// send the transaction
$result = $client->debit($debit);

// now handle the result
if ($result->isSuccess()) {
    //act depending on $result->getReturnType()

    $gatewayReferenceId = $result->getReferenceId(); //store it in your database

    if ($result->getReturnType() == Result::RETURN_TYPE_ERROR) {
        //error handling
        $errors = $result->getErrors();
        //cancelCart();

    } elseif ($result->getReturnType() == Result::RETURN_TYPE_REDIRECT) {
        //redirect the user
        header('Location: '.$result->getRedirectUrl());
        die;

    } elseif ($result->getReturnType() == Result::RETURN_TYPE_PENDING) {
        //payment is pending, wait for callback to complete

        //setCartToPending();

    } elseif ($result->getReturnType() == Result::RETURN_TYPE_FINISHED) {
        //payment is finished, update your cart/payment transaction

        //finishCart();
    }
}

bash
composer