public function _process($params)
 {
     $transaction = new AuthorizeNetAIM($this->settings['api_login_id'], $this->settings['transaction_key']);
     $transaction->amount = $params['amount'];
     $transaction->card_num = $params['card_no'];
     $transaction->exp_date = $params['exp_month'] . $params['exp_year'];
     $transaction->card_code = $params['csc'];
     $transaction->invoice_num = $params['reference'];
     $transaction->customer_ip = $this->CI->input->ip_address();
     $transaction->setSandbox((bool) $this->settings['test_mode']);
     // set extra billing details if we have them
     if (isset($params['card_name'])) {
         $names = explode(' ', $params['card_name'], 2);
         $transaction->first_name = $names[0];
         $transaction->last_name = isset($names[1]) ? $names[1] : '';
     }
     if (isset($params['address']) and isset($params['address2'])) {
         $params['address'] = trim($params['address'] . " \n" . $params['address2']);
     }
     foreach (array('company' => 'company', 'address' => 'address', 'city' => 'city', 'state' => 'region', 'zip' => 'postcode', 'country' => 'country', 'phone' => 'phone', 'email' => 'email') as $key => $field) {
         if (isset($params[$field])) {
             $transaction->{$key} = $params[$field];
         }
     }
     $response = $transaction->authorizeAndCapture();
     if ($response->approved) {
         return new Merchant_response('authorized', $response->response_reason_text, $response->transaction_id, (double) $response->amount);
     } elseif ($response->declined) {
         return new Merchant_response('declined', $response->response_reason_text);
     } else {
         return new Merchant_response('failed', $response->response_reason_text);
     }
 }
 /**
  * [action_form] generates the form to pay at paypal
  */
 public function action_pay()
 {
     $this->auto_render = FALSE;
     $id_order = $this->request->param('id');
     //retrieve info for the item in DB
     $order = new Model_Order();
     $order = $order->where('id_order', '=', $id_order)->where('status', '=', Model_Order::STATUS_CREATED)->limit(1)->find();
     if ($order->loaded()) {
         // include class vendor
         require Kohana::find_file('vendor/authorize/', 'autoload');
         define('AUTHORIZENET_API_LOGIN_ID', Core::config('payment.authorize_login'));
         define('AUTHORIZENET_TRANSACTION_KEY', Core::config('payment.authorize_key'));
         define('AUTHORIZENET_SANDBOX', Core::config('payment.authorize_sandbox'));
         $sale = new AuthorizeNetAIM();
         $sale->amount = $order->amount;
         $sale->card_num = Core::post('card-number');
         $sale->exp_date = Core::post('expiry-month') . '/' . Core::post('expiry-year');
         $response = $sale->authorizeAndCapture();
         if ($response->approved) {
             $order->confirm_payment('authorize', $response->transaction_id);
             //redirect him to his ads
             Alert::set(Alert::SUCCESS, __('Thanks for your payment!') . ' ' . $response->transaction_id);
             $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders')));
         } else {
             Alert::set(Alert::INFO, $response->error_message);
             $this->redirect(Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order)));
         }
     } else {
         Alert::set(Alert::INFO, __('Order could not be loaded'));
         $this->redirect(Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order)));
     }
 }
Exemple #3
0
 function action($data = array(), $post = array(), $id)
 {
     $ci =& get_instance();
     $ci->load->library('session');
     if (isset($this->ini['sandbox']) && isset($this->ini['api_login_id']) && isset($this->ini['transaction_key']) && isset($post['card_num']) && isset($post['exp_date'])) {
         require dirname(__FILE__) . '/lib/shared/AuthorizeNetRequest.php';
         require dirname(__FILE__) . '/lib/shared/AuthorizeNetTypes.php';
         require dirname(__FILE__) . '/lib/shared/AuthorizeNetXMLResponse.php';
         require dirname(__FILE__) . '/lib/shared/AuthorizeNetResponse.php';
         require dirname(__FILE__) . '/lib/AuthorizeNetAIM.php';
         define("AUTHORIZENET_API_LOGIN_ID", $this->ini['api_login_id']);
         define("AUTHORIZENET_TRANSACTION_KEY", $this->ini['transaction_key']);
         define("AUTHORIZENET_SANDBOX", $this->ini['sandbox']);
         $sale = new AuthorizeNetAIM();
         $sale->amount = number_format($data['amount'], 2);
         $sale->card_num = $post['card_num'];
         $sale->exp_date = $post['exp_date'];
         $response = $sale->authorizeAndCapture();
         if ($response->approved) {
             $ci =& get_instance();
             $ci->load->model('order_m');
             $order = $ci->order_m->getOrderNumber($data['item_number']);
             if (count($order) > 0) {
                 $update['status'] = 'completed';
                 $updatehis['order_id'] = $order->id;
                 $updatehis['label'] = 'order_status';
                 $updatehis['content'] = json_encode(array($order->order_number => 'completed'));
                 $updatehis['date'] = date('Y-m-d H:i:s');
                 $ci->order_m->_table_name = 'orders';
                 if ($ci->order_m->save($update, $order->id)) {
                     $ci->order_m->_table_name = 'orders_histories';
                     $ci->order_m->save($updatehis);
                     $ci->load->helper('cms');
                     $user = $ci->session->userdata('user');
                     //params shortcode email.
                     $params = array('username' => $user['username'], 'email' => $user['email'], 'date' => date('Y-m-d H:i:s'), 'shop' => getSiteName(config_item('site_name')), 'shop_url' => site_url(), 'total' => number_format($data['amount'], 2), 'order_number' => $data['item_number'], 'status' => 'completed');
                     //config email.
                     $config = array('mailtype' => 'html');
                     $subject = configEmail('sub_order_status', $params);
                     $message = configEmail('order_status', $params);
                     $ci->load->library('email', $config);
                     $ci->email->from(getEmail(config_item('admin_email')), getSiteName(config_item('site_name')));
                     $ci->email->to($user['email']);
                     $ci->email->subject($subject);
                     $ci->email->message($message);
                     $ci->email->send();
                 }
             }
             $ci->session->set_flashdata('msg', 'Thanks you for payment!');
             if (isset($this->ini['message'])) {
                 $ci->session->set_flashdata('message', $this->ini['message']);
             }
         } else {
             $ci->session->set_flashdata('error', 'Your payment not success!');
         }
     }
     redirect(site_url('payment/confirm'));
 }
