$_SESSION['paypal_ex_Hash'] = $nvpRES; //Must be true to let VM know we have a payment selected. $GLOBALS['payment_selected'] = true; } else { $count = 0; $errorMESSAGE = ""; while (isset($nvpRES["L_SHORTMESSAGE" . $count])) { $errorCODE = $nvpRES["L_ERRORCODE" . $count]; $shortMESSAGE = $nvpRES["L_SHORTMESSAGE" . $count]; $longMESSAGE = $nvpRES["L_LONGMESSAGE" . $count]; $errorMESSAGE .= "Error: " . $errorCODE . " Short Message: " . $shortMESSAGE . " Long Message: " . $longMESSAGE . "<br />"; $vmLogger->debug($errorMESSAGE); $count++; } if (isset($errorCODE)) { $errorText = NVP_ErrorToText($errorCODE, 'getexpress'); if ($errorText) { echo $errorText; $vmLogger->err($errorText); } else { if (PP_WPP_ERRORS == '0') { echo $nvp_common_08; $vmLogger->err($nvp_common_08); } elseif (PP_WPP_ERRORS == '1') { echo $errorMESSAGE; $vmLogger->err($errorMESSAGE); } } } } } else {
function process_payment($order_number, $order_total, &$d) { global $vendor_mail, $vendor_currency, $VM_LANG, $vmLogger; $_SESSION['CURL_ERROR'] = false; $_SESSION['CURL_ERROR_TXT'] = ""; $ps_vendor_id = $_SESSION["ps_vendor_id"]; $auth = $_SESSION['auth']; $ps_checkout = new ps_checkout(); require_once CLASSPATH . "payment/" . __CLASS__ . ".cfg.php"; require_once CLASSPATH . "payment/" . __CLASS__ . ".cfg2.php"; require_once CLASSPATH . "payment/nvp_include/languages/lang." . PP_WPP_LANGUAGE . ".php"; require_once CLASSPATH . "payment/nvp_include/languages/lang." . PP_WPP_LANGUAGE . ".admin.php"; require_once CLASSPATH . "payment/nvp_include/nvp_connection.php"; require_once CLASSPATH . "payment/nvp_include/nvp_functions.php"; require_once CLASSPATH . "payment/nvp_include/nvp_errors.php"; // Get user billing information from the database $dbbt = new ps_DB(); $qt = "SELECT * FROM #__{vm}_user_info WHERE user_id=" . $auth["user_id"] . " AND address_type='BT'"; $dbbt->query($qt); $dbbt->next_record(); $user_info_id = $dbbt->f("user_info_id"); if ($user_info_id != $d["ship_to_info_id"]) { // There is a different shipping address than the billing address, get the shipping information $dbst = new ps_DB(); $qt = "SELECT * FROM #__{vm}_user_info WHERE user_info_id='" . $d["ship_to_info_id"] . "' AND address_type='ST'"; $dbst->query($qt); $dbst->next_record(); } else { // Shipping address is the same as the billing address $dbst = $dbbt; } $ip_address = urlencode($_SERVER['REMOTE_ADDR']); $payment_action = PP_WPP_PAYMENT_ACTION; $ordernum = urlencode(substr($order_number, 0, 20)); $requireCVV = PP_WPP_CHECK_CARD_CODE; //initiate our error out variables. $count = 0; $errorOut = FALSE; $errorOut2 = FALSE; $displayMsg = ""; //Check to see if we are coming from paypal express checkout. //If not we do a directpaymentrequest, otherwise we try express checkout request. if (!isset($_SESSION['paypal_wpp_ex'])) { $nvpreq = NVP_DoDirectPaymentRequest($d, $dbbt, $dbst, $ip_address, $payment_action, $ordernum, $requireCVV); if ($nvpreq) { $nvpLS = $nvpreq; $nvpRES = hash_call("DoDirectPayment", $nvpreq); } else { $displayMsg .= $nvp_common_011; $d["error"] = $displayMsg; $vmLogger->err($displayMsg); return false; } } else { $nvpreq = NVP_DoExpressCheckout($d, $dbbt, $dbst, $ip_address, $payment_action, $ordernum); if ($nvpreq) { $nvpLS = $nvpreq; $nvpRES = hash_call("DoExpressCheckoutPayment", $nvpreq); } else { //We failed to gather the proper array, most likely do to with not having certain parameters properly filled. $errorOut = TRUE; $errorOut2 = TRUE; $displayMsg .= $nvp_common_010; } } // Parse out all the data\ if (isset($nvpRES)) { $ack = strtoupper($nvpRES["ACK"]); //check to see if it was succesful or not. If not error out, otherwise retrieve the transaction status from paypal. if ($ack != "SUCCESS" && $ack != "SUCCESSWITHWARNING") { $displayMsg .= $nvp_common_012 . " - " . $ack . " - "; $errorOut2 = TRUE; } else { if (isset($nvpRES['AVSCODE'])) { $avsCode = $nvpRES['AVSCODE']; } if (isset($nvpRES['CVV2MATCH'])) { $cvv2Code = $nvpRES['CVV2MATCH']; } $transactionID = $nvpRES['TRANSACTIONID']; //get the transaction details array that paypal returned. $nvpDETAILS = NVP_TransactionDetails($transactionID); if ($nvpDETAILS) { if (isset($nvpDETAILS['PAYMENTSTATUS'])) { $status = $nvpDETAILS['PAYMENTSTATUS']; if (strtolower($status) == "completed") { $_SESSION['ps_paypal_wpp_paystatus'] = PP_WPP_SUCCESS_STATUS; } elseif (strtolower($status) == "pending") { $_SESSION['ps_paypal_wpp_paystatus'] = PP_WPP_PENDING_STATUS; } elseif (strtolower($status) == "processed") { $_SESSION['ps_paypal_wpp_paystatus'] = PP_WPP_SUCCESS_STATUS; } elseif (strtolower($status) == "failed") { $_SESSION['ps_paypal_wpp_paystatus'] = PP_WPP_FAILED_STATUS; } else { $_SESSION['ps_paypal_wpp_paystatus'] = PP_WPP_FAILED_STATUS; } } else { $_SESSION['ps_paypal_wpp_paystatus'] = PP_WPP_FAILED_STATUS; } } else { $_SESSION['ps_paypal_wpp_paystatus'] = PP_WPP_FAILED_STATUS; } } //if paypal sent back an error check for it and add it to our error buffer. while (isset($nvpRES["L_SHORTMESSAGE" . $count])) { $errorCODE = $nvpRES["L_ERRORCODE" . $count]; $shortMESSAGE = $nvpRES["L_SHORTMESSAGE" . $count]; $longMESSAGE = $nvpRES["L_LONGMESSAGE" . $count]; if (isset($shortMESSAGE)) { $displayMsg .= 'SHORTMESSAGE =' . $shortMESSAGE . ' - ' . "\n"; $errorOut = TRUE; } if (isset($errorCODE)) { $displayMsg .= 'ERRORCODE =' . $errorCODE . ' - ' . "\n"; $errorOut = TRUE; } if (isset($longMESSAGE)) { $displayMsg .= 'LONGMESSAGE =' . $longMESSAGE . ' - ' . "\n"; $errorOut = TRUE; } if (isset($errorCODE)) { if (!isset($_SESSION['paypal_wpp_ex'])) { $errorText = NVP_ErrorToText($errorCODE, 'dodirect'); if ($errorText) { $d["error"] = $errorText; $vmLogger->err($errorText); return false; } } else { $errorText = NVP_ErrorToText($errorCODE, 'doexpress'); if ($errorText) { $d["error"] = $errorText; $vmLogger->err($errorText); return false; } } } $count++; } //Check the AVS code for faulty address issues. if (isset($avsCode)) { if ($avsCode == "P" || $avsCode == "W" || $avsCode == "X" || $avsCode == "Y" || $avsCode == "Z") { $displayMsg .= $nvp_order_processed; } else { $displayMsg .= $nvp_address_error; $errorOut = TRUE; } } //Check the CVV code to make sure paypal could properly use it. If not we error out. if ($requireCVV == '1') { if (isset($cvv2Code)) { if (strtoupper($cvv2Code) == "N") { $displayMsg .= $nvp_error_invalid_CVV; $errorOut = TRUE; } } } } //Check to see if we display errors or not. //If not set to 1 we only display errors in the debug file and not on screen if (PP_WPP_ERRORS == '1') { //If we have an error we add it to the log. We return false since we had an error. if ($errorOut || $errorOut2) { $d["error"] = $displayMsg; $d["order_payment_log"] = $displayMsg; // Catch Transaction ID if (isset($transactionID)) { $d["order_payment_trans_id"] = $transactionID; } $html = "<br/><span class=\"message\">" . $VM_LANG->_('PHPSHOP_PAYMENT_INTERNAL_ERROR') . " Paypal Pro Direct Payment Error - " . $displayMsg . "</span>"; if ($_SESSION['CURL_ERROR'] == true) { $d["error"] .= "-CURL ERROR: " . $_SESSION['CURL_ERROR_TXT']; $d["order_payment_log"] .= "-CURL ERROR: " . $_SESSION['CURL_ERROR_TXT']; $html .= "<br/><span class=\"message\">-CURL ERROR: " . $_SESSION['CURL_ERROR_TXT'] . "</span>"; } if (isset($nvpLS)) { $displayMsg .= $nvpLS; } $vmLogger->err($displayMsg); } if ($_SESSION['CURL_ERROR'] == true) { echo "<br />" . $displayMsg . "PAYPAL ERROR: " . $_SESSION['CURL_ERROR_TXT'] . "<br /><br />" . $response; $d["error"] = "PAYPAL ERROR: " . $_SESSION['CURL_ERROR_TXT']; } } else { if ($errorOut || $errorOut2) { if ($_SESSION['CURL_ERROR'] == true) { $displayMsg .= $_SESSION['CURL_ERROR_TXT']; } $vmLogger->debug($displayMsg); } } if (isset($transactionID)) { $d["order_payment_trans_id"] = $transactionID; } else { $vmLogger->err($nvp_error_no_transaction); return false; } //if we are down this far that means the order has completed succesfully. $d["order_payment_log"] = "Success: " . $order_number; // Catch Transaction ID $vmLogger->debug($d['order_payment_log']); return true; }