PHP code example of owlympus / owly-monetico

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

    

owlympus / owly-monetico example snippets


$monetico = new \OwlyMonetico\Monetico(
    '1234567', // Code TPE, 7 caractères max
    '0E23341908D38F6119E49F77651A15B8D4290203', // Clé de sécurité, 40 caractères hexadécimaux
    'maSociete' // Code société
);

use OwlyMonetico\Collection\Civility;
use OwlyMonetico\Collection\Country;
use OwlyMonetico\Model\Customer;

$customer = (new Customer())
    ->setCivility($id_gender == 1 ? Civility::MR : Civility::MLLE) // Optionnel
    ->setFirstName('John') // Optionnel
    ->setLastName('Doe') // Optionnel
    ->setBirthdate(new DateTime('1970-01-01')) // Optionnel
    ->setEmail('[email protected]') // Optionnel
    ->setCountry(Country::FR); // Optionnel

use OwlyMonetico\Model\Cart;
use OwlyMonetico\Model\Item;

$item = (new Item())
    ->setName('Item de test') // Optionnel
    ->setQuantity(1)
    ->setUnitPrice(2000); // En centimes

$cart = (new Cart())
    ->addItem($item);

use OwlyMonetico\Collection\Country;
use OwlyMonetico\Model\BillingAddress;

$billingAddress = new BillingAddress(
    'Pl. Général de Gaulle',
    'La Valette-du-Var',
    '83160',
    Country::FR)
    ->setFirstName('John') // Optionnel
    ->setLastName('Doe') // Optionnel
    ->setEmail('[email protected]'); // Optionnel

use OwlyMonetico\Collection\Country;
use OwlyMonetico\Model\ShippingAddress;

$billingAddress = new ShippingAddress(
    'Pl. Général de Gaulle',
    'La Valette-du-Var',
    '83160',
    Country::FR)
    ->setFirstName('John') // Optionnel
    ->setLastName('Doe') // Optionnel
    ->setEmail('[email protected]'); // Optionnel

use OwlyMonetico\Model\Order;

$order = new Order(
    uniqid('ref_'),
    $cart->getItemTotalAmount(),
    $customer,
    $cart,
    $billingAddress,
    $shippingAddress
);

use OwlyMonetico\Collection\Currency;
use OwlyMonetico\Collection\Language;
use OwlyMonetico\Request\SimplePaymentRequest;

$simpleRequest = (new SimplePaymentRequest($order, Language::FR, Currency::EUR))
    ->setUrlSuccess('http://localhost/success') // Optionnel
    ->setUrlError('http://localhost/fail') // Optionnel
    ->setEmail('[email protected]'); // Optionnel pour envoyer le reçu.

// Récupération des valeurs AVEC vérification des champs
try {
    $simpleFields = $monetico->getSimplePaymentRequestFields($simpleRequest); // skipValidation: false par défaut
} catch (Exception $e) {
    die($e->getMessage());
}
var_dump($simpleFields);

// Récupération des champs SANS vérification
$simpleFields = $monetico->getSimplePaymentRequestFields($simpleRequest, true); // skipValidation: true
var_dump($simpleFields);

use OwlyMonetico\Collection\Currency;
use OwlyMonetico\Collection\Language;
use OwlyMonetico\Request\IFramePaymentRequest;

$iFrameRequest = (new IFramePaymentRequest($order, Language::FR, Currency::EUR, '[email protected]')) // Email obligatoire pour cette méthode
    ->setUrlSuccess('http://localhost/success') // Optionnel
    ->setUrlError('http://localhost/fail'); // Optionnel

// Récupération des valeurs AVEC vérification des champs
try {
    $iframeFields = $monetico->getIFramePaymentRequestFields($iFrameRequest); // skipValidation: false par défaut
} catch (Exception $e) {
    die($e->getMessage());
}
var_dump($iframeFields);

// Récupération des champs SANS vérification
$iframeFields = $monetico->getIFramePaymentRequestFields($iFrameRequest, true); // skipValidation: true
var_dump($iframeFields);

use OwlyMonetico\Collection\Currency;
use OwlyMonetico\Collection\Language;
use OwlyMonetico\Request\SplitPaymentRequest;

$splitRequest = (new SplitPaymentRequest($order, Language::FR, Currency::EUR, 2)) // Nombre de paiements
    ->setUrlSuccess('http://localhost/success.php') // Optionnel
    ->setUrlError('http://localhost/fail.php') // Optionnel
    ->setDueAmount1(10.00)
    ->setDueDate1(new DateTime()) // Premier paiement aujourd'hui
    ->setDueAmount2(10.00)
    ->setDueDate2(new DateTime('+1 month')); // Second paiement dans un mois (Échéances mensuelles obligatoires)

