Skip to content

Commit

Permalink
Supported common messages customization.
Browse files Browse the repository at this point in the history
  • Loading branch information
fraudlabspro committed Jun 28, 2021
1 parent 37b91ae commit f1c0315
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 9 deletions.
24 changes: 18 additions & 6 deletions Block/Fraudlabsprosmsverification.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ public function methodBlock()
Your phone has been successfully verified. Thank you.
</div>';
} elseif ( $flpdata['fraudlabspro_sms_email_code'] == $sms_code ) {
$msgOtpSuccess = ($this->getConfig()->getValue('fraudlabsprosmsverification/active_display/msg_otp_success')) ? ($this->getConfig()->getValue('fraudlabsprosmsverification/active_display/msg_otp_success')) : 'A SMS containing the OTP (One Time Passcode) has been sent to {phone}. Please enter the 6 digits OTP value to complete the verification.';
if (strpos($msgOtpSuccess, '{phone}') === false) {
$msgOtpSuccess = 'A SMS containing the OTP (One Time Passcode) has been sent to {phone}. Please enter the 6 digits OTP value to complete the verification.';
}
$msgOtpSuccess = explode("{phone}", $msgOtpSuccess);
$msgOtpFail = ($this->getConfig()->getValue('fraudlabsprosmsverification/active_display/msg_otp_fail')) ? ($this->getConfig()->getValue('fraudlabsprosmsverification/active_display/msg_otp_fail')) : 'Error: Unable to send the SMS verification message to {phone}.';
if (strpos($msgOtpFail, '{phone}') === false) {
$msgOtpFail = 'Error: Unable to send the SMS verification message to {phone}.';
}
$msgOtpFail = explode("{phone}", $msgOtpFail);
$msgInvalidPhone = ($this->getConfig()->getValue('fraudlabsprosmsverification/active_display/msg_invalid_phone')) ? ($this->getConfig()->getValue('fraudlabsprosmsverification/active_display/msg_invalid_phone')) : 'Please enter a valid phone number.';
$msgInvalidOtp = ($this->getConfig()->getValue('fraudlabsprosmsverification/active_display/msg_invalid_otp')) ? ($this->getConfig()->getValue('fraudlabsprosmsverification/active_display/msg_invalid_otp')) : 'Error: Invalid OTP. Please enter the correct OTP.';
return '
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.5/js/intlTelInput.min.js"></script>
Expand Down Expand Up @@ -97,7 +109,7 @@ public function methodBlock()
jQuery("#get_otp").click(function(e) {
if (jQuery("#phone_number").val() == "") {
jQuery("#sms_err").html("Please enter a valid phone number.");
jQuery("#sms_err").html("' . $msgInvalidPhone . '");
jQuery("#sms_err").show();
jQuery("#phone_number").focus();
} else if (!confirm("Send OTP to " + phoneNum.getNumber() + "?")) {
Expand Down Expand Up @@ -144,7 +156,7 @@ public function methodBlock()
} else if (jQuery.trim(jQuery("#sms_verified").val()) == "") {
jQuery(".btn-checkout").prop("disabled",true);
jQuery("#sms_otp2").focus();
document.getElementById("verifysms").scrollIntoView(true);*/
document.getElementById("verifysms").scrollIntoView(true);
}
function doOTP() {
Expand All @@ -166,7 +178,7 @@ function doOTP() {
function sms_doOTP_success(data) {
if (data.includes("FLPOK")) {
var num = data.search("FLPOK");
alert("A verification SMS has been sent to " + phoneNum.getNumber() + ".");
alert("' . $msgOtpSuccess[0] . '" + phoneNum.getNumber() + "' . $msgOtpSuccess[1] . '");
jQuery("#sms_tran_id").val(data.substr(num+5, 20));
jQuery("#get_otp").hide();
jQuery("#sms_err").hide();
Expand All @@ -177,13 +189,13 @@ function sms_doOTP_success(data) {
jQuery("#phone_number").prop("disabled", true);
jQuery("#sms_otp1").prop("disabled", true);
} else {
jQuery("#sms_err").html("Error: Unable to send the SMS verification message to " + phoneNum.getNumber() + ".");
jQuery("#sms_err").html("' . $msgOtpFail[0] . '" + phoneNum.getNumber() + "' . $msgOtpFail[1] . '");
jQuery("#sms_err").show();
}
}
function sms_doOTP_error() {
jQuery("#sms_err").html("Error: Unable to send the SMS verification message to " + phoneNum.getNumber() + ".");
jQuery("#sms_err").html("' . $msgOtpFail[0] . '" + phoneNum.getNumber() + "' . $msgOtpFail[1] . '");
jQuery("#sms_err").show();
}
Expand Down Expand Up @@ -223,7 +235,7 @@ function sms_checkOTP_success(data) {
var url = window.location.href + "&phone=" + phoneNum.getNumber();
window.location.href = url;
} else if (data.includes("ERROR 601")) {
jQuery("#sms_err").html("Error: Invalid OTP. Please enter the correct OTP.");
jQuery("#sms_err").html("' . $msgInvalidOtp . '");
jQuery("#sms_err").show();
} else {
jQuery("#sms_err").html("Error: Error while performing verification.");
Expand Down
15 changes: 15 additions & 0 deletions Block/Fraudlabsprosmsverificationverify.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,26 @@
class Fraudlabsprosmsverificationverify extends \Magento\Framework\View\Element\Template
{

protected $orderRepository ;
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
array $data = []
) {
$this->orderRepository = $orderRepository;
parent::__construct($context, $data);
}

public function getConfig()
{
return $this->_scopeConfig;
}

public function getOrder($id)
{
return $this->orderRepository->get($id);
}

public function methodBlock()
{
$apiKey = ($this->getConfig()->getValue('fraudlabsprosmsverification/active_display/api_key')) ? $this->getConfig()->getValue('fraudlabsprosmsverification/active_display/api_key') : 'API Key cannot be empty.';
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ Revision History for FraudLabs Pro Magento 2
Add default country code for SMS sending.

1.1.3 2021-03-31
Improve SMS verification process.
Improve SMS verification process.

1.2.0 2021-06-25
Support common messages customization.
4 changes: 3 additions & 1 deletion Controller/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ public function sendRequestToFraudLabsProSmsVerification($observer) {
private function randomCode($length=16){
$key = '';
$pattern = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
for($i=0; $i<$length; $i++) $key .= $pattern{rand(0, strlen($pattern)-1)};
for($i=0; $i<$length; $i++) {
$key .= $pattern[rand(0, strlen($pattern)-1)];
}
return $key;
}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "hexasoft/module-fraudlabsprosmsverification",
"description": "FraudLabs Pro SMS Verification extension for Magento 2 that help merchants to authenticate the client's identity by sending them a SMS for verification.",
"version": "1.1.3",
"version": "1.2.0",
"type": "magento2-module",
"require": {
"php": "~5.5.0|~5.6.0|~7.0"
Expand Down
16 changes: 16 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@
<label>Email Body</label>
<comment><![CDATA[Content of the mail. The <strong>{email_verification_link}</strong> tag will be automatically replaced with the page URL for SMS verification, and must not be removed from the email body.]]></comment>
</field>
<field id="msg_otp_success" translate="label" type="textarea" sortOrder="9" showInDefault="1" showInWebsite="1" showInStore="1">
<label>OTP Sent Succesfully Message</label>
<comment><![CDATA[Messages to show the user when the OTP is sent successfully to the phone number. You must include the {phone} tag which will be replaced by the user's phone number.]]></comment>
</field>
<field id="msg_otp_fail" translate="label" type="textarea" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>OTP Sent Failed Message</label>
<comment><![CDATA[Messages to show the user when the OTP is sent failed to the phone number. You must include the {phone} tag which will be replaced by the user's phone number.]]></comment>
</field>
<field id="msg_invalid_phone" translate="label" type="textarea" sortOrder="11" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Invalid Phone Number Message</label>
<comment><![CDATA[Messages to show the user when invalid phone number is entered.]]></comment>
</field>
<field id="msg_invalid_otp" translate="label" type="textarea" sortOrder="12" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Invalid OTP Message</label>
<comment><![CDATA[Messages to show the user when invalid OTP is entered.]]></comment>
</field>
</group>
</section>
</system>
Expand Down
4 changes: 4 additions & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
<otp_timeout>3600</otp_timeout>
<email_subject>Action Required: SMS Verification is required to process the order.</email_subject>
<email_body>Dear Customer, Thanks for your business. Before we can continue processing your order, you may require you to click on the link to complete the SMS verification: {email_verification_link} Thank you.</email_body>
<msg_otp_success>A SMS containing the OTP (One Time Passcode) has been sent to {phone}. Please enter the 6 digits OTP value to complete the verification.</msg_otp_success>
<msg_otp_fail>Error: Unable to send the SMS verification message to {phone}.</msg_otp_fail>
<msg_invalid_phone>Please enter a valid phone number.</msg_invalid_phone>
<msg_invalid_otp>Error: Invalid OTP. Please enter the correct OTP.</msg_invalid_otp>
</general>
</fraudlabsprosmsverification>
</default>
Expand Down

0 comments on commit f1c0315

Please sign in to comment.