berenddeboer,
I want to congratulate you on the module. It does so much and it's still in 1.x-dev !
I am facing a problem with the module. When it receives payment data from 2checkout, the country code is converted from 3-character format to 2-character format by removing the extra character.
I saw in your comments that you're not sure how to do this properly, so here is what I suggest:
We can use the ISO31661 standard which gives each country a 3-character and a corresponding 2-character code.
I have tried to implement this by using an array, however it just crashes (I'm not good with PHP).
This is the array:
$iso_code = array("ALA"=>"AX","AFG"=>"AF","ALB"=>"AL","DZA"=>"DZ","ASM"=>"AS","AND"=>"AD","AGO"=>"AO","AIA"=>"AI","ATA"=>"AQ","ATG"=>"AG","ARG"=>"AR","ARM"=>"AM","ABW"=>"AW","AUS"=>"AU","AUT"=>"AT","AZE"=>"AZ","BHS"=>"BS","BHR"=>"BH","BGD"=>"BD","BRB"=>"BB","BLR"=>"BY","BEL"=>"BE","BLZ"=>"BZ","BEN"=>"BJ","BMU"=>"BM","BTN"=>"BT","BOL"=>"BO","BIH"=>"BA","BWA"=>"BW","BVT"=>"BV","BRA"=>"BR","IOT"=>"IO","BRN"=>"BN","BGR"=>"BG","BFA"=>"BF","BDI"=>"BI","KHM"=>"KH","CMR"=>"CM","CAN"=>"CA","CPV"=>"CV","CYM"=>"KY","CAF"=>"CF","TCD"=>"TD","CHL"=>"CL","CHN"=>"CN","CXR"=>"CX","CCK"=>"CC","COL"=>"CO","COM"=>"KM","COD"=>"CD","COG"=>"CG","COK"=>"CK","CRI"=>"CR","CIV"=>"CI","HRV"=>"HR","CUB"=>"CU","CYP"=>"CY","CZE"=>"CZ","DNK"=>"DK","DJI"=>"DJ","DMA"=>"DM","DOM"=>"DO","ECU"=>"EC","EGY"=>"EG","SLV"=>"SV","GNQ"=>"GQ","ERI"=>"ER","EST"=>"EE","ETH"=>"ET","FLK"=>"FK","FRO"=>"FO","FJI"=>"FJ","FIN"=>"FI","FRA"=>"FR","GUF"=>"GF","PYF"=>"PF","ATF"=>"TF","GAB"=>"GA","GMB"=>"GM","GEO"=>"GE","DEU"=>"DE","GHA"=>"GH","GIB"=>"GI","GRC"=>"GR","GRL"=>"GL","GRD"=>"GD","GLP"=>"GP","GUM"=>"GU","GTM"=>"GT","GIN"=>"GN","GNB"=>"GW","GUY"=>"GY","HTI"=>"HT","HMD"=>"HM","HND"=>"HN","HKG"=>"HK","HUN"=>"HU","ISL"=>"IS","IND"=>"IN","IDN"=>"ID","IRN"=>"IR","IRQ"=>"IQ","IRL"=>"IE","ISR"=>"IL","ITA"=>"IT","JAM"=>"JM","JPN"=>"JP","JOR"=>"JO","KAZ"=>"KZ","KEN"=>"KE","KIR"=>"KI","PRK"=>"KP","KOR"=>"KR","KWT"=>"KW","KGZ"=>"KG","LAO"=>"LA","LVA"=>"LV","LBN"=>"LB","LSO"=>"LS","LBR"=>"LR","LBY"=>"LY","LIE"=>"LI","LTU"=>"LT","LUX"=>"LU","MAC"=>"MO","MKD"=>"MK","MDG"=>"MG","MWI"=>"MW","MYS"=>"MY","MDV"=>"MV","MLI"=>"ML","MLT"=>"MT","MHL"=>"MH","MTQ"=>"MQ","MRT"=>"MR","MUS"=>"MU","MYT"=>"YT","MEX"=>"MX","FSM"=>"FM","MDA"=>"MD","MCO"=>"MC","MNG"=>"MN","MSR"=>"MS","MAR"=>"MA","MOZ"=>"MZ","MMR"=>"MM","NAM"=>"NA","NRU"=>"NR","NPL"=>"NP","NLD"=>"NL","ANT"=>"AN","NCL"=>"NC","NZL"=>"NZ","NIC"=>"NI","NER"=>"NE","NGA"=>"NG","NIU"=>"NU","NFK"=>"NF","MNP"=>"MP","NOR"=>"NO","OMN"=>"OM","PAK"=>"PK","PLW"=>"PW","PSE"=>"PS","PAN"=>"PA","PNG"=>"PG","PRY"=>"PY","PER"=>"PE","PHL"=>"PH","PCN"=>"PN","POL"=>"PL","PRT"=>"PT","PRI"=>"PR","QAT"=>"QA","REU"=>"RE","ROU"=>"RO","RUS"=>"RU","RWA"=>"RW","SHN"=>"SH","KNA"=>"KN","LCA"=>"LC","SPM"=>"PM","VCT"=>"VC","WSM"=>"WS","SMR"=>"SM","STP"=>"ST","SAU"=>"SA","SEN"=>"SN","SCG"=>"CS","SYC"=>"SC","SLE"=>"SL","SGP"=>"SG","SVK"=>"SK","SVN"=>"SI","SLB"=>"SB","SOM"=>"SO","ZAF"=>"ZA","SGS"=>"GS","ESP"=>"ES","LKA"=>"LK","SDN"=>"SD","SUR"=>"SR","SJM"=>"SJ","SWZ"=>"SZ","SWE"=>"SE","CHE"=>"CH","SYR"=>"SY","TWN"=>"TW","TJK"=>"TJ","TZA"=>"TZ","THA"=>"TH","TLS"=>"TL","TGO"=>"TG","TKL"=>"TK","TON"=>"TO","TTO"=>"TT","TUN"=>"TN","TUR"=>"TR","TKM"=>"TM","TCA"=>"TC","TUV"=>"TV","UGA"=>"UG","UKR"=>"UA","ARE"=>"AE","GBR"=>"GB","USA"=>"US","UMI"=>"UM","URY"=>"UY","UZB"=>"UZ","VUT"=>"VU","VAT"=>"VA","VEN"=>"VE","VNM"=>"VN","VGB"=>"VG","VIR"=>"VI","WLF"=>"WF","ESH"=>"EH","YEM"=>"YE","ZMB"=>"ZM","ZWE"=>"ZW");
And then I change this line:
$billing->commerce_customer_address[LANGUAGE_NONE][0]['country'] = substr ($_POST['country'], 0, 2);
To this:
if ( isset($iso_code[$_POST['country']]) )
$billing->commerce_customer_address[LANGUAGE_NONE][0]['country'] = $iso_code[$_POST['country']];
else
$billing->commerce_customer_address[LANGUAGE_NONE][0]['country'] = substr ($_POST['country'], 0, 2);
And also while at it, I do the same to the shipping country, and let it use the shipping country parameter from 2checkout instead of the billing country that it currently uses.
if ( isset($iso_code[$_POST['ship_country']]) )
$shipping->commerce_customer_address[LANGUAGE_NONE][0]['country'] = $iso_code[$_POST['ship_country']];
else
$shipping->commerce_customer_address[LANGUAGE_NONE][0]['country'] = substr ($_POST['ship_country'], 0, 2);
Any idea what I'm doing wrong here ? The thing just crashes...
Regards,
Ahmed
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 2co-1465962.patch | 5.49 KB | neochief |
Comments
Comment #1
berenddeboer commentedAt first glance your code looks pretty good. What do you mean with "just crashes". There will be some output. Try installing xdebug or look in /var/log/syslog or so.
Comment #2
ShErbO commentedYou're right, the code totally works.
Here is what I had to do:
-As a precaution I disabled module, cleared cache then enabled the module with the modified code
-I was using 2Checkout's "Header Redirect" return method... which used GET instead of POST... silly ! After fixing that things worked fine
Please feel free to commit.
Regards,
Ahmed
Comment #3
neochief commentedHere's the patch to fix this.
Comment #4
berenddeboer commentedFeel free to commit neochief.