// Récupération des valeurs AVEC vérification des champs
try {
    $splitFields = $monetico->getSplitPaymentRequestFields($splitRequest); // skipValidation: false par défaut
} catch (Exception $e) {
    die($e->getMessage());
}
var_dump($iframeFields);

// Récupération des champs SANS vérification
$splitFields = $monetico->getSplitPaymentRequestFields($splitRequest, true); // skipValidation: true
var_dump($splitFields);

use OwlyMonetico\Collection\Currency;
use OwlyMonetico\Collection\Language;
use OwlyMonetico\Request\PreAuthorizedPaymentRequest;

$preAuthorizedRequest = (new PreAuthorizedPaymentRequest($order, Language::FR, Currency::EUR, '20150901PRE1')) // Le numéro de dossier obligatoire
    ->setUrlSuccess('http://localhost/success.php') // Optionnel
    ->setUrlError('http://localhost/fail.php'); // Optionnel

// Récupération des valeurs AVEC vérification des champs
try {
    $preAuthorizedFields = $monetico->getPreAuthorizedPaymentRequestFields($splitRequest); // skipValidation: false par défaut
} catch (Exception $e) {
    die($e->getMessage());
}
var_dump($preAuthorizedFields);

// Récupération des champs SANS vérification
$preAuthorizedFields = $monetico->getPreAuthorizedPaymentRequestFields($preAuthorizedRequest, true); // skipValidation: true
var_dump($preAuthorizedFields);

use OwlyMonetico\Collection\Civility;
use OwlyMonetico\Collection\Currency;
use OwlyMonetico\Collection\Language;
use OwlyMonetico\Request\CofidisPaymentRequest;

$cofidisRequest = (new CofidisPaymentRequest($order, Language::FR, Currency::EUR))
    ->setCivility(Civility::MR) // Optionnel
    ->setFirstName('Yannick') // Optionnel
    ->setUrlSuccess('http://localhost/success.php') // Optionnel
    ->setUrlError('http://localhost/fail.php'); // Optionnel

// Récupération des valeurs AVEC vérification des champs
try {
    $cofidisFields = $monetico->getCofidisPaymentRequestFields($splitRequest); // skipValidation: false par défaut
} catch (Exception $e) {
    die($e->getMessage());
}
var_dump($preAuthorizedFields);

// Récupération des valeurs SANS vérification des champs
$cofidisFields = $monetico->getCofidisPaymentRequestFields($cofidisRequest, true); // skipValidation: true
var_dump($cofidisFields);

$monetico = new \OwlyMonetico\Monetico(
    '1234567', // EPT Code, 7 characters max
    '0E23341908D38F6119E49F77651A15B8D4290203', // Security key, 40 hexadecimal characters
    'myCompany' // Company code
);

use OwlyMonetico\Collection\Civility;
use OwlyMonetico\Collection\Country;
use OwlyMonetico\Model\Customer;

$customer = (new Customer())
    ->setCivility($id_gender == 1 ? Civility::MR : Civility::MLLE) // Optional
    ->setFirstName('John') // Optional
    ->setLastName('Doe') // Optional
    ->setBirthdate(new DateTime('1970-01-01')) // Optional
    ->setEmail('[email protected]') // Optional
    ->setCountry(Country::FR); // Optional

use OwlyMonetico\Model\Cart;
use OwlyMonetico\Model\Item;

$item = (new Item())
    ->setName('Test item') // Optional
    ->setQuantity(1)
    ->setUnitPrice(2000); // In cents

$cart = (new Cart())
    ->addItem($item);

use OwlyMonetico\Collection\Country;
use OwlyMonetico\Model\BillingAddress;

$billingAddress = new BillingAddress(
    'Pl. Général de Gaulle',
    'La Valette-du-Var',
    '83160',
    Country::FR)
    ->setFirstName('John') // Optional
    ->setLastName('Doe') // Optional
    ->setEmail('[email protected]'); // Optional

use OwlyMonetico\Collection\Country;
use OwlyMonetico\Model\ShippingAddress;

$billingAddress = new ShippingAddress(
    'Pl. Général de Gaulle',
    'La Valette-du-Var',
    '83160',
    Country::FR)
    ->setFirstName('John') // Optional
    ->setLastName('Doe') // Optional
    ->setEmail('[email protected]'); // Optional

use OwlyMonetico\Model\Order;

