Files
ms1inscription-v5/paypal_prod/api/ExpressCheckout/DoExpressCheckout.php
2026-05-13 09:43:32 -04:00

124 lines
4.6 KiB
PHP
Raw Blame History

<?php
session_start();
ob_start();
require_once('../PPBootStrap.php');
require_once('../../../php/inc_start_time.php');
require_once('../../../php/inc_fonctions.php');
require_once('../../../php/inc_fx_panier.php');
$logger = new PPLoggingManager('DoExpressCheckout');
$token = urlencode($_REQUEST['token']);
$payerId = urlencode($_REQUEST['PayerID']);
$paymentAction = 'Sale';
// ------------------------------------------------------------------
// this section is optional if parameters required for DoExpressCheckout is retrieved from your database
$getExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType($token);
$getExpressCheckoutReq = new GetExpressCheckoutDetailsReq();
$getExpressCheckoutReq->GetExpressCheckoutDetailsRequest = $getExpressCheckoutDetailsRequest;
$paypalService = new PayPalAPIInterfaceServiceService();
try {
/* wrap API method calls on the service object with a try catch */
$getECResponse = $paypalService->GetExpressCheckoutDetails($getExpressCheckoutReq);
} catch (Exception $ex) {
include_once("error.php");
exit;
}
//----------------------------------------------------------------------------
$tabTotal = fxTotalPanier($_SESSION['no_panier'], $strLangue);
$orderTotal = new BasicAmountType();
$orderTotal->currencyID = 'CAD';
$orderTotal->value = $tabTotal['total'];
$paymentDetails= new PaymentDetailsType();
$paymentDetails->OrderTotal = $orderTotal;
/* if (isset($_REQUEST['notifyURL']))
{
$paymentDetails->NotifyURL = $_REQUEST['notifyURL'];
} */
$DoECRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType();
$DoECRequestDetails->PayerID = $payerId;
$DoECRequestDetails->Token = $token;
$DoECRequestDetails->PaymentAction = $paymentAction;
$DoECRequestDetails->PaymentDetails[0] = $paymentDetails;
$DoECRequest = new DoExpressCheckoutPaymentRequestType();
$DoECRequest->DoExpressCheckoutPaymentRequestDetails = $DoECRequestDetails;
$DoECReq = new DoExpressCheckoutPaymentReq();
$DoECReq->DoExpressCheckoutPaymentRequest = $DoECRequest;
try {
/* wrap API method calls on the service object with a try catch */
$DoECResponse = $paypalService->DoExpressCheckoutPayment($DoECReq);
} catch (Exception $ex) {
include_once("error.php");
exit;
}
if ($_SESSION['lang'] == 'fr')
$strPage = 'panier';
else
$strPage = 'cart';
if (isset($DoECResponse))
{
/* echo "<table>";
echo "<tr><td>Ack :</td><td><div id='Ack'>$DoECResponse->Ack</div> </td></tr>";
if (isset($DoECResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo))
{
echo "<tr><td>TransactionID :</td><td><div id='TransactionID'>". $DoECResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo[0]->TransactionID."</div> </td></tr>";
}
echo "</table>";
echo "<pre>";
print_r($DoECResponse);
echo "</pre>"; */
$strErrorLog = print_r($DoECResponse, true);
if (isset($DoECResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo)) {
// sauvegarder les infos dans la bdd
if ($_SESSION['lang'] == 'fr')
$strResultat = 'APPROUVEE - MERCI';
else
$strResultat = 'APPROVED - THANK YOU';
$sqlUpdate = "UPDATE inscriptions_panier_acheteurs SET receipt_text = '" . $strResultat . "', token = '" . $token . "', PayerID = '" . $payerId . "', TransactionID = '" . $DoECResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo[0]->TransactionID . "', pai_id = 1, ach_error_log = '" . $objDatabase->fxEscape($strErrorLog) . "' WHERE no_panie$objDatabase '" . $objDatabase->fxEscape($_SESSION['no_panier']) . "'$objDatabase $qryUpdate = $objDatabase->fxQuery($sqlUpdate);
header('Location: ' . $vDomaine . '/' . $strPage . '/resultat/' . $_SESSION['eve_label_url'] . '?ResponseFile=' . $DoECResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo[0]->TransactionID . '&p=success');
exit;
}
else {
// cr<63>er un num<75>ro de transaction
$strTransaction = uniqid('trx_');
$sqlUpdate = "UPDATE inscriptions_panier_acheteurs SET receipt_text = '', token = '', PayerID = '', TransactionID = '" . $strTransaction $objDatabase', ach_error_log = '" . $objDatabase->fxEscape($strEr$objDatabaseLog) . "' WHERE no_panier = '" . $objDatabase->fxEscape($$objDatabaseSSION['no_panier']) . "'";
$qryUpdate = $objDatabase->fxQuery($sqlUpdate);
fxcreer_log("ERREUR DE PAIMENT: no_panier = :" . $_SESSION['no_panier'] . "\n" . $strErrorLog);
header('Location: ' . $vDomaine . '/' . $strPage . '/resultat/' . $_SESSION['eve_label_url'] . '?p=error&ResponseFile=' . $strTransaction);
exit;
}
}
if ($strLangue == 'fr')
$_SESSION['msg'] = 'e118';
else
$_SESSION['msg'] = 'e518';
header('Location: ' . $vDomaine . '/' . $strPage . '/checkout/' . $_SESSION['eve_label_url'] );
exit;
//require_once '../Response.php';
?>