Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions cartridges/int_tamara_core/cartridge/scripts/util/tamaraHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -929,8 +929,11 @@ var tamaraHelperObj = {
(available_payment_label) => {
if (available_payment_label["payment_type"] === this.PAY_NOW) {
paymentTypes.isEnablePaynow = true;
paymentTypes[this.METHOD_TAMARA_PAYNOW] =
available_payment_label["description_en"];
if (tamaraHelperObj.getCurrentLangCode() === "ar") {
paymentTypes[this.METHOD_TAMARA_PAYNOW] = available_payment_label["description_ar"];
} else {
paymentTypes[this.METHOD_TAMARA_PAYNOW] = available_payment_label["description_en"];
}
}

if (
Expand All @@ -939,8 +942,11 @@ var tamaraHelperObj = {
available_payment_label["instalment"] === 0
) {
paymentTypes.isEnableTamaraPay = true;
paymentTypes[this.METHOD_PAY_BY_INSTALMENTS] =
available_payment_label["description_en"];
if (tamaraHelperObj.getCurrentLangCode() === "ar") {
paymentTypes[this.METHOD_PAY_BY_INSTALMENTS] = available_payment_label["description_ar"];
} else {
paymentTypes[this.METHOD_PAY_BY_INSTALMENTS] = available_payment_label["description_en"];
}
}

if (
Expand All @@ -949,8 +955,11 @@ var tamaraHelperObj = {
available_payment_label["instalment"] === 3
) {
paymentTypes.isEnableInstalments = true;
paymentTypes[this.METHOD_TAMARA_INSTALMENTS] =
available_payment_label["description_en"];
if (tamaraHelperObj.getCurrentLangCode() === "ar") {
paymentTypes[this.METHOD_TAMARA_INSTALMENTS] = available_payment_label["description_ar"];
} else {
paymentTypes[this.METHOD_TAMARA_INSTALMENTS] = available_payment_label["description_en"];
}
}

if (
Expand All @@ -959,8 +968,11 @@ var tamaraHelperObj = {
available_payment_label["instalment"] === 6
) {
paymentTypes.is6InstalmentsEnabled = true;
paymentTypes[this.METHOD_TAMARA_6_INSTALMENTS] =
available_payment_label["description_en"];
if (tamaraHelperObj.getCurrentLangCode() === "ar") {
paymentTypes[this.METHOD_TAMARA_6_INSTALMENTS] = available_payment_label["description_ar"];
} else {
paymentTypes[this.METHOD_TAMARA_6_INSTALMENTS] = available_payment_label["description_en"];
}
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
var Resource = require("dw/web/Resource");
var Transaction = require("dw/system/Transaction");
var tamaraHelper = require("*/cartridge/scripts/util/tamaraHelper");

const errorMessageMap = {
"amount_is_higher_than_max_limit": "error.amount_is_higher_than_max_limit",
"consumer_empty_first_name": "error.consumer_empty_first_name",
"consumer_invalid_phone_number": "error.consumer_invalid_phone_number",
"consumer_invalid_email": "error.consumer_invalid_email",
"consumer_empty_email": "error.consumer_empty_email",
"total_amount_invalid_currency": "error.total_amount_invalid_currency",
"not_supported_delivery_country": "error.not_supported_delivery_country"
};

/**
* Creates a token. This should be replaced by utilizing a tokenization provider
* @returns {string} a token
Expand Down Expand Up @@ -98,7 +109,21 @@ function Authorize(orderNumber, paymentInstrument, paymentProcessor) {
});
} catch (e) {
error = true;
serverErrors.push(Resource.msg("error.technical", "checkout", null));
if (e.message) {
const errorKey = Object.keys(errorMessageMap).find(key => e.message.includes(key));
if (errorKey) {
const errorMessage = errorMessageMap[errorKey];
if (errorMessage) {
serverErrors.push(Resource.msg(errorMessage, "tamara", null));
} else {
serverErrors.push(Resource.msg("error.technical", "checkout", null));
}
} else {
serverErrors.push(Resource.msg("error.technical", "checkout", null));
}
} else {
serverErrors.push(Resource.msg("error.technical", "checkout", null));
}
tamaraHelper
.getTamaraLogger()
.error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ note.content.tamara.capture=[Tamara] Capture from Tamara successfully
note.content.tamara.refund=[Tamara] Refund from Tamara successfully
note.content.tamara.createsession=[Tamara] Create Checkout Session successfully. Triger from tamara.js - Authorize Hook.


error.amount_is_higher_than_max_limit=Oops! It seems like your cart value exceeds your maximum limit to pay using Tamara.
error.consumer_empty_first_name=Oops! It seems like your first name is empty.
error.consumer_invalid_phone_number=Oops! Your phone number is invalid. Please provide a valid phone number to continue.
error.consumer_invalid_email=Oops! Your email is invalid. Please provide a valid email to continue.
error.consumer_empty_email=Oops! Your email is empty. You need to provide your email to continue.
error.total_amount_invalid_currency=Oops! The currency is invalid.
error.not_supported_delivery_country= Oops! It seems like your country is not supported by Tamara.
error.paymenttypes.outoflist=The Paymentmethod doesn't support by Tamara
display.description.on.tamara=The order {0} ({1}) is placed from {2}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error.amount_is_higher_than_max_limit=عذرًا! يبدو أن قيمة سلتك تتجاوز الحد الأقصى المسموح به للدفع باستخدام تمارا.
error.consumer_empty_first_name=عذرًا! يبدو أن اسمك الأول فارغ.
error.consumer_invalid_phone_number=عذرًا! رقم هاتفك غير صالح. يرجى تقديم رقم هاتف صحيح للمتابعة.
error.consumer_invalid_email=عذرًا! بريدك الإلكتروني غير صحيح. يرجى إدخال بريد إلكتروني صحيح للمتابعة.
error.consumer_empty_email=عذرًا! لايوجد لديك بريد إلكتروني. يجب أن يكون لديك بريد إلكتروني للمتابعة.
error.total_amount_invalid_currency=عذرًا! العُملة غير صالحة.
error.not_supported_delivery_country=عذرًا! يبدو أن بلدك غير مدعوم من قبل تمارا.