Exemple #4
0
 public function processPayment(\AuthorizeNetAIM $transaction, array $paymentDetails)
 {
     $transaction->amount = $paymentDetails['amount'];
     $transaction->card_num = $paymentDetails['card_num'];
     $transaction->exp_date = $paymentDetails['exp_date'];
     $response = $transaction->authorizeAndCapture();
     if ($response->approved) {
         return $this->savePayment($response->transaction_id);
     }
     throw new \Exception($response->error_message);
 }
 public function testGetUnsettledTransactionList()
 {
     $sale = new AuthorizeNetAIM();
     $amount = rand(1, 100);
     $response = $sale->authorizeAndCapture($amount, '4012888818888', '04/17');
     $this->assertTrue($response->approved);
     $request = new AuthorizeNetTD();
     $response = $request->getUnsettledTransactionList();
     $this->assertTrue($response->isOk());
     $this->assertTrue($response->xml->transactions->count() >= 1);
 }
 /**
  * Payment process and create subscription
  * @author Gaurav
  */
 public function process()
 {
     $this->layout = false;
     /*$request = new AuthorizeNetTD;
     		$transactionId = "2234120548";
     		$response = $request->getTransactionDetails($transactionId);
     		pr($response);
     		exit;
     		echo $response->xml->transaction->transactionStatus;
     
     		exit;*/
     $transaction = new AuthorizeNetAIM();
     $transaction->setSandbox(AUTHORIZENET_SANDBOX);
     $transaction->setFields(array('amount' => $this->request->data['BusinessOwner']['memberShipPrice'], 'card_num' => $this->request->data['BusinessOwner']['CC_Number'], 'exp_date' => $this->request->data['BusinessOwner']['expiration'], 'card_code' => $this->request->data['BusinessOwner']['cvv']));
     $response = $transaction->authorizeAndCapture();
     //pr($response);exit;
     if (isset($response->declined) && $response->declined == "1") {
         $errMsg = $response->response_reason_text;
         $errMsg .= "Please try again later.";
         $this->Session->setFlash(__($errMsg), 'flash_bad');
         $this->redirect(array('controller' => 'users', 'action' => 'payment'));
     }
     if (isset($response->error) && $response->error == "1") {
         $errMsg = $response->response_reason_text;
         $errMsg .= "Please try again later.";
         $this->Session->setFlash(__($errMsg), 'flash_bad');
         $this->redirect(array('controller' => 'users', 'action' => 'payment'));
     }
     if (isset($response->approved) && $response->approved == "1") {
         /*             * ***********Create Subscription****************** */
         /* $subscription = new AuthorizeNet_Subscription;
                       $subscription->name = 'Api Subscription';
                       $subscription->intervalLength = "1";
                       $subscription->intervalUnit = "months";
                       $subscription->startDate = date('Y-m-d',time());
                       $subscription->totalOccurrences = "999";
                       $subscription->amount = '50';
                       $subscription->creditCardCardNumber = $this->request->data['BusinessOwner']['CC_Number'];
                       $subscription->creditCardExpirationDate = $this->request->data['BusinessOwner']['expiration'];
                       $subscription->creditCardCardCode = $this->request->data['BusinessOwner']['cvv'];
                       $subscription->billToFirstName = 'A3';
                       $subscription->billToLastName = 'Logics';
         
                       $request = new AuthorizeNetARB;
                       $response = $request->createSubscription($subscription);
                       $subscription_id = $response->getSubscriptionId(); */
         $errMsg = "Payment Successful";
         $this->Session->setFlash(__($errMsg), 'flash_good');
         /*             * ***********Create Subscripton******************* */
         $this->redirect(array('controller' => 'users', 'action' => 'payment'));
     }
 }
 public function testGetTransactionDetails()
 {
     $sale = new AuthorizeNetAIM();
     $amount = rand(1, 100);
     $response = $sale->authorizeAndCapture($amount, '4012888818888', '04/17');
     $this->assertTrue($response->approved);
     $transId = $response->transaction_id;
     $request = new AuthorizeNetTD();
     $response = $request->getTransactionDetails($transId);
     $this->assertTrue($response->isOk());
     $this->assertEquals($transId, (string) $response->xml->transaction->transId);
     $this->assertEquals($amount, (string) $response->xml->transaction->authAmount);
     $this->assertEquals("Visa", (string) $response->xml->transaction->payment->creditCard->cardType);
 }
 public function processTransaction($data)
 {
     $log = Logger::getInstance();
     $log->LogDebug("process transaction authorize - ");
     //creditCard,$order,$customer
     $customer = (object) array();
     $customer->first_name = $data->reservationData->userData->first_name;
     $customer->last_name = $data->reservationData->userData->last_name;
     $customer->address = $data->reservationData->userData->address;
     $customer->city = $data->reservationData->userData->city;
     $customer->state = $data->reservationData->userData->state_name;
     $customer->country = $data->reservationData->userData->country;
     $customer->email = $data->reservationData->userData->email;
     $order = array('description' => JText::_('LNG_ORDER_DESC') . ' ' . $data->reservationData->hotel->hotel_name . '(' . $data->reservationData->userData->start_date . '-' . $data->reservationData->userData->end_date . ')', 'invoice_num' => $data->confirmation_id);
     $result = new stdClass();
     $result->card_name = JRequest::getVar("card_name", null);
     $result->card_number = JRequest::getVar("card_number", null);
     $result->card_expiration_year = JRequest::getVar("card_expiration_year", null);
     $result->card_expiration_month = JRequest::getVar("card_expiration_month", null);
     $result->card_security_code = JRequest::getVar("card_security_code", null);
     $result->amount = $data->cost > 0 ? $data->cost : $data->total;
     $creditCard = array('exp_date' => $result->card_expiration_month . "" . substr($result->card_expiration_year, -2), 'card_num' => $result->card_number, 'amount' => $result->amount);
     $sale = new AuthorizeNetAIM($this->AUTHORIZENET_API_LOGIN_ID, $this->AUTHORIZENET_TRANSACTION_KEY);
     if ($this->AUTHORIZENET_SANDBOX == 'false') {
         $sale->setSandbox(false);
     } else {
         $sale->setSandbox(true);
     }
     $sale->setFields($creditCard);
     $sale->setFields($order);
     $sale->setFields($customer);
     $response = $sale->authorizeAndCapture();
     $log->LogDebug("process response authorize -  " . serialize($response));
     if (isset($response->approved) && $response->approved == 1) {
         $result->status = PAYMENT_SUCCESS;
         $result->payment_status = PAYMENT_STATUS_PAID;
     } else {
         $result->status = PAYMENT_ERROR;
         $result->payment_status = PAYMENT_STATUS_FAILURE;
         $result->error_message = $response->error_message;
     }
     $result->transaction_id = 0;
     $result->payment_date = date("Y-m-d");
     $result->response_code = $response->approved;
     $result->confirmation_id = $data->confirmation_id;
     $result->processor_type = $this->type;
     return $result;
 }
 public function process(&$payment, $action)
 {
     if (!$this->validate_billing_information($payment)) {
         wp_redirect(esc_url_raw($payment->get_checkout_url()));
         die;
     }
     if ('pending' != $payment->get_status()) {
         die;
     }
     $payment->clear_errors();
     if (!class_exists('AuthorizeNetAIM')) {
         require_once WPBDP_PATH . 'vendors/anet_php_sdk/AuthorizeNet.php';
     }
     if ($payment->has_item_type('recurring_fee')) {
         // TODO: round fees not within 7-365 days (or make non-recurring).
         return $this->process_recurring($payment);
     }
     $data = $payment->get_data('billing-information');
     $aim = new AuthorizeNetAIM(wpbdp_get_option('authorize-net-login-id'), wpbdp_get_option('authorize-net-transaction-key'));
     if (wpbdp_get_option('payments-test-mode')) {
         $aim->setSandbox(true);
     } else {
         $aim->setSandbox(false);
     }
     // Order info.
     $aim->setFields(array('amount' => $payment->get_total(), 'description' => $payment->get_short_description(), 'invoice_num' => $payment->get_id()));
     // Card info.
     $aim->setFields(array('card_num' => $data['cc_number'], 'exp_date' => $data['cc_exp_month'] . substr($data['cc_exp_year'], 0, 2), 'card_code' => $data['cc_cvc']));
     // Billing addres info.
     $aim->setFields(array('first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'address' => $data['address_line1'], 'city' => $data['address_city'], 'state' => $data['address_state'], 'country' => $data['address_country'], 'zip' => $data['zipcode']));
     // TODO: maybe add zip, phone, email and cust_id
     $aim->setCustomField('payment_id', $payment->get_id());
     $aim->setCustomField('listing_id', $payment->get_listing_id());
     $response = $aim->authorizeAndCapture();
     if ($response->approved) {
         $payment->set_status(WPBDP_Payment::STATUS_COMPLETED, WPBDP_Payment::HANDLER_GATEWAY);
     } elseif ($response->error) {
         $payment->set_data('validation-errors', array(sprintf(_x('The payment gateway didn\'t accept your credit card or billing information. The following reason was given: "%s".', 'authorize-net', 'WPBDM'), '(' . $response->response_reason_code . ') ' . rtrim($response->response_reason_text, '.'))));
     } elseif ($response->held) {
         $payment->add_error(sprintf(_x('Your payment is being held for review by the payment gateway. The following reason was given: "%s".', 'authorize-net', 'WPBDM'), '(' . $response->response_reason_code . ') ' . rtrim($response->response_reason_text, '.')));
     } else {
         $payment->add_error(sprintf(_x('Payment was rejected. The following reason was given: "%s".', 'authorize-net', 'WPBDM'), '(' . $response->response_reason_code . ') ' . rtrim($response->response_reason_text, '.')));
         $payment->set_status(WPBDP_Payment::STATUS_REJECTED, WPBDP_Payment::HANDLER_GATEWAY);
     }
     $payment->save();
     wp_redirect(esc_url_raw($payment->get_redirect_url()));
     die;
 }
 public function _process($params)
 {
     $transaction = new AuthorizeNetAIM($this->settings['api_login_id'], $this->settings['transaction_key']);
     $transaction->amount = $params['amount'];
     $transaction->card_num = $params['card_no'];
     $transaction->exp_date = $params['exp_month'] . $params['exp_year'];
     $transaction->card_code = $params['csc'];
     $transaction->invoice_num = $params['reference'];
     $transaction->setSandbox((bool) $this->settings['test_mode']);
     $response = $transaction->authorizeAndCapture();
     if ($response->approved) {
         return new Merchant_response('authorized', $response->response_reason_text, $response->transaction_id, (double) $response->amount);
     } elseif ($response->declined) {
         return new Merchant_response('declined', $response->response_reason_text);
     } else {
         return new Merchant_response('failed', $response->response_reason_text);
     }
 }
Exemple #11
0
 public function processTransaction($data)
 {
     //creditCard,$order,$customer
     $customer = (object) array();
     $customer->first_name = "George";
     $customer->last_name = "Bara";
     $this->amount = $data->amount;
     $this->itemName = $data->service . " " . $data->description;
     $this->itemNumber = $data->id;
     $order = array('description' => $data->service . " " . $data->description, 'invoice_num' => $data->id);
     $result = new stdClass();
     $result->card_name = JRequest::getVar("card_name", null);
     $result->card_number = JRequest::getVar("card_number", null);
     $result->card_expiration_year = JRequest::getVar("card_expiration_year", null);
     $result->card_expiration_month = JRequest::getVar("card_expiration_month", null);
     $result->card_security_code = JRequest::getVar("card_security_code", null);
     $result->amount = $data->amount;
     $creditCard = array('exp_date' => $result->card_expiration_month . "" . substr($result->card_expiration_year, -2), 'card_num' => $result->card_number, 'amount' => $result->amount);
     $authorize = new AuthorizeNetAIM($this->apiLoginId, $this->transactionKey);
     if ($this->mode == "test") {
         $authorize->setSandbox(true);
     } else {
         $authorize->setSandbox(false);
     }
     $authorize->setFields($creditCard);
     $authorize->setFields($order);
     $authorize->setFields($customer);
     $response = $authorize->authorizeAndCapture();
     dump($response);
     if (isset($response->approved) && $response->approved == 1) {
         $result->status = PAYMENT_SUCCESS;
         $result->payment_status = PAYMENT_STATUS_PAID;
     } else {
         $result->status = PAYMENT_ERROR;
         $result->payment_status = PAYMENT_STATUS_FAILURE;
         $result->error_message = $response->error_message;
     }
     $result->transaction_id = $response->transaction_id;
     $result->payment_date = date("Y-m-d");
     $result->response_code = $response->approved;
     $result->order_id = $data->id;
     $result->processor_type = $this->type;
     return $result;
 }
 /**
  * Do AIM payment.
  */
 public function executeAuthorizeNetAIM()
 {
     include_once AB_PATH . '/lib/payment/authorize.net/autoload.php';
     $response = null;
     $userData = new AB_UserBookingData($this->getParameter('form_id'));
     if ($userData->load()) {
         define("AUTHORIZENET_API_LOGIN_ID", get_option('ab_authorizenet_api_login_id'));
         define("AUTHORIZENET_TRANSACTION_KEY", get_option('ab_authorizenet_transaction_key'));
         define("AUTHORIZENET_SANDBOX", (bool) get_option('ab_authorizenet_sandbox'));
         $price = $userData->getFinalServicePrice() * $userData->get('number_of_persons');
         $sale = new AuthorizeNetAIM();
         $sale->amount = $price;
         $sale->card_num = $this->getParameter('ab_card_number');
         $sale->card_code = $this->getParameter('ab_card_code');
         $sale->exp_date = $this->getParameter('ab_card_month') . '/' . $this->getParameter('ab_card_year');
         $sale->first_name = $userData->get('name');
         $sale->email = $userData->get('email');
         $sale->phone = $userData->get('phone');
         $response = $sale->authorizeAndCapture();
         if ($response->approved) {
             /** @var AB_Appointment $appointment */
             $appointment = $userData->save();
             $customer_appointment = new AB_CustomerAppointment();
             $customer_appointment->loadBy(array('appointment_id' => $appointment->get('id'), 'customer_id' => $userData->getCustomerId()));
             $payment = new AB_Payment();
             $payment->set('total', $price);
             $payment->set('type', 'authorizeNet');
             $payment->set('customer_appointment_id', $customer_appointment->get('id'));
             $payment->set('created', current_time('mysql'));
             $payment->save();
             $response = array('state' => 'success');
         } else {
             $response = array('status' => 'error', 'error' => $response->response_reason_text);
         }
     } else {
         $response = array('status' => 'error', 'error' => __('Session error.', 'bookly'));
     }
     wp_send_json($response);
 }
function authorizepayment($REQUEST)
{
    if (!checkCreditCard($REQUEST['x_card_num'], $REQUEST['card_type'], $ccerror, $ccerrortext)) {
        $_SESSION['donate_msg'] = 'Please enter a valid credit card number.';
        return false;
    } else {
        $transaction = new AuthorizeNetAIM();
        $transaction->setSandbox(AUTHORIZENET_SANDBOX);
        $transaction->setFields(array('amount' => $REQUEST['amount'], 'card_num' => $REQUEST['x_card_num'], 'exp_date' => $REQUEST['exp_month'] . '/' . $REQUEST['exp_year'], 'first_name' => $REQUEST['first_name'], 'last_name' => $REQUEST['last_name'], 'address' => $REQUEST['address'], 'city' => $REQUEST['city'], 'state' => $REQUEST['state'], 'country' => $REQUEST['country'], 'zip' => $REQUEST['zip'], 'email' => $REQUEST['email']));
        $transaction->setCustomField("Donation Form", $REQUEST["form_id"]);
        $transaction->setCustomField("Donation Type", $REQUEST["donation_type"]);
        $transaction->addLineItem("Donation", "Donation to '" . get_bloginfo("name") . "'", "Donation to '" . get_bloginfo("name") . "' using the form: " . $REQUEST["form_id"], 1, $REQUEST['amount'], false);
        $response = $transaction->authorizeAndCapture();
        if ($response->approved) {
            $_SESSION['donate_msg'] = $response->response_reason_text;
            return true;
        } else {
            $_SESSION['donate_msg'] = $response->response_reason_text;
            return false;
        }
    }
}
 public function process_payment($order_id)
 {
     error_reporting(0);
     $order = $this->api->getOrderByID($order_id);
     $this->load_config();
     $sandbox = true;
     if ($this->m_config['AUTHORIZENET_SANDBOX']) {
         $sandbox = false;
     }
     $amount = $order->gross * 100;
     $currency = $order->currency;
     $cardnumber = str_replace(" ", "", $_POST['credit_card_number']);
     $cardname = $_POST['credit_card_name'];
     $cardtype = $_POST['credit_card_type'];
     $cvnnumber = $_POST['credit_card_cvn'];
     $expdate = $_POST['credit_card_exp_month'] . $_POST['credit_card_exp_year'];
     // API credentials only need to be defined once
     define("AUTHORIZENET_API_LOGIN_ID", $this->m_config['AUTHORIZENET_API_LOGIN_ID']);
     define("AUTHORIZENET_TRANSACTION_KEY", $this->m_config['AUTHORIZENET_TRANSACTION_KEY']);
     define("AUTHORIZENET_SANDBOX", $sandbox);
     $sale = new AuthorizeNetAIM();
     $sale->amount = $amount;
     $sale->card_num = $cardnumber;
     $sale->exp_date = $expdate;
     if ($this->m_config['transaction_method'] == 'authorization') {
         $response = $sale->authorizeOnly();
     } elseif ($this->m_config['transaction_method'] == 'capture') {
         $response = $sale->authorizeAndCapture();
     }
     if ($response->approved) {
         $order->paid();
         echo "<h2>Your payment was successfully processed. Thank you!</h2>";
         echo "Success! Transaction ID:" . $response->transaction_id;
     } else {
         echo "<h2>Your card was declined.</h2>";
     }
 }
 public static function processPayment()
 {
     $sale = new AuthorizeNetAIM();
     $data = payment_pro_get_custom(Params::getParam('extra'));
     $sale->amount = $data['amount'];
     $sale->card_num = Params::getParam('authorize_number');
     $sale->exp_date = Params::getParam('authorize_month') . Params::getParam('authorize_year');
     $response = $sale->authorizeAndCapture();
     $status = payment_pro_check_items($data['items'], $response->amount);
     if ($response->approved) {
         Params::setParam('authorize_transaction_id', $response->transaction_id);
         $exists = ModelPaymentPro::newInstance()->getPaymentByCode($response->transaction_id, 'AUTHORIZE', PAYMENT_PRO_COMPLETED);
         if (isset($exists['pk_i_id'])) {
             return PAYMENT_PRO_ALREADY_PAID;
         }
         // SAVE TRANSACTION LOG
         $invoiceId = ModelPaymentPro::newInstance()->saveInvoice($response->transaction_id, $response->amount, $status, 'USD', $data['email'], $data['user'], 'AUTHORIZE', $data['items']);
         //source
         if ($status == PAYMENT_PRO_COMPLETED) {
             foreach ($data['items'] as $item) {
                 if (substr($item['id'], 0, 3) == 'PUB') {
                     $tmp = explode("-", $item['id']);
                     ModelPaymentPro::newInstance()->payPublishFee($tmp[count($tmp) - 1], $invoiceId);
                 } else {
                     if (substr($item['id'], 0, 3) == 'PRM') {
                         $tmp = explode("-", $item['id']);
                         ModelPaymentPro::newInstance()->payPremiumFee($tmp[count($tmp) - 1], $invoiceId);
                     } else {
                         if (substr($item['id'], 0, 3) == 'WLT') {
                             ModelPaymentPro::newInstance()->addWallet($data['user'], $item['amount']);
                         } else {
                             osc_run_hook('payment_pro_item_paid', $item);
                         }
                     }
                 }
             }
         }
         return PAYMENT_PRO_COMPLETED;
     } else {
         $tmp = explode("Reason Text: ", $response->error_message);
         Params::setParam('authorize_error', $tmp[count($tmp) - 1]);
     }
     return PAYMENT_PRO_FAILED;
 }
 /**
  * Authorize.net Payments
  *
  * @param $purchase_data
  */
 public function give_process_authorize_net_payment($purchase_data)
 {
     if (!isset($_POST['card_number']) || $_POST['card_number'] == '') {
         give_set_error('empty_card', __('You must enter a card number', 'give'));
     }
     if (!isset($_POST['card_name']) || $_POST['card_name'] == '') {
         give_set_error('empty_card_name', __('You must enter the name on your card', 'give'));
     }
     if (!isset($_POST['card_exp_month']) || $_POST['card_exp_month'] == '') {
         give_set_error('empty_month', __('You must enter an expiration month', 'give'));
     }
     if (!isset($_POST['card_exp_year']) || $_POST['card_exp_year'] == '') {
         give_set_error('empty_year', __('You must enter an expiration year', 'give'));
     }
     if (!isset($_POST['card_cvc']) || $_POST['card_cvc'] == '' || strlen($_POST['card_cvc']) < 3) {
         give_set_error('empty_cvc', __('You must enter a valid CVC', 'give'));
     }
     $errors = give_get_errors();
     //No errors: Continue with payment processing
     if (!$errors) {
         //Include Authorize SDK
         require_once GIVE_AUTHORIZE_PLUGIN_DIR . '/includes/anet_php_sdk/AuthorizeNet.php';
         if (!give_is_test_mode()) {
             //LIVE:
             $authorize_api_login = give_get_option('give_api_login');
             $authorize_trans_key = give_get_option('give_transaction_key');
         } else {
             //SANDBOX
             $authorize_api_login = give_get_option('give_authorize_sandbox_api_login');
             $authorize_trans_key = give_get_option('give_authorize_sandbox_transaction_key');
         }
         //Check for credentials entered
         if (empty($authorize_api_login) || empty($authorize_trans_key)) {
             give_set_error('error_id_here', __('Error: Missing API Login or Transaction key. Please enter them in the plugin settings.', 'give-authorize'));
             return;
         }
         //Proceed with Authorize AIM
         $transaction = new AuthorizeNetAIM($authorize_api_login, $authorize_trans_key);
         $transaction->VERIFY_PEER = false;
         //Sandbox or not?
         if (give_is_test_mode()) {
             $transaction->setSandbox(true);
         } else {
             $transaction->setSandbox(false);
         }
         $card_info = $purchase_data['card_info'];
         $card_names = explode(' ', $card_info['card_name']);
         $first_name = isset($card_names[0]) ? $card_names[0] : $purchase_data['user_info']['first_name'];
         if (!empty($card_names[1])) {
             unset($card_names[0]);
             $last_name = implode(' ', $card_names);
         } else {
             $last_name = $purchase_data['user_info']['last_name'];
         }
         $transaction->amount = $purchase_data['price'];
         $transaction->card_num = strip_tags(trim($card_info['card_number']));
         $transaction->card_code = strip_tags(trim($card_info['card_cvc']));
         $transaction->exp_date = strip_tags(trim($card_info['card_exp_month'])) . '/' . strip_tags(trim($card_info['card_exp_year']));
         $transaction->description = give_get_purchase_summary($purchase_data);
         $transaction->first_name = $first_name;
         $transaction->last_name = $last_name;
         $transaction->address = $card_info['card_address'] . ' ' . $card_info['card_address_2'];
         $transaction->city = $card_info['card_city'];
         $transaction->country = $card_info['card_country'];
         $transaction->state = $card_info['card_state'];
         $transaction->zip = $card_info['card_zip'];
         $transaction->customer_ip = give_get_ip();
         $transaction->email = $purchase_data['user_email'];
         $transaction->invoice_num = $purchase_data['purchase_key'];
         try {
             $response = $transaction->authorizeAndCapture();
             if ($response->approved) {
                 $payment_data = array('price' => $purchase_data['price'], 'give_form_title' => $purchase_data['post_data']['give-form-title'], 'give_form_id' => intval($purchase_data['post_data']['give-form-id']), 'price_id' => isset($purchase_data['post_data']['give-price-id']) ? intval($purchase_data['post_data']['give-price-id']) : '', 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => give_get_currency(), 'user_info' => $purchase_data['user_info'], 'status' => 'pending', 'gateway' => 'authorizenet');
                 $payment = give_insert_payment($payment_data);
                 if ($payment) {
                     give_update_payment_status($payment, 'publish');
                     give_send_to_success_page();
                 } else {
                     give_set_error('authorize_error', __('Error: your payment could not be recorded. Please try again', 'give'));
                     give_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['give-gateway']);
                 }
             } else {
                 if (isset($response->response_reason_text)) {
                     $error = $response->response_reason_text;
                 } elseif (isset($response->error_message)) {
                     $error = $response->error_message;
                 } else {
                     $error = '';
                 }
                 if (strpos(strtolower($error), 'the credit card number is invalid') !== false) {
                     give_set_error('invalid_card', __('Your card number is invalid', 'give'));
                 } elseif (strpos(strtolower($error), 'this transaction has been declined') !== false) {
                     give_set_error('invalid_card', __('Your card has been declined', 'give'));
                 } elseif (isset($response->response_reason_text)) {
                     give_set_error('api_error', $response->response_reason_text);
                 } elseif (isset($response->error_message)) {
                     give_set_error('api_error', $response->error_message);
                 } else {
                     give_set_error('api_error', sprintf(__('An error occurred. Error data: %s', 'give'), print_r($response, true)));
                 }
                 give_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['give-gateway']);
             }
         } catch (AuthorizeNetException $e) {
             give_set_error('request_error', $e->getMessage());
             give_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['give-gateway']);
         }
     } else {
         give_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['give-gateway']);
     }
 }
 public function get_login($plan)
 {
     if ($plan == 'A') {
         $userdata = array('first_name' => Input::get('first_name'), 'last_name' => Input::get('last_name'), 'email' => Input::get('email'), 'username' => Input::get('username'), 'password' => Hash::make(Input::get('password')), 'address' => Input::get('address'), 'city' => Input::get('city'), 'state' => Input::get('state'), 'zipcode' => Input::get('zipcode'), 'country' => Input::get('country'), 'bgcolor' => "58,104,210", 'fontcolor' => "255,255,255", 'logo' => "http://minitmeet.com/img/logo.png", 'company_name' => Input::get('company_name'));
         $rules = array('first_name' => 'required', 'last_name' => 'required', 'email' => 'required|min:3|max:32|Unique:users,email', 'username' => 'Required|Min:3|Max:80|Regex:/^([a-z0-9- ])+$/i|Unique:users', 'password' => 'required|min:6|max:32', 'captcha' => 'required', 'address' => 'required', 'state' => 'required', 'country' => 'required', 'zipcode' => 'required', 'company_name' => 'required|alpha_num');
         $input = Input::all();
         $v = Validator::make($input, $rules);
         if ($v->fails()) {
             return Redirect::to('register')->withInput(Input::except('password'))->withErrors($v);
         } else {
             $data = $userdata;
             $pass = Input::get('password');
             DB::table('users')->insert($data);
             DB::table('users')->where('email', $data['email'])->update(array('plan' => $plan));
             $mail = Mail::send('emails.message', array('data' => $data, 'plan' => $plan, 'pass' => $pass), function ($message) {
                 $data = Session::get('data');
                 $message->to($data['email'])->subject('Minitmeet');
             });
             return Redirect::to('login')->with('success', 'You Have been Registered Succesfully');
         }
     } elseif ($plan == 'B' or $plan == 'C') {
         $rules = array('payment_type' => 'required');
         $input = Input::all();
         $v = Validator::make($input, $rules);
         if ($v->fails()) {
             return Redirect::to('register')->withInput(Input::except('password'))->withErrors($v);
         } else {
             if ($_POST['payment_type'] == "1") {
                 $userdata = array('first_name' => Input::get('first_name'), 'last_name' => Input::get('last_name'), 'email' => Input::get('email'), 'username' => Input::get('username'), 'password' => Hash::make(Input::get('password')), 'address' => Input::get('address'), 'city' => Input::get('city'), 'state' => Input::get('state'), 'zipcode' => Input::get('zipcode'), 'country' => Input::get('country'), 'bgcolor' => "58,104,210", 'fontcolor' => "255,255,255", 'logo' => "http://minitmeet.com/img/logo.png", 'company_name' => Input::get('company_name'));
                 $rules = array('first_name' => 'required', 'last_name' => 'required', 'email' => 'required|min:3|max:32|Unique:users,email', 'address' => 'required', 'state' => 'required', 'country' => 'required', 'zipcode' => 'required', 'username' => 'Required|Min:3|Max:80|Regex:/^([a-z0-9- ])+$/i|Unique:users', 'password' => 'required|min:6|max:32', 'company_name' => 'required|alpha_num');
                 $input = Input::all();
                 $v = Validator::make($input, $rules);
                 if ($v->fails()) {
                     return Redirect::to('register')->withInput(Input::except('password'))->withErrors($v);
                 } else {
                     Session::put('get_plan', $plan);
                     Session::put('data', $userdata);
                     return Redirect::to('onepagecheckout');
                 }
             }
             if ($_POST['payment_type'] == "2") {
                 $userdata = array('first_name' => Input::get('first_name'), 'last_name' => Input::get('last_name'), 'email' => Input::get('email'), 'username' => Input::get('username'), 'password' => Hash::make(Input::get('password')), 'address' => Input::get('address'), 'city' => Input::get('city'), 'state' => Input::get('state'), 'zipcode' => Input::get('zipcode'), 'country' => Input::get('country'), 'bgcolor' => "58,104,210", 'fontcolor' => "255,255,255", 'logo' => "http://minitmeet.com/img/logo.png", 'company_name' => Input::get('company_name'));
                 $rules = array('first_name' => 'required', 'last_name' => 'required', 'email' => 'required|min:3|max:32|Unique:users,email', 'address' => 'required', 'state' => 'required', 'country' => 'required', 'zipcode' => 'required', 'username' => 'Required|Min:3|Max:80|Regex:/^([a-z0-9- ])+$/i|Unique:users', 'password' => 'required|min:6|max:32', 'company_name' => 'required|alpha_num', 'card_number' => 'required', 'month' => 'required');
                 $input = Input::all();
                 $v = Validator::make($input, $rules);
                 if ($v->fails()) {
                     return Redirect::to('register')->withInput(Input::except('password'))->withErrors($v);
                 } else {
                     $card_num = Input::get('card_number');
                     $month = Input::get('month');
                     $year = Input::get('year');
                     $type = Input::get('card_type');
                     $plan = Session::get('plan');
                     $am = DB::table('plan')->where('plan_name', Session::get('plan'))->first();
                     $amount = $am->plan_price;
                     $data = $userdata;
                     $pass = Input::get('password');
                     require_once 'anet_php_sdk/AuthorizeNet.php';
                     // Make sure this path is correct.
                     $transaction = new AuthorizeNetAIM('9Hs3U7ePV', '7Fjj4kLu39LL62V2');
                     $transaction->amount = $amount;
                     $transaction->card_num = $card_num;
                     $transaction->exp_date = $month . "/" . $year;
                     //$transaction->bank_aba_code = $type;
                     $response = $transaction->authorizeAndCapture();
                     if ($response->approved) {
                         DB::table('users')->insert($data);
                         DB::table('users')->where('email', $data['email'])->update(array('plan' => $plan));
                         $id = DB::table('users')->where('email', $data['email'])->get(array('id'));
                         DB::table('transaction_id')->insert(array('user_id' => $id[0]->id, 'transaction_id' => $response->transaction_id, 'payer_email' => $data['email'], 'txn_type' => "authorise", 'payment_status' => $response->response_code, 'address' => $data['address'], 'zipcode' => $data['zipcode'], 'state' => $data['state'], 'country' => $data['country']));
                         DB::table('transaction_list')->insert(array('transaction_id' => $response->transaction_id, 'amount' => $amount, 'email' => $data['email'], 'medium' => "authorise", 'firstname' => $data['first_name'], 'lastname' => $data['last_name']));
                         $mail = Mail::send('emails.message', array('data' => $data, 'plan' => $plan, 'pass' => $pass), function ($message) {
                             $message->to(Input::get('email'))->subject('Minitmeet');
                         });
                         Session::flush();
                         $responsetext = "Transaction Done.Your transaction Id is: {$response->transaction_id}.Enter Username and password to Login";
                         //echo $responsetext; die();
                         return Redirect::to('login')->with('success', $responsetext);
                     } else {
                         return Redirect::to('register')->with('success', $response->error_message)->with('plan', $plan);
                     }
                 }
             }
         }
     }
 }
