From f5d44f4b7dd750ae7328a7fe41cefb0036f1d224 Mon Sep 17 00:00:00 2001
From: Wojciech Kamiski
Date: Wed, 6 Sep 2017 15:28:04 +0200
Subject: [PATCH 01/12] create feature configuration
---
.../community/Riskified/Full/Helper/Data.php | 69 +++++++++++++++++
.../community/Riskified/Full/etc/system.xml | 77 +++++++++++++++++++
2 files changed, 146 insertions(+)
diff --git a/app/code/community/Riskified/Full/Helper/Data.php b/app/code/community/Riskified/Full/Helper/Data.php
index 6d2db63..7e26505 100644
--- a/app/code/community/Riskified/Full/Helper/Data.php
+++ b/app/code/community/Riskified/Full/Helper/Data.php
@@ -151,4 +151,73 @@ public function getDateTime($time = 'now')
return $dateTime->format($dateTime::ATOM);
}
+
+
+ /**
+ * Retrieve configuration of decline notification
+ *
+ * @return bool
+ */
+ public function isDeclineNotificationEnabled()
+ {
+ return Mage::getStoreConfig('fullsection/decline_notification/enable', $this->getStoreId());
+ }
+
+ /**
+ * Retrieve declination email sender configuration
+ *
+ * @return string
+ */
+ public function getDeclineNotificationSender()
+ {
+ return Mage::getStoreConfig('fullsection/decline_notification/email_identity', $this->getStoreId());
+
+ }
+
+ /**
+ * Retrieve declination email subject set in admin panel
+ *
+ * @return string
+ */
+ public function getDeclineNotificationSubject()
+ {
+ return Mage::getStoreConfig('fullsection/decline_notification/title', $this->getStoreId());
+ }
+
+ /**
+ * Retrieve declination email content set in admin panel
+ *
+ * @return string
+ */
+ public function getDeclineNotificationContent()
+ {
+ return Mage::getStoreConfig('fullsection/decline_notification/content', $this->getStoreId());
+ }
+
+ /**
+ * Retrieve declination email sender email based on configuration in admin panel
+ *
+ * @return string
+ */
+ public function getDeclineNotificationSenderEmail()
+ {
+
+ return Mage::getStoreConfig(
+ 'trans_email/ident_' . $this->getDeclineNotificationSender() . '/email',
+ $this->getStoreId()
+ );
+ }
+
+ /**
+ * Retrieve declination email sender name based on configuration in admin panel
+ *
+ * @return string
+ */
+ public function getDeclineNotificationSenderName()
+ {
+ return Mage::getStoreConfig(
+ 'trans_email/ident_' . $this->getDeclineNotificationSender() . '/name',
+ $this->getStoreId()
+ );
+ }
}
diff --git a/app/code/community/Riskified/Full/etc/system.xml b/app/code/community/Riskified/Full/etc/system.xml
index f6e062f..b1d08d2 100644
--- a/app/code/community/Riskified/Full/etc/system.xml
+++ b/app/code/community/Riskified/Full/etc/system.xml
@@ -194,6 +194,83 @@
+
+
+ 20
+ 1
+ 1
+ 1
+
+
+
+ select
+ adminhtml/system_config_source_yesno
+ 10
+ 1
+ 1
+ 1
+
+
+
+
+
+
+ select
+ adminhtml/system_config_source_email_identity
+ 20
+ 1
+ 1
+ 1
+
+ 1
+
+
+
+
+ text
+ 30
+ 1
+ 1
+ 1
+
+ 1
+
+
+
+ {{products}} - Product names comma separated
+ {{customer_name}} - Customer full name
+ {{customer_firstname}} - Customer first name
+ {{order_increment_id}} - Order Number
+ {{order_view_url}} - Order url to order detail page in customer dashboard
+ {{store_name}} - Store name
+ ]]>
+
+
+
+
+ textarea
+ 40
+ 1
+ 1
+ 1
+
+ 1
+
+
+
+ {{products}} - Product names comma separated
+ {{customer_name}} - Customer full name
+ {{customer_firstname}} - Customer first name
+ {{order_increment_id}} - Order Number
+ {{order_view_url}} - Order url to order detail page in customer dashboard
+ {{store_name}} - Store name
+ ]]>
+
+
+
+
From 623b9204c2771da12b353884de45c2b28dfc8481 Mon Sep 17 00:00:00 2001
From: Wojciech Kamiski
Date: Wed, 6 Sep 2017 15:28:26 +0200
Subject: [PATCH 02/12] Added default config data
---
.../community/Riskified/Full/etc/config.xml | 23 +++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/app/code/community/Riskified/Full/etc/config.xml b/app/code/community/Riskified/Full/etc/config.xml
index 4d742ac..c6bf7da 100644
--- a/app/code/community/Riskified/Full/etc/config.xml
+++ b/app/code/community/Riskified/Full/etc/config.xml
@@ -203,7 +203,25 @@
+
+
+
+ singleton
+ full/observer_order_decline
+ handleOrderDecline
+
+
+
+
+
+
+
+ full/order/declined.html
+ html
+
+
+
@@ -325,6 +343,11 @@
online
0
+
+ general
+ {{store_name}}: Order # {{order_increment_id}} has been declined by Riskified
+ We regret to inform you that your recent order #{{order_increment_id}} for {{products}}
has been declined by Riskified service.
]]>
+
From c363d2dafb347d6f5a32320d07f9c3064b2c9e9e Mon Sep 17 00:00:00 2001
From: Wojciech Kamiski
Date: Wed, 6 Sep 2017 15:28:52 +0200
Subject: [PATCH 03/12] Added base email template, content and subject is
configurable in admin panel
---
.../template/email/full/order/declined.html | 33 +++++++++++++++++++
1 file changed, 33 insertions(+)
create mode 100644 app/locale/en_US/template/email/full/order/declined.html
diff --git a/app/locale/en_US/template/email/full/order/declined.html b/app/locale/en_US/template/email/full/order/declined.html
new file mode 100644
index 0000000..5b4dc86
--- /dev/null
+++ b/app/locale/en_US/template/email/full/order/declined.html
@@ -0,0 +1,33 @@
+
+
+
+
+{{template config_path="design/email/header"}}
+{{inlinecss file="email-inline.css"}}
+
+
+
+
+
+ {{var content}}
+ |
+
+
+
+{{template config_path="design/email/footer"}}
\ No newline at end of file
From c36fd684dbdb21f071fabe2ef12f14e69af90cf7 Mon Sep 17 00:00:00 2001
From: Wojciech Kamiski
Date: Wed, 6 Sep 2017 15:29:18 +0200
Subject: [PATCH 04/12] Updated modman file to handle newly created email
template
---
modman | 1 +
1 file changed, 1 insertion(+)
diff --git a/modman b/modman
index cb2009f..ac747d9 100644
--- a/modman
+++ b/modman
@@ -4,6 +4,7 @@ app/design/adminhtml/default/default/template/full/ app/design/adminhtml/def
app/design/frontend/base/default/layout/full.xml app/design/frontend/base/default/layout/full.xml
app/design/frontend/base/default/template/full/ app/design/frontend/base/default/template/full/
app/etc/modules/Riskified_Full.xml app/etc/modules/Riskified_Full.xml
+app/locale/en_US/template/email/full/order/declined.html app/locale/en_US/template/email/full/order/declined.html
lib/riskified_php_sdk/ lib/riskified_php_sdk/
lib/riskified_scripts/ lib/riskified_scripts/
skin/adminhtml/default/default/images/riskified/ skin/adminhtml/default/default/images/riskified/
From b4daaa4689b2fae491b28dde210d6159f5d334b6 Mon Sep 17 00:00:00 2001
From: Wojciech Kamiski
Date: Wed, 6 Sep 2017 15:29:49 +0200
Subject: [PATCH 05/12] Created observer to send declination email
---
.../Full/Model/Observer/Order/Decline.php | 97 +++++++++++++++++++
1 file changed, 97 insertions(+)
create mode 100644 app/code/community/Riskified/Full/Model/Observer/Order/Decline.php
diff --git a/app/code/community/Riskified/Full/Model/Observer/Order/Decline.php b/app/code/community/Riskified/Full/Model/Observer/Order/Decline.php
new file mode 100644
index 0000000..a24b59b
--- /dev/null
+++ b/app/code/community/Riskified/Full/Model/Observer/Order/Decline.php
@@ -0,0 +1,97 @@
+getOrder();
+ $this->order = $order;
+ /**
+ * @var Riskified_Full_Helper_Data $dataHelper
+ */
+ $dataHelper = Mage::helper("full");
+
+ if (!$dataHelper->isDeclineNotificationEnabled()) {
+ return $this;
+ }
+ if (Mage::registry("decline-email-sent")) {
+ return $this;
+ }
+
+ Mage::register("decline-email-sent", true);
+
+ $emailTemplate = Mage::getModel('core/email_template')
+ ->loadDefault('riskified_order_declined');
+
+ $emailTemplate->setSenderEmail(
+ $dataHelper->getDeclineNotificationSenderEmail()
+ );
+
+ $emailTemplate->setSenderName(
+ $dataHelper->getDeclineNotificationSenderName()
+ );
+
+ $subject = $dataHelper->getDeclineNotificationSubject();
+ $content = $dataHelper->getDeclineNotificationContent();
+
+ $shortCodes = array(
+ "{{customer_name}}",
+ "{{customer_firstname}}",
+ "{{order_increment_id}}",
+ "{{order_view_url}}",
+ "{{products}}",
+ "{{store_name}}",
+ );
+ $formattedPayload = $this->getFormattedData();
+
+ foreach ($shortCodes as $key => $value) {
+ $subject = str_replace($value, $formattedPayload[$key], $subject);
+ $content = str_replace($value, $formattedPayload[$key], $content);
+ }
+
+ try {
+ if ($content == "") {
+ throw new Exception("Email content is empty");
+ }
+
+ if ($subject == "") {
+ throw new Exception("Email subject is empty");
+ }
+
+ $emailTemplate->send(
+ $order->getCustomerEmail(),
+ $order->getCustomerName(),
+ array(
+ 'store' => Mage::app()->getStore(),
+ 'subject' => $subject,
+ 'order' => $order,
+ 'content' => $content
+ )
+ );
+ } catch (Exception $e) {
+ Mage::logException($e);
+ }
+ }
+
+ private function getFormattedData()
+ {
+ $products = array();
+
+ foreach ($this->order->getAllItems() as $item) {
+ $products[] = $item->getName();
+ }
+
+ $data = array(
+ $this->order->getCustomerName(),
+ $this->order->getCustomerFirstname(),
+ $this->order->getIncrementId(),
+ Mage::getUrl('sales/order/view', array('order_id' => $this->order->getId())),
+ join(', ', $products),
+ Mage::app()->getStore()->getFrontendName()
+ );
+
+ return $data;
+ }
+}
From 63b8229188aaae2ffea3f48d9f24277823eb2674 Mon Sep 17 00:00:00 2001
From: Wojciech Kamiski
Date: Thu, 7 Sep 2017 15:32:56 +0200
Subject: [PATCH 06/12] Fixed typo in event declaration
---
app/code/community/Riskified/Full/etc/config.xml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/app/code/community/Riskified/Full/etc/config.xml b/app/code/community/Riskified/Full/etc/config.xml
index c6bf7da..599e56d 100644
--- a/app/code/community/Riskified/Full/etc/config.xml
+++ b/app/code/community/Riskified/Full/etc/config.xml
@@ -203,15 +203,15 @@
-
+
-
+
singleton
full/observer_order_decline
handleOrderDecline
-
+
-
+
From 05b24125d8a4e12e0fc3188e95667cc1667cd70f Mon Sep 17 00:00:00 2001
From: Wojciech Kamiski
Date: Mon, 11 Sep 2017 09:57:19 +0200
Subject: [PATCH 07/12] Add order comment when declination email was sent
---
.../Full/Model/Observer/Order/Decline.php | 34 ++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/app/code/community/Riskified/Full/Model/Observer/Order/Decline.php b/app/code/community/Riskified/Full/Model/Observer/Order/Decline.php
index a24b59b..650c505 100644
--- a/app/code/community/Riskified/Full/Model/Observer/Order/Decline.php
+++ b/app/code/community/Riskified/Full/Model/Observer/Order/Decline.php
@@ -60,7 +60,7 @@ public function handleOrderDecline(
throw new Exception("Email subject is empty");
}
- $emailTemplate->send(
+ $wasSent = $emailTemplate->send(
$order->getCustomerEmail(),
$order->getCustomerName(),
array(
@@ -70,6 +70,38 @@ public function handleOrderDecline(
'content' => $content
)
);
+
+ if ($wasSent === true) {
+ $fileLog = $dataHelper->__(
+ "Declination email was sent to customer %s (%s) for order #%s",
+ $order->getCustomerName(),
+ $order->getCustomerEmail(),
+ $order->getIncrementId()
+ );
+
+ $orderComment = $dataHelper->__(
+ "Declination email was sent to customer %s (%s)",
+ $order->getCustomerName(),
+ $order->getCustomerEmail()
+ );
+ } else {
+ $fileLog = $dataHelper->__(
+ "Declination email was not sent to customer %s (%s) for order #%s - server internal error",
+ $order->getCustomerName(),
+ $order->getCustomerEmail(),
+ $order->getIncrementId()
+ );
+ $orderComment = $dataHelper->__(
+ "Declination email was sent to customer %s (%s) - server internal error",
+ $order->getCustomerName(),
+ $order->getCustomerEmail()
+ );
+ }
+
+ Mage::helper('full/log')->log($fileLog);
+
+ $order->addStatusHistoryComment($orderComment);
+ $order->save();
} catch (Exception $e) {
Mage::logException($e);
}
From 9c2cb9402c0e9b08596661a4e1a58fd6df317e61 Mon Sep 17 00:00:00 2001
From: Wojciech Kamiski
Date: Mon, 11 Sep 2017 11:40:54 +0200
Subject: [PATCH 08/12] Mark comment of the order to customer sent
---
.../community/Riskified/Full/Model/Observer/Order/Decline.php | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/app/code/community/Riskified/Full/Model/Observer/Order/Decline.php b/app/code/community/Riskified/Full/Model/Observer/Order/Decline.php
index 650c505..fc4bcf4 100644
--- a/app/code/community/Riskified/Full/Model/Observer/Order/Decline.php
+++ b/app/code/community/Riskified/Full/Model/Observer/Order/Decline.php
@@ -100,7 +100,9 @@ public function handleOrderDecline(
Mage::helper('full/log')->log($fileLog);
- $order->addStatusHistoryComment($orderComment);
+ $order
+ ->addStatusHistoryComment($orderComment)
+ ->setIsCustomerNotified(true);
$order->save();
} catch (Exception $e) {
Mage::logException($e);
From e8cce50908b36800876f17cbec4e3bb8a261cea8 Mon Sep 17 00:00:00 2001
From: Wojciech Kamiski
Date: Mon, 11 Sep 2017 11:42:56 +0200
Subject: [PATCH 09/12] Fixed typo in failed notification
---
.../community/Riskified/Full/Model/Observer/Order/Decline.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/code/community/Riskified/Full/Model/Observer/Order/Decline.php b/app/code/community/Riskified/Full/Model/Observer/Order/Decline.php
index fc4bcf4..73b0e4a 100644
--- a/app/code/community/Riskified/Full/Model/Observer/Order/Decline.php
+++ b/app/code/community/Riskified/Full/Model/Observer/Order/Decline.php
@@ -92,7 +92,7 @@ public function handleOrderDecline(
$order->getIncrementId()
);
$orderComment = $dataHelper->__(
- "Declination email was sent to customer %s (%s) - server internal error",
+ "Declination email was not sent to customer %s (%s) - server internal error",
$order->getCustomerName(),
$order->getCustomerEmail()
);
From 0659c560eda96de50cba929e70caa27cfb9d4492 Mon Sep 17 00:00:00 2001
From: jchiupro
Date: Mon, 11 Sep 2017 11:52:45 -0400
Subject: [PATCH 10/12] Changed wording of "declination" to "decline" (#38)
---
.../Riskified/Full/Model/Observer/Order/Decline.php | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/app/code/community/Riskified/Full/Model/Observer/Order/Decline.php b/app/code/community/Riskified/Full/Model/Observer/Order/Decline.php
index 73b0e4a..0f13aa4 100644
--- a/app/code/community/Riskified/Full/Model/Observer/Order/Decline.php
+++ b/app/code/community/Riskified/Full/Model/Observer/Order/Decline.php
@@ -73,26 +73,26 @@ public function handleOrderDecline(
if ($wasSent === true) {
$fileLog = $dataHelper->__(
- "Declination email was sent to customer %s (%s) for order #%s",
+ "Decline email was sent to customer %s (%s) for order #%s",
$order->getCustomerName(),
$order->getCustomerEmail(),
$order->getIncrementId()
);
$orderComment = $dataHelper->__(
- "Declination email was sent to customer %s (%s)",
+ "Decline email was sent to customer %s (%s)",
$order->getCustomerName(),
$order->getCustomerEmail()
);
} else {
$fileLog = $dataHelper->__(
- "Declination email was not sent to customer %s (%s) for order #%s - server internal error",
+ "Decline email was not sent to customer %s (%s) for order #%s - server internal error",
$order->getCustomerName(),
$order->getCustomerEmail(),
$order->getIncrementId()
);
$orderComment = $dataHelper->__(
- "Declination email was not sent to customer %s (%s) - server internal error",
+ "Decline email was not sent to customer %s (%s) - server internal error",
$order->getCustomerName(),
$order->getCustomerEmail()
);
From 96c943d002a8c4da9c13e534475d366a5e558c59 Mon Sep 17 00:00:00 2001
From: jchiupro
Date: Tue, 12 Sep 2017 13:01:25 -0400
Subject: [PATCH 11/12] Added case 'gene_braintree_creditcard': to line 162
(#40)
---
app/code/community/Riskified/Full/Helper/Order/Payment.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/app/code/community/Riskified/Full/Helper/Order/Payment.php b/app/code/community/Riskified/Full/Helper/Order/Payment.php
index fcdf1c9..7994a24 100644
--- a/app/code/community/Riskified/Full/Helper/Order/Payment.php
+++ b/app/code/community/Riskified/Full/Helper/Order/Payment.php
@@ -159,6 +159,7 @@ public function getPaymentDetails($order)
);
break;
+ case 'gene_braintree_creditcard':
case 'braintree':
case 'braintreevzero':
$cvvResultCode = $payment
From 66e8bcde96b1af2da856a19ea3de5df972068a5e Mon Sep 17 00:00:00 2001
From: jchiupro
Date: Tue, 12 Sep 2017 13:01:42 -0400
Subject: [PATCH 12/12] Removed "by Riskified" in decline email wording (#39)
---
app/code/community/Riskified/Full/etc/config.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/app/code/community/Riskified/Full/etc/config.xml b/app/code/community/Riskified/Full/etc/config.xml
index 599e56d..b48d142 100644
--- a/app/code/community/Riskified/Full/etc/config.xml
+++ b/app/code/community/Riskified/Full/etc/config.xml
@@ -345,8 +345,8 @@
general
- {{store_name}}: Order # {{order_increment_id}} has been declined by Riskified
- We regret to inform you that your recent order #{{order_increment_id}} for {{products}}
has been declined by Riskified service.]]>
+ {{store_name}}: Order # {{order_increment_id}} has been declined
+ We regret to inform you that your recent order #{{order_increment_id}} for {{products}}
has been declined.]]>