PHP Process Lending Tree Personal Loan Request Example

How to Process Lending Tree Personal Loan Lead Request with PHP

PHP Process Lending Tree Personal Loan Request ExampleFor one of my sites, I had the opportunity to write an interface to process the Lending Tree Personal Loan request. Processing the Lending Tree Personal Loan request is pretty straightforward. For my site, we receive the request, parse the XML, store the lead values in the database, respond to the request with an ACK, make a decision as to whether or not to extend an offer, then prepare and send either an offer or no offer response.

We store the lead information in the database so if the lead reviews our offer and follows the link (we provided in our offer) to complete the application we can retrieve their information from our database and prepopulate our application form. This results in fewer steps required for the lead to complete the application process. The link we provide in our offer includes query string values to identify the lead so we can obtain the lead information from our database. For this example, the function fnPutLeadInfo() has been included in the source below as a placeholder.

The steps are: Get the post, parse the XML, update our database, send the ACK, make a decision, send either the offer or non-offer response.

The logic to make a decision has been omitted. For our example, the variable $offer has been set to false. You would need to add logic to make a decision whether or not to extend an offer to the lead.

For portability I’ve created separate functions for parsing the XML, building the ACK, updating the database, building the offer, building the non-offer, and sending the offer XML.

<?php

	$xml = @file_get_contents("php://input");		// get post contents

	$leadInfo = fnParseXML($xml);				// parse post to array
	if ($leadInfo !== false)				// post parsed without error
	{
		if (fnPutLeadInfo($leadInfo))			// write lead to db 
		{
			$TrackingNumber = $leadInfo["TrackingNumber"];
			$ltack_xml = fnBuildACK($TrackingNumber);
			echo $ltack_xml;			// echo ltack
	
			$offer = false;				// make a decision here
			if ($offer)
			{
				$offer_xml = fnBuildOffer($leadInfo);
				fnSendXML($offer_xml);
			} else {
				$offer_xml = fnBuildNoOffer($leadInfo);
				fnSendXML($offer_xml);
			}
		}
	}

//-------------------------------------------------------------------------
// parse lead xml - return array of values
//-------------------------------------------------------------------------

function fnParseXML($xml)
{
	$leadInfo = array();

	if (simplexml_load_string($xml) !== false)
	{
		$xml_lead = new SimpleXMLElement($xml);

		$leadInfo["TrackingNumber"] = 			$xml_lead->TrackingNumber;
		$leadInfo["RequestAssignmentDate"] = 		$xml_lead->RequestAssignmentDate;
		$leadInfo["ContactAddress"] = 			$xml_lead->ConsumerContactInformation->ContactAddress;
		$leadInfo["ContactCity"] = 			$xml_lead->ConsumerContactInformation->ContactCity;
		$leadInfo["ContactState"] = 			$xml_lead->ConsumerContactInformation->ContactState;
		$leadInfo["ContactZip"] = 			$xml_lead->ConsumerContactInformation->ContactZip;
		$leadInfo["EmailAddress"] = 			$xml_lead->ConsumerContactInformation->EmailAddress;
		$leadInfo["ContactPhone"] = 			$xml_lead->ConsumerContactInformation->ContactPhone;
		$leadInfo["ContactPhoneExtension"] = 		$xml_lead->ConsumerContactInformation->ContactPhoneExtension;
		$leadInfo["ConsumerGeoPhoneAreaCode"] = 	$xml_lead->ConsumerContactInformation->ConsumerGeoPhoneAreaCode;
		$leadInfo["ConsumerGeoPhoneCountryCode"] = 	$xml_lead->ConsumerContactInformation->ConsumerGeoPhoneCountryCode;
		$leadInfo["FirstName"] = 			$xml_lead->ConsumerContactInformation->FirstName;
		$leadInfo["LastName"] = 			$xml_lead->ConsumerContactInformation->LastName;
		$leadInfo["TimeToContact"] = 			$xml_lead->ConsumerContactInformation->TimeToContact;
		$leadInfo["DateOfBirth"] = 			$xml_lead->ConsumerProfileInformation->DateOfBirth;
		$leadInfo["SSN"] = 				$xml_lead->ConsumerProfileInformation->SSN;
		$leadInfo["IsMilitary"] = 			$xml_lead->ConsumerProfileInformation->IsMilitary;
		$leadInfo["AssignedCreditValue"] = 		$xml_lead->ConsumerProfileInformation->Credit->AssignedCreditValue;
		$leadInfo["SelfCreditRating"] = 		$xml_lead->ConsumerProfileInformation->Credit->SelfCreditRating;
		$leadInfo["EmploymentStatus"] = 		$xml_lead->ConsumerProfileInformation->ProductProfileInformation->EmploymentStatus;
		$leadInfo["EmployerName"] = 			$xml_lead->ConsumerProfileInformation->ProductProfileInformation->EmployerName;
		$leadInfo["AnnualIncome"] = 			$xml_lead->ConsumerProfileInformation->ProductProfileInformation->AnnualIncome;
		$leadInfo["ResidenceType"] = 			$xml_lead->ConsumerProfileInformation->ProductProfileInformation->ResidenceType;
		$leadInfo["LoanRequestType"] = 			$xml_lead->LoanInformation->LoanRequestType;
		$leadInfo["LoanRequestPurpose"] = 		$xml_lead->LoanInformation->LoanRequestPurpose;
		$leadInfo["LoanAmount"] = 			$xml_lead->LoanInformation->LoanAmount;
		$leadInfo["Term"] = 				$xml_lead->LoanInformation->Term;
		$leadInfo["TrusteePartnerID"] = 		$xml_lead->PartnerProfileInformation->TrusteePartnerID;
		$leadInfo["NameOfPartner"] = 			$xml_lead->PartnerProfileInformation->NameOfPartner;
		$leadInfo["FilterName"] = 			$xml_lead->PartnerProfileInformation->FilterName;
		$leadInfo["FilterRoutingID"] = 			$xml_lead->PartnerProfileInformation->FilterRoutingID;
		$leadInfo["RoutingParam"] = 			$xml_lead->PartnerProfileInformation->RoutingParam;
		$leadInfo["xml"] = 				$xml;
	} else {
		return false;
	}
	return $leadInfo;
}

