<?php
require_once 'hipay_mapi_php5_1_0/mapi_package.php';

$params = new HIPAY_MAPI_PaymentParams();
//The Hipay platform connection parameters. This is not the information used to connect to your Hipay //account, but the specific login and password used to connect to the payment platform.
//The login is the ID of the hipay merchant account receiving the payment, and the password is
//the « merchant password » set within your Hipay account.
$params->setLogin('3603196','FACEJOBB');
// The amounts will be credited to account 59118, except the taxes which will be credited to account 59119
$params->setAccounts(3603196);
// The payment interface will be in International French by default
$params->setLocale('fr_FR');
// The interface will be the Web interface
$params->setMedia('WEB');
//The order content is intended for people at least 16 years old.
$params->setRating('+16');
// This is a single payment
$params->setPaymentMethod(HIPAY_MAPI_METHOD_SIMPLE);
// The capture take place immediately
$params->setCaptureDay(HIPAY_MAPI_CAPTURE_IMMEDIATE);

// The amounts are expressed in Euros, this has to be the same currency as the merchant’s account.
$params->setCurrency('EUR');
// The merchant-selected identifier for this order is REF6522
$params->setIdForMerchant('REF6522');
//Two data elements of type key=value are declared and will be returned to the merchant after the payment in the notification data feed [C].
//$params->setMerchantDatas('id_client','2000');
//$params->setMerchantDatas('credit','10');
// This order relates to the web site which the merchant declared in the Hipay platform.
// The I.D. assigned to this website is ‘9’
$params->setMerchantSiteId(35641);
// If the payment is accepted, the user will be redirected to this page
$params->setURLOk('http://www.monsite.com/success.html');
// If the payment is refused, the user will be redirected to this page
$params->setUrlNok('http://www.monsite.com/refused.html');
// If the user cancels the payment, he will be redirected to this page
$params->setUrlCancel('http://www.monsite.com/cancel.html');
// The email address used to send the notifications, on top of the http notifications.
// cf chap 19 : RECEIVING A RESULTS NOTIFICATION ABOUT A PAYMENT ACTION
$params->setEmailAck('hipay_notification@monsite.com');
// The merchant’s site will be notified of the result of the payment by a call to the script
// “listen_hipay_notification.php”
// cf chap 19 : RECEIVING A RESULTS NOTIFICATION ABOUT A PAYMENT ACTION
$params->setUrlAck('http://www.monsite.com/listen_hipay_notification.php');
$t=$params->check();
if (!$t)
{ echo "An error occurred while creating the paymentParams object";
exit;
}

// TAXES
// Tax at 19.6%
$tax1 = new HIPAY_MAPI_Tax();
$tax1->setTaxName('TVA (19.6)');
$tax1->setTaxVal(19.6,true);
$t=$tax1->check();
if (!$t)
{
echo "An error occurred while creating a tax object";
exit;
}
// First product: 2 copies of a book at 12.5 Euros per unit on which two taxes are applied
//(taxes $tax3 and $tax2)
$item1 = new HIPAY_MAPI_Product();
$item1->setName('Achat de emps de diffusion pour vos offres');
$item1->setInfo('6 offres durant2 semaines au prix unitaire de 69.0');
$item1->setquantity(1);
$item1->setCategory(618);
$item1->setPrice(828.0);
$t=$item1->check();
if (!$t)
{
echo "An error occurred while creating a product object";
exit;
}

$order = new HIPAY_MAPI_Order();
// Order title and information
$order->setOrderTitle('Votre achat sur facefoot');
$order->setOrderInfo('votre commande numéro 1 de 828.00 euros');

// The order category is 3 (Books)
// Refer to annex 7 to see how to find out what category your site belongs to.
$order->setOrderCategory(618);
$t=$order->check();
if (!$t)
{
echo "An error occurred while creating a product object";
exit;
}

try {
$payment = new HIPAY_MAPI_SimplePayment($params,$order,array($item1));
}
catch (Exception $e) {
echo "Error" .$e->getMessage();
}

$xmlTx=$payment->getXML();
$output=HIPAY_MAPI_SEND_XML::sendXML($xmlTx);

//header('Content-Type: text/xml; charset=UTF-8');
//echo $xmlTx;

$r=HIPAY_MAPI_COMM_XML::analyzeResponseXML($output, $url, $err_msg);
if ($r===true) {
// The internet user is sent to the URL indicated by the Hipay platform
//header('Location: '.$url . '/pay-mode/registered') ;
echo $url;
} else {
// Une erreur est intervenue
echo $err_msg;
// $url_error = “/error.html”;
//header('Location: '.$url_error) ;
}

?>
