Works on paypal module
New: add trigger for fee treatment Todo: problem with global in the triggers
This commit is contained in:
parent
ee7e13e4a1
commit
cd08296965
@ -98,15 +98,41 @@ class InterfacePaypalWorkflow
|
|||||||
// Mettre ici le code a executer en reaction de l'action
|
// Mettre ici le code a executer en reaction de l'action
|
||||||
// Les donnees de l'action sont stockees dans $object
|
// Les donnees de l'action sont stockees dans $object
|
||||||
|
|
||||||
|
|
||||||
// Add Paypal fee
|
// 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);
|
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->rowid);
|
||||||
|
|
||||||
//var_dump($object);
|
require_once(DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php');
|
||||||
// use num_paiement and fk_account
|
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;
|
return 0;
|
||||||
|
|||||||
@ -420,6 +420,8 @@ function GetDetails( $token )
|
|||||||
*/
|
*/
|
||||||
function GetTransactionDetails($transactionID)
|
function GetTransactionDetails($transactionID)
|
||||||
{
|
{
|
||||||
|
//declaring of global variables
|
||||||
|
global $conf, $langs;
|
||||||
global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
|
global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
|
||||||
global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
|
global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
|
||||||
|
|
||||||
@ -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 $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;
|
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);
|
dol_syslog("Paypal API endpoint ".$API_Endpoint);
|
||||||
|
|
||||||
//setting the curl parameters.
|
//setting the curl parameters.
|
||||||
|
|||||||
@ -93,7 +93,24 @@ if(isset($transactionID) && ! empty($transactionID)) {
|
|||||||
$nvpStr.="&TRANSACTIONID=$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();
|
llxHeader();
|
||||||
|
|
||||||
@ -225,26 +242,6 @@ if (empty($conf->global->PAYPAL_API_USER) || empty($conf->global->PAYPAL_API_PAS
|
|||||||
|
|
||||||
<?php
|
<?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
|
// Search parameters
|
||||||
print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
|
print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
|
||||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user