PHP code example of verifone / core

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

    

verifone / core example snippets




rifone\Core\DependencyInjection\Configuration\Backend\GetAvailablePaymentMethodsConfigurationImpl;
use \Verifone\Core\DependencyInjection\CoreResponse\PaymentMethodImpl;
use \Verifone\Core\DependencyInjection\Transporter\CoreResponse;
use \Verifone\Core\ExecutorContainer;
use \Verifone\Core\Executor\BackendServiceExecutor;
use \Verifone\Core\ServiceFactory;
use \Verifone\Core\Service\Backend\GetAvailablePaymentMethodsService;

$configObject = new GetAvailablePaymentMethodsConfigurationImpl(
    file_get_contents('vendor/verifone/core/Verifone/Core/Tests/Integration/Assets/demo-merchant-agreement-private.pem'), // merchant private key
    'demo-merchant-agreement', // merchant agreement code
    'testSystem', // software name
    '1.2.3.4', // software version
    ['https://epayment.test.point.fi/pw/serverinterface'], // payment service URLs
    '978', // currency used in system - in example EUR
    false // disable Rsa Blinding
);

/** @var GetAvailablePaymentMethodsService $service */
$service = ServiceFactory::createService($configObject, 'Backend\GetAvailablePaymentMethodsService');
$container = new ExecutorContainer();

/** @var BackendServiceExecutor $exec */
$exec = $container->getExecutor('backend');

/** @var CoreResponse $response */
$response = $exec->executeService($service, file_get_contents('vendor/verifone/core/Verifone/Core/Tests/Integration/Assets/point-e-commerce-test-public-key.pem'));

if (!$response->getStatusCode()) {
    return null;
}

$body = $response->getBody();
$availableMethods = ['all']; // Default payment method - redirects to page with possibility to select payment methods

/** @var PaymentMethodImpl $item */
foreach ($body as $item) {
    $availableMethods[] = $item->getCode();
}

// Now, you could store $availableMethods in the database.



rifone\Core\DependencyInjection\CryptUtils\RsaKeyGenerator;

$generator = new RsaKeyGenerator();
$result = $generator->generate();

if ($result) {
    // You could store keys in the file or in the database
    // For example
    file_put_contents('shop_public_key.pem', $generator->getPublicKey());
    file_put_contents('shop_private_key.pem', $generator->getPrivateKey());
} else {
    // RSA keys are not generated properly.
}




ifone\Core\DependencyInjection\Configuration\Frontend\FrontendConfigurationImpl;
use Verifone\Core\DependencyInjection\Configuration\Frontend\RedirectUrlsImpl;
use Verifone\Core\DependencyInjection\Service\AddressImpl;
use Verifone\Core\DependencyInjection\Service\CustomerImpl;
use Verifone\Core\DependencyInjection\Service\OrderImpl;
use Verifone\Core\DependencyInjection\Service\PaymentInfoImpl;
use Verifone\Core\DependencyInjection\Service\ProductImpl;
use Verifone\Core\DependencyInjection\Service\TransactionImpl;
use Verifone\Core\ExecutorContainer;
use Verifone\Core\Service\Frontend\CreateNewOrderService;
use Verifone\Core\ServiceFactory;

$urls = new RedirectUrlsImpl(
    'http://www.testikauppa.fi/success', // Return URL for success payment action
    'http://www.testikauppa.fi/rejected', // Return URL for rejected payment action
    'http://www.testikauppa.fi/cancel', // Return URL for cancelled payment action
    'http://www.testikauppa.fi/expired', // Return URL for expired payment action
    'http://www.testikauppa.fi/error' // Return URL for error payment action
);

$address = new AddressImpl(
    'Street 1', // Address - line 1
    '', // Address - line 2
    '', // Address - line 3
    'Helsinki', // City
    '00100', // Postal code
    '246', // Country code
    'John', // First name
    'Doe' // Last name
);

$customer = new CustomerImpl(
    'John', // First name
    'Doe', // Last name
    '0401234567', // Phone number
    '[email protected]', // Email number
    $address
);

