Results 1 to 6 of 6

Threaded View

  1. #1
    Join Date
    Feb 2017
    Location
    Tokyo, Japan
    Posts
    267
    Plugin Contributions
    0

    Default Requirement for state setting in Paypal modules, for certain countries?

    Hello,
    This is a question about whether to se address_state as used for Paypal Express Checkout (paypalwpp.php) and Paypal Website Payments Pro (paypaldp.php), and if so, how best one might set it for Japanese states (prefectures):

    General Information about my setup:
    * URL: My site is currently not available publicly (Japanese version development in progress).
    * ZenCart version: 1.5.5e
    * Server OS: Linux 4.13.0-1-amd64
    * HTTP Server: nginx/1.13.6
    * PHP Version: 7.0.22-3 (Zend: 3.0.0)
    * Database: MySQL 5.5.5-10.1.28-MariaDB-1
    * Plugins: Multi Language EZ Pages, Multi Language Country Names
    * Other: Japanese language module, ported from 1.5.1-jp and in development (Ref: Future Japanese language pack thread: https://www.zen-cart.com/showthread....5-5-and-beyond).

    In paypalwpp.php (and paypaldp.php) the function setStateAndCountry sets the state (not country as far as I can tell, which is already defined by the 2-letter ISO code by this stage apparently) to send to Paypal:
    Code:
      /**
       * Set the state field depending on what PayPal requires for that country.
       * The shipping address state or province is required if the address is in one of the following countries: Argentina, Brazil, Canada, China, Indonesia, India, Japan, Mexico, Thailand, USA
       * https://developer.paypal.com/docs/classic/api/state_codes/
       */
      function setStateAndCountry(&$info) {
        global $db, $messageStack;
        switch ($info['country']['iso_code_2']) {
          case 'AU':
          case 'US':
          case 'CA':
          // Paypal only accepts two character state/province codes for some countries.
          if (strlen($info['state']) > 2) {
            $sql = "SELECT zone_code FROM " . TABLE_ZONES . " WHERE zone_name = :zoneName";
            $sql = $db->bindVars($sql, ':zoneName', $info['state'], 'string');
            $state = $db->Execute($sql);
            if (!$state->EOF) {
              $info['state'] = $state->fields['zone_code'];
            } else {
              $messageStack->add_session('header', MODULE_PAYMENT_PAYPALWPP_TEXT_STATE_ERROR, 'error');
              $this->terminateEC(MODULE_PAYMENT_PAYPALWPP_TEXT_STATE_ERROR);
            }
          }
          break;
          case 'AT':
          case 'BE':
          case 'FR':
          case 'DE':
          case 'CH':
          $info['state'] = '';
          break;
          case 'GB':
          break;
          default:
          $info['state'] = '';
        }
      }
    Questions:
    1. Is the state required for the countries on the list in the comment section? Japan is on the list, but not in the switch statement.
    2. If so, it seems that except for Australia. USA and Canada, the state is not being set. I cannot identify if there are differences in the behaviour for other countries listed there (GB seeems to break without setting anything, although how this is different from setting an empty string I don't understand).
    3. In particular, I am wanting to identify if the state needs to be set for Japan (and if so, how to best go about that).

    Looking at Paypal NVP/SOAP API documents, I do not find any information about whether address_state is required (on the other hand, I do see that regarding countries, for some countries setting the country code is required, but most do not appear to be). However, if one does set the state, Paypal docs show that for Japan the code to be sent must be in capital letters as follows:
    Most are of the pattern <NAME>-KEN, plus the special cases HOKKAIDO, OSAKA-FU, KYOTO-FU and TOKYO-TO.

    Now, if one does not need to send the names, all is fine, but if one does need to send them, then there is an issue that the code required for Paypal does not match the code best suited for address and other uses in Zen Cart.
    Additionally, since I have made country names and zone (=state) names multi-language, depending on the language chosen for viewing the website (English or Japanese), the state code would be either in English or in Japanese.

    One way to work around this I guess would be to put the Paypal-required state name in the ZONES table, while the language-dependent zone names are in the new extended ZONES tables (ZONES_NAME in my case). A bit of a hack, as it requires the implementation of multi-language zones first. Or else to create a new lookup table for the Paypal module to use.
    Even better would be (providing I understand correctly) if Paypal would use ISO codes for the states, like they want for countries. In that case the original ZONES could be extended to include the ISO code, or extended multi language ZONES table could be used (I created it containing the state ISO code) regardless of language.

    Any advice, explanations (regarding the status of the modules, for example), other tips much appreciated.
    Reference: https://developer.paypal.com/docs/cl...i/state_codes/

    Gernot Hassenpflug
    Last edited by gernot; 3 Nov 2017 at 02:48 PM.

 

 

Similar Threads

  1. Replies: 1
    Last Post: 5 May 2016, 01:25 AM
  2. Exclude tax for certain countries (language)
    By Mats369 in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 3
    Last Post: 1 Sep 2014, 09:57 PM
  3. v151 Only allow certain shipping methods for some countries?
    By doooomed in forum Built-in Shipping and Payment Modules
    Replies: 8
    Last Post: 1 Oct 2013, 12:30 AM
  4. v151 Can I restrict certain shipping modules for certain products?
    By gumboot in forum Built-in Shipping and Payment Modules
    Replies: 10
    Last Post: 13 Feb 2013, 05:26 AM
  5. Checkout process doesn't progress for certain countries
    By brettdporter in forum Built-in Shipping and Payment Modules
    Replies: 3
    Last Post: 6 Feb 2007, 08:34 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR