diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index 007cbddbef6..49e0273f676 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -267,84 +267,82 @@ if (empty($doactionsthenredirect)) { } -// Validate the payment (for payment mode that need another step after the callback return for this). -if (isModEnabled('paypal')) { - if ($paymentmethod === 'paypal') { // We call this page only if payment is ok on payment system - if ($PAYPALTOKEN) { - // Get on url call - $onlinetoken = $PAYPALTOKEN; - $fulltag = $FULLTAG; - $payerID = $PAYPALPAYERID; - // Set by newpayment.php - $currencyCodeType = $_SESSION['currencyCodeType']; - $FinalPaymentAmt = $_SESSION["FinalPaymentAmt"]; - $paymentType = $_SESSION['PaymentType']; // Value can be 'Mark', 'Sole', 'Sale' for example - // From env - $ipaddress = $_SESSION['ipaddress']; +// Another step to validate the payment (for payment modes like Paypal that need another step after the callback return for this). +if (isModEnabled('paypal') && $paymentmethod === 'paypal') { // We call this page only if payment is ok on payment system + if ($PAYPALTOKEN) { + // Get on url call + $onlinetoken = $PAYPALTOKEN; + $fulltag = $FULLTAG; + $payerID = $PAYPALPAYERID; + // Set by newpayment.php + $currencyCodeType = $_SESSION['currencyCodeType']; + $FinalPaymentAmt = $_SESSION["FinalPaymentAmt"]; + $paymentType = $_SESSION['PaymentType']; // Value can be 'Mark', 'Sole', 'Sale' for example + // From env + $ipaddress = $_SESSION['ipaddress']; - dol_syslog("Call paymentok with token=".$onlinetoken." paymentType=".$paymentType." currencyCodeType=".$currencyCodeType." payerID=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt." fulltag=".$fulltag, LOG_DEBUG, 0, '_payment'); + dol_syslog("Call paymentok with token=".$onlinetoken." paymentType=".$paymentType." currencyCodeType=".$currencyCodeType." payerID=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt." fulltag=".$fulltag, LOG_DEBUG, 0, '_payment'); - // Validate record - if (!empty($paymentType)) { - dol_syslog("We call GetExpressCheckoutDetails", LOG_DEBUG, 0, '_payment'); - $resArray = getDetails($onlinetoken); - //var_dump($resarray); + // Validate record + if (!empty($paymentType)) { + dol_syslog("We call GetExpressCheckoutDetails", LOG_DEBUG, 0, '_payment'); + $resArray = getDetails($onlinetoken); + //var_dump($resarray); - $ack = strtoupper($resArray["ACK"]); - if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") { - // Nothing to do - dol_syslog("Call to GetExpressCheckoutDetails return ".$ack, LOG_DEBUG, 0, '_payment'); - } else { - dol_syslog("Call to GetExpressCheckoutDetails return error: ".json_encode($resArray), LOG_WARNING, 0, '_payment'); - } - - dol_syslog("We call DoExpressCheckoutPayment token=".$onlinetoken." paymentType=".$paymentType." currencyCodeType=".$currencyCodeType." payerID=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt." fulltag=".$fulltag, LOG_DEBUG, 0, '_payment'); - $resArray2 = confirmPayment($onlinetoken, $paymentType, $currencyCodeType, $payerID, $ipaddress, $FinalPaymentAmt, $fulltag); - //var_dump($resarray); - - $ack = strtoupper($resArray2["ACK"]); - if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") { - dol_syslog("Call to GetExpressCheckoutDetails return ".$ack, LOG_DEBUG, 0, '_payment'); - - $object->source = $source; - $object->ref = $ref; - $object->payerID = $payerID; - $object->fulltag = $fulltag; - $object->resArray = $resArray2; - - // resArray was built from a string like that - // TOKEN=EC%2d1NJ057703V9359028&TIMESTAMP=2010%2d11%2d01T11%3a40%3a13Z&CORRELATIONID=1efa8c6a36bd8&ACK=Success&VERSION=56&BUILD=1553277&TRANSACTIONID=9B994597K9921420R&TRANSACTIONTYPE=expresscheckout&PAYMENTTYPE=instant&ORDERTIME=2010%2d11%2d01T11%3a40%3a12Z&AMT=155%2e57&FEEAMT=5%2e54&TAXAMT=0%2e00&CURRENCYCODE=EUR&PAYMENTSTATUS=Completed&PENDINGREASON=None&REASONCODE=None - $PAYMENTSTATUS = urldecode($resArray2["PAYMENTSTATUS"]); // Should contains 'Completed' - $TRANSACTIONID = urldecode($resArray2["TRANSACTIONID"]); - $TAXAMT = urldecode($resArray2["TAXAMT"]); - $NOTE = urldecode($resArray2["NOTE"]); - - $ispaymentok = true; - } else { - dol_syslog("Call to DoExpressCheckoutPayment return error: ".json_encode($resArray2), LOG_WARNING, 0, '_payment'); - - //Display a user friendly Error on the page using any of the following error information returned by PayPal - $ErrorCode = urldecode($resArray2["L_ERRORCODE0"]); - $ErrorShortMsg = urldecode($resArray2["L_SHORTMESSAGE0"]); - $ErrorLongMsg = urldecode($resArray2["L_LONGMESSAGE0"]); - $ErrorSeverityCode = urldecode($resArray2["L_SEVERITYCODE0"]); - } + $ack = strtoupper($resArray["ACK"]); + if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") { + // Nothing to do + dol_syslog("Call to GetExpressCheckoutDetails return ".$ack, LOG_DEBUG, 0, '_payment'); } else { - $ErrorCode = "SESSIONEXPIRED"; - $ErrorLongMsg = "Session expired. Can't retrieve PaymentType. Payment has not been validated."; - $ErrorShortMsg = "Session expired"; + dol_syslog("Call to GetExpressCheckoutDetails return error: ".json_encode($resArray), LOG_WARNING, 0, '_payment'); + } - dol_syslog($ErrorLongMsg, LOG_WARNING, 0, '_payment'); - dol_print_error(null, 'Session expired'); + dol_syslog("We call DoExpressCheckoutPayment token=".$onlinetoken." paymentType=".$paymentType." currencyCodeType=".$currencyCodeType." payerID=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt." fulltag=".$fulltag, LOG_DEBUG, 0, '_payment'); + $resArray2 = confirmPayment($onlinetoken, $paymentType, $currencyCodeType, $payerID, $ipaddress, $FinalPaymentAmt, $fulltag); + //var_dump($resarray); + + $ack = strtoupper($resArray2["ACK"]); + if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") { + dol_syslog("Call to GetExpressCheckoutDetails return ".$ack, LOG_DEBUG, 0, '_payment'); + + $object->source = $source; + $object->ref = $ref; + $object->payerID = $payerID; + $object->fulltag = $fulltag; + $object->resArray = $resArray2; + + // resArray was built from a string like that + // TOKEN=EC%2d1NJ057703V9359028&TIMESTAMP=2010%2d11%2d01T11%3a40%3a13Z&CORRELATIONID=1efa8c6a36bd8&ACK=Success&VERSION=56&BUILD=1553277&TRANSACTIONID=9B994597K9921420R&TRANSACTIONTYPE=expresscheckout&PAYMENTTYPE=instant&ORDERTIME=2010%2d11%2d01T11%3a40%3a12Z&AMT=155%2e57&FEEAMT=5%2e54&TAXAMT=0%2e00&CURRENCYCODE=EUR&PAYMENTSTATUS=Completed&PENDINGREASON=None&REASONCODE=None + $PAYMENTSTATUS = urldecode($resArray2["PAYMENTSTATUS"]); // Should contains 'Completed' + $TRANSACTIONID = urldecode($resArray2["TRANSACTIONID"]); + $TAXAMT = urldecode($resArray2["TAXAMT"]); + $NOTE = urldecode($resArray2["NOTE"]); + + $ispaymentok = true; + } else { + dol_syslog("Call to DoExpressCheckoutPayment return error: ".json_encode($resArray2), LOG_WARNING, 0, '_payment'); + + //Display a user friendly Error on the page using any of the following error information returned by PayPal + $ErrorCode = urldecode($resArray2["L_ERRORCODE0"]); + $ErrorShortMsg = urldecode($resArray2["L_SHORTMESSAGE0"]); + $ErrorLongMsg = urldecode($resArray2["L_LONGMESSAGE0"]); + $ErrorSeverityCode = urldecode($resArray2["L_SEVERITYCODE0"]); } } else { - $ErrorCode = "PAYPALTOKENNOTDEFINED"; - $ErrorLongMsg = "The parameter PAYPALTOKEN was not defined. Payment has not been validated."; - $ErrorShortMsg = "Parameter PAYPALTOKEN not defined"; + $ErrorCode = "SESSIONEXPIRED"; + $ErrorLongMsg = "Session expired. Can't retrieve PaymentType. Payment has not been validated."; + $ErrorShortMsg = "Session expired"; dol_syslog($ErrorLongMsg, LOG_WARNING, 0, '_payment'); - dol_print_error(null, 'PAYPALTOKEN not defined'); + dol_print_error(null, 'Session expired'); } + } else { + $ErrorCode = "PAYPALTOKENNOTDEFINED"; + $ErrorLongMsg = "The parameter PAYPALTOKEN was not defined. Payment has not been validated."; + $ErrorShortMsg = "Parameter PAYPALTOKEN not defined"; + + dol_syslog($ErrorLongMsg, LOG_WARNING, 0, '_payment'); + dol_print_error(null, 'PAYPALTOKEN not defined'); } }