Forums

Data not saved, email not sent

rhapsody 07 May, 2009
Hi,

My form work fine except when I add "On Submit code" (before or after). The code I add submits form data successfully to PayPal API, but does not save it in my Chronoforms table or generate emails.

Upon removing the code data is saved.

My version: V3.1_RC4.11.

Thank you,
Kamil
GreyHead 07 May, 2009
Hi Kamil,

Then something in your code is breaking ChronoForms - or just diverting everything to PayPal.

Don't do mind-reading - please post the code if you want us to look at it.

Bob
rhapsody 07 May, 2009
Here is the working code for PayPal's Recurring Payments API (adding tags for the benefit of readers):


<?php

$environment = 'sandbox';	// or 'beta-sandbox' or 'live'

/**
 * Send HTTP POST Request
 *
 * @param	string	The API method name
 * @param	string	The POST Message fields in &name=value pair format
 * @return	array	Parsed HTTP Response body
 */
 
 
 /*copied (and modified)from DoDirectPaymentReceipt.php*/
 
	require_once 'test/php_nvp_samples/CallerService.php';
	session_start();
	
	/**
	* Get required parameters from the web form for the request
	*/
	//$paymentType =urlencode( $_POST['paymentType']);
	$firstName =urlencode("xxxx");
	$lastName =urlencode("xxxx");
	$email = urlencode("xxxx@xxxx.com");
	$creditCardType =urlencode( "Visa");
	$creditCardNumber = urlencode("4477432722346252"); // dummy test number
	$expDateMonth =urlencode("1");
	
	// Month must be padded with leading zero
	$padDateMonth = str_pad($expDateMonth, 2, '0', STR_PAD_LEFT);
	
	$expDateYear =urlencode("2010");
	$cvv2Number = urlencode("962");
	$address1 = urlencode("1 Main Street");
	$address2 = urlencode("");
	$city = urlencode("xxxx");
	$state =urlencode( "xx");
	$zip = urlencode("11111");
	$amount = urlencode("1.00");
	$currencyCode="USD";

	$anonymous = urlencode($_POST['anonymous']);// not paypal
	
	
	/* Construct the request string that will be sent to PayPal.
	The variable $nvpstr contains all the variables and is a
	name value pair string with & as a delimiter */
	$nvpStr="&AMT=$amount&CREDITCARDTYPE=$creditCardType&ACCT=$creditCardNumber&EXPDATE=".         $padDateMonth.$expDateYear."&CVV2=$cvv2Number&FIRSTNAME=$firstName&LASTNAME=$lastName&STREET=$address1&CITY=$city&STATE=$state".
	"&ZIP=$zip&COUNTRYCODE=US&CURRENCYCODE=$currencyCode";
 /**/
function PPHttpPost($methodName_, $nvpStr_) {
	global $environment;

	require_once 'test/php_nvp_samples/constants.php';
	
	$API_UserName=API_USERNAME;
	$API_Password=API_PASSWORD;
	$API_Signature=API_SIGNATURE;
	$API_Endpoint =API_ENDPOINT;
	$version=VERSION;


	if("sandbox" === $environment || "beta-sandbox" === $environment) {
		$API_Endpoint = "https://api-3t.$environment.paypal.com/nvp";
	}

	// setting the curl parameters.
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
	curl_setopt($ch, CURLOPT_VERBOSE, 1);

	// turning off the server and peer verification(TrustManager Concept).
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_POST, 1);

	// NVPRequest for submitting to server
	$nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";

	// setting the nvpreq as POST FIELD to curl
	curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);

	// getting response from server
	$httpResponse = curl_exec($ch);

	if(!$httpResponse) {
		exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')');
	}

	// Extract the RefundTransaction response details
	$httpResponseAr = explode("&", $httpResponse);

	$httpParsedResponseAr = array();
	foreach ($httpResponseAr as $i => $value) {
		$tmpAr = explode("=", $value);
		if(sizeof($tmpAr) > 1) {
			$httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
		}
	}

	if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
		exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
	}

	return $httpParsedResponseAr;
}


$profileStartDate = urlencode("2009-5-7T0:0:0Z");
$billingPeriod = urlencode("Month");				// or "Day", "Week", "SemiMonth", "Year"
$billingFreq = urlencode("1");						// combination of this and billingPeriod must be at most a year


$method = urlencode("CreateRecurringPaymentsProfile");
$paymentAction = urlencode("Sale");
$initAmt = 50;
$failedInitAmtAction = urlencode("ContinueOnFailure");
$desc = urlencode("Recurring $50");
$autoBillAmt = urlencode("AddToNextBilling");

if ($anonymous == 1) {
	$profileReference = urlencode("Anonymous");
} else {
	$profileReference = urlencode("-");
}

$nvpStr .= "&BILLINGPERIOD=$billingPeriod&BILLINGFREQUENCY=$billingFreq&PROFILESTARTDATE=$profileStartDate&METHOD=$method&PAYMENTACTION=$paymentAction&INITAMT=$initAmt&FAILEDINITAMTACTION=$failedInitAmtAction&DESC=$desc&AUTOBILLAMT=$autoBillAmt&PROFILEREFERENCE=$profileReference";

$httpParsedResponseAr = PPHttpPost('CreateRecurringPaymentsProfile', $nvpStr);
//$resArray=hash_call("CreateRecurringPaymentsProfile",$nvpStr);// testing

if("Success" == $httpParsedResponseAr["ACK"]) {
	exit('CreateRecurringPaymentsProfile Completed Successfully: '.print_r($httpParsedResponseAr, true));
} else  {
	exit('CreateRecurringPaymentsProfile failed: ' . print_r($httpParsedResponseAr, true));
}

?>


GreyHead 08 May, 2009
Hi rhapsody,

I think that the problem is that the 'exit's at the end are exiting from ChronoForms, not just the curl
if("Success" == $httpParsedResponseAr["ACK"]) {
   exit('CreateRecurringPaymentsProfile Completed Successfully: '.print_r($httpParsedResponseAr, true));
} else  {
   exit('CreateRecurringPaymentsProfile failed: ' . print_r($httpParsedResponseAr, true));
}
Try using this instead
global $mainframe;
if("Success" == $httpParsedResponseAr["ACK"]) {
   $messsage = 'CreateRecurringPaymentsProfile Completed Successfully: ';
} else  {
   $messsage = 'CreateRecurringPaymentsProfile failed: ';
}
$mainframe->enqueumessage($message.print_r($httpParsedResponseAr, true));

Bob
Max_admin 08 May, 2009
Hi Kamil,

not sure if it was your post but I saw a post earlier here today and there was form tags in the form code which will make troubles for sure!

Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
rhapsody 08 May, 2009
I think the problem was because of the way Joomla was installed; in configuration.php $live_site was going to "http://", without the www. So when submitting a form from the www address, it would create intermittent problems, including "you are not allowed access to this URL". After changing the $live_site it is working fine now.

Thanks,
Kamil
GreyHead 08 May, 2009
Hi Kamil,

Great, that makes sense, glad to hear that it's working fine.

Bob
This topic is locked and no more replies can be posted.