Ben volkomen nieuw op dit forum ben geen pro en dit is de eerste keer dat ik PHP gebruik. Ik heb een probleem met het implementeren van rabobank omnikassa 2.0 in mijn webshop. De aanroep van de omnikassa api is een HTTPS POST request met een JSON body. Mijn webshop draait op .NET, maar daar hebben ze bij de rabobank geen voorbeeldcodes voor wel voor PHP en JAVA. De PHP code draait in de test omgeving perfect, maar ik krijg dit niet voor elkaar in .NET. Allebei de codes geven de zelfde JSON string, plak ik de .NET JSON string in de PHP code dan krijg ik een fout 403 van de rabobank server, kopieer ik de JSON string uit de PHP code en plak deze daarna weer in de PHP code dan gaat alles weer goed. Mijn vraag is natuurlijk hoe is dit mogelijk zelfde string met de zelfde HEX waarden een doet het wel de andere doet het niet?
Gebruikte code:
Waarde van string $sPostdata in PHP code:
{"timestamp":"2018-08-23T17:02:36.4279066+02:00","merchantOrderId":"order123","amount":{"currency":"EUR","amount":"100"},"description":"Webshop bestelling order123","merchantReturnURL":"https://returnurl","paymentBrand":"IDEAL","paymentBrandForce":"FORCE_ONCE","signature":"d5fa1f40a4e4f3201928c14440e4ba3b22673cae0ef67a9fadbc6e8f06990dd0dd9b3897f774fccdecf361594c9635a23bb1fea8e58e09ac26fc304aed5cd873"}
Waarde van string json in .NET code:
{"timestamp":"2018-08-23T17:02:36.4279066+02:00","merchantOrderId":"order123","amount":{"currency":"EUR","amount":"100"},"description":"Webshop bestelling order123","merchantReturnUrl":"https://returnurl","paymentBrand":"IDEAL","paymentBrandForce":"FORCE_ONCE","signature":"d5fa1f40a4e4f3201928c14440e4ba3b22673cae0ef67a9fadbc6e8f06990dd0dd9b3897f774fccdecf361594c9635a23bb1fea8e58e09ac26fc304aed5cd873"}
Gebruikte code:
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| PHP code: $aRequest['timestamp'] = "2018-08-23T17:02:36.4279066+02:00"; $aRequest['merchantOrderId'] = "order123" $aRequest['amount'] = array(); $aRequest['amount']['currency'] = "EUR"; $aRequest['amount']['amount'] = "100"; $aRequest['description'] = "Webshop bestelling order123"; $aRequest['merchantReturnURL'] = "https://returnurl"; $aRequest['paymentBrand'] = "IDEAL"; $aRequest['paymentBrandForce'] = 'FORCE_ONCE'; $sHashString = $aRequest['timestamp'] . ',' . $aRequest['merchantOrderId'] . ',' . $aRequest['amount']['currency'] . ',' . $aRequest['amount']['amount'] . ','. ',' . $aRequest['description'] . ',' . $aRequest['merchantReturnURL'] . ',' . $aRequest['paymentBrand'] . ',' . $aRequest['paymentBrandForce']; $sHash = hash_hmac('sha512', $sHashString, base64_decode($this->sSigningKey)); $aRequest['signature'] = $sHash; $sApiUrl = 'https://betalen.rabobank.nl/omnikassa-api' . ($this->bTestMode ? '-sandbox' : '') . '/order/server/api/order'; $sPostData = json_encode($aRequest,JSON_UNESCAPED_SLASHES); $sResponse = _doHttpRequest($sApiUrl, $sPostData, true, 30, false, array('Authorization: Bearer ' . $this->sAccessToken)); |
Waarde van string $sPostdata in PHP code:
{"timestamp":"2018-08-23T17:02:36.4279066+02:00","merchantOrderId":"order123","amount":{"currency":"EUR","amount":"100"},"description":"Webshop bestelling order123","merchantReturnURL":"https://returnurl","paymentBrand":"IDEAL","paymentBrandForce":"FORCE_ONCE","signature":"d5fa1f40a4e4f3201928c14440e4ba3b22673cae0ef67a9fadbc6e8f06990dd0dd9b3897f774fccdecf361594c9635a23bb1fea8e58e09ac26fc304aed5cd873"}
C#:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| .NET code: orderdata od = new orderdata(); od.timestamp = "2018-08-23T17:02:36.4279066+02:00"; od.merchantOrderId = "order123"; od.merchantReturnUrl = "https://returnurl"; od.amount.currency = "EUR"; od.amount.amount = "100"; od.description = "Webshop bestelling order123"; od.paymentBrand = "IDEAL"; od.paymentBrandForce = "FORCE_ONCE"; byte[] signingkeydata = Convert.FromBase64String(sleutels.signingkey); HMACSHA512 hmac = new HMACSHA512(signingkeydata); string sig = od.timestamp + "," + od.merchantOrderId + "," + od.amount.currency + "," + od.amount.amount + "," + "," + od.description + "," + od.merchantReturnUrl + "," + od.paymentBrand + "," + od.paymentBrandForce; byte[] sign = Encoding.UTF8.GetBytes(sig); od.signature = BitConverter.ToString(hmac.ComputeHash(sign)); od.signature = od.signature.Replace("-", "").ToLower(); JavaScriptSerializer a = new JavaScriptSerializer(); string json = a.Serialize(od); |
Waarde van string json in .NET code:
{"timestamp":"2018-08-23T17:02:36.4279066+02:00","merchantOrderId":"order123","amount":{"currency":"EUR","amount":"100"},"description":"Webshop bestelling order123","merchantReturnUrl":"https://returnurl","paymentBrand":"IDEAL","paymentBrandForce":"FORCE_ONCE","signature":"d5fa1f40a4e4f3201928c14440e4ba3b22673cae0ef67a9fadbc6e8f06990dd0dd9b3897f774fccdecf361594c9635a23bb1fea8e58e09ac26fc304aed5cd873"}