public function testAuthCaptureSetMultipleCustomFields() { $sale = new AuthorizeNetAIM(); $sale->setFields(array('amount' => rand(1, 1000), 'card_num' => '6011000000000012', 'exp_date' => '0415')); $sale->setCustomFields(array("foo" => "bar", "foo2" => "bar2")); $response = $sale->authorizeAndCapture(); $this->assertTrue($response->approved); $this->assertEquals("bar", $response->foo); $this->assertEquals("bar2", $response->foo2); }
public function executeProcessSale() { $this->setLayout(false); $this->result = false; $request = $this->getRequest(); $request->setParameter('x_exp_date', $this->getRequestParameter("exp_month") . "/" . $this->getRequestParameter("exp_year")); $request->setParameter("exp_month", ""); $request->setParameter("exp_year", ""); if ($this->getRequestParameter("submitted")) { if (array_key_exists("cart", $_SESSION)) { $products = array(); foreach ($_SESSION["cart"] as $item) { $doc = Document::getDocumentInstance($item); if ($doc) { $cnt = $_SESSION["num"][$item]; if (!$cnt) { $cnt = 1; } $price = $doc->getPrice(); $price = $price * $cnt; echo "price:" . $price . "<br>"; $totalPrice += $price; } } $totalPrice += round($totalPrice * (UtilsHelper::Settings("taxes") / 100), 2); } require_once sfConfig::get('sf_web_dir') . '/anet_php_sdk/AuthorizeNet.php'; $transaction = new AuthorizeNetAIM(); $transaction->setSandbox(AUTHORIZENET_SANDBOX); $transaction->setFields(array('amount' => $totalPrice, 'card_num' => $this->getRequestParameter('x_card_num'), 'exp_date' => $this->getRequestParameter('x_exp_date'), 'first_name' => $this->getRequestParameter('x_first_name'), 'last_name' => $this->getRequestParameter('x_last_name'), 'address' => $this->getRequestParameter('x_address'), 'email' => $this->getRequestParameter('x_email'), 'city' => $this->getRequestParameter('x_city'), 'state' => $this->getRequestParameter('x_state'), 'country' => $this->getRequestParameter('x_country'), 'zip' => $this->getRequestParameter('x_zip'), 'email' => $this->getRequestParameter('x_email'), 'card_code' => $this->getRequestParameter('x_card_code'))); $transaction->setCustomFields(array('products' => $this->getRequestParameter('x_delivery_address'))); $response = $transaction->authorizeAndCapture(); $this->response = $response; if (!$this->getRequestParameter('terms')) { $request->setError('errterms', "Please accept the terms of use"); UtilsHelper::setFlashMsg('', UtilsHelper::MSG_ERROR); } else { if ($response->approved) { $this->result = "success"; $this->transaction_id = $response->transaction_id; $message = "\n\t\t\t\t\tYou successfully ordered products from SubcommPools.com<br>\n\t\t\t\t\t<br>Date:" . date('l jS \\of F Y h:i:s A') . "<br>\n\t\t\t\t\t<br>Transaction number:" . $response->transaction_id . "<br>\n\t\t\t\t\t<br>Name: " . $this->getRequestParameter('x_first_name') . " " . $this->getRequestParameter('x_last_name') . "<br>\n\t\t\t\t\t<br>-------------------<br><br>"; foreach ($_SESSION["cart"] as $item) { $doc = Document::getDocumentInstance($item); if ($doc) { $itemCnt = $_SESSION["num"][$item]; if (!$itemCnt) { $itemCnt = 1; } $itemPrice = $doc->getPrice(); $itemPrice = $itemPrice * $cnt; $message .= $doc->getLabel() . ", Quantity: " . $itemCnt . ", \$" . $itemPrice . "<br>"; } } $message .= "<br>Total+Tax: \$" . $totalPrice . "<br>\n\t\t\t\t\t<br>Thank you for your purchase."; UtilsHelper::sendEmail($this->getRequestParameter('x_email'), $message, "SubcommPools Purchase", UtilsHelper::Settings("main_email"), "SubcommPools", UtilsHelper::Settings("main_email")); $_SESSION["cart"] = null; $_SESSION["num"] = null; } else { $this->response_text = $response->response_reason_text; //var_dump($response); $request->setError('errsubmit', $response->response_reason_text); UtilsHelper::setFlashMsg('', UtilsHelper::MSG_ERROR); //$this->result = $response->response_reason_text; //header('Location: error_page.php?response_reason_code='.$response->response_reason_code.'&response_code='.$response->response_code.'&response_reason_text=' .$response->response_reason_text); } } } }