Exemple #18
0
 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);
             }
         }
     }
 }
 /**
  * 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;
 }
function espresso_process_aim($payment_data)
{
    extract($payment_data);
    global $wpdb, $org_options;
    require_once 'AuthorizeNet.php';
    $authnet_aim_settings = get_option('event_espresso_authnet_aim_settings');
    $authnet_aim_login_id = $authnet_aim_settings['authnet_aim_login_id'];
    $authnet_aim_transaction_key = $authnet_aim_settings['authnet_aim_transaction_key'];
    // Enable test mode if needed
    //4007000000027  <-- test successful visa
    //4222222222222  <-- test failure card number
    if ($authnet_aim_settings['use_sandbox']) {
        define("AUTHORIZENET_SANDBOX", true);
        define("AUTHORIZENET_LOG_FILE", true);
    } else {
        define("AUTHORIZENET_SANDBOX", false);
    }
    //start transaction
    $transaction = new AuthorizeNetAIM($authnet_aim_login_id, $authnet_aim_transaction_key);
    echo '<!--Event Espresso Authorize.net AIM Gateway Version ' . $transaction->gateway_version . '-->';
    $transaction->amount = $_POST['amount'];
    $transaction->card_num = $_POST['card_num'];
    $transaction->exp_date = $_POST['exp_date'];
    $transaction->card_code = $_POST['ccv_code'];
    $transaction->first_name = $_POST['first_name'];
    $transaction->last_name = $_POST['last_name'];
    $transaction->email = $_POST['email'];
    $transaction->address = $_POST['address'];
    $transaction->city = $_POST['city'];
    $transaction->state = $_POST['state'];
    $transaction->zip = $_POST['zip'];
    $transaction->cust_id = $_POST['x_cust_id'];
    $transaction->invoice_num = $_POST['invoice_num'];
    if ($authnet_aim_settings['test_transactions']) {
        $transaction->test_request = "true";
    }
    $payment_data['txn_type'] = 'authorize.net AIM';
    $payment_data['payment_status'] = 'Incomplete';
    $payment_data['txn_id'] = 0;
    $payment_data['txn_details'] = 'No response from authorize.net';
    $payment_data = apply_filters('filter_hook_espresso_prepare_event_link', $payment_data);
    $payment_data = apply_filters('filter_hook_espresso_get_total_cost', $payment_data);
    //Capture response
    $response = $transaction->authorizeAndCapture();
    if (!empty($response)) {
        if ($authnet_aim_settings['use_sandbox']) {
            $payment_data['txn_id'] = $response->invoice_number;
        } else {
            $payment_data['txn_id'] = $response->transaction_id;
        }
        $payment_data['txn_details'] = serialize($response);
        if ($response->approved) {
            $payment_data['payment_status'] = 'Completed';
            ?>
			<h2><?php 
            _e('Thank You!', 'event_espresso');
            ?>
</h2>
			<p><?php 
            _e('Your transaction has been processed.', 'event_espresso');
            ?>
</p>
			<p><?php 
            __('Transaction ID:', 'event_espresso') . $response->transaction_id;
            ?>
</p>
			<?php 
        } else {
            print $response->error_message;
            $payment_data['payment_status'] = 'Payment Declined';
        }
    } else {
        ?>
		<p><?php 
        _e('There was no response from Authorize.net.', 'event_espresso');
        ?>
</p>
		<?php 
    }
    add_action('action_hook_espresso_email_after_payment', 'espresso_email_after_payment');
    return $payment_data;
}
 public function testInvalidCredentials()
 {
     if (MERCHANT_LIVE_API_LOGIN_ID) {
         // Post a response to live server using invalid credentials.
         $sale = new AuthorizeNetAIM('a', 'a');
         $sale->setSandbox(false);
         $sale->setFields(array('amount' => rand(1, 1000), 'card_num' => '6011000000000012', 'exp_date' => '0415'));
         $response = $sale->authorizeAndCapture();
         $this->assertTrue($response->error);
         $this->assertEquals("13", $response->response_reason_code);
     }
 }
 public function process_payment($order_id)
 {
     global $woocommerce;
     $wc_order = new WC_Order($order_id);
     $cardtype = $this->get_card_type(sanitize_text_field(str_replace(' ', '', $_POST['authorizenet-card-number'])));
     if (!in_array($cardtype, $this->authorizenet_cardtypes)) {
         wc_add_notice('Merchant do not support accepting in ' . $cardtype, $notice_type = 'error');
         return array('result' => 'success', 'redirect' => WC()->cart->get_checkout_url());
         die;
     }
     $card_num = sanitize_text_field(str_replace(' ', '', $_POST['authorizenet-card-number']));
     $exp_date = explode("/", sanitize_text_field($_POST['authorizenet-card-expiry']));
     $exp_month = str_replace(' ', '', $exp_date[0]);
     $exp_year = str_replace(' ', '', $exp_date[1]);
     if (strlen($exp_year) == 2) {
         $exp_year += 2000;
     }
     $cvc = sanitize_text_field($_POST['authorizenet-card-cvc']);
     $sale = new AuthorizeNetAIM();
     $sale->amount = $wc_order->order_total;
     $sale->card_num = $card_num;
     $sale->exp_date = $exp_year . '/' . $exp_month;
     $sale->card_code = $cvc;
     $customer = (object) array();
     $customer->first_name = $wc_order->billing_first_name;
     $customer->last_name = $wc_order->billing_last_name;
     $customer->company = $wc_order->billing_company;
     $customer->address = $wc_order->billing_address_1 . ' ' . $wc_order->billing_address_2;
     $customer->city = $wc_order->billing_city;
     $customer->state = $wc_order->billing_state;
     $customer->zip = $wc_order->billing_postcode;
     $customer->country = $wc_order->billing_country;
     $customer->phone = $wc_order->billing_phone;
     $customer->email = $wc_order->billing_email;
     $customer->cust_id = $wc_order->user_id;
     $customer->invoice_num = $wc_order->get_order_number();
     $customer->description = get_bloginfo('blogname') . ' Order #' . $wc_order->get_order_number();
     $customer->ship_to_first_name = $wc_order->shipping_first_name;
     $customer->ship_to_last_name = $wc_order->shipping_last_name;
     $customer->ship_to_company = $wc_order->shipping_company;
     $customer->ship_to_address = $wc_order->shipping_address_1 . ' ' . $wc_order->shipping_address_2;
     $customer->ship_to_city = $wc_order->shipping_city;
     $customer->ship_to_state = $wc_order->shipping_state;
     $customer->ship_to_zip = $wc_order->shipping_postcode;
     $customer->ship_to_country = $wc_order->shipping_country;
     $customer->delim_char = '|';
     $customer->encap_char = '';
     $customer->customer_ip = $this->get_client_ip();
     $customer->tax = $wc_order->get_total_tax();
     $customer->freight = $wc_order->get_total_shipping();
     $customer->header_email_receipt = 'Order Receipt ' . get_bloginfo('blogname');
     $customer->footer_email_receipt = 'Thank you for Using ' . get_bloginfo('blogname');
     $sale->setFields($customer);
     if ('yes' == AUTHORIZENET_TRANSACTION_MODE) {
         $response = $sale->authorizeOnly();
     } else {
         $response = $sale->authorizeAndCapture();
     }
     if ($response) {
         if (1 == $response->approved || 4 == $response->approved) {
             $wc_order->add_order_note(__($response->response_reason_text . 'on' . date("d-m-Y h:i:s e") . 'with Transaction ID = ' . $response->transaction_id . ' using ' . strtoupper($response->transaction_type) . ' and authorization code ' . $response->authorization_code, 'woocommerce'));
             $wc_order->payment_complete($response->transaction_id);
             WC()->cart->empty_cart();
             $transactionmetas = array('approved' => $response->approved, 'declined' => $response->declined, 'error' => $response->error, 'held' => $response->held, 'response_code' => $response->response_code, 'response_subcode' => $response->response_subcode, 'response_reason_code' => $response->response_reason_code, 'authorization_code' => $response->authorization_code, 'card_type' => $response->card_type, 'transaction_type' => $response->transaction_type, 'account_number' => $response->account_number, 'cavv_response' => $response->cavv_response, 'card_code_response' => $response->card_code_response);
             add_post_meta($order_id, '_' . $order_id . '_' . $response->transaction_id . '_metas', $transactionmetas);
             if (1 == $response->approved && "auth_capture" == $response->transaction_type) {
                 add_post_meta($order_id, '_authorizenet_charge_status', 'charge_auth_captured');
             }
             if (1 == $response->approved && "auth_only" == $response->transaction_type) {
                 add_post_meta($order_id, '_authorizenet_charge_status', 'charge_auth_only');
             }
             return array('result' => 'success', 'redirect' => $this->get_return_url($wc_order));
         } else {
             $wc_order->add_order_note(__($response->response_reason_text . '---' . $response->error_message . ' on' . date("d-m-Y h:i:s e") . ' using ' . strtoupper($response->transaction_type), 'woocommerce'));
             wc_add_notice($response->response_reason_text, $notice_type = 'error');
         }
     } else {
         $wc_order->add_order_note(__($response->response_reason_text . '---' . $response->error_message . ' on' . date("d-m-Y h:i:s e") . ' using ' . strtoupper($response->transaction_type), 'woocommerce'));
         wc_add_notice($response->response_reason_text, $notice_type = 'error');
     }
 }
 function onTP_Processpayment($data, $vars = array())
 {
     $isValid = true;
     $error = array();
     $error['code'] = '';
     $error['desc'] = '';
     if (!empty($data['payment_type']) && $data['payment_type'] == "recurring") {
         $response = plgpaymentAuthorizenet::onTP_Processpayment_recurring($data);
         return $response;
     }
     $authnet_values = array("login" => $this->login_id, "tran_key" => $this->tran_key, "version" => "3.1", "delim_char" => "|", "delim_data" => "TRUE", "type" => "AUTH_CAPTURE", "method" => "CC", "relay_response" => "FALSE", "card_num" => $data['cardnum'], "card_code" => $data['cardcvv'], "exp_date" => $data['cardexp'], "description" => "", "amount" => $data['amount'], "first_name" => $data['cardfname'], "last_name" => $data['cardlname'], "address" => $data['cardaddress1'], "city" => $data['cardcity'], "state" => $data['cardstate'], "zip" => $data['cardzip'], "country" => $data['cardcountry'], "cust_id" => $data['user_id'], "email" => $data['email'], "invoice_num" => $vars->order_id, "description" => $vars->item_name);
     require_once 'authorizenet/lib/AuthorizeNet.php';
     $sale = new AuthorizeNetAIM($this->login_id, $this->tran_key);
     //Check sandbox or live
     $plgPaymentAuthorizenetHelper = new plgPaymentAuthorizenetHelper();
     $sandbox = $plgPaymentAuthorizenetHelper->isSandboxEnabled();
     $sale->setSandbox($sandbox);
     $sale->setFields($authnet_values);
     $allresp = $sale->authorizeAndCapture();
     if ($allresp->approved) {
         //echo "Sale successful!";
     } else {
         $error['desc'] = $allresp->error_message;
     }
     //print_r($allresp);die;
     //3.compare response order id and send order id in notify URL
     $res_orderid = '';
     $res_orderid = $data['order_id'];
     if ($isValid) {
         if (!empty($vars) && $res_orderid != $vars->order_id) {
             $isValid = false;
             $error['desc'] .= " ORDER_MISMATCH" . "Invalid ORDERID; notify order_is " . $vars->order_id . ", and response " . $res_orderid;
         }
     }
     // amount check
     if ($isValid) {
         if (!empty($vars)) {
             // Check that the amount is correct
             $order_amount = (double) $vars->amount;
             $retrunamount = (double) $allresp->amount;
             $epsilon = 0.01;
             if ($order_amount - $retrunamount > $epsilon) {
                 $allresp[0] = 'ERROR';
                 // change response status to ERROR FOR AMOUNT ONLY
                 $isValid = false;
                 $error['desc'] .= "ORDER_AMOUNT_MISTMATCH - order amount= " . $order_amount . ' response order amount = ' . $retrunamount;
             }
         }
     }
     // TRANSLET PAYMENT RESPONSE
     $payment_status = $this->translateResponse($allresp->response_code);
     $transaction_id = $allresp->transaction_id;
     $result = array('transaction_id' => $transaction_id, 'order_id' => $data['order_id'], 'status' => $payment_status, 'total_paid_amt' => $allresp->amount, 'raw_data' => $allresp, 'error' => $error, 'return' => $data['return']);
     return $result;
 }
 /**
  *function to reactivate the account
  *@author Priti Kabra
  */
 public function reactivate($regType = NULL, $refId = NULL)
 {
     $userId = $this->Encryption->decode($this->Session->read('Auth.Front.id'));
     $userData = $this->User->find('first', array('conditions' => array('User.id' => $userId)));
     $this->set(compact('userData'));
     if ($this->request->is('post')) {
         $this->loadModel('Coupon');
         $this->loadModel('Transaction');
         $this->loadModel('Subscription');
         //Check Coupon Code
         if (!empty($this->request->data['BusinessOwner']['code'])) {
             $couponCheck = $this->checkCouponCode($this->request->data['BusinessOwner']['code']);
             if (isset($couponCheck['error'])) {
                 $checkCouponError = 1;
                 $this->User->validationErrors['couponcheck'] = $couponCheck['error'];
                 $this->request->data = $this->request->data;
             } else {
                 $this->request->data['BusinessOwner']['memberShipPrice'] = $couponCheck['newMembershipPrice'];
             }
         } else {
             $this->request->data['BusinessOwner']['memberShipPrice'] = Configure::read('PLANPRICE');
         }
         $this->request->data['BusinessOwner']['expiration'] = $this->request->data['BusinessOwner']['expiration_month']['month'] . '/' . $this->request->data['BusinessOwner']['expiration_year']['year'];
         if (!isset($checkCouponError)) {
             //PAYMENT
             $transaction = new AuthorizeNetAIM();
             $transaction->setSandbox(AUTHORIZENET_SANDBOX);
             $transaction->setFields(array('amount' => $this->request->data['BusinessOwner']['memberShipPrice'], 'card_num' => $this->request->data['BusinessOwner']['CC_Number'], 'exp_date' => $this->request->data['BusinessOwner']['expiration'], 'card_code' => $this->request->data['BusinessOwner']['cvv']));
             $response = $transaction->authorizeAndCapture();
             if (isset($response->declined) && $response->declined == "1") {
                 $errMsg = $response->response_reason_text;
                 $this->Session->setFlash(__($errMsg), 'Front/flash_bad');
                 $this->__unsetData();
             } else {
                 if (isset($response->error) && $response->error == "1") {
                     $errMsg = $response->response_reason_text;
                     $this->Session->setFlash(__($errMsg), 'Front/flash_bad');
                     $this->__unsetData();
                 } else {
                     if (isset($response->approved) && $response->approved == "1") {
                         $userDataUpdate['deactivated_by_user'] = 0;
                         $userDataUpdate['reactivate'] = 1;
                         $this->User->id = $userId;
                         if ($this->User->save($userDataUpdate)) {
                             if ($regType != NULL && $refId != NULL) {
                                 $decrypted = $this->Encryption->decode($refId);
                                 $inviteData = $this->InvitePartner->find('first', array('conditions' => array('id' => $decrypted)));
                                 if ($this->request->data['User']['user_email'] == $inviteData['InvitePartner']['invitee_email']) {
                                     $data = array('InvitePartner.referral_amount' => 'InvitePartner.referral_amount + 5', 'InvitePartner.status' => "'active'", 'invitee_userid' => $this->User->id);
                                     $this->InvitePartner->updateAll($data, array('id' => $decrypted));
                                 }
                             }
                             $transactions['user_id'] = $userId;
                             $transactions['transaction_id'] = $response->transaction_id;
                             $transactions['status'] = 1;
                             $transactions['amount_paid'] = $this->request->data['BusinessOwner']['memberShipPrice'];
                             $transactions['credit_card_number'] = $this->Encryption->encode(substr($this->request->data['BusinessOwner']['CC_Number'], -4, 4));
                             $this->Transaction->save($transactions);
                             $txId = $this->Transaction->getLastInsertID();
                             //Create Subscription
                             $this->request->data['Subscription']['transaction_id'] = $response->transaction_id;
                             $this->createSubscription($this->request->data, $userId);
                             //Update Purchase date
                             $this->Transaction->id = $txId;
                             $this->Transaction->save(array('purchase_date' => $this->Common->getCurrentActiveDate($userId)));
                             //delete goals
                             //$this->GroupGoals->resetUserGoals($userId);
                             $this->Session->write('UID', $this->Encryption->encode($this->User->id));
                             $this->Session->write('countryInfo', $this->request->data['BusinessOwner']['country_id']);
                             $this->Session->write('zipInfo', $this->request->data['BusinessOwner']['zipcode']);
                             //Create Subscripton ends
                             $this->redirect(array('controller' => 'groups', 'action' => 'group-selection'));
                         } else {
                             foreach ($this->User->validationErrors as $key => $value) {
                                 $err[] = $value[0];
                             }
                             $this->Session->setFlash(__($err), 'Front/flash_bad');
                             $this->__unsetData();
                         }
                     } else {
                         foreach ($this->BusinessOwner->validationErrors as $key => $value) {
                             $err[] = $value[0];
                         }
                         $this->Session->setFlash(__($err[0]), 'Front/flash_bad');
                         $this->__unsetData();
                     }
                 }
             }
         } else {
             $this->Session->setFlash(__($this->User->validationErrors['couponcheck']), 'Front/flash_bad');
             $this->__unsetData();
             $this->request->data = $this->request->data;
         }
     }
 }
 /**
  * process a AIM transaction with authorize.net
  *
  * @return  Boolean,Int false on failure
  */
 public function anet_AIM()
 {
     // DEV RETURN TRUE
     return true;
     unset($this->_responses['last']);
     unset($this->_responses['TransactionResponse']);
     unset($this->_responses['CustomerProfileResponse']);
     unset($this->_responses['PaymentProfileResponse']);
     $anet = new AuthorizeNetAIM();
     $anet->amount = $this->amounts['total']->formatted;
     $anet->card_num = $this->info->card_num;
     $anet->card_code = $this->info->card_code;
     $anet->exp_date = $this->info->exp_date;
     $anet->description = $this->info->description;
     $anet->first_name = $this->info->first_name;
     $anet->last_name = $this->info->last_name;
     $anet->address = $this->info->address;
     $anet->city = $this->info->city;
     $anet->state = $this->info->state;
     $anet->zip = $this->info->zip;
     $anet->cust_id = $this->info->CustomerID;
     $anet->customer_ip = $this->info->customer_ip;
     $anet->trans_id = $this->old_trans_id;
     $anet->email = $this->info->email;
     if ($this->info->card_num) {
         $this->PymtRefCrdCd = substr($this->info->card_num, -4);
     }
     $anet->duplicate_window = AUTHORIZENET_DUPLICATE_WINDOW;
     if ($this->amounts['total']->rounded < 0) {
         $anet->amount = -$this->amounts['total']->rounded;
         $this->_responses['last'] = $anet->credit();
     } elseif ($this->amounts['total']->rounded > 0) {
         $this->_responses['last'] = $anet->authorizeAndCapture();
     } else {
         return 1;
     }
     if ($this->_responses['last']->approved) {
         $this->_responses['TransactionResponse'] = $this->_responses['last'];
         $this->_responses['last'] = $this->_responses['TransactionResponse'];
         $this->PymtRefCd = $this->_responses['TransactionResponse']->transaction_id;
         $this->PymtRefCrdCd = substr($this->_responses['TransactionResponse']->account_number, -4);
         $this->card_type = $this->_responses['TransactionResponse']->card_type;
         return true;
     } else {
         if ($this->debug) {
             ri($anet);
         }
         return false;
     }
 }