$order = new OrderImpl(
    '1000000260', // Order identification number
    '2021-05-23 11:58:16', // Order create date
    '978', // Currency code
    '1845', // Order total 

$container = new ExecutorContainer(array(ExecutorContainer::REQUEST_CONVERTER => ExecutorContainer::REQUEST_CONVERTER_TYPE_JSON));



rifone\Core\DependencyInjection\Service\OrderImpl;
use \Verifone\Core\ServiceFactory;
use \Verifone\Core\Service\FrontendResponse\FrontendResponseServiceImpl;
use \Verifone\Core\DependencyInjection\Transporter\CoreResponse;
use \Verifone\Core\ExecutorContainer;
use \Verifone\Core\DependencyInjection\CoreResponse\PaymentResponseImpl;
use \Verifone\Core\Converter\Response\CoreResponseConverter;

$exampleResponse = [
    'i-f-1-11_interface-version' => '5',
    'i-f-1-3_order-currency-code' => '978',
    'l-f-1-20_order-gross-amount' => '1845',
    'l-f-1-20_transaction-number' => '4516533313',
    's-f-1-10_software-version' => '1.92.1.64j',
    's-f-1-30_payment-method-code' => 'visa',
    's-f-1-36_order-number' => '1000000260',
    's-t-1-26_filing-code' => '210418261011',
    's-t-1-36_order-note' => '',
    's-t-256-256_signature-one' => '6F7E4A2DAACA57C0AA91F933A6C991DDA38B0E17B6438334478846E42D0C9D6BC3FDFEA02B9B7E21296BA51BCC992181E1D79DBF81382EFFE1BF48A5F689F46AD1B7BB35061C9183733A3C0C3E5463759B4F8DE18EAEC2A8F85A89FE5C79EA0D712C79DBF58D91A542AEC8918DF09DA4663A4C1E66BF665099C512CBB45D8BCA',
    's-t-256-256_signature-two' => '7849E6D685D09C1E8A365BFA5CA46519E040BDB6ABDD4739779248FD7E4DE474473BB96FCD1B05E709B97013DEB94390CB7BE9100668B5F162C09A921CF559F469C8FE5F21AB6981246458C7F7735535215C7CF9BCC9D60F5FD1E8AC998D255B24944522EC781BE1E11F7BE58395E646898D18008E85509222154E51B2A7911C',
    't-f-14-19_order-timestamp' => '2021-05-23 11:58:16',
];

/** @var FrontendResponseServiceImpl $service */
$service = ServiceFactory::createResponseService($exampleResponse);

$orderNumber = $service->getOrderNumber();

// order information
$order = new OrderImpl(
    '1000000260',
    '2021-05-23 11:58:16',
    '978',
    '1845',
    '1500',
    '345'
);

/** @var FrontendResponseServiceImpl $service */
$service->insertOrder($order);
$container = new ExecutorContainer(array('responseConversion.class' => 'Converter\Response\FrontendServiceResponseConverter'));
$exec = $container->getExecutor(ExecutorContainer::EXECUTOR_TYPE_FRONTEND_RESPONSE);

/** @var CoreResponse $parseResponse */
$parsedResponse = $exec->executeService($service, file_get_contents('vendor/verifone/core/Verifone/Core/Tests/Integration/Assets/point-e-commerce-test-public-key.pem'));

/** @var PaymentResponseImpl $body */
$responseBody = $parsedResponse->getBody();
$validate = true;

if ($parsedResponse->getStatusCode() == CoreResponseConverter::STATUS_OK
    && empty($responseBody->getCancelMessage())
) {
    $transactionId = $responseBody->getTransactionNumber();
    $paymentMethod = $responseBody->getPaymentMethodCode();
    
    // Store $paymentMethod and $transactionId in the order data
    // If you need, you could fetch paid amount with: `$responseBody->getOrderGrossAmount() / 100;`
}



use Verifone\Core\DependencyInjection\Configuration\Backend\BackendConfigurationImpl;
use Verifone\Core\DependencyInjection\Service\OrderImpl;
use Verifone\Core\DependencyInjection\Service\TransactionImpl;
use Verifone\Core\DependencyInjection\Transporter\CoreResponse;
use Verifone\Core\Executor\BackendServiceExecutor;
use Verifone\Core\ExecutorContainer;
use Verifone\Core\Service\Backend\GetPaymentStatusService;
use Verifone\Core\Service\Backend\ListTransactionNumbersService;
use Verifone\Core\ServiceFactory;

;
$service->insertOrder($order);

$container = new ExecutorContainer();

/** @var BackendServiceExecutor $executor */
$executor = $container->getExecutor('backend');

/** @var CoreResponse $response */
$response = $executor->executeService($service, file_get_contents('vendor/verifone/core/Verifone/Core/Tests/Integration/Assets/point-e-commerce-test-public-key.pem'));

$transactions = $response->getStatusCode() ? $response->getBody() : [];

/** @var TransactionImpl $transaction */
foreach ($transactions as $transaction) {
    $transaction = new TransactionImpl($transaction->getMethodCode(), $transaction->getNumber());

    /** @var GetPaymentStatusService $service */
    $paymentStatusService = ServiceFactory::createService($config, 'Backend\GetPaymentStatusService');
    $paymentStatusService->insertTransaction($transaction);

    $response = $executor->executeService($paymentStatusService, file_get_contents('vendor/verifone/core/Verifone/Core/Tests/Integration/Assets/point-e-commerce-test-public-key.pem'));
}



use Verifone\Core\DependencyInjection\Configuration\Backend\BackendConfigurationImpl;
use Verifone\Core\DependencyInjection\Service\TransactionImpl;
use Verifone\Core\Executor\BackendServiceExecutor;
use Verifone\Core\ExecutorContainer;
use Verifone\Core\Service\Backend\RefundPaymentService;
use Verifone\Core\ServiceFactory;

', // Payment method
    '4516533313', // Transaction code
    '100', // Refund amount
    '978' // Currency code - EUR in the example
);

