diff --git a/cartridges/int_tamara_core/cartridge/scripts/util/tamaraHelper.js b/cartridges/int_tamara_core/cartridge/scripts/util/tamaraHelper.js index 31d337f..68f30e2 100644 --- a/cartridges/int_tamara_core/cartridge/scripts/util/tamaraHelper.js +++ b/cartridges/int_tamara_core/cartridge/scripts/util/tamaraHelper.js @@ -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 ( @@ -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 ( @@ -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 ( @@ -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"]; + } } } ); diff --git a/cartridges/int_tamara_sfra/cartridge/scripts/hooks/payment/processor/tamara.js b/cartridges/int_tamara_sfra/cartridge/scripts/hooks/payment/processor/tamara.js index 2a36d6b..03eff3f 100644 --- a/cartridges/int_tamara_sfra/cartridge/scripts/hooks/payment/processor/tamara.js +++ b/cartridges/int_tamara_sfra/cartridge/scripts/hooks/payment/processor/tamara.js @@ -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 @@ -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( diff --git a/cartridges/int_tamara_sfra/cartridge/templates/resources/tamara.properties b/cartridges/int_tamara_sfra/cartridge/templates/resources/tamara.properties index 53f3269..0ee4986 100644 --- a/cartridges/int_tamara_sfra/cartridge/templates/resources/tamara.properties +++ b/cartridges/int_tamara_sfra/cartridge/templates/resources/tamara.properties @@ -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} diff --git a/cartridges/int_tamara_sfra/cartridge/templates/resources/tamara_ar.properties b/cartridges/int_tamara_sfra/cartridge/templates/resources/tamara_ar.properties new file mode 100644 index 0000000..18bcfd8 --- /dev/null +++ b/cartridges/int_tamara_sfra/cartridge/templates/resources/tamara_ar.properties @@ -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=عذرًا! يبدو أن بلدك غير مدعوم من قبل تمارا. \ No newline at end of file