//-------------------------------------------------------------------------
// build the ACK response
//-------------------------------------------------------------------------

function fnBuildACK($TrackingNumber)
{
	$xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
		<LTACK>
			<ERRSTATUS>
				<QFNAME>$TrackingNumber</QFNAME>
				<ERRORNUM>0</ERRORNUM>
				<ERRORDESCRIPTION>SUCCESS</ERRORDESCRIPTION>
			</ERRSTATUS>
		</LTACK>";

	return $xml;
}

//-------------------------------------------------------------------------
// build the offer response
//-------------------------------------------------------------------------

function fnBuildOffer($leadInfo)
{

	$lendingtreeprofile_username = "Your LendingTree Username";	// protect this
	$lendingtreeprofile_password = "Your LendingTree Password";	// protect this
	$lendingtreeprofile_lenderid = "Your LendingTree Lender Id";	

	$LoanApplicationID = $leadInfo["TrackingNumber"];

	$xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
	<LenderResponse>
		<UserName>$lendingtreeprofile_username</UserName>
		<Password>$lendingtreeprofile_password</Password>
		<Mode>1</Mode>
		<LoanApplicationID>$LoanApplicationID</LoanApplicationID>
		<LenderID>$lendingtreeprofile_lenderid</LenderID>
		<TransactionType>3</TransactionType>
		<Offers>
			<Offer>
				<Offerid>1</Offerid>
				<Offertype>Fixed</Offertype>
				<LoanProgramName>5 Year Fixed</LoanProgramName>
				<LoanAmount>5000.00</LoanAmount>
				<InterestRate>15.000</InterestRate>
				<Term>36</Term>
				<TermConstant>1</TermConstant>
				<DiscountPoints>0</DiscountPoints>
				<MonthlyPayment>150.00</MonthlyPayment>
				<MonthlyPaymentOption>2</MonthlyPaymentOption>
				<APR>15.000</APR>
				<Annualfee>0</Annualfee>
				<OriginationFee>0.0</OriginationFee>
				<ExpirationDate>2016-07-31</ExpirationDate>
			</Offer>
		</Offers>
		<LenderContactInformation>
			<Name>YourCompanyName</Name>
			<Email>YourCompanyEmailAddress</Email>
			<WorkPhone>YourCompanyPhoneNumber</WorkPhone>
			<WorkphoneExtension></WorkphoneExtension>
			<Fax>YourCompanyFaxNumber</Fax>
		</LenderContactInformation>
		<PersonalizedURL>https://www.example.com/apply/?ID=LendingTree&TrackingNumber=$LoanApplicationID</PersonalizedURL>
		<OtherFees/>
		<OfferDescription>
			<![CDATA[Congratulations consumer! Based on your credit score, you have been approved for a loan through YourCompanyName. Below is the loan amount you qualify for, along with the interest rate.]]>
		</OfferDescription>
		<CustomizedMessageToBorrower>
			<![CDATA[You qualify for the following loan:
			5000.0 at 15.000%
			To complete your secure online loan request, copy and paste this URL into your browser address field:
			https://www.example.com/apply/?ID=LendingTree&TrackingNumber=$LoanApplicationID
			]]>
		</CustomizedMessageToBorrower>
		<CannedText>
			<![CDATA[Legal disclosure
			This does not constitute an actual commitment to lend or an offer to extend credit. Upon submitting a loan application, you may be asked to provide additional documents to enable us to verify your income, assets, and financial condition. Your interest rate and terms for which you are approved will be shown to you as part of the online application process. Most applicants will receive a variety of loan offerings to choose from, with varying loan amounts and interest rates. In addition to a loan origination fee, which is deducted from the loan proceeds, borrowers may be subject to fees for late payments and unsuccessful payment attempts. Refer to full borrower agreement for all terms, conditions and requirements.
			]]>
		</CannedText>
	</LenderResponse>";

	return $xml;

}

