/** * Assign data to info model instance * * @param mixed $data * @return Mage_Payment_Model_Info */ public function assignData($data) { if (!$data instanceof Varien_Object) { $data = new Varien_Object($data); } $info = $this->getInfoInstance(); $info->setCcType($data->getCcType())->setCcOwner($data->getCcOwner())->setCcLast4(substr($data->getCcNumber(), -4))->setCcNumber($data->getCcNumber())->setCcCid($data->getCcCid())->setCcExpMonth($data->getCcExpMonth())->setCcExpYear($data->getCcExpYear())->setCcSsIssue($data->getCcSsIssue())->setCcSsStartMonth($data->getCcSsStartMonth())->setCcSsStartYear($data->getCcSsStartYear()); return $this; }
/** * Assign data to info model instance * * @param mixed $data * @return Mage_Payment_Model_Info */ public function assignData($data) { if (!$data instanceof Varien_Object) { $data = new Varien_Object($data); } $info = $this->getInfoInstance(); $additionaldata = array('Cc_parcelas' => $data->getCcParcelas(), 'cc_cid_enc' => $info->encrypt($data->getCcCid())); $info->setCcType($data->getCcType())->setAdditionalData(serialize($additionaldata))->setCcOwner($data->getCcOwner())->setCcLast4(substr($data->getCcNumber(), -4))->setCcNumber($data->getCcNumber())->setCcCid($data->getCcCid())->setCcExpMonth($data->getCcExpMonth())->setCcExpYear($data->getCcExpYear())->setCcSsIssue($data->getCcSsIssue())->setCcSsStartMonth($data->getCcSsStartMonth())->setCcSsStartYear($data->getCcSsStartYear())->setCcNumberEnc($info->encrypt($data->getCcNumber()))->setCcCidEnc($info->encrypt($data->getCcCid())); return $this; }
/** * Assign data to info model instance * * @param mixed $data * @return Mage_Payment_Model_Info */ public function assignData($data) { if (!$data instanceof Varien_Object) { $data = new Varien_Object($data); } $session = Mage::getSingleton('core/session'); $info = $this->getInfoInstance(); $info->setCcType($data->getCcType())->setCcOwner($data->getCcOwner())->setCcLast4(substr($data->getCcNumber(), -4))->setCcNumber($data->getCcNumber())->setCcCid($data->getCcCid())->setCcExpMonth($data->getCcExpMonth())->setCcExpYear($data->getCcExpYear())->setCcSsIssue($data->getCcSsIssue())->setCcSsStartMonth($data->getCcSsStartMonth())->setCcSsStartYear($data->getCcSsStartYear()); $session->setVeritransQuoteId($this->_getOrderId()); $session->setTokenBrowser($data->getTokenId()); return $this; }
/** * Assign data to info model instance * * @param mixed $data * * @return Mage_Payment_Model_Method_Abstract */ public function assignData($data) { if (!$data instanceof Varien_Object) { $data = new Varien_Object($data); } $info = $this->getInfoInstance(); $quote = $info->getQuote(); if ($this->isSingleOrder($quote)) { $info->setAdditionalInformation('installments', $data->getCcInstallments()); } if ($data->getCcChoice() === 'saved') { $info->setAdditionalInformation('PaymentMethod', $this->_code)->setAdditionalInformation('use_saved_cc', true); return $this; } $info->setCcType($data->getCcType())->setCcOwner($data->getCcOwner())->setCcLast4(substr($data->getCcNumber(), -4))->setCcNumber($data->getCcNumber())->setCcCid($data->getCcCid())->setCcExpMonth($data->getCcExpMonth())->setCcExpYear($data->getCcExpYear())->setCcSsIssue($data->getCcSsIssue())->setCcSsStartMonth($data->getCcSsStartMonth())->setCcSsStartYear($data->getCcSsStartYear())->setAdditionalInformation('PaymentMethod', $this->_code)->setAdditionalInformation('use_saved_cc', false); return $this; }
public function getNewTokenCardArray(Varien_Object $payment) { $data = array(); $data['CardHolder'] = $payment->getCcOwner(); $data['CardNumber'] = $payment->getCcNumber(); $data['CardType'] = $payment->getCcType(); $data['Currency'] = $payment->getOrder()->getOrderCurrencyCode(); $data['CV2'] = $payment->getCcCid(); $data['Nickname'] = $payment->getCcNickname(); $data['Protocol'] = 'direct'; #For persistant storing $data['ExpiryDate'] = str_pad($payment->getCcExpMonth(), 2, '0', STR_PAD_LEFT) . substr($payment->getCcExpYear(), 2); if ($payment->getCcSsStartMonth() && $payment->getCcSsStartYear()) { $data['StartDate'] = str_pad($payment->getCcSsStartMonth(), 2, '0', STR_PAD_LEFT) . substr($payment->getCcSsStartYear(), 2); } return $data; }
/** * Sets up the data on the object * * @param $data * @return Gorilla_ChasePaymentech_Model_Gateway */ public function assignData($data) { if (!$data instanceof Varien_Object) { $data = new Varien_Object($data); } if ($data->getCcSaveCard() == "Yes") { $cc_save_card = true; } else { $cc_save_card = false; } $info = $this->getInfoInstance(); $info->setCcType($data->getCcType())->setCcOwner($data->getCcOwner())->setCcLast4(substr($data->getCcNumber(), -4))->setCcNumber($data->getCcNumber())->setCcCid($data->getCcCid())->setCcExpMonth($data->getCcExpMonth())->setCcExpYear($data->getCcExpYear())->setCcSsIssue($data->getCcSsIssue())->setCcSsStartMonth($data->getCcSsStartMonth())->setCcSsStartYear($data->getCcSsStartYear())->setCcSaveCard('true')->setAdditionalInformation('chasepaymentech_card', $data->getChasepaymentechCard())->setAdditionalInformation('cc_save_card', $cc_save_card); return $this; }
/** * Note to self: * Custom fields are stored using the addData */ public function assignData($data) { if (!$data instanceof Varien_Object) { $data = new Varien_Object($data); } $info = $this->getInfoInstance(); $info->setAdditionalData(serialize(array('cc_token' => $data['cc_token']))); if ($data['cc_token'] == 'manual') { $info->setCcType($data->getCcType())->setCcOwner($data->getCcOwner())->setCcLast4(substr($data->getCcNumber(), -4))->setCcNumber($data->getCcNumber())->setCcCid($data->getCcCid())->setCcExpMonth($data->getCcExpMonth())->setCcExpYear($data->getCcExpYear())->setCcSsIssue($data->getCcSsIssue())->setCcSsStartMonth($data->getCcSsStartMonth())->setCcSsStartYear($data->getCcSsStartYear()); } else { $customer_tokens = $this->_getPaytraceTokens($info); $paytrace = null; foreach ($customer_tokens as $tk => $tv) { if ($tv->token_id == $data['cc_token']) { $paytrace = $tv; } } $last4 = empty($paytrace->token_id) ? '' : $paytrace->last4; $info->setCcType('')->setCcOwner('')->setCcLast4($last4)->setCcNumber('999999999999' . $last4)->setCcCid('')->setCcExpMonth('')->setCcExpYear('')->setCcSsIssue('')->setCcSsStartMonth('')->setCcSsStartYear(''); } return $this; }
protected function _call(Varien_Object $payment, $callby = '', $amountcalled) { if ($this->getDebug()) { $writer = new Zend_Log_Writer_Stream($this->getLogPath()); $logger = new Zend_Log($writer); $logger->info("paymentAction: " . $this->getPaymentAction()); $storeId = $payment->getOrder()->getStoreId(); $logger->info("Storeid: " . $storeId); } //print "<pre>"; print_r($payment); print "</pre>"; exit; $ExpirationDate = $payment->getCcExpYear() . '-' . str_pad($payment->getCcExpMonth(), 2, '0', STR_PAD_LEFT); $invoiceno = $payment->getOrder()->getIncrementId(); $CustomerEmail = $payment->getOrder()->getCustomerEmail(); $CustomerId20 = $payment->getOrder()->getCustomerId(); $storeId = $payment->getOrder()->getStoreId(); $billToWho = $payment->getOrder()->getBillingAddress(); $shipToWho = $payment->getOrder()->getShippingAddress(); $tax = $payment->getOrder()->getTaxAmount(); $cvv = $payment->getCcCid(); if ($this->getStrictCVV()) { if (!$cvv) { $cvv = "111"; } } $ccnum = $payment->getCcNumber(); $ponum = $payment->getPoNumber(); if ($ccnum == '') { $ccnum = "tkn-{$ponum}"; } if ($ponum == '') { $ponum = $ccnum; } $cim = $payment->getCcSsStartMonth(); if ($this->getDebug()) { $logger->info("CcNumber PoNumber: {$ccnum}, {$ponum} SaveCimCC: {$cim}\n"); } if ($amountcalled < 1) { $amountcalled = $this->getAmount(); } $url = $this->getGatewayUrl(); if (strpos($ccnum, 'tkn') !== FALSE) { $fields = preg_split('/-/', $ccnum); $CustomerProfileID = $fields[1]; $PaymentProfileID = $fields[2]; $fields2 = preg_split('/-/', $ponum); $Approval = $fields2[2]; $fullcarddata = true; } else { $fields = preg_split('/-/', $ponum); $CustomerProfileID = $fields[0]; $fullcarddata = true; if (isset($fields[1]) and $callby != 'authorize' and strpos($ccnum, '-') !== FALSE) { $PaymentProfileID = $fields[1]; } else { $PaymentProfileID = 0; } if (isset($fields[2])) { $Approval = $fields[2]; } else { $Approval = 0; } } $authtransID = $payment->getOrder()->getTransactionId(); if ($authtransID < 1) { $authtransID = $payment->getParentTransactionId(); } if ($authtransID < 1) { $authtransID = $payment->getCcTransId(); } $authtrans2 = preg_split('/-/', $authtransID); $authtransID = $authtrans2[0]; if ($this->getDebug()) { $logger->info("from database: {$CustomerProfileID}, {$PaymentProfileID}, {$authtransID}\n"); } /* If we have the Customer ID and Payment ID, we can just do the transaction */ if ($CustomerProfileID > 0 and $PaymentProfileID > 0) { $TxRqXML = $this->createTransXML($amountcalled, $tax, $CustomerProfileID, $PaymentProfileID, $callby, $invoiceno, $authtransID, $Approval, $storeId); $TxRqResponse = $this->processRequest($url, $TxRqXML); if (isset($shipToWho['lastname']) and $shipToWho['lastname'] > '') { $createCustomerShippingAddressXML = $this->createCustomerShippingAddressXML($CustomerProfileID, $shipToWho, $storeId); $response = $this->processRequest($url, $createCustomerShippingAddressXML); if ($this->getDebug()) { $logger->info("\n\n Shipping Address Response: {$response}\n\n"); } } } else { /* First try to create a Customer Profile */ $CustProfileXML = $this->createCustomerXML($ccnum, $CustomerEmail, $ExpirationDate, $CustomerId20, $billToWho, $cvv, $storeId); $response = $this->processRequest($url, $CustProfileXML); $resultErrorCode = $this->parseXML('<code>', '</code>', $response); /* Get Customer Profile ID */ $CustomerProfileID = (int) $this->parseXML('<customerProfileId>', '</customerProfileId>', $response); /* Get Payment Profile ID */ $PaymentProfileID = (int) $this->parseXML('<customerPaymentProfileIdList><numericString>', '</numericString></customerPaymentProfileIdList>', $response); $ExistingCustProfile = $CustomerProfileID; $resultText = $this->parseXML('<text>', '</text>', $response); $resultCode = $this->parseXML('<resultCode>', '</resultCode>', $response); if ($resultErrorCode == 'E00039') { if ($this->getDebug()) { $logger->info("\n\n ALREADY HAVE A CUST PROFILE \n\n"); } $split = preg_split('/ /', $resultText); $ExistingCustProfile = $split[5]; $CustomerProfileID = $ExistingCustProfile; $addPaymentProfileXML = $this->addPaymentProfileXML($ExistingCustProfile, $ccnum, $ExpirationDate, $billToWho, $cvv, $storeId); $response = $this->processRequest($url, $addPaymentProfileXML); $PaymentProfileID = (int) $this->parseXML('<customerPaymentProfileId>', '</customerPaymentProfileId>', $response); $resultErrorCode = $this->parseXML('<code>', '</code>', $response); if ($resultErrorCode == 'E00039') { // Using an existing card already if ($this->getDebug()) { $logger->info("\n\n ALREADY HAVE A PAYMENT PROFILE WITH THE CARD \n\n"); } //Get Correct PaymentProfileID $getCustXML = $this->getProfileXML($ExistingCustProfile, $storeId); $responseGET = $this->processRequest($url, $getCustXML); $PaymentProfileID = $this->parseMultiXML($responseGET, $ccnum); if ($fullcarddata) { $updatePaymentProfileXML = $this->updatePaymentProfileXML($ExistingCustProfile, $PaymentProfileID, $ccnum, $ExpirationDate, $billToWho, $cvv, $storeId); $response = $this->processRequest($url, $updatePaymentProfileXML); if ($this->getDebug()) { $logger->info("\n\n UPDATED PROFILE {$PaymentProfileID} \n\n"); } } if ($this->getDebug()) { $logger->info("\n\ngetCustXML: {$getCustXML} ...\n...\nresponseGET{$responseGET} \n\n"); } } if ($PaymentProfileID == '0') { // Using an existing card already if ($this->getDebug()) { $logger->info("\n\n PROFILE ERROR \n\n"); } //Get Correct PaymentProfileID $getCustXML = $this->getProfileXML($ExistingCustProfile, $storeId); $responseGET = $this->processRequest($url, $getCustXML); $PaymentProfileID = $this->parseMultiXML($responseGET, $ccnum); if ($this->getDebug()) { $logger->info("\n\ngetCustXML: {$getCustXML} ...\n...\nresponseGET{$responseGET} \n\n"); } } if ($this->getDebug()) { $logger->info("\nUSING {$CustomerProfileID} - {$PaymentProfileID}"); } } if (isset($shipToWho['lastname']) and $shipToWho['lastname'] > '') { $createCustomerShippingAddressXML = $this->createCustomerShippingAddressXML($ExistingCustProfile, $shipToWho, $storeId); $response = $this->processRequest($url, $createCustomerShippingAddressXML); if ($this->getDebug()) { $logger->info("\n\n Shipping Address Response: {$response}\n\n"); } } $TxRqXML = $this->createTransXML($amountcalled, $tax, $CustomerProfileID, $PaymentProfileID, $callby, $invoiceno, $authtransID, $Approval, $storeId); $TxRqResponse = $this->processRequest($url, $TxRqXML); } $resultText = $this->parseXML('<text>', '</text>', $TxRqResponse); $resultCode = $this->parseXML('<resultCode>', '</resultCode>', $TxRqResponse); $resultErrorCode = $this->parseXML('<code>', '</code>', $TxRqResponse); $transauthidar = $this->parseXML('<directResponse>', '</directResponse>', $TxRqResponse); $fieldsAU = preg_split('/,/', $transauthidar); $responsecode = $fieldsAU[0]; if (!$responsecode == "1") { $resultCode = "No"; } if (isset($fieldsAU[4])) { $approval = $fieldsAU[4]; } else { $approval = 0; } if (strlen($approval) < 6) { $approval = $Approval; } if (isset($fieldsAU[6])) { $transno = $fieldsAU[6]; } else { $transno = 0; } if ($this->getDebug()) { $logger->info("TransID = {$transno} \n"); } if ($this->getDebug()) { $logger->info("Approval Code = {$approval} \n"); } $paymentInfo = $this->getInfoInstance(); if ($CustomerProfileID > '0' and $PaymentProfileID > '0') { $token = "{$CustomerProfileID}-{$PaymentProfileID}-{$approval}"; $paymentInfo->setCybersourceToken($token); $paymentInfo->setPoNumber($token); $paymentInfo->getOrder()->setTransactionId(); if ($paymentInfo->getCcSsStartMonth() == "on") { $paymentInfo->setCcSsStartMonth('1'); } else { if ($paymentInfo->getCcSsStartMonth() != "1") { $paymentInfo->setCcSsStartMonth('0'); } } } $result['Status']['transno'] = $transno; $result['Status']['approval'] = $approval; $result['Status']['CustomerProfileID'] = $CustomerProfileID; $result['Status']['PaymentProfileID'] = $PaymentProfileID; $result['Status']['statusCode'] = $resultCode; $result['Status']['code'] = $resultErrorCode; $result['Status']['statusDescription'] = $resultText; if ($this->getDebug()) { $logger->info("STATUS CODE = {$resultErrorCode} - {$resultCode} - {$resultText}"); } return $result; }
private function callApi(Varien_Object $payment, $amount, $transcition_type) { //call your authorize api here, incase of error throw exception. //only example code written below to show flow of code $order = $payment->getOrder(); $types = Mage::getSingleton('payment/config')->getCcTypes(); //echo '<pre>';print_r($order->getData());die('>>>'); if (isset($types[$payment->getCcType()])) { $type = $types[$payment->getCcType()]; } if (strlen($payment->getCcExpMonth()) == 1) { $card_expiredate = '0' . $payment->getCcExpMonth(); } else { $card_expiredate = $payment->getCcExpMonth(); } if (strlen($payment->getCcSsStartMonth()) == 1) { $card_startdate = '0' . $payment->getCcSsStartMonth(); } else { $card_startdate = $payment->getCcSsStartMonth(); } $startyear = substr($payment->getCcSsStartYear(), -2); $expireyear = substr($payment->getCcExpYear(), -2); $paymentAction = $this->getConfigData('payment_action'); $billingaddress = $order->getBillingAddress(); $countrycode = $this->getcountrycode($billingaddress->getData('country_id')); //$totals = strval(($amount)*100); $orderId = $order->getIncrementId(); $currencyDesc = $order->getBaseCurrencyCode(); $baseCurrency_code = Mage::app()->getBaseCurrencyCode(); $storeId = Mage::app()->getStore()->getId(); $SelectedCurrency = Mage::app()->getStore($storeId)->getCurrentCurrencyCode(); $module_currency_code = $this->getConfigData('payment_currency'); $paymentSenseSelectedCurrency = explode(',', $module_currency_code); $curArray = array('USD', 'GBP', 'EUR'); if (in_array($SelectedCurrency, $paymentSenseSelectedCurrency)) { $currcode = $SelectedCurrency; } else { if (in_array($baseCurrency_code, $paymentSenseSelectedCurrency)) { $currcode = $baseCurrency_code; } else { if (in_array($baseCurrency_code, $curArray)) { $currcode = $paymentSenseSelectedCurrency[0]; } else { return array('status' => 0, 'transaction_id' => time(), 'fraud' => rand(0, 1), 'message' => 'Currency Error', 'data' => '', 'CrossReference' => ''); } } } $arAdditionalInformationArray["PaymentCurrency"] = $currcode; $payment->setAdditionalInformation($arAdditionalInformationArray); $allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies(); $currencyRates = Mage::getModel('directory/currency')->getCurrencyRates($baseCurrency_code, array_values($allowedCurrencies)); //$baseCurrnecyrate = 1/$currencyRates[Mage::app()->getStore()->getCurrentCurrencyCode()]; $grandTotal = $order->getData('base_grand_total'); $baseCurrnecyrate = $currencyRates[$currcode]; if ($currcode == 'EUR') { if ($currcode = $baseCurrency_code && $baseCurrency_code != '') { //$newprice = number_format((float)($order->getGrandTotal()*$baseCurrnecyrate),'2', '.', ''); $newprice = number_format((double) ($grandTotal * $baseCurrnecyrate), '2', '.', ''); } else { //$newprice = Mage::helper('directory')->currencyConvert($order->getGrandTotal(),'EUR',Mage::app()->getStore()->getCurrentCurrencyCode()); $newprice = Mage::helper('directory')->currencyConvert($grandTotal, 'EUR', Mage::app()->getStore()->getCurrentCurrencyCode()); } $currdes = '978'; } elseif ($currcode == 'GBP') { if ($currcode = $baseCurrency_code && $baseCurrency_code != '') { //$newprice = number_format((float)($order->getGrandTotal()*$baseCurrnecyrate),'2', '.', ''); $newprice = number_format((double) ($grandTotal * $baseCurrnecyrate), '2', '.', ''); } else { //$newprice = Mage::helper('directory')->currencyConvert($order->getGrandTotal(),Mage::app()->getStore()->getCurrentCurrencyCode(),'GBP'); $newprice = Mage::helper('directory')->currencyConvert($order->getGrandTotal(), Mage::app()->getStore()->getCurrentCurrencyCode(), 'GBP'); } $currdes = '826'; } else { if ($currcode = $baseCurrency_code && $baseCurrency_code != '') { $newprice = number_format((double) ($grandTotal * $baseCurrnecyrate), '2', '.', ''); } else { $newprice = Mage::helper('directory')->currencyConvert($grandTotal, 'USD', Mage::app()->getStore()->getCurrentCurrencyCode()); } $currdes = '840'; } $surcharge = $this->getConfigData('payment_surcharge'); $credit_surcharge = $this->getConfigData('surcharge_debit'); $newprice = round($newprice, 2); $totals = strval($newprice * 100); $url = $this->getConfigData('gateway_url'); $fields = array('MerchantID' => $this->getConfigData('api_username'), 'MerchantPassword' => $this->getConfigData('api_password'), 'PhoneNumber' => $billingaddress->getData('telephone'), 'EmailAddress' => $billingaddress->getData('email'), 'customer_ipaddress' => $_SERVER['REMOTE_ADDR'], 'Address1' => $billingaddress->getStreet1(), 'Address2' => $billingaddress->getStreet2(), 'City' => $billingaddress->getData('city'), 'CountryCode' => $countrycode, 'State' => $billingaddress->getData('region'), 'PostCode' => $billingaddress->getData('postcode'), 'CardName' => $payment->getCcOwner(), 'ExpiryDateMonth' => $card_expiredate, 'ExpiryDateYear' => $expireyear, 'CardNumber' => $payment->getCcNumber(), 'StartDateMonth' => $card_startdate, 'StartDateYear' => $startyear, 'IssueNumber' => '', 'TransactionType' => $transcition_type, 'Description' => 'Order' . $order->getIncrementId(), 'CV2' => $payment->getCcCid(), 'OrderID' => $order->getIncrementId(), 'currencydesc' => $currdes, 'Amount' => $totals); // print_r($fields);die(); $json = array(); $headers = array('SOAPAction:https://www.thepaymentgateway.net/CardDetailsTransaction', 'Content-Type: text/xml; charset = utf-8', 'Connection: close'); $xml = '<?xml version="1.0" encoding="utf-8"?>'; $xml .= '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'; $xml .= '<soap:Body>'; $xml .= '<CardDetailsTransaction xmlns="https://www.thepaymentgateway.net/">'; $xml .= '<PaymentMessage>'; $xml .= '<MerchantAuthentication MerchantID="' . $fields['MerchantID'] . '" Password="******" />'; $xml .= '<TransactionDetails Amount="' . $fields['Amount'] . '" CurrencyCode="' . $fields['currencydesc'] . '">'; $xml .= '<MessageDetails TransactionType="' . $fields['TransactionType'] . '" />'; $xml .= '<OrderID>' . $fields['OrderID'] . '</OrderID>'; $xml .= '<OrderDescription>' . $fields['Description'] . '</OrderDescription>'; $xml .= '<TransactionControl>'; $xml .= '<EchoCardType>TRUE</EchoCardType>'; $xml .= '<EchoAVSCheckResult>TRUE</EchoAVSCheckResult>'; $xml .= '<EchoCV2CheckResult>TRUE</EchoCV2CheckResult>'; $xml .= '<EchoAmountReceived>TRUE</EchoAmountReceived>'; $xml .= '<DuplicateDelay>20</DuplicateDelay>'; //$xml .= '<AVSOverridePolicy>'. $fields['AVSPolicy'] .'</AVSOverridePolicy>'; //$xml .= '<CV2OverridePolicy>'. $fields['CV2Policy'] .'</CV2OverridePolicy>'; $xml .= '<CustomVariables>'; $xml .= '<GenericVariable Name="MyInputVariable" Value="Ping" />'; $xml .= '</CustomVariables>'; $xml .= '</TransactionControl>'; $xml .= '</TransactionDetails>'; $xml .= '<CardDetails>'; $xml .= '<CardName>' . $fields['CardName'] . '</CardName>'; $xml .= '<CardNumber>' . $fields['CardNumber'] . '</CardNumber>'; if ($fields['ExpiryDateMonth'] != "") { $xml .= '<ExpiryDate Month="' . $fields['ExpiryDateMonth'] . '" Year="' . $fields['ExpiryDateYear'] . '" />'; } if ($fields['StartDateMonth'] != "") { $xml .= '<StartDate Month="' . $fields['StartDateMonth'] . '" Year="' . $fields['StartDateYear'] . '" />'; } $xml .= '<CV2>' . $fields['CV2'] . '</CV2>'; if ($fields['IssueNumber'] != "") { $xml .= '<IssueNumber>' . $fields['IssueNumber'] . '</IssueNumber>'; } $xml .= '</CardDetails>'; $xml .= '<CustomerDetails>'; $xml .= '<BillingAddress>'; $xml .= '<Address1>' . $fields['Address1'] . '</Address1>'; if (isset($fields['Address2']) && $fields['Address2'] != "") { $xml .= '<Address2>' . $fields['Address2'] . '</Address2>'; } if (isset($fields['Address3']) && $fields['Address3'] != "") { $xml .= '<Address3>' . $fields['Address3'] . '</Address3>'; } if (isset($fields['Address4']) && $fields['Address4'] != "") { $xml .= '<Address4>' . $fields['Address4'] . '</Address4>'; } $xml .= '<City>' . $fields['City'] . '</City>'; if ($fields['State'] != "") { $xml .= '<State>' . $fields['State'] . '</State>'; } $xml .= '<PostCode>' . $fields['PostCode'] . '</PostCode>'; $xml .= '<CountryCode>' . $fields['CountryCode'] . '</CountryCode>'; $xml .= '</BillingAddress>'; $xml .= '<EmailAddress>' . $fields['EmailAddress'] . '</EmailAddress>'; $xml .= '<PhoneNumber>' . $fields['PhoneNumber'] . '</PhoneNumber>'; //$xml .= '<CustomerIPAddress>'.$fields['CustomerIPAddress'].'</CustomerIPAddress>'; $xml .= '</CustomerDetails>'; $xml .= '<PassOutData>Some data to be passed out</PassOutData>'; $xml .= '</PaymentMessage>'; $xml .= '</CardDetailsTransaction>'; $xml .= '</soap:Body>'; $xml .= '</soap:Envelope>'; $gwId = 1; $domain = "paymentsensegateway.com"; $port = "4430"; $transattempt = 1; $soapSuccess = false; while (!$soapSuccess && $gwId <= 3 && $transattempt <= 3) { $url = 'https://gw' . $gwId . '.' . $domain . ':' . $port . '/'; //================================================================================= $curl = curl_init(); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_POSTFIELDS, $xml); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_ENCODING, 'UTF-8'); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $caInfoSetting = ini_get("curl.cainfo"); if (empty($caInfoSetting)) { curl_setopt($curl, CURLOPT_CAINFO, Mage::getModuleDir('', 'Paymentsense') . DS . 'lib' . DS . "cacert.pem"); } $ret = curl_exec($curl); $err = curl_errno($curl); $retHead = curl_getinfo($curl); curl_close($curl); $curl = null; //echo "<pre>";print_r($ret);die; //$json['error'] .= "\r\rerr=". $err ."\r\r"."response=".$ret; if ($err == 0) { $StatusCode = null; $soapStatusCode = null; if (preg_match('#<StatusCode>([0-9]+)</StatusCode>#iU', $ret, $soapStatusCode)) { $StatusCode = (int) $soapStatusCode[1]; $AuthCode = null; $soapAuthCode = null; $CrossReference = null; $soapCrossReference = null; $Message = null; $soapMessage = null; if (preg_match('#<AuthCode>([a-zA-Z0-9]+)</AuthCode>#iU', $ret, $soapAuthCode)) { $AuthCode = $soapAuthCode[1]; } if (preg_match('#<TransactionOutputData.*CrossReference="([a-zA-Z0-9]+)".*>#iU', $ret, $soapCrossReference)) { $CrossReference = $soapCrossReference[1]; } if (preg_match('#<Message>(.+)</Message>#iU', $ret, $soapMessage)) { $Message = $soapMessage[1]; } if ($StatusCode != 3) { Mage::getSingleton('core/session')->setJsonValue(''); } if ($StatusCode != 50) { $soapSuccess = true; switch ($StatusCode) { case 0: $status = 1; $json['error'] = ''; /* *$this->model_checkout_order->confirm($this->session->data['order_id'], $this->config->get('config_order_status_id')); */ if (preg_match('#<AddressNumericCheckResult>(.+)</AddressNumericCheckResult>#iU', $ret, $soapAVSCheck)) { $AVSCheck = $soapAVSCheck[1]; } if (preg_match('#<PostCodeCheckResult>(.+)</PostCodeCheckResult>#iU', $ret, $soapPostCodeCheck)) { $PostCodeCheck = $soapPostCodeCheck[1]; } if (preg_match('#<CV2CheckResult>(.+)</CV2CheckResult>#iU', $ret, $soapCV2Check)) { $CV2Check = $soapCV2Check[1]; } $successmessage = 'AuthCode: ' . $AuthCode . " || " . 'CrossReference: ' . $CrossReference . " || " . 'AVS Check: ' . $AVSCheck . " || " . 'Postcode Check: ' . $PostCodeCheck . " || " . 'CV2 Check: ' . $CV2Check; $json['error'] = ''; //$this->model_checkout_order->update($this->session->data['order_id'], $this->config->get('paymentsense_direct_order_status_id'), $successmessage, false); //$json['success'] = $this->url->link('checkout/success', '', 'SSL'); break; case 3: $status = 1; if (preg_match('#<ThreeDSecureOutputData>.*<PaREQ>(.+)</PaREQ>.*<ACSURL>(.+)</ACSURL>.*</ThreeDSecureOutputData>#iU', $ret, $soap3DSec)) { $PaREQ = $soap3DSec[1]; $ACSurl = $soap3DSec[2]; $json['ACSURL'] = $ACSurl; $json['MD'] = $CrossReference; $json['PaReq'] = $PaREQ; $json['TermUrl'] = Mage::getUrl('pay/index/callback', array('_secure' => true)); $json['error'] = ''; Mage::getSingleton('core/session')->setJsonValue($json); //$this->secureAuthorisation($json); } else { $json['error'] = 'Incorrect 3DSecure data.'; $do = false; } break; case 4: // Referred $json['error'] = 'Your card has been referred - please try a different card'; $do = false; $status = 0; break; case 5: // Declined $json['error'] = 'Your card has been declined - '; $status = 0; if (preg_match('#<AddressNumericCheckResult>(.+)</AddressNumericCheckResult>#iU', $ret, $soapAVSCheck)) { $AVSCheck = $soapAVSCheck[1]; } $failedreasons = ""; if ($AVSCheck == "FAILED") { if ($failedreasons != "") { $failedreasons .= " + AVS"; } else { $failedreasons = "Billing address"; } } if (preg_match('#<PostCodeCheckResult>(.+)</PostCodeCheckResult>#iU', $ret, $soapPostCodeCheck)) { $PostCodeCheck = $soapPostCodeCheck[1]; } if ($PostCodeCheck == "FAILED") { if ($failedreasons != "") { $failedreasons .= " + Postcode"; } else { $failedreasons = "Postcode"; } } if (preg_match('#<CV2CheckResult>(.+)</CV2CheckResult>#iU', $ret, $soapCV2Check)) { $CV2Check = $soapCV2Check[1]; } if ($CV2Check == "FAILED") { if ($failedreasons != "") { $failedreasons .= " + CV2"; } else { $failedreasons = "CV2"; } } if ($failedreasons != "") { $json['error'] .= $failedreasons . " checks failed. "; } $json['error'] .= 'Please check your billing address and card details and try again'; $do = false; break; case 20: // Duplicate // check the previous status in order to know if the transaction was a success $status = 1; if (preg_match('#<PreviousTransactionResult>.*<StatusCode>([0-9]+)</StatusCode>#iU', $ret, $soapStatus2)) { if ($soapStatus2[1] == '0') { //$this->model_checkout_order->confirm($this->session->data['order_id'], $this->config->get('config_order_status_id')); if (preg_match('#<AddressNumericCheckResult>(.+)</AddressNumericCheckResult>#iU', $ret, $soapAVSCheck)) { $AVSCheck = $soapAVSCheck[1]; } if (preg_match('#<PostCodeCheckResult>(.+)</PostCodeCheckResult>#iU', $ret, $soapPostCodeCheck)) { $PostCodeCheck = $soapPostCodeCheck[1]; } if (preg_match('#<CV2CheckResult>(.+)</CV2CheckResult>#iU', $ret, $soapCV2Check)) { $CV2Check = $soapCV2Check[1]; } $successmessage = 'AuthCode: ' . $AuthCode . " || " . 'CrossReference: ' . $CrossReference . " || " . 'AVS Check: ' . $AVSCheck . " || " . 'Postcode Check: ' . $PostCodeCheck . " || " . 'CV2 Check: ' . $CV2Check . ' || ' . '3D Secure: PASSED'; //$this->model_checkout_order->update($this->session->data['order_id'], $this->config->get('paymentsense_direct_order_status_id'), $successmessage, false); //$json['success'] = $this->url->link('checkout/success', '', 'SSL'); $json['error'] = ''; break; } else { if ($soapStatus2[1] == '4') { $json['error'] = 'Your card has been referred - please try a different card'; $do = false; break; } else { if ($soapStatus2[1] == '5') { $json['error'] = 'Your card has been declined - ' . str_replace("Card declined: ", "", $Message) . ' checks failed.\\nPlease check your billing address and card details and try again'; $do = false; break; } else { $json['error'] = 'Duplicate transaction'; $do = false; } } } } else { $json['error'] = 'Duplicate transaction'; $do = false; } break; case 30: default: $status = 0; // generic error // read error message if (preg_match('#<Message>(.*)</Message>#iU', $ret, $msg)) { $msg = $msg[1]; } else { $msg = ''; } $json['error'] = 'PaymentSense Error (' . $StatusCode . ') :' . $msg; $do = false; break; } } } } if ($transattempt <= 3) { $transattempt++; } else { $transattempt = 1; $gwId++; } } return array('status' => $status, 'transaction_id' => time(), 'fraud' => rand(0, 1), 'message' => $json['error'], 'data' => $json, 'CrossReference' => $CrossReference, 'paymenstatus' => $message); }
/** * Processing the transaction using the transparent redirect integration * * @param Varien_Object $payment * @param unknown_type $amount */ public function _runTransparentRedirectTransaction(Varien_Object $payment, $amount) { $takePaymentInStoreBaseCurrency = $this->getConfigData('takePaymentInStoreBaseCurrency'); $GLOBALS['m_boPayInvoice'] = false; $payment->setIsTransactionPending(true); $nVersion = $this->getVersion(); $szMerchantID = $this->getConfigData('merchantid'); $szPassword = $this->getConfigData('password'); $szPreSharedKey = $this->getConfigData('presharedkey'); $hmHashMethod = $this->getConfigData('hashmethod'); $szCallbackURL = Mage::getUrl('cardsaveonlinepayments/payment/callbacktransparentredirect', array('_secure' => true)); $order = $payment->getOrder(); $billingAddress = $order->getBillingAddress(); $iclISOCurrencyList = CSV_ISOCurrencies::getISOCurrencyList(); $iclISOCountryList = CSV_ISOCountries::getISOCountryList(); $szStartDateMonth = ''; $szStartDateYear = ''; if (!$takePaymentInStoreBaseCurrency) { // Take payment in order currency $szCurrencyShort = $order->getOrderCurrency()->getCurrencyCode(); if ($szCurrencyShort != '' && $iclISOCurrencyList->getISOCurrency($szCurrencyShort, $icISOCurrency)) { $nCurrencyCode = $icISOCurrency->getISOCode(); } // Calculate amount $power = pow(10, $icISOCurrency->getExponent()); $nAmount = round($order->getGrandTotal() * $power, 0); } else { // Take payment in site base currency //$szCurrencyShort = $order->getOrderCurrency()->getCurrencyCode(); $szCurrencyShort = $order->getBaseCurrencyCode(); if ($szCurrencyShort != '' && $iclISOCurrencyList->getISOCurrency($szCurrencyShort, $icISOCurrency)) { $nCurrencyCode = $icISOCurrency->getISOCode(); } // Calculate amount $nAmount = $this->_getRoundedAmount($amount, $icISOCurrency->getExponent()); } $szOrderID = $payment->getOrder()->increment_id; //date time with 2008-12-01 14:12:00 +01:00 format $szTransactionDateTime = date('Y-m-d H:i:s P'); $szOrderDescription = ''; //$szTransactionType = 'SALE'; $paymentAction = $this->getConfigData('payment_action'); if ($paymentAction == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE_CAPTURE) { $szTransactionType = "SALE"; } else { if ($paymentAction == Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE) { $szTransactionType = "PREAUTH"; } else { Mage::throwException('Unknown payment action: ' . $paymentAction); } } $szAddress1 = $billingAddress->getStreet1(); $szAddress2 = $billingAddress->getStreet2(); $szAddress3 = $billingAddress->getStreet3(); $szAddress4 = $billingAddress->getStreet4(); $szCity = $billingAddress->getCity(); $szState = $billingAddress->getRegion(); $szPostCode = $billingAddress->getPostcode(); $szISO2CountryCode = $billingAddress->getCountry(); $szCountryShort = $this->_getISO3Code($szISO2CountryCode); if ($iclISOCountryList->getISOCountry($szCountryShort, $icISOCountry)) { $nCountryCode = $icISOCountry->getISOCode(); } $szCardName = $payment->getCcOwner(); $szCardNumber = $payment->getCcNumber(); $szExpiryDateMonth = $payment->getCcExpMonth(); $szExpiryDateYear = $payment->getCcExpYear(); if ($payment->getCcSsStartMonth() != '') { $szStartDateMonth = $payment->getCcSsStartMonth(); } if ($payment->getCcSsStartYear() != '') { $szStartDateYear = $payment->getCcSsStartYear(); } $szIssueNumber = $payment->getCcSsIssue(); $szCV2 = $payment->getCcCid(); $szHashDigest = CSV_PaymentFormHelper::calculateTransparentRedirectHashDigest($szMerchantID, $szPassword, $hmHashMethod, $szPreSharedKey, $nAmount, $nCurrencyCode, $szOrderID, $szTransactionType, $szTransactionDateTime, $szCallbackURL, $szOrderDescription); Mage::getSingleton('checkout/session')->setHashdigest($szHashDigest)->setMerchantid($szMerchantID)->setAmount($nAmount)->setCurrencycode($nCurrencyCode)->setOrderid($szOrderID)->setTransactiontype($szTransactionType)->setTransactiondatetime($szTransactionDateTime)->setCallbackurl($szCallbackURL)->setOrderdescription($szOrderDescription)->setAddress1($szAddress1)->setAddress2($szAddress2)->setAddress3($szAddress3)->setAddress4($szAddress4)->setCity($szCity)->setState($szState)->setPostcode($szPostCode)->setCountrycode($nCountryCode)->setCardname($szCardName)->setCardnumber($szCardNumber)->setExpirydatemonth($szExpiryDateMonth)->setExpirydateyear($szExpiryDateYear)->setStartdatemonth($szStartDateMonth)->setStartdateyear($szStartDateYear)->setIssuenumber($szIssueNumber)->setCv2($szCV2); Mage::getSingleton('checkout/session')->setRedirectionmethod('_runRedirectedPaymentComplete'); $payment->getOrder()->setIsHostedPaymentPending(true); /* serve out a dummy CrossReference as the TransactionId - this need to be done to enable the "Refund" button in the Magento CreditMemo internal refund mechanism */ $payment->setTransactionId($szOrderID . "_" . date('YmdHis')); }