This repository was archived by the owner on Dec 27, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 9 files changed +41
-9
lines changed Expand file tree Collapse file tree 9 files changed +41
-9
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ use alexLE\DHLExpress\RequestedShipment;
18
18
use alexLE\DHLExpress\InternationalDetail;
19
19
20
20
21
- $credentials = new Credentials();
21
+ $credentials = new Credentials(true); // use testmode
22
22
$credentials
23
23
->setUsername('YOUR-USERNAME')
24
24
->setPassword('YOUR-PASSWORD');
Original file line number Diff line number Diff line change 17
17
use alexLE \DHLExpress \InternationalDetail ;
18
18
19
19
20
- $ credentials = new Credentials ();
20
+ $ credentials = new Credentials (true );
21
21
$ credentials
22
22
->setUsername ('YOUR-USERNAME ' )
23
23
->setPassword ('YOUR-PASSWORD ' );
Original file line number Diff line number Diff line change 15
15
use alexLE \DHLExpress \RequestedShipment ;
16
16
use alexLE \DHLExpress \InternationalDetail ;
17
17
18
- $ credentials = new Credentials ();
18
+ $ credentials = new Credentials (true );
19
19
$ credentials
20
20
->setUsername ('YOUR-USERNAME ' )
21
21
->setPassword ('YOUR-PASSWORD ' );
Original file line number Diff line number Diff line change 15
15
use alexLE \DHLExpress \RequestedShipment ;
16
16
use alexLE \DHLExpress \InternationalDetail ;
17
17
18
- $ credentials = new Credentials ();
18
+ $ credentials = new Credentials (true );
19
19
$ credentials
20
20
->setUsername ('YOUR-USERNAME ' )
21
21
->setPassword ('YOUR-PASSWORD ' );
Original file line number Diff line number Diff line change 17
17
use alexLE \DHLExpress \RequestedShipment ;
18
18
use alexLE \DHLExpress \InternationalDetail ;
19
19
20
- $ credentials = new Credentials ();
20
+ $ credentials = new Credentials (true );
21
21
$ credentials
22
22
->setUsername ('YOUR-USERNAME ' )
23
23
->setPassword ('YOUR-PASSWORD ' );
Original file line number Diff line number Diff line change 16
16
use alexLE \DHLExpress \RequestedShipment ;
17
17
use alexLE \DHLExpress \InternationalDetail ;
18
18
19
- $ credentials = new Credentials ();
19
+ $ credentials = new Credentials (true );
20
20
$ credentials
21
21
->setUsername ('YOUR-USERNAME ' )
22
22
->setPassword ('YOUR-PASSWORD ' );
Original file line number Diff line number Diff line change 16
16
use alexLE \DHLExpress \RequestedShipment ;
17
17
use alexLE \DHLExpress \InternationalDetail ;
18
18
19
- $ credentials = new Credentials ();
19
+ $ credentials = new Credentials (true );
20
20
$ credentials
21
21
->setUsername ('YOUR-USERNAME ' )
22
22
->setPassword ('YOUR-PASSWORD ' );
Original file line number Diff line number Diff line change @@ -13,6 +13,18 @@ class Credentials {
13
13
*/
14
14
protected $ password ;
15
15
16
+ /**
17
+ * @var bool
18
+ */
19
+ protected $ testMode ;
20
+
21
+ /**
22
+ * @param bool $testMode
23
+ */
24
+ public function __construct ($ testMode = false ) {
25
+ $ this ->testMode = $ testMode ;
26
+ }
27
+
16
28
/**
17
29
* @return string
18
30
*/
@@ -44,4 +56,21 @@ public function setPassword($password) {
44
56
$ this ->password = $ password ;
45
57
return $ this ;
46
58
}
59
+
60
+ /**
61
+ * @return bool
62
+ */
63
+ public function isTestMode () {
64
+ return $ this ->testMode ;
65
+ }
66
+
67
+ /**
68
+ * @param bool $testMode
69
+ * @return Credentials
70
+ */
71
+ public function setTestMode ($ testMode ) {
72
+ $ this ->testMode = $ testMode ;
73
+
74
+ return $ this ;
75
+ }
47
76
}
Original file line number Diff line number Diff line change 6
6
7
7
class ShipmentRequest {
8
8
9
- const ENDPOINT = 'https://wsbexpress.dhl.com/rest/sndpt/ShipmentRequest ' ;
9
+ const ENDPOINT_TEST = 'https://wsbexpress.dhl.com/rest/sndpt/ShipmentRequest ' ;
10
+ const ENDPOINT_LIVE = 'https://wsbexpress.dhl.com:443/rest/gbl/ShipmentRequest ' ;
10
11
11
12
/**
12
13
* @var Credentials
@@ -67,8 +68,10 @@ public function send() {
67
68
]
68
69
];
69
70
71
+ $ endpoint = ($ this ->credentials ->isTestMode ()) ? self ::ENDPOINT_TEST : self ::ENDPOINT_LIVE ;
72
+
70
73
try {
71
- $ apiResponse = $ client ->post (self :: ENDPOINT , $ options );
74
+ $ apiResponse = $ client ->post ($ endpoint , $ options );
72
75
} catch (TransferException $ e ) {
73
76
$ this ->errors [] = $ e ->getMessage ();
74
77
return false ;
You can’t perform that action at this time.
0 commit comments