/** @var RefundPaymentService $service */
$service = ServiceFactory::createService($config, 'Backend\RefundPaymentService');
$service->insertTransaction($transaction);

$container = new ExecutorContainer();
/** @var BackendServiceExecutor $executor */
$executor = $container->getExecutor('backend');

$response = $executor->executeService($service, file_get_contents('vendor/verifone/core/Verifone/Core/Tests/Integration/Assets/point-e-commerce-test-public-key.pem'));

// if success then store information about refund



ifone\Core\DependencyInjection\Configuration\Frontend\FrontendConfigurationImpl;
use Verifone\Core\DependencyInjection\Configuration\Frontend\RedirectUrlsImpl;
use Verifone\Core\DependencyInjection\Service\AddressImpl;
use Verifone\Core\DependencyInjection\Service\CustomerImpl;
use Verifone\Core\DependencyInjection\Service\OrderImpl;
use Verifone\Core\DependencyInjection\Service\PaymentInfoImpl;
use Verifone\Core\ExecutorContainer;
use Verifone\Core\Service\Frontend\AddNewCardService;
use Verifone\Core\ServiceFactory;

$urls = new RedirectUrlsImpl(
    'http://www.testikauppa.fi/success',
    'http://www.testikauppa.fi/rejected',
    'http://www.testikauppa.fi/cancel',
    'http://www.testikauppa.fi/expired',
    'http://www.testikauppa.fi/error'
);

$address = new AddressImpl(
    'Street 1',
    '',
    '',
    'Helsinki',
    '00100',
    '246',
    'John',
    'Doe'
);

$customer = new CustomerImpl(
    'John',
    'Doe',
    '0401234567',
    '[email protected]',
    $address
);

$order = new OrderImpl(
    '1000000260',
    '2021-05-23 11:58:16',
    '978',
    '1',
    '1',
    '0'
);

$container = new ExecutorContainer(array(ExecutorContainer::REQUEST_CONVERTER => ExecutorContainer::REQUEST_CONVERTER_TYPE_HTML));
$executor = $container->getExecutor('frontend');

