function onBeforeOrderCreate(&$order, &$do) { if (parent::onBeforeOrderCreate($order, $do) === true) { return true; } if (!function_exists('curl_init')) { $this->app->enqueueMessage('The eSelect payment plugin needs the CURL library installed but it seems that it is not available on your server. Please contact your web hosting to set it up.', 'error'); $do = false; return false; } $this->ccLoad(); ob_start(); $dbg = ''; $amount = number_format($order->cart->full_total->prices[0]->price_value_with_tax, 2, '.', ''); require_once dirname(__FILE__) . DS . 'eselect_lib.php'; $txnArray = array('type' => 'purchase', 'order_id' => uniqid(), 'cust_id' => $this->user->user_id, 'amount' => $amount, 'pan' => $this->cc_number, 'expdate' => $this->cc_month . $this->cc_year, 'crypt_type' => '7', 'dynamic_descriptor' => ''); $mpgTxn = new mpgTransaction($txnArray); if ($this->payment_params->ask_ccv) { $cvdTemplate = array('cvd_indicator' => 1, 'cvd_value' => $this->cc_CCV); $mpgCvdInfo = new mpgCvdInfo($cvdTemplate); $mpgTxn->setCvdInfo($mpgCvdInfo); } $mpgRequest = new mpgRequest($mpgTxn); $mpgHttpPost = new mpgHttpsPost($this->payment_params->store_id, $this->payment_params->api_token, $mpgRequest, (int) $this->payment_params->debug != 0); $mpgResponse = $mpgHttpPost->getMpgResponse(); $ret = $mpgResponse->getResponseCode(); if ($ret !== null && $ret != 'null') { $ret = (int) $ret; if ($ret < 50 && $mpgResponse->getComplete() == 'true') { ob_get_clean(); ob_start(); $this->modifyOrder($order, $this->payment_params->verified_status, true, true); } else { $responseMsg = $mpgResponse->getMessage(); if (!empty($responseMsg)) { $this->app->enqueueMessage($responseMsg); } else { $this->app->enqueueMessage('Eselect/Moneris Response Error'); } $do = false; } } else { if (!empty($mpgHttpPost->curl_err)) { $this->app->enqueueMessage($mpgHttpPost->curl_err_msg); } else { $msg = $mpgResponse->getMessage(); if (empty($msg)) { $this->app->enqueueMessage('Eselect/Moneris Generic Error'); } else { $this->app->enqueueMessage('Eselect/Moneris: ' . $msg); } } $do = false; } if ($do == false) { return true; } $this->ccClear(); return true; }
function run_transaction($txnArray, $cvdTemplate = array(), $avsTemplate = array(), $custInfo = array()) { global $db, $config; if (is_file($config['root_dir'] . '/plugins/payment/moneris/lib/mpgclasses.php')) { require_once $config['root_dir'] . '/plugins/payment/moneris/lib/mpgclasses.php'; } else { return; } $store_id = $this->config['store_id']; $api_token = $this->config['api_token']; $mpgTxn = new mpgTransaction($txnArray); if ($cvdTemplate) { $mpgCvdInfo = new mpgCvdInfo($cvdTemplate); $mpgTxn->setCvdInfo($mpgCvdInfo); } if ($avsTemplate) { $mpgAvsInfo = new mpgAvsInfo($avsTemplate); $mpgTxn->setAvsInfo($mpgAvsInfo); } if ($custInfo) { $mpgCustInfo = new mpgCustInfo($custInfo); $mpgTxn->setCustInfo($mpgCustInfo); } $mpgRequest = new mpgRequest($mpgTxn); $mpgHttpPost = new mpgHttpsPost($store_id, $api_token, $mpgRequest, $this->config['testing']); $mpgResponse = $mpgHttpPost->getMpgResponse(); return $mpgResponse; }
<?php require "../mpgClasses.php"; $store_id = 'store3'; $api_token = 'yesguy'; $orderid = 'ord-' . date("dmy-G:i:s"); ## step 1) create transaction hash ### $txnArray = array('type' => 'idebit_purchase', 'order_id' => $orderid, 'cust_id' => 'my cust id', 'amount' => '50.00', 'idebit_track2' => '3728024906540591206=0609AAAAAAAAAAAAA'); ## step 2) create a transaction object passing the hash created in ## step 1. $mpgTxn = new mpgTransaction($txnArray); ## step 3) create a mpgRequest object passing the transaction object created ## in step 2 $mpgRequest = new mpgRequest($mpgTxn); ## step 4) create mpgHttpsPost object which does an https post ## $mpgHttpPost = new mpgHttpsPost($store_id, $api_token, $mpgRequest); ## step 5) get an mpgResponse object ## $mpgResponse = $mpgHttpPost->getMpgResponse(); ## step 6) retrieve data using get methods print "\nCardType = " . $mpgResponse->getCardType(); print "\nTransAmount = " . $mpgResponse->getTransAmount(); print "\nTxnNumber = " . $mpgResponse->getTxnNumber(); print "\nReceiptId = " . $mpgResponse->getReceiptId(); print "\nTransType = " . $mpgResponse->getTransType(); print "\nReferenceNum = " . $mpgResponse->getReferenceNum(); print "\nResponseCode = " . $mpgResponse->getResponseCode(); print "\nISO = " . $mpgResponse->getISO(); print "\nMessage = " . $mpgResponse->getMessage(); print "\nAuthCode = " . $mpgResponse->getAuthCode(); print "\nComplete = " . $mpgResponse->getComplete(); print "\nTransDate = " . $mpgResponse->getTransDate();
function doDirectPayment(&$params) { //make sure i've been called correctly ... if (!$this->_profile) { return self::error('Unexpected error, missing profile'); } if ($params['currencyID'] != 'CAD') { return self::error('Invalid currency selection, must be $CAD'); } /* unused params: cvv not yet implemented, payment action ingored (should test for 'Sale' value?) [cvv2] => 000 [ip_address] => 192.168.0.103 [payment_action] => Sale [contact_type] => Individual [geo_coord_id] => 1 */ //this code based on Moneris example code # //create an mpgCustInfo object $mpgCustInfo = new mpgCustInfo(); //call set methods of the mpgCustinfo object $mpgCustInfo->setEmail($params['email']); //get text representations of province/country to send to moneris for billing info $billing = array('first_name' => $params['first_name'], 'last_name' => $params['last_name'], 'address' => $params['street_address'], 'city' => $params['city'], 'province' => $params['state_province'], 'postal_code' => $params['postal_code'], 'country' => $params['country']); $mpgCustInfo->setBilling($billing); $my_orderid = $params['invoiceID']; // set orderid as invoiceID to help match things up with Moneris later $expiry_string = sprintf('%04d%02d', $params['year'], $params['month']); $txnArray = array('type' => 'purchase', 'order_id' => $my_orderid, 'amount' => sprintf('%01.2f', $params['amount']), 'pan' => $params['credit_card_number'], 'expdate' => substr($expiry_string, 2, 4), 'crypt_type' => '7', 'cust_id' => $params['contact_id']); // Allow further manipulation of params via custom hooks CRM_Utils_Hook::alterPaymentProcessorParams($this, $params, $txnArray); //create a transaction object passing the hash created above $mpgTxn = new mpgTransaction($txnArray); //use the setCustInfo method of mpgTransaction object to //set the customer info (level 3 data) for this transaction $mpgTxn->setCustInfo($mpgCustInfo); // add a recurring payment if requested if ($params['is_recur'] && $params['installments'] > 1) { //Recur Variables $recurUnit = $params['frequency_unit']; $recurInterval = $params['frequency_interval']; $next = time(); $day = 60 * 60 * 24; switch ($recurUnit) { case 'day': $next += $recurInterval * $day; break; case 'week': $next += $recurInterval * $day * 7; break; case 'month': $date = getdate(); $date['mon'] += $recurInterval; while ($date['mon'] > 12) { $date['mon'] -= 12; $date['year'] += 1; } $next = mktime($date['hours'], $date['minutes'], $date['seconds'], $date['mon'], $date['mday'], $date['year']); break; case 'year': $date = getdate(); $date['year'] += 1; $next = mktime($date['hours'], $date['minutes'], $date['seconds'], $date['mon'], $date['mday'], $date['year']); break; default: die('Unexpected error!'); } $startDate = date("Y/m/d", $next); // next payment in moneris required format $numRecurs = $params['installments'] - 1; //$startNow = 'true'; -- setting start now to false will mean the main transaction doesn't happen! $recurAmount = sprintf('%01.2f', $params['amount']); //Create an array with the recur variables $recurArray = array('recur_unit' => $recurUnit, 'start_date' => $startDate, 'num_recurs' => $numRecurs, 'start_now' => 'true', 'period' => $recurInterval, 'recur_amount' => $recurAmount); $mpgRecur = new mpgRecur($recurArray); // set the Recur Object to mpgRecur $mpgTxn->setRecur($mpgRecur); } //create a mpgRequest object passing the transaction object $mpgRequest = new mpgRequest($mpgTxn); // create mpgHttpsPost object which does an https post ## // [extra parameter added to library by AD] $isProduction = $this->_profile['mode'] == 'live'; $mpgHttpPost = new mpgHttpsPost($this->_profile['storeid'], $this->_profile['apitoken'], $mpgRequest, $isProduction); // get an mpgResponse object $mpgResponse = $mpgHttpPost->getMpgResponse(); $params['trxn_result_code'] = $mpgResponse->getResponseCode(); if (self::isError($mpgResponse)) { if ($params['trxn_result_code']) { return self::error($mpgResponse); } else { return self::error('No reply from server - check your settings &/or try again'); } } /* Check for application errors */ $result =& self::checkResult($mpgResponse); if (is_a($result, 'CRM_Core_Error')) { return $result; } /* Success */ $params['trxn_result_code'] = (int) $mpgResponse->getResponseCode(); // todo: above assignment seems to be ignored, not getting stored in the civicrm_financial_trxn table $params['trxn_id'] = $mpgResponse->getTxnNumber(); $params['gross_amount'] = $mpgResponse->getTransAmount(); return $params; }
public function actionCreditPayment() { $customer_model = new Customer(); $commande_model = new Commande(); $order_totals; $credit_card = new CreditCard($_POST['ccNumber'], $_POST['cvdNumber'], $_POST['ccName'], $_POST['expYear'], $_POST['expMonth']); $customer_model->attributes = Yii::app()->user->getState('Customer'); $commande_model->attributes = Yii::app()->user->getState('Commande'); $order_totals = $this->getInvoiceTotals($customer_model, $commande_model); $city = Goodcity::model()->findByPk($commande_model->comgoodcitykey); if (sizeof($customer_model->search()->getData()) == 0) { $customer_model->bilsignupip = CHttpRequest::getUserHostAddress(); $customer_model->save(); $commande_model->bilkey = $customer_model->bilkey; $commande_model->comdebut = date("Y-m-d"); $commande_model->save(); } else { $customerTemp = $customer_model->search()->getData(); $customer_model->bilkey = $customerTemp[0]->attributes['bilkey']; } Yii::import('ext.mail.vendors.*'); require "mpgClasses.php"; $store_id = 'monca70830'; $api_token = 'bFqjQoK69Li9wve1JkUk'; /*$store_id='store5'; $api_token='yesguy';*/ $typePurchase = 'purchase'; $typeAdd = 'res_add_cc'; $cust_id = $customer_model->bilkey; $phone = $customer_model['bilphone1']; $email = $customer_model['bilemail']; $note = "Mailbox in {$city->goodcity} for {$commande_model->comperiod}"; $order_id = 'MailNetwork-' . date("dmy-G:i:s"); $amount = str_replace(',', '', $order_totals['total']); $pan = $credit_card['cardNumber']; $expiry_date = substr($credit_card['expYear'], 2) . $credit_card['expMonth']; $crypt = '7'; $dynamic_descriptor = 'MailingNetwork'; $status_check = 'false'; $txnArray = array('type' => $typePurchase, 'order_id' => $order_id, 'cust_id' => $cust_id, 'amount' => $amount, 'pan' => $pan, 'expdate' => $expiry_date, 'crypt_type' => $crypt, 'dynamic_descriptor' => $dynamic_descriptor); $cvd_indicator = '1'; $cvd_value = $credit_card['cardCVD']; $cvdTemplate = array('cvd_indicator' => $cvd_indicator, 'cvd_value' => $cvd_value); $mpgCvdInfo = new mpgCvdInfo($cvdTemplate); $mpgAvsInfo = null; $mpgTxn = new mpgTransaction($txnArray); $mpgTxn->setCvdInfo($mpgCvdInfo); $mpgTxn->setAvsInfo($mpgAvsInfo); $mpgRequest = new mpgRequest($mpgTxn); $mpgHttpPost = new mpgHttpsPost($store_id, $api_token, $mpgRequest); $mpgResponse = $mpgHttpPost->getMpgResponse(); if ($mpgResponse->getComplete()) { if ($mpgResponse->getResponseCode() > 0 && $mpgResponse->getResponseCode() <= 49) { $auth_code = $mpgResponse->getAuthCode(); //Add card to vault if first purchase worked $txnArray = array('type' => $typeAdd, 'order_id' => $order_id, 'cust_id' => $cust_id, 'amount' => $amount, 'phone' => $phone, 'email' => $email, 'note' => $note, 'pan' => $pan, 'expdate' => $expiry_date, 'crypt_type' => $crypt, 'dynamic_descriptor' => $dynamic_descriptor); $cvd_indicator = '1'; $cvd_value = $credit_card['cardCVD']; $cvdTemplate = array('cvd_indicator' => $cvd_indicator, 'cvd_value' => $cvd_value); $mpgCvdInfo = null; $mpgAvsInfo = null; $mpgTxn = new mpgTransaction($txnArray); $mpgTxn->setCvdInfo($mpgCvdInfo); $mpgTxn->setAvsInfo($mpgAvsInfo); $mpgRequest = new mpgRequest($mpgTxn); $mpgHttpPost = new mpgHttpsPost($store_id, $api_token, $mpgRequest); $mpgResponse = $mpgHttpPost->getMpgResponse(); //Redirect to receipt after adding card $city = Goodcity::model()->findByPk($commande_model->comgoodcitykey); $this->render('application/2-orderform', array('goodcity' => $city, 'thanks' => true, 'payment_type' => "credit_card", 'payment_method' => "email", 'order_totals' => $order_totals, 'customer_model' => $customer_model, 'commande_model' => $commande_model, 'auth_code' => $auth_code)); $this->sendEmailConfirmation($customer_model, $city, $commande_model, $auth_code, $order_totals); } else { $this->redirect(array('user/order', 'transactionError' => true)); } } else { $this->redirect(array('user/order', 'transactionError' => true)); } }
function bill_checkout($amount, $invoice, $currency_iso, $acct_fields, $total_recurring = false, $recurr_bill_arr = false) { # Validate currency if (!$this->validate_currency($currency_iso)) { return false; } $ret = false; if (!$this->validate_card_details($ret)) { return false; } # Get the country $country = $this->getCountry('name', $this->account["country_id"]); # Test Transaction if ($this->cfg['mode'] == "1") { $test = "TRUE"; } else { $test = "FALSE"; } require_once "CLASS_MONERIS/mpgClasses.php"; $storeid = $this->cfg['user']; $apitoken = $this->cfg['pass']; $txnArray = array('type' => $this->cfg['type'], 'order_id' => $invoice, 'amount' => $amount, 'pan' => $this->billing["cc_no"], 'expdate' => $this->billing["exp_year"] . $this->billing["exp_month"], 'crypt_type' => '7'); $mpgTxn = new mpgTransaction($txnArray); /* $mpgCustInfo = new mpgCustInfo(); $billing = Array( 'first_name' => $this->account["first_name"], 'last_name' => $this->account["last_name"], 'company_name' => $this->account["company"], 'address' => $this->account["address1"] . ' ' . $this->account["address2"], 'city' => $this->account["city"], 'province' => $this->account["state"], 'postal_code' => $this->account["zip"], 'country' => $country); $mpgCustInfo->setBilling($billing); $mpgCustInfo->setEmail($acct_fields["email"]); $mpgTxn->setCustInfo($mpgCustInfo); */ $mpgRequest = new mpgRequest($mpgTxn); $mpgHttpPost = new mpgHttpsPost($storeid, $apitoken, $mpgRequest); $mpgResponse = $mpgHttpPost->getMpgResponse(); ## step 6) retrieve data using get methods print "\nCardType = " . $mpgResponse->getCardType(); print "\nTransAmount = " . $mpgResponse->getTransAmount(); print "\nTxnNumber = " . $mpgResponse->getTxnNumber(); print "\nReceiptId = " . $mpgResponse->getReceiptId(); print "\nTransType = " . $mpgResponse->getTransType(); print "\nReferenceNum = " . $mpgResponse->getReferenceNum(); print "\nResponseCode = " . $mpgResponse->getResponseCode(); print "\nISO = " . $mpgResponse->getISO(); print "\nMessage = " . $mpgResponse->getMessage(); print "\nAuthCode = " . $mpgResponse->getAuthCode(); print "\nComplete = " . $mpgResponse->getComplete(); print "\nTransDate = " . $mpgResponse->getTransDate(); print "\nTransTime = " . $mpgResponse->getTransTime(); print "\nTicket = " . $mpgResponse->getTicket(); print "\nTimedOut = " . $mpgResponse->getTimedOut(); # Test Mode if ($this->cfg['mode'] == "1") { echo '<script language=Javascript>alert(\'Gateway response: ' . $response . '\') </script>'; } # Get return response if (!$response) { echo '<script language=Javascript>alert(\'SSL Failed!\') </script>'; return false; } else { $response = explode(',', $response); } # Transaction Status: if ($response[0] == '1') { $ret['status'] = 1; } else { $ret['status'] = 0; } # Transaction ID: @($ret['avs'] = @$response[4]); # Message: @($ret['msg'] = @$response[3]); # AVS Details: if (@$response[5] == 'A') { $ret['avs'] = 'avs_address_only'; } elseif (@$response[5] == 'E') { $ret['avs'] = 'avs_error'; } elseif (@$response[5] == 'N') { $ret['avs'] = 'avs_no_match'; } elseif (@$response[5] == 'P') { $ret['avs'] = 'avs_na'; } elseif (@$response[5] == 'R') { $ret['avs'] = 'avs_retry'; } elseif (@$response[5] == 'S') { $ret['avs'] = 'avs_not_supported'; } elseif (@$response[5] == 'U') { $ret['avs'] = 'avs_address_unavail'; } elseif (@$response[5] == 'W') { $ret['avs'] = 'avs_fullzip_only'; } elseif (@$response[5] == 'X') { $ret['avs'] = 'avs_exact'; } elseif (@$response[5] == 'Y') { $ret['avs'] = 'avs_address_zip'; } elseif (@$response[5] == 'Z') { $ret['avs'] = 'avs_partzip_only'; } else { $ret['avs'] = 'avs_na'; } if ($ret['status'] == 1) { return $ret; } else { global $VAR; @($VAR['msg'] = $ret["msg"]); return false; } }
function process_payment() { $settings = $this->CI->Settings_model->get_settings('moneris'); $customer = $this->CI->go_cart->customer(); // Load the global classes require APPPATH . "packages/payment/moneris/libraries/mpgClasses.php"; /**************************** Request Variables *******************************/ if ($settings['mode'] == 'test') { $store_id = 'store5'; $api_token = 'yesguy'; } else { $store_id = $settings['site_id']; $api_token = $settings['api_key']; } $cc_data = $this->CI->session->userdata('cc_data'); /*********************** Transactional Associative Array **********************/ $txnArray = array('type' => 'purchase', 'order_id' => 'trans-' . date("dmy-G:i:s"), 'cust_id' => @$customer['id'], 'amount' => (string) number_format((double) $this->CI->go_cart->total(), 2), 'pan' => $cc_data['card_num'], 'expdate' => $cc_data['exp_date_yy'] . $cc_data['exp_date_mm'], 'cvd_value' => $cc_data['card_code'], 'cvd_indicator' => 1, 'crypt_type' => '7', 'dynamic_descriptor' => $settings['descriptor']); /**************************** Transaction Object *****************************/ $mpgTxn = new mpgTransaction($txnArray); /****************************** Request Object *******************************/ $mpgRequest = new mpgRequest($mpgTxn); /***************************** HTTPS Post Object *****************************/ /* Status Check Example $mpgHttpPost =new mpgHttpsPostStatus($store_id,$api_token,$status_check,$mpgRequest); */ $mpgHttpPost = new mpgHttpsPost($store_id, $api_token, $mpgRequest); /******************************* Response ************************************/ $mpgResponse = $mpgHttpPost->getMpgResponse(); /* for debugging print("\nCardType = " . $mpgResponse->getCardType()); print("\nTransAmount = " . $mpgResponse->getTransAmount()); print("\nTxnNumber = " . $mpgResponse->getTxnNumber()); print("\nReceiptId = " . $mpgResponse->getReceiptId()); print("\nTransType = " . $mpgResponse->getTransType()); print("\nReferenceNum = " . $mpgResponse->getReferenceNum()); print("\nResponseCode = " . $mpgResponse->getResponseCode()); print("\nISO = " . $mpgResponse->getISO()); print("\nMessage = " . $mpgResponse->getMessage()); print("\nIsVisaDebit = " . $mpgResponse->getIsVisaDebit()); print("\nAuthCode = " . $mpgResponse->getAuthCode()); print("\nComplete = " . $mpgResponse->getComplete()); print("\nTransDate = " . $mpgResponse->getTransDate()); print("\nTransTime = " . $mpgResponse->getTransTime()); print("\nTicket = " . $mpgResponse->getTicket()); print("\nTimedOut = " . $mpgResponse->getTimedOut()); print("\nStatusCode = " . $mpgResponse->getStatusCode()); print("\nStatusMessage = " . $mpgResponse->getStatusMessage()); */ if ($mpgResponse->getResponseCode() == 'null') { // Incomplete Transaction return lang('processing_error'); } $responseCode = (int) $mpgResponse->getResponseCode(); if ($responseCode >= 0 && $responseCode < 50) { // Transaction is good $this->CI->session->unset_userdata('cc_data'); return false; // no errors } else { // Transaction Declined return lang('transaction_declined'); } }
/** * * @return HTML */ function _process() { $data = JRequest::get('post'); $order = JTable::getInstance('Orders', 'TiendaTable'); $order->load($data['order_id']); $items = $order->getItems(); $orderpayment_id = $data['orderpayment_id']; $orderpayment_amount = $data['orderpayment_amount']; $amount = $data['orderpayment_amount']; /************************ Request Variables ***************************/ $store_id = $this->_store_id; $api_token = $this->_api_token; /************************** Recur Variables *****************************/ $is_recurring = $order->isRecurring(); // Check recurring items are present or not if ($is_recurring) { $vars->cmd = '_cart'; $vars->mixed_cart = true; // Adjust the orderpayment amount since it's a mixed cart // first orderpayment is just the non-recurring items total // then upon return, ask user to checkout again for recurring items $recurAmount = $order->recurring_trial ? $order->recurring_trial_price : $order->recurring_amount; $recurInterval = $order->recurring_trial ? $order->recurring_trial_period_interval : $order->recurring_period_interval; // '10'; $numRecurs = recurring_payments; //'4'; $recurUnit = $order->recurring_trial ? $order->recurring_trial_period_unit : $order->recurring_period_unit; // (day | week | month) $orderpayment->orderpayment_amount = $orderpayment->orderpayment_amount - $recurAmount; $orderpayment->save(); $amount = $orderpayment->orderpayment_amount; $startNow = 'true'; $startDate = date("Y/m/d"); // '2006/11/30'; //yyyy/mm/dd /****************************** Recur Array **************************/ $recurArray = array('recur_unit' => $recurUnit, 'start_date' => $startDate, 'num_recurs' => $numRecurs, 'start_now' => $startNow, 'period' => $recurInterval, 'recur_amount' => $recurAmount); /****************************** Recur Object **************************/ $mpgRecur = new mpgRecur($recurArray); } /****************** Transactional Variables ************************/ $type = 'purchase'; // genrate the unique Order Id to preserve the payment Id also $orderid = 'ord-' . $orderpayment_id . '-' . date("dmy-G:i:s"); //Check decimal (.) exist or not $temp_amount = explode('.', $amount); if (count($temp_amount) <= 1) { $amount = $amount . ".0"; } $cust_id = JFactory::getUser()->id; $pan = $data['cardnum']; // '4242424242424242'; $expiry_date = $data['cardexp']; // YYMM, so 0812 = December 2008 $crypt = '7'; // SSL-enabled merchant $commcard_invoice = ''; $commcard_tax_amount = ''; /******************* Customer Information Variables ********************/ $instructions = ''; $billing = $this->_getBillingAddress($data); /************************** AVS Variables *****************************/ $avs_street_number = intval($billing['address']); $avs_street_name = $billing['address']; $avs_zipcode = $billing['postal_code']; /************************** CVD Variables *****************************/ $cvd_indicator = '1'; // yes, we're using CVD $cvd_value = $data['cardcvv']; /********************** AVS Associative Array *************************/ $avsTemplate = array('avs_street_number' => $avs_street_number, 'avs_street_name' => $avs_street_name, 'avs_zipcode' => $avs_zipcode); /********************** CVD Associative Array *************************/ $cvdTemplate = array('cvd_indicator' => $cvd_indicator, 'cvd_value' => $cvd_value); /************************** AVS Object ********************************/ $mpgAvsInfo = new mpgAvsInfo($avsTemplate); /************************** CVD Object ********************************/ $mpgCvdInfo = new mpgCvdInfo($cvdTemplate); /******************** Customer Information Object *********************/ $mpgCustInfo = new mpgCustInfo(); /********************** Set Customer Information **********************/ $mpgCustInfo->setBilling($billing); $shipping = $this->_getShippingAddress($data); $mpgCustInfo->setShipping($shipping); $email = JFactory::getUser()->email; $mpgCustInfo->setEmail($email); $mpgCustInfo->setInstructions($instructions); /*********************** Set Line Item Information *********************/ foreach ($items as $itemObject) { $items_temp[0] = array('name' => $itemObject->orderitem_name, 'quantity' => $itemObject->orderitem_quantity, 'product_code' => $itemObject->orderitem_name, 'extended_amount' => $itemObject->orderitem_price); $mpgCustInfo->setItems($items_temp[0]); } /***************** Transactional Associative Array ********************/ $txnArray = array('type' => $type, 'order_id' => $orderid, 'cust_id' => $cust_id, 'amount' => $amount, 'pan' => $pan, 'expdate' => $expiry_date, 'crypt_type' => $crypt, 'commcard_invoice' => '', 'commcard_tax_amount' => ''); /********************** Transaction Object ****************************/ $mpgTxn = new mpgTransaction($txnArray); /******************** Set Customer Information ************************/ $mpgTxn->setCustInfo($mpgCustInfo); /************************ Set AVS and CVD *****************************/ $mpgTxn->setAvsInfo($mpgAvsInfo); $mpgTxn->setCvdInfo($mpgCvdInfo); /************************* Request Object *****************************/ $mpgRequest = new mpgRequest($mpgTxn); /************************ HTTPS Post Object ***************************/ $mpgHttpPost = new mpgHttpsPost($store_id, $api_token, $mpgRequest); /****************8********** Response *********************************/ $mpgResponse = $mpgHttpPost->getMpgResponse(); return $this->_evaluateResponse($mpgResponse); }
function doDirectPayment(&$params) { # make sure i've been called correctly ... if (!$this->_profile) { return CRM_Contribute_Payment_Moneris::error(); } if ($params['currencyID'] != 'CAD') { return CRM_Contribute_Payment_Moneris::error(); } /* unused params: cvv not yet implemented, payment action ingored (should test for 'Sale' value?) [cvv2] => 000 [ip_address] => 192.168.0.103 [payment_action] => Sale [contact_type] => Individual [geo_coord_id] => 1 */ # this code based on Moneris example code # ## create an mpgCustInfo object $mpgCustInfo = new mpgCustInfo(); ## call set methods of the mpgCustinfo object $mpgCustInfo->setEmail($params['email']); ## get text representations of province/country to send to moneris for billing info # $province = CRM_Core_PseudoConstant::stateProvince($params['state_province_id']); $country = CRM_Core_PseudoConstant::country($params['country_id']); $billing = array(first_name => $params['first_name'], last_name => $params['last_name'], address => $params['street_address'], city => $params['city'], province => $province, postal_code => $params['postal_code'], country => $country); $mpgCustInfo->setBilling($billing); $my_orderid = $params['invoiceID']; // set orderid as invoiceID to help match things up with Moneris later $expiry_string = sprintf('%04d%02d', $params['year'], $params['month']); $txnArray = array(type => 'purchase', order_id => $my_orderid, amount => sprintf('%01.2f', $params['amount']), pan => $params['credit_card_number'], expdate => substr($expiry_string, 2, 4), crypt_type => '7', cust_id => $params['contact_id']); ## create a transaction object passing the hash created above $mpgTxn = new mpgTransaction($txnArray); ## use the setCustInfo method of mpgTransaction object to ## set the customer info (level 3 data) for this transaction $mpgTxn->setCustInfo($mpgCustInfo); ## create a mpgRequest object passing the transaction object $mpgRequest = new mpgRequest($mpgTxn); ## create mpgHttpsPost object which does an https post ## // [extra parameter added to library by AD] $isProduction = $this->_profile['mode'] == 'live'; $mpgHttpPost = new mpgHttpsPost($this->_profile['storeid'], $this->_profile['apitoken'], $mpgRequest, $isProduction); ## get an mpgResponse object ## $mpgResponse = $mpgHttpPost->getMpgResponse(); $params['trxn_result_code'] = $mpgResponse->getResponseCode(); if (CRM_Contribute_Payment_Moneris::isError($mpgResponse)) { return CRM_Contribute_Payment_Moneris::error($mpgResponse); } /* Check for application errors */ $result =& CRM_Contribute_Payment_Moneris::checkResult($mpgResponse); if (is_a($result, 'CRM_Core_Error')) { return $result; } /* Success */ $params['trxn_result_code'] = (int) $mpgResponse->getResponseCode(); // todo: above assignment seems to be ignored, not getting stored in the civicrm_financial_trxn table $params['trxn_id'] = $mpgResponse->getTxnNumber(); $params['gross_amount'] = $mpgResponse->getTransAmount(); return $params; }
function moneris_refund($params) { $txnArray = array("type" => "ind_refund", "crypt_type" => 7); $store_id = $params['testmode'] ? "store1" : $params['store_id']; $api_token = $params['testmode'] ? "yesguy" : $params['api_token']; $test_mode = $params['testmode'] ? true : false; $txnArray['order_id'] = sprintf($params['order_id_format'], uniqid($params['invoiceid'] . ".")); $txnArray['cust_id'] = $params['clientdetails']['email']; $txnArray['amount'] = $params['amount']; $txnArray['pan'] = $params['cardnum']; $txnArray['expdate'] = substr($params['cardexp'], 2, 2) . substr($params['cardexp'], 0, 2); $mpgTxn = new mpgTransaction($txnArray); $mpgRequest = new mpgRequest($mpgTxn); $mpgHttpPost = new mpgHttpsPost($store_id, $api_token, $mpgRequest, $test_mode); $mpgResponse = $mpgHttpPost->getMpgResponse(); $m_result = array("CardType" => $mpgResponse->getCardType(), "TransAmount" => $mpgResponse->getTransAmount(), "TxnNumber" => $mpgResponse->getTxnNumber(), "ReceiptId" => $mpgResponse->getReceiptId(), "TransType" => $mpgResponse->getTransType(), "ReferenceNum" => $mpgResponse->getReferenceNum(), "ResponseCode" => $mpgResponse->getResponseCode(), "ISO" => $mpgResponse->getISO(), "Message" => $mpgResponse->getMessage(), "AuthCode" => $mpgResponse->getAuthCode(), "Complete" => $mpgResponse->getComplete(), "TransDate" => $mpgResponse->getTransDate(), "TransTime" => $mpgResponse->getTransTime(), "Ticket" => $mpgResponse->getTicket(), "TimedOut" => $mpgResponse->getTimedOut()); $responseCode = "null" == $mpgResponse->getResponseCode() ? null : intval($mpgResponse->getResponseCode()); if (null === $responseCode) { $result = array("status" => "error", "rawdata" => $m_result); } else { if (0 <= $responseCode && $responseCode < 50) { $result = array("status" => "success", "transid" => $m_result['TxnNumber'], "rawdata" => $m_result); } else { $result = array("status" => "declined", "rawdata" => $m_result); } } return $result; }
/** * Receive a moneris transaction object and send it to the moneris webservice * * @var mpgTransaction $transaction */ public function _send(mpgTransaction $transaction) { $store_id = $this->getConfigData('store_id'); $api_token = $this->getConfigData('api_token'); $request = new mpgRequest($transaction); $mpgHttpsPost = new mpgHttpsPost($store_id, $api_token, $request); return $mpgHttpsPost->getMpgResponse(); }
function mondca_process_payment($purchase_data) { global $edd_options; // check there is a gateway name if (!isset($purchase_data['post_data']['edd-gateway'])) { return; } // collect payment data $payment_data = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => edd_get_currency(), 'downloads' => $purchase_data['downloads'], 'user_info' => $purchase_data['user_info'], 'cart_details' => $purchase_data['cart_details'], 'gateway' => 'mondca', 'status' => 'pending'); if (!mondca_is_credit_card_number($purchase_data['post_data']['card_number'])) { edd_set_error('invalid_card_number', __('Credit Card Number is not valid.', 'mondca_patsatech')); } if (!mondca_is_correct_expire_date(date("y", strtotime($purchase_data['post_data']['card_exp_month'])), $purchase_data['post_data']['card_exp_year'])) { edd_set_error('invalid_card_expiry', __('Card Expire Date is not valid.', 'mondca_patsatech')); } if (!$purchase_data['post_data']['card_cvc']) { edd_set_error('invalid_card_cvc', __('Card CVV is not entered.', 'mondca_patsatech')); } if (!$purchase_data['post_data']['card_name']) { edd_set_error('invalid_card_name', __('CardHolder Name is not entered.', 'mondca_patsatech')); } if (!$purchase_data['post_data']['card_address']) { edd_set_error('invalid_card_address', __('Billing Address is not entered.', 'mondca_patsatech')); } if (!$purchase_data['post_data']['card_zip']) { edd_set_error('invalid_card_zip', __('Post Code is not entered.', 'mondca_patsatech')); } if (!$purchase_data['post_data']['card_state']) { edd_set_error('invalid_card_state', __('State is not entered.', 'mondca_patsatech')); } if (!$purchase_data['post_data']['card_city']) { edd_set_error('invalid_card_city', __('City is not entered.', 'mondca_patsatech')); } if (!$purchase_data['post_data']['edd_first']) { edd_set_error('invalid_edd_first', __('First Name is not entered.', 'mondca_patsatech')); } if (!$purchase_data['post_data']['edd_last']) { edd_set_error('invalid_edd_last', __('Last Name is not entered.', 'mondca_patsatech')); } $errors = edd_get_errors(); if ($errors) { // problems? send back edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']); } else { // record the pending payment $payment = edd_insert_payment($payment_data); // check payment if (!$payment) { // problems? send back edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']); } else { $store_id = $edd_options['mondca_storeid']; $api_token = $edd_options['mondca_apitoken']; $type = 'purchase'; //$cust_id = $order->order_key; $amount = number_format($purchase_data['price'], 2, '.', ''); $pan = $purchase_data['post_data']['card_number']; $cavv = $purchase_data['post_data']['card_cvc']; $expiry_date = substr($purchase_data['post_data']['card_exp_year'], -2) . sprintf("%02s", $purchase_data['post_data']['card_exp_month']); $crypt = '7'; $status_check = 'false'; $stamp = date("YdmHisB"); $orderid = $stamp . '|' . $payment; /***************** Transactional Associative Array ********************/ //$arr=explode("|",$teststring); $txnArray = array('type' => $type, 'order_id' => $orderid, 'cust_id' => '', 'amount' => $amount, 'pan' => $pan, 'expdate' => $expiry_date, 'cavv' => $cavv); /********************** Transaction Object ****************************/ $mpgTxn = new mpgTransaction($txnArray); /************************ Request Object ******************************/ $mpgRequest = new mpgRequest($mpgTxn); /*********************** HTTPSPost Object ****************************/ $mpgHttpPost = new mpgHttpsPost($store_id, $api_token, $mpgRequest); /*************************** Response *********************************/ $mpgResponse = $mpgHttpPost->getMpgResponse(); $txnno = $mpgResponse->getTxnNumber(); $receipt = explode("|", $mpgResponse->getReceiptId()); $respcode = $mpgResponse->getResponseCode(); $refnum = $mpgResponse->getReferenceNum(); $auth = $mpgResponse->getAuthCode(); $mess = $mpgResponse->getMessage(); if ($respcode < '50' && $respcode > '0') { edd_update_payment_status($payment, 'publish'); edd_insert_payment_note($payment, sprintf(__('Moneris CA Payment %s. The Transaction Id is %s', 'mondca_patsatech'), $mess, $txnno)); edd_empty_cart(); edd_send_to_success_page(); } else { edd_insert_payment_note($payment, sprintf(__('Transaction Error. Message : %s', 'mondca_patsatech'), $mess)); edd_set_error('error_tranasction_failed', sprintf(__('Transaction Error. Message : %s', 'mondca_patsatech'), $mess)); edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']); } } } }
function purchase($customerID, $orderID, $amount, $ccNum, $ccDate) { /************************* Transactional Variables ****************************/ $type = CreditCardProcessor::TRANSACTION_TYPE_PURCHASE; // $cust_id='CUST13343'; // $order_id='ord-'.date("dmy-G:i:s"); // $amount='10.68'; // $pan='4242424242424242'; // $expiry_date='0812'; //YYMM -- yes, it is opposite to what is shown on card... $crypt = CreditCardProcessor::CRYPT_SSL; /*********************** Transactional Associative Array **********************/ $txnArray = array('type' => $type, 'order_id' => $orderID, 'cust_id' => $customerID, 'amount' => $amount, 'pan' => $ccNum, 'expdate' => $ccDate, 'crypt_type' => $crypt); // echo "<br>Trans. Array: <pre>".print_r($txnArray,true)."</pre>"; // echo "<br>store id = ".$this->store_id; // echo "<br>api token = ".$this->api_token; /**************************** Transaction Object *****************************/ $mpgTxn = new mpgTransaction($txnArray); /****************************** Request Object *******************************/ $mpgRequest = new mpgRequest($mpgTxn); /***************************** HTTPS Post Object *****************************/ $mpgHttpPost = new mpgHttpsPost($this->store_id, $this->api_token, $mpgRequest); /******************************* Response ************************************/ $mpgResponse = $mpgHttpPost->getMpgResponse(); // print("\nCardType = " . $mpgResponse->getCardType()); // print("\nTransAmount = " . $mpgResponse->getTransAmount()); // print("\nTxnNumber = " . $mpgResponse->getTxnNumber()); // print("\nReceiptId = " . $mpgResponse->getReceiptId()); // print("\nTransType = " . $mpgResponse->getTransType()); // print("\nReferenceNum = " . $mpgResponse->getReferenceNum()); // print("\nResponseCode = " . $mpgResponse->getResponseCode()); // print("\nISO = " . $mpgResponse->getISO()); // print("\nMessage = " . $mpgResponse->getMessage()); // print("\nAuthCode = " . $mpgResponse->getAuthCode()); // print("\nComplete = " . $mpgResponse->getComplete()); // print("\nTransDate = " . $mpgResponse->getTransDate()); // print("\nTransTime = " . $mpgResponse->getTransTime()); // print("\nTicket = " . $mpgResponse->getTicket()); // print("\nTimedOut = " . $mpgResponse->getTimedOut()); return $mpgResponse; }