866581;
#---------------------------------------------------------------
#
# Generated by ISControlISConfigCtrl
#
#---------------------------------------------------------------
#
my $bCompleteOnTechnicalFailures = $::FALSE;
my $bCompleteOnFinancialFailures = $::FALSE;
my $bAuthorize = $::TRUE;
my $bTestMode = $::FALSE;
my $sGTime = '1774712519';
my $sSanity = '2bdcb75c2022cde00d512a3d1b6a0264';
my $sProcessScriptURL = 'https://www.paypal.com/cgi-bin/webscr';
my $sADF01 = 'customerservices@stardustkids.co.uk';
my $sADFDump = '0201028000000030000000002F6DE6AEE9798977130D426FC13B4A217E4B6D9385DC361219310BC46BFF31C1891039C5959994990BEDDD08CED77A7CAECB8814ADB59823D8562A7109BA94C6B18AC4538CC48ABFA7E1D5BB78DF86B36CD825376FD60EDFC1AAEEE2D59777136AA60414703B4C321B807EC80CE9E224AB5DA0876CE617AB737E9C27AF47B67D5A8C800EFC9939BB2B6ED2DEEE3A8C81AA7A1BE7E64C2740777B2C81908DBEDB42BDB8E1797DEA6EF73C854384ABDB6F';
#
#---------------------------------------------------------------
#
# OCCPayPalTemplate.pl	- code part of OCC script
#
# *** Do not change this code unless you know what you are doing ***
#
# Adapted from OCCAuthorizeNetScriptTemplate.pl by Bill Birthisel
#
# This script is called by an eval() function and it will already
# have the following variables set up:
#
#	Expects:		$::sOrderNumber		- the alphanumeric order number for this order
#					$::nOrderTotal			- the total for this order (stored in based currency format e.g. 1000 = $10.00)
#					%::PriceFormatBlob   - the price format data
#					%::InvoiceContact		- customer invoice contact information
#					%::OCCShipData			- customer invoice shipping information
#					$::sCallBackURLAuth	- the URL of the authorization callback script
#					$::sCallBackURLBack	- the URL of the backup script
#					$::sCallBackURLUser	- the URL of the receipt script
#					$::sPath					- the path to the Catalog directory
#					$::sWebSiteUrl			- the Catalog web site URL
#					$::sContentUrl			- the content URL
#					$::sCartID			   - the cart id
#
#	Affects:		$::eStatus     		- the status of the transaction:
#						$::FAILURE 	- Failure
#						$::ACCEPTED - Accepted
#						$::REJECTED - Rejected
#						$::PENDING  - Pending
#					$::sErrorMessage		- error message if any
#					$::sHTML					- the HTML to display
#					$::sRedirectURL		- (optional) data for logging or
#                                     for redirect if implemented someday
#
#  $Revision: 33041 $
#
#---------------------------------------------------------------

use strict;
#
# This block of code isolates the plug-in scripts from version specific code that they have historically used
# BEGIN
my $sCartID;
if (defined $::EC_MAJOR_VERSION)						# EC version 6 or greater
	{
	$sCartID = $::sCartID;								# Use the value setup by OrderScript.pl
	}
else															# Pre-version 6
	{
	$sCartID = $::g_sCartId;							# copy the global value
	}
# END
# This block of code isolates the plug-in scripts from version specific code that they have historically used
#
#
# The OCC plug-in runs in pending mode.  This script does not
# perform the transaction.  Rather, it forwards the customer to
# the OCC site for completion.
#
$::eStatus = $::PENDING;
#
# constants
#
my $ALWAYS = 1;
my $OPTION = 0;
my $NOENCODE = 0;
my $ENCODE = 1;		# encode both bounce and redirect
my $REDIRECT = 2;		# encode redirect only

my %VarTable;			# substitution hash for template

my $sMerchantID = $sADF01;
#
# insert the OCC web site URL into the HTML template
#
$VarTable{$::VARPREFIX . 'OCC_URL'} = $sProcessScriptURL;
#
# build up a string of all of the values that must be passed to OCC
#
my $sHiddenValues;
my $sRedirectData = $sProcessScriptURL;
#
# sprintf template for data form sent to the OCC
#
my $OCC_template = '<INPUT TYPE=HIDDEN NAME="%s" VALUE="%s">'."\n";
my $POST_template = '%s%s=%s';
#
# Required PayPal fields - these values are hard coded based on the options that work best with Actinic
#
AddPostValues ('?', 'cmd', '_xclick', $ALWAYS, $NOENCODE); # required "command" value
AddPostValues ('&', 'undefined_quantity', 0, $ALWAYS, $NOENCODE);	# make the quantity editable - I'm just going to leave it hard coded to one
#
# We can only offer Seller Protection if the Invoice and Delivery Addresses are the same
# See https://cms.paypal.com/uk/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_Appx_BillingShippingAddress
#    - document refers to US but also applies to UK
#
if ($::InvoiceContact{'SEPARATE'})
	{
	AddPostValues ('&', 'no_shipping', 1, $ALWAYS, $NOENCODE); # don't display address as shipping address
	AddPostValues ('&', 'address_override', 0, $ALWAYS, $NOENCODE); # don't force address to be known PayPal address
	}
