0

For some Reasons when I use OnTap MasterCard Extension, Any Arabic characters in shippment addresses throws an error:

INVALID_REQUEST: Field [order.avsDetails.billToFirstname] was not in charset [ISO-8859-1]

The extension link :

https://marketplace.magento.com/ontap-module-mastercard.html

Please help.

Jsparo30
  • 405
  • 4
  • 10
  • 30
  • Looks like an encoding problem, however is strange that the extension is requesting specifically `ISO-8859-1` as an encoding, what is the encoding of your tables in the database? – oirad Apr 18 '17 at 05:41
  • Encoding of tables: `utf8_general_ci`, and encoding of database : `utf8mb4` – Jsparo30 Apr 18 '17 at 09:49
  • That looks correct, if I were you I would try contacting the person that created that extension directly. – oirad Apr 18 '17 at 15:09
  • I tried alot to contact with him and they didn't reply. The don't present any support as they advertise that in the extension home page `https://marketplace.magento.com/ontap-module-mastercard.html`. can you help ? – Jsparo30 Apr 18 '17 at 15:13
  • I downloaded the extension, but since I will not be able to test it fully myself can you provide the full stack trace (omitting sensitive informations)? As well can you please provide information on when does the happen exactly? (I can see that a request is sent for Capture, Sale, or Verification and is built using the builder classes that you find inside `Gateway/Request`) – oirad Apr 18 '17 at 15:48
  • Thanks for your help. Firstly, I used `Hosted session form` in backend. Secondly the problem happened when I enter any Arabic words or characters in the shipping or billing information. when I enter the data (the master input, expiration date, card verification, then it redirects to a popup of ACS Emulator which following the MASTER/VISA, then choose successful authentication, then authentication is done successfully , then redirect to checkout page and got the error. If I entered an English data in billing or shipping addresses, there is no error happens. – Jsparo30 Apr 18 '17 at 16:00
  • yes, looks like the error does not come from the extension itself but from mastercard that does not accept those characters, so you will need to either modify the extension to encode all the data in the "correct" encoding in the builders, but not sure how will this data look like when is sent to the mastercard API afterwards. – oirad Apr 18 '17 at 16:39

1 Answers1

1

You can try encoding the data generated in the Builders (inside the Gateway/Request folder) by using plugins.

You can read more how to create plugins here that perform the encoding on all the fields in the builders when needed.

You will create a new module that is doing the modifications needed on the extension you took from the market.

To define your builder in this case your di.xml will look something like:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="\OnTap\MasterCard\Gateway\Request\ShippingDataBuilder">
        <plugin name="jsparo_ontap_mastercard_gateway_request_shippingdatabuilder" type="Jsparo\MasterCard\Plugin\Gateway\Request\ShippingDataBuilder" sortOrder="1"/>
    </type>
</config>

And the Plugin/Gateway/Request/ShippingDataBuilder.php that you will be something like:

<?php
namespace Jsparo\MasterCard\Plugin\Gateway\Request;
class ShippingDataBuilder {
    public function afterBuild(array $subject, $result) {
        array_walk_recursive($result, function(&$value) {
            $value = mb_convert_encoding($value, 'ISO-8859-1', 'UTF-8');
        }
        return $result;
    }
}

You will have to do this for all the builders that generate incorrect data.

oirad
  • 587
  • 5
  • 7
  • Thank you, I tried the solution, in Arabic is worked fine but when return back to test English words got this error `[ISO-8859-1]The operation was declined or rejected by the gateway, acquirer or issuer Internal system error occurred processing the transaction` – Jsparo30 Apr 18 '17 at 18:44
  • Do you get any errors in your logs (check both your webserver and your magento logs), because this error says that either the gateway has problems with the encoding or your server returned a 500 / other error when checking the returned data. – oirad Apr 19 '17 at 02:19
  • My server does not return any error, just the log has the error `[ISO-8859-1]The operation was declined or rejected by the gateway, acquirer or issuer Internal system error occurred processing the transaction` – Jsparo30 Apr 19 '17 at 08:28
  • In this case you probably have to find out if the data you are sending contains characters that are not correctly recognized, and change them only in that specific case. I don't have any experience with arabic language so is a bit difficult from my side helping you further. You can however find some other solutions searching on [stackoverflow](http://stackoverflow.com/questions/19141075/why-doesnt-mb-ereg-detect-arabic-characters). Let me know if you solve it. – oirad Apr 19 '17 at 13:05
  • Yes already I did it yesterday, I could check by `'firstName' => mb_detect_encoding($billingAddress->getFirstname(), "auto") == 'UTF-8' ? mb_convert_encoding($billingAddress->getFirstname(), 'ISO-8859-1', 'UTF-8') : $billingAddress->getFirstname(),` in ciustomerDataBuilder.php. but in english words it threw `The operation was declined or rejected by the gateway, acquirer or issuer Internal system error occurred processing the transaction`. – Jsparo30 Apr 19 '17 at 18:44
  • OHHH, I removed the plugin and rollback to the original files and in English and Arabic words got this error. `The operation was declined or rejected by the gateway, acquirer or issuer Internal system error occurred processing the transaction` – Jsparo30 Apr 19 '17 at 19:06
  • Uhm looks like you have some different problem if you removed the custom module you did, are you sure you cleaned up the other module correctly? – oirad Apr 20 '17 at 05:31
  • Just go back to your previous git commit (or revert if your are using svn) – oirad Apr 20 '17 at 09:03
  • Thank you for your help bro. Yes, I tried that and made upgrade and di:compile and works well now on English data. but still got the first error on Arabic data. `INVALID_REQUEST: Field [order.avsDetails.billToFirstname] was not in charset [ISO-8859-1]`. Do you have any another idea? – Jsparo30 Apr 20 '17 at 09:06
  • Maybe try to only encode again the billing first name and last name, those might be the only fields that require the different encoding, or try to look at mastercard developer documentation to see if you find any clues. – oirad Apr 20 '17 at 14:34
  • I think the best way is reading the official documentation (that now is pretty well done) and the core code, each time you want to develop a specific function you can check examples on how to do in the core and follow what the magento core developers did there. – oirad Apr 21 '17 at 06:27
  • Hi Oirad, Could you please check this link: [http://stackoverflow.com/questions/43888186/magento-2-save-tokenization-and-order-details-rest-api] – Jsparo30 May 10 '17 at 09:16