sveawebpay / php-integration

SDK for Sveas payment methods (standalone and Svea Checkout)
Other
15 stars 19 forks source link

individualCustomer() and companyCustomer() merged #15

Closed timint closed 9 years ago

timint commented 11 years ago

I assume the need to solve the logic is what makes us have to separate the behaviors for creating an order using the SWP framework.

However I find the two methods individualCustomer() and companyCustomer() possible to merge.

A universal method could something like this:

Proposal:

->addCustomerDetails( Item::Customer() ->setTaxId("000000-0000") ->setCompanyName("ACME Inc.") // Required if TaxId validates as comany ->setName("John", "Doe") ->setCoAddress("c/o Simpsons") ->setStreetAddress("Street", 7) ->setZipCode(9999) ->setLocality("Timbuktu") ->setEmail("john@acme.com")
->setIpAddress("0.0.0.0") ->setPhoneNumber(081234567) )

Hypothetical changes from merging individualCustomer() and companyCustomer():

Benefits for the store / user-end:

How to tell if a swedish tax Id is a company or individual. http://sv.wikipedia.org/wiki/Organisationsnummer

VATIN formats http://en.wikipedia.org/wiki/VAT_identification_number

If birthdays cannot be extracted from NL or DE individuals Id-numbers I suppose the setBirthDate must stick.

Thoughts?

nlii commented 11 years ago

We have discussed this problem quite a lot. The difficult is that how ever we solve this, quite a lot of logic will be needed to decide what kind of data is neccesary. The credit check companies requirers different data depending on country and customertype.

For Sweden only social security number for private customers is required for example.

I will mark this as "feature suggestion" thought, because there are som things worth to reevaluate.

Prestaworks commented 11 years ago

I aggre that the setStreetAddress should accept both ("Gatan 23") or ("Gatan", 23) since 23 is an int, what if the adress is "Gatan 3A"?

timint commented 10 years ago

To push for this feature, I am donating an old piece of code regarding personnr/orgnr. Prolly 6 years old just gaining dust.

function TiM_crn_info($crn, $country_code) {

  switch ($country_code) {

    case 'SE':

    // Remove dash
      $crn = str_replace(array('-', ' '), '', $crn);

    // Make sure 10 or 12 digits
      if (!preg_match('/^[0-9]{10}$/', $crn) && !preg_match('/^[0-9]{12}$/', $crn)) return false;

    // Prepend century digits if missing
      if (strlen($crn) == 10) {

        if (substr($crn, 2, 2) > 19) {
          $crn = '16' . $crn;

        } else if (date('y') < substr($crn, 0, 2)) {
          $crn = '19' . $crn;
        } else {
          $crn = '20' . $crn;
        }
      }

    // Check century digits
      if (!in_array(substr($crn, 0, 2), array('16', '19', '20'))) return false;

    // Validate modulus-10
      $n = 2;
      for ($i=2; $i<11; $i++) {
        $tmp = $crn[$i] * $n;
        ($tmp > 9) ? $sum += 1 + ($tmp % 10) : $sum += $tmp;
        ($n == 2) ? $n = 1 : $n = 2;
      }
      if (($sum + $crn[11]) % 10) return false;

    // Extract company info
      if (substr($crn, 0, 2) == '16') {

        $info['type'] = 'company';

        switch(substr($crn, 2, 1)) {
          case '2':
            $info['gender'] = 'governmental'; // Stat / Landsting / Kommun
            break;
          case '5':
            $info['gender'] = 'incorporated'; // Aktiebolag
            break;
          case '7':
            $info['gender'] = 'association'; // Ekonomisk förening
            break;
          case '8':
            $info['gender'] = 'foundation'; // Stiftelse / Ideell förening
            break;
          case '9':
            $info['gender'] = 'partnership'; // Handels- / Kommanditbolag
            break;
        }

    // Extract individual or coordination info
      } else if (in_array(substr($crn, 0, 2), array(18, 19, 20))) {

    // Check if coordination
      if (substr($crn, 6, 2)-60 > 0) {
        $info['type'] = 'coordination';
      } else {
        $info['type'] = "individual";
      }

    // Extract year of birth
      $info['year'] = substr($crn, 0, 4);

    // Extract month of birth 
      $info['month']  = substr($crn, 4, 2);

    // Extract day of birth
      if ($info['type'] == "coordination") {
        $info['day'] = substr($crn, 6, 2)-60;
      } else {
        $info['day'] = substr($crn, 6, 2);
      }

    // Extract age
        $info['age'] = date('Y') - $info['year'];
        if ($info['month'] > date('m')) {
          $info['age']--;
        } else if ($info['month'] == date('m') && $info['day'] < date('d')) {
          $info['age']--;
        }

      // Extract gender
        if (in_array(substr($crn, 10, 1), array(1,3,5,7,9))) {
          $info['gender'] = 'male';
        } else {
          $info['gender'] = 'female';
        }
      }

    // Format civic registration number
      $info['crn10'] = substr($crn, 2, 6) .'-'. substr($crn, 8, 4);
      $info['crn12'] = substr($crn, 0, 8) .'-'. substr($crn, 8, 4);

      return $info;

    default:
      return false;
  }
}

Supports any input like 16550000-1234, 197000001234, 5500001234, 700000-1234.

Usage: $crn_info = TiM_crn_info($pno);

The code can be optimized/reduced a lot by making use of preg_replace() in many scenarios. At the time of coding, my regexp skills were limited.

kilskrift commented 9 years ago

Just a heads-up to say that for some time now, the IndividualCustomer and CompanyCustomer classes setStreetAddress($street, $housenumber) method has accepted one or two arguments .

If no housenumber is given, the entire street address including any housenumber can be found in street attribute, with housenumber set to null.

The recommended way is to use a single argument, unless your customer is based in NL or DE.

/kgm