Exemple #26
0
 //		$donation->trans_id
 //		$donation->type
 //		$donation->version
 if ($dep_Type == "CreditCard") {
     $donation->card_num = $creditCard;
     $donation->exp_date = $expMonth . "/" . $expYear;
 } else {
     // check payment info if supplied...
     // Use eCheck:
     $donation->bank_acct_name = $firstName . ' ' . $lastName;
     $donation->bank_acct_num = $account;
     $donation->bank_acct_type = 'CHECKING';
     $donation->bank_name = $bankName;
     $donation->setECheck($route, $account, 'CHECKING', $bankName, $firstName . ' ' . $lastName, 'WEB');
 }
 $response = $donation->authorizeAndCapture();
 if ($response->approved) {
     $transaction_id = $response->transaction_id;
 }
 if ($response->approved) {
     // Push the authorized transaction date forward by the interval
     $sSQL = "UPDATE autopayment_aut SET aut_NextPayDate=DATE_ADD('" . $authDate . "', INTERVAL " . $aut_Interval . " MONTH) WHERE aut_ID = " . $aut_ID . " AND aut_Amount = " . $plg_amount;
     RunQuery($sSQL);
     // Update the serial number in any case, even if this is not the scheduled payment
     $sSQL = "UPDATE autopayment_aut SET aut_Serial=aut_Serial+1 WHERE aut_ID = " . $aut_ID;
     RunQuery($sSQL);
 }
 if (!$response->approved) {
     $response->approved = 0;
 }
 $sSQL = "UPDATE pledge_plg SET plg_aut_Cleared=" . $response->approved . " WHERE plg_plgID=" . $plg_plgID;
