/** * Authorize, or Authorize and Capture a Credit Card Transaction * * @param ContactDBO $contactDBO Billing contact * @param string $cardNumber Credit card number (XXXXXXXXXXXXXXXXXXXX) * @param string $expireDate CC expiration date (MMYY) * @param string $cardCode CVV2/CVC2/CID code * @param PaymentDBO $paymentDBO Payment DBO for this transaction * $param boolean $authOnly When true, the transaction will be authorized only * @return boolean False when there is an error processing the transaction */ function charge($contactDBO, $cardNumber, $expireDate, $cardCode, &$paymentDBO, $authOnly) { // Build PaymentDBO $paymentDBO->setDate(DBConnection::format_datetime(time())); $paymentDBO->setType("Module"); $paymentDBO->setModule($this->getName()); /* old busted method // Construct a list of parameters to be passed to Authorize.net $message = $this->buildPOSTFields( array( "x_login" => $this->getLoginID(), "x_version" => $this->getAPIVersion(), "x_delim_char" => $this->getDelimiter(), "x_delim_data" => "TRUE", "x_type" => $authOnly ? "AUTH_ONLY" : "AUTH_CAPTURE", "x_method" => "CC", "x_tran_key" => $this->getTransactionKey(), "x_card_num" => $cardNumber, "x_exp_date" => $expireDate, "x_amount" => $paymentDBO->getAmount(), "x_card_code" => $cardCode, "x_first_name" => substr( $contactDBO->getName(), 0, 50 ), "x_address" => substr( sprintf( "%s %s", $contactDBO->getAddress1(), $contactDBO->getAddress2() ), 0, 60 ), "x_city" => substr( $contactDBO->getCity(), 0, 40 ), "x_state" => substr( $contactDBO->getState(), 0, 40 ), "x_zip" => substr( $contactDBO->getPostalCode(), 0, 20 ), "x_country" => substr( $contactDBO->getCountry(), 0, 60 ), "x_phone" => substr( $contactDBO->getPhone(), 0, 25 ), "x_fax" => substr( $contactDBO->getFax(), 0, 25 ) ) ); // Carry out the transaction $resp = $this->executeTransaction( $message ); */ // New SDK method //$transaction = new AuthorizeNetAIM($this->getLoginID(), $this->getTransactionKey()); /* $transaction->amount = $paymentDBO->getAmount(); $transaction->card_num = $cardNumber; $transaction->exp_date = $expireDate; $customerData = (object) array(); $customerData->first_name = substr( $contactDBO->getName(), 0, 50 ); $customerData->address = substr( sprintf( "%s %s", $contactDBO->getAddress1(), $contactDBO->getAddress2() ), 0, 60 ); $customerData->city = substr( $contactDBO->getCity(), 0, 40 ); $customerData->state = substr( $contactDBO->getState(), 0, 40 ); $customerData->zip = substr( $contactDBO->getPostalCode(), 0, 20 ); $transaction->setFields($customerData); */ $transaction = new AuthorizeNetAIM('95n98SqG5', '4gc88U7xV5g78TYU'); $transaction->amount = '9.99'; $transaction->card_num = '4007000000027'; $transaction->exp_date = '10/16'; $response = $transaction->authorizeAndCapture(); if ($response->approved) { echo "<h1>Success! The test credit card has been charged!</h1>"; echo "Transaction ID: " . $response->transaction_id; } else { echo $response->error_message; } // Parse the transaction response switch ($response) { case AIM_APPROVED: $paymentDBO->setStatus($authOnly ? "Authorized" : "Completed"); $paymentDBO->setTransaction1($resp[AIM_RESP_TRANSACTION_ID]); $paymentDBO->setTransaction2($resp[AIM_RESP_APPROVAL_CODE]); if (!$this->saveTransaction($resp[AIM_RESP_TRANSACTION_ID], substr($cardNumber, -1, 4))) { fatal_error("AuthorizeAIM::authorize", "Failed to save transaction data: "); } break; case AIM_DECLINED: $paymentDBO->setStatus("Declined"); $paymentDBO->setStatusMessage($resp[AIM_RESP_REASON_TEXT]); break; case AIM_ERROR: log_error("AuthorizeAIM::authorize()", "An error occured while processing an Authorize.net transaction: " . $resp[AIM_RESP_REASON_TEXT]); return false; break; } return true; }
/** * Process Credit Card Payment */ function processCard() { // Update contact information $billingContact = new ContactDBO($this->post['contactname'], null, null, $this->post['address1'], $this->post['address2'], $this->post['city'], $this->post['state'], $this->post['postalcode'], $this->post['country'], $this->post['phone'], null, null); // Format the expire date $expireDate = date("my", $this->post['cardexpire']); // Create a new Payment DBO and process the payment $paymentDBO = new PaymentDBO(); $paymentDBO->setType("Module"); $paymentDBO->setModule($_SESSION['module']->getName()); $paymentDBO->setOrderID($this->session['order']->getID()); $paymentDBO->setAmount($this->session['order']->getTotal()); $paymentDBO->setStatus("Pending"); if (!$paymentDBO->processCreditCard($billingContact, $this->post['cardnumber'], $expireDate, $this->post['cardcode'], $this->conf['payment_gateway']['order_method'])) { print "card error"; $this->setError(array("type" => "[CC_PROCESSING_ERROR]")); $this->reload(); } // Card processed, save the payment DBO add_PaymentDBO($paymentDBO); // Complete the order $_SESSION['order']->complete(); // Show receipt $this->gotoPage("receipt"); }