Skip to content

Commit

Permalink
Merge pull request #7 from signifyd/4.6.2
Browse files Browse the repository at this point in the history
4.6.2
  • Loading branch information
ebanolopes authored Sep 1, 2020
2 parents 919c1f8 + 22823f7 commit c690a6d
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ public function render(Varien_Object $row)
$value = $row->getData($this->getColumn()->getIndex());
$column = $this->getColumn()->getId();



switch ($column) {
case 'score':
if ($column == 'score' && !is_numeric($value)) {
Expand All @@ -21,7 +19,9 @@ public function render(Varien_Object $row)
case 'guarantee':
$entries = $row->getEntries();
if (!empty($entries)) {
@$entries = unserialize($entries);
$serializer = new Zend_Serializer_Adapter_PhpSerialize();
$entries = $serializer->unserialize($entries);

if (is_array($entries) && isset($entries['testInvestigation']) && $entries['testInvestigation'] == true) {
$value = "TEST: {$value}";
}
Expand Down
81 changes: 42 additions & 39 deletions www/magento/app/code/community/Signifyd/Connect/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,25 +458,25 @@ public function getCard($order, $payment, $case = null)
return $card;
}

public function getSignifydAddress($address_object)
public function getSignifydAddress($addressObject)
{
$address = array();

$address['streetAddress'] = $address_object->getStreet1();
$address['unit'] = null;
$address['latitude'] = null;
$address['longitude'] = null;

if ($address_object->getStreet2()) {
$address['unit'] = $address_object->getStreet2();
}

$address['city'] = $address_object->getCity();
if (is_object($addressObject)) {
$address['streetAddress'] = $addressObject->getStreet1();

$address['provinceCode'] = $address_object->getRegionCode();
$address['postalCode'] = $address_object->getPostcode();
$address['countryCode'] = $address_object->getCountryId();
if ($addressObject->getStreet2()) {
$address['unit'] = $addressObject->getStreet2();
}

$address['latitude'] = null;
$address['longitude'] = null;
$address['city'] = $addressObject->getCity();
$address['provinceCode'] = $addressObject->getRegionCode();
$address['postalCode'] = $addressObject->getPostcode();
$address['countryCode'] = $addressObject->getCountryId();
}

return $address;
}
Expand Down Expand Up @@ -520,35 +520,36 @@ public function getUserAccount($customer, $order)
);

if ($customer && $customer->getId()) {
$user['emailAddress'] = $customer->getEmail();

$user['phone'] = $order->getBillingAddress()->getTelephone();
$billing = $order->getBillingAddress();

if ($billing instanceof Mage_Sales_Model_Order_Address) {
$user['phone'] = $billing->getTelephone();
}

$user['emailAddress'] = $customer->getEmail();
$user['createdDate'] = date('c', strtotime($customer->getCreatedAt()));
$user['lastUpdateDate'] = date('c', strtotime($customer->getUpdatedAt()));

$user['accountNumber'] = $customer->getId();

$last_order_id = null;

$orders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('customer_id', $customer->getId());
$orders->getSelect()->order('created_at DESC');

$aggregate_total = 0.;
$order_count = 0;
$aggregateTotal = 0.;
$orderCount = 0;
$lastOrderId = null;

foreach ($orders as $order) {
if ($last_order_id === null) {
$last_order_id = $order->getIncrementId();
if ($lastOrderId === null) {
$lastOrderId = $order->getIncrementId();
}

$aggregate_total += floatval($order->getGrandTotal());
$order_count += 1;
$aggregateTotal += floatval($order->getGrandTotal());
$orderCount += 1;
}

$user['lastOrderId'] = $last_order_id;
$user['aggregateOrderCount'] = $order_count;
$user['aggregateOrderDollars'] = floatval($aggregate_total);
$user['lastOrderId'] = $lastOrderId;
$user['aggregateOrderCount'] = $orderCount;
$user['aggregateOrderDollars'] = floatval($aggregateTotal);
}

return $user;
Expand Down Expand Up @@ -690,7 +691,7 @@ public function buildAndSendOrderToSignifyd($order, $forceSend = false, $updateO

$caseUpdateData = $this->generateCaseUpdateData($order, $lastPayment, $case);
$caseJson = json_encode($caseUpdateData);
$newMd5 = md5($caseJson);
$newHash = sha1($caseJson);

if ($case->getId()) {
if ($case->getMagentoStatus() == Signifyd_Connect_Model_Case::WAITING_SUBMISSION_STATUS) {
Expand Down Expand Up @@ -748,22 +749,22 @@ public function buildAndSendOrderToSignifyd($order, $forceSend = false, $updateO
$case->setOrderIncrement($orderIncrementId);
$case->setCreated(strftime('%Y-%m-%d %H:%M:%S', time()));
$case->setMagentoStatus(Signifyd_Connect_Model_Case::WAITING_SUBMISSION_STATUS);
$case->setEntries('md5', $newMd5);
$case->setEntries('hash', $newHash);
$case->setEntries('card_data', $cardData);
$case->setEntries('purchase_data', $purchaseData);
$case->save();

$requestUri = $this->getCaseUrl();
} else {
} else {
$caseCode = $case->getCode();
if (empty($caseCode)) {
return 'no case for update';
}

$currentMd5 = $case->getEntries('md5');
$currentHash = $case->getEntries('hash');
// If the case exists and has not changed, return 'exists'
// MD5 checks must occur on case update data only
if ($currentMd5 == $newMd5) {
// Hash checks must occur on case update data only
if ($currentHash == $newHash) {
return 'exists';
}

Expand Down Expand Up @@ -797,7 +798,7 @@ public function buildAndSendOrderToSignifyd($order, $forceSend = false, $updateO
$case->setCode($caseId);

if ($isUpdate) {
$case->setEntries('md5', $newMd5);
$case->setEntries('hash', $newHash);
$previousScore = intval($case->getScore());
Mage::getModel('signifyd_connect/case')->processCreation($case, $responseData);
$newScore = intval($case->getScore());
Expand Down Expand Up @@ -1260,18 +1261,20 @@ public function buildAndSendFulfillmentToSignifyd(Mage_Sales_Model_Order_Shipmen
*/
public function prepareFulfillmentToDatabase($fulfillmentData)
{
$serializer = new Zend_Serializer_Adapter_PhpSerialize();

/** @var Signifyd_Connect_Model_Fulfillment $fulfillment */
$fulfillment = Mage::getModel('signifyd_connect/fulfillment');
$fulfillment->setData('id', $fulfillmentData['fulfillments'][0]['id']);
$fulfillment->setData('order_id', $fulfillmentData['fulfillments'][0]['orderId']);
$fulfillment->setData('created_at', $fulfillmentData['fulfillments'][0]['createdAt']);
$fulfillment->setData('delivery_email', $fulfillmentData['fulfillments'][0]['deliveryEmail']);
$fulfillment->setData('fulfillment_status', $fulfillmentData['fulfillments'][0]['fulfillmentStatus']);
$fulfillment->setData('tracking_numbers', serialize($fulfillmentData['fulfillments'][0]['trackingNumbers']));
$fulfillment->setData('tracking_urls', serialize($fulfillmentData['fulfillments'][0]['trackingUrls']));
$fulfillment->setData('products', serialize($fulfillmentData['fulfillments'][0]['products']));
$fulfillment->setData('tracking_numbers', $serializer->serialize($fulfillmentData['fulfillments'][0]['trackingNumbers']));
$fulfillment->setData('tracking_urls', $serializer->serialize($fulfillmentData['fulfillments'][0]['trackingUrls']));
$fulfillment->setData('products', $serializer->serialize($fulfillmentData['fulfillments'][0]['products']));
$fulfillment->setData('shipment_status', $fulfillmentData['fulfillments'][0]['shipmentStatus']);
$fulfillment->setData('delivery_address', serialize($fulfillmentData['fulfillments'][0]['deliveryAddress']));
$fulfillment->setData('delivery_address', $serializer->serialize($fulfillmentData['fulfillments'][0]['deliveryAddress']));
$fulfillment->setData('recipient_name', $fulfillmentData['fulfillments'][0]['recipientName']);
$fulfillment->setData('confirmation_name', $fulfillmentData['fulfillments'][0]['confirmationName']);
$fulfillment->setData('confirmation_phone', $fulfillmentData['fulfillments'][0]['confirmationPhone']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ public function getAvsResponseCode()
$avsResponseCode = null;

if (is_object($this->charge) &&
isset($this->charge->source->address_line1_check) &&
isset($this->charge->source->address_zip_check) ) {
$addressLine1Check = $this->charge->source->address_line1_check;
$addressZipCheck = $this->charge->source->address_zip_check;
isset($this->charge->source->card->address_line1_check) &&
isset($this->charge->source->card->address_zip_check) ) {
$addressLine1Check = $this->charge->source->card->address_line1_check;
$addressZipCheck = $this->charge->source->card->address_zip_check;
$key = "{$addressLine1Check}-{$addressZipCheck}";

if (isset($this->avsMap[$key])) {
Expand All @@ -94,8 +94,8 @@ public function getCvvResponseCode()
{
$cvvResponseCode = null;

if (is_object($this->charge) && isset($this->charge->source->cvc_check)) {
$cvcCheck = $this->charge->source->cvc_check;
if (is_object($this->charge) && isset($this->charge->source->card->cvc_check)) {
$cvcCheck = $this->charge->source->card->cvc_check;

if (isset($this->cvvMap[$cvcCheck])) {
$cvvResponseCode = $this->filterCvvResponseCode($this->cvvMap[$cvcCheck]);
Expand All @@ -112,8 +112,8 @@ public function getCvvResponseCode()
*/
public function getCardHolderName()
{
if (is_object($this->charge) && isset($this->charge->source->name)) {
$cardHolderName = trim($this->charge->source->name);
if (is_object($this->charge) && isset($this->charge->source->card->name)) {
$cardHolderName = trim($this->charge->source->card->name);
if (!empty($cardHolderName)) return $cardHolderName;
}

Expand All @@ -125,8 +125,8 @@ public function getCardHolderName()
*/
public function getLast4()
{
if (is_object($this->charge) && isset($this->charge->source->last4)) {
$last4 = $this->filterLast4($this->charge->source->last4);
if (is_object($this->charge) && isset($this->charge->source->card->last4)) {
$last4 = $this->filterLast4($this->charge->source->card->last4);
}

$this->logger->addLog('Last4 found on payment helper: ' . (empty($last4) ? 'false' : 'true'), $this->payment);
Expand All @@ -143,8 +143,8 @@ public function getLast4()
*/
public function getExpiryMonth()
{
if (is_object($this->charge) && isset($this->charge->source->exp_month)) {
$expiryMonth = $this->filterExpiryMonth($this->charge->source->exp_month);
if (is_object($this->charge) && isset($this->charge->source->card->exp_month)) {
$expiryMonth = $this->filterExpiryMonth($this->charge->source->card->exp_month);
}

$this->logger->addLog('Expiry month found on payment helper: ' . (empty($expiryMonth) ? 'false' : $expiryMonth), $this->payment);
Expand All @@ -161,8 +161,8 @@ public function getExpiryMonth()
*/
public function getExpiryYear()
{
if (is_object($this->charge) && isset($this->charge->source->exp_year)) {
$expiryYear = $this->filterExpiryYear($this->charge->source->exp_year);
if (is_object($this->charge) && isset($this->charge->source->card->exp_year)) {
$expiryYear = $this->filterExpiryYear($this->charge->source->card->exp_year);
}

$this->logger->addLog('Expiry year found on payment helper: ' . (empty($expiryYear) ? 'false' : $expiryYear), $this->payment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,12 @@ public function getCardHolderName()
return $this->signifydData['cc_owner'];
} else {
$billing = $this->order->getBillingAddress();
return $billing->getFirstname() . ' ' . $billing->getLastname();

if ($billing instanceof Mage_Sales_Model_Order_Address) {
return $billing->getFirstname() . ' ' . $billing->getLastname();
} else {
return null;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ public function getLast4()
public function getCardHolderName()
{
$billing = $this->order->getBillingAddress();
return $billing->getFirstname() . ' ' . $billing->getLastname();

if ($billing instanceof Mage_Sales_Model_Order_Address) {
return $billing->getFirstname() . ' ' . $billing->getLastname();
} else {
return null;
}
}

/**
Expand Down
10 changes: 8 additions & 2 deletions www/magento/app/code/community/Signifyd/Connect/Model/Case.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class Signifyd_Connect_Model_Case extends Mage_Core_Model_Abstract
/* The request data */
protected $_request;

/**
* @var Zend_Serializer_Adapter_PhpSerialize();
*/
protected $serializer;

/* The previous guarantee for the case */
public $_previousGuarantee = false;

Expand All @@ -49,6 +54,7 @@ protected function _construct()
$this->_init('signifyd_connect/case');
$this->_isPkAutoIncrement = false;
$this->logger = Mage::helper('signifyd_connect/log');
$this->serializer = $serializer = new Zend_Serializer_Adapter_PhpSerialize();
}

/**
Expand Down Expand Up @@ -347,7 +353,7 @@ public function getEntries($index = null)
$entries = $this->getData('entries');

if (!empty($entries)) {
@$entries = unserialize($entries);
$entries = $this->serializer->unserialize($entries);
}

if (!is_array($entries)) {
Expand Down Expand Up @@ -380,7 +386,7 @@ public function setEntries($index, $value = null)
}
}

@$entries = serialize($entries);
$entries = $this->serializer->serialize($entries);
$this->setData('entries', $entries);

return $this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ protected function _getCacheId()
*/
protected function _renderBlock()
{
return $this->_getPlaceHolderBlock()->toHtml();
if (method_exists($this, '_getPlaceHolderBlock')) {
return $this->_getPlaceHolderBlock()->toHtml();
}
}
}
42 changes: 0 additions & 42 deletions www/magento/app/code/community/Signifyd/Connect/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,6 @@ public function unholdOrderAndCapture(Mage_Sales_Model_Order $order, $reason)
$status = $this->helper->getOrderPaymentStatus($order);

try {
// Authorize the order
$result = $this->authorizeOrder($order);
if ($result === false) {
$this->holdOrder($order, 'failed to authorise order');
}

// Generate the invoice
if ($status['capture'] !== true) {
$result = $this->generateInvoice($order);
Expand All @@ -283,42 +277,6 @@ public function unholdOrderAndCapture(Mage_Sales_Model_Order $order, $reason)
return true;
}

/**
* @param Mage_Sales_Model_Order $order
* @return bool
*/
public function authorizeOrder(Mage_Sales_Model_Order $order)
{
// Get the payment status for this order
$status = $this->helper->getOrderPaymentStatus($order);

if($status['authorize']){
$this->logger->addLog("Order {$order->getIncrementId()} is already authorize", $order);
return true;
}

$payment = $order->getPayment();
$method = $payment->getMethodInstance();
if(!$method->canAuthorize()){
$this->logger->addLog("Order {$order->getIncrementId()} cannot be authorize", $order);
return true;
}

$amount = $order->getData('grand_total');

try{
// check if method authorize returns anything usefully
$method->authorize($payment, $amount);
$this->logger->addLog("Authorize order {$order->getIncrementId()} was successful", $order);
} catch (Exception $e) {
$this->logger->addLog("Authorize order {$order->getIncrementId()} was not authorized:", $order);
$this->logger->addLog($e->__toString(), $order);
return false;
}

return true;
}

/**
* Method to generate the invoice after a order was placed
* @param $order
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<config>
<modules>
<Signifyd_Connect>
<version>4.6.1</version>
<version>4.6.2</version>
</Signifyd_Connect>
</modules>
<global>
Expand Down
Loading

0 comments on commit c690a6d

Please sign in to comment.