git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@7524 b9a71923-0436-4b27-9f14-aed3839534dd

This commit is contained in:
rGaillard
2011-07-06 10:54:11 +00:00
parent ba9cdcf295
commit 8a59d0dc41
5398 changed files with 482149 additions and 0 deletions
+232
View File
@@ -0,0 +1,232 @@
<?php
/**
* Objet représentant un affilié
* montant de base : montant à partir duquel est calculé le montant qui sera distribué à l'affilié
* cible : si l'affiliation est un piurcentage, la cible indique sur quels montant de la transaction
* s'applique ce pourcentage
* montant calculé : montant reversé à l'affilié
*
*
*/
class HIPAY_MAPI_Affiliate extends HIPAY_MAPI_lockable {
/**
* Numéro de client
*
* @var int
*/
protected $customerId;
/**
* Numéro de compte
*
* @var unknown_type
*/
protected $accountId;
/**
* Valeur de l'affiliation (montant fixe ou pourcentage)
*
* @var float
*/
protected $val;
/**
* Si >0, $val est un pourcentage et $percentageTarget détermine
* sur quels montants appliquer le pourcentage
*
* @var unknown_type
*/
protected $percentageTarget;
/**
* Montant à reversé à l'affilié
*
* @var unknown_type
*/
protected $_amount;
/**
* Montant de base sur lequel est calculé le montant
* reversé à l'affilié
*
* @var unknown_type
*/
protected $_baseAmount;
/**
* Assigne le numéro de client
*
* @param int $customerId
* @return boolean
*/
public function setCustomerId($customerId) {
if ($this->_locked)
return false;
$customerId = (int)$customerId;
if ($customerId <= 0)
return false;
$this->customerId = $customerId;
return true;
}
/**
* Retourne le numéro de client
*
* @return int
*/
public function getCustomerId() {
return $this->customerId;
}
/**
* Assigne le numéro de compte
*
* @param int $accountId
* @return boolean
*/
public function setAccountId($accountId) {
if ($this->_locked)
return false;
$accountId = (int)$accountId;
if ($accountId <= 0)
return false;
$this->accountId = $accountId;
return true;
}
/**
* Retourne le numéro de compte
*
* @return int
*/
public function getAccountId() {
return $this->accountId;
}
/**
* Assigne le valeur de l'affiliation, qui est un montant fixe ou un pourcentage
* S'il s'agit d'un pourcentage, $percentageTarget représente la cible, c'est à dire sur quels
* montants est basé le montant de l'affiliation
*
* @param float $val
* @param int $percentageTarget
* @return boolean
*/
public function setValue($val, $percentageTarget = 0) {
if ($this->_locked)
return false;
$val = sprintf('%.02f',(float)$val);
$percentageTarget = (int)$percentageTarget;
if ($val <= 0 || $percentageTarget < 0)
return false;
if ($percentageTarget > 0 && $val > 100)
return false;
if ($percentageTarget > 0 && $percentageTarget > HIPAY_MAPI_TTARGET_ALL)
return false;
$this->val = $val;
$this->percentageTarget = $percentageTarget;
$this->setAmount();
return true;
}
/**
* Retourne la valeur de l'affiliation
*
* @return float
*/
public function getValue() {
return $this->val;
}
/**
* Retourne sur quoi s'applique le pourcentage
*
* @return int
*/
public function getPercentageTarget() {
return $this->percentageTarget;
}
/**
* Assigne le montant sur lequel sera calculé l'affiliation
*
* @param float $baseAmount
* @return boolean
*/
public function setBaseAmount($baseAmount) {
if ($this->_locked)
return false;
$baseAmount = sprintf('%.02f',(float)$baseAmount);
if ($baseAmount < 0)
return false;
$this->_baseAmount = $baseAmount;
$this->setAmount();
return true;
}
/**
* Retourne le montant sur lequel sera calculé l'affiliation
*
* @return int
*/
public function getBaseAmount() {
return $this->_baseAmount;
}
/**
* Retourne le montant calculé de l'affiliation
*
* @return float
*/
public function getAmount() {
return $this->_amount;
}
/**
* Assigne le montant calculé de l'affiliation
*
*/
protected function setAmount() {
if ($this->percentageTarget > 0) {
$this->_amount = sprintf('%.02f',($this->_baseAmount/100) * $this->val);
} else {
$this->_amount = sprintf('%.02f',$this->_baseAmount);
}
}
/**
* Vérifie que l'objet est bien initialisé
*
* @return boolean
*/
public function check() {
if ($this->customerId <= 0 || $this->accountId <= 0 || $this->val <= 0 || $this->percentageTarget < 0)
throw new Exception('Customer identifier, account number, value or invalid target');
return true;
}
protected function init() {
$this->customerId = 0;
$this->accountId = 0;
$this->_amount = 0;
$this->_baseAmount = 0;
$this->val = 0;
$this->percentageTarget = 0;
}
function __construct() {
$this->init();
parent::__construct();
}
}
+124
View File
@@ -0,0 +1,124 @@
<?php
class HIPAY_MAPI_COMM_XML
{
/**
* Traitement de la réponse de la plateforme après l'envoi du
* flux représentant un paiement
*
* @param string $xml
* @param string $url
* @param string $err_msg
* @param string $err_keyword
* @param string $err_value
* @param string $err_code
* @return boolean
*/
public static function analyzeResponseXML($xml, &$url, &$err_msg, &$err_keyword, &$err_value, &$err_code)
{
$url = '';
$err_msg = '';
$err_keyword = '';
$err_value = '';
$err_code = '';
try {
$obj = @new SimpleXMLElement(trim($xml));
} catch (Exception $e) {
return false;
}
if (isset($obj->result[0]->url)) {
$url = $obj->result[0]->url;
return true;
}
if (isset($obj->result[0]->message))
$err_msg = $obj->result[0]->message;
if (isset($obj->result[0]->keyword))
$err_keyword = $obj->result[0]->keyword;
if (isset($obj->result[0]->value))
$err_value = $obj->result[0]->value;
if (isset($obj->result[0]->code))
$err_code = $obj->result[0]->code;
return false;
}
/**
* Traitement du flux XML envoyé par HiPay notifiant le résultat d'une action sur une transaction
*
* @param string $xml
* @param unknown_type $status
* @param string $date
* @param string $time
* @param string $transid
* @param string $origAmount
* @param string $origCurrency
* @param string $idformerchant
* @param array $merchantdatas
* @return boolean
*/
public static function analyzeNotificationXML($xml, &$operation, &$status, &$date, &$time, &$transid, &$origAmount, &$origCurrency, &$idformerchant, &$merchantdatas)
{
$operation = '';
$status = '';
$date = '';
$time = '';
$transid = '';
$origAmount = '';
$origCurrency = '';
$idformerchant = '';
$merchantdatas = array();
try {
$obj = new SimpleXMLElement(trim($xml));
} catch (Exception $e) {
return false;
}
if (isset($obj->result[0]->operation))
$operation=$obj->result[0]->operation;
else return false;
if (isset($obj->result[0]->status))
$status=$obj->result[0]->status;
else return false;
if (isset($obj->result[0]->date))
$date=$obj->result[0]->date;
else return false;
if (isset($obj->result[0]->time))
$time=$obj->result[0]->time;
else return false;
if (isset($obj->result[0]->transid))
$transid=$obj->result[0]->transid;
else return false;
if (isset($obj->result[0]->origAmount))
$origAmount=$obj->result[0]->origAmount;
else return false;
if (isset($obj->result[0]->origCurrency))
$origCurrency=$obj->result[0]->origCurrency;
else return false;
if (isset($obj->result[0]->idForMerchant))
$idformerchant=$obj->result[0]->idForMerchant;
else return false;
if (isset($obj->result[0]->merchantDatas)) {
$d = $obj->result[0]->merchantDatas->children();
foreach($d as $xml2) {
if (preg_match('#^_aKey_#i',$xml2->getName())) {
$indice = substr($xml2->getName(),6);
$xml2 = (array)$xml2;
$valeur = (string)$xml2[0];
$merchantdatas[$indice] = $valeur;
}
}
}
return true;
}
}
+83
View File
@@ -0,0 +1,83 @@
<?php
/**
* Définition des montants sur lesquels s'appliquent les taxes
*
*/
define('HIPAY_MAPI_TTARGET_TAX', 1);
define('HIPAY_MAPI_TTARGET_INSURANCE', 2);
define('HIPAY_MAPI_TTARGET_FCOST', 4);
define('HIPAY_MAPI_TTARGET_SHIPPING', 8);
define('HIPAY_MAPI_TTARGET_ITEM', 16);
define('HIPAY_MAPI_TTARGET_ALL', HIPAY_MAPI_TTARGET_TAX+HIPAY_MAPI_TTARGET_INSURANCE+HIPAY_MAPI_TTARGET_FCOST+HIPAY_MAPI_TTARGET_SHIPPING+HIPAY_MAPI_TTARGET_ITEM);
/**
* Type de paiements possibles
*
*/
define('HIPAY_MAPI_METHOD_SIMPLE', 0);
define('HIPAY_MAPI_METHOD_MULTI', 1);
/**
* Valeurs par défaut
*
*/
define('HIPAY_MAPI_DEFLANG', 'FR_fr');
define('HIPAY_MAPI_DEFMEDIA', 'WEB');
define('HIPAY_MAPI_MAX_INFO_LENGTH', 200);
define('HIPAY_MAPI_MAX_TITLE_LENGTH', 80);
define('HIPAY_MAPI_MAX_LOGIN_LENGTH', 20);
define('HIPAY_MAPI_MAX_PASSWORD_LENGTH', 20);
define('HIPAY_MAPI_MAX_RATING_LENGTH', 8);
define('HIPAY_MAPI_MAX_MDATAS_LENGTH', 200);
define('HIPAY_MAPI_MAX_ACKWD_LENGTH', 8);
define('HIPAY_MAPI_MAX_ACKMAIL_LENGTH', 64);
define('HIPAY_MAPI_MAX_PRODUCT_NAME_LENGTH', 100);
define('HIPAY_MAPI_MAX_PRODUCT_INFO_LENGTH', 100);
define('HIPAY_MAPI_MAX_PRODUCT_REF_LENGTH', 35);
define('HIPAY_MAPI_MAX_TAX_NAME_LENGTH', 32);
/**
* Valeurs particulières pour le délai de capture
*
*/
define('HIPAY_MAPI_CAPTURE_MANUAL', -1);
define('HIPAY_MAPI_CAPTURE_IMMEDIATE', 0);
define('HIPAY_MAPI_CAPTURE_MAX_DAYS', 7);
define('HIPAY_MAPI_OPE_PREAUTH', 'preauthorization');
define('HIPAY_MAPI_OPE_AUTH', 'authorization');
define('HIPAY_MAPI_OPE_CANCEL', 'cancellation');
define('HIPAY_MAPI_OPE_REFUND', 'refund');
define('HIPAY_MAPI_OPE_CAPTURE', 'capture');
define('HIPAY_MAPI_OPE_REJECT', 'rejet');
define('HIPAY_MAPI_STATUS_OK', 'ok');
define('HIPAY_MAPI_STATUS_NOK', 'nok');
// Nombre de secondes avant le timeout de curl avec le serveur Hipay
// A régler en fonction de votre rapidité d'accès à la plate forme hipay
define('HIPAY_MAPI_CURL_TIMEOUT', 30);
// Configuration d'un serveur proxy
// activer cette option a true pour demander au curl de passer par un proxy
define('HIPAY_MAPI_CURL_PROXY_ON', false);
// Adresse du proxy
define('HIPAY_MAPI_CURL_PROXY', 'http://');
// port du proxy
define('HIPAY_MAPI_CURL_PROXYPORT', '');
// Configuration d'un fichier de log pour curl en cas de pb de connexion avec le serveur Hipay
define('HIPAY_MAPI_CURL_LOG_ON', false);
// fichier de log de curl (sous environnement windows, le chemin du fichier pourra être de type C:\tmp\mapicurl.log)
define('HIPAY_MAPI_CURL_LOGFILE', '/tmp/curl.log');
define('MAPI_VERSION','1.0');
+125
View File
@@ -0,0 +1,125 @@
<?php
define('MAPI_EXCEPTION_AFFILIATE_BASE_ERROR', 101);
define('MAPI_EXCEPTION_AFFILIATE_UNKNOWN_AFFILIATE', 102);
define('MAPI_EXCEPTION_AFFILIATE_INCORRECT_EU', 103);
define('MAPI_EXCEPTION_AFFILIATE_CUSTOMER_ID_ERROR', 104);
define('MAPI_EXCEPTION_AFFILIATE_ACCOUNT_ID_ERROR', 105);
define('MAPI_EXCEPTION_AFFILIATE_VALUE_ERROR', 106);
define('MAPI_EXCEPTION_AFFILIATE_INCORRECT_TAG', 107);
define('MAPI_EXCEPTION_INSTALLMENT_BASE_ERROR', 201);
define('MAPI_EXCEPTION_INSTALLMENT_SETFIRST_ERROR', 202);
define('MAPI_EXCEPTION_INSTALLMENT_FIRST_BOOLEAN', 203);
define('MAPI_EXCEPTION_INSTALLMENT_PRICE_ERROR', 204);
define('MAPI_EXCEPTION_INSTALLMENT_INCORRECT_TAG', 205);
define('MAPI_EXCEPTION_INSTALLMENT_TAX_ERROR', 206);
define('MAPI_EXCEPTION_MULTIPLEP_ORDER_TAG_CONTENT_ERROR', 301);
define('MAPI_EXCEPTION_MULTIPLEP_ORDER_TAG_TOO_MANY_OBJECTS', 302);
define('MAPI_EXCEPTION_MULTIPLEP_ITEMS_TAG_CONTENT_ERROR', 303);
define('MAPI_EXCEPTION_MULTIPLEP_ITEMS_TAG_TOO_MANY_OBJECTS', 304);
define('MAPI_EXCEPTION_MULTIPLEP_INCORRECT_TAG', 305);
define('MAPI_EXCEPTION_MULTIPLEP_CONSTRUCT_ERROR', 306);
define('MAPI_EXCEPTION_ORDER_BASE_ERROR', 401);
define('MAPI_EXCEPTION_ORDER_UNKNOWN_CATEGORY', 402);
define('MAPI_EXCEPTION_ORDER_TITLE_ERROR', 403);
define('MAPI_EXCEPTION_ORDER_INFO_ERROR', 404);
define('MAPI_EXCEPTION_ORDER_UNKNOWN_TAG', 405);
define('MAPI_EXCEPTION_ORDER_SHIPPING_ERROR', 406);
define('MAPI_EXCEPTION_ORDER_INSURANCE_ERROR', 407);
define('MAPI_EXCEPTION_ORDER_FCOST_ERROR', 408);
define('MAPI_EXCEPTION_ORDER_AFFILIATE_ERROR', 409);
define('MAPI_EXCEPTION_SIMPLEP_ORDER_TAG_CONTENT_ERROR', 501);
define('MAPI_EXCEPTION_SIMPLEP_ITEMS_TAG_CONTENT_ERROR', 502);
define('MAPI_EXCEPTION_SIMPLEP_INCORRECT_TAG', 503);
define('MAPI_EXCEPTION_SIMPLEP_CONSTRUCT_ERROR', 504);
define('MAPI_EXCEPTION_PARAMS_BASE_ERROR', 601);
define('MAPI_EXCEPTION_PARAMS_INCORRECT_LOGIN', 602);
define('MAPI_EXCEPTION_PARAMS_INCORRECT_PASSWORD', 603);
define('MAPI_EXCEPTION_PARAMS_INCORRECT_LOGIN_2', 604);
define('MAPI_EXCEPTION_PARAMS_UNKNOWN_ITEM_ACCT', 605);
define('MAPI_EXCEPTION_PARAMS_FORBIDDEN_ITEM_ACCT', 606);
define('MAPI_EXCEPTION_PARAMS_UNKNOWN_ITEM_ACCT_2', 607);
define('MAPI_EXCEPTION_PARAMS_UNKNOWN_TAX_ACCT', 608);
define('MAPI_EXCEPTION_PARAMS_FORBIDDEN_TAX_ACCT', 609);
define('MAPI_EXCEPTION_PARAMS_UNKNOWN_TAX_ACCT_2', 610);
define('MAPI_EXCEPTION_PARAMS_UNKNOWN_INS_ACCT', 611);
define('MAPI_EXCEPTION_PARAMS_FORBIDDEN_INS_ACCT', 612);
define('MAPI_EXCEPTION_PARAMS_UNKNOWN_INS_ACCT_2', 613);
define('MAPI_EXCEPTION_PARAMS_UNKNOWN_FCOST_ACCT', 614);
define('MAPI_EXCEPTION_PARAMS_FORBIDDEN_FCOST_ACCT', 615);
define('MAPI_EXCEPTION_PARAMS_UNKNOWN_FCOST_ACCT_2', 616);
define('MAPI_EXCEPTION_PARAMS_UNKNOWN_SHIP_ACCT', 617);
define('MAPI_EXCEPTION_PARAMS_FORBIDDEN_SHIP_ACCT', 618);
define('MAPI_EXCEPTION_PARAMS_UNKNOWN_SHIP_ACCT_2', 619);
define('MAPI_EXCEPTION_PARAMS_UNKNOWN_EU_ID', 620);
define('MAPI_EXCEPTION_PARAMS_NO_LANG_AVAILABLE', 621);
define('MAPI_EXCEPTION_PARAMS_LANG_NOT_SUPPORTED', 622);
define('MAPI_EXCEPTION_PARAMS_NO_MEDIA_AVAILABLE', 623);
define('MAPI_EXCEPTION_PARAMS_MEDIA_NOT_SUPPORTED', 624);
define('MAPI_EXCEPTION_PARAMS_INCORRECT_RATING', 625);
define('MAPI_EXCEPTION_PARAMS_INCORRECT_PAYMENT_METHOD', 626);
define('MAPI_EXCEPTION_PARAMS_INCORRECT_CURRENCY', 627);
define('MAPI_EXCEPTION_PARAMS_INCORRECT_MERCH_SITE_ID', 628);
define('MAPI_EXCEPTION_PARAMS_LANG_ERROR', 629);
define('MAPI_EXCEPTION_PARAMS_MEDIA_ERROR', 630);
define('MAPI_EXCEPTION_PARAMS_RATING_ERROR', 631);
define('MAPI_EXCEPTION_PARAMS_METHOD_ERROR', 632);
define('MAPI_EXCEPTION_PARAMS_CAPTURE_DAY_ERROR', 633);
define('MAPI_EXCEPTION_PARAMS_CURRENCY_ERROR', 634);
define('MAPI_EXCEPTION_PARAMS_ID_MERCHANT_ERROR', 635);
define('MAPI_EXCEPTION_PARAMS_SITE_ID_ERROR', 636);
define('MAPI_EXCEPTION_PARAMS_URLOK_ERROR', 637);
define('MAPI_EXCEPTION_PARAMS_URLNOK_ERROR', 638);
define('MAPI_EXCEPTION_PARAMS_URLCAN_ERROR', 639);
define('MAPI_EXCEPTION_PARAMS_URLACK_ERROR', 640);
define('MAPI_EXCEPTION_PARAMS_ACKWD_ERROR', 641);
define('MAPI_EXCEPTION_PARAMS_EMAILACK_ERROR', 642);
define('MAPI_EXCEPTION_PARAMS_BGCOLOR_ERROR', 643);
define('MAPI_EXCEPTION_PARAMS_URLLOGO_ERROR', 644);
define('MAPI_EXCEPTION_PARAMS_MDATAS_ERROR', 645);
define('MAPI_EXCEPTION_PARAMS_UNKNOWN_TAG', 646);
define('MAPI_EXCEPTION_PARAMS_LOGIN_ERROR', 647);
define('MAPI_EXCEPTION_PARAMS_ACCTS_ERROR', 648);
define('MAPI_EXCEPTION_PARAMS_ID_GROUP_ERROR', 649);
define('MAPI_EXCEPTION_PRODUCT_BASE_ERROR', 701);
define('MAPI_EXCEPTION_PRODUCT_NAME_ERROR', 702);
define('MAPI_EXCEPTION_PRODUCT_INFO_ERROR', 703);
define('MAPI_EXCEPTION_PRODUCT_QUANTITY_ERROR', 704);
define('MAPI_EXCEPTION_PRODUCT_REF_ERROR', 705);
define('MAPI_EXCEPTION_PRODUCT_CATEGORY_ERROR', 706);
define('MAPI_EXCEPTION_PRODUCT_PRICE_ERROR', 707);
define('MAPI_EXCEPTION_PRODUCT_INCORRECT_TAG', 708);
define('MAPI_EXCEPTION_PRODUCT_TAX_ERROR', 709);
define('MAPI_EXCEPTION_TAX_BASE_ERROR', 801);
define('MAPI_EXCEPTION_TAX_NAME_ERROR', 802);
define('MAPI_EXCEPTION_TAX_ACCOUNT_ERROR', 803);
define('MAPI_EXCEPTION_TAX_PERCENTAGE_NOT_BOOLEAN_ERROR', 804);
define('MAPI_EXCEPTION_TAX_VALUE_ERROR', 805);
define('MAPI_EXCEPTION_TAX_INCORRECT_TAG', 806);
class MAPI_Exception extends Exception {
private $keyword;
private $value;
function __construct($keyword, $value, $msg, $code = 0) {
$this->keyword = $keyword;
$this->value = $value;
parent::__construct($msg, $code);
}
public function getKeyword() {
return $this->keyword;
}
public function getValue() {
return $this->value;
}
}
+215
View File
@@ -0,0 +1,215 @@
<?php
/**
* Représente la ligne de la commande pour un paiement récurrent
*
*/
class HIPAY_MAPI_Installment extends HIPAY_MAPI_Item {
/**
* Montant HT
*
* @var float
*/
protected $price;
/**
* Taxes s'appliquant à ce paiement
*
* @var array
*/
protected $tax;
/**
* Indique s'il s'agit du premier paiement (true) ou des suivants (false)
*
* @var boolean
*/
protected $first;
/**
* Délai avant le déclenchement du premier paiement (si $first=true),
* ou interval entre les paiements suivants (si $first=false)
*
* @var string
*/
protected $paymentDelay;
/**
* timestamp du premier paiement ou des paiements récurrents
*
* @var integer
*/
protected $_delayTS;
/**
* Assigne le montant HT
*
* @param float $price
* @return boolean
*/
public function setPrice($price) {
if ($this->_locked)
return false;
$price = sprintf('%.02f',(float)$price);
if ($price < 0)
return false;
$this->price = $price;
return true;
}
/**
* Retourne le montant HT
*
* @return float
*/
public function getPrice() {
return $this->price;
}
/**
* Défini s'il s'agit du premier paiement ou des suivants et le délai de déclenchement
*
* @param boolean $first
* @param string $paymentDelay
* @return boolean
*/
public function setFirst($first,$paymentDelay) {
if ($this->_locked)
return false;
if (!is_bool($first))
return false;
$paymentDelay=trim($paymentDelay);
if ($first) {
if (!preg_match("#[0-9]+[HDM]#",$paymentDelay))
{
return false;
}
} else {
if (!preg_match("#[0-9]+[DM]#",$paymentDelay)) {
return false;
}
}
$num = (int)substr($paymentDelay, 0, strlen($paymentDelay)-1);
if (($num < 1 && !$first) || ($num < 0 && $first) || $num > 365) {
return false;
}
$this->first = $first;
$this->paymentDelay = $paymentDelay;
return true;
}
/**
* Assigne les taxes s'appliquant à ce paiement
*
* @param array $tax
* @return boolean
*/
public function setTax($tax) {
if ($this->_locked)
return false;
if (!HIPAY_MAPI_UTILS::is_an_array_of($tax, 'HIPAY_MAPI_Tax'))
return false;
foreach ($tax as $obj)
$this->tax[]= clone $obj;
return true;
}
/**
* assigne le timestamp du premier paiement ou des paiements récurrents
*
*/
public function setDelayTS( $baseTS=0 )
{
if ((int)$baseTS <= 0) {
$baseTS = time();
}
switch (substr($this->paymentDelay, -1, 1)) {
case 'd': case 'D': $unit='day'; break;
case 'm': case 'M': $unit='month'; break;
case 'h': case 'H':
default : $unit='hour'; break;
}
$this->_delayTS = strtotime('+'.substr($this->paymentDelay, 0, -1).' '.$unit, $baseTS);
}
/**
* Retourne les taxes s'appliquant à ce paiement
*
* @return array
*/
public function getTax() {
return $this->tax;
}
/**
* Retourne s'il s'agit du premier paiement
*
* @return boolean
*/
public function getFirst() {
return $this->first;
}
/**
* Retourne le délai de déclenchement
*
* @return string
*/
public function getPaymentDelay() {
return $this->paymentDelay;
}
/**
* retourne le timestamp du premier paiement
*
*/
public function getDelayTS()
{
return $this->_delayTS;
}
/**
* Vérifie si l'objet est correctement initialisé
*
* @return float
*/
public function check() {
if ($this->price < 0)
throw new Exception('Invalid amount or not initialized');
if (!HIPAY_MAPI_UTILS::is_an_array_of($this->tax, 'HIPAY_MAPI_Tax'))
throw new Exception('Invalid taxes or not initialized');
foreach($this->tax as $obj) {
if (!$obj->check())
return false;
}
if (!is_bool($this->first))
throw new Exception('Premier paiement ou suivant n\'est pas initialisé');
return true;
}
protected function init()
{
$this->price = -1;
$this->tax = array();
$this->first = '';
$this->paymentDelay = '';
$this->_delayTS = '';
}
function __construct() {
$this->init();
parent::__construct();
}
}
+43
View File
@@ -0,0 +1,43 @@
<?php
/**
* Représente une ligne de la commande
*
*/
class HIPAY_MAPI_Item extends HIPAY_MAPI_lockable {
function __construct() {
parent::__construct();
}
public function getName() {
return '';
}
public function getInfo() {
return '';
}
public function getQuantity() {
return 1;
}
public function getRef() {
return '';
}
public function getCategory() {
return 1;
}
public function getPrice() {
return 0;
}
public function getTax() {
return array();
}
public function check() {
return false;
}
}
+21
View File
@@ -0,0 +1,21 @@
<?php
class HIPAY_MAPI_lockable extends HIPAY_MAPI_XML {
/**
* Etat du vérou
*
* @var boolean
*/
protected $_locked;
/**
* Verouille l'objet
*
*/
public function lock() {
$this->_locked = true;
}
function __construct() {
$this->_locked = false;
}
}
@@ -0,0 +1,45 @@
<?php
/**
* Représente un paiement récurrent
* Un paiement simple contient :
* - 1 objet paramètres HIPAY_MAPI_PaymentParams
* - 1 objet order pour le premier paiement HIPAY_MAPI_Order
* - 1 objet installment pour le premier paiement HIPAY_MAPI_Installment
* - 1 objet order pour le second paiement HIPAY_MAPI_Order
* - 1 objet installment pour le second paiement HIPAY_MAPI_Installment
*
*/
class HIPAY_MAPI_MultiplePayment extends HIPAY_MAPI_Payment {
function __construct(HIPAY_MAPI_PaymentParams $paymentParams, HIPAY_MAPI_Order $firstOrder, HIPAY_MAPI_Installment $firstInstallment, HIPAY_MAPI_Order $nextOrder, HIPAY_MAPI_Installment $nextInstallment) {
if ($firstInstallment->getFirst() === $nextInstallment->getFirst() || !$firstInstallment->getFirst()) {
throw new Exception('You must define a installment object for the first payment and next payments');
}
$firstInstallment->setDelayTS();
$nextInstallment->setDelayTS($firstInstallment->getDelayTS());
try {
parent::__construct($paymentParams, array($firstOrder, $nextOrder), array($firstInstallment, $nextInstallment));
} catch(Exception $e) {
throw new Exception($e->getMessage());
}
}
/**
* Retourne le montant total de la somme devant être
* distribuée aux affiliés
*/
protected function _getTotalAmountForAffiliates($installement_nr) {
$affiliates = $this->order[0]->getAffiliate();
if (!HIPAY_MAPI_UTILS::is_an_array_of($affiliates, 'HIPAY_MAPI_Affiliate'))
return false;
$total_aff = 0;
foreach($affiliates as $aff) {
$total_aff += $aff->getAmount();
}
return $total_aff;
}
}
+396
View File
@@ -0,0 +1,396 @@
<?php
/**
* Objet représentant les informations de la commande
*
*/
class HIPAY_MAPI_Order extends HIPAY_MAPI_lockable {
/**
* Montant des frais de livraison
*
* @var float
*/
protected $shippingAmount;
/**
* Taxes s'appliquants aux frais de livraison
*
* @var array
*/
protected $shippingTax;
/**
* Montant des assurances
*
* @var float
*/
protected $insuranceAmount;
/**
* Taxes s'appliquants aux assurances
*
* @var array
*/
protected $insuranceTax;
/**
* Montant des coûts fixes
*
* @var float
*/
protected $fixedCostAmount;
/**
* Taxes s'appliquants aux coûts fixes
*
* @var array
*/
protected $fixedCostTax;
/**
* Affiliés
*
* @var array
*/
protected $affiliate;
/**
* Intitulé de la commande
*
* @var string
*/
protected $orderTitle;
/**
* Informations sur la commande
*
* @var string
*/
protected $orderInfo;
/**
* Catégorie de la commande
*
* @var int
*/
protected $orderCategory;
/**
* Défini le montant des frais d'envoi et les taxes s'y appliquant
*
* @param float $shippingAmount
* @param array $shippingTax
* @return boolean
*/
public function setShipping($shippingAmount, $shippingTax) {
if ($this->_locked)
return false;
$shippingAmount = sprintf('%.02f', (float)$shippingAmount);
if ($shippingAmount < 0) {
return false;
}
if(empty($shippingTax)) {
return false;
}
if (!HIPAY_MAPI_UTILS::is_an_array_of($shippingTax, 'HIPAY_MAPI_Tax')) {
return false;
}
$this->shippingAmount = $shippingAmount;
foreach ($shippingTax as $obj)
$this->shippingTax[] = clone $obj;
return true;
}
/**
* Retourne le montant des frais d'envoi
*
* @return float
*/
public function getShippingAmount() {
return $this->shippingAmount;
}
/**
* Retourne les taxes s'appliquants aux frais d'envoi
*
* @return array
*/
public function &getShippingTax() {
return $this->shippingTax;
}
/**
* Défini le montant des assurances
*
* @param float $insuranceAmount
* @param array $insuranceTax
* @return boolean
*/
public function setInsurance($insuranceAmount, $insuranceTax) {
if ($this->_locked)
return false;
$insuranceAmount = sprintf('%.02f', (float)$insuranceAmount);
if ($insuranceAmount < 0)
return false;
if(empty($insuranceTax)) {
return false;
}
if (!HIPAY_MAPI_UTILS::is_an_array_of($insuranceTax, 'HIPAY_MAPI_Tax'))
return false;
$this->insuranceAmount = $insuranceAmount;
foreach ($insuranceTax as $obj)
$this->insuranceTax[] = clone $obj;
return true;
}
/**
* Retourne le montant des assurances
*
* @return float
*/
public function getInsuranceAmount() {
return $this->insuranceAmount;
}
/**
* Retourne les taxes s'appliquants aux assurances
*
* @return array
*/
public function &getInsuranceTax() {
return $this->insuranceTax;
}
/**
* Défini le montant des coûts fixes et les taxes s'y appliquant
*
* @param float $fixedCostAmount
* @param array $fixedCostTax
* @return boolean
*/
public function setFixedCost($fixedCostAmount,$fixedCostTax) {
if ($this->_locked)
return false;
$fixedCostAmount = sprintf('%.02f', (float)$fixedCostAmount);
if ($fixedCostAmount<0)
return false;
if(empty($fixedCostTax)) {
return false;
}
if (!HIPAY_MAPI_UTILS::is_an_array_of($fixedCostTax, 'HIPAY_MAPI_Tax'))
return false;
$this->fixedCostAmount = $fixedCostAmount;
foreach ($fixedCostTax as $obj)
$this->fixedCostTax[] = clone $obj;
return true;
}
/**
* Retourne le montant des coûts fixes
*
* @return float
*/
public function getFixedCostAmount() {
return $this->fixedCostAmount;
}
/**
* Retourne les taxes s'appliquant aux coûts fixes
*
* @return array
*/
public function &getFixedCostTax() {
return $this->fixedCostTax;
}
/**
* Défini les affiliés qui recevront une rétribution pour cette commande
*
* @param array $affiliate
* @return boolean
*/
public function setAffiliate($affiliate) {
if ($this->_locked)
return false;
if(empty($affiliate)) {
return false;
}
if (!HIPAY_MAPI_UTILS::is_an_array_of($affiliate, 'HIPAY_MAPI_Affiliate'))
return false;
foreach ($affiliate as $obj)
$this->affiliate[] = clone $obj;
return true;
}
/**
* Retourne la liste des affiliés de cette commande
*
* @return array
*/
public function &getAffiliate() {
return $this->affiliate;
}
/**
* Assigne l'intitulé de la commande
*
* @param string $orderTitle
* @return boolean
*/
public function setOrderTitle($orderTitle) {
if ($this->_locked)
return false;
$orderTitle = HIPAY_MAPI_UTF8::forceUTF8($orderTitle);
$len = HIPAY_MAPI_UTF8::strlen_utf8($orderTitle);
if ($len < 1 || $len > HIPAY_MAPI_MAX_TITLE_LENGTH)
return false;
$this->orderTitle = $orderTitle;
return true;
}
/**
* Retourne l'intitulé de la commande
*
* @return string
*/
public function getOrderTitle() {
return $this->orderTitle;
}
/**
* Assigne les infos sur la commande
*
* @param string $orderInfo
* @return boolean
*/
public function setOrderInfo($orderInfo) {
if ($this->_locked)
return false;
$orderInfo = HIPAY_MAPI_UTF8::forceUTF8($orderInfo);
$len = HIPAY_MAPI_UTF8::strlen_utf8($orderInfo);
if ($len > HIPAY_MAPI_MAX_INFO_LENGTH)
return false;
$this->orderInfo = $orderInfo;
return true;
}
/**
* Retourne les infos sur la commande
*
* @return string
*/
public function getOrderInfo() {
return $this->orderInfo;
}
/**
* Assigne la catégorie de la commande
*
* @param int $orderCategory
* @return boolean
*/
public function setOrderCategory($orderCategory) {
if ($this->_locked)
return false;
$orderCategory = (int)$orderCategory;
if ($orderCategory < 1)
return false;
$this->orderCategory = $orderCategory;
return true;
}
/**
* Retourne la catégorie de la commande
*
* @return int
*/
public function getOrderCategory() {
return $this->orderCategory;
}
/**
* Vérifie si l'objet est correctement initialisé
*
* @return boolean
*/
public function check() {
if ($this->orderTitle == '' || $this->orderCategory < 0)
throw new Exception('Label and/or category of order are missing');
foreach($this->affiliate as $obj) {
try {
$obj->check();
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
}
foreach($this->shippingTax as $obj) {
try {
$obj->check();
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
}
foreach($this->insuranceTax as $obj) {
try {
$obj->check();
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
}
foreach($this->fixedCostTax as $obj) {
try {
$obj->check();
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
}
return true;
}
protected function init() {
$this->shippingAmount = 0;
$this->shippingTax = array();
$this->insuranceAmount = 0;
$this->insuranceTax = array();
$this->fixedCostAmount = 0;
$this->fixedCostTax = array();
$this->affiliate = array();
$this->orderTitle = '';
$this->orderInfo = '';
$this->orderCategory = -1;
}
function __construct() {
$this->init();
parent::__construct();
}
}
+20
View File
@@ -0,0 +1,20 @@
<?php
$_mapi_dir = dirname(__FILE__);
require_once($_mapi_dir.'/mapi_defs.php');
require_once($_mapi_dir.'/mapi_utils.php');
require_once($_mapi_dir.'/mapi_utf8.php');
require_once($_mapi_dir.'/mapi_xml.php');
require_once($_mapi_dir.'/mapi_send_xml.php');
require_once($_mapi_dir.'/mapi_comm_xml.php');
require_once($_mapi_dir.'/mapi_lockable.php');
require_once($_mapi_dir.'/mapi_tax.php');
require_once($_mapi_dir.'/mapi_affiliate.php');
require_once($_mapi_dir.'/mapi_item.php');
require_once($_mapi_dir.'/mapi_installment.php');
require_once($_mapi_dir.'/mapi_product.php');
require_once($_mapi_dir.'/mapi_paymentparams.php');
require_once($_mapi_dir.'/mapi_order.php');
require_once($_mapi_dir.'/mapi_payment.php');
require_once($_mapi_dir.'/mapi_multiplepayment.php');
require_once($_mapi_dir.'/mapi_simplepayment.php');
+447
View File
@@ -0,0 +1,447 @@
<?php
/**
* Représente un paiement.
* N'est pas utilisé directement
*
*/
class HIPAY_MAPI_Payment extends HIPAY_MAPI_XML {
/**
* Paramètres du paiement
*
* @var HIPAY_MAPI_PaymentParams
*/
protected $paymentParams;
/**
* Objets HIPAY_MAPI_Order
*
* @var array
*/
protected $order;
/**
* Objets HIPAY_MAPI_Item
*
* @var array
*/
protected $items;
/**
* Total des taxes sur les produits
*
* @var array
*/
protected $_taxItemsAmount;
/**
* Total des taxes sur les frais d'envoi
*
* @var array
*/
protected $_taxShippingAmount;
/**
* Total des taxes sur les assurances
*
* @var array
*/
protected $_taxInsuranceAmount;
/**
* Total des taxes sur les coûts fixes
*
* @var array
*/
protected $_taxFixedCostAmount;
/**
* Total du montant HT des produits
*
* @var array
*/
protected $_itemsTotalAmount;
/**
* Total des taxes
*
* @var array
*/
public $_taxTotalAmount;
/**
* Total de la commande hors taxes
*
* @var array
*/
protected $_orderTotalAmountHT;
/**
* Total de la commande
*
* @var array
*/
protected $_orderTotalAmount;
/**
* Total des affilies
*
* @var array
*/
protected $_affiliateTotalAmount;
public function __construct($paymentParams, $order, $items) {
try {
$this->init($paymentParams, $order, $items);
} catch(Exception $e) {
throw new Exception($e->getMessage());
}
}
protected function init($paymentParams, $order, $items) {
if (!($paymentParams instanceof HIPAY_MAPI_PaymentParams)
|| !HIPAY_MAPI_UTILS::is_an_array_of($order, 'HIPAY_MAPI_Order')
|| !HIPAY_MAPI_UTILS::is_an_array_of($items, 'HIPAY_MAPI_Item')
|| count($items) < 1)
throw new Exception('Wrong parameters');
try {
$paymentParams->check();
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
foreach($order as $orderObj) {
try {
$orderObj->check();
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
}
foreach($items as $obj) {
try {
$obj->check();
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
}
$this->paymentParams = clone $paymentParams;
$this->paymentParams->lock();
foreach($order as $obj) {
$this->order[] = clone $obj;
end($this->order)->lock();
$this->_taxItemsAmount[] = 0;
$this->_taxShippingAmount[] = 0;
$this->_taxInsuranceAmount[] = 0;
$this->_taxFixedCostAmount[] = 0;
$this->_itemsTotalAmount[] = 0;
$this->_taxTotalAmount[] = 0;
$this->_orderTotalAmount[] = 0;
$this->_affiliateTotalAmount[] = 0;
}
foreach($items as $obj) {
$this->items[] = clone $obj;
end($this->items)->lock();
}
try {
$this->compute();
} catch(Exception $e) {
throw new Exception($e->getMessage());
}
}
/**
* Calcul les différents montants (taxes, affiliés, totaux) de la commande
*
*/
protected function compute() {
// Mise à jour du montant total des taxes pour chaque item du tableau _taxItemsAmount
// Mise à jour du montant total des taxes de livraison pour chaque order du tableau _taxShippingAmount
// Mise à jour du montant total des taxes d'assurances pour chaque order du tableau _taxInsuranceAmount
// Mise à jour du montant total des taxes de couts fixes pour chaque order du tableau _taxFixedCostAmount
$this->computeTaxes();
// Mise a jour du montant total HT des produits pour chaque item du tableau _itemsTotalAmount
$this->computeItemsAmount();
// Pour chaque commande
foreach($this->order as $key=>$order) {
$this->_taxTotalAmount[$key] = $this->_taxItemsAmount[$key] + $this->_taxShippingAmount[$key] + $this->_taxInsuranceAmount[$key] + $this->_taxFixedCostAmount[$key];
$this->_orderTotalAmountHT[$key] = $order->getShippingAmount() + $order->getInsuranceAmount() + $order->getFixedCostAmount() + $this->_itemsTotalAmount[$key];
$this->_orderTotalAmount[$key] = $this->_orderTotalAmountHT[$key] + $this->_taxTotalAmount[$key];
// $this->_orderTotalAmount[$key] = $order->getShippingAmount() + $order->getInsuranceAmount() + $order->getFixedCostAmount() + $this->_itemsTotalAmount[$key] +
// $this->_taxItemsAmount[$key] +
// $this->_taxShippingAmount[$key] +
// $this->_taxInsuranceAmount[$key] +
// $this->_taxFixedCostAmount[$key];
}
try {
$this->computeAffiliates();
} catch(Exception $e) {
throw new Exception($e->getMessage());
}
}
/**
* Calcul le montant des taxes
*
*/
protected function computeTaxes() {
// Taxes sur les produits au niveau de l'item (ligne de commande)
// @FIXME bug et confusion entre indice d'item et indice d'order ?
$cur = 0;
// pour chaque ligne de commande
foreach($this->items as $item) {
// Liste des taxes de la ligne
$itemTaxes = $item->getTax();
$tItemsAmount = 0;
// pour chaque taxe appliquée sur cette ligne
foreach($itemTaxes as $tax) {
$amount = HIPAY_MAPI_UTILS::computeTax($item->getPrice(), $tax);
$tax->setTaxAmount($amount);
$tax->lock();
// mise a jour du montant total des taxes pour cet item (ligne de commande)
$tItemsAmount += $amount;
}
if (!isset($this->order[$cur]))
$cur = 0;
if (!isset($this->_taxItemsAmount[$cur]))
$this->_taxItemsAmount[$cur] = 0;
// mise a jour du montant total des taxes pour cette ligne de commande
// avec prise en compte du nombre de produits dans l'indice numLigneCommande
// du tableau _taxItemsAmount de cette commande
$this->_taxItemsAmount[$cur] += ($tItemsAmount*$item->getQuantity());
$item->lock();
$cur++;
}
// Taxes sur frais d'envoi, assurances, coûts fixes
// au niveau des commandes
$cur = 0;
foreach($this->order as $order) {
// Taxes sur frais d'envoi
$taxArr =& $order->getShippingTax();
foreach($taxArr as $key=>$tax) {
$amount = HIPAY_MAPI_UTILS::computeTax($order->getShippingAmount(), $tax);
$taxArr[$key]->setTaxAmount($amount);
$taxArr[$key]->lock();
if (!isset($this->_taxShippingAmount[$cur]))
$this->_taxShippingAmount[$cur] = 0;
$this->_taxShippingAmount[$cur] += $amount;
}
// Taxes sur assurances
$taxArr =& $order->getInsuranceTax();
foreach($taxArr as $key=>$tax) {
$amount = HIPAY_MAPI_UTILS::computeTax($order->getInsuranceAmount(), $tax);
$taxArr[$key]->setTaxAmount($amount);
$taxArr[$key]->lock();
if (!isset($this->_taxInsuranceAmount[$cur]))
$this->_taxInsuranceAmount[$cur] = 0;
$this->_taxInsuranceAmount[$cur] += $amount;
}
// Taxes sur coûts fixes
$taxArr =& $order->getFixedCostTax();
foreach($taxArr as $key=>$tax) {
$amount = HIPAY_MAPI_UTILS::computeTax($order->getFixedCostAmount(), $tax);
$taxArr[$key]->setTaxAmount($amount);
$taxArr[$key]->lock();
if (!isset($this->_taxFixedCostAmount[$cur]))
$this->_taxFixedCostAmount[$cur] = 0;
$this->_taxFixedCostAmount[$cur] += $amount;
}
$cur++;
}
}
/**
* Calcul le montant total HT des produits
*
*/
protected function computeItemsAmount() {
$itemsAmount = 0;
$cur = 0;
foreach($this->items as $item) {
$mt = sprintf("%.02f", $item->getPrice() * $item->getQuantity());
if (!isset($this->order[$cur]))
$cur = 0;
if (!isset($this->_itemsTotalAmount[$cur]))
$this->_itemsTotalAmount[$cur] = 0;
$this->_itemsTotalAmount[$cur] += $mt;
$cur++;
}
}
/**
* Retourne le montant total des taxes
*
* @param array $tItemsAmount
* @param array $tShippingAmount
* @param array $tInsuranceAmount
* @param array $tFixedCostAmount
*/
public function getTotalTaxes(&$tItemsAmount, &$tShippingAmount, &$tInsuranceAmount, &$tFixedCostAmount) {
$tItemsAmount = $this->getItemsTaxes();
$tShippingAmount = $this->getShippingTaxes();
$tInsuranceAmount = $this->getInsuranceTaxes();
$tFixedCostAmount = $this->getFixedCostTaxes();
}
/**
* Retourne le montant des taxes sur les articles
*
* @return float
*/
public function getItemsTaxes() {
return $this->_taxItemsAmount;
}
/**
* Retourne le montant des taxes sur les frais de port
*
* @return float
*/
public function getShippingTaxes() {
return $this->_taxShippingAmount;
}
/**
* Retourne le montant des taxes sur les assurances
*
* @return float
*/
public function getInsuranceTaxes() {
return $this->_taxInsuranceAmount;
}
/**
* Retourne le montant des taxes sur les couts fixes
*
* @return float
*/
public function getFixedCostTaxes() {
return $this->_taxFixedCostAmount;
}
/**
* Retourne le montant total des produits
*
* @return array
*/
public function getItemsTotalAmount() {
return $this->_itemsTotalAmount;
}
/**
* Retourne le montant total des taxes
*
* @return array
*/
public function getTaxesTotalAmount() {
return $this->_taxTotalAmount;
}
/**
* Retourne le montant total hors taxes de la commande
*
* @return array
*/
public function getOrderTotalAmountHT() {
return $this->_orderTotalAmountHT;
}
/**
* Retourne le montant total TTC de la commande
*
* @return array
*/
public function getOrderTotalAmount() {
return $this->_orderTotalAmount;
}
/**
* Retourne le montant total des affiliés
*
* @return array
*/
public function getAffiliateTotalAmount() {
return $this->_affiliateTotalAmount;
}
/**
* Retourne les objets order
*
* @return array
*/
public function getOrder() {
return $this->order;
}
/**
* Retourne les objets items
*
* @return array
*/
public function getItems() {
return $this->items;
}
/**
* Retourne l'objet paramètre
*
* @return HIPAY_MAPI_PaymentParams
*/
public function getPaymentParams() {
return $this->paymentParams;
}
/**
* Calcul les montants à redistribuer aux affiliés
*
*/
protected function computeAffiliates() {
foreach($this->order as $k=>$order) {
$totalAmount = 0;
$tAffiliate = $order->getAffiliate();
foreach($tAffiliate as $key=>$affiliate) {
$baseAmount = 0;
$percentageTarget = $affiliate->getPercentageTarget();
if ($percentageTarget > 0) {
if ($percentageTarget & HIPAY_MAPI_TTARGET_ITEM)
$baseAmount +=$this->_itemsTotalAmount[$k];
if ($percentageTarget & HIPAY_MAPI_TTARGET_TAX)
$baseAmount += $this->_taxItemsAmount[$k] + $this->_taxFixedCostAmount[$k] + $this->_taxInsuranceAmount[$k] + $this->_taxShippingAmount[$k];
if ($percentageTarget& HIPAY_MAPI_TTARGET_INSURANCE)
$baseAmount += $order->getInsuranceAmount();
if ($percentageTarget & HIPAY_MAPI_TTARGET_FCOST)
$baseAmount += $order->getFixedCostAmount();
if ($percentageTarget & HIPAY_MAPI_TTARGET_SHIPPING)
$baseAmount += $order->getShippingAmount();
$tAffiliate[$key]->setBaseAmount($baseAmount);
} else {
$baseAmount = $affiliate->getValue();
$tAffiliate[$key]->setBaseAmount($baseAmount);
}
$totalAmount += $tAffiliate[$key]->getAmount();
$tAffiliate[$key]->lock();
}
$this->_affiliateTotalAmount[$k] = $totalAmount;
if ($totalAmount > $this->_orderTotalAmount[$k]) {
throw new Exception('The total amount to distribute is greather than the transaction amount ('.$totalAmount.'/'.$this->_orderTotalAmount.')');
}
}
}
}
+880
View File
@@ -0,0 +1,880 @@
<?php
/**
* Paramètres
*
*/
class HIPAY_MAPI_PaymentParams extends HIPAY_MAPI_lockable {
/**
* Nom d'utilisateur pour se connecter à la plateforme
*
* @var string
*/
protected $login;
/**
* Mot de passe de connexion
*
* @var string
*/
protected $password;
/**
* Compte sur lequel verser le montant HT des produits
*
* @var int
*/
protected $itemAccount;
/**
* Compte sur lequel verser le montant des taxes
*
* @var int
*/
protected $taxAccount;
/**
* Compte sur lequel verser le montant des assurances
*
* @var int
*/
protected $insuranceAccount;
/**
* Compte sur lequel verser le montant des coûts fixes
*
* @var int
*/
protected $fixedCostAccount;
/**
* Compte sur lequel verser le montant des frais de livraison
*
* @var int
*/
protected $shippingCostAccount;
/**
* Langue par défaut de l'interface de paiement
*
* @var string
*/
protected $defaultLang;
/**
* Type d'interface de paiement
*
* @var string
*/
protected $media;
/**
* Classe d'age à laquelle s'applique cette vente
*
* @var string
*/
protected $rating;
/**
* Type du paiement (simple ou récurrent)
*
* @var int
*/
protected $paymentMethod;
/**
* Délai de capture
*
* @var int
*/
protected $captureDay;
/**
* Devise dans laquelle sont exprimés les montants
*
* @var string
*/
protected $currency;
/**
* Identifiant de cette vente pour le marchant
*
* @var int
*/
protected $idForMerchant;
/**
* Identifiant du site marchand tel que renseigné
* dans l'interface marchande de la plateforme
*
* @var int
*/
protected $merchantSiteId;
/**
* Identifiant du groupe statistique auquel appartient ce paiement
*
* @var int
*/
protected $statsGroupId;
/**
* Données propres au marchand
*
* @var string
*/
protected $merchantDatas;
/**
* Url sur laquelle est redirigée le client si le paiement est ok
*
* @var string
*/
protected $url_ok;
/**
* Url sur laquelle est redirigée le client si le paiement n'est pas ok
*
* @var string
*/
protected $url_nok;
/**
* Url sur laquelle est redirigée le client si le paiement est annulé
*
* @var string
*/
protected $url_cancel;
/**
* Url du script qui sera appellé pour signifier le résultat du paiement
*
* @var string
*/
protected $url_ack;
/**
* Chaine de caractère devant etre retournée par le script $url_ack
* pour informer de la bonne réception des informations
*
* @var string
*/
protected $ack_wd;
/**
* Adresse email vers laquelle la plateforme enverra un email
* pour informer d'un nouveau paiement
*
* @var string
*/
protected $email_ack;
/**
* code hexa de la couleur de fond de l'interface
*
* @var string
*/
protected $bg_color;
/**
* Url du logo du marchand
*
* @var string
*/
protected $logo_url;
/**
* Assigne le login et le mot de passe
*
* @param string $login
* @param string $password
* @return boolean
*/
public function setLogin($login, $password) {
if ($this->_locked)
return false;
$login = HIPAY_MAPI_UTF8::forceUTF8($login);
if (empty($login))
return false;
$password = HIPAY_MAPI_UTF8::forceUTF8($password);
if (empty($password))
return false;
$this->login = $login;
$this->password = $password;
return true;
}
/**
* Retourne le login
*
* @return string
*/
public function getLogin() {
return $this->login;
}
/**
* Retourne le mot de passe
*
* @return string
*/
public function getPassword() {
return $this->password;
}
/**
* Assigne les comptes sur lesquels seront versés les différents montants
*
* @param int $itemAccount
* @param int $taxAccount
* @param int $insuranceAccount
* @param int $fixedCostAccount
* @param int $shippingCostAccount
* @return boolean
*/
public function setAccounts($itemAccount, $taxAccount = 0, $insuranceAccount = 0, $fixedCostAccount =0, $shippingCostAccount = 0) {
if ($this->_locked)
return false;
$itemAccount = (int)$itemAccount;
$taxAccount = (int)$taxAccount;
$insuranceAccount = (int)$insuranceAccount;
$fixedCostAccount = (int)$fixedCostAccount;
$shippingCostAccount = (int)$shippingCostAccount;
if ($itemAccount <= 0)
return false;
if ($taxAccount <= 0)
$taxAccount = $itemAccount;
if ($insuranceAccount <= 0)
$insuranceAccount = $itemAccount;
if ($fixedCostAccount <= 0)
$fixedCostAccount = $itemAccount;
if ($shippingCostAccount <= 0)
$shippingCostAccount = $itemAccount;
$this->itemAccount = $itemAccount;
$this->taxAccount = $taxAccount;
$this->insuranceAccount = $insuranceAccount;
$this->fixedCostAccount = $fixedCostAccount;
$this->shippingCostAccount = $shippingCostAccount;
return true;
}
/**
* Retourne le numéro de compte sur lequel sera versé
* le montant de produits
*
* @return int
*/
public function getItemAccount() {
return $this->itemAccount;
}
/**
* Retourne le numéro de compte sur lequel sera versé
* le montant des taxes
*
* @return int
*/
public function getTaxAccount() {
return $this->taxAccount;
}
/**
* Retourne le numéro de compte sur lequel sera versé
* le montant des assurances
*
* @return int
*/
public function getInsuranceAccount() {
return $this->insuranceAccount;
}
/**
* Retourne le numéro de compte sur lequel sera versé
* le montant des coûts fixes
*
* @return int
*/
public function getFixedCostAccount() {
return $this->fixedCostAccount;
}
/**
* Retourne le numéro de compte sur lequel sera versé
* le montant des frais d'envoi
*
* @return int
*/
public function getShippingCostAccount() {
return $this->shippingCostAccount;
}
/**
* Assigne la lange par défaut (AZ_az = pays_langue)
*
* @param string $defaultLang
* @return boolean
*/
public function setDefaultLang($defaultLang) {
if ($this->_locked)
return false;
if (!preg_match('#^[A-Z]{2}_[a-z]{2}$#', $defaultLang))
return false;
$this->defaultLang = $defaultLang;
return true;
}
/**
* Retourne la langue par défaut
*
* @return string
*/
public function getDefaultLang() {
return $this->defaultLang;
}
/**
* Défini le type d'interface de paiement
*
* @param string $media
* @return boolean
*/
public function setMedia($media) {
if ($this->_locked)
return false;
if (!preg_match('#^[A-Z]+$#', $media))
return false;
$this->media = $media;
return true;
}
/**
* Retourne le type d'interface de paiement
*
* @return string
*/
public function getMedia() {
return $this->media;
}
/**
* Défini le public visé
*
* @param string $rating
* @return boolean
*/
public function setRating($rating) {
if ($this->_locked)
return false;
$rating = trim(substr($rating, 0, HIPAY_MAPI_MAX_RATING_LENGTH));
if ($rating == '')
return false;
$this->rating = $rating;
return true;
}
/**
* Retourne le type de public visé
*
* @return string
*/
public function getRating() {
return $this->rating;
}
/**
* Défini si le paiement est simple ou récurrent
*
* @param int $paymentMethod
* @return boolean
*/
public function setPaymentMethod($paymentMethod) {
if ($this->_locked)
{
return false;
}
$paymentMethod = (int)$paymentMethod;
if ($paymentMethod != HIPAY_MAPI_METHOD_SIMPLE && $paymentMethod != HIPAY_MAPI_METHOD_MULTI)
return false;
$this->paymentMethod = $paymentMethod;
return true;
}
/**
* Retourne le type de paiement (simple ou récurrent)
*
* @return int
*/
public function getPaymentMethod() {
return $this->paymentMethod;
}
/**
* Défini le délai de capture
*
* @param int $captureDay
* @return boolean
*/
public function setCaptureDay($captureDay) {
if ($this->_locked)
return false;
$captureDay = (int)$captureDay;
if (($captureDay != HIPAY_MAPI_CAPTURE_MANUAL && $captureDay != HIPAY_MAPI_CAPTURE_IMMEDIATE && $captureDay <= 0) || $captureDay > HIPAY_MAPI_CAPTURE_MAX_DAYS)
return false;
$this->captureDay = $captureDay;
return true;
}
/**
* Retourne le délai de capture
*
* @return int
*/
public function getCaptureDay() {
return $this->captureDay;
}
/**
* Défini la devise
*
* @param string $currency
* @return boolean
*/
public function setCurrency($currency) {
if ($this->_locked)
return false;
if (!preg_match('#^[A-Z]{3}$#', $currency))
return false;
$this->currency = $currency;
return true;
}
/**
* Retourne la devise
*
* @return string
*/
public function getCurrency() {
return $this->currency;
}
/**
* Défini l'identifiant du groupe statistique auquel appartient ce paiement
*
* @param int $statsGroupId
* @return boolean
*/
public function setStatsGroupId($statsGroupId) {
if ($this->_locked)
return false;
$statsGroupId = (int)$statsGroupId;
if ($statsGroupId < 0)
return false;
$this->statsGroupId = $statsGroupId;
return true;
}
/**
* Retourne l'identifiant du groupe statistique auquel appartient ce paiement
*
* @return int
*/
public function getStatsGroupId() {
return $this->statsGroupId;
}
/**
* Défini l'identifiant de cette vente chez le marchand
*
* @param string $idForMerchant
* @return boolean
*/
public function setIdForMerchant($idForMerchant) {
if ($this->_locked)
return false;
$this->idForMerchant = $idForMerchant;
return true;
}
/**
* Retourne l'identifiant de la vente pour le marchand
*
* @return string
*/
public function getIdForMerchant() {
return $this->idForMerchant;
}
/**
* Défini l'identifiant du site marchand
*
* @param int $merchantSiteId
* @return boolean
*/
public function setMerchantSiteId($merchantSiteId) {
if ($this->_locked)
return false;
$merchantSiteId = (int)$merchantSiteId;
if ($merchantSiteId < 0)
return false;
$this->merchantSiteId = $merchantSiteId;
return true;
}
/**
* Retourne l'identifiant du site marchand
*
* @return int
*/
public function getMerchantSiteId() {
return $this->merchantSiteId;
}
/**
* Assigne des données marchandes
*
* @param string $merchantDatas
* @return boolean
*/
public function setMerchantDatas($key,$merchantDatas) {
if ($this->_locked)
return false;
if ($key == '')
return false;
$merchantDatas = substr($merchantDatas, 0, HIPAY_MAPI_MAX_MDATAS_LENGTH);
$this->merchantDatas[$key] = $merchantDatas;
return true;
}
/**
* Retourne les données marchandes
*
* @return array
*/
public function getMerchantDatas() {
return $this->merchantDatas;
}
/**
* Assigne l'url à appeller si le paiement est ok
*
* @param string $url_ok
* @return unknown
*/
public function setUrlOk($url_ok) {
if ($this->_locked)
return false;
$url_ok = trim($url_ok);
if (!HIPAY_MAPI_UTILS::checkURL($url_ok) && $url_ok != '')
return false;
$this->url_ok = $url_ok;
return true;
}
/**
* Retourne l'url_ok
*
* @return string
*/
public function getUrlOk() {
return $this->url_ok;
}
/**
* Assigne l'url à appeller si le paiement n'est pas ok
*
* @param string $url_nok
* @return unknown
*/
public function setUrlNok($url_nok) {
if ($this->_locked)
return false;
$url_nok = trim($url_nok);
if (!HIPAY_MAPI_UTILS::checkURL($url_nok) && $url_nok != '')
return false;
$this->url_nok = $url_nok;
return true;
}
/**
* Retourne l'url_nok
*
* @return string
*/
public function getUrlNok() {
return $this->url_nok;
}
/**
* Assigne l'url à appeller si le paiement est annulé
*
* @param string $url_cancel
* @return boolean
*/
public function setUrlCancel($url_cancel) {
if ($this->_locked)
return false;
$url_cancel = trim($url_cancel);
if (!HIPAY_MAPI_UTILS::checkURL($url_cancel) && $url_cancel != '')
return false;
$this->url_cancel = $url_cancel;
return true;
}
/**
* Retourne l'url_cancel
*
* @return string
*/
public function getUrlCancel() {
return $this->url_cancel;
}
/**
* Assigne l'url à appeller pour notifier le paiement
*
* @param string $url_cancel
* @return boolean
*/
public function setUrlAck($url_ack) {
if ($this->_locked)
return false;
$url_ack = trim($url_ack);
if (!HIPAY_MAPI_UTILS::checkURL($url_ack) && $url_ack != '')
return false;
$this->url_ack = $url_ack;
return true;
}
/**
* Retourne l'url_ack
*
* @return string
*/
public function getUrlAck() {
return $this->url_ack;
}
/**
* Assigne le mot clé d'acquittement
*
* @param string $ack_wd
* @return boolean
*/
public function setAckWd($ack_wd) {
if ($this->_locked)
return false;
$ack_wd=trim($ack_wd);
if (strlen($ack_wd) > HIPAY_MAPI_MAX_ACKWD_LENGTH)
return false;
$this->ack_wd = $ack_wd;
return true;
}
/**
* Retourne le mot clé d'acquittement
*
* @return string
*/
public function getAckWd() {
return $this->ack_wd;
}
/**
* Assigne l'adresse email de notification de paiement
*
* @param string $email_ack
* @return boolean
*/
public function setEmailAck($email_ack) {
if ($this->_locked)
return false;
$email_ack = trim($email_ack);
if (strlen($email_ack) > HIPAY_MAPI_MAX_ACKMAIL_LENGTH || (!HIPAY_MAPI_UTILS::checkemail($email_ack) && $email_ack != ''))
return false;
$this->email_ack = $email_ack;
return true;
}
/**
* Retourne l'email de notification
*
* @return string
*/
public function getEmailAck() {
return $this->email_ack;
}
/**
* Assigne la couleur de fond de l'interface (#XXXXXX)
*
* @param string $bg_color
* @return boolean
*/
public function setBackgroundColor($bg_color) {
if ($this->_locked)
return false;
$bg_color = trim($bg_color);
if (!preg_match('#^\#([0-9a-f]){6}$#i', $bg_color) && $bg_color != '')
return false;
$this->bg_color = $bg_color;
return true;
}
/**
* Retourne la couleur de fond de l'interface
*
* @return string
*/
public function getBackgroundColor() {
return $this->bg_color;
}
/**
* Assigne l'url du logo du marchand
*
* @param string $logo_url
* @return boolean
*/
public function setLogoUrl($logo_url) {
if ($this->_locked)
return false;
$logo_url = trim($logo_url);
if (!HIPAY_MAPI_UTILS::checkURL($logo_url) && $logo_url != '')
return false;
$this->logo_url = $logo_url;
return true;
}
/**
* Retourne l'url du logo du marchand
*
* @return string
*/
public function getLogoUrl() {
return $this->logo_url;
}
/**
* Vérifie que l'objet est correctement initialisé
*
* @return boolean
*/
public function check() {
if ($this->login == '')
throw new Exception('Username is missing');
if ($this->itemAccount <= 0 || $this->taxAccount <= 0 || $this->insuranceAccount <= 0 ||
$this->fixedCostAccount <= 0 || $this->shippingCostAccount <= 0)
throw new Exception('Invalid account numbers');
if ($this->rating == '')
throw new Exception('Invalid public target');
if ($this->paymentMethod < 0)
throw new Exception('Invalid payment type');
if ($this->captureDay == -100)
throw new Exception('Invalid capture delay');
if ($this->currency == '')
throw new Exception('Undefined currency');
if ($this->idForMerchant < 0)
throw new Exception('Merchant ID is missing');
if ($this->idForMerchant > 0)
if ($this->password == '')
throw new Exception('Password is missing');
if ($this->statsGroupId < 0)
throw new Exception('Negative group ID');
if ($this->merchantSiteId < 0)
throw new Exception('Merchant site ID is missing');
return true;
}
protected function init() {
$this->login = '';
$this->password = '';
$this->itemAccount = 0;
$this->taxAccount = 0;
$this->insuranceAccount = 0;
$this->fixedCostAccount = 0;
$this->shippingCostAccount = 0;
$this->defaultLang = HIPAY_MAPI_DEFLANG;
$this->media = HIPAY_MAPI_DEFMEDIA;
$this->rating = '';
$this->paymentMethod = -1;
$this->captureDay = -100;
$this->currency = '';
$this->idForMerchant = -1;
$this->statsGroupId = 0;
$this->merchantSiteId = -1;
$this->merchantDatas = array();
$this->url_ok = '';
$this->url_nok = '';
$this->url_cancel = '';
$this->url_ack = '';
$this->ack_wd = '';
$this->email_ack = '';
$this->bg_color = '';
$this->logo_url = '';
}
function __construct() {
$this->init();
parent::__construct();
}
}
+285
View File
@@ -0,0 +1,285 @@
<?php
/**
* Représente une ligne de la commande pour un paiement simple
*
*/
class HIPAY_MAPI_Product extends HIPAY_MAPI_Item {
/**
* Nom du produit
*
* @var string
*/
protected $name;
/**
* Informations sur le produit
*
* @var string
*/
protected $info;
/**
* quantité
*
* @var int
*/
protected $quantity;
/**
* Réference produit
*
* @var string
*/
protected $ref;
/**
* Catégorie du produit
*
* @var int
*/
protected $category;
/**
* Montant unitaire HT du produit
*
* @var float
*/
protected $price;
/**
* Taxes s'appliquant à ce produit
*
* @var array
*/
protected $tax;
/**
* Assigne le nom du produit
*
* @param string $name
* @return boolean
*/
public function setName($name) {
if ($this->_locked)
return false;
$name = HIPAY_MAPI_UTF8::forceUTF8($name);
$len = HIPAY_MAPI_UTF8::strlen_utf8($name);
if ($len < 1 || $len > HIPAY_MAPI_MAX_PRODUCT_NAME_LENGTH)
return false;
$this->name = $name;
return true;
}
/**
* Retourne le nom du produit
*
* @return string
*/
public function getName() {
return $this->name;
}
/**
* Assigne les informations sur le produit
*
* @param string $info
* @return boolean
*/
public function setInfo($info) {
if ($this->_locked)
return false;
$info = HIPAY_MAPI_UTF8::forceUTF8($info);
$len = HIPAY_MAPI_UTF8::strlen_utf8($info);
if ($len > HIPAY_MAPI_MAX_PRODUCT_INFO_LENGTH)
return false;
$this->info = $info;
return true;
}
/**
* Retourne les informations sur le produit
*
* @return string
*/
public function getInfo() {
return $this->info;
}
/**
* Assigne la quantité de produit
*
* @param int $quantity
* @return boolean
*/
public function setQuantity($quantity) {
if ($this->_locked)
return false;
$quantity = (int)$quantity;
if ($quantity < 1)
return false;
$this->quantity = $quantity;
return true;
}
/**
* Retourne la quantité de produit
*
* @return int
*/
public function getQuantity() {
return $this->quantity;
}
/**
* Assigne la réference du produit
*
* @param string $ref
* @return boolean
*/
public function setRef($ref) {
if ($this->_locked)
return false;
$ref = HIPAY_MAPI_UTF8::forceUTF8($ref);
$len = HIPAY_MAPI_UTF8::strlen_utf8($ref);
if ($len > HIPAY_MAPI_MAX_PRODUCT_REF_LENGTH)
return false;
$this->ref = $ref;
return true;
}
/**
* Retourne la réference du produit
*
* @return string
*/
public function getRef() {
return $this->ref;
}
/**
* Assigne la catégorie du produit
*
* @param int $category
* @return boolean
*/
public function setCategory($category) {
if ($this->_locked)
return false;
$category = (int)$category;
if ($category < 1)
return false;
$this->category = $category;
return true;
}
/**
* Retourne la catégorie du produit
*
* @return int
*/
public function getCategory() {
return $this->category;
}
/**
* Assigne le montant unitaire HT du produit
*
* @param float $price
* @return boolean
*/
public function setPrice($price) {
if ($this->_locked)
return false;
$price = sprintf('%.02f', (float)$price);
if ($price < 0)
return false;
$this->price = $price;
return true;
}
/**
* Retourne montant unitaire HT du produit
*
* @return float
*/
public function getPrice() {
return $this->price;
}
/**
* Assigne les taxes s'appliquant à ce produit
*
* @param array $tax
* @return boolean
*/
public function setTax($tax) {
if ($this->_locked)
return false;
if (empty($tax))
return false;
if (!HIPAY_MAPI_UTILS::is_an_array_of($tax,'HIPAY_MAPI_Tax'))
return false;
foreach ($tax as $obj)
$this->tax[]= clone $obj;
return true;
}
/**
* Retourne les taxes s'appliquant à ce produit
*
* @return array
*/
public function getTax() {
return $this->tax;
}
/**
* Vérifie que l'objet est correctement initialisé
*
* @return boolean
*/
public function check() {
if ($this->name == '' || $this->quantity < 0 || $this->category < 0 || $this->price < 0 || !HIPAY_MAPI_UTILS::is_an_array_of($this->tax, 'HIPAY_MAPI_Tax'))
throw new Exception('Object not initialized. Please precise a product name, quantity, price, category and taxes');
foreach($this->tax as $obj) {
if (!$obj->check())
return false;
}
return true;
}
protected function init() {
$this->name = '';
$this->info = '';
$this->quantity = -1;
$this->ref = '';
$this->category = -1;
$this->price = -1;
$this->tax = array();
}
function __construct() {
$this->init();
parent::__construct();
}
}
+89
View File
@@ -0,0 +1,89 @@
<?php
class HIPAY_MAPI_SEND_XML {
/**
* Envoi le flux XML et retourne la réponse du serveur
*
* un timeout trop bas
* Une mauvaise url
* un proxy mal configuré s'il existe
*
* peuvent engendrer une erreur de connexion
*
* @param string $xml
* @return string
*/
public static function sendXML($xml, $url = "") {
$xml = self::prepare($xml);
if ($url == "")
$turl = parse_url(HIPAY_GATEWAY_URL);
else
$turl = parse_url($url);
if (!isset($turl['path']))
$turl['path'] = '/';
$curl = curl_init();
curl_setopt($curl, CURLOPT_TIMEOUT, HIPAY_MAPI_CURL_TIMEOUT);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_USERAGENT, "HIPAY");
curl_setopt($curl, CURLOPT_URL, $turl['scheme'].'://'.$turl['host'].$turl['path']);
curl_setopt($curl, CURLOPT_POSTFIELDS, 'xml='.urlencode($xml));
if(HIPAY_MAPI_CURL_PROXY_ON === true)
{
curl_setopt($curl, CURLOPT_PROXY, HIPAY_MAPI_CURL_PROXY);
curl_setopt($curl, CURLOPT_PROXYPORT, HIPAY_MAPI_CURL_PROXYPORT);
}
if(HIPAY_MAPI_CURL_LOG_ON === true)
{
$errorFileLog = fopen(HIPAY_MAPI_CURL_LOGFILE, "a+");
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_STDERR, $errorFileLog);
}
curl_setopt($curl, CURLOPT_HEADER, 0);
ob_start();
if (curl_exec($curl) !== true)
{
$output = $turl['scheme'].'://'.$turl['host'].$turl['path'].' is not reachable';
$output .= '<br />Network problem ? Verify your proxy configuration in mapi_defs.php';
}
else
$output = ob_get_contents();
ob_end_clean();
curl_close($curl);
if(HIPAY_MAPI_CURL_LOG_ON === true)
{
fclose($errorFileLog);
}
return $output;
}
/**
* Prépare le flux XML
*
* @param string $xml
* @return string
*/
public static function prepare($xml) {
$cleanXML = '';
$xml = trim($xml);
$md5 = hash('md5', $xml);
$cleanXML = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
$cleanXML .= "<mapi>\n";
$cleanXML .= "<mapiversion>".MAPI_VERSION."</mapiversion>\n";
$cleanXML .= '<md5content>'.$md5."</md5content>\n";
$cleanXML .= $xml;
$cleanXML .= "\n</mapi>\n";
return trim($cleanXML);
}
}
+19
View File
@@ -0,0 +1,19 @@
<?php
/**
* Représente un paiement simple
* Un paiement simple contient :
* - 1 objet paramètres HIPAY_MAPI_PaymentParams
* - 1 objet order HIPAY_MAPI_Order
* - n objet produits représentant les lignes de la commande HIPAY_MAPI_Product
*
*/
class HIPAY_MAPI_SimplePayment extends HIPAY_MAPI_Payment {
function __construct(HIPAY_MAPI_PaymentParams $paymentParams, HIPAY_MAPI_Order $order, $items) {
try {
parent::__construct($paymentParams, array($order), $items);
} catch(Exception $e) {
throw new Exception($e->getMessage());
}
}
}
+165
View File
@@ -0,0 +1,165 @@
<?php
/**
* Gestion des taxes
*
*/
class HIPAY_MAPI_Tax extends HIPAY_MAPI_lockable
{
/**
* nom de la taxe
*
* @var string
*/
protected $taxName;
/**
* valeur de la taxe
*
* @var float
*/
protected $taxVal;
/**
* true si la valeur de la taxe est un pourcentage
*
* @var boolean
*/
protected $percentage;
/**
* Montant calculé de la taxe
*
* @var float
*/
protected $_amount;
/**
* assigne le nom de la taxe
*
* @param string $taxName nom de la taxe
* @return boolean true si l'assignation s'est bien déroulée
*/
public function setTaxName($taxName) {
if ($this->_locked)
return false;
$taxName = HIPAY_MAPI_UTF8::forceUTF8($taxName);
$len = HIPAY_MAPI_UTF8::strlen_utf8($taxName);
if ($len < 1 || $len > HIPAY_MAPI_MAX_TAX_NAME_LENGTH)
return false;
$this->taxName = $taxName;
return true;
}
/**
* retourne le nom de la taxe
*
* @return string nom de la taxe
*/
public function getTaxName() {
return $this->taxName;
}
/**
* assigne la valeur de la taxe
*
* @param float $taxVal valeur de la taxe
* @param boolean $percentage true si la valeur de la taxe est un pourcentage
* @return boolean true si l'assignation s'est bien déroulée
*/
public function setTaxVal($taxVal, $percentage = true) {
if ($this->_locked)
return false;
if (!is_bool($percentage))
return false;
$taxVal = sprintf('%.02f', (float)$taxVal);
if ($percentage && ($taxVal <= 0 || $taxVal > 100))
return false;
$this->taxVal = $taxVal;
$this->percentage = $percentage;
return true;
}
/**
* retourne la valeur de la taxe
*
* @return float valeur de la taxe
*/
public function getTaxVal() {
return $this->taxVal;
}
/**
* détermine si la valeur de la taxe est un pourcentage
*
* @return boolean true si la valeur de la taxe est un pourcentage
*/
public function isPercentage() {
return $this->percentage;
}
/**
* effectue une vérification des propriétés de la taxe
*
* @return boolean true si les propriétés de la taxe sont correctes
*/
public function check() {
if ($this->taxName == '' || $this->taxVal < 0)
throw new Exception('Tax name or Tax value not initialized');
return true;
}
/**
* initilise les propriétés de la taxe
*
*/
protected function init() {
$this->taxVal = -1;
$this->taxName = '';
$this->percentage = false;
$this->_amount = 0;
$this->_locked = false;
}
/**
* assigne le montant calculé de la taxe
*
* @param float $amount montant calculé
* @return boolean true si l'assignation s'est bien déroulée
*/
public function setTaxAmount($amount) {
if ($this->_locked)
return false;
$amount = (float)$amount;
if ($amount < 0)
$amount = 0;
$this->_amount = sprintf("%.02f", $amount);
return true;
}
/**
* retourne le montant calculé de la taxe
*
* @return float montant calculé
*/
public function getTaxAmount() {
return $this->_amount;
}
/**
* constructeur
*
*/
function __construct() {
$this->init();
parent::__construct();
}
}
+70
View File
@@ -0,0 +1,70 @@
<?php
class HIPAY_MAPI_UTF8
{
/**
* Test si une chaine est en UTF-8
*
* @param string $string
* @return boolean
*/
public static function is_utf8($string) {
// From http://w3.org/International/questions/qa-forms-utf-8.html
return preg_match('%^(?:
[\x09\x0A\x0D\x20-\x7E] # ASCII
| [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
| \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
| [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
| \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
| \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
| [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
| \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
)*$%xs', $string);
}
/**
* Encode une chaine en UTF-8 si elle ne l'est pas déjà
*
* @param string $string
* @return string
*/
public static function forceUTF8($string) {
if (!self::is_utf8($string))
return utf8_encode($string);
else
return $string;
}
/**
* Longueur d'une chaine UTF-8
*
* @param string $str
* @return int longueur de la chaine
*/
public static function strlen_utf8 ($str) {
$i = 0;
$count = 0;
$len = strlen ($str);
while ($i < $len)
{
$chr = ord($str[$i]);
$count++;
$i++;
if ($i >= $len)
break;
if ($chr & 0x80)
{
$chr <<= 1;
while ($chr & 0x80)
{
$i++;
$chr <<= 1;
}
}
}
return $count;
}
}
+73
View File
@@ -0,0 +1,73 @@
<?php
class HIPAY_MAPI_UTILS {
/**
* Vérifie si le tableau $array contient des objet $objectName
*
* @param array $array
* @param string $objectName
* @return boolean
*/
public static function is_an_array_of($array, $objectName) {
if (!is_array($array))
return false;
try {
foreach($array as $obj) {
if (!($obj instanceof $objectName)) {
return false;
}
}
} catch (Exception $e) {
return false;
}
return true;
}
/**
* Retourne le montant calculé d'une taxe en fonction de la valeur $itemValue
*
* @param float $itemValue
* @param HIPAY_MAPI_Tax $tax
* @return float
*/
public static function computeTax($itemValue, HIPAY_MAPI_Tax $tax) {
$itemValue = (float)$itemValue;
$taxAmount = 0;
if ($tax->isPercentage()) {
$taxAmount = sprintf("%.02f", ($itemValue / 100) * $tax->getTaxVal());
} else {
$taxAmount += sprintf("%.02f", $tax->getTaxVal());
}
return (float)$taxAmount;
}
/**
* Vérifie la validité d'une URL
*
* @param string $url
* @return boolean
*/
public static function checkURL($url) {
return preg_match('#^(((http|https):\/\/){0,1})(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(.*)#i', $url);
}
/**
* Vérifie la validité de l'email
*
* @param string $email
* @return boolean
*/
public static function checkemail($email) {
return preg_match('#^[_a-z0-9-]+(\.[_a-z0-9-]*)*@[a-z0-9-]+(\.[a-z0-9-]+)+$#i', $email);
}
public static function parseDelay($delay)
{
$array = array_fill_keys(array('H', 'I', 'S', 'M', 'D', 'Y'), 0);
$n = substr($delay, 0, -1);
$r = substr($delay, -1, 1);
$array[strtoupper($r)] = $n;
return $array;
}
}
+72
View File
@@ -0,0 +1,72 @@
<?php
class HIPAY_MAPI_XML {
/**
* Cré le flux XML de cet objet.
* Les membres commençants par "_" sont ignorées
*
* @param int $t
* @return string
*/
public function getXML($t = 0, $noshow = true) {
$xml = '';
$xml .= str_repeat(chr(9), $t)."<".get_class($this).">\n";
foreach($this as $name => $value) {
if ($noshow && substr($name, 0, 1) == '_')
continue;
if (!is_array($this->$name) && !is_object($this->$name) && !is_bool($this->$name)) {
$xml .= str_repeat(chr(9), $t + 1)."<$name>$value</$name>\n";
} else if (is_bool($this->$name)) {
if ($value === true)
$xml .= str_repeat(chr(9), $t + 1)."<$name>true</$name>\n";
else
$xml .= str_repeat(chr(9), $t + 1)."<$name>false</$name>\n";
} else if (is_object($this->$name) && method_exists($this->$name, 'getXML')) {
$xml .= $this->$name->getXml($t + 1);
} else if (is_array($this->$name)) {
$xml .= str_repeat(chr(9), $t + 1)."<$name>\n";
$xml .= self::getXMLArray($this->$name, $t + 1, $noshow);
$xml .= str_repeat(chr(9), $t + 1)."</$name>\n";
}
// else : no getXML method available
}
$xml .= str_repeat(chr(9), $t)."</".get_class($this).">\n";
return $xml;
}
/**
* Cré le flux XML d'un tableau
*
* @param array $array
* @param int $t
* @return string
*/
protected function getXMLArray($array, $t = 0, $noshow = true) {
$xml = '';
foreach($array as $name => $value) {
if (substr($name, 0, 1) == '_')
continue;
if (!is_array($array[$name]) && !is_object($array[$name]) && !is_bool($array[$name])) {
$xml .= str_repeat(chr(9), $t + 1)."<_aKey_$name>$value</_aKey_$name>\n";
} else if (is_bool($array[$name])) {
if ($value === true)
$xml .= str_repeat(chr(9), $t + 1)."<$name>true</$name>\n";
else
$xml .= str_repeat(chr(9), $t + 1)."<$name>false</$name>\n";
} else if (is_object($array[$name]) && method_exists($array[$name], 'getXML')) {
$xml .= $array[$name]->getXml($t + 1);
} else if (is_array($array[$name])){
$xml .= str_repeat(chr(9), $t + 1)."<$name>\n";
$xml .= self::getXMLArray($array[$name], $t + 1, $noshow);
$xml .= str_repeat(chr(9), $t + 1)."</$name>\n";
}
}
return $xml;
}
}