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; }
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; }
/** * * @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; }
$mpgCustInfo->setBilling($billing); $shipping = array('first_name' => $first_name, 'last_name' => $last_name, 'company_name' => $company_name, 'address' => $address, 'city' => $city, 'province' => $province, 'postal_code' => $postal_code, 'country' => $country, 'phone_number' => $phone_number, 'fax' => $fax, 'tax1' => $tax1, 'tax2' => $tax2, 'tax3' => $tax3, 'shipping_cost' => $shipping_cost); $mpgCustInfo->setShipping($shipping); $mpgCustInfo->setEmail($email); $mpgCustInfo->setInstructions($instructions); /*********************** Set Line Item Information *********************/ $item[0] = array('name' => $item_name[0], 'quantity' => $item_quantity[0], 'product_code' => $item_product_code[0], 'extended_amount' => $item_extended_amount[0]); $item[1] = array('name' => $item_name[1], 'quantity' => $item_quantity[1], 'product_code' => $item_product_code[1], 'extended_amount' => $item_extended_amount[1]); $mpgCustInfo->setItems($item[0]); $mpgCustInfo->setItems($item[1]); /***************** Transactional Associative Array ********************/ $txnArray = array('type' => $type, 'order_id' => $order_id, 'cust_id' => $cust_id, 'amount' => $amount, 'pan' => $pan, 'expdate' => $expiry_date, 'crypt_type' => $crypt); /********************** Transaction Object ****************************/ $mpgTxn = new mpgTransaction($txnArray); /******************** Set Customer Information ************************/ $mpgTxn->setCustInfo($mpgCustInfo); /************************* Request Object *****************************/ $mpgRequest = new mpgRequest($mpgTxn); /************************ HTTPS Post Object ***************************/ $mpgHttpPost = new mpgHttpsPost($store_id, $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();