Works on paypal module

New: add trigger for fee treatment
Todo: problem with global in the triggers
This commit is contained in:
Regis Houssin 2011-05-24 20:20:24 +00:00
parent ee7e13e4a1
commit cd08296965
3 changed files with 73 additions and 25 deletions

View File

@ -98,15 +98,41 @@ class InterfacePaypalWorkflow
// Mettre ici le code a executer en reaction de l'action
// Les donnees de l'action sont stockees dans $object
// Add Paypal fee
if ($action == 'PAYMENT_ADD_TO_BANK')
if ($action == 'PAYMENT_ADD_TO_BANK' && $object->fk_account == $conf->global->PAYPAL_BANK_ACCOUNT)
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->rowid);
//var_dump($object);
// use num_paiement and fk_account
require_once(DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php');
require_once(DOL_DOCUMENT_ROOT."/paypal/lib/paypalfunctions.lib.php");
require_once(DOL_DOCUMENT_ROOT."/compta/bank/class/account.class.php");
if (! empty($conf->global->PAYPAL_API_USER) && ! empty($conf->global->PAYPAL_API_PASSWORD)
&& ! empty($conf->global->PAYPAL_API_SIGNATURE))
{
$resArray=GetTransactionDetails(trim($object->num_paiement));
if (is_array($resArray))
{
$ack = strtoupper($resArray["ACK"]);
if($ack!="SUCCESS" && $ack!="SUCCESSWITHWARNING")
{
$_SESSION['reshash']=$resArray;
$errors = GetApiError();
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". error=".$errors[0]);
return -2;
}
else
{
$langs->load('paypal');
$acct=new Account($this->db);
$acct->fetch($object->fk_account);
$now=dol_now();
$amount = -$resArray["FEEAMT"]; // get paypal fee amount and convert to negative
$ret = $acct->addline($now, 2, $langs->trans('FeeAmount'), $amount, $object->num_paiement, '', $user,'Paypal','Paypal');
if ($ret < 0) return -1;
}
}
}
}
return 0;

View File

@ -420,7 +420,9 @@ function GetDetails( $token )
*/
function GetTransactionDetails($transactionID)
{
global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
//declaring of global variables
global $conf, $langs;
global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
$transactionID=urlencode($transactionID);
@ -550,6 +552,29 @@ function hash_call($methodName,$nvpStr)
global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT, $PROXY_USER, $PROXY_PASS;
global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
// TODO problem with this global if the request into triggers
$API_version="56";
if ($conf->global->PAYPAL_API_SANDBOX)
{
$API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
$API_Url = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
}
else
{
$API_Endpoint = "https://api-3t.paypal.com/nvp";
$API_Url = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=";
}
// Clean parameters
$PAYPAL_API_USER="";
if ($conf->global->PAYPAL_API_USER) $PAYPAL_API_USER=$conf->global->PAYPAL_API_USER;
$PAYPAL_API_PASSWORD="";
if ($conf->global->PAYPAL_API_PASSWORD) $PAYPAL_API_PASSWORD=$conf->global->PAYPAL_API_PASSWORD;
$PAYPAL_API_SIGNATURE="";
if ($conf->global->PAYPAL_API_SIGNATURE) $PAYPAL_API_SIGNATURE=$conf->global->PAYPAL_API_SIGNATURE;
$PAYPAL_API_SANDBOX="";
if ($conf->global->PAYPAL_API_SANDBOX) $PAYPAL_API_SANDBOX=$conf->global->PAYPAL_API_SANDBOX;
// TODO END
dol_syslog("Paypal API endpoint ".$API_Endpoint);
//setting the curl parameters.

View File

@ -93,7 +93,24 @@ if(isset($transactionID) && ! empty($transactionID)) {
$nvpStr.="&TRANSACTIONID=$transactionID";
}
// Call Paypal API
if (! empty($nvpStr))
{
$resArray=hash_call("TransactionSearch",$nvpStr);
//var_dump($resArray);
if (is_array($resArray))
{
$reqArray=$_SESSION['nvpReqArray'];
$ack = strtoupper($resArray["ACK"]);
if($ack!="SUCCESS" && $ack!="SUCCESSWITHWARNING")
{
$_SESSION['reshash']=$resArray;
$errors = GetApiError();
}
}
}
llxHeader();
@ -225,26 +242,6 @@ if (empty($conf->global->PAYPAL_API_USER) || empty($conf->global->PAYPAL_API_PAS
<?php
// Call Paypal API
if (! empty($nvpStr))
{
$resArray=hash_call("TransactionSearch",$nvpStr);
//var_dump($resArray);
if (is_array($resArray))
{
$reqArray=$_SESSION['nvpReqArray'];
$ack = strtoupper($resArray["ACK"]);
if($ack!="SUCCESS" && $ack!="SUCCESSWITHWARNING")
{
$_SESSION['reshash']=$resArray;
$errors = GetApiError();
}
}
}
// Search parameters
print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';