'req' => false,
'name' => 'remote_addr'
);
+ $e[] = array(
+ 'type' => 'hidden',
+ 'req' => false,
+ 'name' => 'mail_ok',
+ );
$e[] = array(
'type' => 'header',
'name' => 'firstHdr_rmv',
'req' => true,
'name' => 'qty',
'display' => 'Passports',
- 'opts' => array(''=>'') + $qty
+ 'opts' => array(''=>'') + $qty,
+ 'att' => array('style' => 'width: 70px;margin-left: 50px;')
);
$e[] = array(
'type' => 'static',
'req' => false,
- 'name' => 'postage',
- 'display' => 'Postage and Handling $3.00'
- );
- $e[] = array(
- 'type' => 'text',
- 'req' => false,
- 'name' => 'total_price',
- 'display' => 'Total Price',
- 'opts' => array('id' => 'passport_total')
+ 'display' => '</label><table role="grid">'
+ . '<tr><td>Postage and Handling</td><td><input type="text" readonly value="3" style="width: 50px;"></td></tr>'
+ . '<tr><td>Total Price</td><td><input type="text" id="passport_total" name="total_price" readonly value="0" style="width: 50px;"></td></tr>'
+ . '</table></label>'
);
if ($this->hasAuthNetAcc) {
'reset' => true,
'force' => false
);
- /*
- $r[] = array(
- 'element' => 'state',
- 'message' => 'ERROR: Invalid State!',
- 'type' => 'numeric',
- 'format' => null,
- 'validation' => $this->validationType,
- 'reset' => true,
- 'force' => false
- );
- */
$r[] = array(
'element' => 'phone',
'message' => 'ERROR: Invalid number (xxx) xxx-xxxx!',
'reset' => true,
'force' => false
);
- /*
- $r[] = array(
- 'element' => 'zip',
- 'message' => 'ERROR: Invalid Zip!',
- 'type' => 'zip',
- 'format' => array('requireDBCheck' => false),
- 'validation' => $this->validationType,
- 'reset' => true,
- 'force' => false
- );
- */
$r[] = array(
'element' => 'mail_ok',
'message' => 'ERROR: Invalid Value!',
'reset' => false,
'force' => false
);
+ $r[] = array(
+ 'element' => 'cc_exp',
+ 'message' => 'ERROR: Card has expired!',
+ 'type' => 'callback',
+ 'format' => array(&$this, 'checkExpireDate'),
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
}
$this->setupRules($r);
}
// }}}
+ public function checkExpireDate($value)
+ {
+ $month = filter_var($value['m'], FILTER_VALIDATE_INT);
+ $year = filter_var($value['Y'], FILTER_VALIDATE_INT);
+ if (!($month && $year)) {
+ return false;
+ }
+ $firstDay = mktime(0, 0, 0, $month, 1, $year);
+ $lastDay = mktime(0, 0, 0, $month, date('t', $firstDay), $year);
+ $today = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
+ return ($today < $lastDay);
+ }
// {{{ checkNumber()
/**
}
// }}}
+ // {{{ processAuthNet()
+
+ /**
+ * Send payment to auth.net
+ *
+ * Test Cards
+ * Card Number Card Type
+ * =============== ===============
+ * 370000000000002 American Express
+ * 6011000000000012 Discover Card
+ * 5424000000000015 MasterCard
+ * 4000000000000000 Visa
+ *
+ * @param array $values Submitted values from the form
+ *
+ * @return array Auth.net response
+ * @access protected
+ */
+ protected function processAuthNet($values)
+ {
+ $authNetLoginId = AUTH_LOGIN;
+ $authNetTranKey = AUTH_TRAN_KEY;
+ $authNetUrl = "https://secure.authorize.net/gateway/transact.dll";
+
+ $authNetValues = array(
+ 'x_login' => $authNetLoginId,
+ 'x_version' => '3.1',
+ 'x_delim_char' => '|',
+ 'x_delim_data' => 'TRUE',
+ 'x_type' => 'AUTH_CAPTURE',
+ 'x_method' => 'CC',
+ "x_test_request" => DEVELOPMENT ? "TRUE" : "FALSE",
+ 'x_tran_key' => $authNetTranKey,
+ 'x_relay_response' => 'FALSE',
+ 'x_card_num' => $values['cc_num'],
+ 'x_exp_date' => implode('/', $values['cc_exp']),
+ 'x_amount' => $values['total_price'],
+ 'x_first_name' => $values['fname'],
+ 'x_last_name' => $values['lname'],
+ );
+
+ $fields = '';
+ foreach ($authNetValues as $i => $j) {
+ $fields .= "$i=" . urlencode($j) . '&';
+ }
+
+ $ch = curl_init($authNetUrl);
+ // set to 0 to elimindate header info from response
+ curl_setopt($ch, CURLOPT_HEADER, 0);
+ // Returns response data instead of TRUE(1)
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ // Use HTTP POST to send form data
+ curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim($fields, "& "));
+ // Uncomment this line if you get no gateway response. ###
+ // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+ // Execute post and get results
+ $resp = curl_exec($ch);
+ curl_close($ch);
+
+ $res = explode('|', $resp);
+ return $res;
+ }
+
+ // }}}
+ public function processData($values)
+ {
+ $res = parent::processData($values);
+ if ($res) {
+ $res2 = $this->processAuthNet($values);
+// echo '<pre>'.print_r($res2, true).'</pre>';exit;
+ if (is_array($res2) && !empty($res2)) {
+ if ($res2[0] == 1) {
+ // CC was Accepted.
+ return true;
+ } elseif ($res2[0] == 2) {
+ // CC was Declined.
+ return 2;
+ } else {
+ // There was a CC processing error.
+ return $res2[0];
+ }
+ } else {
+ // There was a CC processing error.
+ return false;
+ }
+ }
+ echo '<pre>'.print_r($res, true).'</pre>';
+ echo '<pre>'.print_r($values, true).'</pre>';
+ exit;
+
+ }
+
+ /**
+ * Handles how to display the current step the user is at in the form
+ *
+ * destroying and resetting the captcha value dis-allows someone from
+ * re-sending a form on a previous captcha.
+ *
+ * @return string form HTML state
+ * @access public
+ */
+ public function toHtml()
+ {
+ if ($this->validate()) {
+ $res = $this->process(
+ array(&$this, 'processData'),
+ $this->mergeFiles
+ );
+ if ($res === true) {
+ $this->cleanForm();
+ $this->freeze();
+ $this->emailOwner();
+ if (method_exists($this, 'confirmation')) {
+ $this->confirmation();
+ }
+ $output = $this->successMsg;
+ $rem = array(
+ 'cc_cvv',
+ 'cc_type',
+ 'captcha_question',
+ );
+ foreach ($rem as $i) {
+ if ($this->elementExists($i)) {
+ $this->removeElement($i);
+ }
+ }
+
+ if ($this->elementExists('cc_num')) {
+ // Obscure th CC Num so its not displayed.
+ $e = $this->getElement('cc_num');
+ $ccNum = $e->getValue();
+ $newCCNum = preg_replace(
+ '/\d/',
+ '*',
+ $ccNum,
+ strlen($ccNum) - 4
+ );
+ $e->setValue($newCCNum);
+ }
+ } elseif ($res == 2) {
+ $this->_errors['cc_num'] = 'ERROR: Your credit card has been declined!';
+ $this->captchaQuestion->destroy();
+ $this->captchaAnswer->setValue('');
+ $this->setupRenderers();
+ $output = $this->errorMsg;
+ $output .= $this->template->bufferedOutputObject($this->view);
+ } else {
+ $this->_errors['cc_num'] = 'ERROR: There was an error processing your credit card!';
+ $this->captchaQuestion->destroy();
+ $this->captchaAnswer->setValue('');
+ $this->setupRenderers();
+ $output = $this->errorMsg;
+ $output .= $this->template->bufferedOutputObject($this->view);
+ }
+ $this->sent = true;
+ } elseif ($this->isSubmitted()) {
+ $this->captchaQuestion->destroy();
+ $this->captchaAnswer->setValue('');
+ $this->setupRenderers();
+ $output = $this->errorMsg;
+ $output .= $this->template->bufferedOutputObject($this->view);
+ } else {
+ $this->captchaQuestion->destroy();
+ $this->captchaAnswer->setValue('');
+ $this->setupRenderers();
+ $output .= $this->template->bufferedOutputObject($this->view);
+ }
+ return $output;
+ }
}