Hi
I've done quite a bit of searching on this but still can't find the answer so any input/help is very much appreciated!...
I (think I) know the issue but can't seem to find the answer here: I have a Formit form that I am redirecting to another page which has a PHP snippet embedded in it. This works fine except I need to analyse and manipulate the data with the PHP script and have an output. I understand that MODX complies scripts/data/pages before running them so the data/variables I am trying to use are not available for the script to use.
How do I do this - what am I missing?! ...please!
Code below if it helps:
<?php
require_once('/home/finearses/public_html/assets/scripts/lib/sagepay.php');
$key = 'XXXXXXXXXX'; // LIVE SERVER KEY
$output = '';
$VendorTxCode = '';
$Amount = '';
$Currency = 'GBP';
$Description = 'Custom made fine art canvases';
$SuccessURL = 'http://www.mydomain.co.uk/success.html';
$FailureURL = 'http://www.mydomain.co.uk/failure.html';
$CustomerName = '[[!+fi.BillingFirstnames]]'.' '.'[[!+fi.BillingSurname]]';
$CustomerEMail = '[[!+fi.CustomerEMail]]'; // If provided, the customer will be emailed on completion of a successful transaction (but not an unsuccessful one).
$VendorEMail = '[email protected]'; // If provided, an email will be sent to this address when each transaction completes (successfully or otherwise).
$EmailMessage = ''; // If provided this message is included toward the top of the customer confirmation emails.
$BillingSurname = $scriptProperties['BillingSurname'];
$BillingFirstnames = '[[!+fi.BillingFirstnames]]';
$BillingAddress1 = '[[!+fi.BillingAddress1]]';
$BillingAddress2 = '[[!+fi.BillingAddress2]]';
$BillingCity = '[[!+fi.BillingCity]]';
$BillingPostCode = '[[!+fi.BillingPostCode]]';
$BillingCountry = '[[!+fi.BillingCountry]]';
$BillingPhone = '[[!+fi.BillingPhone]]';
$DeliverySurname = '[[!+fi.DeliverySurname]]';
$DeliveryFirstnames = '[[!+fi.DeliveryFirstnames]]';
$DeliveryAddress1 = '[[!+fi.DeliveryAddress1]]';
$DeliveryAddress2 = '[[!+fi.DeliveryAddress2]]';
$DeliveryCity = '[[!+fi.DeliveryCity]]';
$DeliveryPostCode = '[[!+fi.DeliveryPostCode]]';
$DeliveryCountry = '[[!+fi.DeliveryCountry]]';
$DeliveryPhone = '[[!+fi.DeliveryPhone]]';
// VendoTxCode
$VendorTxCode = substr(time().$BillingSurname,0,40);
$output .= 'VendorTxCode='.$VendorTxCode;
// Amount
if(isset($_SESSION["products"])) {
foreach ($_SESSION["products"] as $item) {
$subtotal = ($item["qty"] * $item["price"]);
$Amount += $subtotal;
}
}
$Amount = number_format($Amount, 2,'.','');
$output .= '&Amount='.$Amount;
// General Fields
$output .= '&Currency='.$Currency;
$output .= '&Description='.$Description;
$output .= '&SuccessURL='.$SuccessURL;
$output .= '&FailureURL='.$FailureURL;
$output .= '&CustomerName='.$CustomerName;
$output .= '&CustomerEMail='.$CustomerEMail;
$output .= '&VendorEMail='.$VendorEMail;
$output .= '&EmailMessage='.$EmailMessage;
// Billing Details
$output .= '&BillingSurname='.$BillingSurname;
$output .= '&BillingFirstnames='.$BillingFirstnames;
$output .= '&BillingAddress1='.$BillingAddress1;
$output .= '&BillingAddress2='.$BillingAddress2;
$output .= '&BillingCity='.$BillingCity;
$output .= '&BillingPostCode='.$BillingPostCode;
$output .= '&BillingCountry='.$BillingCountry;
$output .= '&BillingPhone='.$BillingPhone;
// Delivery Details
$output .= '&DeliverySurname='.$DeliverySurname;
$output .= '&DeliveryFirstnames='.$DeliveryFirstnames;
$output .= '&DeliveryAddress1='.$DeliveryAddress1;
$output .= '&DeliveryAddress2='.$DeliveryAddress2;
$output .= '&DeliveryCity='.$DeliveryCity;
$output .= '&DeliveryPostCode='.$DeliveryPostCode;
$output .= '&DeliveryCountry='.$DeliveryCountry;
$output .= '&DeliveryPhone='.$DeliveryPhone;
// Basket XML
$BasketXML = '<basket>';
if(isset($_SESSION["products"])) {
$total = 0;
foreach ($_SESSION["products"] as $item) {
$itemnet = ($item["price"] / 1.2);
$itemnet = number_format($itemnet, 2,'.',''); // Round
$itemtax = ($item["price"] - $itemnet);
$itemtax = number_format($itemtax, 2,'.',''); // Round
$subtotal = ($item["qty"] * $item["price"]);
$subtotal = number_format($subtotal, 2,'.',''); // Round
$BasketXML .= "<item><description>".str_replace('<br />',' - ',$item["desc"])."</description><productSku>".$item["code"]."</productSku><quantity>".$item["qty"]."</quantity><unitNetAmount>".$itemnet."</unitNetAmount><unitTaxAmount>".$itemtax."</unitTaxAmount><unitGrossAmount>".$item["price"]."</unitGrossAmount><totalGrossAmount>".$subtotal."</totalGrossAmount></item>";
}
}
$BasketXML .= '</basket>';
$output .= '&BasketXML='.$BasketXML;
$CryptField = '<input type="hidden" name="Crypt" value="'.SagepayUtil::encryptAes($output, $key).'" />';
//$CryptField = '<input type="hidden" name="Crypt" value="'.$output.'" />'; // Debug line so I could see output!
return $CryptField;
?>
Thanking anyone who helps in advance.
Gareth
[ed. note: doglegdesign last edited this post 8 years, 9 months ago.]