Exemple #27
0
    $amount_to_pay = is_numeric($amount_to_pay) ? normalPrettyPrice($amount_to_pay) : '';
    $amount_to_pay = unPrettyPrice($amount_to_pay);
    $payment_description .= isset($res['title']) ? $res['title'] : '';
    /*dump($amount_to_pay);
    	dump($payment_description);*/
    if (isset($_POST['x_card_num'])) {
        define("AUTHORIZENET_API_LOGIN_ID", $autho_api_id);
        define("AUTHORIZENET_TRANSACTION_KEY", $autho_key);
        define("AUTHORIZENET_SANDBOX", $mode_autho == "sandbox" ? true : false);
        //define("TEST_REQUEST", $mode_autho=="sandbox"?"FALSE":"TRUE");
        require_once 'anet_php_sdk/AuthorizeNet.php';
        $transaction = new AuthorizeNetAIM();
        $transaction->setSandbox(AUTHORIZENET_SANDBOX);
        $params = array('description' => $payment_description, 'amount' => $amount_to_pay, 'card_num' => $_POST['x_card_num'], 'exp_date' => $_POST['expiration_month'] . "/" . $_POST['expiration_yr'], 'first_name' => $_POST['x_first_name'], 'last_name' => $_POST['x_last_name'], 'address' => $_POST['x_address'], 'city' => $_POST['x_city'], 'state' => $_POST['x_state'], 'country' => $_POST['x_country'], 'zip' => $_POST['x_zip'], 'card_code' => $_POST['cvv']);
        $transaction->setFields($params);
        $response = $transaction->authorizeAndCapture();
        if ($response->approved) {
            $resp_transaction = $response->transaction_id;
            $params = array('merchant_id' => Yii::app()->functions->getMerchantID(), 'sms_package_id' => $package_id, 'payment_type' => $payment_code, 'package_price' => $amount_to_pay, 'sms_limit' => isset($res['sms_limit']) ? $res['sms_limit'] : '', 'date_created' => date('c'), 'ip_address' => $_SERVER['REMOTE_ADDR'], 'payment_gateway_response' => json_encode($response), 'status' => "paid", 'payment_reference' => $resp_transaction);
            if ($db_ext->insertData("{{sms_package_trans}}", $params)) {
                header('Location: ' . Yii::app()->request->baseUrl . "/merchant/smsReceipt/id/" . Yii::app()->db->getLastInsertID());
            } else {
                $error = Yii::t("default", "ERROR: Cannot insert record.");
            }
        } else {
            $error = $response->response_reason_text;
        }
    }
} else {
    $error = Yii::t("default", "Sorry but we cannot find what your are looking for.");
}
 public function testGetUnsettledTransactionList()
 {
     $this->markTestSkipped('Ignoring for Travis. Will fix after release.');
     //TODO
     $sale = new AuthorizeNetAIM();
     $amount = rand(1, 100);
     $response = $sale->authorizeAndCapture($amount, '4012888818888', '04/17');
     $this->assertTrue($response->approved);
     $request = new AuthorizeNetTD();
     $response = $request->getUnsettledTransactionList();
     $this->assertTrue($response->isOk());
     $this->assertTrue($response->xml->transactions->count() >= 1);
 }
 public function testUpdateSplitTenderGroup()
 {
     // Create a partial auth test transaction
     $amount = 4.92;
     
     $sale = new AuthorizeNetAIM;
     $sale->amount = $amount;
     $sale->card_num = '4222222222222';
     $sale->zip = "46225";
     $sale->exp_date = '04/24';
     $sale->allow_partial_auth = true;
     $response = $sale->authorizeAndCapture();
     $this->assertTrue($response->held);
     $this->assertEquals("1.23", $response->amount);
     $this->assertEquals($amount, $response->requested_amount);
     $split_tender_id = $response->split_tender_id;
     
     // Charge a bit more
     $sale = new AuthorizeNetAIM;
     $sale->amount = 1.23;
     $sale->card_num = '6011000000000012';
     $sale->exp_date = '04/26';
     $sale->split_tender_id = $split_tender_id;
     $sale->allow_partial_auth = true;
     $response = $sale->authorizeAndCapture();
     $this->assertTrue($response->approved);
     
     // Void the group of partial auths.
     
     $request = new AuthorizeNetCIM;
     $response = $request->updateSplitTenderGroup($split_tender_id, "voided");
     $this->assertTrue($response->isOk());
 }
Exemple #30
0
         $app->response->setStatus(200);
         $app->response()->headers->set('Content-Type', 'application/json');
         //echo json_encode($client);
         $allPostVars = $app->request->post();
         $amount = $allPostVars['amount'];
         $card_num = $allPostVars['card_num'];
         $exp_date = $allPostVars['exp_date'];
         if (isset($amount, $card_num, $exp_date)) {
             define("AUTHORIZENET_API_LOGIN_ID", $client->authnet_api_login_id);
             define("AUTHORIZENET_TRANSACTION_KEY", $client->authnet_transaction_key);
             //define("AUTHORIZENET_SANDBOX", true);
             $sale = new AuthorizeNetAIM();
             $sale->amount = $amount;
             $sale->card_num = $card_num;
             $sale->exp_date = $exp_date;
             $response = $sale->authorizeAndCapture();
             if ($response->approved) {
                 echo json_encode("Success! Transaction ID:" . $response->transaction_id);
             } else {
                 echo json_encode("ERROR:" . $response->error_message);
             }
         }
         $db = null;
     } else {
         throw new PDOException('No records found.');
     }
 } catch (PDOException $e) {
     $app->response()->setStatus(404);
     echo '{"error":{"text":' . $e->getMessage() . '}}';
 }
 //end try