When ordering more than 9 products the SHASIGN becomes invalid and payment through Ogone returns an error. The error shown in the Ogone dashboard is "unknown order/1/s" which (according to the support departments) is due to an issue with the SHASIGN calculated by the Ogone module.
After some investigation i found out the problem lies in the order of signature parameters handled in the signData method. The issue is fixed rather easily by adding a sorting_flag parameter to the ksort function so sorting is done in a natural order.
Current order:
..
..
ITEMNAME1=Product1
ITEMNAME10=Product10
ITEMNAME2=Product2
..
..
..
Correct order:
..
..
ITEMNAME1=PRODUCT1
ITEMNAME2=PRODUCT2
ITEMNAME3=PRODUCT3
..
..
ITEMNAME10=PRODUCT10
Attached path should fix this issue.
Comment | File | Size | Author |
---|---|---|---|
#8 | hash_issue_when-2475173-8.patch | 817 bytes | ericmulder1980 |
Comments
Comment #1
ericmulder1980 CreditAttribution: ericmulder1980 commentedSome background information from the Ogone implementation guide.
Ascending order of line item details for SHA calculation
Please take into account that as from 10 line item details the order of the parameters for the SHA calculation may differ from what is expected on your system's side.
Where for the calculation of the SHA we normally stress that all parameters should be sorted alphabetically, a "logical" ascending order is put in place for the line item details:
- Ascending order: 1, 2, 3, 4, 5, 6, 7, etc.
- Alphabetical order: 1, 10, 11, 2, 3, 4, etc. (NOT applied)
Comment #2
XanoComment #3
XanoAlso fix this for Ingenico.
Comment #5
ericmulder1980 CreditAttribution: ericmulder1980 commentedIt seemd SORT_NATURAL was added in PHP 5.4 and will not work in previous versions.
replaced ksort function with natsort.
Comment #6
XanoComment #7
XanoThat sorts the values, not the keys. We either have to go with the first solution and require PHP 5.4 (which is the lowest supported PHP version nowadays anyway) or split keys and values, the order the keys (which are values in the new array), then combine them in the order of the array that contains the sorted keys. Using
uksort()
is possible too, but that needs a callback. Using a separate function makes the code harder to read as well and even using a closure would require us to increase the PHP requirement to 5.3Comment #8
ericmulder1980 CreditAttribution: ericmulder1980 commentedAh, my newborn daughter seems to be affecting my skills ;)
Using PHP's built-in strnatcmp would prevent having another callback function in code.
uksort( $data, 'strnatcmp');
Comment #9
XanoThanks! Did you test this manually and does it work?
Comment #10
ericmulder1980 CreditAttribution: ericmulder1980 commentedYes, tested in devel/php with following code
returns exactly what we need.
Comment #11
XanoAnd any Ogone redirects with more than 9 items works too?
Comment #12
ericmulder1980 CreditAttribution: ericmulder1980 commentedWell since assumption is the mother of all f#ck ups i will deploy this to our staging environment (which is hooked up to Ogone test environment) and give it a go.
The previous ksort($data, SORT_NATURAL) fix was already running on production without any issues.
Will report back after testing.
Comment #13
Xano@ericmulder1980: Did you manage to test this yet?
Comment #14
ericmulder1980 CreditAttribution: ericmulder1980 as a volunteer commentedHi Xano, sorry for the delay.
Works great over here so i guess this means we can check the box "tested by community" :)
Comment #15
XanoComment #16
XanoMeh. Can't make a connection to the Git repo from here. Will have to push at home.
Comment #18
XanoThanks again!