else
	{
	AddPostValues ('&', 'no_shipping', 2, $ALWAYS, $NOENCODE); # display shipping address enables 'Seller Protection'
	#
	# Do not allow the buyer to edit the addresses otherwise 
	# they won't match what is recorded with the order
	#
	AddPostValues ('&', 'address_override', 1, $ALWAYS, $NOENCODE); # address overridden by SellerDeck checkout
	}
#
# Transaction data to be returned as POST data
#
AddPostValues ('&', 'rm', 2, $ALWAYS, $NOENCODE); # don't use paypal's shipping calculator

AddPostValues ('&', 'no_note', 1, $ALWAYS, $NOENCODE); # don't allow entry of a payment note
AddPostValues ('&', 'bn', 'ActinicCat_Cart_ST', $ALWAYS, $NOENCODE); # hard code the provider
#
# Merchant ID
#
AddPostValues ('&', 'business', $sMerchantID, $ALWAYS, $REDIRECT); # the merchant email address or business PayPal ID
#
# Pack some additional values on the authorization URL
#
my $sCompleteCallBackURLAuth = $::sCallBackURLAuth;
my $nTestMode = $bTestMode ? 1 : 0;
$sCompleteCallBackURLAuth .= "TM=" . $nTestMode;
$sCompleteCallBackURLAuth .= "&AM=" . $::nOrderTotal;
$sCompleteCallBackURLAuth .= "&ACT_POSTPROCESS=1&";
#
# URLs:
#
#		AUTH - the URL to create the authorization blob
#		BACK - the URL to return to the Catalog checkout process
#		USER - the URL to the receipt script
#
AddPostValues ('&', 'notify_url', $sCompleteCallBackURLAuth, $ALWAYS, $REDIRECT);
AddPostValues ('&', 'cancel_return', $::sCallBackURLBack, $ALWAYS, $REDIRECT);
AddPostValues ('&', 'return', $::sCallBackURLUser, $ALWAYS, $REDIRECT);
#
# order details
#
AddPostValues ('&', 'invoice', $::sOrderNumber, $ALWAYS, $NOENCODE);
AddPostValues ('&', 'item_name', $::sOrderNumber, $ALWAYS, $NOENCODE);
AddPostValues ('&', 'item_number', $::sOrderNumber, $ALWAYS, $NOENCODE);
#
# Calculate the conversion factor for the currency
#
my $nFactor = 100;
my $nNumDigits = $::PriceFormatBlob{"ICURRDIGITS"};	# read the currency format values
if(defined $nNumDigits)
	{
	$nFactor = (10 ** $nNumDigits);
	}
my $sCurrencyFormat = sprintf('%%d.%%0%dd', $nNumDigits);
my $sAmount .= sprintf($sCurrencyFormat, $::nOrderTotal / $nFactor,
							  $::nOrderTotal % $nFactor);
AddPostValues ('&', 'amount', $sAmount, $ALWAYS, $NOENCODE);
#
# Currency
#
AddPostValues ('&', 'currency_code', $::PriceFormatBlob{SINTLSYMBOLS}, $ALWAYS, $NOENCODE);
#
# supply the cardholder's address details
#
my ($sFirstName, $sLastName);
$sLastName = $::InvoiceContact{NAME};				# default to a blank first name and complete last name
if ($sLastName =~ /^(.+)\s+(\S+)/)					# if the name field looks to contain at least two name parts
	{
	$sFirstName = $1;										# break the name up
	$sLastName = $2;
	}
	
my $sCountry = $::g_LocationInfo{INVOICE_COUNTRY_CODE};
$sCountry =~ s/^UK$/GB/;
my $sState = $::InvoiceContact{ADDRESS4};
if ('US' eq $sCountry)
	{
	#
	# Only send state code for US addresses
	#
	$sState = ($::g_LocationInfo{INVOICE_REGION_CODE} ne $ActinicOrder::UNDEFINED_REGION) ?
		ActinicLocations::GetISOInvoiceRegionCode() : $::InvoiceContact{ADDRESS4};
	}

