Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Custom Module call after Payment transaction

 
Reply
   X-Cart forums > X-Cart 5 > Third Party Add-Ons for X-Cart 5
 
Thread Tools Search this Thread
  #1  
Old 02-08-2017, 04:52 AM
 
Sooraj Sooraj is offline
 

Newbie
  
Join Date: Mar 2016
Posts: 9
 

Default Custom Module call after Payment transaction - Xcart 5.3

Im trying to implement a third party library related to credit card prevention service. I have installed xpayment connector and enabled authorizenet aim module.
I need to fetch credit card details that customer entered and pass those informations with order details to api.
How can I call my function after order is processed. I tried to call my function within handleCheckoutAction() but couldn't fetch credit card datas.

My module structure is:
Code:
CustomModule/ CustomModule/ Install.yaml Main.php icon.png Model/ Payment/ Transaction.php


Transaction.php file


Code:
<?php // vim: set ts=4 sw=4 sts=4 et: namespace XLite\Module\CustomModule\CustomModule\Model\Payment; /** * Payment transaction * */ class Transaction extends \XLite\Model\Payment\Transaction implements \XLite\Base\IDecorator { protected function getclientIpAddress() { $ipaddress = ''; if (getenv('HTTP_CLIENT_IP')) $ipaddress = getenv('HTTP_CLIENT_IP'); else if(getenv('HTTP_X_FORWARDED_FOR')) $ipaddress = getenv('HTTP_X_FORWARDED_FOR'); else if(getenv('HTTP_X_FORWARDED')) $ipaddress = getenv('HTTP_X_FORWARDED'); else if(getenv('HTTP_FORWARDED_FOR')) $ipaddress = getenv('HTTP_FORWARDED_FOR'); else if(getenv('HTTP_FORWARDED')) $ipaddress = getenv('HTTP_FORWARDED'); else if(getenv('REMOTE_ADDR')) $ipaddress = getenv('REMOTE_ADDR'); else $ipaddress = 'UNKNOWN'; return $ipaddress; } protected function getFormattedPrice($price) { return number_format( $price,//$this->transaction->getCurrency()->roundValue($price), 2, '.', '' ); } /** * Process checkout action * * @return string */ public function handleCheckoutAction() { $this->processCardFraudCheck(); return parent::handleCheckoutAction(); } public function processCardFraudCheck() { $config = \XLite\Core\Config::getInstance()->CustomModule->CustomModule; $api_key = $config->my_api_key; $api_endpoint = $config->my_api_url; $api_endpoint = rtrim($api_endpoint, '/'); $api_url = $api_endpoint.'/cases'; $currencytype = $this->getOrder()->getCurrency(); $currency = $currencytype->getCode(); //@todo - check if payment method is authorizenet $paymentMethod = $this->getOrder()->getPaymentMethod(); $paymentGateway = $paymentMethod->getServiceName(); /*if($paymentGateway != 'XPayments.XPay_Module_AuthorizeNetXML' || $paymentGateway != 'Stripe'){ return; }*/ $paymentGateway = 'authorizenet'; $shippingAddress = $this->getProfile()->getShippingAddress(); if (null === $shippingAddress) { $shippingAddress = $this->getProfile()->getBillingAddress(); } $objDateTime = new \DateTime('NOW'); $isoDate = $objDateTime->format(\DateTime::ISO8601); //products info $cart_items = array(); foreach ($this->getOrder()->getItems() as $item) { $product = $item->getProduct(); $cart_items[] = array( 'itemId' => $product->getProductId(), 'itemName' => $product->getName(), 'itemUrl' => $product->getCleanURL(), 'itemPrice' => $this->getFormattedPrice($item->getNetPrice()), 'itemQuantity' => $item->getAmount() ); } //recipient info $billingFirst = $this->getProfile()->getBillingAddress()->getFirstname(); $billingLast = $this->getProfile()->getBillingAddress()->getLastname(); $billingAddress1 = $this->getProfile()->getBillingAddress()->getStreet(); $billingAddress2 = ''; $billingCity = $this->getProfile()->getBillingAddress()->getCity(); $billingState = ''; $billingZip = $this->getProfile()->getBillingAddress()->getZipcode(); $billingPhone = $this->getProfile()->getBillingAddress()->getPhone(); $billingEmail = $this->getProfile()->getLogin(); $billingCountry = strtoupper($this->getProfile()->getBillingAddress()->getCountry()->getCode()); if ('US' === $billingCountry) { $billingState = $this->getProfile()->getBillingAddress()->getState()->getCode(); } $shippingFirst = $shippingAddress->getFirstname(); $shippingLast = $shippingAddress->getLastname(); $shippingAddress1 = $shippingAddress->getStreet(); $shippingAddress2 = ''; $shippingCity = $shippingAddress->getCity(); $shippingState = ''; $shippingZip = $shippingAddress->getZipcode(); $shippingPhone = ''; $shippingCountry = strtoupper($shippingAddress->getCountry()->getCode()); if ('US' === $shippingCountry) { $shippingState = $shippingAddress->getState()->getCode(); } $request = \XLite\Core\Request::getInstance(); //@todo - get credit card details $card_number = $request->card_number; $card_holder_name = $request->card_name; $card_expire = $request->card_number; $expire_info = explode('/', $card_expire); $card_expire_month = $expire_info[0]; $card_expire_year = $expire_info[1]; //@todo - get credit card info avs cvv response etc $avsResponseCode = 'Y'; $cvvResponseCode = 'M'; $bin = $card_number; $bin = str_replace("-","",$bin); $bin = str_replace(" ","",$bin) ; $bin = substr($bin, 0, 6); $totalPrice = $this->getFormattedPrice($this->getOrder()->getTotal()); //@todo - get order number instead orderid $orderId = $this->getOrder()->getOrderId();//$this->getTransactionId(); $order_number = \XLite\Core\Request::getInstance()->order_number; //code to call api \XLite\Core\OrderHistory::getInstance()->registerEvent( $this->getOrder()->getOrderId(), \XLite\Core\OrderHistory::CODE_CHANGE_STATUS_ORDER, 'credit card fraud prevention service is applied. '. ); } }

How can I fetch credit card information after order is processed.
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Third Party Add-Ons for X-Cart 5


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 02:40 AM.

   

 
X-Cart forums © 2001-2020