<?php

// Include required library files.
require_once '../includes/config.php';
require_once '../autoload.php';
// Create PayPal object.
$PayPalConfig = array('Sandbox' => $sandbox, 'APIUsername' => $payflow_username, 'APIPassword' => $payflow_password, 'APIVendor' => $payflow_vendor, 'APIPartner' => $payflow_partner, 'Verbosity' => 'HIGH', 'PrintHeaders' => $print_headers, 'LogResults' => $log_results, 'LogPath' => $log_path);
$PayPal = new angelleye\PayPal\PayFlow($PayPalConfig);
// Prepare request arrays
$PayPalRequestData = array('tender' => 'C', 'trxtype' => 'S', 'acct' => '4012888888881881', 'expdate' => '1215', 'amt' => '10.00', 'dutyamt' => '', 'freightamt' => '5.00', 'taxamt' => '2.50', 'taxexempt' => '', 'comment1' => 'This is a test!', 'comment2' => 'This is only a test!', 'cvv2' => '123', 'recurring' => '', 'swipe' => '', 'orderid' => '', 'billtoemail' => '*****@*****.**', 'billtophonenum' => '816-555-5555', 'billtofirstname' => 'Tester', 'billtomiddlename' => '', 'billtolastname' => 'Testerson', 'billtostreet' => '123 Test Ave.', 'billtocity' => 'Kansas City', 'billtostate' => 'MO', 'billtozip' => '64111', 'billtocountry' => 'US', 'shiptofirstname' => 'Tester', 'shiptomiddlename' => '', 'shiptolastname' => 'Testerson', 'shiptostreet' => '123 Test Ave.', 'shiptocity' => 'Kansas City', 'shiptostate' => 'MO', 'shiptozip' => '64111', 'shiptocountry' => 'US', 'origid' => '', 'custref' => '', 'custcode' => '', 'custip' => '', 'invnum' => '', 'ponum' => '', 'starttime' => '', 'endtime' => '', 'securetoken' => '', 'partialauth' => '', 'authcode' => '');
// Pass data into class for processing with PayPal and load the response array into $PayPalResult
$PayPalResult = $PayPal->ProcessTransaction($PayPalRequestData);
// Write the contents of the response array to the screen for demo purposes.
echo '<pre />';
print_r($PayPalResult);
    $returnHtml .= '</div>';
    $returnHtml .= '</div>';
    // DebugMode output
    if (isset($config['DebugMode']) && $config['DebugMode']) {
        $returnHtml .= '<hr>';
        $returnHtml .= '<pre>' . print_r($_SESSION['DPResult'], TRUE) . '</pre>';
    }
    echo json_encode(array('result' => 'success', 'result_data' => $returnData, 'result_html' => $returnHtml));
    exit;
} elseif (isset($config['ApiSelection']) && strtolower($config['ApiSelection']) == 'paypalpro-payflow') {
    /**
     * PayFlow API
     */
    // PayPal object
    $paypal_config = array('Sandbox' => $config['Sandbox'], 'APIUsername' => $config['PayFlowUsername'], 'APIPassword' => $config['PayFlowPassword'], 'APIVendor' => $config['PayFlowVendor'], 'APIPartner' => $config['PayFlowPartner']);
    $paypal = new \angelleye\PayPal\PayFlow($paypal_config);
    ############[ SESSIONS ]################
    $_SESSION['invoice'] = isset($_POST['InvoiceID']) ? $_POST['InvoiceID'] : '';
    $_SESSION['notes'] = isset($_POST['Notes']) ? $_POST['Notes'] : '';
    $_SESSION['item_name'] = isset($_POST['ItemName']) ? $_POST['ItemName'] : '';
    $_SESSION['transaction_type'] = isset($_POST['TransactionType']) ? $_POST['TransactionType'] : 'Authorization';
    $_SESSION['cc_type'] = isset($_POST['CreditCardType']) ? $_POST['CreditCardType'] : '';
    $_SESSION['cc_number'] = isset($_POST['CreditCardNumber']) ? $_POST['CreditCardNumber'] : '';
    $_SESSION['cc_expdate'] = isset($_POST['CreditCardExpMo']) ? $_POST['CreditCardExpMo'] . substr($_POST['CreditCardExpYear'], 2, 2) : '';
    $_SESSION['cvv2'] = isset($_POST['CreditCardSecurityCode']) ? $_POST['CreditCardSecurityCode'] : '';
    // Check to see if they manually enter in billing information
    if (isset($_POST['billingInfo']) && $_POST['billingInfo'] == 'true') {
        $_SESSION['billing_first_name'] = $_POST['BillingFirstName'];
        $_SESSION['billing_last_name'] = $_POST['BillingLastName'];
        $_SESSION['billing_street1'] = $_POST['BillingStreet'];
        $_SESSION['billing_street2'] = $_POST['BillingStreet2'];