Ideal Professional

Door Martijn Wieringa, 19 jaar geleden, 17.664x bekeken

Code voor de implementatie van iDEAL Professional (voorheen Basic), geschikt voor PHP 5. Voor meer achtergrond informatie over iDEAL installatie, zie:
Ideal Basic

De 'standaard code' van de bank zijn vervangen voor eigen geschreven classes, geschikt voor PHP 5. Net als in de tutorial van Ideal Basic bestaat het proces uit 3 stappen (step1.php, step2.php en step3.php

IdealRequest (algemene class)
Algemene functionaliteit.

IssuerRequest (extends IdealRequest)
Helpt bij het opvragen van de lijst met banken.

TransactionRequest (extends IdealRequest)
Helpt bij het opzetten van een transactie.

StatusRequest (extends IdealRequest)
Helpt bij het opvragen van de status van een transactie.


Cerificaten
Plaats je privé certificaat (private.cer) en je privé sleutel (private.key) samen met de publieke certificaten (rabobank.cer, ingbank.cer, enz) in 1 map. Zorg dat de map niet toegankelijk is voor de bezoekers van uw website. Stel met setSecurePath het pad in naar deze map.

Upload je private.cer ook in je iDEAL Dashboard van je bank (zowel LIVE als TEST omgeving).

Code downloaden
Alle code kun je eenvoudig downloaden via: ideal.php5.zip


Aanvraag/oproep
Ik ben nog op zoek naar de publieke certificaten van de Fortis en SNS Bank. Ook ben ik voor deze banken nog op zoek naar de URLs voor communicatie met de hun server (zowel TEST als LIVE server). Als iemand deze voor me heeft hoor ik het graag... Het blijkt dat de fortis alleen een ideal oplossing biedt via www.neossolution.com (een alle-betaalmethoden-in-1 oplossing). De SNS bank biedt helemaal geen ondersteuning voor IDEAL.

Voorbeeld: http://www.php-solutions.nl/scripts/ideal/pro/step1.php

Gesponsorde koppelingen

PHP script bestanden

  1. ideal-professional

 

Er zijn 19 reacties op 'Ideal professional'

PHP hulp
PHP hulp
0 seconden vanaf nu
 

Gesponsorde koppelingen
Klaasjan Boven
Klaasjan Boven
19 jaar geleden
 
0 +1 -0 -1
Pholeron,
Het ziet er bijzonder netjes en compleet uit (ik ga er maar vanuit dat het werkt)
Arend a
Arend a
19 jaar geleden
 
0 +1 -0 -1
Ziet er zeer uitgebreid en compleet uit, misschien een idee om iets completere documentatie te schrijven. Je serie van scripts is ondertussen zo groot, misschien een keer aardig om er een google code projectje van te maken?
Martijn Wieringa
Martijn Wieringa
19 jaar geleden
 
0 +1 -0 -1
Goed idee, maar nog nooit gedaan. Ik zal 'es kijken hoe ik zo'n project kan maken/beheren.
Robin de Vries
Robin de Vries
19 jaar geleden
 
0 +1 -0 -1
voorbeeldje? misschien levert het nog wat op :P
Martijn Wieringa
Martijn Wieringa
19 jaar geleden
 
Ericbruggema x
ericbruggema x
19 jaar geleden
 
0 +1 -0 -1
Perfect geschreven, heb ooit al eens een andere versie van je gebruikt en die werkte ook al goed (na wat kleine aanpassingen).

Is het geen idee om ook gelijk een super handige PayPal class te bouwen, waarbij je dan ook gelijk een omgeving maakt dat beide betalingsmogelijkheden gebruikt kunnen worden?
Ericbruggema x
ericbruggema x
19 jaar geleden
 
0 +1 -0 -1
Ow en waarom dit

$string = str_replace('"', '"', $string);
$string = str_replace('&lt;', '<', $string);
$string = str_replace('&gt;', '>', $string);
$string = str_replace('&amp;', '&', $string);

als het ook zo kan

$string = str_replace(array('&quot;', '&lt;','&gt;','&amp;'),
array('"','<','>','&'),
$string);

? of is het per regel sneller (niet getest)
Martijn Wieringa
Martijn Wieringa
19 jaar geleden
 
0 +1 -0 -1
@eric

Volgens mij stamt dat stukje code nog uit een tijd dat er geen array's als parameters mochten worden meegegeven. Ik heb echter geen idee welke variant sneller is..
Ericbruggema x
ericbruggema x
19 jaar geleden
 
0 +1 -0 -1
Ik heb even een benchmarkje gedaan en zag dat een array iets sneller te verwerken is. (scheelt niet veel maar alle kleine beetjes helpen)
Martijn Wieringa
Martijn Wieringa
19 jaar geleden
 
0 +1 -0 -1
Ik zal het meenemen in de volgende release/tutorial (:
Jan geen
Jan geen
19 jaar geleden
 
0 +1 -0 -1
Mooi script, ik zie alleen dat je constanten zo aanmaakt: protected $LF = "\n";. Waarom niet op de manier zoals het hoort namelijk: const LF = "\n"; ? je kan hem dan aanspreken binnen de class (self::LF) en buiten de class IdealRequest::LF
Arend a
Arend a
19 jaar geleden
 
0 +1 -0 -1
Ik heb even phpdoc toegevoegd aan de classes:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
<?php
    /**
     * @author Pholeron
     * Base class, used for setting the merchant and security certificate information.
     * Extended by all three other classes.
     *
     *
     * Explanation of terms used in these classes in relation of Ideal
     * - Aquirer: The bank of the company selling stuff
     * - Issuer: The bank of the client buying stuff
     * - Merchant: The company selling stuff
     * - Acceptant: alias for merchant
     */

    class IdealRequest
    {
        /**
         * Array containing errors
         * @var array
         */

        private $aErrors = array();


        /**
         * Security Settings
         * @var string
         */

        protected $sSecurePath;
        
        /**
         * Private keypass
         * @var string
         */

        protected $sPrivateKeyPass;
        
        /**
         * Path to private key file
         * @var string
         */

        protected $sPrivateKeyFile;
        
        /**
         * Path to certificate file
         * @var string
         */

        protected $sPrivateCertificateFile;
        
        /**
         * Path to public certificate file
         * @var string
         */

        protected $sPublicCertificateFile;


        /**
         * Account settings:
         * Arquirer url
         * @var string
         */

        protected $sAquirerUrl;
        
        /**
         * Merchant Id, a unique number composed of a unique aquiererId and a unique serial number of 5 positions
         * @var string
         */
    
        protected $sMerchantId;
        
        /**
         * Sub marchant Id
         * A unique number to seperate between different names used by the merchant, default 0
         * @var string
         */

        protected $sSubId;

        /**
         * @var string
         */

        protected $LF = "\n";
        /**
         * @var string
         */

        protected $CRLF = "\r\n";

        /**
         * Constructor
         * Sets the Private Key File to "private.key" and Private Certificate file to "private.cer"
         * @return void
         */

        public function __construct()
        {

            $this->sPrivateKeyFile = 'private.key';
            $this->sPrivateCertificateFile = 'private.cer';
        }


        //
        /**
         * $sPath Should point to directory with .cer and .key files
         * @param string $sPath
         * @return void
         */

        public function setSecurePath($sPath)
        {

            $this->sSecurePath = $sPath;
        }


        /**
         * Set password to generate signatures
         * @param string $sPass
         * @return void
         */

        public function setPrivateKey($sPass)
        {

            $this->sPrivateKeyPass = $sPass;
        }


        /**
         * Set MerchantID id and SubID
         * @param string $sMerchantId
         * @param string $sSubId
         * @return void
         */

        public function setMerchant($sMerchantId, $sSubId = 0)
        {

            $this->sMerchantId = $sMerchantId;
            $this->sSubId = $sSubId;
        }


        /**
         * Set aquirer (Use: Rabobank, ING Bank, ABN Amro, etc)
         * Returns true/false on success / failure
         *
         * @param string $sIssuer
         * @param boolean $bTestMode
         * @return boolean
         */

        public function setAquirer($sIssuer, $bTestMode = false)
        {

            if(stripos($sIssuer, 'rabo') !== false) // Rabobank
            {
                $this->sPublicCertificateFile = 'rabobank.cer';
                $this->sAquirerUrl = 'ssl://ideal' . ($bTestMode ? 'test' : '') . '.rabobank.nl:443/ideal/iDeal';
            }

            elseif(stripos($sIssuer, 'ing') !== false) // ING Bank
            {
                $this->sPublicCertificateFile = 'ingbank.cer';
                $this->sAquirerUrl = 'ssl://ideal' . ($bTestMode ? 'test' : '') . '.secure-ing.com:443/ideal/iDeal';
            }

            elseif(stripos($sIssuer, 'abn') !== false) // ABN Amro
            {
                $this->sPublicCertificateFile = 'abnamro.cer';
                $this->sAquirerUrl = 'ssl://idealm-et.abnamro.nl:443/';
            }

            elseif(stripos($sIssuer, 'fortis') !== false) // Fortis Bank
            {
                $this->sPublicCertificateFile = 'fortisbank.cer';
                // $this->sAquirerUrl = 'ssl://;
            }
            elseif(stripos($sIssuer, 'sns') !== false) // SNS Bank
            {
                $this->sPublicCertificateFile = 'snsbank.cer';
                // $this->sAquirerUrl = 'ssl://';
            }
            else // Unknown issuer
            {
                $this->setError('Unknown aquirer. Please use Rabobank, ING Bank, ABN Amro, SNS Bank or Fortis.', false, __FILE__, __LINE__);
                return false;
            }

            return true;
        }




        /**
         * Error functions
         * @param string $sDesc Description of the error
         * @param string $sCode Error code
         * @param string $sFile Error file
         * @param string $sLine Error line
         * @return void
         */

        protected function setError($sDesc, $sCode = false, $sFile = 0, $sLine = 0)
        {

            $this->aErrors[] = array('desc' => $sDesc, 'code' => $sCode, 'file' => $sFile, 'line' => $sLine);
        }


        /**
         * Returns the array of errors in the following format:
         * array('desc' => $sDesc,
         *          'code' => $sCode,
         *          'file' => $sFile,
         *       'line' => $sLine)
         * @return array
         */

        public function getErrors()
        {

            return $this->aErrors;
        }


        /**
         * Returns if there are errors or not
         * @return boolean
         */

        public function hasErrors()
        {

            return (sizeof($this->aErrors) ? true : false);
        }


        /**
         * Checks if the settings are configured properly
         * @param array $settings
         * @return boolean
         */

        protected function checkConfiguration($settings = array('sSecurePath', 'sPrivateKeyPass', 'sPrivateKeyFile', 'sPrivateCertificateFile', 'sPublicCertificateFile', 'sAquirerUrl', 'sMerchantId'))
        {

            $bOk = true;

            for($i = 0; $i < sizeof($settings); $i++)
            {

                // echo $settings[$i] . ' = ' . $this->$settings[$i] . '<br>';

                if(empty($this->$settings[$i]))
                {

                    $bOk = false;
                    $this->setError('Setting ' . $settings[$i] . ' was not configurated.', false, __FILE__, __LINE__);
                }
            }


            return $bOk;
        }




        /**
         * Utilities: HTTP POST to a url, data
         *
         * @param string $url
         * @param mixed $data
         * @param integer $timeout miliseconds
         * @return string result
         */

        protected function postToHost($url, $data, $timeout = 30)
        {

            $idx = strrpos($url, ':');
            $host = substr($url, 0, $idx);
            $url = substr($url, $idx + 1);
            $idx = strpos($url, '/');
            $port = substr($url, 0, $idx);
            $path = substr($url, $idx);

            $fsp = fsockopen($host, $port, $errno, $errstr, $timeout);
            $res = '';
            
            if($fsp)
            {

                fputs($fsp, 'POST ' . $path . ' HTTP/1.0' . $this->CRLF);
                fputs($fsp, 'Accept: text/html' . $this->CRLF);
                fputs($fsp, 'Accept: charset=ISO-8859-1' . $this->CRLF);
                fputs($fsp, 'Content-Length:' . strlen($data) . $this->CRLF);
                fputs($fsp, 'Content-Type: text/html; charset=ISO-8859-1' . $this->CRLF . $this->CRLF);
                fputs($fsp, $data, strlen($data));

                while(!feof($fsp))
                {

                    $res .= fgets($fsp, 128);
                }


                fclose($fsp);
            }

            else
            {
                $this->setError($errstr, $errno, __FILE__, __LINE__);
            }


            return $res;
        }


        /**
         * Utilities: Parse a specific XML key
         *
         * @param string $key Name of the xml key
         * @param string $xml String containing the XML file
         * @return string unescaped xml partion
         */

        protected function parseFromXml($key, $xml)
        {

            $begin = 0;
            $end = 0;
            $begin = strpos($xml, '<' . $key . '>');
            
            if($begin === false)
            {

                return false;
            }


            $begin += strlen($key) + 2;
            $end = strpos($xml, '</' . $key . '>');

            if($end === false)
            {

                return false;
            }


            $result = substr($xml, $begin, $end - $begin);
            $result = $this->unescapeXml($result);

            return utf8_decode($result);
        }


        /**
         * Utilities: Remove space characters from $string
         * @param $string
         * @return string
         */

        protected function removeSpaceCharacters($string)
        {

            return preg_replace('/\s/', '', $string);
        }


        /**
         * Utilities:
         * Escapes ampersand (&), Greather then (>), Lesser then (<), and Quote (") characters with htmlentities versions
         *  
         * @param $string
         * @return string
         */

        protected function escapeXml($string)
        {

            $string = str_replace('&', '&amp;', $string);
            $string = str_replace('<', '&lt;', $string);
            $string = str_replace('>', '&gt;', $string);
            $string = str_replace('"', '&quot;', $string);
            return $string;
        }


        /**
         * Utilities:
         * Unescapes ampersand (&) Greather then (>), Lesser then (<), and Quote (") characters from htmlentities to unescaped versions
         * @param $string
         * @return string
         */

        protected function unescapeXml($string)
        {

            $string = str_replace('&quot;', '"', $string);
            $string = str_replace('&lt;', '<', $string);
            $string = str_replace('&gt;', '>', $string);
            $string = str_replace('&amp;', '&', $string);
            return $string;
        }





        /**
         * Security functions: Get the certificate fingerprint
         * @param boolean $bPublicCertificate
         * @return string Fingerprint data
         */

        protected function getCertificateFingerprint($bPublicCertificate = false)
        {

            if($fp = fopen($this->sSecurePath . ($bPublicCertificate ? $this->sPublicCertificateFile : $this->sPrivateCertificateFile), 'r'))
            {

                $sRawData = fread($fp, 8192);
                fclose($fp);

                $sData = openssl_x509_read($sRawData);

                if(!openssl_x509_export($sData, $sData))
                {

                    $this->setError('Error in certificate ' . $this->sSecurePath . $this->sPrivateCertificateFile, false, __FILE__, __LINE__);
                    return false;
                }

            
                $sData = str_replace('-----BEGIN CERTIFICATE-----', '', $sData);
                $sData = str_replace('-----END CERTIFICATE-----', '', $sData);

                return strtoupper(sha1(base64_decode($sData)));
            }

            else
            {
                $this->setError('Certificate file ' . $this->sSecurePath . $this->sPrivateCertificateFile . ' not found.', false, __FILE__, __LINE__);
            }
        }


        /**
         * Returns the SSL signature of $sMessage
         * @param $sMessage
         * @return string Signature
         */

        protected function getSignature($sMessage)
        {

            $sMessage = preg_replace('/\s/', '', $sMessage);

            if($fp = fopen($this->sSecurePath . $this->sPrivateKeyFile, 'r'))
            {

                $sRawData = fread($fp, 8192);
                fclose($fp);

                $sPrivateKey = openssl_get_privatekey($sRawData, $this->sPrivateKeyPass);
                $sSignature = '';

                openssl_sign($sMessage, $sSignature, $sPrivateKey);
                openssl_free_key($sPrivateKey);

                return $sSignature;
            }
        }


        /**
         * Verify the signature from the data in $sData against the string $sSignature
         *
         * @param $sData
         * @param $sSignature
         * @return boolean
         */

        protected function verifySignature($sData, $sSignature)
        {

            $bOk = false;

            if($fp = fopen($this->sSecurePath . $this->sPublicCertificateFile, 'r'))
            {

                $sRawData = fread($fp, 8192);
                fclose($fp);

                $sPublicKey = openssl_get_publickey($sRawData);
                $bOk = (openssl_verify($sData, $sSignature, $sPublicKey) ? true : false);
                openssl_free_key($sPublicKey);
            }


            return $bOk;
        }
    }





    /**
     * @author pholeron
     * Class to Request the list of issuers (banks). Used in Step 1.
     */

    class IssuerRequest extends IdealRequest
    {
        /**
         * Calls the parent constructor
         * @return void
         */

        public function __construct()
        {

            parent::__construct();
        }


        /**
         * Execute request (Lookup issuer list)
         * Returns array in format array( "issuerId" => "IssuerName", .. )
         *
         * @return array with issuerlists
         */

        public function doRequest()
        {

            if($this->checkConfiguration())
            {

                $sTimestamp = gmdate('Y-m-d') . 'T' . gmdate('H:i:s') . '.000Z';
                $sMessage = $this->removeSpaceCharacters($sTimestamp . $this->sMerchantId . $this->sSubId);

                $sToken = $this->getCertificateFingerprint();
                $sTokenCode = base64_encode($this->getSignature($sMessage));

                $sXmlMessage = '<?xml version="1.0" encoding="UTF-8" ?>' . $this->LF
                . '<DirectoryReq xmlns="http://www.idealdesk.com/Message" version="1.1.0">' . $this->LF
                . '<createDateTimeStamp>' . utf8_encode($sTimestamp) . '</createDateTimeStamp>' . $this->LF
                . '<Merchant>' . $this->LF
                . '<merchantID>' . utf8_encode($this->sMerchantId) . '</merchantID>' . $this->LF
                . '<subID>' . utf8_encode($this->sSubId) . '</subID>' . $this->LF
                . '<authentication>SHA1_RSA</authentication>' . $this->LF
                . '<token>' . utf8_encode($sToken) . '</token>' . $this->LF
                . '<tokenCode>' . utf8_encode($sTokenCode) . '</tokenCode>' . $this->LF
                . '</Merchant>' . $this->LF
                . '</DirectoryReq>';

                $sXmlReply = $this->postToHost($this->sAquirerUrl, $sXmlMessage, 10);

                if($sXmlReply)
                {

                    if($this->parseFromXml('errorCode', $sXmlReply)) // Error found
                    {
                        // Add error to error-list
                        $this->setError($this->parseFromXml('errorMessage', $sXmlReply), $this->parseFromXml('errorCode', $sXmlReply), __FILE__, __LINE__);                    
                    }

                    else
                    {
                        $aIssuerList = array();

                        while(strpos($sXmlReply, '<issuerID>'))
                        {
                            
                            $sIssuerId = $this->parseFromXml('issuerID', $sXmlReply);
                            $sIssuerName = $this->parseFromXml('issuerName', $sXmlReply);
                            $sIssuerList = $this->parseFromXml('issuerList', $sXmlReply);

                            if(strcmp($sIssuerList, 'Short') === 0)
                            {

                                $aIssuerList[$sIssuerId] = $sIssuerName;
                            }


                            $sXmlReply = substr($sXmlReply, strpos($sXmlReply, '</issuerList>') + 13);
                        }


                        return $aIssuerList;
                    }
                }
            }


            return false;
        }
    }





    /**
     * @author pholeron
     *
     * Used in Step 2: Handle the transaction request
     * For reference to the elements used, see the iDeal reference guide
     * APPENDIX
     */

    class TransactionRequest extends IdealRequest
    {
        /**
         * Order Id, to be generated by yourself
         * @var string
         */

        protected $sOrderId;
        /**
         * String containing the description of the order
         * @var string
         */

        protected $sOrderDescription;
        
        /**
         * The total amount of money for the order (in eurocents)
         * @var integer
         */

        protected $iOrderAmount;
        
        /**
         * The redirect url where the user will be returned
         * @var string
         */

        protected $sReturnUrl;
        
        /**
         * Issuer Id (Id of the bank)
         * @var string
         */

        protected $sIssuerId;
        
        /**
         * Entrance Code, a code used to recognize the customer upon returning to the return URL
         * @var string
         */

        protected $sEntranceCode;


        /**
         * Transaction info:
         * Transaction Id
         * @var string
         */

        protected $sTransactionId;
        
        /**
         * Transaction URL
         * @var string
         */

        protected $sTransactionUrl;

        /**
         * Constructor
         * - Randomly generates an entrance code as a "session Id"
         * - Calls the parent constructor
         * @return void
         */

        public function __construct()
        {

            parent::__construct();

            // Random EntranceCode
            $this->sEntranceCode = sha1(rand(1000000, 9999999));
        }


        /**
         * Set the order id (max 16 chars)
         * @param string $sOrderId
         * @return void
         */

        public function setOrderId($sOrderId)
        {

            $this->sOrderId = substr($sOrderId, 0, 16);
        }


        /**
         * Set the order description
         * (Max 32 chars, no html)
         * @param string $sOrderDescription
         * @return void
         */

        public function setOrderDescription($sOrderDescription)
        {

            $this->sOrderDescription = substr($sOrderDescription, 0, 32);
        }


        /**
         * Set the amount for the order, in floating number euro's
         * @param float $fOrderAmount
         * @return void
         */

        public function setOrderAmount($fOrderAmount)
        {

            $this->iOrderAmount = round($fOrderAmount * 100);
        }


        /**
         * Set the return URL (max 512 characters)
         * @param string $sReturnUrl
         * @return void
         */

        public function setReturnUrl($sReturnUrl)
        {

            $this->sReturnUrl = substr($sReturnUrl, 0, 512);
        }


        /**
         * Set the issuer Id
         * @param $sIssuerId
         * @return void
         */

        public function setIssuerId($sIssuerId)
        {

            $this->sIssuerId = $sIssuerId;
        }


        /**
         * Set the entrance code (max 40 chars)
         * @param $sEntranceCode
         * @return void
         */

        public function setEntranceCode($sEntranceCode)
        {

            $this->sEntranceCode = substr($sEntranceCode, 0, 40);
        }

        /**
         * Executes the transaction request
         * Returns false upon failure
         * @return string Transaction Id
         */

        public function doRequest()
        {

            if($this->checkConfiguration() && $this->checkConfiguration(array('sOrderId', 'sOrderDescription', 'iOrderAmount', 'sReturnUrl', 'sReturnUrl', 'sIssuerId', 'sEntranceCode')))
            {

                $sTimestamp = gmdate('Y-m-d') . 'T' . gmdate('H:i:s') . '.000Z';
                $sMessage = $this->removeSpaceCharacters($sTimestamp . $this->sIssuerId . $this->sMerchantId . $this->sSubId . $this->sReturnUrl . $this->sOrderId . $this->iOrderAmount . 'EUR' . 'nl' . $this->sOrderDescription . $this->sEntranceCode);
                $sToken = $this->getCertificateFingerprint();
                $sTokenCode = $this->getSignature($sMessage);
                $sTokenCode = base64_encode($sTokenCode);

                $sXmlMessage = '<?xml version="1.0" encoding="UTF-8" ?>' . $this->LF
                . '<AcquirerTrxReq xmlns="http://www.idealdesk.com/Message" version="1.1.0">' . $this->LF
                . '<createDateTimeStamp>' . utf8_encode($sTimestamp) .  '</createDateTimeStamp>' . $this->LF
                . '<Issuer>' . $this->LF
                . '<issuerID>' . utf8_encode($this->sIssuerId) . '</issuerID>' . $this->LF
                . '</Issuer>' . $this->LF
                . '<Merchant>' . $this->LF
                . '<merchantID>' . utf8_encode($this->sMerchantId) . '</merchantID>' . $this->LF
                . '<subID>' . utf8_encode($this->sSubId) . '</subID>' . $this->LF
                . '<authentication>SHA1_RSA</authentication>' . $this->LF
                . '<token>' . utf8_encode($sToken) . '</token>' . $this->LF
                . '<tokenCode>' . utf8_encode($sTokenCode) . '</tokenCode>' . $this->LF
                . '<merchantReturnURL>' . utf8_encode($this->escapeXml($this->sReturnUrl)) . '</merchantReturnURL>' . $this->LF
                . '</Merchant>' . $this->LF
                . '<Transaction>' . $this->LF
                . '<purchaseID>' . utf8_encode($this->escapeXml($this->sOrderId)) . '</purchaseID>' . $this->LF
                . '<amount>' . utf8_encode($this->iOrderAmount) . '</amount>' . $this->LF
                . '<currency>EUR</currency>' . $this->LF
                . '<expirationPeriod>PT30M</expirationPeriod>' . $this->LF
                . '<language>nl</language>' . $this->LF
                . '<description>' . utf8_encode($this->escapeXml($this->sOrderDescription)) . '</description>' . $this->LF
                . '<entranceCode>' . utf8_encode($this->escapeXml($this->sEntranceCode)) . '</entranceCode>' . $this->LF
                . '</Transaction>' . $this->LF
                . '</AcquirerTrxReq>';

                $sXmlReply = $this->postToHost($this->sAquirerUrl, $sXmlMessage, 10);

                if($sXmlReply)
                {

                    if($this->parseFromXml('errorCode', $sXmlReply)) // Error found
                    {
                        // Add error to error-list
                        $this->setError($this->parseFromXml('errorMessage', $sXmlReply), $this->parseFromXml('errorCode', $sXmlReply), __FILE__, __LINE__);                    
                    }

                    else
                    {
                        $this->sTransactionId = $this->parseFromXml('transactionID', $sXmlReply);
                        $this->sTransactionUrl = html_entity_decode($this->parseFromXml('issuerAuthenticationURL', $sXmlReply));

                        return $this->sTransactionId;
                    }
                }
            }


            return false;
        }


        /**
         * Start transaction
         * Redirects the user to the transaction URL, returns false upon failure
         *
         * @return false / void
         */

        public function doTransaction()
        {

            if((sizeof($this->aErrors) == 0) && $this->sTransactionId && $this->sTransactionUrl)
            {

                header('Location: ' . $this->sTransactionUrl);
                exit;
            }


            $this->setError('Please setup a valid transaction request first.', false, __FILE__, __LINE__);
            return false;
        }
    }





    /**
     * Used in Step 3: to get back the information of the transaction request
     * @author pholeron
     */

    class StatusRequest extends IdealRequest
    {
 
        /**
         * Account info: The city of the user (max 24 chars)
         * @var string
         */

        protected $sAccountCity;
        
        /**
         * Name of the user (max 24 chars)
         * @var string
         */

        protected $sAccountName;
        
        /**
         * The account number of the user (Max 10 numeric chars)
         * @var string
         */

        protected $sAccountNumber;


        /**
         * Transaction info: transaction Id, a unique 16 digit number, issued by the aquirer
         * Composed of the aquirerId + a unique 12 digit number
         * @var string
         */

        protected $sTransactionId;
        
        /**
         * Transaction status ("Open","Success","Failure","Cancelled" or "Expired")
         * @var string
         */

        protected $sTransactionStatus;

        /**
         * Constructor
         * @return void
         */

        public function __construct()
        {

            parent::__construct();
        }



        /**
         * Set transaction id
         * @param $sTransactionId
         * @return void
         */

        public function setTransactionId($sTransactionId)
        {

            $this->sTransactionId = $sTransactionId;
        }


        /**
         * Get user's account city
         * @return string
         */

        public function getAccountCity()
        {

            if(!empty($this->sAccountCity))
            {

                return $this->sAccountCity;
            }


            return '';
        }



        /**
         * Get account name
         * @return string
         */

        public function getAccountName()
        {

            if(!empty($this->sAccountName))
            {

                return $this->sAccountName;
            }


            return '';
        }


        /**
         * Get account number
         * @return string
         */

        public function getAccountNumber()
        {

            if(!empty($this->sAccountNumber))
            {

                return $this->sAccountNumber;
            }


            return '';
        }


        //
        /**
         * Execute the status request and returns the status of the request
         * ("Open","Success","Failure","Cancelled" or "Expired")
         * @return string
         */

        public function doRequest()
        {

            if($this->checkConfiguration() && $this->checkConfiguration(array('sTransactionId')))
            {

                $sTimestamp = gmdate('Y-m-d') . 'T' . gmdate('H:i:s') . '.000Z';
                $sMessage = $this->removeSpaceCharacters($sTimestamp . $this->sMerchantId . $this->sSubId . $this->sTransactionId);
                $sToken = $this->getCertificateFingerprint();
                $sTokenCode = $this->getSignature($sMessage);
                $sTokenCode = base64_encode($sTokenCode);

                $sXmlMessage = '<?xml version="1.0" encoding="UTF-8" ?>' . $this->LF
                . '<AcquirerStatusReq xmlns="http://www.idealdesk.com/Message" version="1.1.0">' . $this->LF
                . '<createDateTimeStamp>' . utf8_encode($sTimestamp) . '</createDateTimeStamp>' . $this->LF
                . '<Merchant>'
                . '<merchantID>' . utf8_encode($this->sMerchantId) . '</merchantID>' . $this->LF
                . '<subID>' . utf8_encode($this->sSubId) . '</subID>' . $this->LF
                . '<authentication>SHA1_RSA</authentication>' . $this->LF
                . '<token>' . utf8_encode($sToken) . '</token>' . $this->LF
                . '<tokenCode>' . utf8_encode($sTokenCode) . '</tokenCode>' . $this->LF
                . '</Merchant>' . $this->LF
                . '<Transaction>'
                . '<transactionID>' . utf8_encode($this->sTransactionId) . '</transactionID>' . $this->LF
                . '</Transaction>'
                . '</AcquirerStatusReq>';

                $sXmlReply = $this->postToHost($this->sAquirerUrl, $sXmlMessage, 10);

                if($sXmlReply)
                {

                    if($this->parseFromXml('errorCode', $sXmlReply)) // Error found
                    {
                        // Add error to error-list
                        $this->setError($this->parseFromXml('errorMessage', $sXmlReply), $this->parseFromXml('errorCode', $sXmlReply), __FILE__, __LINE__);                    
                    }

                    else
                    {
                        $sTimestamp = $this->parseFromXml('createDateTimeStamp', $sXmlReply);
                        $sTransactionId = $this->parseFromXml('transactionID', $sXmlReply);
                        $sTransactionStatus = $this->parseFromXml('status', $sXmlReply);

                        $sAccountNumber = $this->parseFromXml('consumerAccountNumber', $sXmlReply);
                        $sAccountName = $this->parseFromXml('consumerName', $sXmlReply);
                        $sAccountCity = $this->parseFromXml('consumerCity', $sXmlReply);

                        $sMessage = $this->removeSpaceCharacters($sTimestamp . $sTransactionId . $sTransactionStatus . $sAccountNumber);

                        $sSignature = base64_decode($this->parseFromXml('signatureValue', $sXmlReply));
                        $sFingerprint = $this->parseFromXml('fingerprint', $sXmlReply);

                        if(strcasecmp($sFingerprint, $this->getCertificateFingerprint(true)) !== 0)
                        {

                            // Invalid Fingerprint
                            $this->setError('Unknown fingerprint.', false, __FILE__, __LINE__);
                        }

                        elseif($this->verifySignature($sMessage, $sSignature) == false)
                        {

                            // Invalid Fingerprint
                            $this->setError('Bad signature.', false, __FILE__, __LINE__);
                        }

                        else
                        {
                            // $this->sTransactionId = $sTransactionId;
                            $this->sTransactionStatus = strtoupper($sTransactionStatus);

                            $this->sAccountCity = $sAccountCity;
                            $this->sAccountName = $sAccountName;
                            $this->sAccountNumber = $sAccountNumber;

                            return $this->sTransactionStatus;
                        }
                    }
                }
            }


            return false;
        }
    }

?>
Martijn Wieringa
Martijn Wieringa
19 jaar geleden
 
0 +1 -0 -1
Hmm, waar zijn de reacties op dit script gebleven? :)
Ericbruggema x
ericbruggema x
19 jaar geleden
 
0 +1 -0 -1
Geen ideem maar de template is ook verneukt :D
Midas
Midas
19 jaar geleden
 
0 +1 -0 -1
Er staan nog een hoop reacties hoor. :-)
Niet zo snel scrollen. :P
Martijn Wieringa
Martijn Wieringa
19 jaar geleden
 
0 +1 -0 -1
lol; hmm; ik zie ut.. :p
bedankt arend
Hans boogaard
hans boogaard
16 jaar geleden
 
0 +1 -0 -1
hallo na het nieuwe sertifikaat van ing in de map te hebben geplaats kunnen de klanten niet meer via ideal betalen.

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
Niels: code verwijderd.


wat heb ik fout gedaan en kan iemand me daar mee helpen
Niels K
Niels K
16 jaar geleden
 
0 +1 -0 -1
Beste Hans,

Graag een nieuw topic openen zodat het in de library overzichtelijk blijft.

Alvast bedankt,

Niels kieviet
PHP hulp
PHP hulp
0 seconden vanaf nu
 

Gesponsorde koppelingen
Hans boogaard
hans boogaard
16 jaar geleden
 
0 +1 -0 -1
oke dacht dat het hier thuis hoorde

Om te reageren heb je een account nodig en je moet ingelogd zijn.

Inhoudsopgave

  1. ideal-professional

Labels

  • Geen tags toegevoegd.

Navigatie

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.