$order = new Order(
    uniqid('ref_'),
    $cart->getItemTotalAmount(),
    $customer,
    $cart,
    $billingAddress,
    $shippingAddress
);

use OwlyMonetico\Collection\Currency;
use OwlyMonetico\Collection\Language;
use OwlyMonetico\Request\SimplePaymentRequest;

$simpleRequest = (new SimplePaymentRequest($order, Language::FR, Currency::EUR))
    ->setUrlSuccess('http://localhost/success') // Optional
    ->setUrlError('http://localhost/fail') // Optional
    ->setEmail('[email protected]'); // Optional to send the bill.

// Get the fields WITH field validation
try {
    $simpleFields = $monetico->getSimplePaymentRequestFields($simpleRequest); // skipValidation: false by default
} catch (Exception $e) {
    die($e->getMessage());
}
var_dump($simpleFields);

// Get the fields WITHOUT field validation
$simpleFields = $monetico->getSimplePaymentRequestFields($simpleRequest, true); // skipValidation: true
var_dump($simpleFields);

use OwlyMonetico\Collection\Currency;
use OwlyMonetico\Collection\Language;
use OwlyMonetico\Request\IFramePaymentRequest;

$iFrameRequest = (new IFramePaymentRequest($order, Language::FR, Currency::EUR, '[email protected]')) // Email uest); // skipValidation: false by default
} catch (Exception $e) {
    die($e->getMessage());
}
var_dump($iframeFields);

// Get the fields WITHOUT field validation
$iframeFields = $monetico->getIFramePaymentRequestFields($iFrameRequest, true); // skipValidation: true
var_dump($iframeFields);

use OwlyMonetico\Collection\Currency;
use OwlyMonetico\Collection\Language;
use OwlyMonetico\Request\SplitPaymentRequest;

$splitRequest = (new SplitPaymentRequest($order, Language::FR, Currency::EUR, 2)) // Nombre de paiements
    ->setUrlSuccess('http://localhost/success.php') // Optional
    ->setUrlError('http://localhost/fail.php') // Optional
    ->setDueAmount1(10.00)
    ->setDueDate1(new DateTime()) // First payment today
    ->setDueAmount2(10.00)
    ->setDueDate2(new DateTime('+1 month')); // Second payment in a month (Monthly due dates)

// Get the fields WITH field validation
try {
    $splitFields = $monetico->getSplitPaymentRequestFields($splitRequest); // skipValidation: false by default
} catch (Exception $e) {
    die($e->getMessage());
}
var_dump($iframeFields);

// Get the fields WITHOUT field validation
$splitFields = $monetico->getSplitPaymentRequestFields($splitRequest, true); // skipValidation: true
var_dump($splitFields);

use OwlyMonetico\Collection\Currency;
use OwlyMonetico\Collection\Language;
use OwlyMonetico\Request\PreAuthorizedPaymentRequest;

$preAuthorizedRequest = (new PreAuthorizedPaymentRequest($order, Language::FR, Currency::EUR, '20150901PRE1')) // Required file number
    ->setUrlSuccess('http://localhost/success.php') // Optional
    ->setUrlError('http://localhost/fail.php'); // Optional

// Get the fields WITH field validation
try {
    $preAuthorizedFields = $monetico->getPreAuthorizedPaymentRequestFields($splitRequest); // skipValidation: false by default
} catch (Exception $e) {
    die($e->getMessage());
}
var_dump($preAuthorizedFields);

// Get the fields WITHOUT field validation
$preAuthorizedFields = $monetico->getPreAuthorizedPaymentRequestFields($preAuthorizedRequest, true); // skipValidation: true
var_dump($preAuthorizedFields);

use OwlyMonetico\Collection\Civility;
use OwlyMonetico\Collection\Currency;
use OwlyMonetico\Collection\Language;
use OwlyMonetico\Request\CofidisPaymentRequest;

$cofidisRequest = (new CofidisPaymentRequest($order, Language::FR, Currency::EUR))
    ->setCivility(Civility::MR) // Optional
    ->setFirstName('Yannick') // Optional
    ->setUrlSuccess('http://localhost/success.php') // Optional
    ->setUrlError('http://localhost/fail.php'); // Optional

// Get the fields WITH field validation
try {
    $cofidisFields = $monetico->getCofidisPaymentRequestFields($splitRequest); // skipValidation: false by default
} catch (Exception $e) {
    die($e->getMessage());
}
var_dump($preAuthorizedFields);

// Get the fields WITHOUT field validation
$cofidisFields = $monetico->getCofidisPaymentRequestFields($cofidisRequest, true); // skipValidation: true
var_dump($cofidisFields);