//-------------------------------------------------------------------------
// build the NO offer response
//-------------------------------------------------------------------------

function fnBuildNoOffer($leadInfo)
{
	$lendingtreeprofile_username = "Your LendingTree Username";	// protect this
	$lendingtreeprofile_password = "Your LendingTree Password";	// protect this
	$lendingtreeprofile_lenderid = "Your LendingTree Lender Id";	

	$LoanApplicationID = $leadInfo["TrackingNumber"];

	$xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
		<LenderResponse>
			<UserName>$lendingtreeprofile_username</UserName>
			<Password>$lendingtreeprofile_password</Password>
			<Mode>2</Mode> <!-- Indicating No Offers-->
			<LoanApplicationID>$LoanApplicationID</LoanApplicationID>
			<LenderID>$lendingtreeprofile_lenderid</LenderID>
			<TransactionType>3</TransactionType>
		<LenderResponse>";

	return $xml;
}

//-------------------------------------------------------------------------
// send xml to lending tree
//-------------------------------------------------------------------------

function fnSendXML($xml)
{

	global $ch; 
	$blnLive = false;

// set url
	if ($blnLive) 
	{
		$url = "https://lenderweb.lendingtree.com/offers/personalofferpost.aspx";	// Production
	} else {
		$url = "https://lenderweb.staging.lendingtree.com/offers/personalofferpost.aspx";	// Staging
	}

// initialize curl

	try
	{
		$vars = $xml;
		$ch = curl_init();

		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml')); 
		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
		curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); 
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);

		$curlRespose = curl_exec ($ch);

		if (curl_errno($ch) > 0) 
		{
			return false;
		}

		curl_close ($ch);

	} catch (Exception $e) {
//		 print_r($e);
		// There was an error with the connection
		return false;
	}

	return true;

}

//-------------------------------------------------------------------------
// write lead info to the database - returns true or false
//-------------------------------------------------------------------------

function fnPutLeadInfo($leadInfo)
{
	try
	{
		// update the database
	} catch (Exception $e) {
		//print_r($e);
		// There was an error with the connection
		return false;
	}
	return true;
}

?>

Copy Code

References

PHP file_get_contents
PHP arrays
PHP echo
PHP simplexml_load_string
PHP SimpleXMLElement
PHP Curl

One Reply to “PHP Process Lending Tree Personal Loan Request Example”

Leave a Reply

I appreciate and welcome your comments. Please keep in mind that comments are moderated according to my comment policy.
Your email address will not be published. Required fields are marked *