Forums

Problems with custom data, Auth.net, and Confirmation email

jakejones 19 Sep, 2013
I am using Chronoforms 4.0 on Joomla 2.5
I have built a form that asks the visitor for a foreign currency amount to be sent to a company in that nation. I have written a custom PHP script that talks to Google Conversion and comes back with the equivalent dollar amount in US Currency plus a service fee. Then I am sending it to the Auth.net payment module and I need Auth.net to call up that amount from the database to process the payment. Upon successful payment transaction, I wish to bring up the order information as a confirmation & email reciept.


1.) How can I get my newly converted USD amount to save into the database since it is calculated in a custom PHP field?

2.) How can I call that dollar amount into the Amount Field of the Authorize.net module?

3.) How can I call that newly saved information to a confirmation page & email them a receipt with all the info including cf_id, cf_created, creditcardnumber (last 4 digits), and the amount they paid in usd from my php calculation?

Here is a copy of my PHP conversion script (I called the field kestousd:

<?php
function currency_convert($amount, $from="kes", $to="usd") {

    $exchangeProvider='http://www.google.com/ig/calculator?hl=en&q=' . $amount . $from . '=?' . $to;
    
    $result=file_get_contents($exchangeProvider);
	
    $result=preg_replace('/[^\w." ]/', '', $result);
	
    $expl=explode('"', $result);

	if (($expl[1] == '') || ($expl[3] == '')) {
		return false;
	} else {
		return array($expl[1], $expl[3]);
	}
	
}

$amountTotal=currency_convert($_POST['amount'], 'kes', 'usd');

$amountTotal=$amountTotal[1]*1.03;

$amountTotal=round($amountTotal+2.99,2);

?>
GreyHead 20 Sep, 2013
Hi JakeJones,

I'd do this using a Custom Code action in the form On Submit event:
<?php
$amount = $form->data['amount'];
$from = 'kes';
if ( isset($form->data['from']) ) {
  $from = $form->data['from'];
}
$to = 'usd';
if ( isset($form->data['to']) ) {
  $to = $form->data['to'];
}
$exchangeProvider = "http://www.google.com/ig/calculator?hl=en&q={$amount}{$from}=?{$to}";
$result = file_get_contents($exchangeProvider);
$result = preg_replace('/[^\w." ]/', '', $result);
$expl   = explode('"', $result);
if ( ($expl[1] == '') || ($expl[3] == '') ) {
  $amountTotal = false;
} else {
  $amountTotal = $expl[1];
  $amountTotal = $amountTotal[1] * 1.03;
  $amountTotal = round($amountTotal + 2.99, 2);
}
$form->data['amount_total'] = $amountTotal;
?>
Then you can validate you have a result and, if so, use amount_total in the ANet action.

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