AddPostValues ('&', 'first_name', 	$sFirstName, $OPTION, $REDIRECT);
AddPostValues ('&', 'last_name', 	$sLastName, $ALWAYS, $REDIRECT);
AddPostValues ('&', 'email', 			$::InvoiceContact{EMAIL}, $OPTION, $NOENCODE);
AddPostValues ('&', 'address1', 		$::InvoiceContact{ADDRESS1}, $ALWAYS, $REDIRECT);
AddPostValues ('&', 'address2', 		$::InvoiceContact{ADDRESS2}, $OPTION, $REDIRECT);
AddPostValues ('&', 'city', 			$::InvoiceContact{ADDRESS3}, $OPTION, $REDIRECT);
AddPostValues ('&', 'state', 			$sState, $OPTION, $REDIRECT);
AddPostValues ('&', 'zip', 			$::InvoiceContact{POSTALCODE}, $OPTION, $REDIRECT);
AddPostValues ('&', 'country', 		$sCountry, $OPTION, $REDIRECT);

my ($nAreaCode, $nPart1, $nPart2);
if ($::InvoiceContact{PHONE} =~ /(\d*)\D*(\d*)\D*(\d*)/)
	{
	$nAreaCode = $1;
	$nPart1 = $2;
	$nPart2 = $3;
	}

if (length $nPart1 == 0)   # if only digits were entered
	{
	$nPart1 = $nAreaCode;
	$nPart2 = $nAreaCode = '';
	}
	
if ($::InvoiceContact{PHONE} =~ /\+(\d{2})(.*)/)
	{
	$nAreaCode = $1;
	$nPart1 = $2;
	$nPart2 = '';
	}
		
AddPostValues ('&', 'night_phone_a', $nAreaCode, $OPTION, $NOENCODE);
AddPostValues ('&', 'night_phone_b', $nPart1, $OPTION, $NOENCODE);
AddPostValues ('&', 'night_phone_c', $nPart2, $OPTION, $REDIRECT);
if ($bAuthorize)
	{
	AddPostValues ('&', 'paymentaction', 'sale', $OPTION, $NOENCODE);
	}
else
	{
	AddPostValues ('&', 'paymentaction', 'authorization', $OPTION, $NOENCODE);
	}
#
# end of the invoice address details
#
#
# add the OCC values to the template
#
$VarTable{$::VARPREFIX . 'OCC_VALUES'} = $sHiddenValues;

my $sLinkHTML = 'occlink.html';
if(defined $::g_pPaymentList)
	{
	$sLinkHTML = $$::g_pPaymentList{ActinicOrder::PaymentStringToEnum($::g_PaymentInfo{'METHOD'})}{BOUNCE_HTML};
	}
my @Response = ACTINIC::TemplateFile($::sPath . $sLinkHTML, \%VarTable); # build the file

if ($Response[0] != $::SUCCESS)
	{
	$::eStatus = $::FAILURE;							# return a plug-in error
	$::sErrorMessage = $Response[1];
	return ($::SUCCESS);									# always return success if the script runs
	}

@Response = ACTINIC::MakeLinksAbsolute($Response[2], $::sWebSiteUrl, $::sContentUrl);
if ($Response[0] != $::SUCCESS)
	{
	$::eStatus = $::FAILURE;							# return a plug-in error
	$::sErrorMessage = $Response[1];
	return ($::SUCCESS);									# always return success if the script runs
	}

$::sHTML = $Response[2];								# grab the resulting HTML
$::sRedirectURL = $sRedirectData;					# data for log or redirect
#
# process the test mode warning
#
my ($sDelimiter) = $::DELPREFIX . 'TESTMODE';
if ($bTestMode)											# only include the test mode block if we are in test mode
	{
	$::sHTML =~ s/$sDelimiter//g;						# remove the delimiter text
	}
else															# not in test mode - remove the block
	{
	$::sHTML =~ s/$sDelimiter(.*?)$sDelimiter//gs;	# remove the test mode warning blob (/s removes the \n limitation of .)
	}
#
# AddPostValues ($sPostSeparator, $sPostName, $sPostValue, $bAlways, $bEncode)
#
# adds a name/value pair to $sHiddenValues and $sRedirectData
#
sub AddPostValues
	{
	my ($sDelim, $sName, $sValue, $bAlways, $eEncode) = @_;
	if ($sValue || $bAlways)
		{
		my $sEncValue = $sValue;
		if ($eEncode)
			{
			$sEncValue = ACTINIC::EncodeText2 ($sValue, $::FALSE);
			}
		if ($eEncode == $REDIRECT)
			{
			$sHiddenValues .= sprintf ($OCC_template, $sName, $sValue);
			}
		else
			{
			$sHiddenValues .= sprintf ($OCC_template, $sName, $sEncValue);
			}
		$sRedirectData .= sprintf ($POST_template, $sDelim, $sName, $sEncValue);
		}
	}

return ($::SUCCESS);
#
# End of OCCPayPalTemplate.pl
#
#
# End of File