$config = new FrontendConfigurationImpl(
    $urls,
    file_get_contents('vendor/verifone/core/Verifone/Core/Tests/Integration/Assets/demo-merchant-agreement-private.pem'),
    'demo-merchant-agreement',
    'testSystem',
    '1.2.3.4',
    '1'
);

/**
 * @var AddNewCardService $service
 */
$service = ServiceFactory::createService($config, 'Frontend\AddNewCardService');

$payment = new PaymentInfoImpl('fi_FI', PaymentInfoImpl::SAVE_METHOD_SAVE_ONLY);

$service->insertCustomer($customer);
$service->insertPaymentInfo($payment);
$service->insertOrder($order);
$form = $executor->executeService($service, array('https://epayment.test.point.fi/pw/payment'));


erifone\Core\DependencyInjection\Service\PaymentInfoImpl;
use Verifone\Core\DependencyInjection\Service\RecurringImpl;

// Same implementation as above

$recurring = new RecurringImpl('Test', 'test');
$payment = new PaymentInfoImpl(
    'fi_FI', 
    PaymentInfoImpl::SAVE_METHOD_SAVE_ONLY, 
    '', 
    '', 
    false,
    $recurring
);

// Same implementation as above



ifone\Core\Executor\BackendServiceExecutor;
use Verifone\Core\ExecutorContainer;
use Verifone\Core\DependencyInjection\Configuration\Backend\BackendConfigurationImpl;
use Verifone\Core\DependencyInjection\Service\CustomerImpl;
use Verifone\Core\Service\Backend\GetSavedCreditCardsService;
use Verifone\Core\ServiceFactory;

$customer = new CustomerImpl(
    'John',
    'Doe',
    '0401234567',
    '[email protected]'
);

$config = new BackendConfigurationImpl(
    file_get_contents('vendor/verifone/core/Verifone/Core/Tests/Integration/Assets/demo-merchant-agreement-private.pem'),
    'demo-merchant-agreement',
    'testSystem',
    '1.2.3.4',
    ['https://epayment.test.point.fi/pw/serverinterface']
);

/** @var GetSavedCreditCardsService $service */
$service = ServiceFactory::createService($config, 'Backend\GetSavedCreditCardsService');
$service->insertCustomer($customer);

$container = new ExecutorContainer();
/** @var BackendServiceExecutor $executor */
$executor = $container->getExecutor('backend');

$response = $executor->executeService($service, file_get_contents('vendor/verifone/core/Verifone/Core/Tests/Integration/Assets/point-e-commerce-test-public-key.pem'));



ifone\Core\Executor\BackendServiceExecutor;
use Verifone\Core\ExecutorContainer;
use Verifone\Core\DependencyInjection\Service\PaymentInfoImpl;
use Verifone\Core\DependencyInjection\Configuration\Backend\BackendConfigurationImpl;
use Verifone\Core\DependencyInjection\Service\CustomerImpl;
use Verifone\Core\Service\Backend\RemoveSavedCreditCardsService;
use Verifone\Core\ServiceFactory;


$customer = new CustomerImpl(
    'John',
    'Doe',
    '0401234567',
    '[email protected]'
);

$config = new BackendConfigurationImpl(
    file_get_contents('vendor/verifone/core/Verifone/Core/Tests/Integration/Assets/demo-merchant-agreement-private.pem'),
    'demo-merchant-agreement',
    'testSystem',
    '1.2.3.4',
    ['https://epayment.test.point.fi/pw/serverinterface']
);

$payment = new PaymentInfoImpl(
    '', 
    '', 
    '123456789' // Saved payment method id
);

/** @var RemoveSavedCreditCardsService $service */
$service = ServiceFactory::createService($config, 'Backend\RemoveSavedCreditCardsService');
$service->insertCustomer($customer);
$service->insertPaymentInfo($payment);

$container = new ExecutorContainer();
/** @var BackendServiceExecutor $executor */
$executor = $container->getExecutor('backend');

$response = $executor->executeService($service, file_get_contents('vendor/verifone/core/Verifone/Core/Tests/Integration/Assets/point-e-commerce-test-public-key.pem'));