*
 * @package			Angell_EYE_PayPal_Adaptive_Class_Library
 * @author			Andrew K. Angell
 * @copyright		Copyright © 2016 Angell EYE, LLC
 * @link			http://www.angelleye.com
 * @since			Version 3.0.0
 * @updated			01.29.2016
 * @filesource
 */
require_once('Paypal_pro.php');
class PayPal_Adaptive extends PayPal_Pro {
    var $DeveloperAccountEmail = '';
    var $XMLNamespace = '';
    var $ApplicationID = '';
    var $DeviceID = '';
    var $IPAddress = '';
    var $DetailLevel = '';
    var $ErrorLanguage = '';
    /**
     * Constructor
     *
     * @access	public
     * @param	array	config preferences
     * @return	void
     */
    function __construct($DataArray) {
        parent::__construct($DataArray);
        $this->XMLNamespace = 'http://svcs.paypal.com/types/ap';
        $this->DeviceID = isset($DataArray['DeviceID']) ? $DataArray['DeviceID'] : '';
        $this->IPAddress = isset($DataArray['IPAddress']) ? $DataArray['IPAddress'] : $_SERVER['REMOTE_ADDR'];
        $this->DetailLevel = isset($DataArray['DetailLevel']) ? $DataArray['DetailLevel'] : 'ReturnAll';
        $this->ErrorLanguage = isset($DataArray['ErrorLanguage']) ? $DataArray['ErrorLanguage'] : 'en_US';
        $this->APISubject = isset($DataArray['APISubject']) ? $DataArray['APISubject'] : '';
        $this->DeveloperAccountEmail = isset($DataArray['DeveloperAccountEmail']) ? $DataArray['DeveloperAccountEmail'] : '';
        if ($this->Sandbox) {
            // Sandbox Credentials
            $this->ApplicationID = isset($DataArray['ApplicationID']) ? $DataArray['ApplicationID'] : '';
            $this->APIUsername = isset($DataArray['APIUsername']) && $DataArray['APIUsername'] != '' ? $DataArray['APIUsername'] : '';
            $this->APIPassword = isset($DataArray['APIPassword']) && $DataArray['APIPassword'] != '' ? $DataArray['APIPassword'] : '';
            $this->APISignature = isset($DataArray['APISignature']) && $DataArray['APISignature'] != '' ? $DataArray['APISignature'] : '';
            $this->EndPointURL = isset($DataArray['EndPointURL']) && $DataArray['EndPointURL'] != '' ? $DataArray['EndPointURL'] : 'https://svcs.sandbox.paypal.com/';
        } elseif ($this->BetaSandbox) {
            // Beta Sandbox Credentials
            $this->ApplicationID = isset($DataArray['ApplicationID']) ? $DataArray['ApplicationID'] : '';
            $this->APIUsername = isset($DataArray['APIUsername']) && $DataArray['APIUsername'] != '' ? $DataArray['APIUsername'] : '';
            $this->APIPassword = isset($DataArray['APIPassword']) && $DataArray['APIPassword'] != '' ? $DataArray['APIPassword'] : '';
            $this->APISignature = isset($DataArray['APISignature']) && $DataArray['APISignature'] != '' ? $DataArray['APISignature'] : '';
            $this->EndPointURL = isset($DataArray['EndPointURL']) && $DataArray['EndPointURL'] != '' ? $DataArray['EndPointURL'] : 'https://svcs.beta-sandbox.paypal.com/';
        } else {
            // Live Credentials
            $this->ApplicationID = isset($DataArray['ApplicationID']) ? $DataArray['ApplicationID'] : 'YOUR_APP_ID';
            $this->APIUsername = isset($DataArray['APIUsername']) && $DataArray['APIUsername'] != '' ? $DataArray['APIUsername'] : '';
            $this->APIPassword = isset($DataArray['APIPassword']) && $DataArray['APIPassword'] != '' ? $DataArray['APIPassword'] : '';
            $this->APISignature = isset($DataArray['APISignature']) && $DataArray['APISignature'] != '' ? $DataArray['APISignature'] : '';
            $this->EndPointURL = isset($DataArray['EndPointURL']) && $DataArray['EndPointURL'] != '' ? $DataArray['EndPointURL'] : 'https://svcs.paypal.com/';
        }
    }
    /**
     * Build all HTTP headers required for the API call.
     *
     * @access	public
     * @param	boolean	$PrintHeaders - Whether to print headers on screen or not (true/false)
     * @return	array $headers
     */
    function BuildHeaders($PrintHeaders) {
        $headers = array(
            'X-PAYPAL-SECURITY-USERID: ' . $this->APIUsername,
            'X-PAYPAL-SECURITY-PASSWORD: ' . $this->APIPassword,
            'X-PAYPAL-SECURITY-SIGNATURE: ' . $this->APISignature,
            'X-PAYPAL-SECURITY-SUBJECT: ' . $this->APISubject,
            'X-PAYPAL-SECURITY-VERSION: ' . $this->APIVersion,
            'X-PAYPAL-REQUEST-DATA-FORMAT: XML',
            'X-PAYPAL-RESPONSE-DATA-FORMAT: XML',
            'X-PAYPAL-APPLICATION-ID: ' . $this->ApplicationID,
            'X-PAYPAL-DEVICE-ID: ' . $this->DeviceID,
            'X-PAYPAL-DEVICE-IPADDRESS: ' . $this->IPAddress
        );
        if ($this->Sandbox) {
            array_push($headers, 'X-PAYPAL-SANDBOX-EMAIL-ADDRESS: ' . $this->DeveloperAccountEmail);
        }
        if ($PrintHeaders) {
            echo '
';
            print_r($headers);
        }
        return $headers;
    }
    /**
     * Send the API request to PayPal using CURL
     *
     * @access	public
     * @param	string $Request
     * @param   string $APIName
     * @param   string $APIOperation
     * @return	string
     */
    function CURLRequest($Request = "", $APIName = "", $APIOperation = "") {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_VERBOSE, 1);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_TIMEOUT, 30);
        curl_setopt($curl, CURLOPT_URL, $this->EndPointURL . $APIName . '/' . $APIOperation);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $Request);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $this->BuildHeaders(false));
        if ($this->APIMode == 'Certificate') {
            curl_setopt($curl, CURLOPT_SSLCERT, $this->PathToCertKeyPEM);
        }
        $Response = curl_exec($curl);
        curl_close($curl);
        return $Response;
    }
    /**
     * Get all errors returned from PayPal
     *
     * @access	public
     * @param	string	XML response from PayPal
     * @return	array
     */
    function GetErrors($XML) {
        $DOM = new DOMDocument();
        $DOM->loadXML($XML);
        $Errors = $DOM->getElementsByTagName('error')->length > 0 ? $DOM->getElementsByTagName('error') : array();
        $ErrorsArray = array();
        foreach ($Errors as $Error) {
            $Receiver = $Error->getElementsByTagName('receiver')->length > 0 ? $Error->getElementsByTagName('receiver')->item(0)->nodeValue : '';
            $Category = $Error->getElementsByTagName('category')->length > 0 ? $Error->getElementsByTagName('category')->item(0)->nodeValue : '';
            $Domain = $Error->getElementsByTagName('domain')->length > 0 ? $Error->getElementsByTagName('domain')->item(0)->nodeValue : '';
            $ErrorID = $Error->getElementsByTagName('errorId')->length > 0 ? $Error->getElementsByTagName('errorId')->item(0)->nodeValue : '';
            $ExceptionID = $Error->getElementsByTagName('exceptionId')->length > 0 ? $Error->getElementsByTagName('exceptionId')->item(0)->nodeValue : '';
            $Message = $Error->getElementsByTagName('message')->length > 0 ? $Error->getElementsByTagName('message')->item(0)->nodeValue : '';
            $Parameter = $Error->getElementsByTagName('parameter')->length > 0 ? $Error->getElementsByTagName('parameter')->item(0)->nodeValue : '';
            $Severity = $Error->getElementsByTagName('severity')->length > 0 ? $Error->getElementsByTagName('severity')->item(0)->nodeValue : '';
            $Subdomain = $Error->getElementsByTagName('subdomain')->length > 0 ? $Error->getElementsByTagName('subdomain')->item(0)->nodeValue : '';
            $CurrentError = array(
                'Receiver' => $Receiver,
                'Category' => $Category,
                'Domain' => $Domain,
                'ErrorID' => $ErrorID,
                'ExceptionID' => $ExceptionID,
                'Message' => $Message,
                'Parameter' => $Parameter,
                'Severity' => $Severity,
                'Subdomain' => $Subdomain
            );
            array_push($ErrorsArray, $CurrentError);
        }
        return $ErrorsArray;
    }
    /**
     * Get the request envelope from the XML string
     *
     * @access	public
     * @return	string XML request envelope
     */
    function GetXMLRequestEnvelope() {
        $XML = '';
        $XML .= '' . $this->DetailLevel . '';
        $XML .= '' . $this->ErrorLanguage . '';
        $XML .= '';
        return $XML;
    }
    /**
     * Log result to a location on the disk.
     *
     * @access	public
     * @param	string	$filename 
     * @param   string  $string_data
     * @return	array
     */
    function Logger($filename, $string_data) {
        $timestamp = strtotime('now');
        $timestamp = date('mdY_giA_', $timestamp);
        $file = $_SERVER['DOCUMENT_ROOT'] . "/paypal/logs/" . $timestamp . $filename . ".xml";
        $fh = fopen($file, 'w');
        fwrite($fh, $string_data);
        fclose($fh);
    }
    /**
     * Submit Pay() API request to PayPal
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function Pay($DataArray) {
        // PayRequest Fields
        $PayRequestFields = isset($DataArray['PayRequestFields']) ? $DataArray['PayRequestFields'] : array();
        $ActionType = isset($PayRequestFields['ActionType']) ? $PayRequestFields['ActionType'] : '';
        $CancelURL = isset($PayRequestFields['CancelURL']) ? $PayRequestFields['CancelURL'] : '';
        $CurrencyCode = isset($PayRequestFields['CurrencyCode']) ? $PayRequestFields['CurrencyCode'] : '';
        $FeesPayer = isset($PayRequestFields['FeesPayer']) ? $PayRequestFields['FeesPayer'] : '';
        $IPNNotificationURL = isset($PayRequestFields['IPNNotificationURL']) ? $PayRequestFields['IPNNotificationURL'] : '';
        $Memo = isset($PayRequestFields['Memo']) ? $PayRequestFields['Memo'] : '';
        $Pin = isset($PayRequestFields['Pin']) ? $PayRequestFields['Pin'] : '';
        $PreapprovalKey = isset($PayRequestFields['PreapprovalKey']) ? $PayRequestFields['PreapprovalKey'] : '';
        $ReturnURL = isset($PayRequestFields['ReturnURL']) ? $PayRequestFields['ReturnURL'] : '';
        $ReverseAllParallelPaymentsOnError = isset($PayRequestFields['ReverseAllParallelPaymentsOnError']) ? $PayRequestFields['ReverseAllParallelPaymentsOnError'] : '';
        $SenderEmail = isset($PayRequestFields['SenderEmail']) ? $PayRequestFields['SenderEmail'] : '';
        $TrackingID = isset($PayRequestFields['TrackingID']) ? $PayRequestFields['TrackingID'] : '';
        // ClientDetails Fields
        $ClientDetailsFields = isset($DataArray['ClientDetailsFields']) ? $DataArray['ClientDetailsFields'] : array();
        $CustomerID = isset($ClientDetailsFields['CustomerID']) ? $ClientDetailsFields['CustomerID'] : '';
        $CustomerType = isset($ClientDetailsFields['CustomerType']) ? $ClientDetailsFields['CustomerType'] : '';
        $GeoLocation = isset($ClientDetailsFields['GeoLocation']) ? $ClientDetailsFields['GeoLocation'] : '';
        $Model = isset($ClientDetailsFields['Model']) ? $ClientDetailsFields['Model'] : '';
        $PartnerName = isset($ClientDetailsFields['PartnerName']) ? $ClientDetailsFields['PartnerName'] : '';
        // FundingConstraint Fields
        $FundingTypes = isset($DataArray['FundingTypes']) ? $DataArray['FundingTypes'] : array();
        // Receivers Fields
        $Receivers = isset($DataArray['Receivers']) ? $DataArray['Receivers'] : array();
        $Amount = isset($Receivers['Amount']) ? $Receivers['Amount'] : '';
        $Email = isset($Receivers['Email']) ? $Receivers['Email'] : '';
        $InvoiceID = isset($Receivers['InvoiceID']) ? $Receivers['InvoiceID'] : '';
        $PaymentType = isset($Receivers['PaymentType']) ? $Receivers['PaymentType'] : '';
        $PaymentSubType = isset($Receivers['PaymentSubType']) ? $Receivers['PaymentSubType'] : '';
        $Phone = isset($Receivers['Phone']) ? $Receivers['Phone'] : '';
        $Primary = isset($Receivers['Primary']) ? strtolower($Receivers['Primary']) : '';
        // SenderIdentifier Fields
        $SenderIdentifierFields = isset($DataArray['SenderIdentifierFields']) ? $DataArray['SenderIdentifierFields'] : array();
        $UseCredentials = isset($SenderIdentifierFields['UseCredentials']) ? $SenderIdentifierFields['UseCredentials'] : '';
        // AccountIdentifierFields Fields
        $AccountIdentifierFields = isset($DataArray['AccountIdentifierFields']) ? $DataArray['AccountIdentifierFields'] : array();
        $AccountEmail = isset($AccountIdentifierFields['Email']) ? $AccountIdentifierFields['Email'] : '';
        $AccountPhone = isset($AccountIdentifierFields['Phone']) ? $AccountIdentifierFields['Phone'] : '';
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= $ActionType != '' ? '' . $ActionType . '' : '';
        $XMLRequest .= $CancelURL != '' ? '' . $CancelURL . '' : '';
        if (count($ClientDetailsFields) > 0) {
            $XMLRequest .= '';
            $XMLRequest .= $this->ApplicationID != '' ? '' . $this->ApplicationID . '' : '';
            $XMLRequest .= $CustomerID != '' ? '' . $CustomerID . '' : '';
            $XMLRequest .= $CustomerType != '' ? '' . $CustomerType . '' : '';
            $XMLRequest .= $this->DeviceID != '' ? '' . $this->DeviceID . '' : '';
            $XMLRequest .= $GeoLocation != '' ? '' . $GeoLocation . '' : '';
            $XMLRequest .= $this->IPAddress != '' ? '' . $this->IPAddress . '' : '';
            $XMLRequest .= $Model != '' ? '' . $Model . '' : '';
            $XMLRequest .= $PartnerName != '' ? '' . $PartnerName . '' : '';
            $XMLRequest .= '';
        }
        $XMLRequest .= $CurrencyCode != '' ? '' . $CurrencyCode . '' : '';
        $XMLRequest .= $FeesPayer != '' ? '' . $FeesPayer . '' : '';
        if (count($FundingTypes) > 0) {
            $XMLRequest .= '';
            $XMLRequest .= '';
            foreach ($FundingTypes as $FundingType) {
                $XMLRequest .= '';
                $XMLRequest .= '' . $FundingType . '';
                $XMLRequest .= '';
            }
            $XMLRequest .= '';
            $XMLRequest .= '';
        }
        $XMLRequest .= $IPNNotificationURL != '' ? '' . $IPNNotificationURL . '' : '';
        $XMLRequest .= $Memo != '' ? '' . $Memo . '' : '';
        $XMLRequest .= $Pin != '' ? '' . $Pin . '' : '';
        $XMLRequest .= $PreapprovalKey != '' ? '' . $PreapprovalKey . '' : '';
        $XMLRequest .= '';
        $IsDigitalGoods = FALSE;
        foreach ($Receivers as $Receiver) {
            $IsDigitalGoods = strtoupper($Receiver['PaymentType']) == 'DIGITALGOODS' ? TRUE : FALSE;
            $XMLRequest .= '';
            $XMLRequest .= $Receiver['Amount'] != '' ? '' . $Receiver['Amount'] . '' : '';
            $XMLRequest .= $Receiver['Email'] != '' ? '' . $Receiver['Email'] . '' : '';
            $XMLRequest .= $Receiver['InvoiceID'] != '' ? '' . $Receiver['InvoiceID'] . '' : '';
            $XMLRequest .= $Receiver['PaymentType'] != '' ? '' . $Receiver['PaymentType'] . '' : '';
            $XMLRequest .= $Receiver['PaymentSubType'] != '' ? '' . $Receiver['PaymentSubType'] . '' : '';
            if ($Receiver['Phone']['CountryCode'] != '') {
                $XMLRequest .= '';
                $XMLRequest .= $Receiver['Phone']['CountryCode'] != '' ? '' . $Receiver['Phone']['CountryCode'] . '' : '';
                $XMLRequest .= $Receiver['Phone']['PhoneNumber'] != '' ? '' . $Receiver['Phone']['PhoneNumber'] . '' : '';
                $XMLRequest .= $Receiver['Phone']['Extension'] != '' ? '' . $Receiver['Phone']['Extension'] . '' : '';
                $XMLRequest .= '';
            }
            $XMLRequest .= $Receiver['Primary'] != '' ? '' . strtolower($Receiver['Primary']) . '' : '';
            $XMLRequest .= '';
        }
        $XMLRequest .= '';
        if (count($SenderIdentifierFields) > 0) {
            $XMLRequest .= '';
            $XMLRequest .= '' . $SenderIdentifierFields['UseCredentials'] . '';
            $XMLRequest .= '';
        }
        if (count($AccountIdentifierFields) > 0) {
            $XMLRequest .= '';
            $XMLRequest .= $AccountEmail != '' ? '' . $AccountEmail . '' : '';
            if ($AccountPhone != '') {
                $XMLRequest .= '';
                $XMLRequest .= $AccountPhone['CountryCode'] != '' ? '' . $AccountPhone['CountryCode'] . '' : '';
                $XMLRequest .= $AccountPhone['PhoneNumber'] != '' ? '' . $AccountPhone['PhoneNumber'] . '' : '';
                $XMLRequest .= $AccountPhone['Extension'] != '' ? '' . $AccountPhone['Extension'] . '' : '';
                $XMLRequest .= '';
            }
            $XMLRequest .= '';
        }
        $XMLRequest .= $ReturnURL != '' ? '' . $ReturnURL . '' : '';
        $XMLRequest .= $ReverseAllParallelPaymentsOnError != '' ? '' . $ReverseAllParallelPaymentsOnError . '' : '';
        $XMLRequest .= $SenderEmail != '' ? '' . $SenderEmail . '' : '';
        $XMLRequest .= $TrackingID != '' ? '' . $TrackingID . '' : '';
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'AdaptivePayments', 'Pay');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $PayKey = $DOM->getElementsByTagName('payKey')->length > 0 ? $DOM->getElementsByTagName('payKey')->item(0)->nodeValue : '';
        $PaymentExecStatus = $DOM->getElementsByTagName('paymentExecStatus')->length > 0 ? $DOM->getElementsByTagName('paymentExecStatus')->item(0)->nodeValue : '';
        if ($this->Sandbox) {
            if ($IsDigitalGoods) {
                $RedirectURL = 'https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay?paykey=' . $PayKey;
            } else {
                $RedirectURL = 'https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=' . $PayKey;
            }
        } elseif ($this->BetaSandbox) {
            if ($IsDigitalGoods) {
                $RedirectURL = 'https://www.beta-sandbox.paypal.com/webapps/adaptivepayment/flow/pay?paykey=' . $PayKey;
            } else {
                $RedirectURL = 'https://www.beta-sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=' . $PayKey;
            }
        } else {
            if ($IsDigitalGoods) {
                $RedirectURL = 'https://www.paypal.com/webapps/adaptivepayment/flow/pay?paykey=' . $PayKey;
            } else {
                $RedirectURL = 'https://www.paypal.com/webscr?cmd=_ap-payment&paykey=' . $PayKey;
            }
        }
        $ResponseDataArray = array( 
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'PayKey' => $PayKey,
            'PaymentExecStatus' => $PaymentExecStatus,
            'RedirectURL' => $PayKey != '' ? $RedirectURL : '',
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit PayWithOptions() API request to PayPal
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function PayWithOptions($DataArray) {
        // PayRequest Fields
        $PayRequestFields = isset($DataArray['PayRequestFields']) ? $DataArray['PayRequestFields'] : array();
        $ActionType = 'CREATE';
        $CancelURL = isset($PayRequestFields['CancelURL']) ? $PayRequestFields['CancelURL'] : '';
        $CurrencyCode = isset($PayRequestFields['CurrencyCode']) ? $PayRequestFields['CurrencyCode'] : '';
        $FeesPayer = isset($PayRequestFields['FeesPayer']) ? $PayRequestFields['FeesPayer'] : '';
        $IPNNotificationURL = isset($PayRequestFields['IPNNotificationURL']) ? $PayRequestFields['IPNNotificationURL'] : '';
        $Memo = isset($PayRequestFields['Memo']) ? $PayRequestFields['Memo'] : '';
        $Pin = isset($PayRequestFields['Pin']) ? $PayRequestFields['Pin'] : '';
        $PreapprovalKey = isset($PayRequestFields['PreapprovalKey']) ? $PayRequestFields['PreapprovalKey'] : '';
        $ReturnURL = isset($PayRequestFields['ReturnURL']) ? $PayRequestFields['ReturnURL'] : '';
        $ReverseAllParallelPaymentsOnError = isset($PayRequestFields['ReverseAllParallelPaymentsOnError']) ? $PayRequestFields['ReverseAllParallelPaymentsOnError'] : '';
        $SenderEmail = isset($PayRequestFields['SenderEmail']) ? $PayRequestFields['SenderEmail'] : '';
        $TrackingID = isset($PayRequestFields['TrackingID']) ? $PayRequestFields['TrackingID'] : '';
        // ClientDetails Fields
        $ClientDetailsFields = isset($DataArray['ClientDetailsFields']) ? $DataArray['ClientDetailsFields'] : array();
        $CustomerID = isset($ClientDetailsFields['CustomerID']) ? $ClientDetailsFields['CustomerID'] : '';
        $CustomerType = isset($ClientDetailsFields['CustomerType']) ? $ClientDetailsFields['CustomerType'] : '';
        $GeoLocation = isset($ClientDetailsFields['GeoLocation']) ? $ClientDetailsFields['GeoLocation'] : '';
        $Model = isset($ClientDetailsFields['Model']) ? $ClientDetailsFields['Model'] : '';
        $PartnerName = isset($ClientDetailsFields['PartnerName']) ? $ClientDetailsFields['PartnerName'] : '';
        // FundingConstraint Fields
        $FundingTypes = isset($DataArray['FundingTypes']) ? $DataArray['FundingTypes'] : array();
        // Receivers Fields
        $Receivers = isset($DataArray['Receivers']) ? $DataArray['Receivers'] : array();
        $Amount = isset($Receivers['Amount']) ? $Receivers['Amount'] : '';
        $Email = isset($Receivers['Email']) ? $Receivers['Email'] : '';
        $InvoiceID = isset($Receivers['InvoiceID']) ? $Receivers['InvoiceID'] : '';
        $PaymentType = isset($Receivers['PaymentType']) ? $Receivers['PaymentType'] : '';
        $PaymentSubType = isset($Receivers['PaymentSubType']) ? $Receivers['PaymentSubType'] : '';
        $Phone = isset($Receivers['Phone']) ? $Receivers['Phone'] : '';
        $Primary = isset($Receivers['Primary']) ? strtolower($Receivers['Primary']) : '';
        // SenderIdentifier Fields
        $SenderIdentifierFields = isset($DataArray['SenderIdentifierFields']) ? $DataArray['SenderIdentifierFields'] : array();
        $UseCredentials = isset($SenderIdentifierFields['UseCredentials']) ? $SenderIdentifierFields['UseCredentials'] : '';
        // AccountIdentifierFields Fields
        $AccountIdentifierFields = isset($DataArray['AccountIdentifierFields']) ? $DataArray['AccountIdentifierFields'] : array();
        $AccountEmail = isset($AccountIdentifierFields['Email']) ? $AccountIdentifierFields['Email'] : '';
        $AccountPhone = isset($AccountIdentifierFields['Phone']) ? $AccountIdentifierFields['Phone'] : '';
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= $ActionType != '' ? '' . $ActionType . '' : '';
        $XMLRequest .= $CancelURL != '' ? '' . $CancelURL . '' : '';
        if (count($ClientDetailsFields) > 0) {
            $XMLRequest .= '';
            $XMLRequest .= $this->ApplicationID != '' ? '' . $this->ApplicationID . '' : '';
            $XMLRequest .= $CustomerID != '' ? '' . $CustomerID . '' : '';
            $XMLRequest .= $CustomerType != '' ? '' . $CustomerType . '' : '';
            $XMLRequest .= $this->DeviceID != '' ? '' . $this->DeviceID . '' : '';
            $XMLRequest .= $GeoLocation != '' ? '' . $GeoLocation . '' : '';
            $XMLRequest .= $this->IPAddress != '' ? '' . $this->IPAddress . '' : '';
            $XMLRequest .= $Model != '' ? '' . $Model . '' : '';
            $XMLRequest .= $PartnerName != '' ? '' . $PartnerName . '' : '';
            $XMLRequest .= '';
        }
        $XMLRequest .= $CurrencyCode != '' ? '' . $CurrencyCode . '' : '';
        $XMLRequest .= $FeesPayer != '' ? '' . $FeesPayer . '' : '';
        if (count($FundingTypes) > 0) {
            $XMLRequest .= '';
            $XMLRequest .= '';
            foreach ($FundingTypes as $FundingType) {
                $XMLRequest .= '';
                $XMLRequest .= '' . $FundingType . '';
                $XMLRequest .= '';
            }
            $XMLRequest .= '';
            $XMLRequest .= '';
        }
        $XMLRequest .= $IPNNotificationURL != '' ? '' . $IPNNotificationURL . '' : '';
        $XMLRequest .= $Memo != '' ? '' . $Memo . '' : '';
        $XMLRequest .= $Pin != '' ? '' . $Pin . '' : '';
        $XMLRequest .= $PreapprovalKey != '' ? '' . $PreapprovalKey . '' : '';
        $XMLRequest .= '';
        $IsDigitalGoods = FALSE;
        foreach ($Receivers as $Receiver) {
            $IsDigitalGoods = strtoupper($Receiver['PaymentType']) == 'DIGITALGOODS' ? TRUE : FALSE;
            $XMLRequest .= '';
            $XMLRequest .= $Receiver['Amount'] != '' ? '' . $Receiver['Amount'] . '' : '';
            $XMLRequest .= $Receiver['Email'] != '' ? '' . $Receiver['Email'] . '' : '';
            $XMLRequest .= $Receiver['InvoiceID'] != '' ? '' . $Receiver['InvoiceID'] . '' : '';
            $XMLRequest .= $Receiver['PaymentType'] != '' ? '' . $Receiver['PaymentType'] . '' : '';
            $XMLRequest .= $Receiver['PaymentSubType'] != '' ? '' . $Receiver['PaymentSubType'] . '' : '';
            if ($Receiver['Phone']['CountryCode'] != '') {
                $XMLRequest .= '';
                $XMLRequest .= $Receiver['Phone']['CountryCode'] != '' ? '' . $Receiver['Phone']['CountryCode'] . '' : '';
                $XMLRequest .= $Receiver['Phone']['PhoneNumber'] != '' ? '' . $Receiver['Phone']['PhoneNumber'] . '' : '';
                $XMLRequest .= $Receiver['Phone']['Extension'] != '' ? '' . $Receiver['Phone']['Extension'] . '' : '';
                $XMLRequest .= '';
            }
            $XMLRequest .= $Receiver['Primary'] != '' ? '' . strtolower($Receiver['Primary']) . '' : '';
            $XMLRequest .= '';
        }
        $XMLRequest .= '';
        if (count($SenderIdentifierFields) > 0) {
            $XMLRequest .= '';
            $XMLRequest .= '' . $SenderIdentifierFields['UseCredentials'] . '';
            $XMLRequest .= '';
        }
        if (count($AccountIdentifierFields) > 0) {
            $XMLRequest .= '';
            $XMLRequest .= $AccountEmail != '' ? '' . $AccountEmail . '' : '';
            if ($AccountPhone != '') {
                $XMLRequest .= '';
                $XMLRequest .= $AccountPhone['CountryCode'] != '' ? '' . $AccountPhone['CountryCode'] . '' : '';
                $XMLRequest .= $AccountPhone['PhoneNumber'] != '' ? '' . $AccountPhone['PhoneNumber'] . '' : '';
                $XMLRequest .= $AccountPhone['Extension'] != '' ? '' . $AccountPhone['Extension'] . '' : '';
                $XMLRequest .= '';
            }
            $XMLRequest .= '';
        }
        $XMLRequest .= $ReturnURL != '' ? '' . $ReturnURL . '' : '';
        $XMLRequest .= $ReverseAllParallelPaymentsOnError != '' ? '' . $ReverseAllParallelPaymentsOnError . '' : '';
        $XMLRequest .= $SenderEmail != '' ? '' . $SenderEmail . '' : '';
        $XMLRequest .= $TrackingID != '' ? '' . $TrackingID . '' : '';
        $XMLRequest .= '';
        $PayXMLRequest = $XMLRequest;
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'AdaptivePayments', 'Pay');
        $PayXMLResponse = $XMLResponse;
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $PayKey = $DOM->getElementsByTagName('payKey')->length > 0 ? $DOM->getElementsByTagName('payKey')->item(0)->nodeValue : '';
        $PaymentExecStatus = $DOM->getElementsByTagName('paymentExecStatus')->length > 0 ? $DOM->getElementsByTagName('paymentExecStatus')->item(0)->nodeValue : '';
        if ($this->Sandbox) {
            if ($IsDigitalGoods) {
                $RedirectURL = 'https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay?paykey=' . $PayKey;
            } else {
                $RedirectURL = 'https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=' . $PayKey;
            }
        } elseif ($this->BetaSandbox) {
            if ($IsDigitalGoods) {
                $RedirectURL = 'https://www.beta-sandbox.paypal.com/webapps/adaptivepayment/flow/pay?paykey=' . $PayKey;
            } else {
                $RedirectURL = 'https://www.beta-sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=' . $PayKey;
            }
        } else {
            if ($IsDigitalGoods) {
                $RedirectURL = 'https://www.paypal.com/webapps/adaptivepayment/flow/pay?paykey=' . $PayKey;
            } else {
                $RedirectURL = 'https://www.paypal.com/webscr?cmd=_ap-payment&paykey=' . $PayKey;
            }
        }
        if (!$this->APICallSuccessful($Ack)) {
            $ResponseDataArray = array(
                'Errors' => $Errors,
                'Ack' => $Ack,
                'Build' => $Build,
                'CorrelationID' => $CorrelationID,
                'Timestamp' => $Timestamp,
                'PayKey' => $PayKey,
                'PaymentExecStatus' => $PaymentExecStatus,
                'PayXMLRequest' => $PayXMLRequest,
                'PayXMLResponse' => $PayXMLResponse
            );
            return $ResponseDataArray;
            exit();
        }
        // SetPaymentOptions Basic Fields
        $SPOFields = isset($DataArray['SPOFields']) ? $DataArray['SPOFields'] : array();
        $ShippingAddressID = isset($SPOFields['ShippingAddressID']) ? $SPOFields['ShippingAddressID'] : '';
        // DisplayOptions Fields
        $DisplayOptions = isset($DataArray['DisplayOptions']) ? $DataArray['DisplayOptions'] : array();
        $EmailHeaderImageURL = isset($DisplayOptions['EmailHeaderImageURL']) ? $DisplayOptions['EmailHeaderImageURL'] : '';
        $EmailMarketingImageURL = isset($DisplayOptions['EmailMarketingImageURL']) ? $DisplayOptions['EmailMarketingImageURL'] : '';
        $HeaderImageURL = isset($DisplayOptions['HeaderImageURL']) ? $DisplayOptions['HeaderImageURL'] : '';
        $BusinessName = isset($DisplayOptions['BusinessName']) ? $DisplayOptions['BusinessName'] : '';
        // InstitutionCustomer Fields
        $InstitutionCustomer = isset($DataArray['InstitutionCustomer']) ? $DataArray['InstitutionCustomer'] : array();
        $CountryCode = isset($InstitutionCustomer['CountryCode']) ? $InstitutionCustomer['CountryCode'] : '';
        $DisplayName = isset($InstitutionCustomer['DisplayName']) ? $InstitutionCustomer['DisplayName'] : '';
        $InstitutionCustomerEmail = isset($InstitutionCustomer['Email']) ? $InstitutionCustomer['Email'] : '';
        $FirstName = isset($InstitutionCustomer['FirstName']) ? $InstitutionCustomer['FirstName'] : '';
        $LastName = isset($InstitutionCustomer['LastName']) ? $InstitutionCustomer['LastName'] : '';
        $InstitutionCustomerID = isset($InstitutionCustomer['InstitutionCustomerID']) ? $InstitutionCustomer['InstitutionCustomerID'] : '';
        $InstitutionID = isset($InstitutionCustomer['InstitutionID']) ? $InstitutionCustomer['InstitutionID'] : '';
        // SenderOptions Fields
        $SenderOptions = isset($DataArray['SenderOptions']) ? $DataArray['SenderOptions'] : array();
        $RequireShippingAddressSelection = isset($SenderOptions['RequireShippingAddressSelection']) ? $SenderOptions['RequireShippingAddressSelection'] : '';
        $ReferrerCode = $this->APIButtonSource;
        // ReceiverOptions Fields
        $ReceiverOptionsXML = '';
        $ReceiverOptions = isset($DataArray['ReceiverOptions']) ? $DataArray['ReceiverOptions'] : array();
        foreach ($ReceiverOptions as $ReceiverOption) {
            $Description = isset($ReceiverOption['Description']) ? $ReceiverOption['Description'] : '';
            $CustomID = isset($ReceiverOption['CustomID']) ? $ReceiverOption['CustomID'] : '';
            // Invoice Data
            $InvoiceData = isset($ReceiverOption['InvoiceData']) ? $ReceiverOption['InvoiceData'] : array();
            $TotalTax = isset($InvoiceData['TotalTax']) ? $InvoiceData['TotalTax'] : '';
            $TotalShipping = isset($InvoiceData['TotalShipping']) ? $InvoiceData['TotalShipping'] : '';
            // InvoiceItem Fields
            $InvoiceItems = isset($ReceiverOption['InvoiceItems']) ? $ReceiverOption['InvoiceItems'] : array();
            // ReceiverIdentifer Fields
            $ReceiverIdentifier = isset($ReceiverOption['ReceiverIdentifier']) ? $ReceiverOption['ReceiverIdentifier'] : array();
            $ReceiverIdentifierEmail = isset($ReceiverIdentifier['Email']) ? $ReceiverIdentifier['Email'] : '';
            $PhoneCountryCode = isset($ReceiverIdentifier['PhoneCountryCode']) ? $ReceiverIdentifier['PhoneCountryCode'] : '';
            $PhoneNumber = isset($ReceiverIdentifier['PhoneNumber']) ? $ReceiverIdentifier['PhoneNumber'] : '';
            $PhoneExtension = isset($ReceiverIdentifier['PhoneExtension']) ? $ReceiverIdentifier['PhoneExtension'] : '';
            $ReceiverOptionsXML .= '';
            $ReceiverOptionsXML .= $Description != '' ? '' . $Description . '' : '';
            $ReceiverOptionsXML .= $CustomID != '' ? '' . $CustomID . '' : '';
            if (!empty($InvoiceData)) {
                $ReceiverOptionsXML .= '';
                $ReceiverOptionsXML .= $TotalTax != '' ? '' . $TotalTax . '' : '';
                $ReceiverOptionsXML .= $TotalShipping != '' ? '' . $TotalShipping . '' : '';
                foreach ($InvoiceItems as $InvoiceItem) {
                    $ReceiverOptionsXML .= '- ';
                    $ReceiverOptionsXML .= $InvoiceItem['Name'] != '' ? '' . $InvoiceItem['Name'] . '' : '';
                    $ReceiverOptionsXML .= $InvoiceItem['Identifier'] != '' ? '' . $InvoiceItem['Identifier'] . '' : '';
                    $ReceiverOptionsXML .= $InvoiceItem['Price'] != '' ? '' . $InvoiceItem['Price'] . '' : '';
                    $ReceiverOptionsXML .= $InvoiceItem['ItemPrice'] != '' ? '' . $InvoiceItem['ItemPrice'] . '' : '';
                    $ReceiverOptionsXML .= $InvoiceItem['ItemCount'] != '' ? '' . $InvoiceItem['ItemCount'] . '' : '';
                    $ReceiverOptionsXML .= '';
                }
                $ReceiverOptionsXML .= '';
            }
            if (count($ReceiverIdentifier) > 0) {
                $ReceiverOptionsXML .= '';
                $ReceiverOptionsXML .= $ReceiverIdentifierEmail != '' ? '' . $ReceiverIdentifierEmail . '' : '';
                if ($PhoneNumber != '') {
                    $ReceiverOptionsXML .= '';
                    $ReceiverOptionsXML .= $PhoneCountryCode != '' ? '' . $PhoneCountryCode . '' : '';
                    $ReceiverOptionsXML .= $PhoneNumber != '' ? '' . $PhoneNumber . '' : '';
                    $ReceiverOptionsXML .= $PhoneExtension != '' ? '' . $PhoneExtension . '' : '';
                    $ReceiverOptionsXML .= '';
                }
                $ReceiverOptionsXML .= '';
            }
            $ReceiverOptionsXML .= '';
        }
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= $PayKey != '' ? '' . $PayKey . '' : '';
        $XMLRequest .= $ShippingAddressID != '' ? '' . $ShippingAddressID . '' : '';
        if (count($InstitutionCustomer) > 0) {
            $XMLRequest .= '';
            $XMLRequest .= '';
            $XMLRequest .= $InstitutionID != '' ? '' . $InstitutionID . '' : '';
            $XMLRequest .= $FirstName != '' ? '' . $FirstName . '' : '';
            $XMLRequest .= $LastName != '' ? '' . $LastName . '' : '';
            $XMLRequest .= $DisplayName != '' ? '' . $DisplayName . '' : '';
            $XMLRequest .= $InstitutionCustomerID != '' ? '' . $InstitutionCustomerID . '' : '';
            $XMLRequest .= $CountryCode != '' ? '' . $CountryCode . '' : '';
            $XMLRequest .= $InstitutionCustomerEmail != '' ? '' . $InstitutionCustomerEmail . '' : '';
            $XMLRequest .= '';
            $XMLRequest .= '';
        }
        if (count($DisplayOptions) > 0) {
            $XMLRequest .= '';
            $XMLRequest .= $EmailHeaderImageURL != '' ? '' . $EmailHeaderImageURL . '' : '';
            $XMLRequest .= $EmailMarketingImageURL != '' ? '' . $EmailMarketingImageURL . '' : '';
            $XMLRequest .= $HeaderImageURL != '' ? '' . $HeaderImageURL . '' : '';
            $XMLRequest .= $BusinessName != '' ? '' . $BusinessName . '' : '';
            $XMLRequest .= '';
        }
        if (count($SenderOptions) > 0) {
            $XMLRequest .= '';
            $XMLRequest .= $RequireShippingAddressSelection != '' ? '' . $RequireShippingAddressSelection . '' : '';
            $XMLRequest .= $ReferrerCode != '' ? '' . $ReferrerCode . '' : '';
            $XMLRequest .= '';
        }
        $XMLRequest .= $ReceiverOptionsXML;
        $XMLRequest .= '';
        $SetPaymentOptionsXMLRequest = $XMLRequest;
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'AdaptivePayments', 'SetPaymentOptions');
        $SetPaymentOptionsXMLResponse = $XMLResponse;
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'PayKey' => $PayKey,
            'PaymentExecStatus' => $PaymentExecStatus,
            'RedirectURL' => $PayKey != '' ? $RedirectURL : '',
            'PayXMLRequest' => $PayXMLRequest,
            'PayXMLResponse' => $PayXMLResponse,
            'SetPaymentOptionsXMLRequest' => $SetPaymentOptionsXMLRequest,
            'SetPaymentOptionsXMLResponse' => $SetPaymentOptionsXMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit PaymentDetails API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function PaymentDetails($DataArray) {
        // PaymentDetails Fields
        $PaymentDetailsFields = isset($DataArray['PaymentDetailsFields']) ? $DataArray['PaymentDetailsFields'] : array();
        $PayKey = isset($PaymentDetailsFields['PayKey']) ? $PaymentDetailsFields['PayKey'] : '';
        $TransactionID = isset($PaymentDetailsFields['TransactionID']) ? $PaymentDetailsFields['TransactionID'] : '';
        $TrackingID = isset($PaymentDetailsFields['TrackingID']) ? $PaymentDetailsFields['TrackingID'] : '';
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= $PayKey != '' ? '' . $PayKey . '' : '';
        $XMLRequest .= $TransactionID != '' ? '' . $TransactionID . '' : '';
        $XMLRequest .= $TrackingID != '' ? '' . $TrackingID . '' : '';
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'AdaptivePayments', 'PaymentDetails');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $ActionType = $DOM->getElementsByTagName('actionType')->length > 0 ? $DOM->getElementsByTagName('actionType')->item(0)->nodeValue : '';
        $CancelURL = $DOM->getElementsByTagName('cancelUrl')->length > 0 ? $DOM->getElementsByTagName('cancelUrl')->item(0)->nodeValue : '';
        $CurrencyCode = $DOM->getElementsByTagName('currencyCode')->length > 0 ? $DOM->getElementsByTagName('currencyCode')->item(0)->nodeValue : '';
        $FeesPayer = $DOM->getElementsByTagName('feesPayer')->length > 0 ? $DOM->getElementsByTagName('feesPayer')->item(0)->nodeValue : '';
        $FundingTypesDOM = $DOM->getElementsByTagName('fundingType')->length > 0 ? $DOM->getElementsByTagName('fundingType') : array();
        $FundingTypes = array();
        foreach ($FundingTypesDOM as $FundingType) {
            array_push($FundingTypes, $FundingType);
        }
        $IPNNotificationURL = $DOM->getElementsByTagName('ipnNotificationUrl')->length > 0 ? $DOM->getElementsByTagName('ipnNotificationUrl')->item(0)->nodeValue : '';
        $Memo = $DOM->getElementsByTagName('memo')->length > 0 ? $DOM->getElementsByTagName('memo')->item(0)->nodeValue : '';
        $PayKey = $DOM->getElementsByTagName('payKey')->length > 0 ? $DOM->getElementsByTagName('payKey')->item(0)->nodeValue : '';
        $PendingRefund = $DOM->getElementsByTagName('pendingRefund')->length > 0 ? $DOM->getElementsByTagName('pendingRefund')->item(0)->nodeValue : 'false';
        $RefundedAmount = $DOM->getElementsByTagName('refundedAmount')->length > 0 ? $DOM->getElementsByTagName('refundedAmount')->item(0)->nodeValue : '';
        $SenderTransactionID = $DOM->getElementsByTagName('senderTransactionID')->length > 0 ? $DOM->getElementsByTagName('senderTransactionID')->item(0)->nodeValue : '';
        $SenderTransactionStatus = $DOM->getElementsByTagName('senderTransactionStatus')->length > 0 ? $DOM->getElementsByTagName('senderTransactionStatus')->item(0)->nodeValue : '';
        $TransactionID = $DOM->getElementsByTagName('transactionId')->length > 0 ? $DOM->getElementsByTagName('transactionId')->item(0)->nodeValue : '';
        $TransactionStatus = $DOM->getElementsByTagName('transactionStatus')->length > 0 ? $DOM->getElementsByTagName('transactionStatus')->item(0)->nodeValue : '';
        $PaymentInfo = array(
            'PendingRefund' => $PendingRefund,
            'RefundAmount' => $RefundedAmount,
            'SenderTransactionID' => $SenderTransactionID,
            'SenderTransactionStatus' => $SenderTransactionStatus,
            'TransactionID' => $TransactionID,
            'TransactionStatus' => $TransactionStatus
        );
        $PreapprovalKey = $DOM->getElementsByTagName('preapprovalKey')->length > 0 ? $DOM->getElementsByTagName('preapprovalKey')->item(0)->nodeValue : '';
        $ReturnURL = $DOM->getElementsByTagName('returnUrl')->length > 0 ? $DOM->getElementsByTagName('returnUrl')->item(0)->nodeValue : '';
        $ReverseAllParallelPaymentsOnError = $DOM->getElementsByTagName('reverseAllParallelPaymentsOnError')->length > 0 ? $DOM->getElementsByTagName('reverseAllParallelPaymentsOnError')->item(0)->nodeValue : '';
        $SenderEmail = $DOM->getElementsByTagName('senderEmail')->length > 0 ? $DOM->getElementsByTagName('senderEmail')->item(0)->nodeValue : '';
        $Status = $DOM->getElementsByTagName('status')->length > 0 ? $DOM->getElementsByTagName('status')->item(0)->nodeValue : '';
        $TrackingID = $DOM->getElementsByTagName('trackingId')->length > 0 ? $DOM->getElementsByTagName('trackingId')->item(0)->nodeValue : '';
        $Amount = $DOM->getElementsByTagName('amount')->length > 0 ? $DOM->getElementsByTagName('amount')->item(0)->nodeValue : '';
        $Email = $DOM->getElementsByTagName('email')->length > 0 ? $DOM->getElementsByTagName('email')->item(0)->nodeValue : '';
        $InvoiceID = $DOM->getElementsByTagName('invoiceId')->length > 0 ? $DOM->getElementsByTagName('invoiceId')->item(0)->nodeValue : '';
        $PaymentType = $DOM->getElementsByTagName('paymentType')->length > 0 ? $DOM->getElementsByTagName('paymentType')->item(0)->nodeValue : '';
        $Primary = $DOM->getElementsByTagName('primary')->length > 0 ? $DOM->getElementsByTagName('primary')->item(0)->nodeValue : 'false';
        $Receiver = array(
            'Amount' => $Amount,
            'Email' => $Email,
            'InvoiceID' => $InvoiceID,
            'PaymentType' => $PaymentType,
            'Primary' => $Primary
        );
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'ActionType' => $ActionType,
            'CancelURL' => $CancelURL,
            'CurrencyCode' => $CurrencyCode,
            'FeesPayer' => $FeesPayer,
            'FundingTypes' => $FundingTypes,
            'IPNNotificationURL' => $IPNNotificationURL,
            'Memo' => $Memo,
            'PayKey' => $PayKey,
            'PaymentInfo' => $PaymentInfo,
            'PreapprovalKey' => $PreapprovalKey,
            'ReturnURL' => $ReturnURL,
            'ReverseAllParallelPaymentsOnError' => $ReverseAllParallelPaymentsOnError,
            'SenderEmail' => $SenderEmail,
            'Status' => $Status,
            'TrackingID' => $TrackingID,
            'Receiver' => $Receiver,
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit ExecutePayment API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function ExecutePayment($DataArray) {
        // ExecutePaymentFields Fields
        $ExecutePaymentFields = isset($DataArray['ExecutePaymentFields']) ? $DataArray['ExecutePaymentFields'] : array();
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= isset($ExecutePaymentFields['PayKey']) && $ExecutePaymentFields['PayKey'] != '' ? '' . $ExecutePaymentFields['PayKey'] . '' : '';
        $XMLRequest .= isset($ExecutePaymentFields['FundingPlanID']) && $ExecutePaymentFields['FundingPlanID'] != '' ? '' . $ExecutePaymentFields['FundingPlanID'] . '' : '';
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'AdaptivePayments', 'ExecutePayment');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $PaymentExecStatus = $DOM->getElementsByTagName('paymentExecStatus')->length > 0 ? $DOM->getElementsByTagName('paymentExecStatus')->item(0)->nodeValue : '';
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'PaymentExecStatus' => $PaymentExecStatus,
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit GetPaymentOptions API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function GetPaymentOptions($PayKey) {
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= $PayKey != '' ? '' . $PayKey . '' : '';
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'AdaptivePayments', 'GetPaymentOptions');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        // GetPaymentOptionsResponse Fields
        $PayKey = $DOM->getElementsByTagName('payKey')->length > 0 ? $DOM->getElementsByTagName('payKey')->item(0)->nodeValue : '';
        $ShippingAddressID = $DOM->getElementsByTagName('shippingAddressId')->length > 0 ? $DOM->getElementsByTagName('shippingAddressId')->item(0)->nodeValue : '';
        // InitiatingEntity Fields
        $InstitutionCustomer = $DOM->getElementsByTagName('institutionCustomer')->length > 0 ? $DOM->getElementsByTagName('institutionCustomer')->item(0)->nodeValue : '';
        $CountryCode = $InstitutionCustomer != '' && $InstitutionCustomer->getElementsByTagName('countryCode')->length > 0 ? $InstitutionCustomer->getElementsByTagName('countryCode')->item(0)->nodeValue : '';
        $DisplayName = $InstitutionCustomer != '' && $InstitutionCustomer->getElementsByTagName('displayName')->length > 0 ? $InstitutionCustomer->getElementsByTagName('displayName')->item(0)->nodeValue : '';
        $Email = $InstitutionCustomer != '' && $InstitutionCustomer->getElementsByTagName('email')->length > 0 ? $InstitutionCustomer->getElementsByTagName('email')->item(0)->nodeValue : '';
        $FirstName = $InstitutionCustomer != '' && $InstitutionCustomer->getElementsByTagName('firstName')->length > 0 ? $InstitutionCustomer->getElementsByTagName('firstName')->item(0)->nodeValue : '';
        $InstitutionCustomerID = $InstitutionCustomer != '' && $InstitutionCustomer->getElementsByTagName('institutionCustomerId')->length > 0 ? $InstitutionCustomer->getElementsByTagName('institutionCustomerId')->item(0)->nodeValue : '';
        $InstitutionID = $InstitutionCustomer != '' && $InstitutionCustomer->getElementsByTagName('institutionId')->length > 0 ? $InstitutionCustomer->getElementsByTagName('institutionId')->item(0)->nodeValue : '';
        $LastName = $InstitutionCustomer != '' && $InstitutionCustomer->getElementsByTagName('lastName')->length > 0 ? $InstitutionCustomer->getElementsByTagName('lastName')->item(0)->nodeValue : '';
        $InitiatingEntity = array(
            'CountryCode' => $CountryCode,
            'DisplayName' => $DisplayName,
            'Email' => $Email,
            'FirstName' => $FirstName,
            'InstitutionCustomerID' => $InstitutionCustomerID,
            'InstitutionID' => $InstitutionID,
            'LastName' => $LastName
        );
        // DisplayOptions Fields
        $EmailHeaderImageURL = $DOM->getElementsByTagName('emailHeaderImageUrl')->length > 0 ? $DOM->getElementsByTagName('emailHeaderImageUrl')->item(0)->nodeValue : '';
        $EmailMarketingImageURL = $DOM->getElementsByTagName('emailMarketingImageUrl')->length > 0 ? $DOM->getElementsByTagName('emailMarketingImageUrl')->item(0)->nodeValue : '';
        $BusinessName = $DOM->getElementsByTagName('businessName')->length > 0 ? $DOM->getElementsByTagName('businessName')->item(0)->nodeValue : '';
        $DisplayOptions = array(
            'EmailHeaderImageURL' => $EmailHeaderImageURL,
            'EmailMarketingImageURL' => $EmailMarketingImageURL,
            'BusinessName' => $BusinessName
        );
        // Sender Options
        $RequireShippingAddressSelection = $DOM->getElementsByTagName('requireShippingAddressSelection')->length > 0 ? $DOM->getElementsByTagName('requireShippingAddressSelection')->item(0)->nodeValue : '';
        // ReceiverOptions Fields
        $ReceiverOptions = $DOM->getElementsByTagName('receiverOptions')->length > 0 ? $DOM->getElementsByTagName('receiverOptions')->item(0)->nodeValue : '';
        $Description = $ReceiverOptions != '' && $ReceiverOptions->getElementsByTagName('description')->length > 0 ? $ReceiverOptions->getElementsByTagName('description')->item(0)->nodeValue : '';
        $CustomID = $ReceiverOptions != '' && $ReceiverOptions->getElementsByTagName('customId')->length > 0 ? $ReceiverOptions->getElementsByTagName('customId')->item(0)->nodeValue : '';
        $Email = $ReceiverOptions != '' && $ReceiverOptions->getElementsByTagName('email')->length > 0 ? $ReceiverOptions->getElementsByTagName('email')->item(0)->nodeValue : '';
        $PhoneCountryCode = $ReceiverOptions != '' && $ReceiverOptions->getElementsByTagName('countryCode')->length > 0 ? $ReceiverOptions->getElementsByTagName('countryCode')->item(0)->nodeValue : '';
        $PhoneNumber = $ReceiverOptions != '' && $ReceiverOptions->getElementsByTagName('phoneNumber')->length > 0 ? $ReceiverOptions->getElementsByTagName('phoneNumber')->item(0)->nodeValue : '';
        $PhoneExtension = $ReceiverOptions != '' && $ReceiverOptions->getElementsByTagName('extension')->length > 0 ? $ReceiverOptions->getElementsByTagName('extension')->item(0)->nodeValue : '';
        // InvoiceDataFields
        $InvoiceItems = $ReceiverOptions != '' && $ReceiverOptions->getElementsByTagName('item')->length > 0 ? $ReceiverOptions->getElementsByTagName('item') : array();
        $TotalTax = $ReceiverOptions != '' && $ReceiverOptions->getElementsByTagName('totalTax')->length > 0 ? $ReceiverOptions->getElementsByTagName('totalTax')->item(0)->nodeValue : '';
        $TotalShipping = $ReceiverOptions != '' && $ReceiverOptions->getElementsByTagName('totalShipping')->length > 0 ? $ReceiverOptions->getElementsByTagName('totalShipping')->item(0)->nodeValue : '';
        $InvoiceItemsArray = array();
        foreach ($InvoiceItems as $InvoiceItem) {
            $ItemName = $InvoiceItem->getElementsByTagName('name')->length > 0 ? $InvoiceItem->getElementsByTagName('name')->item(0)->nodeValue : '';
            $ItemIdentifier = $InvoiceItem->getElementsByTagName('identifier')->length > 0 ? $InvoiceItem->getElementsByTagName('identifier')->item(0)->nodeValue : '';
            $ItemSubtotal = $InvoiceItem->getElementsByTagName('price')->length > 0 ? $InvoiceItem->getElementsByTagName('price')->item(0)->nodeValue : '';
            $ItemPrice = $InvoiceItem->getElementsByTagName('itemPrice')->length > 0 ? $InvoiceItem->getElementsByTagName('itemPrice')->item(0)->nodeValue : '';
            $ItemCount = $InvoiceItem->getElementsByTagName('itemCount')->length > 0 ? $InvoiceItem->getElementsByTagName('itemCount')->item(0)->nodeValue : '';
            $CurrentItem = array(
                'Name' => $ItemName,
                'Identifier' => $ItemIdentifier,
                'Subtotal' => $ItemSubtotal,
                'Price' => $ItemPrice,
                'ItemCount' => $ItemCount
            );
            array_push($InvoiceItemsArray, $CurrentItem);
        }
        $InvoiceData = array('TotalTax' => $TotalTax, 'TotalShipping' => $TotalShipping, 'InvoiceItems' => $InvoiceItemsArray);
        $ReceiverOptionsFields = array(
            'Description' => $Description,
            'CustomID' => $CustomID,
            'Email' => $Email,
            'PhoneCountryCode' => $PhoneCountryCode,
            'PhoneNumber' => $PhoneNumber,
            'PhoneExtension' => $PhoneExtension,
            'InvoiceData' => $InvoiceData
        );
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'PayKey' => $PayKey,
            'ShippingAddressID' => $ShippingAddressID,
            'InitiatingEntity' => $InitiatingEntity,
            'DisplayOptions' => $DisplayOptions,
            'RequireShippingAddressSelection' => $RequireShippingAddressSelection,
            'ReceiverOptions' => $ReceiverOptionsFields,
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit SetPaymentOptions API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function SetPaymentOptions($DataArray) {
        // SetPaymentOptions Basic Fields
        $SPOFields = isset($DataArray['SPOFields']) ? $DataArray['SPOFields'] : array();
        $PayKey = isset($SPOFields['PayKey']) ? $SPOFields['PayKey'] : '';
        $ShippingAddressID = isset($SPOFields['ShippingAddressID']) ? $SPOFields['ShippingAddressID'] : '';
        // DisplayOptions Fields
        $DisplayOptions = isset($DataArray['DisplayOptions']) ? $DataArray['DisplayOptions'] : array();
        $EmailHeaderImageURL = isset($DisplayOptions['EmailHeaderImageURL']) ? $DisplayOptions['EmailHeaderImageURL'] : '';
        $EmailMarketingImageURL = isset($DisplayOptions['EmailMarketingImageURL']) ? $DisplayOptions['EmailMarketingImageURL'] : '';
        $HeaderImageURL = isset($DisplayOptions['HeaderImageURL']) ? $DisplayOptions['HeaderImageURL'] : '';
        $BusinessName = isset($DisplayOptions['BusinessName']) ? $DisplayOptions['BusinessName'] : '';
        // InstitutionCustomer Fields
        $InstitutionCustomer = isset($DataArray['InstitutionCustomer']) ? $DataArray['InstitutionCustomer'] : array();
        $CountryCode = isset($InstitutionCustomer['CountryCode']) ? $InstitutionCustomer['CountryCode'] : '';
        $DisplayName = isset($InstitutionCustomer['DisplayName']) ? $InstitutionCustomer['DisplayName'] : '';
        $InstitutionCustomerEmail = isset($InstitutionCustomer['Email']) ? $InstitutionCustomer['Email'] : '';
        $FirstName = isset($InstitutionCustomer['FirstName']) ? $InstitutionCustomer['FirstName'] : '';
        $LastName = isset($InstitutionCustomer['LastName']) ? $InstitutionCustomer['LastName'] : '';
        $InstitutionCustomerID = isset($InstitutionCustomer['InstitutionCustomerID']) ? $InstitutionCustomer['InstitutionCustomerID'] : '';
        $InstitutionID = isset($InstitutionCustomer['InstitutionID']) ? $InstitutionCustomer['InstitutionID'] : '';
        // SenderOptions Fields
        $SenderOptions = isset($DataArray['SenderOptions']) ? $DataArray['SenderOptions'] : array();
        $RequireShippingAddressSelection = isset($SenderOptions['RequireShippingAddressSelection']) ? $SenderOptions['RequireShippingAddressSelection'] : '';
        $ReferrerCode = $this->APIButtonSource;
        // ReceiverOptions Fields
        $ReceiverOptionsXML = '';
        $ReceiverOptions = isset($DataArray['ReceiverOptions']) ? $DataArray['ReceiverOptions'] : array();
        foreach ($ReceiverOptions as $ReceiverOption) {
            $Description = isset($ReceiverOption['Description']) ? $ReceiverOption['Description'] : '';
            $CustomID = isset($ReceiverOption['CustomID']) ? $ReceiverOption['CustomID'] : '';
            // Invoice Data
            $InvoiceData = isset($ReceiverOption['InvoiceData']) ? $ReceiverOption['InvoiceData'] : array();
            $TotalTax = isset($InvoiceData['TotalTax']) ? $InvoiceData['TotalTax'] : '';
            $TotalShipping = isset($InvoiceData['TotalShipping']) ? $InvoiceData['TotalShipping'] : '';
            // InvoiceItem Fields
            $InvoiceItems = isset($ReceiverOption['InvoiceItems']) ? $ReceiverOption['InvoiceItems'] : array();
            // ReceiverIdentifer Fields
            $ReceiverIdentifier = isset($ReceiverOption['ReceiverIdentifier']) ? $ReceiverOption['ReceiverIdentifier'] : array();
            $ReceiverIdentifierEmail = isset($ReceiverIdentifier['Email']) ? $ReceiverIdentifier['Email'] : '';
            $PhoneCountryCode = isset($ReceiverIdentifier['PhoneCountryCode']) ? $ReceiverIdentifier['PhoneCountryCode'] : '';
            $PhoneNumber = isset($ReceiverIdentifier['PhoneNumber']) ? $ReceiverIdentifier['PhoneNumber'] : '';
            $PhoneExtension = isset($ReceiverIdentifier['PhoneExtension']) ? $ReceiverIdentifier['PhoneExtension'] : '';
            $ReceiverOptionsXML .= '';
            $ReceiverOptionsXML .= $Description != '' ? '' . $Description . '' : '';
            $ReceiverOptionsXML .= $CustomID != '' ? '' . $CustomID . '' : '';
            if (!empty($InvoiceData)) {
                $ReceiverOptionsXML .= '';
                $ReceiverOptionsXML .= $TotalTax != '' ? '' . $TotalTax . '' : '';
                $ReceiverOptionsXML .= $TotalShipping != '' ? '' . $TotalShipping . '' : '';
                foreach ($InvoiceItems as $InvoiceItem) {
                    $ReceiverOptionsXML .= '
- ';
                    $ReceiverOptionsXML .= $InvoiceItem['Name'] != '' ? '' . $InvoiceItem['Name'] . '' : '';
                    $ReceiverOptionsXML .= $InvoiceItem['Identifier'] != '' ? '' . $InvoiceItem['Identifier'] . '' : '';
                    $ReceiverOptionsXML .= $InvoiceItem['Price'] != '' ? '' . $InvoiceItem['Price'] . '' : '';
                    $ReceiverOptionsXML .= $InvoiceItem['ItemPrice'] != '' ? '' . $InvoiceItem['ItemPrice'] . '' : '';
                    $ReceiverOptionsXML .= $InvoiceItem['ItemCount'] != '' ? '' . $InvoiceItem['ItemCount'] . '' : '';
                    $ReceiverOptionsXML .= '';
                }
                $ReceiverOptionsXML .= '';
            }
            if (count($ReceiverIdentifier) > 0) {
                $ReceiverOptionsXML .= '';
                $ReceiverOptionsXML .= $ReceiverIdentifierEmail != '' ? '' . $ReceiverIdentifierEmail . '' : '';
                if ($PhoneNumber != '') {
                    $ReceiverOptionsXML .= '';
                    $ReceiverOptionsXML .= $PhoneCountryCode != '' ? '' . $PhoneCountryCode . '' : '';
                    $ReceiverOptionsXML .= $PhoneNumber != '' ? '' . $PhoneNumber . '' : '';
                    $ReceiverOptionsXML .= $PhoneExtension != '' ? '' . $PhoneExtension . '' : '';
                    $ReceiverOptionsXML .= '';
                }
                $ReceiverOptionsXML .= '';
            }
            $ReceiverOptionsXML .= '';
        }
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= $PayKey != '' ? '' . $PayKey . '' : '';
        $XMLRequest .= $ShippingAddressID != '' ? '' . $ShippingAddressID . '' : '';
        if (count($InstitutionCustomer) > 0) {
            $XMLRequest .= '';
            $XMLRequest .= '';
            $XMLRequest .= $InstitutionID != '' ? '' . $InstitutionID . '' : '';
            $XMLRequest .= $FirstName != '' ? '' . $FirstName . '' : '';
            $XMLRequest .= $LastName != '' ? '' . $LastName . '' : '';
            $XMLRequest .= $DisplayName != '' ? '' . $DisplayName . '' : '';
            $XMLRequest .= $InstitutionCustomerID != '' ? '' . $InstitutionCustomerID . '' : '';
            $XMLRequest .= $CountryCode != '' ? '' . $CountryCode . '' : '';
            $XMLRequest .= $InstitutionCustomerEmail != '' ? '' . $InstitutionCustomerEmail . '' : '';
            $XMLRequest .= '';
            $XMLRequest .= '';
        }
        if (count($DisplayOptions) > 0) {
            $XMLRequest .= '';
            $XMLRequest .= $EmailHeaderImageURL != '' ? '' . $EmailHeaderImageURL . '' : '';
            $XMLRequest .= $EmailMarketingImageURL != '' ? '' . $EmailMarketingImageURL . '' : '';
            $XMLRequest .= $HeaderImageURL != '' ? '' . $HeaderImageURL . '' : '';
            $XMLRequest .= $BusinessName != '' ? '' . $BusinessName . '' : '';
            $XMLRequest .= '';
        }
        if (count($SenderOptions) > 0) {
            $XMLRequest .= '';
            $XMLRequest .= $RequireShippingAddressSelection != '' ? '' . $RequireShippingAddressSelection . '' : '';
            $XMLRequest .= $ReferrerCode != '' ? '' . $ReferrerCode . '' : '';
            $XMLRequest .= '';
        }
        $XMLRequest .= $ReceiverOptionsXML;
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'AdaptivePayments', 'SetPaymentOptions');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit Preapproval API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function Preapproval($DataArray) {
        $PreapprovalFields = isset($DataArray['PreapprovalFields']) ? $DataArray['PreapprovalFields'] : array();
        $CancelURL = isset($PreapprovalFields['CancelURL']) ? $PreapprovalFields['CancelURL'] : '';
        $CurrencyCode = isset($PreapprovalFields['CurrencyCode']) ? $PreapprovalFields['CurrencyCode'] : '';
        $DateOfMonth = isset($PreapprovalFields['DateOfMonth']) ? $PreapprovalFields['DateOfMonth'] : '';
        $DayOfWeek = isset($PreapprovalFields['DayOfWeek']) ? $PreapprovalFields['DayOfWeek'] : '';
        $EndingDate = isset($PreapprovalFields['EndingDate']) ? $PreapprovalFields['EndingDate'] : '';
        $IPNNotificationURL = isset($PreapprovalFields['IPNNotificationURL']) ? $PreapprovalFields['IPNNotificationURL'] : '';
        $MaxAmountPerPayment = isset($PreapprovalFields['MaxAmountPerPayment']) ? $PreapprovalFields['MaxAmountPerPayment'] : '';
        $MaxNumberOfPayments = isset($PreapprovalFields['MaxNumberOfPayments']) ? $PreapprovalFields['MaxNumberOfPayments'] : '';
        $MaxNumberOfPaymentsPerPeriod = isset($PreapprovalFields['MaxNumberOfPaymentsPerPeriod']) ? $PreapprovalFields['MaxNumberOfPaymentsPerPeriod'] : '';
        $MaxTotalAmountOfAllPayments = isset($PreapprovalFields['MaxTotalAmountOfAllPayments']) ? $PreapprovalFields['MaxTotalAmountOfAllPayments'] : '';
        $Memo = isset($PreapprovalFields['Memo']) ? $PreapprovalFields['Memo'] : '';
        $PaymentPeriod = isset($PreapprovalFields['PaymentPeriod']) ? $PreapprovalFields['PaymentPeriod'] : '';
        $PinType = isset($PreapprovalFields['PinType']) ? $PreapprovalFields['PinType'] : '';
        $ReturnURL = isset($PreapprovalFields['ReturnURL']) ? $PreapprovalFields['ReturnURL'] : '';
        $SenderEmail = isset($PreapprovalFields['SenderEmail']) ? $PreapprovalFields['SenderEmail'] : '';
        $StartingDate = isset($PreapprovalFields['StartingDate']) ? $PreapprovalFields['StartingDate'] : '';
        $FeesPayer = isset($PreapprovalFields['FeesPayer']) ? $PreapprovalFields['FeesPayer'] : '';
        $DisplayMaxTotalAmount = isset($PreapprovalFields['DisplayMaxTotalAmount']) ? $PreapprovalFields['DisplayMaxTotalAmount'] : '';
        $ClientDetailsFields = isset($DataArray['ClientDetailsFields']) ? $DataArray['ClientDetailsFields'] : array();
        $CustomerID = isset($ClientDetailsFields['CustomerID']) ? $ClientDetailsFields['CustomerID'] : '';
        $CustomerType = isset($ClientDetailsFields['CustomerType']) ? $ClientDetailsFields['CustomerType'] : '';
        $GeoLocation = isset($ClientDetailsFields['GeoLocation']) ? $ClientDetailsFields['GeoLocation'] : '';
        $Model = isset($ClientDetailsFields['Model']) ? $ClientDetailsFields['Model'] : '';
        $PartnerName = isset($ClientDetailsFields['PartnerName']) ? $ClientDetailsFields['PartnerName'] : '';
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= '' . $CancelURL . '';
        $XMLRequest .= '';
        $XMLRequest .= $this->ApplicationID != '' ? '' . $this->ApplicationID . '' : '';
        $XMLRequest .= $CustomerID != '' ? '' . $CustomerID . '' : '';
        $XMLRequest .= $CustomerType != '' ? '' . $CustomerType . '' : '';
        $XMLRequest .= $this->DeviceID != '' ? '' . $this->DeviceID . '' : '';
        $XMLRequest .= $GeoLocation != '' ? '' . $GeoLocation . '' : '';
        $XMLRequest .= $this->IPAddress != '' ? '' . $this->IPAddress . '' : '';
        $XMLRequest .= $Model != '' ? '' . $Model . '' : '';
        $XMLRequest .= $PartnerName != '' ? '' . $PartnerName . '' : '';
        $XMLRequest .= '';
        $XMLRequest .= '' . $CurrencyCode . '';
        $XMLRequest .= $DateOfMonth != '' ? '' . $DateOfMonth . '' : '';
        $XMLRequest .= $DayOfWeek != '' ? '' . $DayOfWeek . '' : '';
        $XMLRequest .= $EndingDate != '' ? '' . $EndingDate . '' : '';
        $XMLRequest .= $IPNNotificationURL != '' ? '' . $IPNNotificationURL . '' : '';
        $XMLRequest .= $MaxAmountPerPayment != '' ? '' . $MaxAmountPerPayment . '' : '';
        $XMLRequest .= $MaxNumberOfPayments != '' ? '' . $MaxNumberOfPayments . '' : '';
        $XMLRequest .= $MaxNumberOfPaymentsPerPeriod != '' ? '' . $MaxNumberOfPaymentsPerPeriod . '' : '';
        $XMLRequest .= $MaxTotalAmountOfAllPayments != '' ? '' . $MaxTotalAmountOfAllPayments . '' : '';
        $XMLRequest .= $Memo != '' ? '' . $Memo . '' : '';
        $XMLRequest .= $PaymentPeriod != '' ? '' . $PaymentPeriod . '' : '';
        $XMLRequest .= $PinType != '' ? '' . $PinType . '' : '';
        $XMLRequest .= $FeesPayer != '' ? '' . $FeesPayer . '' : '';
        $XMLRequest .= $DisplayMaxTotalAmount != '' ? '' . $DisplayMaxTotalAmount . '' : '';
        $XMLRequest .= $ReturnURL != '' ? '' . $ReturnURL . '' : '';
        $XMLRequest .= $SenderEmail != '' ? '' . $SenderEmail . '' : '';
        $XMLRequest .= $StartingDate != '' ? '' . $StartingDate . '' : '';
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'AdaptivePayments', 'Preapproval');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $PreapprovalKey = $DOM->getElementsByTagName('preapprovalKey')->length > 0 ? $DOM->getElementsByTagName('preapprovalKey')->item(0)->nodeValue : '';
        if ($this->Sandbox) {
            $RedirectURL = 'https://www.sandbox.paypal.com/webscr?cmd=_ap-preapproval&preapprovalkey=' . $PreapprovalKey;
        } elseif ($this->BetaSandbox) {
            $RedirectURL = 'https://www.beta-sandbox.paypal.com/webscr?cmd=_ap-preapproval&preapprovalkey=' . $PreapprovalKey;
        } else {
            $RedirectURL = 'https://www.paypal.com/webscr?cmd=_ap-preapproval&preapprovalkey=' . $PreapprovalKey;
        }
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'PreapprovalKey' => $PreapprovalKey,
            'RedirectURL' => $PreapprovalKey != '' ? $RedirectURL : '',
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit PreapprovalDetails API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function PreapprovalDetails($DataArray) {
        $PreapprovalDetailsFields = isset($DataArray['PreapprovalDetailsFields']) ? $DataArray['PreapprovalDetailsFields'] : array();
        $GetBillingAddress = isset($PreapprovalDetailsFields['GetBillingAddress']) ? $PreapprovalDetailsFields['GetBillingAddress'] : '';
        $PreapprovalKey = isset($PreapprovalDetailsFields['PreapprovalKey']) ? $PreapprovalDetailsFields['PreapprovalKey'] : '';
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= $GetBillingAddress != '' ? '' . $GetBillingAddress . '' : '';
        $XMLRequest .= $PreapprovalKey != '' ? '' . $PreapprovalKey . '' : '';
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'AdaptivePayments', 'PreapprovalDetails');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $Approved = $DOM->getElementsByTagName('approved')->length > 0 ? $DOM->getElementsByTagName('approved')->item(0)->nodeValue : '';
        $CancelURL = $DOM->getElementsByTagName('cancelUrl')->length > 0 ? $DOM->getElementsByTagName('cancelUrl')->item(0)->nodeValue : '';
        $CurPayments = $DOM->getElementsByTagName('curPayments')->length > 0 ? $DOM->getElementsByTagName('curPayments')->item(0)->nodeValue : '';
        $CurPaymentsAmount = $DOM->getElementsByTagName('curPaymentsAmount')->length > 0 ? $DOM->getElementsByTagName('curPaymentsAmount')->item(0)->nodeValue : '';
        $CurPeriodAttempts = $DOM->getElementsByTagName('curPeriodAttempts')->length > 0 ? $DOM->getElementsByTagName('curPeriodAttempts')->item(0)->nodeValue : '';
        $CurPeriodEndingDate = $DOM->getElementsByTagName('curPeriodEndingDate')->length > 0 ? $DOM->getElementsByTagName('curPeriodEndingDate')->item(0)->nodeValue : '';
        $CurrencyCode = $DOM->getElementsByTagName('currencyCode')->length > 0 ? $DOM->getElementsByTagName('currencyCode')->item(0)->nodeValue : '';
        $DateOfMonth = $DOM->getElementsByTagName('dateOfMonth')->length > 0 ? $DOM->getElementsByTagName('dateOfMonth')->item(0)->nodeValue : '';
        $DayOfWeek = $DOM->getElementsByTagName('dayOfWeek')->length > 0 ? $DOM->getElementsByTagName('dayOfWeek')->item(0)->nodeValue : '';
        $EndingDate = $DOM->getElementsByTagName('endingDate')->length > 0 ? $DOM->getElementsByTagName('endingDate')->item(0)->nodeValue : '';
        $IPNNotificationURL = $DOM->getElementsByTagName('ipnNotificationUrl')->length > 0 ? $DOM->getElementsByTagName('ipnNotificationUrl')->item(0)->nodeValue : '';
        $MaxAmountPerPayment = $DOM->getElementsByTagName('maxAmountPerPayment')->length > 0 ? $DOM->getElementsByTagName('maxAmountPerPayment')->item(0)->nodeValue : '';
        $MaxNumberOfPayments = $DOM->getElementsByTagName('maxNumberOfPayments')->length > 0 ? $DOM->getElementsByTagName('maxNumberOfPayments')->item(0)->nodeValue : '';
        $MaxNumberOfPaymentsPerPeriod = $DOM->getElementsByTagName('maxNumberOfPaymentsPerPeriod')->length > 0 ? $DOM->getElementsByTagName('maxNumberOfPaymentsPerPeriod')->item(0)->nodeValue : '';
        $MaxTotalAmountOfAllPayments = $DOM->getElementsByTagName('maxTotalAmountOfAllPayments')->length > 0 ? $DOM->getElementsByTagName('maxTotalAmountOfAllPayments')->item(0)->nodeValue : '';
        $Memo = $DOM->getElementsByTagName('memo')->length > 0 ? $DOM->getElementsByTagName('memo')->item(0)->nodeValue : '';
        $PaymentPeriod = $DOM->getElementsByTagName('paymentPeriod')->length > 0 ? $DOM->getElementsByTagName('paymentPeriod')->item(0)->nodeValue : '';
        $PinType = $DOM->getElementsByTagName('pinType')->length > 0 ? $DOM->getElementsByTagName('pinType')->item(0)->nodeValue : '';
        $ReturnUrl = $DOM->getElementsByTagName('returnUrl')->length > 0 ? $DOM->getElementsByTagName('returnUrl')->item(0)->nodeValue : '';
        $SenderEmail = $DOM->getElementsByTagName('senderEmail')->length > 0 ? $DOM->getElementsByTagName('senderEmail')->item(0)->nodeValue : '';
        $StartingDate = $DOM->getElementsByTagName('startingDate')->length > 0 ? $DOM->getElementsByTagName('startingDate')->item(0)->nodeValue : '';
        $Status = $DOM->getElementsByTagName('status')->length > 0 ? $DOM->getElementsByTagName('status')->item(0)->nodeValue : '';
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'Approved' => $Approved,
            'CancelURL' => $CancelURL,
            'CurPayments' => $CurPayments,
            'CurPaymentsAmount' => $CurPaymentsAmount,
            'CurPeriodAttempts' => $CurPeriodAttempts,
            'CurPeriodEndingDate' => $CurPeriodEndingDate,
            'CurrencyCode' => $CurrencyCode,
            'DateOfMonth' => $DateOfMonth,
            'DayOfWeek' => $DayOfWeek,
            'EndingDate' => $EndingDate,
            'IPNNotificationURL' => $IPNNotificationURL,
            'MaxAmountPerPayment' => $MaxAmountPerPayment,
            'MaxNumberOfPayments' => $MaxNumberOfPayments,
            'MaxNumberOfPaymentsPerPeriod' => $MaxNumberOfPaymentsPerPeriod,
            'MaxTotalAmountOfAllPayments' => $MaxTotalAmountOfAllPayments,
            'Memo' => $Memo,
            'PaymentPeriod' => $PaymentPeriod,
            'PinType' => $PinType,
            'ReturnUrl' => $ReturnUrl,
            'SenderEmail' => $SenderEmail,
            'StartingDate' => $StartingDate,
            'Status' => $Status,
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit CancelPreapproval API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function CancelPreapproval($DataArray) {
        $CancelPreapprovalFields = isset($DataArray['CancelPreapprovalFields']) ? $DataArray['CancelPreapprovalFields'] : array();
        $PreapprovalKey = isset($CancelPreapprovalFields['PreapprovalKey']) ? $CancelPreapprovalFields['PreapprovalKey'] : '';
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= $PreapprovalKey != '' ? '' . $PreapprovalKey . '' : '';
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'AdaptivePayments', 'CancelPreapproval');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit Refund API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function Refund($DataArray) {
        $RefundFields = isset($DataArray['RefundFields']) ? $DataArray['RefundFields'] : array();
        $CurrencyCode = isset($RefundFields['CurrencyCode']) ? $RefundFields['CurrencyCode'] : '';
        $PayKey = isset($RefundFields['PayKey']) ? $RefundFields['PayKey'] : '';
        $TransactionID = isset($RefundFields['TransactionID']) ? $RefundFields['TransactionID'] : '';
        $TrackingID = isset($RefundFields['TrackingID']) ? $RefundFields['TrackingID'] : '';
        $Receivers = isset($DataArray['Receivers']) ? $DataArray['Receivers'] : array();
        $Amount = isset($Receivers['Amount']) ? $Receivers['Amount'] : '';
        $Email = isset($Receivers['Email']) ? $Receivers['Email'] : '';
        $InvoiceID = isset($Receivers['InvoiceID']) ? $Receivers['InvoiceID'] : '';
        $Primary = isset($Receivers['Primary']) ? $Receivers['Primary'] : '';
        $PaymentType = isset($Receivers['PaymentType']) ? $Receivers['PaymentType'] : '';
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= $CurrencyCode != '' ? '' . $CurrencyCode . '' : '';
        $XMLRequest .= $PayKey != '' ? '' . $PayKey . '' : '';
        if (!empty($Receivers)) {
            $XMLRequest .= '';
            foreach ($Receivers as $Receiver) {
                $XMLRequest .= '';
                $XMLRequest .= $Receiver['Amount'] != '' ? '' . $Receiver['Amount'] . '' : '';
                $XMLRequest .= $Receiver['Email'] != '' ? '' . $Receiver['Email'] . '' : '';
                $XMLRequest .= $Receiver['InvoiceID'] != '' ? '' . $Receiver['InvoiceID'] . '' : '';
                $XMLRequest .= $Receiver['PaymentType'] != '' ? '' . $Receiver['PaymentType'] . '' : '';
                $XMLRequest .= '';
            }
            $XMLRequest .= '';
        }
        $XMLRequest .= $TransactionID != '' ? '' . $TransactionID . '' : '';
        $XMLRequest .= $TrackingID != '' ? '' . $TrackingID . '' : '';
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'AdaptivePayments', 'Refund');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $EncryptedTransactionID = $DOM->getElementsByTagName('encryptedRefundTransactionId')->length > 0 ? $DOM->getElementsByTagName('encryptedRefundTransactionId')->item(0)->nodeValue : '';
        $RefundFeeAmount = $DOM->getElementsByTagName('refundFeeAmount')->length > 0 ? $DOM->getElementsByTagName('refundFeeAmount')->item(0)->nodeValue : '';
        $RefundGrossAmount = $DOM->getElementsByTagName('refundGrossAmount')->length > 0 ? $DOM->getElementsByTagName('refundGrossAmount')->item(0)->nodeValue : '';
        $RefundHasBecomeFull = $DOM->getElementsByTagName('refundHasBecomeFull')->length > 0 ? $DOM->getElementsByTagName('refundHasBecomeFull')->item(0)->nodeValue : '';
        $RefundNetAmount = $DOM->getElementsByTagName('refundNetAmount')->length > 0 ? $DOM->getElementsByTagName('refundNetAmount')->item(0)->nodeValue : '';
        $RefundStatus = $DOM->getElementsByTagName('refundStatus')->length > 0 ? $DOM->getElementsByTagName('refundStatus')->item(0)->nodeValue : '';
        $RefundTransactionStatus = $DOM->getElementsByTagName('refundTransactionStatus')->length > 0 ? $DOM->getElementsByTagName('refundTransactionStatus')->item(0)->nodeValue : '';
        $TotalOfAllRefunds = $DOM->getElementsByTagName('totalOfAllRefunds')->length > 0 ? $DOM->getElementsByTagName('totalOfAllRefunds')->item(0)->nodeValue : '';
        $Amount = $DOM->getElementsByTagName('amount')->length > 0 ? $DOM->getElementsByTagName('amount')->item(0)->nodeValue : '';
        $Email = $DOM->getElementsByTagName('email')->length > 0 ? $DOM->getElementsByTagName('email')->item(0)->nodeValue : '';
        $InvoiceID = $DOM->getElementsByTagName('invoiceId')->length > 0 ? $DOM->getElementsByTagName('invoiceId')->item(0)->nodeValue : '';
        $PaymentType = $DOM->getElementsByTagName('paymentType')->length > 0 ? $DOM->getElementsByTagName('paymentType')->item(0)->nodeValue : '';
        $Primary = $DOM->getElementsByTagName('primary')->length > 0 ? $DOM->getElementsByTagName('primary')->item(0)->nodeValue : '';
        $Receiver = array(
            'Amount' => $Amount,
            'Email' => $Email,
            'InvoiceID' => $InvoiceID,
            'PaymentType' => $PaymentType,
            'Primary' => $Primary
        );
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'EncryptedTransactionID' => $EncryptedTransactionID,
            'RefundFeeAmount' => $RefundFeeAmount,
            'RefundGrossAmount' => $RefundGrossAmount,
            'RefundHasBecomeFull' => $RefundHasBecomeFull,
            'RefundNetAmount' => $RefundNetAmount,
            'RefundStatus' => $RefundStatus,
            'RefundTransactionStatus' => $RefundTransactionStatus,
            'TotalOfAllRefunds' => $TotalOfAllRefunds,
            'Receiver' => $Receiver,
            'RawRequest' => $XMLRequest,
            'RawResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit ConvertCurrency API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function ConvertCurrency($DataArray) {
        $BaseAmountList = isset($DataArray['BaseAmountList']) ? $DataArray['BaseAmountList'] : array();
        $ConvertToCurrencyList = isset($DataArray['ConvertToCurrencyList']) ? $DataArray['ConvertToCurrencyList'] : array();
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= '';
        foreach ($BaseAmountList as $BaseAmount) {
            $XMLRequest .= '';
            $XMLRequest .= '
' . $BaseAmount['Code'] . '';
            $XMLRequest .= '' . $BaseAmount['Amount'] . '';
            $XMLRequest .= '';
        }
        $XMLRequest .= '';
        $XMLRequest .= '';
        foreach ($ConvertToCurrencyList as $CurrencyCode) {
            $XMLRequest .= '' . $CurrencyCode . '';
        }
        $XMLRequest .= '';
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'AdaptivePayments', 'ConvertCurrency');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $CurrencyConversionListArray = array();
        $CurrencyConversionListDOM = $DOM->getElementsByTagName('currencyConversionList')->length > 0 ? $DOM->getElementsByTagName('currencyConversionList') : array();
        foreach ($CurrencyConversionListDOM as $CurrencyConversionList) {
            $BaseAmountDOM = $CurrencyConversionList->getElementsByTagName('baseAmount')->length > 0 ? $CurrencyConversionList->getElementsByTagName('baseAmount') : array();
            foreach ($BaseAmountDOM as $BaseAmount) {
                $BaseAmountCurrencyCode = $BaseAmount->getElementsByTagName('code')->length > 0 ? $BaseAmount->getElementsByTagName('code')->item(0)->nodeValue : '';
                $BaseAmountValue = $BaseAmount->getElementsByTagName('amount')->length > 0 ? $BaseAmount->getElementsByTagName('amount')->item(0)->nodeValue : '';
                $BaseAmountArray = array(
                    'Code' => $BaseAmountCurrencyCode,
                    'Amount' => $BaseAmountValue
                );
            }
            $CurrencyListArray = array();
            $CurrencyListDOM = $CurrencyConversionList->getElementsByTagName('currency')->length > 0 ? $CurrencyConversionList->getElementsByTagName('currency') : array();
            foreach ($CurrencyListDOM as $CurrencyList) {
                $ListCurrencyCode = $CurrencyList->getElementsByTagName('code')->length > 0 ? $CurrencyList->getElementsByTagName('code')->item(0)->nodeValue : '';
                $ListCurrencyAmount = $CurrencyList->getElementsByTagName('amount')->length > 0 ? $CurrencyList->getElementsByTagName('amount')->item(0)->nodeValue : '';
                $ListCurrencyCurrent = array(
                    'Code' => $ListCurrencyCode,
                    'Amount' => $ListCurrencyAmount
                );
                array_push($CurrencyListArray, $ListCurrencyCurrent);
            }
            $CurrencyConversionListCurrent = array(
                'BaseAmount' => $BaseAmountArray,
                'CurrencyList' => $CurrencyListArray
            );
            array_push($CurrencyConversionListArray, $CurrencyConversionListCurrent);
        }
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'CurrencyConversionList' => $CurrencyConversionListArray,
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit CreateAccount API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function CreateAccount($DataArray) {
        $CreateAccountFields = isset($DataArray['CreateAccountFields']) ? $DataArray['CreateAccountFields'] : array();
        $AccountType = isset($CreateAccountFields['AccountType']) ? $CreateAccountFields['AccountType'] : '';
        $CitizenshipCountryCode = isset($CreateAccountFields['CitizenshipCountryCode']) ? $CreateAccountFields['CitizenshipCountryCode'] : '';
        $ContactPhoneNumber = isset($CreateAccountFields['ContactPhoneNumber']) ? $CreateAccountFields['ContactPhoneNumber'] : '';
        $HomePhoneNumber = isset($CreateAccountFields['HomePhoneNumber']) ? $CreateAccountFields['HomePhoneNumber'] : '';
        $MobilePhoneNumber = isset($CreateAccountFields['MobilePhoneNumber']) ? $CreateAccountFields['MobilePhoneNumber'] : '';
        $CurrencyCode = isset($CreateAccountFields['CurrencyCode']) ? $CreateAccountFields['CurrencyCode'] : '';
        $DateOfBirth = isset($CreateAccountFields['DateOfBirth']) ? $CreateAccountFields['DateOfBirth'] : '';
        $EmailAddress = isset($CreateAccountFields['EmailAddress']) ? $CreateAccountFields['EmailAddress'] : '';
        $Salutation = isset($CreateAccountFields['Salutation']) ? $CreateAccountFields['Salutation'] : '';
        $FirstName = isset($CreateAccountFields['FirstName']) ? $CreateAccountFields['FirstName'] : '';
        $MiddleName = isset($CreateAccountFields['MiddleName']) ? $CreateAccountFields['MiddleName'] : '';
        $LastName = isset($CreateAccountFields['LastName']) ? $CreateAccountFields['LastName'] : '';
        $Suffix = isset($CreateAccountFields['Suffix']) ? $CreateAccountFields['Suffix'] : '';
        $NotificationURL = isset($CreateAccountFields['NotificationURL']) ? $CreateAccountFields['NotificationURL'] : '';
        $PerformExtraVettingOnThisAccount = isset($CreateAccountFields['PerformExtraVettingOnThisAccount']) ? $CreateAccountFields['PerformExtraVettingOnThisAccount'] : '';
        $PreferredLanguageCode = isset($CreateAccountFields['PreferredLanguageCode']) && $CreateAccountFields['PreferredLanguageCode'] != '' ? $CreateAccountFields['PreferredLanguageCode'] : 'en_US';
        $RegistrationType = isset($CreateAccountFields['RegistrationType']) ? $CreateAccountFields['RegistrationType'] : 'Web';
        $SuppressWelcomeEmail = isset($CreateAccountFields['SuppressWelcomeEmail']) ? $CreateAccountFields['SuppressWelcomeEmail'] : '';
        $TaxID = isset($CreateAccountFields['TaxID']) ? $CreateAccountFields['TaxID'] : '';
        $ReturnURL = isset($CreateAccountFields['ReturnURL']) ? $CreateAccountFields['ReturnURL'] : '';
        $ShowAddCreditCard = isset($CreateAccountFields['ShowAddCreditCard']) ? $CreateAccountFields['ShowAddCreditCard'] : '';
        $ShowMobileConfirm = isset($CreateAccountFields['ShowMobileConfirm']) ? $CreateAccountFields['ShowMobileConfirm'] : '';
        $ReturnURLDescription = isset($CreateAccountFields['ReturnURLDescription']) ? $CreateAccountFields['ReturnURLDescription'] : '';
        $UseMiniBrowser = isset($CreateAccountFields['UseMiniBrowser']) ? $CreateAccountFields['UseMiniBrowser'] : '';
        $Address = isset($DataArray['Address']) ? $DataArray['Address'] : array();
        $Line1 = isset($Address['Line1']) ? $Address['Line1'] : '';
        $Line2 = isset($Address['Line2']) ? $Address['Line2'] : '';
        $City = isset($Address['City']) ? $Address['City'] : '';
        $State = isset($Address['State']) ? $Address['State'] : '';
        $PostalCode = isset($Address['PostalCode']) ? $Address['PostalCode'] : '';
        $CountryCode = isset($Address['CountryCode']) ? $Address['CountryCode'] : '';
        $BusinessInfo = isset($DataArray['BusinessInfo']) ? $DataArray['BusinessInfo'] : array();
        $AveragePrice = isset($BusinessInfo['AveragePrice']) ? $BusinessInfo['AveragePrice'] : '';
        $AverageMonthlyVolume = isset($BusinessInfo['AverageMonthlyVolume']) ? $BusinessInfo['AverageMonthlyVolume'] : '';
        $BusinessName = isset($BusinessInfo['BusinessName']) ? $BusinessInfo['BusinessName'] : '';
        $BusinessType = isset($BusinessInfo['BusinessType']) ? $BusinessInfo['BusinessType'] : '';
        $BusinessSubType = isset($BusinessInfo['BusinessSubType']) ? $BusinessInfo['BusinessSubType'] : '';
        $Category = isset($BusinessInfo['Category']) ? $BusinessInfo['Category'] : '';
        $CommercialRegistrationLocation = isset($BusinessInfo['CommercialRegistrationLocation']) ? $BusinessInfo['CommercialRegistrationLocation'] : '';
        $CompanyID = isset($BusinessInfo['CompanyID']) ? $BusinessInfo['CompanyID'] : '';
        $CustomerServiceEmail = isset($BusinessInfo['CustomerServiceEmail']) ? $BusinessInfo['CustomerServiceEmail'] : '';
        $CustomerServicePhone = isset($BusinessInfo['CustomerServicePhone']) ? $BusinessInfo['CustomerServicePhone'] : '';
        $DateOfEstablishment = isset($BusinessInfo['DateOfEstablishment']) ? $BusinessInfo['DateOfEstablishment'] : '';
        $DisputeEmail = isset($BusinessInfo['DisputeEmail']) ? $BusinessInfo['DisputeEmail'] : '';
        $DoingBusinessAs = isset($BusinessInfo['DoingBusinessAs']) ? $BusinessInfo['DoingBusinessAs'] : '';
        $EstablishmentCountryCode = isset($BusinessInfo['EstablishmentCountryCode']) ? $BusinessInfo['EstablishmentCountryCode'] : '';
        $EstablishmentState = isset($BusinessInfo['EstablishmentState']) ? $BusinessInfo['EstablishmentState'] : '';
        $IncorporationID = isset($BusinessInfo['IncorporationID']) ? $BusinessInfo['IncorporationID'] : '';
        $MerchantCategoryCode = isset($BusinessInfo['MerchantCategoryCode']) ? $BusinessInfo['MerchantCategoryCode'] : '';
        $PercentageRevenueFromOnline = isset($BusinessInfo['PercentageRevenueFromOnline']) ? $BusinessInfo['PercentageRevenueFromOnline'] : '';
        $SalesVenu = isset($BusinessInfo['SalesVenu']) ? $BusinessInfo['SalesVenu'] : '';
        $SalesVenuDesc = isset($BusinessInfo['SalesVenuDesc']) ? $BusinessInfo['SalesVenuDesc'] : '';
        $SubCategory = isset($BusinessInfo['SubCategory']) ? $BusinessInfo['SubCategory'] : '';
        $VatCountryCode = isset($BusinessInfo['VatCountryCode']) ? $BusinessInfo['VatCountryCode'] : '';
        $VatID = isset($BusinessInfo['VatID']) ? $BusinessInfo['VatID'] : '';
        $WebSite = isset($BusinessInfo['WebSite']) ? $BusinessInfo['WebSite'] : '';
        $WorkPhone = isset($BusinessInfo['WorkPhone']) ? $BusinessInfo['WorkPhone'] : '';
        $BusinessAddress = isset($DataArray['BusinessAddress']) ? $DataArray['BusinessAddress'] : array();
        $BusinessAddressLine1 = isset($BusinessAddress['Line1']) ? $BusinessAddress['Line1'] : '';
        $BusinessAddressLine2 = isset($BusinessAddress['Line2']) ? $BusinessAddress['Line2'] : '';
        $BusinessAddressCity = isset($BusinessAddress['City']) ? $BusinessAddress['City'] : '';
        $BusinessAddressState = isset($BusinessAddress['State']) ? $BusinessAddress['State'] : '';
        $BusinessAddressPostalCode = isset($BusinessAddress['PostalCode']) ? $BusinessAddress['PostalCode'] : '';
        $BusinessAddressCountryCode = isset($BusinessAddress['CountryCode']) ? $BusinessAddress['CountryCode'] : '';
        $PrinciplePlaceOfBusinessAddress = isset($DataArray['PrinciplePlaceOfBusinessAddress']) ? $DataArray['PrinciplePlaceOfBusinessAddress'] : array();
        $PrinciplePlaceOfBusinessAddressLine1 = isset($PrinciplePlaceOfBusinessAddress['Line1']) ? $PrinciplePlaceOfBusinessAddress['Line1'] : '';
        $PrinciplePlaceOfBusinessAddressLine2 = isset($PrinciplePlaceOfBusinessAddress['Line2']) ? $PrinciplePlaceOfBusinessAddress['Line2'] : '';
        $PrinciplePlaceOfBusinessAddressCity = isset($PrinciplePlaceOfBusinessAddress['City']) ? $PrinciplePlaceOfBusinessAddress['City'] : '';
        $PrinciplePlaceOfBusinessAddressState = isset($PrinciplePlaceOfBusinessAddress['State']) ? $PrinciplePlaceOfBusinessAddress['State'] : '';
        $PrinciplePlaceOfBusinessAddressPostalCode = isset($PrinciplePlaceOfBusinessAddress['PostalCode']) ? $PrinciplePlaceOfBusinessAddress['PostalCode'] : '';
        $PrinciplePlaceOfBusinessAddressCountryCode = isset($PrinciplePlaceOfBusinessAddress['CountryCode']) ? $PrinciplePlaceOfBusinessAddress['CountryCode'] : '';
        $RegisteredOfficeAddress = isset($DataArray['RegisteredOfficeAddress']) ? $DataArray['RegisteredOfficeAddress'] : array();
        $RegisteredOfficeAddressLine1 = isset($RegisteredOfficeAddress['Line1']) ? $RegisteredOfficeAddress['Line1'] : '';
        $RegisteredOfficeAddressLine2 = isset($RegisteredOfficeAddress['Line2']) ? $RegisteredOfficeAddress['Line2'] : '';
        $RegisteredOfficeAddressCity = isset($RegisteredOfficeAddress['City']) ? $RegisteredOfficeAddress['City'] : '';
        $RegisteredOfficeAddressState = isset($RegisteredOfficeAddress['State']) ? $RegisteredOfficeAddress['State'] : '';
        $RegisteredOfficeAddressPostalCode = isset($RegisteredOfficeAddress['PostalCode']) ? $RegisteredOfficeAddress['PostalCode'] : '';
        $RegisteredOfficeAddressCountryCode = isset($RegisteredOfficeAddress['CountryCode']) ? $RegisteredOfficeAddress['CountryCode'] : '';
        $BusinessStakeHolder = isset($DataArray['BusinessStakeHolder']) ? $DataArray['BusinessStakeHolder'] : array();
        $BusinessStakeHolderDateOfBirth = isset($BusinessStakeHolder['DateOfBirth']) ? $BusinessStakeHolder['DateOfBirth'] : '';
        $BusinessStakeHolderFullLegalName = isset($BusinessStakeHolder['FullLegalName']) ? $BusinessStakeHolder['FullLegalName'] : '';
        $BusinessStakeHolderSalutation = isset($BusinessStakeHolder['Salutation']) ? $BusinessStakeHolder['Salutation'] : '';
        $BusinessStakeHolderFirstName = isset($BusinessStakeHolder['FirstName']) ? $BusinessStakeHolder['FirstName'] : '';
        $BusinessStakeHolderMiddleName = isset($BusinessStakeHolder['MiddleName']) ? $BusinessStakeHolder['MiddleName'] : '';
        $BusinessStakeHolderLastName = isset($BusinessStakeHolder['LastName']) ? $BusinessStakeHolder['LastName'] : '';
        $BusinessStakeHolderSuffix = isset($BusinessStakeHolder['Suffix']) ? $BusinessStakeHolder['Suffix'] : '';
        $BusinessStakeHolderRole = isset($BusinessStakeHolder['Role']) ? $BusinessStakeHolder['Role'] : '';
        $BusinessStakeHolderCountryCode = isset($BusinessStakeHolder['CountryCode']) ? $BusinessStakeHolder['CountryCode'] : '';
        $BusinessStakeHolderAddress = isset($DataArray['BusinessStakeHolderAddress']) ? $DataArray['BusinessStakeHolderAddress'] : array();
        $BusinessStakeHolderAddressLine1 = isset($BusinessStakeHolderAddress['Line1']) ? $BusinessStakeHolderAddress['Line1'] : '';
        $BusinessStakeHolderAddressLine2 = isset($BusinessStakeHolderAddress['Line2']) ? $BusinessStakeHolderAddress['Line2'] : '';
        $BusinessStakeHolderAddressCity = isset($BusinessStakeHolderAddress['City']) ? $BusinessStakeHolderAddress['City'] : '';
        $BusinessStakeHolderAddressState = isset($BusinessStakeHolderAddress['State']) ? $BusinessStakeHolderAddress['State'] : '';
        $BusinessStakeHolderAddressPostalCode = isset($BusinessStakeHolderAddress['PostalCode']) ? $BusinessStakeHolderAddress['PostalCode'] : '';
        $BusinessStakeHolderAddressCountryCode = isset($BusinessStakeHolderAddress['CountryCode']) ? $BusinessStakeHolderAddress['CountryCode'] : '';
        $PartnerFields = isset($DataArray['PartnerFields']) ? $DataArray['PartnerFields'] : array();
        $PartnerField1 = isset($PartnerFields['Field1']) ? $PartnerFields['Field1'] : '';
        $PartnerField2 = isset($PartnerFields['Field2']) ? $PartnerFields['Field2'] : '';
        $PartnerField3 = isset($PartnerFields['Field3']) ? $PartnerFields['Field3'] : '';
        $PartnerField4 = isset($PartnerFields['Field4']) ? $PartnerFields['Field4'] : '';
        $PartnerField5 = isset($PartnerFields['Field5']) ? $PartnerFields['Field5'] : '';
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= $AccountType != '' ? '' . $AccountType . '' : '';
        $XMLRequest .= $EmailAddress != '' ? '' . $EmailAddress . '' : '';
        if ($Salutation != '' || $FirstName != '' || $MiddleName != '' || $LastName != '' || $Suffix != '') {
            $XMLRequest .= '';
            $XMLRequest .= $Salutation != '' ? '' . $Salutation . '' : '';
            $XMLRequest .= $FirstName != '' ? '' . $FirstName . '' : '';
            $XMLRequest .= $MiddleName != '' ? '' . $MiddleName . '' : '';
            $XMLRequest .= $LastName != '' ? '' . $LastName . '' : '';
            $XMLRequest .= $Suffix != '' ? '' . $Suffix . '' : '';
            $XMLRequest .= '';
        }
        $XMLRequest .= $DateOfBirth != '' ? '' . $DateOfBirth . '' : '';
        if (!empty($Address)) {
            $XMLRequest .= '';
            $XMLRequest .= $Line1 != '' ? '' . $Line1 . '' : '';
            $XMLRequest .= $Line2 != '' ? '' . $Line2 . '' : '';
            $XMLRequest .= $City != '' ? '' . $City . '' : '';
            $XMLRequest .= $State != '' ? '' . $State . '' : '';
            $XMLRequest .= $PostalCode != '' ? '' . $PostalCode . '' : '';
            $XMLRequest .= $CountryCode != '' ? '' . $CountryCode . '' : '';
            $XMLRequest .= '';
        }
        $XMLRequest .= $ContactPhoneNumber != '' ? '' . $ContactPhoneNumber . '' : '';
        $XMLRequest .= $HomePhoneNumber != '' ? '' . $HomePhoneNumber . '' : '';
        $XMLRequest .= $MobilePhoneNumber != '' ? '' . $MobilePhoneNumber . '' : '';
        $XMLRequest .= $CurrencyCode != '' ? '' . $CurrencyCode . '' : '';
        $XMLRequest .= $CitizenshipCountryCode != '' ? '' . $CitizenshipCountryCode . '' : '';
        $XMLRequest .= $PreferredLanguageCode != '' ? '' . $PreferredLanguageCode . '' : '';
        $XMLRequest .= $NotificationURL != '' ? '' . $NotificationURL . '' : '';
        $XMLRequest .= $PartnerField1 != '' ? '' . $PartnerField1 . '' : '';
        $XMLRequest .= $PartnerField2 != '' ? '' . $PartnerField2 . '' : '';
        $XMLRequest .= $PartnerField3 != '' ? '' . $PartnerField3 . '' : '';
        $XMLRequest .= $PartnerField4 != '' ? '' . $PartnerField4 . '' : '';
        $XMLRequest .= $PartnerField5 != '' ? '' . $PartnerField5 . '' : '';
        $XMLRequest .= $RegistrationType != '' ? '' . $RegistrationType . '' : '';
        $XMLRequest .= $SuppressWelcomeEmail != '' ? '' . $SuppressWelcomeEmail . '' : '';
        $XMLRequest .= $PerformExtraVettingOnThisAccount != '' ? '' . $PerformExtraVettingOnThisAccount . '' : '';
        $XMLRequest .= $TaxID != '' ? '' . $TaxID . '' : '';
        if ($ReturnURL != '' || $ReturnURLDescription != '' || $ShowAddCreditCard != '' || $ShowMobileConfirm != '' || $UseMiniBrowser != '') {
            $XMLRequest .= '';
            $XMLRequest .= $ReturnURL != '' ? '' . $ReturnURL . '' : '';
            $XMLRequest .= $ReturnURLDescription != '' ? '' . $ReturnURLDescription . '' : '';
            $XMLRequest .= $ShowAddCreditCard != '' ? '' . $ShowAddCreditCard . '' : '';
            $XMLRequest .= $ShowMobileConfirm != '' ? '' . $ShowMobileConfirm . '' : '';
            $XMLRequest .= $UseMiniBrowser != '' ? '' . $UseMiniBrowser . '' : '';
            $XMLRequest .= '';
        }
        if (!empty($BusinessInfo)) {
            $XMLRequest .= '';
            $XMLRequest .= $BusinessName != '' ? '' . $BusinessName . '' : '';
            if (!empty($BusinessAddress)) {
                $XMLRequest .= '';
                $XMLRequest .= $BusinessAddressLine1 != '' ? '' . $BusinessAddressLine1 . '' : '';
                $XMLRequest .= $BusinessAddressLine2 != '' ? '' . $BusinessAddressLine2 . '' : '';
                $XMLRequest .= $BusinessAddressCity != '' ? '' . $BusinessAddressCity . '' : '';
                $XMLRequest .= $BusinessAddressState != '' ? '' . $BusinessAddressState . '' : '';
                $XMLRequest .= $BusinessAddressPostalCode != '' ? '' . $BusinessAddressPostalCode . '' : '';
                $XMLRequest .= $BusinessAddressCountryCode != '' ? '' . $BusinessAddressCountryCode . '' : '';
                $XMLRequest .= '';
            }
            $XMLRequest .= $WorkPhone != '' ? '' . $WorkPhone . '' : '';
            $XMLRequest .= $Category != '' ? '' . $Category . '' : '';
            $XMLRequest .= $SubCategory != '' ? '' . $SubCategory . '' : '';
            $XMLRequest .= $MerchantCategoryCode != '' ? '' . $MerchantCategoryCode . '' : '';
            $XMLRequest .= $DoingBusinessAs != '' ? '' . $DoingBusinessAs . '' : '';
            $XMLRequest .= $CustomerServicePhone != '' ? '' . $CustomerServicePhone . '' : '';
            $XMLRequest .= $CustomerServiceEmail != '' ? '' . $CustomerServiceEmail . '' : '';
            $XMLRequest .= $DisputeEmail != '' ? '' . $DisputeEmail . '' : '';
            $XMLRequest .= $WebSite != '' ? '' . $WebSite . '' : '';
            $XMLRequest .= $CompanyID != '' ? '' . $CompanyID . '' : '';
            $XMLRequest .= $DateOfEstablishment != '' ? '' . $DateOfEstablishment . '' : '';
            $XMLRequest .= $BusinessType != '' ? '' . $BusinessType . '' : '';
            $XMLRequest .= $BusinessSubType != '' ? '' . $BusinessSubType . '' : '';
            $XMLRequest .= $IncorporationID != '' ? '' . $IncorporationID . '' : '';
            $XMLRequest .= $AveragePrice != '' ? '' . $AveragePrice . '' : '';
            $XMLRequest .= $AverageMonthlyVolume != '' ? '' . $AverageMonthlyVolume . '' : '';
            $XMLRequest .= $PercentageRevenueFromOnline != '' ? '' . $PercentageRevenueFromOnline . '' : '';
            $XMLRequest .= $SalesVenu != '' ? '' . $SalesVenu . '' : '';
            $XMLRequest .= $SalesVenuDesc != '' ? '' . $SalesVenuDesc . '' : '';
            $XMLRequest .= $VatID != '' ? '' . $VatID . '' : '';
            $XMLRequest .= $VatCountryCode != '' ? '' . $VatCountryCode . '' : '';
            $XMLRequest .= $CommercialRegistrationLocation != '' ? '' . $CommercialRegistrationLocation . '' : '';
            if (!empty($PrinciplePlaceOfBusinessAddress)) {
                $XMLRequest .= '';
                $XMLRequest .= $PrinciplePlaceOfBusinessAddressLine1 != '' ? '' . $PrinciplePlaceOfBusinessAddressLine1 . '' : '';
                $XMLRequest .= $PrinciplePlaceOfBusinessAddressLine2 != '' ? '' . $PrinciplePlaceOfBusinessAddressLine2 . '' : '';
                $XMLRequest .= $PrinciplePlaceOfBusinessAddressCity != '' ? '' . $PrinciplePlaceOfBusinessAddressCity . '' : '';
                $XMLRequest .= $PrinciplePlaceOfBusinessAddressState != '' ? '' . $PrinciplePlaceOfBusinessAddressState . '' : '';
                $XMLRequest .= $PrinciplePlaceOfBusinessAddressPostalCode != '' ? '' . $PrinciplePlaceOfBusinessAddressPostalCode . '' : '';
                $XMLRequest .= $PrinciplePlaceOfBusinessAddressCountryCode != '' ? '' . $PrinciplePlaceOfBusinessAddressCountryCode . '' : '';
                $XMLRequest .= '';
            }
            if (!empty($RegisteredOfficeAddress)) {
                $XMLRequest .= '';
                $XMLRequest .= $RegisteredOfficeAddressLine1 != '' ? '' . $RegisteredOfficeAddressLine1 . '' : '';
                $XMLRequest .= $RegisteredOfficeAddressLine2 != '' ? '' . $RegisteredOfficeAddressLine2 . '' : '';
                $XMLRequest .= $RegisteredOfficeAddressCity != '' ? '' . $RegisteredOfficeAddressCity . '' : '';
                $XMLRequest .= $RegisteredOfficeAddressState != '' ? '' . $RegisteredOfficeAddressState . '' : '';
                $XMLRequest .= $RegisteredOfficeAddressPostalCode != '' ? '' . $RegisteredOfficeAddressPostalCode . '' : '';
                $XMLRequest .= $RegisteredOfficeAddressCountryCode != '' ? '' . $RegisteredOfficeAddressCountryCode . '' : '';
                $XMLRequest .= '';
            }
            $XMLRequest .= $EstablishmentCountryCode != '' ? '' . $EstablishmentCountryCode . '' : '';
            $XMLRequest .= $EstablishmentState != '' ? '' . $EstablishmentState . '' : '';
            if (!empty($BusinessStakeHolder)) {
                $XMLRequest .= '';
                $XMLRequest .= $BusinessStakeHolderRole != '' ? '' . $BusinessStakeHolderRole . '' : '';
                if ($BusinessStakeHolderSalutation != '' || $BusinessStakeHolderFirstName != '' || $BusinessStakeHolderMiddleName != '' || $BusinessStakeHolderLastName != '' || $BusinessStakeHolderSuffix != '') {
                    $XMLRequest .= '';
                    $XMLRequest .= $BusinessStakeHolderSalutation != '' ? '' . $BusinessStakeHolderSalutation . '' : '';
                    $XMLRequest .= $BusinessStakeHolderFirstName != '' ? '' . $BusinessStakeHolderFirstName . '' : '';
                    $XMLRequest .= $BusinessStakeHolderMiddleName != '' ? '' . $BusinessStakeHolderMiddleName . '' : '';
                    $XMLRequest .= $BusinessStakeHolderLastName != '' ? '' . $BusinessStakeHolderLastName . '' : '';
                    $XMLRequest .= $BusinessStakeHolderSuffix != '' ? '' . $BusinessStakeHolderSuffix . '' : '';
                    $XMLRequest .= '';
                }
                $XMLRequest .= $BusinessStakeHolderFullLegalName != '' ? '' . $BusinessStakeHolderFullLegalName . '' : '';
                if (!empty($BusinessStakeHolderAddress)) {
                    $XMLRequest .= '';
                    $XMLRequest .= $BusinessStakeHolderAddressLine1 != '' ? '' . $BusinessStakeHolderAddressLine1 . '' : '';
                    $XMLRequest .= $BusinessStakeHolderAddressLine2 != '' ? '' . $BusinessStakeHolderAddressLine2 . '' : '';
                    $XMLRequest .= $BusinessStakeHolderAddressCity != '' ? '' . $BusinessStakeHolderAddressCity . '' : '';
                    $XMLRequest .= $BusinessStakeHolderAddressState != '' ? '' . $BusinessStakeHolderAddressState . '' : '';
                    $XMLRequest .= $BusinessStakeHolderAddressPostalCode != '' ? '' . $BusinessStakeHolderAddressPostalCode . '' : '';
                    $XMLRequest .= $BusinessStakeHolderAddressCountryCode != '' ? '' . $BusinessStakeHolderAddressCountryCode . '' : '';
                    $XMLRequest .= '';
                }
                $XMLRequest .= $BusinessStakeHolderDateOfBirth != '' ? '' . $BusinessStakeHolderDateOfBirth . '' : '';
                $XMLRequest .= '';
            }
            $XMLRequest .= '';
        }
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'AdaptiveAccounts', 'CreateAccount');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $AccountID = $DOM->getElementsByTagName('accountId')->length > 0 ? $DOM->getElementsByTagName('accountId')->item(0)->nodeValue : '';
        $CreateAccountKey = $DOM->getElementsByTagName('createAccountKey')->length > 0 ? $DOM->getElementsByTagName('createAccountKey')->item(0)->nodeValue : '';
        $ExecStatus = $DOM->getElementsByTagName('execStatus')->length > 0 ? $DOM->getElementsByTagName('execStatus')->item(0)->nodeValue : '';
        $RedirectURL = $DOM->getElementsByTagName('redirectURL')->length > 0 ? $DOM->getElementsByTagName('redirectURL')->item(0)->nodeValue : '';
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'AccountID' => $AccountID,
            'CreateAccountKey' => $CreateAccountKey,
            'ExecStatus' => $ExecStatus,
            'RedirectURL' => $RedirectURL,
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit AddBankAccount API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function AddBankAccount($DataArray) {
        $AddBankAccountFields = isset($DataArray['AddBankAccountFields']) ? $DataArray['AddBankAccountFields'] : array();
        $EmailAddress = isset($AddBankAccountFields['EmailAddress']) ? $AddBankAccountFields['EmailAddress'] : '';
        $AccountID = isset($AddBankAccountFields['AccountID']) ? $AddBankAccountFields['AccountID'] : '';
        $CreateAccountKey = isset($AddBankAccountFields['CreateAccountKey']) ? $AddBankAccountFields['CreateAccountKey'] : '';
        $BankCountryCode = isset($AddBankAccountFields['BankCountryCode']) ? $AddBankAccountFields['BankCountryCode'] : '';
        $BankName = isset($AddBankAccountFields['BankName']) ? $AddBankAccountFields['BankName'] : '';
        $RoutingNumber = isset($AddBankAccountFields['RoutingNumber']) ? $AddBankAccountFields['RoutingNumber'] : '';
        $BankAccountType = isset($AddBankAccountFields['BankAccountType']) ? $AddBankAccountFields['BankAccountType'] : '';
        $BankAccountNumber = isset($AddBankAccountFields['BankAccountNumber']) ? $AddBankAccountFields['BankAccountNumber'] : '';
        $IBAN = isset($AddBankAccountFields['IBAN']) ? $AddBankAccountFields['IBAN'] : '';
        $CLABE = isset($AddBankAccountFields['CLABE']) ? $AddBankAccountFields['CLABE'] : '';
        $BSBNumber = isset($AddBankAccountFields['BSBNumber']) ? $AddBankAccountFields['BSBNumber'] : '';
        $BranchLocation = isset($AddBankAccountFields['BranchLocation']) ? $AddBankAccountFields['BranchLocation'] : '';
        $SortCode = isset($AddBankAccountFields['SortCode']) ? $AddBankAccountFields['SortCode'] : '';
        $BankTransitNumber = isset($AddBankAccountFields['BankTransitNumber']) ? $AddBankAccountFields['BankTransitNumber'] : '';
        $InstitutionNumber = isset($AddBankAccountFields['InstitutionNumber']) ? $AddBankAccountFields['InstitutionNumber'] : '';
        $BranchCode = isset($AddBankAccountFields['BranchCode']) ? $AddBankAccountFields['BranchCode'] : '';
        $AgencyNumber = isset($AddBankAccountFields['AgencyNumber']) ? $AddBankAccountFields['AgencyNumber'] : '';
        $BankCode = isset($AddBankAccountFields['BankCode']) ? $AddBankAccountFields['BankCode'] : '';
        $RibKey = isset($AddBankAccountFields['RibKey']) ? $AddBankAccountFields['RibKey'] : '';
        $ControlDigit = isset($AddBankAccountFields['ControlDigit']) ? $AddBankAccountFields['ControlDigit'] : '';
        $TaxIDType = isset($AddBankAccountFields['TaxIDType']) ? $AddBankAccountFields['TaxIDType'] : '';
        $TaxIDNumber = isset($AddBankAccountFields['TaxIDNumber']) ? $AddBankAccountFields['TaxIDNumber'] : '';
        $AccountHolderDateOfBirth = isset($AddBankAccountFields['AccountHolderDateOfBirth']) ? $AddBankAccountFields['AccountHolderDateOfBirth'] : '';
        $ConfirmationType = isset($AddBankAccountFields['ConfirmationType']) ? $AddBankAccountFields['ConfirmationType'] : '';
        $WebOptions = isset($DataArray['WebOptions']) ? $DataArray['WebOptions'] : array();
        $ReturnURL = isset($WebOptions['ReturnURL']) ? $WebOptions['ReturnURL'] : '';
        $CancelURL = isset($WebOptions['CancelURL']) ? $WebOptions['CancelURL'] : '';
        $ReturnURLDescription = isset($WebOptions['ReturnURLDescription']) ? $WebOptions['ReturnURLDescription'] : '';
        $CancelURLDescription = isset($WebOptions['CancelURLDescription']) ? $WebOptions['CancelURLDescription'] : '';
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= $EmailAddress != '' ? '' . $EmailAddress . '' : '';
        $XMLRequest .= $AccountID != '' ? '' . $AccountID . '' : '';
        $XMLRequest .= $CreateAccountKey != '' ? '' . $CreateAccountKey . '' : '';
        $XMLRequest .= $BankCountryCode != '' ? '' . $BankCountryCode . '' : '';
        $XMLRequest .= $BankName != '' ? '' . $BankName . '' : '';
        $XMLRequest .= $RoutingNumber != '' ? '' . $RoutingNumber . '' : '';
        $XMLRequest .= $BankAccountType != '' ? '' . $BankAccountType . '' : '';
        $XMLRequest .= $BankAccountNumber != '' ? '' . $BankAccountNumber . '' : '';
        $XMLRequest .= $IBAN != '' ? '' . $IBAN . '' : '';
        $XMLRequest .= $CLABE != '' ? '' . $CLABE . '' : '';
        $XMLRequest .= $BSBNumber != '' ? '' . $BSBNumber . '' : '';
        $XMLRequest .= $BranchLocation != '' ? '' . $BranchLocation . '' : '';
        $XMLRequest .= $SortCode != '' ? '' . $SortCode . '' : '';
        $XMLRequest .= $BankTransitNumber != '' ? '' . $BankTransitNumber . '' : '';
        $XMLRequest .= $InstitutionNumber != '' ? '' . $InstitutionNumber . '' : '';
        $XMLRequest .= $BranchCode != '' ? '' . $BranchCode . '' : '';
        $XMLRequest .= $AgencyNumber != '' ? '' . $AgencyNumber . '' : '';
        $XMLRequest .= $BankCode != '' ? '' . $BankCode . '' : '';
        $XMLRequest .= $RibKey != '' ? '' . $RibKey . '' : '';
        $XMLRequest .= $ControlDigit != '' ? '' . $ControlDigit . '' : '';
        $XMLRequest .= $TaxIDType != '' ? '' . $TaxIDType . '' : '';
        $XMLRequest .= $TaxIDNumber != '' ? '' . $TaxIDNumber . '' : '';
        $XMLRequest .= $AccountHolderDateOfBirth != '' ? '' . $AccountHolderDateOfBirth . '' : '';
        $XMLRequest .= $ConfirmationType != '' ? '' . $ConfirmationType . '' : '';
        if (!empty($WebOptions)) {
            $XMLRequest .= '';
            $XMLRequest .= $ReturnURL != '' ? '' . $ReturnURL . '' : '';
            $XMLRequest .= $CancelURL != '' ? '' . $CancelURL . '' : '';
            $XMLRequest .= $ReturnURLDescription != '' ? '' . $ReturnURLDescription . '' : '';
            $XMLRequest .= $CancelURLDescription != '' ? '' . $CancelURLDescription . '' : '';
            $XMLRequest .= '';
        }
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'AdaptiveAccounts', 'AddBankAccount');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $ExecStatus = $DOM->getElementsByTagName('execStatus')->length > 0 ? $DOM->getElementsByTagName('execStatus')->item(0)->nodeValue : '';
        $FundingSourceKey = $DOM->getElementsByTagName('fundingSourceKey')->length > 0 ? $DOM->getElementsByTagName('fundingSourceKey')->item(0)->nodeValue : '';
        $RedirectURL = $DOM->getElementsByTagName('redirectURL')->length > 0 ? $DOM->getElementsByTagName('redirectURL')->item(0)->nodeValue : '';
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'ExecStatus' => $ExecStatus,
            'FundingSourceKey' => $FundingSourceKey,
            'RedirectURL' => $RedirectURL,
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit AddPaymentCard API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function AddPaymentCard($DataArray) {
        $AddPaymentCardFields = isset($DataArray['AddPaymentCardFields']) ? $DataArray['AddPaymentCardFields'] : array();
        $EmailAddress = isset($AddPaymentCardFields['EmailAddress']) ? $AddPaymentCardFields['EmailAddress'] : '';
        $AccountID = isset($AddPaymentCardFields['AccountID']) ? $AddPaymentCardFields['AccountID'] : '';
        $CreateAccountKey = isset($AddPaymentCardFields['CreateAccountKey']) ? $AddPaymentCardFields['CreateAccountKey'] : '';
        $CardOwnerDateOfBirth = isset($AddPaymentCardFields['CardOwnerDateOfBirth']) ? $AddPaymentCardFields['CardOwnerDateOfBirth'] : '';
        $CardNumber = isset($AddPaymentCardFields['CardNumber']) ? $AddPaymentCardFields['CardNumber'] : '';
        $CardType = isset($AddPaymentCardFields['CardType']) ? $AddPaymentCardFields['CardType'] : '';
        $CardVerificationNumber = isset($AddPaymentCardFields['CardVerificationNumber']) ? $AddPaymentCardFields['CardVerificationNumber'] : '';
        $StartDate = isset($AddPaymentCardFields['StartDate']) ? $AddPaymentCardFields['StartDate'] : '';
        $IssueNumber = isset($AddPaymentCardFields['IssueNumber']) ? $AddPaymentCardFields['IssueNumber'] : '';
        $ConfirmationType = isset($AddPaymentCardFields['ConfirmationType']) ? $AddPaymentCardFields['ConfirmationType'] : '';
        $NameOnCard = isset($DataArray['NameOnCard']) ? $DataArray['NameOnCard'] : array();
        $Salutation = isset($NameOnCard['Salutation']) ? $NameOnCard['Salutation'] : '';
        $FirstName = isset($NameOnCard['FirstName']) ? $NameOnCard['FirstName'] : '';
        $MiddleName = isset($NameOnCard['MiddleName']) ? $NameOnCard['MiddleName'] : '';
        $LastName = isset($NameOnCard['LastName']) ? $NameOnCard['LastName'] : '';
        $Suffix = isset($NameOnCard['Suffix']) ? $NameOnCard['Suffix'] : '';
        $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array();
        $Line1 = isset($BillingAddress['Line1']) ? $BillingAddress['Line1'] : '';
        $Line2 = isset($BillingAddress['Line2']) ? $BillingAddress['Line2'] : '';
        $City = isset($BillingAddress['City']) ? $BillingAddress['City'] : '';
        $State = isset($BillingAddress['State']) ? $BillingAddress['State'] : '';
        $PostalCode = isset($BillingAddress['PostalCode']) ? $BillingAddress['PostalCode'] : '';
        $CountryCode = isset($BillingAddress['CountryCode']) ? $BillingAddress['CountryCode'] : '';
        $ExpirationDate = isset($DataArray['ExpirationDate']) ? $DataArray['ExpirationDate'] : array();
        $Month = isset($ExpirationDate['Month']) ? $ExpirationDate['Month'] : '';
        $Year = isset($ExpirationDate['Year']) ? $ExpirationDate['Year'] : '';
        $WebOptions = isset($DataArray['WebOptions']) ? $DataArray['WebOptions'] : array();
        $ReturnURL = isset($WebOptions['ReturnURL']) ? $WebOptions['ReturnURL'] : '';
        $CancelURL = isset($WebOptions['CancelURL']) ? $WebOptions['CancelURL'] : '';
        $ReturnURLDescription = isset($WebOptions['ReturnURLDescription']) ? $WebOptions['ReturnURLDescription'] : '';
        $CancelURLDescription = isset($WebOptions['CancelURLDescription']) ? $WebOptions['CancelURLDescription'] : '';
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= $EmailAddress != '' ? '' . $EmailAddress . '' : '';
        $XMLRequest .= $AccountID != '' ? '' . $AccountID . '' : '';
        $XMLRequest .= $CreateAccountKey != '' ? '' . $CreateAccountKey . '' : '';
        if (!empty($NameOnCard)) {
            $XMLRequest .= '';
            $XMLRequest .= $Salutation != '' ? '' . $Salutation . '' : '';
            $XMLRequest .= $FirstName != '' ? '' . $FirstName . '' : '';
            $XMLRequest .= $MiddleName != '' ? '' . $MiddleName . '' : '';
            $XMLRequest .= $LastName != '' ? '' . $LastName . '' : '';
            $XMLRequest .= $Suffix != '' ? '' . $Suffix . '' : '';
            $XMLRequest .= '';
        }
        if (!empty($BillingAddress)) {
            $XMLRequest .= '';
            $XMLRequest .= $Line1 != '' ? '' . $Line1 . '' : '';
            $XMLRequest .= $Line2 != '' ? '' . $Line2 . '' : '';
            $XMLRequest .= $City != '' ? '' . $City . '' : '';
            $XMLRequest .= $State != '' ? '' . $State . '' : '';
            $XMLRequest .= $PostalCode != '' ? '' . $PostalCode . '' : '';
            $XMLRequest .= $CountryCode != '' ? '' . $CountryCode . '' : '';
            $XMLRequest .= '';
        }
        $XMLRequest .= $CardOwnerDateOfBirth != '' ? '' . $CardOwnerDateOfBirth . '' : '';
        $XMLRequest .= $CardNumber != '' ? '' . $CardNumber . '' : '';
        $XMLRequest .= $CardType != '' ? '' . $CardType . '' : '';
        if (!empty($ExpirationDate)) {
            $XMLRequest .= '';
            $XMLRequest .= $Month != '' ? '' . $Month . '' : '';
            $XMLRequest .= $Year != '' ? '' . $Year . '' : '';
            $XMLRequest .= '';
        }
        $XMLRequest .= $CardVerificationNumber != '' ? '' . $CardVerificationNumber . '' : '';
        $XMLRequest .= $StartDate != '' ? '' . $StartDate . '' : '';
        $XMLRequest .= $IssueNumber != '' ? '' . $IssueNumber . '' : '';
        $XMLRequest .= $ConfirmationType != '' ? '' . $ConfirmationType . '' : '';
        if (!empty($WebOptions)) {
            $XMLRequest .= '';
            $XMLRequest .= $ReturnURL != '' ? '' . $ReturnURL . '' : '';
            $XMLRequest .= $CancelURL != '' ? '' . $CancelURL . '' : '';
            $XMLRequest .= $ReturnURLDescription != '' ? '' . $ReturnURLDescription . '' : '';
            $XMLRequest .= $CancelURLDescription != '' ? '' . $CancelURLDescription . '' : '';
            $XMLRequest .= '';
        }
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'AdaptiveAccounts', 'AddPaymentCard');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $ExecStatus = $DOM->getElementsByTagName('execStatus')->length > 0 ? $DOM->getElementsByTagName('execStatus')->item(0)->nodeValue : '';
        $FundingSourceKey = $DOM->getElementsByTagName('fundingSourceKey')->length > 0 ? $DOM->getElementsByTagName('fundingSourceKey')->item(0)->nodeValue : '';
        $RedirectURL = $DOM->getElementsByTagName('redirectURL')->length > 0 ? $DOM->getElementsByTagName('redirectURL')->item(0)->nodeValue : '';
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'ExecStatus' => $ExecStatus,
            'FundingSourceKey' => $FundingSourceKey,
            'RedirectURL' => $RedirectURL,
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit SetFundingSourceConfirmed API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function SetFundingSourceConfirmed($DataArray) {
        $SetFundingSourceConfirmedFields = isset($DataArray['SetFundingSourceConfirmedFields']) ? $DataArray['SetFundingSourceConfirmedFields'] : array();
        $EmailAddress = isset($SetFundingSourceConfirmedFields['EmailAddress']) ? $SetFundingSourceConfirmedFields['EmailAddress'] : '';
        $AccountID = isset($SetFundingSourceConfirmedFields['AccountID']) ? $SetFundingSourceConfirmedFields['AccountID'] : '';
        $FundingSourceKey = isset($SetFundingSourceConfirmedFields['FundingSourceKey']) ? $SetFundingSourceConfirmedFields['FundingSourceKey'] : '';
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= $EmailAddress != '' ? '' . $EmailAddress . '' : '';
        $XMLRequest .= $AccountID != '' ? '' . $AccountID . '' : '';
        $XMLRequest .= $FundingSourceKey != '' ? '' . $FundingSourceKey . '' : '';
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'AdaptiveAccounts', 'SetFundingSourceConfirmed');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit GetVerifiedStatus API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function GetVerifiedStatus($DataArray) {
        $GetVerifiedStatusFields = isset($DataArray['GetVerifiedStatusFields']) ? $DataArray['GetVerifiedStatusFields'] : array();
        $EmailAddress = isset($GetVerifiedStatusFields['EmailAddress']) ? $GetVerifiedStatusFields['EmailAddress'] : '';
        $MatchCriteria = isset($GetVerifiedStatusFields['MatchCriteria']) ? $GetVerifiedStatusFields['MatchCriteria'] : '';
        $FirstName = isset($GetVerifiedStatusFields['FirstName']) ? $GetVerifiedStatusFields['FirstName'] : '';
        $LastName = isset($GetVerifiedStatusFields['LastName']) ? $GetVerifiedStatusFields['LastName'] : '';
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= $EmailAddress != '' ? '' . $EmailAddress . '' : '';
        $XMLRequest .= $MatchCriteria != '' ? '' . $MatchCriteria . '' : '';
        $XMLRequest .= $FirstName != '' ? '' . $FirstName . '' : '';
        $XMLRequest .= $LastName != '' ? '' . $LastName . '' : '';
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'AdaptiveAccounts', 'GetVerifiedStatus');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $AccountStatus = $DOM->getElementsByTagName('accountStatus')->length > 0 ? $DOM->getElementsByTagName('accountStatus')->item(0)->nodeValue : '';
        $CountryCode = $DOM->getElementsByTagName('countryCode')->length > 0 ? $DOM->getElementsByTagName('countryCode')->item(0)->nodeValue : '';
        $EmailAddress = $DOM->getElementsByTagName('emailAddress')->length > 0 ? $DOM->getElementsByTagName('emailAddress')->item(0)->nodeValue : '';
        $AccountID = $DOM->getElementsByTagName('accountId')->length > 0 ? $DOM->getElementsByTagName('accountId')->item(0)->nodeValue : '';
        $AccountType = $DOM->getElementsByTagName('accountType')->length > 0 ? $DOM->getElementsByTagName('accountType')->item(0)->nodeValue : '';
        $BusinessName = $DOM->getElementsByTagName('businessName')->length > 0 ? $DOM->getElementsByTagName('businessName')->item(0)->nodeValue : '';
        $Salutation = $DOM->getElementsByTagName('salutation')->length > 0 ? $DOM->getElementsByTagName('salutation')->item(0)->nodeValue : '';
        $FirstName = $DOM->getElementsByTagName('firstName')->length > 0 ? $DOM->getElementsByTagName('firstName')->item(0)->nodeValue : '';
        $MiddleName = $DOM->getElementsByTagName('middleName')->length > 0 ? $DOM->getElementsByTagName('middleName')->item(0)->nodeValue : '';
        $LastName = $DOM->getElementsByTagName('lastName')->length > 0 ? $DOM->getElementsByTagName('lastName')->item(0)->nodeValue : '';
        $Suffix = $DOM->getElementsByTagName('suffix')->length > 0 ? $DOM->getElementsByTagName('suffix')->item(0)->nodeValue : '';
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'AccountStatus' => $AccountStatus,
            'CountryCode' => $CountryCode,
            'EmailAddress' => $EmailAddress,
            'AccountID' => $AccountID,
            'BusinessName' => $BusinessName,
            'Salutation' => $Salutation,
            'FirstName' => $FirstName,
            'MiddleName' => $MiddleName,
            'LastName' => $LastName,
            'Suffix' => $Suffix,
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit GetFundingPlans API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function GetFundingPlans($DataArray) {
        $GetFundingPlansFields = isset($DataArray['GetFundingPlansFields']) ? $DataArray['GetFundingPlansFields'] : array();
        $PayKey = isset($GetFundingPlansFields['PayKey']) ? $GetFundingPlansFields['PayKey'] : '';
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= $PayKey != '' ? '' . $PayKey . '' : '';
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'AdaptiveAccounts', 'GetFundingPlans');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $FundingPlanType = $DOM->getElementsByTagName('fundingPlan')->length > 0 ? $DOM->getElementsByTagName('fundingPlan') : array();
        foreach ($FundingPlanType as $FundingPlan) {
            $FundingPlanID = $FundingPlan->getElementsByTagName('fundingPlanId')->length > 0 ? $FundingPlan->getElementsByTagName('fundingPlanId')->item(0)->nodeValue : '';
            $FundingAmountType = $FundingPlan->getElementsByTagName('fundingAmount')->length > 0 ? $FundingPlan->getElementsByTagName('fundingAmount') : array();
            foreach ($FundingAmountType as $FundingAmount) {
                $FundingAmountCode = $FundingAmount->getElementsByTagName('code')->length > 0 ? $FundingAmount->getElementsByTagName('code')->item(0)->nodeValue : '';
                $FundingAmountAmount = $FundingAmount->getElementsByTagName('amount')->length > 0 ? $FundingAmount->getElementsByTagName('amount')->item(0)->nodeValue : '';
            }
            $BackupFundingSourceType = $FundingPlan->getElementsByTagName('backupFundingSource')->length > 0 ? $FundingPlan->getElementsByTagName('backupFundingSource') : array();
            foreach ($BackupFundingSourceType as $BackupFundingSource) {
                $BackupFundingSource_LastFourOfAccountNumber = $BackupFundingSource->getElementsByTagName('lastFourOfAccountNumber')->length > 0 ? $BackupFundingSource->getElementsByTagName('lastFourOfAccountNumber')->item(0)->nodeValue : '';
                $BackupFundingSource_Type = $BackupFundingSource->getElementsByTagName('type')->length > 0 ? $BackupFundingSource->getElementsByTagName('type')->item(0)->nodeValue : '';
                $BackupFundingSource_DisplayName = $BackupFundingSource->getElementsByTagName('displayName')->length > 0 ? $BackupFundingSource->getElementsByTagName('displayName')->item(0)->nodeValue : '';
                $BackupFundingSource_FundingSourceID = $BackupFundingSource->getElementsByTagName('fundingSourceId')->length > 0 ? $BackupFundingSource->getElementsByTagName('fundingSourceId')->item(0)->nodeValue : '';
                $BackupFundingSource_Allowed = $BackupFundingSource->getElementsByTagName('allowed')->length > 0 ? $BackupFundingSource->getElementsByTagName('allowed')->item(0)->nodeValue : '';
            }
            $SenderFeesType = $FundingPlan->getElementsByTagName('senderFees')->length > 0 ? $FundingPlan->getElementsByTagName('senderFees') : array();
            foreach ($SenderFeesType as $SenderFees) {
                $SenderFeesCode = $SenderFees->getElementsByTagName('code')->length > 0 ? $SenderFees->getElementsByTagName('code')->item(0)->nodeValue : '';
                $SenderFeesAmount = $SenderFees->getElementsByTagName('amount')->length > 0 ? $SenderFees->getElementsByTagName('amount')->item(0)->nodeValue : '';
            }
            $CurrencyConversionType = $FundingPlan->getElementsByTagName('currencyConversion')->length > 0 ? $FundingPlan->getElementsByTagName('currencyConversion') : array();
            foreach ($CurrencyConversionType as $CurrencyConversion) {
                $CurrencyConversion_From = $CurrencyConversion->getElementsByTagName('from')->length > 0 ? $CurrencyConversion->getElementsByTagName('from')->item(0)->nodeValue : '';
                $CurrencyConversion_To = $CurrencyConversion->getElementsByTagName('to')->length > 0 ? $CurrencyConversion->getElementsByTagName('to')->item(0)->nodeValue : '';
                $CurrencyConversion_ExchangeRate = $CurrencyConversion->getElementsByTagName('exchangeRate')->length > 0 ? $CurrencyConversion->getElementsByTagName('exchangeRate')->item(0)->nodeValue : '';
            }
            $FundingPlanChargeType = $FundingPlan->getElementsByTagName('charge')->length > 0 ? $FundingPlan->getElementsByTagName('charge') : array();
            foreach ($FundingPlanChargeType as $FundingPlanCharge) {
                $FundingPlanChargeCode = $FundingPlanCharge->getElementsByTagName('code')->length > 0 ? $FundingPlanCharge->getElementsByTagName('code')->item(0)->nodeValue : '';
                $FundingPlanChargeAmount = $FundingPlanCharge->getElementsByTagName('amount')->length > 0 ? $FundingPlanCharge->getElementsByTagName('amount')->item(0)->nodeValue : '';
                $FundingPlanChargeFundingSourceType = $FundingPlanCharge->getElementsByTagName('fundingSource')->length > 0 ? $FundingPlanCharge->getElementsByTagName('fundingSource') : array();
                foreach ($FundingPlanChargeFundingSourceType as $FundingPlanChargeFundingSource) {
                    $FundingPlanChargeFundingSource_LastFourOfAccountNumber = $FundingPlanChargeFundingSource->getElementsByTagName('lastFourOfAccountNumber')->length > 0 ? $FundingPlanChargeFundingSource->getElementsByTagName('lastFourOfAccountNumber')->item(0)->nodeValue : '';
                    $FundingPlanChargeFundingSource_Type = $FundingPlanChargeFundingSource->getElementsByTagName('type')->length > 0 ? $FundingPlanChargeFundingSource->getElementsByTagName('type')->item(0)->nodeValue : '';
                    $FundingPlanChargeFundingSource_DisplayName = $FundingPlanChargeFundingSource->getElementsByTagName('displayName')->length > 0 ? $FundingPlanChargeFundingSource->getElementsByTagName('displayName')->item(0)->nodeValue : '';
                    $FundingPlanChargeFundingSource_FundingSourceID = $FundingPlanChargeFundingSource->getElementsByTagName('fundingSourceId')->length > 0 ? $FundingPlanChargeFundingSource->getElementsByTagName('fundingSourceId')->item(0)->nodeValue : '';
                    $FundingPlanChargeFundingSource_Allowed = $FundingPlanChargeFundingSource->getElementsByTagName('allowed')->length > 0 ? $FundingPlanChargeFundingSource->getElementsByTagName('allowed')->item(0)->nodeValue : '';
                }
            }
        }
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'FundingPlanID' => isset($FundingPlanID) ? $FundingPlanID : '',
            'FundingAmountCode' => isset($FundingAmountCode) ? $FundingAmountCode : '',
            'FundingAmountAmount' => isset($FundingAmountAmount) ? $FundingAmountAmount : '',
            'SenderFeesCode' => isset($SenderFeesCode) ? $SenderFeesCode : '',
            'SenderFeesAmount' => isset($SenderFeesAmount) ? $SenderFeesAmount : '',
            'BackupFundingSource_LastFourOfAccountNumber' => isset($BackupFundingSource_LastFourOfAccountNumber) ? $BackupFundingSource_LastFourOfAccountNumber : '',
            'BackupFundingSource_Type' => isset($BackupFundingSource_Type) ? $BackupFundingSource_Type : '',
            'BackupFundingSource_DisplayName' => isset($BackupFundingSource_DisplayName) ? $BackupFundingSource_DisplayName : '',
            'BackupFundingSource_FundingSourceID' => isset($BackupFundingSource_FundingSourceID) ? $BackupFundingSource_FundingSourceID : '',
            'BackupFundingSource_Allowed' => isset($BackupFundingSource_Allowed) ? $BackupFundingSource_Allowed : '',
            'CurrencyConversion_From' => isset($CurrencyConversion_From) ? $CurrencyConversion_From : '',
            'CurrencyConversion_To' => isset($CurrencyConversion_To) ? $CurrencyConversion_To : '',
            'CurrencyConversion_ExchangeRate' => isset($CurrencyConversion_ExchangeRate) ? $CurrencyConversion_ExchangeRate : '',
            'FundingPlanChargeCode' => isset($FundingPlanChargeCode) ? $FundingPlanChargeCode : '',
            'FundingPlanChargeAmount' => isset($FundingPlanChargeAmount) ? $FundingPlanChargeAmount : '',
            'FundingPlanChargeFundingSource_LastFourOfAccountNumber' => isset($FundingPlanChargeFundingSource_LastFourOfAccountNumber) ? $FundingPlanChargeFundingSource_LastFourOfAccountNumber : '',
            'FundingPlanChargeFundingSource_Type' => isset($FundingPlanChargeFundingSource_Type) ? $FundingPlanChargeFundingSource_Type : '',
            'FundingPlanChargeFundingSource_DisplayName' => isset($FundingPlanChargeFundingSource_DisplayName) ? $FundingPlanChargeFundingSource_DisplayName : '',
            'FundingPlanChargeFundingSource_FundingSourceID' => isset($FundingPlanChargeFundingSource_FundingSourceID) ? $FundingPlanChargeFundingSource_FundingSourceID : '',
            'FundingPlanChargeFundingSource_Allowed' => isset($FundingPlanChargeFundingSource_Allowed) ? $FundingPlanChargeFundingSource_Allowed : '',
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit GetShippingAddresses API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function GetShippingAddresses($PayKey) {
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= $PayKey != '' ? '' . $PayKey . '' : '';
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'AdaptivePayments', 'GetShippingAddresses');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $AddresseeName = $DOM->getElementsByTagName('addresseeName')->length > 0 ? $DOM->getElementsByTagName('addresseeName')->item(0)->nodeValue : '';
        $AddressID = $DOM->getElementsByTagName('addressId')->length > 0 ? $DOM->getElementsByTagName('addressId')->item(0)->nodeValue : '';
        $Line1 = $DOM->getElementsByTagName('line1')->length > 0 ? $DOM->getElementsByTagName('line1')->item(0)->nodeValue : '';
        $Line2 = $DOM->getElementsByTagName('line2')->length > 0 ? $DOM->getElementsByTagName('line2')->item(0)->nodeValue : '';
        $City = $DOM->getElementsByTagName('city')->length > 0 ? $DOM->getElementsByTagName('city')->item(0)->nodeValue : '';
        $State = $DOM->getElementsByTagName('state')->length > 0 ? $DOM->getElementsByTagName('state')->item(0)->nodeValue : '';
        $PostalCode = $DOM->getElementsByTagName('postalCode')->length > 0 ? $DOM->getElementsByTagName('postalCode')->item(0)->nodeValue : '';
        $CountryCode = $DOM->getElementsByTagName('countryCode')->length > 0 ? $DOM->getElementsByTagName('countryCode')->item(0)->nodeValue : '';
        $Type = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'AddresseeName' => $AddresseeName,
            'AddressID' => $AddressID,
            'Line1' => $Line1,
            'Line2' => $Line2,
            'City' => $City,
            'State' => $State,
            'PostalCode' => $PostalCode,
            'CountryCode' => $CountryCode,
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit CreateInvoice API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function CreateInvoice($DataArray) {
        $CreateInvoiceFields = isset($DataArray['CreateInvoiceFields']) ? $DataArray['CreateInvoiceFields'] : array();
        $MerchantEmail = isset($CreateInvoiceFields['MerchantEmail']) ? $CreateInvoiceFields['MerchantEmail'] : '';
        $PayerEmail = isset($CreateInvoiceFields['PayerEmail']) ? $CreateInvoiceFields['PayerEmail'] : '';
        $Number = isset($CreateInvoiceFields['Number']) ? $CreateInvoiceFields['Number'] : '';
        $CurrencyCode = isset($CreateInvoiceFields['CurrencyCode']) ? $CreateInvoiceFields['CurrencyCode'] : '';
        $InvoiceDate = isset($CreateInvoiceFields['InvoiceDate']) ? $CreateInvoiceFields['InvoiceDate'] : '';
        $DueDate = isset($CreateInvoiceFields['DueDate']) ? $CreateInvoiceFields['DueDate'] : '';
        $PaymentTerms = isset($CreateInvoiceFields['PaymentTerms']) ? $CreateInvoiceFields['PaymentTerms'] : '';
        $DiscountPercent = isset($CreateInvoiceFields['DiscountPercent']) ? $CreateInvoiceFields['DiscountPercent'] : '';
        $DiscountAmount = isset($CreateInvoiceFields['DiscountAmount']) ? $CreateInvoiceFields['DiscountAmount'] : '';
        $Terms = isset($CreateInvoiceFields['Terms']) ? $CreateInvoiceFields['Terms'] : '';
        $Note = isset($CreateInvoiceFields['Note']) ? $CreateInvoiceFields['Note'] : '';
        $MerchantMemo = isset($CreateInvoiceFields['MerchantMemo']) ? $CreateInvoiceFields['MerchantMemo'] : '';
        $ShippingAmount = isset($CreateInvoiceFields['ShippingAmount']) ? $CreateInvoiceFields['ShippingAmount'] : '';
        $ShippingTaxName = isset($CreateInvoiceFields['ShippingTaxName']) ? $CreateInvoiceFields['ShippingTaxName'] : '';
        $ShippingTaxRate = isset($CreateInvoiceFields['ShippingTaxRate']) ? $CreateInvoiceFields['ShippingTaxRate'] : '';
        $LogoURL = isset($CreateInvoiceFields['LogoURL']) ? $CreateInvoiceFields['LogoURL'] : '';
        $BusinessInfo = isset($DataArray['BusinessInfo']) ? $DataArray['BusinessInfo'] : array();
        $BusinessFirstName = isset($BusinessInfo['FirstName']) ? $BusinessInfo['FirstName'] : '';
        $BusinessLastName = isset($BusinessInfo['LastName']) ? $BusinessInfo['LastName'] : '';
        $BusinessBusinessName = isset($BusinessInfo['BusinessName']) ? $BusinessInfo['BusinessName'] : '';
        $BusinessPhone = isset($BusinessInfo['Phone']) ? $BusinessInfo['Phone'] : '';
        $BusinessFax = isset($BusinessInfo['Fax']) ? $BusinessInfo['Fax'] : '';
        $BusinessWebsite = isset($BusinessInfo['Website']) ? $BusinessInfo['Website'] : '';
        $BusinessCustom = isset($BusinessInfo['Custom']) ? $BusinessInfo['Custom'] : '';
        $BusinessInfoAddress = isset($DataArray['BusinessInfoAddress']) ? $DataArray['BusinessInfoAddress'] : array();
        $BusinessInfoAddressLine1 = isset($BusinessInfoAddress['Line1']) ? $BusinessInfoAddress['Line1'] : '';
        $BusinessInfoAddressLine2 = isset($BusinessInfoAddress['Line2']) ? $BusinessInfoAddress['Line2'] : '';
        $BusinessInfoAddressCity = isset($BusinessInfoAddress['City']) ? $BusinessInfoAddress['City'] : '';
        $BusinessInfoAddressState = isset($BusinessInfoAddress['State']) ? $BusinessInfoAddress['State'] : '';
        $BusinessInfoAddressPostalCode = isset($BusinessInfoAddress['PostalCode']) ? $BusinessInfoAddress['PostalCode'] : '';
        $BusinessInfoAddressCountryCode = isset($BusinessInfoAddress['CountryCode']) ? $BusinessInfoAddress['CountryCode'] : '';
        $BusinessInfoAddressType = isset($BusinessInfoAddress['AddressType']) ? $BusinessInfoAddress['AddressType'] : '';
        $BillingInfo = isset($DataArray['BillingInfo']) ? $DataArray['BillingInfo'] : array();
        $BillingFirstName = isset($BillingInfo['FirstName']) ? $BillingInfo['FirstName'] : '';
        $BillingLastName = isset($BillingInfo['LastName']) ? $BillingInfo['LastName'] : '';
        $BillingBusinessName = isset($BillingInfo['BusinessName']) ? $BillingInfo['BusinessName'] : '';
        $BillingPhone = isset($BillingInfo['Phone']) ? $BillingInfo['Phone'] : '';
        $BillingFax = isset($BillingInfo['Fax']) ? $BillingInfo['Fax'] : '';
        $BillingWebsite = isset($BillingInfo['Website']) ? $BillingInfo['Website'] : '';
        $BillingCustom = isset($BillingInfo['Custom']) ? $BillingInfo['Custom'] : '';
        $BillingInfoAddress = isset($DataArray['BillingInfoAddress']) ? $DataArray['BillingInfoAddress'] : array();
        $BillingInfoAddressLine1 = isset($BillingInfoAddress['Line1']) ? $BillingInfoAddress['Line1'] : '';
        $BillingInfoAddressLine2 = isset($BillingInfoAddress['Line2']) ? $BillingInfoAddress['Line2'] : '';
        $BillingInfoAddressCity = isset($BillingInfoAddress['City']) ? $BillingInfoAddress['City'] : '';
        $BillingInfoAddressState = isset($BillingInfoAddress['State']) ? $BillingInfoAddress['State'] : '';
        $BillingInfoAddressPostalCode = isset($BillingInfoAddress['PostalCode']) ? $BillingInfoAddress['PostalCode'] : '';
        $BillingInfoAddressCountryCode = isset($BillingInfoAddress['CountryCode']) ? $BillingInfoAddress['CountryCode'] : '';
        $BillingInfoAddressType = isset($BillingInfoAddress['AddressType']) ? $BillingInfoAddress['AddressType'] : '';
        $ShippingInfo = isset($DataArray['ShippingInfo']) ? $DataArray['ShippingInfo'] : array();
        $ShippingFirstName = isset($ShippingInfo['FirstName']) ? $ShippingInfo['FirstName'] : '';
        $ShippingLastName = isset($ShippingInfo['LastName']) ? $ShippingInfo['LastName'] : '';
        $ShippingBusinessName = isset($ShippingInfo['BusinessName']) ? $ShippingInfo['BusinessName'] : '';
        $ShippingPhone = isset($ShippingInfo['Phone']) ? $ShippingInfo['Phone'] : '';
        $ShippingFax = isset($ShippingInfo['Fax']) ? $ShippingInfo['Fax'] : '';
        $ShippingWebsite = isset($ShippingInfo['Website']) ? $ShippingInfo['Website'] : '';
        $ShippingCustom = isset($ShippingInfo['Custom']) ? $ShippingInfo['Custom'] : '';
        $ShippingInfoAddress = isset($DataArray['ShippingInfoAddress']) ? $DataArray['ShippingInfoAddress'] : array();
        $ShippingInfoAddressLine1 = isset($ShippingInfoAddress['Line1']) ? $ShippingInfoAddress['Line1'] : '';
        $ShippingInfoAddressLine2 = isset($ShippingInfoAddress['Line2']) ? $ShippingInfoAddress['Line2'] : '';
        $ShippingInfoAddressCity = isset($ShippingInfoAddress['City']) ? $ShippingInfoAddress['City'] : '';
        $ShippingInfoAddressState = isset($ShippingInfoAddress['State']) ? $ShippingInfoAddress['State'] : '';
        $ShippingInfoAddressPostalCode = isset($ShippingInfoAddress['PostalCode']) ? $ShippingInfoAddress['PostalCode'] : '';
        $ShippingInfoAddressCountryCode = isset($ShippingInfoAddress['CountryCode']) ? $ShippingInfoAddress['CountryCode'] : '';
        $ShippingInfoAddressType = isset($ShippingInfoAddress['AddressType']) ? $ShippingInfoAddress['AddressType'] : '';
        $InvoiceItems = isset($DataArray['InvoiceItems']) ? $DataArray['InvoiceItems'] : array();
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= '';
        $XMLRequest .= $MerchantEmail != '' ? '' . $MerchantEmail . '' : '';
        $XMLRequest .= $PayerEmail != '' ? '' . $PayerEmail . '' : '';
        $XMLRequest .= $Number != '' ? '' . $Number . '' : '';
        if (!empty($BusinessInfo)) {
            $XMLRequest .= '';
            $XMLRequest .= $BusinessFirstName != '' ? '' . $BusinessFirstName . '' : '';
            $XMLRequest .= $BusinessLastName != '' ? '' . $BusinessLastName . '' : '';
            $XMLRequest .= $BusinessBusinessName != '' ? '' . $BusinessBusinessName . '' : '';
            $XMLRequest .= $BusinessPhone != '' ? '' . $BusinessPhone . '' : '';
            $XMLRequest .= $BusinessFax != '' ? '' . $BusinessFax . '' : '';
            $XMLRequest .= $BusinessWebsite != '' ? '' . $BusinessWebsite . '' : '';
            $XMLRequest .= $BusinessCustom != '' ? '' . $BusinessCustom . '' : '';
            if (!empty($BusinessInfoAddress)) {
                $XMLRequest .= '';
                $XMLRequest .= $BusinessInfoAddressLine1 != '' ? '' . $BusinessInfoAddressLine1 . '' : '';
                $XMLRequest .= $BusinessInfoAddressLine2 != '' ? '' . $BusinessInfoAddressLine2 . '' : '';
                $XMLRequest .= $BusinessInfoAddressCity != '' ? '' . $BusinessInfoAddressCity . '' : '';
                $XMLRequest .= $BusinessInfoAddressState != '' ? '' . $BusinessInfoAddressState . '' : '';
                $XMLRequest .= $BusinessInfoAddressPostalCode != '' ? '' . $BusinessInfoAddressPostalCode . '' : '';
                $XMLRequest .= $BusinessInfoAddressCountryCode != '' ? '' . $BusinessInfoAddressCountryCode . '' : '';
                $XMLRequest .= $BusinessInfoAddressType != '' ? '' . $BusinessInfoAddressType . '' : '';
                $XMLRequest .= '';
            }
            $XMLRequest .= '';
        }
        if (!empty($InvoiceItems)) {
            $XMLRequest .= '';
            foreach ($InvoiceItems as $InvoiceItem) {
                $XMLRequest .= '- ';
                $XMLRequest .= $InvoiceItem['Name'] != '' ? '' . $InvoiceItem['Name'] . '' : '';
                $XMLRequest .= $InvoiceItem['Description'] != '' ? '' . $InvoiceItem['Description'] . '' : '';
                $XMLRequest .= $InvoiceItem['Date'] != '' ? '' . $InvoiceItem['Date'] . '' : '';
                $XMLRequest .= $InvoiceItem['Quantity'] != '' ? '' . $InvoiceItem['Quantity'] . '' : '';
                $XMLRequest .= $InvoiceItem['UnitPrice'] != '' ? '' . $InvoiceItem['UnitPrice'] . '' : '';
                $XMLRequest .= $InvoiceItem['TaxName'] != '' ? '' . $InvoiceItem['TaxName'] . '' : '';
                $XMLRequest .= $InvoiceItem['TaxRate'] != '' ? '' . $InvoiceItem['TaxRate'] . '' : '';
                $XMLRequest .= '';
            }
            $XMLRequest .= '';
        }
        $XMLRequest .= $CurrencyCode != '' ? '' . $CurrencyCode . '' : '';
        $XMLRequest .= $InvoiceDate != '' ? '' . $InvoiceDate . '' : '';
        $XMLRequest .= $DueDate != '' ? '' . $DueDate . '' : '';
        $XMLRequest .= $PaymentTerms != '' ? '' . $PaymentTerms . '' : '';
        $XMLRequest .= $DiscountPercent != '' ? '' . $DiscountPercent . '' : '';
        $XMLRequest .= $DiscountAmount != '' ? '' . $DiscountAmount . '' : '';
        $XMLRequest .= $Terms != '' ? '' . $Terms . '' : '';
        $XMLRequest .= $Note != '' ? '' . $Note . '' : '';
        $XMLRequest .= $MerchantMemo != '' ? '' . $MerchantMemo . '' : '';
        if (!empty($BillingInfo)) {
            $XMLRequest .= '';
            $XMLRequest .= $BillingFirstName != '' ? '' . $BillingFirstName . '' : '';
            $XMLRequest .= $BillingLastName != '' ? '' . $BillingLastName . '' : '';
            $XMLRequest .= $BillingBusinessName != '' ? '' . $BillingBusinessName . '' : '';
            $XMLRequest .= $BillingPhone != '' ? '' . $BillingPhone . '' : '';
            $XMLRequest .= $BillingFax != '' ? '' . $BillingFax . '' : '';
            $XMLRequest .= $BillingWebsite != '' ? '' . $BillingWebsite . '' : '';
            $XMLRequest .= $BillingCustom != '' ? '' . $BillingCustom . '' : '';
            if (!empty($BillingInfoAddress)) {
                $XMLRequest .= '';
                $XMLRequest .= $BillingInfoAddressLine1 != '' ? '' . $BillingInfoAddressLine1 . '' : '';
                $XMLRequest .= $BillingInfoAddressLine2 != '' ? '' . $BillingInfoAddressLine2 . '' : '';
                $XMLRequest .= $BillingInfoAddressCity != '' ? '' . $BillingInfoAddressCity . '' : '';
                $XMLRequest .= $BillingInfoAddressState != '' ? '' . $BillingInfoAddressState . '' : '';
                $XMLRequest .= $BillingInfoAddressPostalCode != '' ? '' . $BillingInfoAddressPostalCode . '' : '';
                $XMLRequest .= $BillingInfoAddressCountryCode != '' ? '' . $BillingInfoAddressCountryCode . '' : '';
                $XMLRequest .= $BillingInfoAddressType != '' ? '' . $BillingInfoAddressType . '' : '';
                $XMLRequest .= '';
            }
            $XMLRequest .= '';
        }
        if (!empty($ShippingInfo)) {
            $XMLRequest .= '';
            $XMLRequest .= $ShippingFirstName != '' ? '' . $ShippingFirstName . '' : '';
            $XMLRequest .= $ShippingLastName != '' ? '' . $ShippingLastName . '' : '';
            $XMLRequest .= $ShippingBusinessName != '' ? '' . $ShippingBusinessName . '' : '';
            $XMLRequest .= $ShippingPhone != '' ? '' . $ShippingPhone . '' : '';
            $XMLRequest .= $ShippingFax != '' ? '' . $ShippingFax . '' : '';
            $XMLRequest .= $ShippingWebsite != '' ? '' . $ShippingWebsite . '' : '';
            $XMLRequest .= $ShippingCustom != '' ? '' . $ShippingCustom . '' : '';
            if (!empty($ShippingInfoAddress)) {
                $XMLRequest .= '';
                $XMLRequest .= $ShippingInfoAddressLine1 != '' ? '' . $ShippingInfoAddressLine1 . '' : '';
                $XMLRequest .= $ShippingInfoAddressLine2 != '' ? '' . $ShippingInfoAddressLine2 . '' : '';
                $XMLRequest .= $ShippingInfoAddressCity != '' ? '' . $ShippingInfoAddressCity . '' : '';
                $XMLRequest .= $ShippingInfoAddressState != '' ? '' . $ShippingInfoAddressState . '' : '';
                $XMLRequest .= $ShippingInfoAddressPostalCode != '' ? '' . $ShippingInfoAddressPostalCode . '' : '';
                $XMLRequest .= $ShippingInfoAddressCountryCode != '' ? '' . $ShippingInfoAddressCountryCode . '' : '';
                $XMLRequest .= $ShippingInfoAddressType != '' ? '' . $ShippingInfoAddressType . '' : '';
                $XMLRequest .= '';
            }
            $XMLRequest .= '';
        }
        $XMLRequest .= $ShippingAmount != '' ? '' . $ShippingAmount . '' : '';
        $XMLRequest .= $ShippingTaxName != '' ? '' . $ShippingTaxName . '' : '';
        $XMLRequest .= $ShippingTaxRate != '' ? '' . $ShippingTaxRate . '' : '';
        $XMLRequest .= $LogoURL != '' ? '' . $LogoURL . '' : '';
        $XMLRequest .= '' . $this->APIButtonSource . '';
        $XMLRequest .= '';
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'Invoice', 'CreateInvoice');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $InvoiceID = $DOM->getElementsByTagName('invoiceID')->length > 0 ? $DOM->getElementsByTagName('invoiceID')->item(0)->nodeValue : '';
        $InvoiceNumber = $DOM->getElementsByTagName('invoiceNumber')->length > 0 ? $DOM->getElementsByTagName('invoiceNumber')->item(0)->nodeValue : '';
        $InvoiceURL = $DOM->getElementsByTagName('invoiceURL')->length > 0 ? $DOM->getElementsByTagName('invoiceURL')->item(0)->nodeValue : '';
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'InvoiceID' => $InvoiceID,
            'InvoiceNumber' => $InvoiceNumber,
            'InvoiceURL' => $InvoiceURL,
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit SendInvoice API request to PayPal.
     *
     * @access	public
     * @param	string	InvoiceID
     * @return	array
     */
    function SendInvoice($InvoiceID) {
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= $InvoiceID != '' ? '' . $InvoiceID . '' : '';
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'Invoice', 'SendInvoice');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $InvoiceID = $DOM->getElementsByTagName('invoiceID')->length > 0 ? $DOM->getElementsByTagName('invoiceID')->item(0)->nodeValue : '';
        $InvoiceURL = $DOM->getElementsByTagName('invoiceURL')->length > 0 ? $DOM->getElementsByTagName('invoiceURL')->item(0)->nodeValue : '';
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'InvoiceID' => $InvoiceID,
            'InvoiceURL' => $InvoiceURL,
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit CreateAndSendInvoice API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function CreateAndSendInvoice($DataArray) {
        $CreateInvoiceFields = isset($DataArray['CreateInvoiceFields']) ? $DataArray['CreateInvoiceFields'] : array();
        $MerchantEmail = isset($CreateInvoiceFields['MerchantEmail']) ? $CreateInvoiceFields['MerchantEmail'] : '';
        $PayerEmail = isset($CreateInvoiceFields['PayerEmail']) ? $CreateInvoiceFields['PayerEmail'] : '';
        $Number = isset($CreateInvoiceFields['Number']) ? $CreateInvoiceFields['Number'] : '';
        $CurrencyCode = isset($CreateInvoiceFields['CurrencyCode']) ? $CreateInvoiceFields['CurrencyCode'] : '';
        $InvoiceDate = isset($CreateInvoiceFields['InvoiceDate']) ? $CreateInvoiceFields['InvoiceDate'] : '';
        $DueDate = isset($CreateInvoiceFields['DueDate']) ? $CreateInvoiceFields['DueDate'] : '';
        $PaymentTerms = isset($CreateInvoiceFields['PaymentTerms']) ? $CreateInvoiceFields['PaymentTerms'] : '';
        $DiscountPercent = isset($CreateInvoiceFields['DiscountPercent']) ? $CreateInvoiceFields['DiscountPercent'] : '';
        $DiscountAmount = isset($CreateInvoiceFields['DiscountAmount']) ? $CreateInvoiceFields['DiscountAmount'] : '';
        $Terms = isset($CreateInvoiceFields['Terms']) ? $CreateInvoiceFields['Terms'] : '';
        $Note = isset($CreateInvoiceFields['Note']) ? $CreateInvoiceFields['Note'] : '';
        $MerchantMemo = isset($CreateInvoiceFields['MerchantMemo']) ? $CreateInvoiceFields['MerchantMemo'] : '';
        $ShippingAmount = isset($CreateInvoiceFields['ShippingAmount']) ? $CreateInvoiceFields['ShippingAmount'] : '';
        $ShippingTaxName = isset($CreateInvoiceFields['ShippingTaxName']) ? $CreateInvoiceFields['ShippingTaxName'] : '';
        $ShippingTaxRate = isset($CreateInvoiceFields['ShippingTaxRate']) ? $CreateInvoiceFields['ShippingTaxRate'] : '';
        $LogoURL = isset($CreateInvoiceFields['LogoURL']) ? $CreateInvoiceFields['LogoURL'] : '';
        $BusinessInfo = isset($DataArray['BusinessInfo']) ? $DataArray['BusinessInfo'] : array();
        $BusinessFirstName = isset($BusinessInfo['FirstName']) ? $BusinessInfo['FirstName'] : '';
        $BusinessLastName = isset($BusinessInfo['LastName']) ? $BusinessInfo['LastName'] : '';
        $BusinessBusinessName = isset($BusinessInfo['BusinessName']) ? $BusinessInfo['BusinessName'] : '';
        $BusinessPhone = isset($BusinessInfo['Phone']) ? $BusinessInfo['Phone'] : '';
        $BusinessFax = isset($BusinessInfo['Fax']) ? $BusinessInfo['Fax'] : '';
        $BusinessWebsite = isset($BusinessInfo['Website']) ? $BusinessInfo['Website'] : '';
        $BusinessCustom = isset($BusinessInfo['Custom']) ? $BusinessInfo['Custom'] : '';
        $BusinessInfoAddress = isset($DataArray['BusinessInfoAddress']) ? $DataArray['BusinessInfoAddress'] : array();
        $BusinessInfoAddressLine1 = isset($BusinessInfoAddress['Line1']) ? $BusinessInfoAddress['Line1'] : '';
        $BusinessInfoAddressLine2 = isset($BusinessInfoAddress['Line2']) ? $BusinessInfoAddress['Line2'] : '';
        $BusinessInfoAddressCity = isset($BusinessInfoAddress['City']) ? $BusinessInfoAddress['City'] : '';
        $BusinessInfoAddressState = isset($BusinessInfoAddress['State']) ? $BusinessInfoAddress['State'] : '';
        $BusinessInfoAddressPostalCode = isset($BusinessInfoAddress['PostalCode']) ? $BusinessInfoAddress['PostalCode'] : '';
        $BusinessInfoAddressCountryCode = isset($BusinessInfoAddress['CountryCode']) ? $BusinessInfoAddress['CountryCode'] : '';
        $BusinessInfoAddressType = isset($BusinessInfoAddress['AddressType']) ? $BusinessInfoAddress['AddressType'] : '';
        $BillingInfo = isset($DataArray['BillingInfo']) ? $DataArray['BillingInfo'] : array();
        $BillingFirstName = isset($BillingInfo['FirstName']) ? $BillingInfo['FirstName'] : '';
        $BillingLastName = isset($BillingInfo['LastName']) ? $BillingInfo['LastName'] : '';
        $BillingBusinessName = isset($BillingInfo['BusinessName']) ? $BillingInfo['BusinessName'] : '';
        $BillingPhone = isset($BillingInfo['Phone']) ? $BillingInfo['Phone'] : '';
        $BillingFax = isset($BillingInfo['Fax']) ? $BillingInfo['Fax'] : '';
        $BillingWebsite = isset($BillingInfo['Website']) ? $BillingInfo['Website'] : '';
        $BillingCustom = isset($BillingInfo['Custom']) ? $BillingInfo['Custom'] : '';
        $BillingInfoAddress = isset($DataArray['BillingInfoAddress']) ? $DataArray['BillingInfoAddress'] : array();
        $BillingInfoAddressLine1 = isset($BillingInfoAddress['Line1']) ? $BillingInfoAddress['Line1'] : '';
        $BillingInfoAddressLine2 = isset($BillingInfoAddress['Line2']) ? $BillingInfoAddress['Line2'] : '';
        $BillingInfoAddressCity = isset($BillingInfoAddress['City']) ? $BillingInfoAddress['City'] : '';
        $BillingInfoAddressState = isset($BillingInfoAddress['State']) ? $BillingInfoAddress['State'] : '';
        $BillingInfoAddressPostalCode = isset($BillingInfoAddress['PostalCode']) ? $BillingInfoAddress['PostalCode'] : '';
        $BillingInfoAddressCountryCode = isset($BillingInfoAddress['CountryCode']) ? $BillingInfoAddress['CountryCode'] : '';
        $BillingInfoAddressType = isset($BillingInfoAddress['AddressType']) ? $BillingInfoAddress['AddressType'] : '';
        $ShippingInfo = isset($DataArray['ShippingInfo']) ? $DataArray['ShippingInfo'] : array();
        $ShippingFirstName = isset($ShippingInfo['FirstName']) ? $ShippingInfo['FirstName'] : '';
        $ShippingLastName = isset($ShippingInfo['LastName']) ? $ShippingInfo['LastName'] : '';
        $ShippingBusinessName = isset($ShippingInfo['BusinessName']) ? $ShippingInfo['BusinessName'] : '';
        $ShippingPhone = isset($ShippingInfo['Phone']) ? $ShippingInfo['Phone'] : '';
        $ShippingFax = isset($ShippingInfo['Fax']) ? $ShippingInfo['Fax'] : '';
        $ShippingWebsite = isset($ShippingInfo['Website']) ? $ShippingInfo['Website'] : '';
        $ShippingCustom = isset($ShippingInfo['Custom']) ? $ShippingInfo['Custom'] : '';
        $ShippingInfoAddress = isset($DataArray['ShippingInfoAddress']) ? $DataArray['ShippingInfoAddress'] : array();
        $ShippingInfoAddressLine1 = isset($ShippingInfoAddress['Line1']) ? $ShippingInfoAddress['Line1'] : '';
        $ShippingInfoAddressLine2 = isset($ShippingInfoAddress['Line2']) ? $ShippingInfoAddress['Line2'] : '';
        $ShippingInfoAddressCity = isset($ShippingInfoAddress['City']) ? $ShippingInfoAddress['City'] : '';
        $ShippingInfoAddressState = isset($ShippingInfoAddress['State']) ? $ShippingInfoAddress['State'] : '';
        $ShippingInfoAddressPostalCode = isset($ShippingInfoAddress['PostalCode']) ? $ShippingInfoAddress['PostalCode'] : '';
        $ShippingInfoAddressCountryCode = isset($ShippingInfoAddress['CountryCode']) ? $ShippingInfoAddress['CountryCode'] : '';
        $ShippingInfoAddressType = isset($ShippingInfoAddress['AddressType']) ? $ShippingInfoAddress['AddressType'] : '';
        $InvoiceItems = isset($DataArray['InvoiceItems']) ? $DataArray['InvoiceItems'] : array();
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= '';
        $XMLRequest .= $MerchantEmail != '' ? '' . $MerchantEmail . '' : '';
        $XMLRequest .= $PayerEmail != '' ? '' . $PayerEmail . '' : '';
        $XMLRequest .= $Number != '' ? '' . $Number . '' : '';
        if (!empty($BusinessInfo)) {
            $XMLRequest .= '';
            $XMLRequest .= $BusinessFirstName != '' ? '' . $BusinessFirstName . '' : '';
            $XMLRequest .= $BusinessLastName != '' ? '' . $BusinessLastName . '' : '';
            $XMLRequest .= $BusinessBusinessName != '' ? '' . $BusinessBusinessName . '' : '';
            $XMLRequest .= $BusinessPhone != '' ? '' . $BusinessPhone . '' : '';
            $XMLRequest .= $BusinessFax != '' ? '' . $BusinessFax . '' : '';
            $XMLRequest .= $BusinessWebsite != '' ? '' . $BusinessWebsite . '' : '';
            $XMLRequest .= $BusinessCustom != '' ? '' . $BusinessCustom . '' : '';
            if (!empty($BusinessInfoAddress)) {
                $XMLRequest .= '';
                $XMLRequest .= $BusinessInfoAddressLine1 != '' ? '' . $BusinessInfoAddressLine1 . '' : '';
                $XMLRequest .= $BusinessInfoAddressLine2 != '' ? '' . $BusinessInfoAddressLine2 . '' : '';
                $XMLRequest .= $BusinessInfoAddressCity != '' ? '' . $BusinessInfoAddressCity . '' : '';
                $XMLRequest .= $BusinessInfoAddressState != '' ? '' . $BusinessInfoAddressState . '' : '';
                $XMLRequest .= $BusinessInfoAddressPostalCode != '' ? '' . $BusinessInfoAddressPostalCode . '' : '';
                $XMLRequest .= $BusinessInfoAddressCountryCode != '' ? '' . $BusinessInfoAddressCountryCode . '' : '';
                $XMLRequest .= $BusinessInfoAddressType != '' ? '' . $BusinessInfoAddressType . '' : '';
                $XMLRequest .= '';
            }
            $XMLRequest .= '';
        }
        if (!empty($InvoiceItems)) {
            $XMLRequest .= '';
            foreach ($InvoiceItems as $InvoiceItem) {
                $XMLRequest .= '
- ';
                $XMLRequest .= $InvoiceItem['Name'] != '' ? '' . $InvoiceItem['Name'] . '' : '';
                $XMLRequest .= $InvoiceItem['Description'] != '' ? '' . $InvoiceItem['Description'] . '' : '';
                $XMLRequest .= $InvoiceItem['Date'] != '' ? '' . $InvoiceItem['Date'] . '' : '';
                $XMLRequest .= $InvoiceItem['Quantity'] != '' ? '' . $InvoiceItem['Quantity'] . '' : '';
                $XMLRequest .= $InvoiceItem['UnitPrice'] != '' ? '' . $InvoiceItem['UnitPrice'] . '' : '';
                $XMLRequest .= $InvoiceItem['TaxName'] != '' ? '' . $InvoiceItem['TaxName'] . '' : '';
                $XMLRequest .= $InvoiceItem['TaxRate'] != '' ? '' . $InvoiceItem['TaxRate'] . '' : '';
                $XMLRequest .= '';
            }
            $XMLRequest .= '';
        }
        $XMLRequest .= $CurrencyCode != '' ? '' . $CurrencyCode . '' : '';
        $XMLRequest .= $InvoiceDate != '' ? '' . $InvoiceDate . '' : '';
        $XMLRequest .= $DueDate != '' ? '' . $DueDate . '' : '';
        $XMLRequest .= $PaymentTerms != '' ? '' . $PaymentTerms . '' : '';
        $XMLRequest .= $DiscountPercent != '' ? '' . $DiscountPercent . '' : '';
        $XMLRequest .= $DiscountAmount != '' ? '' . $DiscountAmount . '' : '';
        $XMLRequest .= $Terms != '' ? '' . $Terms . '' : '';
        $XMLRequest .= $Note != '' ? '' . $Note . '' : '';
        $XMLRequest .= $MerchantMemo != '' ? '' . $MerchantMemo . '' : '';
        if (!empty($BillingInfo)) {
            $XMLRequest .= '';
            $XMLRequest .= $BillingFirstName != '' ? '' . $BillingFirstName . '' : '';
            $XMLRequest .= $BillingLastName != '' ? '' . $BillingLastName . '' : '';
            $XMLRequest .= $BillingBusinessName != '' ? '' . $BillingBusinessName . '' : '';
            $XMLRequest .= $BillingPhone != '' ? '' . $BillingPhone . '' : '';
            $XMLRequest .= $BillingFax != '' ? '' . $BillingFax . '' : '';
            $XMLRequest .= $BillingWebsite != '' ? '' . $BillingWebsite . '' : '';
            $XMLRequest .= $BillingCustom != '' ? '' . $BillingCustom . '' : '';
            if (!empty($BillingInfoAddress)) {
                $XMLRequest .= '';
                $XMLRequest .= $BillingInfoAddressLine1 != '' ? '' . $BillingInfoAddressLine1 . '' : '';
                $XMLRequest .= $BillingInfoAddressLine2 != '' ? '' . $BillingInfoAddressLine2 . '' : '';
                $XMLRequest .= $BillingInfoAddressCity != '' ? '' . $BillingInfoAddressCity . '' : '';
                $XMLRequest .= $BillingInfoAddressState != '' ? '' . $BillingInfoAddressState . '' : '';
                $XMLRequest .= $BillingInfoAddressPostalCode != '' ? '' . $BillingInfoAddressPostalCode . '' : '';
                $XMLRequest .= $BillingInfoAddressCountryCode != '' ? '' . $BillingInfoAddressCountryCode . '' : '';
                $XMLRequest .= $BillingInfoAddressType != '' ? '' . $BillingInfoAddressType . '' : '';
                $XMLRequest .= '';
            }
            $XMLRequest .= '';
        }
        if (!empty($ShippingInfo)) {
            $XMLRequest .= '';
            $XMLRequest .= $ShippingFirstName != '' ? '' . $ShippingFirstName . '' : '';
            $XMLRequest .= $ShippingLastName != '' ? '' . $ShippingLastName . '' : '';
            $XMLRequest .= $ShippingBusinessName != '' ? '' . $ShippingBusinessName . '' : '';
            $XMLRequest .= $ShippingPhone != '' ? '' . $ShippingPhone . '' : '';
            $XMLRequest .= $ShippingFax != '' ? '' . $ShippingFax . '' : '';
            $XMLRequest .= $ShippingWebsite != '' ? '' . $ShippingWebsite . '' : '';
            $XMLRequest .= $ShippingCustom != '' ? '' . $ShippingCustom . '' : '';
            if (!empty($ShippingInfoAddress)) {
                $XMLRequest .= '';
                $XMLRequest .= $ShippingInfoAddressLine1 != '' ? '' . $ShippingInfoAddressLine1 . '' : '';
                $XMLRequest .= $ShippingInfoAddressLine2 != '' ? '' . $ShippingInfoAddressLine2 . '' : '';
                $XMLRequest .= $ShippingInfoAddressCity != '' ? '' . $ShippingInfoAddressCity . '' : '';
                $XMLRequest .= $ShippingInfoAddressState != '' ? '' . $ShippingInfoAddressState . '' : '';
                $XMLRequest .= $ShippingInfoAddressPostalCode != '' ? '' . $ShippingInfoAddressPostalCode . '' : '';
                $XMLRequest .= $ShippingInfoAddressCountryCode != '' ? '' . $ShippingInfoAddressCountryCode . '' : '';
                $XMLRequest .= $ShippingInfoAddressType != '' ? '' . $ShippingInfoAddressType . '' : '';
                $XMLRequest .= '';
            }
            $XMLRequest .= '';
        }
        $XMLRequest .= $ShippingAmount != '' ? '' . $ShippingAmount . '' : '';
        $XMLRequest .= $ShippingTaxName != '' ? '' . $ShippingTaxName . '' : '';
        $XMLRequest .= $ShippingTaxRate != '' ? '' . $ShippingTaxRate . '' : '';
        $XMLRequest .= $LogoURL != '' ? '' . $LogoURL . '' : '';
        $XMLRequest .= '' . $this->APIButtonSource . '';
        $XMLRequest .= '';
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'Invoice', 'CreateAndSendInvoice');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $InvoiceID = $DOM->getElementsByTagName('invoiceID')->length > 0 ? $DOM->getElementsByTagName('invoiceID')->item(0)->nodeValue : '';
        $InvoiceNumber = $DOM->getElementsByTagName('invoiceNumber')->length > 0 ? $DOM->getElementsByTagName('invoiceNumber')->item(0)->nodeValue : '';
        $InvoiceURL = $DOM->getElementsByTagName('invoiceURL')->length > 0 ? $DOM->getElementsByTagName('invoiceURL')->item(0)->nodeValue : '';
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'InvoiceID' => $InvoiceID,
            'InvoiceNumber' => $InvoiceNumber,
            'InvoiceURL' => $InvoiceURL,
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit UpdateInvoice API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function UpdateInvoice($DataArray) {
        $UpdateInvoiceFields = isset($DataArray['UpdateInvoiceFields']) ? $DataArray['UpdateInvoiceFields'] : array();
        $InvoiceID = isset($UpdateInvoiceFields['InvoiceID']) ? $UpdateInvoiceFields['InvoiceID'] : '';
        $MerchantEmail = isset($UpdateInvoiceFields['MerchantEmail']) ? $UpdateInvoiceFields['MerchantEmail'] : '';
        $PayerEmail = isset($UpdateInvoiceFields['PayerEmail']) ? $UpdateInvoiceFields['PayerEmail'] : '';
        $Number = isset($UpdateInvoiceFields['Number']) ? $UpdateInvoiceFields['Number'] : '';
        $CurrencyCode = isset($UpdateInvoiceFields['CurrencyCode']) ? $UpdateInvoiceFields['CurrencyCode'] : '';
        $InvoiceDate = isset($UpdateInvoiceFields['InvoiceDate']) ? $UpdateInvoiceFields['InvoiceDate'] : '';
        $DueDate = isset($UpdateInvoiceFields['DueDate']) ? $UpdateInvoiceFields['DueDate'] : '';
        $PaymentTerms = isset($UpdateInvoiceFields['PaymentTerms']) ? $UpdateInvoiceFields['PaymentTerms'] : '';
        $DiscountPercent = isset($UpdateInvoiceFields['DiscountPercent']) ? $UpdateInvoiceFields['DiscountPercent'] : '';
        $DiscountAmount = isset($UpdateInvoiceFields['DiscountAmount']) ? $UpdateInvoiceFields['DiscountAmount'] : '';
        $Terms = isset($UpdateInvoiceFields['Terms']) ? $UpdateInvoiceFields['Terms'] : '';
        $Note = isset($UpdateInvoiceFields['Note']) ? $UpdateInvoiceFields['Note'] : '';
        $MerchantMemo = isset($UpdateInvoiceFields['MerchantMemo']) ? $UpdateInvoiceFields['MerchantMemo'] : '';
        $ShippingAmount = isset($UpdateInvoiceFields['ShippingAmount']) ? $UpdateInvoiceFields['ShippingAmount'] : '';
        $ShippingTaxName = isset($UpdateInvoiceFields['ShippingTaxName']) ? $UpdateInvoiceFields['ShippingTaxName'] : '';
        $ShippingTaxRate = isset($UpdateInvoiceFields['ShippingTaxRate']) ? $UpdateInvoiceFields['ShippingTaxRate'] : '';
        $LogoURL = isset($UpdateInvoiceFields['LogoURL']) ? $UpdateInvoiceFields['LogoURL'] : '';
        $BusinessInfo = isset($DataArray['BusinessInfo']) ? $DataArray['BusinessInfo'] : array();
        $BusinessFirstName = isset($BusinessInfo['FirstName']) ? $BusinessInfo['FirstName'] : '';
        $BusinessLastName = isset($BusinessInfo['LastName']) ? $BusinessInfo['LastName'] : '';
        $BusinessBusinessName = isset($BusinessInfo['BusinessName']) ? $BusinessInfo['BusinessName'] : '';
        $BusinessPhone = isset($BusinessInfo['Phone']) ? $BusinessInfo['Phone'] : '';
        $BusinessFax = isset($BusinessInfo['Fax']) ? $BusinessInfo['Fax'] : '';
        $BusinessWebsite = isset($BusinessInfo['Website']) ? $BusinessInfo['Website'] : '';
        $BusinessCustom = isset($BusinessInfo['Custom']) ? $BusinessInfo['Custom'] : '';
        $BusinessInfoAddress = isset($DataArray['BusinessInfoAddress']) ? $DataArray['BusinessInfoAddress'] : array();
        $BusinessInfoAddressLine1 = isset($BusinessInfoAddress['Line1']) ? $BusinessInfoAddress['Line1'] : '';
        $BusinessInfoAddressLine2 = isset($BusinessInfoAddress['Line2']) ? $BusinessInfoAddress['Line2'] : '';
        $BusinessInfoAddressCity = isset($BusinessInfoAddress['City']) ? $BusinessInfoAddress['City'] : '';
        $BusinessInfoAddressState = isset($BusinessInfoAddress['State']) ? $BusinessInfoAddress['State'] : '';
        $BusinessInfoAddressPostalCode = isset($BusinessInfoAddress['PostalCode']) ? $BusinessInfoAddress['PostalCode'] : '';
        $BusinessInfoAddressCountryCode = isset($BusinessInfoAddress['CountryCode']) ? $BusinessInfoAddress['CountryCode'] : '';
        $BusinessInfoAddressType = isset($BusinessInfoAddress['AddressType']) ? $BusinessInfoAddress['AddressType'] : '';
        $BillingInfo = isset($DataArray['BillingInfo']) ? $DataArray['BillingInfo'] : array();
        $BillingFirstName = isset($BillingInfo['FirstName']) ? $BillingInfo['FirstName'] : '';
        $BillingLastName = isset($BillingInfo['LastName']) ? $BillingInfo['LastName'] : '';
        $BillingBusinessName = isset($BillingInfo['BusinessName']) ? $BillingInfo['BusinessName'] : '';
        $BillingPhone = isset($BillingInfo['Phone']) ? $BillingInfo['Phone'] : '';
        $BillingFax = isset($BillingInfo['Fax']) ? $BillingInfo['Fax'] : '';
        $BillingWebsite = isset($BillingInfo['Website']) ? $BillingInfo['Website'] : '';
        $BillingCustom = isset($BillingInfo['Custom']) ? $BillingInfo['Custom'] : '';
        $BillingInfoAddress = isset($DataArray['BillingInfoAddress']) ? $DataArray['BillingInfoAddress'] : array();
        $BillingInfoAddressLine1 = isset($BillingInfoAddress['Line1']) ? $BillingInfoAddress['Line1'] : '';
        $BillingInfoAddressLine2 = isset($BillingInfoAddress['Line2']) ? $BillingInfoAddress['Line2'] : '';
        $BillingInfoAddressCity = isset($BillingInfoAddress['City']) ? $BillingInfoAddress['City'] : '';
        $BillingInfoAddressState = isset($BillingInfoAddress['State']) ? $BillingInfoAddress['State'] : '';
        $BillingInfoAddressPostalCode = isset($BillingInfoAddress['PostalCode']) ? $BillingInfoAddress['PostalCode'] : '';
        $BillingInfoAddressCountryCode = isset($BillingInfoAddress['CountryCode']) ? $BillingInfoAddress['CountryCode'] : '';
        $BillingInfoAddressType = isset($BillingInfoAddress['AddressType']) ? $BillingInfoAddress['AddressType'] : '';
        $ShippingInfo = isset($DataArray['ShippingInfo']) ? $DataArray['ShippingInfo'] : array();
        $ShippingFirstName = isset($ShippingInfo['FirstName']) ? $ShippingInfo['FirstName'] : '';
        $ShippingLastName = isset($ShippingInfo['LastName']) ? $ShippingInfo['LastName'] : '';
        $ShippingBusinessName = isset($ShippingInfo['BusinessName']) ? $ShippingInfo['BusinessName'] : '';
        $ShippingPhone = isset($ShippingInfo['Phone']) ? $ShippingInfo['Phone'] : '';
        $ShippingFax = isset($ShippingInfo['Fax']) ? $ShippingInfo['Fax'] : '';
        $ShippingWebsite = isset($ShippingInfo['Website']) ? $ShippingInfo['Website'] : '';
        $ShippingCustom = isset($ShippingInfo['Custom']) ? $ShippingInfo['Custom'] : '';
        $ShippingInfoAddress = isset($DataArray['ShippingInfoAddress']) ? $DataArray['ShippingInfoAddress'] : array();
        $ShippingInfoAddressLine1 = isset($ShippingInfoAddress['Line1']) ? $ShippingInfoAddress['Line1'] : '';
        $ShippingInfoAddressLine2 = isset($ShippingInfoAddress['Line2']) ? $ShippingInfoAddress['Line2'] : '';
        $ShippingInfoAddressCity = isset($ShippingInfoAddress['City']) ? $ShippingInfoAddress['City'] : '';
        $ShippingInfoAddressState = isset($ShippingInfoAddress['State']) ? $ShippingInfoAddress['State'] : '';
        $ShippingInfoAddressPostalCode = isset($ShippingInfoAddress['PostalCode']) ? $ShippingInfoAddress['PostalCode'] : '';
        $ShippingInfoAddressCountryCode = isset($ShippingInfoAddress['CountryCode']) ? $ShippingInfoAddress['CountryCode'] : '';
        $ShippingInfoAddressType = isset($ShippingInfoAddress['AddressType']) ? $ShippingInfoAddress['AddressType'] : '';
        $InvoiceItems = isset($DataArray['InvoiceItems']) ? $DataArray['InvoiceItems'] : array();
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= $InvoiceID != '' ? '' . $InvoiceID . '' : '';
        $XMLRequest .= '';
        $XMLRequest .= $MerchantEmail != '' ? '' . $MerchantEmail . '' : '';
        $XMLRequest .= $PayerEmail != '' ? '' . $PayerEmail . '' : '';
        $XMLRequest .= $Number != '' ? '' . $Number . '' : '';
        if (!empty($BusinessInfo)) {
            $XMLRequest .= '';
            $XMLRequest .= $BusinessFirstName != '' ? '' . $BusinessFirstName . '' : '';
            $XMLRequest .= $BusinessLastName != '' ? '' . $BusinessLastName . '' : '';
            $XMLRequest .= $BusinessBusinessName != '' ? '' . $BusinessBusinessName . '' : '';
            $XMLRequest .= $BusinessPhone != '' ? '' . $BusinessPhone . '' : '';
            $XMLRequest .= $BusinessFax != '' ? '' . $BusinessFax . '' : '';
            $XMLRequest .= $BusinessWebsite != '' ? '' . $BusinessWebsite . '' : '';
            $XMLRequest .= $BusinessCustom != '' ? '' . $BusinessCustom . '' : '';
            if (!empty($BusinessInfoAddress)) {
                $XMLRequest .= '';
                $XMLRequest .= $BusinessInfoAddressLine1 != '' ? '' . $BusinessInfoAddressLine1 . '' : '';
                $XMLRequest .= $BusinessInfoAddressLine2 != '' ? '' . $BusinessInfoAddressLine2 . '' : '';
                $XMLRequest .= $BusinessInfoAddressCity != '' ? '' . $BusinessInfoAddressCity . '' : '';
                $XMLRequest .= $BusinessInfoAddressState != '' ? '' . $BusinessInfoAddressState . '' : '';
                $XMLRequest .= $BusinessInfoAddressPostalCode != '' ? '' . $BusinessInfoAddressPostalCode . '' : '';
                $XMLRequest .= $BusinessInfoAddressCountryCode != '' ? '' . $BusinessInfoAddressCountryCode . '' : '';
                $XMLRequest .= $BusinessInfoAddressType != '' ? '' . $BusinessInfoAddressType . '' : '';
                $XMLRequest .= '';
            }
            $XMLRequest .= '';
        }
        if (!empty($InvoiceItems)) {
            $XMLRequest .= '';
            foreach ($InvoiceItems as $InvoiceItem) {
                $XMLRequest .= '
- ';
                $XMLRequest .= $InvoiceItem['Name'] != '' ? '' . $InvoiceItem['Name'] . '' : '';
                $XMLRequest .= $InvoiceItem['Description'] != '' ? '' . $InvoiceItem['Description'] . '' : '';
                $XMLRequest .= $InvoiceItem['Date'] != '' ? '' . $InvoiceItem['Date'] . '' : '';
                $XMLRequest .= $InvoiceItem['Quantity'] != '' ? '' . $InvoiceItem['Quantity'] . '' : '';
                $XMLRequest .= $InvoiceItem['UnitPrice'] != '' ? '' . $InvoiceItem['UnitPrice'] . '' : '';
                $XMLRequest .= $InvoiceItem['TaxName'] != '' ? '' . $InvoiceItem['TaxName'] . '' : '';
                $XMLRequest .= $InvoiceItem['TaxRate'] != '' ? '' . $InvoiceItem['TaxRate'] . '' : '';
                $XMLRequest .= '';
            }
            $XMLRequest .= '';
        }
        $XMLRequest .= $CurrencyCode != '' ? '' . $CurrencyCode . '' : '';
        $XMLRequest .= $InvoiceDate != '' ? '' . $InvoiceDate . '' : '';
        $XMLRequest .= $DueDate != '' ? '' . $DueDate . '' : '';
        $XMLRequest .= $PaymentTerms != '' ? '' . $PaymentTerms . '' : '';
        $XMLRequest .= $DiscountPercent != '' ? '' . $DiscountPercent . '' : '';
        $XMLRequest .= $DiscountAmount != '' ? '' . $DiscountAmount . '' : '';
        $XMLRequest .= $Terms != '' ? '' . $Terms . '' : '';
        $XMLRequest .= $Note != '' ? '' . $Note . '' : '';
        $XMLRequest .= $MerchantMemo != '' ? '' . $MerchantMemo . '' : '';
        if (!empty($BillingInfo)) {
            $XMLRequest .= '';
            $XMLRequest .= $BillingFirstName != '' ? '' . $BillingFirstName . '' : '';
            $XMLRequest .= $BillingLastName != '' ? '' . $BillingLastName . '' : '';
            $XMLRequest .= $BillingBusinessName != '' ? '' . $BillingBusinessName . '' : '';
            $XMLRequest .= $BillingPhone != '' ? '' . $BillingPhone . '' : '';
            $XMLRequest .= $BillingFax != '' ? '' . $BillingFax . '' : '';
            $XMLRequest .= $BillingWebsite != '' ? '' . $BillingWebsite . '' : '';
            $XMLRequest .= $BillingCustom != '' ? '' . $BillingCustom . '' : '';
            if (!empty($BillingInfoAddress)) {
                $XMLRequest .= '';
                $XMLRequest .= $BillingInfoAddressLine1 != '' ? '' . $BillingInfoAddressLine1 . '' : '';
                $XMLRequest .= $BillingInfoAddressLine2 != '' ? '' . $BillingInfoAddressLine2 . '' : '';
                $XMLRequest .= $BillingInfoAddressCity != '' ? '' . $BillingInfoAddressCity . '' : '';
                $XMLRequest .= $BillingInfoAddressState != '' ? '' . $BillingInfoAddressState . '' : '';
                $XMLRequest .= $BillingInfoAddressPostalCode != '' ? '' . $BillingInfoAddressPostalCode . '' : '';
                $XMLRequest .= $BillingInfoAddressCountryCode != '' ? '' . $BillingInfoAddressCountryCode . '' : '';
                $XMLRequest .= $BillingInfoAddressType != '' ? '' . $BillingInfoAddressType . '' : '';
                $XMLRequest .= '';
            }
            $XMLRequest .= '';
        }
        if (!empty($ShippingInfo)) {
            $XMLRequest .= '';
            $XMLRequest .= $ShippingFirstName != '' ? '' . $ShippingFirstName . '' : '';
            $XMLRequest .= $ShippingLastName != '' ? '' . $ShippingLastName . '' : '';
            $XMLRequest .= $ShippingBusinessName != '' ? '' . $ShippingBusinessName . '' : '';
            $XMLRequest .= $ShippingPhone != '' ? '' . $ShippingPhone . '' : '';
            $XMLRequest .= $ShippingFax != '' ? '' . $ShippingFax . '' : '';
            $XMLRequest .= $ShippingWebsite != '' ? '' . $ShippingWebsite . '' : '';
            $XMLRequest .= $ShippingCustom != '' ? '' . $ShippingCustom . '' : '';
            if (!empty($ShippingInfoAddress)) {
                $XMLRequest .= '';
                $XMLRequest .= $ShippingInfoAddressLine1 != '' ? '' . $ShippingInfoAddressLine1 . '' : '';
                $XMLRequest .= $ShippingInfoAddressLine2 != '' ? '' . $ShippingInfoAddressLine2 . '' : '';
                $XMLRequest .= $ShippingInfoAddressCity != '' ? '' . $ShippingInfoAddressCity . '' : '';
                $XMLRequest .= $ShippingInfoAddressState != '' ? '' . $ShippingInfoAddressState . '' : '';
                $XMLRequest .= $ShippingInfoAddressPostalCode != '' ? '' . $ShippingInfoAddressPostalCode . '' : '';
                $XMLRequest .= $ShippingInfoAddressCountryCode != '' ? '' . $ShippingInfoAddressCountryCode . '' : '';
                $XMLRequest .= $ShippingInfoAddressType != '' ? '' . $ShippingInfoAddressType . '' : '';
                $XMLRequest .= '';
            }
            $XMLRequest .= '';
        }
        $XMLRequest .= $ShippingAmount != '' ? '' . $ShippingAmount . '' : '';
        $XMLRequest .= $ShippingTaxName != '' ? '' . $ShippingTaxName . '' : '';
        $XMLRequest .= $ShippingTaxRate != '' ? '' . $ShippingTaxRate . '' : '';
        $XMLRequest .= $LogoURL != '' ? '' . $LogoURL . '' : '';
        $XMLRequest .= '';
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'Invoice', 'UpdateInvoice');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $InvoiceID = $DOM->getElementsByTagName('invoiceID')->length > 0 ? $DOM->getElementsByTagName('invoiceID')->item(0)->nodeValue : '';
        $InvoiceNumber = $DOM->getElementsByTagName('invoiceNumber')->length > 0 ? $DOM->getElementsByTagName('invoiceNumber')->item(0)->nodeValue : '';
        $InvoiceURL = $DOM->getElementsByTagName('invoiceURL')->length > 0 ? $DOM->getElementsByTagName('invoiceURL')->item(0)->nodeValue : '';
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'InvoiceID' => $InvoiceID,
            'InvoiceNumber' => $InvoiceNumber,
            'InvoiceURL' => $InvoiceURL,
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit UpdateInvoice API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function GetInvoiceDetails($InvoiceID) {
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= $InvoiceID != '' ? '' . $InvoiceID . '' : '';
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'Invoice', 'GetInvoiceDetails');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $InvoiceURL = $DOM->getElementsByTagName('invoiceURL')->length > 0 ? $DOM->getElementsByTagName('invoiceURL')->item(0)->nodeValue : '';
        $InvoiceType = $DOM->getElementsByTagName('invoice')->length > 0 ? $DOM->getElementsByTagName('invoice') : array();
        foreach ($InvoiceType as $Invoice) {
            $MerchantEmail = $Invoice->getElementsByTagName('merchantEmail')->length > 0 ? $Invoice->getElementsByTagName('merchantEmail')->item(0)->nodeValue : '';
            $PayerEmail = $Invoice->getElementsByTagName('payerEmail')->length > 0 ? $Invoice->getElementsByTagName('payerEmail')->item(0)->nodeValue : '';
            $Number = $Invoice->getElementsByTagName('number')->length > 0 ? $Invoice->getElementsByTagName('number')->item(0)->nodeValue : '';
            $CurrencyCode = $Invoice->getElementsByTagName('currencyCode')->length > 0 ? $Invoice->getElementsByTagName('currencyCode')->item(0)->nodeValue : '';
            $InvoiceDate = $Invoice->getElementsByTagName('invoiceDate')->length > 0 ? $Invoice->getElementsByTagName('invoiceDate')->item(0)->nodeValue : '';
            $DueDate = $Invoice->getElementsByTagName('dueDate')->length > 0 ? $Invoice->getElementsByTagName('dueDate')->item(0)->nodeValue : '';
            $PaymentTerms = $Invoice->getElementsByTagName('paymentTerms')->length > 0 ? $Invoice->getElementsByTagName('paymentTerms')->item(0)->nodeValue : '';
            $DiscountPercent = $Invoice->getElementsByTagName('discountPercent')->length > 0 ? $Invoice->getElementsByTagName('discountPercent')->item(0)->nodeValue : '';
            $DiscountAmount = $Invoice->getElementsByTagName('discountAmount')->length > 0 ? $Invoice->getElementsByTagName('discountAmount')->item(0)->nodeValue : '';
            $Terms = $Invoice->getElementsByTagName('terms')->length > 0 ? $Invoice->getElementsByTagName('terms')->item(0)->nodeValue : '';
            $InvoiceNote = $Invoice->getElementsByTagName('note')->length > 0 ? $Invoice->getElementsByTagName('note')->item(0)->nodeValue : '';
            $MerchantMemo = $Invoice->getElementsByTagName('merchantMemo')->length > 0 ? $Invoice->getElementsByTagName('merchantMemo')->item(0)->nodeValue : '';
            $ShippingAmount = $Invoice->getElementsByTagName('shippingAmount')->length > 0 ? $Invoice->getElementsByTagName('shippingAmount')->item(0)->nodeValue : '';
            $ShippingTaxName = $Invoice->getElementsByTagName('shippingTaxName')->length > 0 ? $Invoice->getElementsByTagName('shippingTaxName')->item(0)->nodeValue : '';
            $ShippingTaxRate = $Invoice->getElementsByTagName('shippingTaxRate')->length > 0 ? $Invoice->getElementsByTagName('shippingTaxRate')->item(0)->nodeValue : '';
            $LogoURL = $Invoice->getElementsByTagName('logoUrl')->length > 0 ? $Invoice->getElementsByTagName('logoUrl')->item(0)->nodeValue : '';
        }
        $InvoiceDetailsType = $DOM->getElementsByTagName('invoiceDetails')->length > 0 ? $DOM->getElementsByTagName('invoiceDetails') : array();
        foreach ($InvoiceDetailsType as $InvoiceDetails) {
            $Status = $InvoiceDetails->getElementsByTagName('status')->length > 0 ? $InvoiceDetails->getElementsByTagName('status')->item(0)->nodeValue : '';
            $TotalAmount = $InvoiceDetails->getElementsByTagName('totalAmount')->length > 0 ? $InvoiceDetails->getElementsByTagName('totalAmount')->item(0)->nodeValue : '';
            $Origin = $InvoiceDetails->getElementsByTagName('origin')->length > 0 ? $InvoiceDetails->getElementsByTagName('origin')->item(0)->nodeValue : '';
            $CreatedDate = $InvoiceDetails->getElementsByTagName('createdDate')->length > 0 ? $InvoiceDetails->getElementsByTagName('createdDate')->item(0)->nodeValue : '';
            $CreatedBy = $InvoiceDetails->getElementsByTagName('createdBy')->length > 0 ? $InvoiceDetails->getElementsByTagName('createdBy')->item(0)->nodeValue : '';
            $CanceledDate = $InvoiceDetails->getElementsByTagName('canceledDate')->length > 0 ? $InvoiceDetails->getElementsByTagName('canceledDate')->item(0)->nodeValue : '';
            $CanceledByActor = $InvoiceDetails->getElementsByTagName('canceledByActor')->length > 0 ? $InvoiceDetails->getElementsByTagName('canceledByActor')->item(0)->nodeValue : '';
            $CanceledBy = $InvoiceDetails->getElementsByTagName('canceledBy')->length > 0 ? $InvoiceDetails->getElementsByTagName('canceledBy')->item(0)->nodeValue : '';
            $LastUpdatedDate = $InvoiceDetails->getElementsByTagName('lastUpdatedDate')->length > 0 ? $InvoiceDetails->getElementsByTagName('lastUpdatedDate')->item(0)->nodeValue : '';
            $LastUpdatedBy = $InvoiceDetails->getElementsByTagName('lastUpdatedBy')->length > 0 ? $InvoiceDetails->getElementsByTagName('lastUpdatedBy')->item(0)->nodeValue : '';
            $FirstSentDate = $InvoiceDetails->getElementsByTagName('firstSentDate')->length > 0 ? $InvoiceDetails->getElementsByTagName('firstSentDate')->item(0)->nodeValue : '';
            $LastSentDate = $InvoiceDetails->getElementsByTagName('lastSentDate')->length > 0 ? $InvoiceDetails->getElementsByTagName('lastSentDate')->item(0)->nodeValue : '';
            $LastSentBy = $InvoiceDetails->getElementsByTagName('lastSentBy')->length > 0 ? $InvoiceDetails->getElementsByTagName('lastSentBy')->item(0)->nodeValue : '';
            $PaidDate = $InvoiceDetails->getElementsByTagName('paidDate')->length > 0 ? $InvoiceDetails->getElementsByTagName('paidDate')->item(0)->nodeValue : '';
        }
        $InvoiceItems = array();
        $InvoiceItemsType = $DOM->getElementsByTagName('item')->length > 0 ? $DOM->getElementsByTagName('item') : array();
        foreach ($InvoiceItemsType as $InvoiceItem) {
            $ItemName = $InvoiceItem->getElementsByTagName('name')->length > 0 ? $InvoiceItem->getElementsByTagName('name')->item(0)->nodeValue : '';
            $ItemDescription = $InvoiceItem->getElementsByTagName('description')->length > 0 ? $InvoiceItem->getElementsByTagName('description')->item(0)->nodeValue : '';
            $ItemDate = $InvoiceItem->getElementsByTagName('date')->length > 0 ? $InvoiceItem->getElementsByTagName('date')->item(0)->nodeValue : '';
            $ItemQuantity = $InvoiceItem->getElementsByTagName('quantity')->length > 0 ? $InvoiceItem->getElementsByTagName('quantity')->item(0)->nodeValue : '';
            $ItemUnitPrice = $InvoiceItem->getElementsByTagName('unitPrice')->length > 0 ? $InvoiceItem->getElementsByTagName('unitPrice')->item(0)->nodeValue : '';
            $ItemTaxName = $InvoiceItem->getElementsByTagName('taxName')->length > 0 ? $InvoiceItem->getElementsByTagName('taxName')->item(0)->nodeValue : '';
            $ItemTaxRate = $InvoiceItem->getElementsByTagName('taxRate')->length > 0 ? $InvoiceItem->getElementsByTagName('taxRate')->item(0)->nodeValue : '';
            $InvoiceItemArray = array(
                'Name' => $ItemName,
                'Description' => $ItemDescription,
                'Date' => $ItemDate,
                'Quantity' => $ItemQuantity,
                'UnitPrice' => $ItemUnitPrice,
                'TaxName' => $ItemTaxName,
                'TaxRate' => $ItemTaxRate
            );
            array_push($InvoiceItems, $InvoiceItemArray);
        }
        $MerchantInfoType = $DOM->getElementsByTagName('merchantInfo')->length > 0 ? $DOM->getElementsByTagName('merchantInfo') : array();
        foreach ($MerchantInfoType as $MerchantInfo) {
            $MerchantFirstName = $MerchantInfo->getElementsByTagName('firstName')->length > 0 ? $MerchantInfo->getElementsByTagName('firstName')->item(0)->nodeValue : '';
            $MerchantLastName = $MerchantInfo->getElementsByTagName('lastName')->length > 0 ? $MerchantInfo->getElementsByTagName('lastName')->item(0)->nodeValue : '';
            $MerchantBusinessName = $MerchantInfo->getElementsByTagName('businessName')->length > 0 ? $MerchantInfo->getElementsByTagName('businessName')->item(0)->nodeValue : '';
            $MerchantPhone = $MerchantInfo->getElementsByTagName('phone')->length > 0 ? $MerchantInfo->getElementsByTagName('phone')->item(0)->nodeValue : '';
            $MerchantFax = $MerchantInfo->getElementsByTagName('fax')->length > 0 ? $MerchantInfo->getElementsByTagName('fax')->item(0)->nodeValue : '';
            $MerchantWebsite = $MerchantInfo->getElementsByTagName('website')->length > 0 ? $MerchantInfo->getElementsByTagName('website')->item(0)->nodeValue : '';
            $MerchantCustom = $MerchantInfo->getElementsByTagName('customValue')->length > 0 ? $MerchantInfo->getElementsByTagName('customValue')->item(0)->nodeValue : '';
            $MerchantInfoAddressType = $MerchantInfo->getElementsByTagName('address')->length > 0 ? $MerchantInfo->getElementsByTagName('address') : array();
            foreach ($MerchantInfoAddressType as $MerchantInfoAddress) {
                $MerchantAddressLine1 = $MerchantInfoAddress->getElementsByTagName('line1')->length > 0 ? $MerchantInfoAddress->getElementsByTagName('line1')->item(0)->nodeValue : '';
                $MerchantAddressLine2 = $MerchantInfoAddress->getElementsByTagName('line2')->length > 0 ? $MerchantInfoAddress->getElementsByTagName('line2')->item(0)->nodeValue : '';
                $MerchantAddressCity = $MerchantInfoAddress->getElementsByTagName('city')->length > 0 ? $MerchantInfoAddress->getElementsByTagName('city')->item(0)->nodeValue : '';
                $MerchantAddressState = $MerchantInfoAddress->getElementsByTagName('state')->length > 0 ? $MerchantInfoAddress->getElementsByTagName('state')->item(0)->nodeValue : '';
                $MerchantAddressPostalCode = $MerchantInfoAddress->getElementsByTagName('postalCode')->length > 0 ? $MerchantInfoAddress->getElementsByTagName('postalCode')->item(0)->nodeValue : '';
                $MerchantAddressCountryCode = $MerchantInfoAddress->getElementsByTagName('countryCode')->length > 0 ? $MerchantInfoAddress->getElementsByTagName('countryCode')->item(0)->nodeValue : '';
                $MerchantAddressType = $MerchantInfoAddress->getElementsByTagName('type')->length > 0 ? $MerchantInfoAddress->getElementsByTagName('type')->item(0)->nodeValue : '';
            }
        }
        $BillingInfoType = $DOM->getElementsByTagName('billingInfo')->length > 0 ? $DOM->getElementsByTagName('billingInfo') : array();
        foreach ($BillingInfoType as $BillingInfo) {
            $BillingFirstName = $BillingInfo->getElementsByTagName('firstName')->length > 0 ? $BillingInfo->getElementsByTagName('firstName')->item(0)->nodeValue : '';
            $BillingLastName = $BillingInfo->getElementsByTagName('lastName')->length > 0 ? $BillingInfo->getElementsByTagName('lastName')->item(0)->nodeValue : '';
            $BillingBusinessName = $BillingInfo->getElementsByTagName('businessName')->length > 0 ? $BillingInfo->getElementsByTagName('businessName')->item(0)->nodeValue : '';
            $BillingPhone = $BillingInfo->getElementsByTagName('phone')->length > 0 ? $BillingInfo->getElementsByTagName('phone')->item(0)->nodeValue : '';
            $BillingFax = $BillingInfo->getElementsByTagName('fax')->length > 0 ? $BillingInfo->getElementsByTagName('fax')->item(0)->nodeValue : '';
            $BillingWebsite = $BillingInfo->getElementsByTagName('website')->length > 0 ? $BillingInfo->getElementsByTagName('website')->item(0)->nodeValue : '';
            $BillingCustom = $BillingInfo->getElementsByTagName('customValue')->length > 0 ? $BillingInfo->getElementsByTagName('customValue')->item(0)->nodeValue : '';
            $BillingInfoAddressType = $BillingInfo->getElementsByTagName('address')->length > 0 ? $BillingInfo->getElementsByTagName('address') : array();
            foreach ($BillingInfoAddressType as $BillingInfoAddress) {
                $BillingAddressLine1 = $BillingInfoAddress->getElementsByTagName('line1')->length > 0 ? $BillingInfoAddress->getElementsByTagName('line1')->item(0)->nodeValue : '';
                $BillingAddressLine2 = $BillingInfoAddress->getElementsByTagName('line2')->length > 0 ? $BillingInfoAddress->getElementsByTagName('line2')->item(0)->nodeValue : '';
                $BillingAddressCity = $BillingInfoAddress->getElementsByTagName('city')->length > 0 ? $BillingInfoAddress->getElementsByTagName('city')->item(0)->nodeValue : '';
                $BillingAddressState = $BillingInfoAddress->getElementsByTagName('state')->length > 0 ? $BillingInfoAddress->getElementsByTagName('state')->item(0)->nodeValue : '';
                $BillingAddressPostalCode = $BillingInfoAddress->getElementsByTagName('postalCode')->length > 0 ? $BillingInfoAddress->getElementsByTagName('postalCode')->item(0)->nodeValue : '';
                $BillingAddressCountryCode = $BillingInfoAddress->getElementsByTagName('countryCode')->length > 0 ? $BillingInfoAddress->getElementsByTagName('countryCode')->item(0)->nodeValue : '';
                $BillingAddressType = $BillingInfoAddress->getElementsByTagName('type')->length > 0 ? $BillingInfoAddress->getElementsByTagName('type')->item(0)->nodeValue : '';
            }
        }
        $ShippingInfoType = $DOM->getElementsByTagName('shippingInfo')->length > 0 ? $DOM->getElementsByTagName('shippingInfo') : array();
        foreach ($ShippingInfoType as $ShippingInfo) {
            $ShippingFirstName = $ShippingInfo->getElementsByTagName('firstName')->length > 0 ? $ShippingInfo->getElementsByTagName('firstName')->item(0)->nodeValue : '';
            $ShippingLastName = $ShippingInfo->getElementsByTagName('lastName')->length > 0 ? $ShippingInfo->getElementsByTagName('lastName')->item(0)->nodeValue : '';
            $ShippingBusinessName = $ShippingInfo->getElementsByTagName('businessName')->length > 0 ? $ShippingInfo->getElementsByTagName('businessName')->item(0)->nodeValue : '';
            $ShippingPhone = $ShippingInfo->getElementsByTagName('phone')->length > 0 ? $ShippingInfo->getElementsByTagName('phone')->item(0)->nodeValue : '';
            $ShippingFax = $ShippingInfo->getElementsByTagName('fax')->length > 0 ? $ShippingInfo->getElementsByTagName('fax')->item(0)->nodeValue : '';
            $ShippingWebsite = $ShippingInfo->getElementsByTagName('website')->length > 0 ? $ShippingInfo->getElementsByTagName('website')->item(0)->nodeValue : '';
            $ShippingCustom = $ShippingInfo->getElementsByTagName('customValue')->length > 0 ? $ShippingInfo->getElementsByTagName('customValue')->item(0)->nodeValue : '';
            $ShippingInfoAddressType = $ShippingInfo->getElementsByTagName('address')->length > 0 ? $ShippingInfo->getElementsByTagName('address') : array();
            foreach ($ShippingInfoAddressType as $ShippingInfoAddress) {
                $ShippingAddressLine1 = $ShippingInfoAddress->getElementsByTagName('line1')->length > 0 ? $ShippingInfoAddress->getElementsByTagName('line1')->item(0)->nodeValue : '';
                $ShippingAddressLine2 = $ShippingInfoAddress->getElementsByTagName('line2')->length > 0 ? $ShippingInfoAddress->getElementsByTagName('line2')->item(0)->nodeValue : '';
                $ShippingAddressCity = $ShippingInfoAddress->getElementsByTagName('city')->length > 0 ? $ShippingInfoAddress->getElementsByTagName('city')->item(0)->nodeValue : '';
                $ShippingAddressState = $ShippingInfoAddress->getElementsByTagName('state')->length > 0 ? $ShippingInfoAddress->getElementsByTagName('state')->item(0)->nodeValue : '';
                $ShippingAddressPostalCode = $ShippingInfoAddress->getElementsByTagName('postalCode')->length > 0 ? $ShippingInfoAddress->getElementsByTagName('postalCode')->item(0)->nodeValue : '';
                $ShippingAddressCountryCode = $ShippingInfoAddress->getElementsByTagName('countryCode')->length > 0 ? $ShippingInfoAddress->getElementsByTagName('countryCode')->item(0)->nodeValue : '';
                $ShippingAddressType = $ShippingInfoAddress->getElementsByTagName('type')->length > 0 ? $ShippingInfoAddress->getElementsByTagName('type')->item(0)->nodeValue : '';
            }
        }
        $ViaPayPal = $DOM->getElementsByTagName('viaPayPal')->length > 0 ? $DOM->getElementsByTagName('viaPayPal')->item(0)->nodeValue : '';
        $PayPalPaymentDetailsType = $DOM->getElementsByTagName('paypalPayment')->length > 0 ? $DOM->getElementsByTagName('paypalPayment') : array();
        foreach ($PayPalPaymentDetailsType as $PayPalPaymentDetails) {
            $PayPalTransactionID = $PayPalPaymentDetails->getElementsByTagName('transactionID')->length > 0 ? $PayPalPaymentDetails->getElementsByTagName('transactionID')->item(0)->nodeValue : '';
            $PayPalTransactionDate = $PayPalPaymentDetails->getElementsByTagName('date')->length > 0 ? $PayPalPaymentDetails->getElementsByTagName('date')->item(0)->nodeValue : '';
        }
        $OtherPaymentDetailsType = $DOM->getElementsByTagName('otherPayment')->length > 0 ? $DOM->getElementsByTagName('otherPayment') : array();
        foreach ($OtherPaymentDetailsType as $OtherPaymentDetails) {
            $PaymentMethod = $OtherPaymentDetails->getElementsByTagName('method')->length > 0 ? $OtherPaymentDetails->getElementsByTagName('method')->item(0)->nodeValue : '';
            $PaymentMethodNote = $OtherPaymentDetails->getElementsByTagName('note')->length > 0 ? $OtherPaymentDetails->getElementsByTagName('note')->item(0)->nodeValue : '';
            $PaymentMethodDate = $OtherPaymentDetails->getElementsByTagName('date')->length > 0 ? $OtherPaymentDetails->getElementsByTagName('date')->item(0)->nodeValue : '';
        }
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'InvoiceURL' => $InvoiceURL,
            'MerchantEmail' => isset($MerchantEmail) ? $MerchantEmail : '',
            'PayerEmail' => isset($PayerEmail) ? $PayerEmail : '',
            'Number' => isset($Number) ? $Number : '',
            'CurrencyCode' => isset($CurrencyCode) ? $CurrencyCode : '',
            'InvoiceDate' => isset($InvoiceDate) ? $InvoiceDate : '',
            'DueDate' => isset($DueDate) ? $DueDate : '',
            'PaymentTerms' => isset($PaymentTerms) ? $PaymentTerms : '',
            'DiscountPercent' => isset($DiscountPercent) ? $DiscountPercent : '',
            'DiscountAmount' => isset($DiscountAmount) ? $DiscountAmount : '',
            'Terms' => isset($Terms) ? $Terms : '',
            'InvoiceNote' => isset($InvoiceNote) ? $InvoiceNote : '',
            'MerchantMemo' => isset($MerchantMemo) ? $MerchantMemo : '',
            'ShippingAmount' => isset($ShippingAmount) ? $ShippingAmount : '',
            'ShippingTaxName' => isset($ShippingTaxName) ? $ShippingTaxName : '',
            'ShippingTaxRate' => isset($ShippingTaxRate) ? $ShippingTaxRate : '',
            'LogoURL' => isset($LogoURL) ? $LogoURL : '',
            'Status' => isset($Status) ? $Status : '',
            'TotalAmount' => isset($TotalAmount) ? $TotalAmount : '',
            'Origin' => isset($Origin) ? $Origin : '',
            'CreatedDate' => isset($CreatedDate) ? $CreatedDate : '',
            'CreatedBy' => isset($CreatedBy) ? $CreatedBy : '',
            'CanceledDate' => isset($CanceledDate) ? $CanceledDate : '',
            'CanceledByActor' => isset($CanceledByActor) ? $CanceledByActor : '',
            'CanceledBy' => isset($CanceledBy) ? $CanceledBy : '',
            'LastUpdatedDate' => isset($LastUpdatedDate) ? $LastUpdatedDate : '',
            'LastUpdatedBy' => isset($LastUpdatedBy) ? $LastUpdatedBy : '',
            'FistSentDate' => isset($FirstSentDate) ? $FirstSentDate : '',
            'LastSentDate' => isset($LastSentDate) ? $LastSentDate : '',
            'LastSentBy' => isset($LastSentBy) ? $LastSentBy : '',
            'PaidDate' => isset($PaidDate) ? $PaidDate : '',
            'InvoiceItems' => isset($InvoiceItems) ? $InvoiceItems : '',
            'MerchantFirstName' => isset($MerchantFirstName) ? $MerchantFirstName : '',
            'MerchantLastName' => isset($MerchantLastName) ? $MerchantLastName : '',
            'MerchantBusinessName' => isset($MerchantBusinessName) ? $MerchantBusinessName : '',
            'MerchantPhone' => isset($MerchantPhone) ? $MerchantPhone : '',
            'MerchantFax' => isset($MerchantFax) ? $MerchantFax : '',
            'MerchantWebsite' => isset($MerchantWebsite) ? $MerchantWebsite : '',
            'MerchantCustom' => isset($MerchantCustom) ? $MerchantCustom : '',
            'MerchantAddressLine1' => isset($MerchantAddressLine1) ? $MerchantAddressLine1 : '',
            'MerchantAddressLine2' => isset($MerchantAddressLine2) ? $MerchantAddressLine2 : '',
            'MerchantAddressCity' => isset($MerchantAddressCity) ? $MerchantAddressCity : '',
            'MerchantAddressState' => isset($MerchantAddressState) ? $MerchantAddressState : '',
            'MerchantAddressPostalCode' => isset($MerchantAddressPostalCode) ? $MerchantAddressPostalCode : '',
            'MerchantAddressCountryCode' => isset($MerchantAddressCountryCode) ? $MerchantAddressCountryCode : '',
            'MerchantAddressType' => isset($MerchantAddressType) ? $MerchantAddressType : '',
            'BillingFirstName' => isset($BillingFirstName) ? $BillingFirstName : '',
            'BillingLastName' => isset($BillingLastName) ? $BillingLastName : '',
            'BillingBusinessName' => isset($BillingBusinessName) ? $BillingBusinessName : '',
            'BillingPhone' => isset($BillingPhone) ? $BillingPhone : '',
            'BillingFax' => isset($BillingFax) ? $BillingFax : '',
            'BillingWebsite' => isset($BillingWebsite) ? $BillingWebsite : '',
            'BillingCustom' => isset($BillingCustom) ? $BillingCustom : '',
            'BillingAddressLine1' => isset($BillingAddressLine1) ? $BillingAddressLine1 : '',
            'BillingAddressLine2' => isset($BillingAddressLine2) ? $BillingAddressLine2 : '',
            'BillingAddressCity' => isset($BillingAddressCity) ? $BillingAddressCity : '',
            'BillingAddressState' => isset($BillingAddressState) ? $BillingAddressState : '',
            'BillingAddressPostalCode' => isset($BillingAddressPostalCode) ? $BillingAddressPostalCode : '',
            'BillingAddressCountryCode' => isset($BillingAddressCountryCode) ? $BillingAddressCountryCode : '',
            'BillingAddressType' => isset($BillingAddressType) ? $BillingAddressType : '',
            'ShippingFirstName' => isset($ShippingFirstName) ? $ShippingFirstName : '',
            'ShippingLastName' => isset($ShippingLastName) ? $ShippingLastName : '',
            'ShippingBusinessName' => isset($ShippingBusinessName) ? $ShippingBusinessName : '',
            'ShippingPhone' => isset($ShippingPhone) ? $ShippingPhone : '',
            'ShippingFax' => isset($ShippingFax) ? $ShippingFax : '',
            'ShippingWebsite' => isset($ShippingWebsite) ? $ShippingWebsite : '',
            'ShippingCustom' => isset($ShippingCustom) ? $ShippingCustom : '',
            'ShippingAddressLine1' => isset($ShippingAddressLine1) ? $ShippingAddressLine1 : '',
            'ShippingAddressLine2' => isset($ShippingAddressLine2) ? $ShippingAddressLine2 : '',
            'ShippingAddressCity' => isset($ShippingAddressCity) ? $ShippingAddressCity : '',
            'ShippingAddressState' => isset($ShippingAddressState) ? $ShippingAddressState : '',
            'ShippingAddressPostalCode' => isset($ShippingAddressPostalCode) ? $ShippingAddressPostalCode : '',
            'ShippingAddressCountryCode' => isset($ShippingAddressCountryCode) ? $ShippingAddressCountryCode : '',
            'ShippingAddressType' => isset($ShippingAddressType) ? $ShippingAddressType : '',
            'ViaPayPal' => isset($ViaPayPal) ? $ViaPayPal : '',
            'PayPalTransactionID' => isset($PayPalTransactionID) ? $PayPalTransactionID : '',
            'PayPalTransactionDate' => isset($PayPalTransactionDate) ? $PayPalTransactionDate : '',
            'PaymentMethod' => isset($PaymentMethod) ? $PaymentMethod : '',
            'PaymentMethodNote' => isset($PaymentMethodNote) ? $PaymentMethodNote : '',
            'PaymentMethodDate' => isset($PaymentMethodDate) ? $PaymentMethodDate : '',
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit CancelInvoice API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function CancelInvoice($DataArray) {
        $CancelInvoiceFields = isset($DataArray['CancelInvoiceFields']) ? $DataArray['CancelInvoiceFields'] : array();
        $InvoiceID = isset($CancelInvoiceFields['InvoiceID']) ? $CancelInvoiceFields['InvoiceID'] : '';
        $Subject = isset($CancelInvoiceFields['Subject']) ? $CancelInvoiceFields['Subject'] : '';
        $NoteForPayer = isset($CancelInvoiceFields['NoteForPayer']) ? $CancelInvoiceFields['NoteForPayer'] : '';
        $SendCopyToMerchant = isset($CancelInvoiceFields['SendCopyToMerchant']) ? $CancelInvoiceFields['SendCopyToMerchant'] : '';
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= $InvoiceID != '' ? '' . $InvoiceID . '' : '';
        $XMLRequest .= $Subject != '' ? '' . $Subject . '' : '';
        $XMLRequest .= $NoteForPayer != '' ? '' . $NoteForPayer . '' : '';
        $XMLRequest .= $SendCopyToMerchant != '' ? '' . $SendCopyToMerchant . '' : '';
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'Invoice', 'CancelInvoice');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $InvoiceID = $DOM->getElementsByTagName('invoiceID')->length > 0 ? $DOM->getElementsByTagName('invoiceID')->item(0)->nodeValue : '';
        $InvoiceNumber = $DOM->getElementsByTagName('invoiceNumber')->length > 0 ? $DOM->getElementsByTagName('invoiceNumber')->item(0)->nodeValue : '';
        $InvoiceURL = $DOM->getElementsByTagName('invoiceURL')->length > 0 ? $DOM->getElementsByTagName('invoiceURL')->item(0)->nodeValue : '';
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'InvoiceID' => $InvoiceID,
            'InvoiceNumber' => $InvoiceNumber,
            'InvoiceURL' => $InvoiceURL,
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit SearchInvoices API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function SearchInvoices($DataArray) {
        $SearchInvoicesFields = isset($DataArray['SearchInvoicesFields']) ? $DataArray['SearchInvoicesFields'] : array();
        $MerchantEmail = isset($SearchInvoicesFields['MerchantEmail']) ? $SearchInvoicesFields['MerchantEmail'] : '';
        $Page = isset($SearchInvoicesFields['Page']) ? $SearchInvoicesFields['Page'] : '';
        $PageSize = isset($SearchInvoicesFields['PageSize']) ? $SearchInvoicesFields['PageSize'] : '';
        $Parameters = isset($DataArray['Parameters']) ? $DataArray['Parameters'] : array();
        $Email = isset($Parameters['Email']) ? $Parameters['Email'] : '';
        $RecipientName = isset($Parameters['RecipientName']) ? $Parameters['RecipientName'] : '';
        $BusinessName = isset($Parameters['BusinessName']) ? $Parameters['BusinessName'] : '';
        $InvoiceNumber = isset($Parameters['InvoiceNumber']) ? $Parameters['InvoiceNumber'] : '';
        $Status = isset($Parameters['Status']) ? $Parameters['Status'] : '';
        $LowerAmount = isset($Parameters['LowerAmount']) ? $Parameters['LowerAmount'] : '';
        $UpperAmount = isset($Parameters['UpperAmount']) ? $Parameters['UpperAmount'] : '';
        $CurrencyCode = isset($Parameters['CurrencyCode']) ? $Parameters['CurrencyCode'] : '';
        $Memo = isset($Parameters['Memo']) ? $Parameters['Memo'] : '';
        $Origin = isset($Parameters['Origin']) ? $Parameters['Origin'] : '';
        $InvoiceDate = isset($Parameters['InvoiceDate']) ? $Parameters['InvoiceDate'] : array();
        $DueDate = isset($Parameters['DueDate']) ? $Parameters['DueDate'] : array();
        $PaymentDate = isset($Parameters['PaymentDate']) ? $Parameters['PaymentDate'] : array();
        $CreationDate = isset($Parameters['CreationDate']) ? $Parameters['CreationDate'] : array();
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= $MerchantEmail != '' ? '' . $MerchantEmail . '' : '';
        $XMLRequest .= $Page != '' ? '' . $Page . '' : '';
        $XMLRequest .= $PageSize != '' ? '' . $PageSize . '' : '';
        if (!empty($Parameters)) {
            $XMLRequest .= '';
            $XMLRequest .= $Email != '' ? '' . $Email . '' : '';
            $XMLRequest .= $RecipientName != '' ? '' . $RecipientName . '' : '';
            $XMLRequest .= $BusinessName != '' ? '' . $BusinessName . '' : '';
            $XMLRequest .= $InvoiceNumber != '' ? '' . $InvoiceNumber . '' : '';
            $XMLRequest .= $Status != '' ? '' . $Status . '' : '';
            $XMLRequest .= $LowerAmount != '' ? '' . $LowerAmount . '' : '';
            $XMLRequest .= $UpperAmount != '' ? '' . $UpperAmount . '' : '';
            $XMLRequest .= $CurrencyCode != '' ? '' . $CurrencyCode . '' : '';
            $XMLRequest .= $Memo != '' ? '' . $Memo . '' : '';
            $XMLRequest .= $Origin != '' ? '' . $Origin . '' : '';
            if (!empty($InvoiceDate)) {
                $XMLRequest .= '';
                $XMLRequest .= '' . $InvoiceDate['StartDate'] . '';
                $XMLRequest .= '' . $InvoiceDate['EndDate'] . '';
                $XMLRequest .= '';
            }
            if (!empty($DueDate)) {
                $XMLRequest .= '';
                $XMLRequest .= '' . $DueDate['StartDate'] . '';
                $XMLRequest .= '' . $DueDate['EndDate'] . '';
                $XMLRequest .= '';
            }
            if (!empty($PaymentDate)) {
                $XMLRequest .= '';
                $XMLRequest .= '' . $PaymentDate['StartDate'] . '';
                $XMLRequest .= '' . $PaymentDate['EndDate'] . '';
                $XMLRequest .= '';
            }
            if (!empty($CreationDate)) {
                $XMLRequest .= '';
                $XMLRequest .= '' . $CreationDate['StartDate'] . '';
                $XMLRequest .= '' . $CreationDate['EndDate'] . '';
                $XMLRequest .= '';
            }
            $XMLRequest .= '';
        }
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'Invoice', 'CancelInvoice');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $Count = $DOM->getElementsByTagName('count')->length > 0 ? $DOM->getElementsByTagName('count')->item(0)->nodeValue : '';
        $Page = $DOM->getElementsByTagName('page')->length > 0 ? $DOM->getElementsByTagName('page')->item(0)->nodeValue : '';
        $HasNextPage = $DOM->getElementsByTagName('hasNextPage')->length > 0 ? $DOM->getElementsByTagName('hasNextPage')->item(0)->nodeValue : '';
        $HasPreviousPage = $DOM->getElementsByTagName('hasPreviousPage')->length > 0 ? $DOM->getElementsByTagName('hasPreviousPage')->item(0)->nodeValue : '';
        $InvoicesType = $DOM->getElementsByTagName('invoice')->length > 0 ? $DOM->getElementsByTagName('invoice') : array();
        $Invoices = array();
        foreach ($InvoicesType as $Invoice) {
            $InvoiceID = $Invoice->getElementsByTagName('invoiceID')->length > 0 ? $Invoice->getElementsByTagName('invoiceID')->item(0)->nodeValue : '';
            $MerchantEmail = $Invoice->getElementsByTagName('merchantEmail')->length > 0 ? $Invoice->getElementsByTagName('merchantEmail')->item(0)->nodeValue : '';
            $PayerEmail = $Invoice->getElementsByTagName('payerEmail')->length > 0 ? $Invoice->getElementsByTagName('payerEmail')->item(0)->nodeValue : '';
            $Number = $Invoice->getElementsByTagName('number')->length > 0 ? $Invoice->getElementsByTagName('number')->item(0)->nodeValue : '';
            $BillingBusinessName = $Invoice->getElementsByTagName('billingBusinessName')->length > 0 ? $Invoice->getElementsByTagName('billingBusinessName')->item(0)->nodeValue : '';
            $BillingFirstName = $Invoice->getElementsByTagName('billingFirstName')->length > 0 ? $Invoice->getElementsByTagName('billingFirstName')->item(0)->nodeValue : '';
            $BillingLastName = $Invoice->getElementsByTagName('billingLastName')->length > 0 ? $Invoice->getElementsByTagName('billingLastName')->item(0)->nodeValue : '';
            $ShippingBusinessName = $Invoice->getElementsByTagName('shippingBusinessName')->length > 0 ? $Invoice->getElementsByTagName('shippingBusinessName')->item(0)->nodeValue : '';
            $ShippingFirstName = $Invoice->getElementsByTagName('shippingFirstName')->length > 0 ? $Invoice->getElementsByTagName('shippingFirstName')->item(0)->nodeValue : '';
            $ShippingLastName = $Invoice->getElementsByTagName('shippingLastName')->length > 0 ? $Invoice->getElementsByTagName('shippingLastName')->item(0)->nodeValue : '';
            $TotalAmount = $Invoice->getElementsByTagName('totalAmount')->length > 0 ? $Invoice->getElementsByTagName('totalAmount')->item(0)->nodeValue : '';
            $CurrencyCode = $Invoice->getElementsByTagName('currencyCode')->length > 0 ? $Invoice->getElementsByTagName('currencyCode')->item(0)->nodeValue : '';
            $InvoiceDate = $Invoice->getElementsByTagName('invoiceDate')->length > 0 ? $Invoice->getElementsByTagName('invoiceDate')->item(0)->nodeValue : '';
            $DueDate = $Invoice->getElementsByTagName('dueDate')->length > 0 ? $Invoice->getElementsByTagName('dueDate')->item(0)->nodeValue : '';
            $Status = $Invoice->getElementsByTagName('status')->length > 0 ? $Invoice->getElementsByTagName('status')->item(0)->nodeValue : '';
            $Origin = $Invoice->getElementsByTagName('origin')->length > 0 ? $Invoice->getElementsByTagName('origin')->item(0)->nodeValue : '';
            $InvoiceItem = array(
                'InvoiceID' => $InvoiceID,
                'MerchantEmail' => $MerchantEmail,
                'PayerEmail' => $PayerEmail,
                'Number' => $Number,
                'BillingBusinessName' => $BillingBusinessName,
                'BillingFirstName' => $BillingFirstName,
                'BillingLastName' => $BillingLastName,
                'ShippingBusinessName' => $ShippingBusinessName,
                'ShippingFirstName' => $ShippingFirstName,
                'ShippingLastName' => $ShippingLastName,
                'TotalAmount' => $TotalAmount,
                'CurrencyCode' => $CurrencyCode,
                'InvoiceDate' => $InvoiceDate,
                'DueDate' => $DueDate,
                'Status' => $Status,
                'Origin' => $Origin
            );
            array_push($Invoices, $InvoiceItem);
        }
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'Count' => $Count,
            'Page' => $Page,
            'HasNextPage' => $HasNextPage,
            'HasPreviousPage' => $HasPreviousPage,
            'Invoices' => $Invoices,
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit MarkInvoiceAsPaid API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function MarkInvoiceAsPaid($DataArray) {
        $MarkInvoiceAsPaidFields = isset($DataArray['MarkInvoiceAsPaidFields']) ? $DataArray['MarkInvoiceAsPaidFields'] : array();
        $InvoiceID = isset($MarkInvoiceAsPaidFields['InvoiceID']) ? $MarkInvoiceAsPaidFields['InvoiceID'] : '';
        $Method = isset($MarkInvoiceAsPaidFields['Method']) ? $MarkInvoiceAsPaidFields['Method'] : '';
        $Note = isset($MarkInvoiceAsPaidFields['Note']) ? $MarkInvoiceAsPaidFields['Note'] : '';
        $Date = isset($MarkInvoiceAsPaidFields['Date']) ? $MarkInvoiceAsPaidFields['Date'] : '';
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= $InvoiceID != '' ? '' . $InvoiceID . '' : '';
        $XMLRequest .= '';
        $XMLRequest .= $Method != '' ? '' . $Method . '' : '';
        $XMLRequest .= $Note != '' ? '' . $Note . '' : '';
        $XMLRequest .= $Date != '' ? '' . $Date . '' : '';
        $XMLRequest .= '';
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'Invoice', 'MarkInvoiceAsPaid');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $InvoiceID = $DOM->getElementsByTagName('invoiceID')->length > 0 ? $DOM->getElementsByTagName('invoiceID')->item(0)->nodeValue : '';
        $InvoiceNumber = $DOM->getElementsByTagName('invoiceNumber')->length > 0 ? $DOM->getElementsByTagName('invoiceNumber')->item(0)->nodeValue : '';
        $InvoiceURL = $DOM->getElementsByTagName('invoiceURL')->length > 0 ? $DOM->getElementsByTagName('invoiceURL')->item(0)->nodeValue : '';
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'InvoiceID' => $InvoiceID,
            'InvoiceNumber' => $InvoiceNumber,
            'InvoiceURL' => $InvoiceURL,
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit RequestPermissions API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function RequestPermissions($DataArray) {
        $RequestPermissionsFields = isset($DataArray['RequestPermissionsFields']) ? $DataArray['RequestPermissionsFields'] : array();
        $Scope = isset($RequestPermissionsFields['Scope']) ? $RequestPermissionsFields['Scope'] : array();
        $Callback = isset($RequestPermissionsFields['Callback']) ? $RequestPermissionsFields['Callback'] : '';
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        foreach ($Scope as $Value) {
            $XMLRequest .= $Scope != '' ? '' . $Value . '' : '';
        }
        $XMLRequest .= $Callback != '' ? '' . $Callback . '' : '';
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'Permissions', 'RequestPermissions');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $Token = $DOM->getElementsByTagName('token')->length > 0 ? $DOM->getElementsByTagName('token')->item(0)->nodeValue : '';
        $RedirectURL = $this->Sandbox ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_grant-permission&request_token=' . $Token : 'https://www.paypal.com/cgi-bin/webscr?cmd=_grant-permission&request_token=' . $Token;
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'Token' => $Token,
            'RedirectURL' => $RedirectURL,
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit GetAccessToken API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function GetAccessToken($DataArray) {
        $GetAccessTokenFields = isset($DataArray['GetAccessTokenFields']) ? $DataArray['GetAccessTokenFields'] : array();
        $Token = isset($GetAccessTokenFields['Token']) ? $GetAccessTokenFields['Token'] : '';
        $Verifier = isset($GetAccessTokenFields['Verifier']) ? $GetAccessTokenFields['Verifier'] : '';
        $SubjectAlias = isset($GetAccessTokenFields['SubjectAlias']) ? $GetAccessTokenFields['SubjectAlias'] : '';
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= $Token != '' ? '' . $Token . '' : '';
        $XMLRequest .= $Verifier != '' ? '' . $Verifier . '' : '';
        $XMLRequest .= $SubjectAlias != '' ? '' . $SubjectAlias . '' : '';
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'Permissions', 'GetAccessToken');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $Scope = array();
        $Scopes = $DOM->getElementsByTagName('scope')->length > 0 ? $DOM->getElementsByTagName('scope') : array();
        foreach ($Scopes as $ScopeType) {
            array_push($Scope, $ScopeType->nodeValue);
        }
        $Token = $DOM->getElementsByTagName('token')->length > 0 ? $DOM->getElementsByTagName('token')->item(0)->nodeValue : '';
        $TokenSecret = $DOM->getElementsByTagName('tokenSecret')->length > 0 ? $DOM->getElementsByTagName('tokenSecret')->item(0)->nodeValue : '';
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'Scope' => $Scope,
            'Token' => $Token,
            'TokenSecret' => $TokenSecret,
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit GetPermissions API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function GetPermissions($Token) {
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= $Token != '' ? '' . $Token . '' : '';
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'Permissions', 'GetPermissions');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $Scope = array();
        $Scopes = $DOM->getElementsByTagName('scope')->length > 0 ? $DOM->getElementsByTagName('scope') : array();
        foreach ($Scopes as $ScopeType) {
            array_push($Scope, $ScopeType->nodeValue);
        }
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'Scope' => $Scope,
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit CancelPermissions API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function CancelPermissions($Token) {
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= $Token != '' ? '' . $Token . '' : '';
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'Permissions', 'CancelPermissions');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit GetBasicPersonalData API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function GetBasicPersonalData($AttributeList) {
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= '';
        foreach ($AttributeList as $Attribute) {
            $XMLRequest .= '' . $Attribute . '';
        }
        $XMLRequest .= '';
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'Permissions', 'GetBasicPersonalData');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $PersonalDataList = $DOM->getElementsByTagName('personalData')->length > 0 ? $DOM->getElementsByTagName('personalData') : array();
        $PersonalData = array();
        foreach ($PersonalDataList as $PersonalDataType) {
            $PersonalDataKey = $PersonalDataType->getElementsByTagName('personalDataKey')->length > 0 ? $PersonalDataType->getElementsByTagName('personalDataKey')->item(0)->nodeValue : '';
            $PersonalDataValue = $PersonalDataType->getElementsByTagName('personalDataValue')->length > 0 ? $PersonalDataType->getElementsByTagName('personalDataValue')->item(0)->nodeValue : '';
            $PersonalDataItem = array('PersonalDataKey' => $PersonalDataKey, 'PersonalDataValue' => $PersonalDataValue);
            array_push($PersonalData, $PersonalDataItem);
        }
        $PersonalDataKey = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $PersonalDataValue = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'PersonalData' => $PersonalData,
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
    /**
     * Submit GetAdvancedPersonalData API request to PayPal.
     *
     * @access	public
     * @param	array	call config data
     * @return	array
     */
    function GetAdvancedPersonalData($AttributeList) {
        // Generate XML Request
        $XMLRequest = '';
        $XMLRequest .= '';
        $XMLRequest .= $this->GetXMLRequestEnvelope();
        $XMLRequest .= '';
        foreach ($AttributeList as $Attribute) {
            $XMLRequest .= '' . $Attribute . '';
        }
        $XMLRequest .= '';
        $XMLRequest .= '';
        // Call the API and load XML response into DOM
        $XMLResponse = $this->CURLRequest($XMLRequest, 'Permissions', 'GetBasicPersonalData');
        $DOM = new DOMDocument();
        $DOM->loadXML($XMLResponse);
        // Parse XML values
        $Fault = $DOM->getElementsByTagName('FaultMessage')->length > 0 ? true : false;
        $Errors = $this->GetErrors($XMLResponse);
        $Ack = $DOM->getElementsByTagName('ack')->length > 0 ? $DOM->getElementsByTagName('ack')->item(0)->nodeValue : '';
        $Build = $DOM->getElementsByTagName('build')->length > 0 ? $DOM->getElementsByTagName('build')->item(0)->nodeValue : '';
        $CorrelationID = $DOM->getElementsByTagName('correlationId')->length > 0 ? $DOM->getElementsByTagName('correlationId')->item(0)->nodeValue : '';
        $Timestamp = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $PersonalDataList = $DOM->getElementsByTagName('personalData')->length > 0 ? $DOM->getElementsByTagName('personalData') : array();
        $PersonalData = array();
        foreach ($PersonalDataList as $PersonalDataType) {
            $PersonalDataKey = $PersonalDataType->getElementsByTagName('personalDataKey')->length > 0 ? $PersonalDataType->getElementsByTagName('personalDataKey')->item(0)->nodeValue : '';
            $PersonalDataValue = $PersonalDataType->getElementsByTagName('personalDataValue')->length > 0 ? $PersonalDataType->getElementsByTagName('personalDataValue')->item(0)->nodeValue : '';
            $PersonalDataItem = array('PersonalDataKey' => $PersonalDataKey, 'PersonalDataValue' => $PersonalDataValue);
            array_push($PersonalData, $PersonalDataItem);
        }
        $PersonalDataKey = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $PersonalDataValue = $DOM->getElementsByTagName('timestamp')->length > 0 ? $DOM->getElementsByTagName('timestamp')->item(0)->nodeValue : '';
        $ResponseDataArray = array(
            'Errors' => $Errors,
            'Ack' => $Ack,
            'Build' => $Build,
            'CorrelationID' => $CorrelationID,
            'Timestamp' => $Timestamp,
            'PersonalData' => $PersonalData,
            'XMLRequest' => $XMLRequest,
            'XMLResponse' => $XMLResponse
        );
        return $ResponseDataArray;
    }
}
/* End of file Paypal_pro.php */
/* Location: ./system/application/libraries/Paypal_pro.php */