2
2
3
3
namespace Drip \Connect \Model \ApiCalls ;
4
4
5
+ use Drip \Connect \Logger \Logger ;
6
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
7
+ use Magento \Framework \App \Config \Storage \WriterInterface ;
8
+ use Magento \Framework \ArchiveFactory ;
9
+ use Magento \Framework \Filesystem \DirectoryList ;
10
+ use Magento \Store \Model \StoreManagerInterface ;
11
+ use Drip \Connect \Model \Http \ClientFactory ;
12
+ use Drip \Connect \Model \Configuration ;
5
13
use \Drip \Connect \Model \Restapi \RestapiAbstract ;
14
+ use Laminas \Http \Response ;
15
+ use Laminas \Http \Client \Exception \ExceptionInterface ;
6
16
7
17
/**
8
18
* Restapi base class
@@ -11,16 +21,16 @@ class Base extends RestapiAbstract
11
21
{
12
22
13
23
/**
14
- * @var \Magento\Framework\App\Config\ ScopeConfigInterface
24
+ * @var ScopeConfigInterface
15
25
*/
16
26
protected $ scopeConfig ;
17
27
18
28
/**
19
- * @var \Drip\Connect\Model\Http\ ClientFactory
29
+ * @var ClientFactory
20
30
*/
21
31
protected $ connectHttpClientFactory ;
22
32
23
- /** @var \Magento\Store\Model\ StoreManagerInterface */
33
+ /** @var StoreManagerInterface */
24
34
protected $ storeManager ;
25
35
26
36
/**
@@ -37,14 +47,14 @@ class Base extends RestapiAbstract
37
47
* @param String $v3 API version
38
48
*/
39
49
public function __construct (
40
- \ Drip \ Connect \ Logger \ Logger $ logger ,
41
- \ Magento \ Framework \ App \ Config \ ScopeConfigInterface $ scopeConfig ,
42
- \ Magento \ Framework \ App \ Config \ Storage \ WriterInterface $ configWriter ,
43
- \ Magento \ Framework \ ArchiveFactory $ archiveFactory ,
44
- \ Magento \ Framework \ Filesystem \ DirectoryList $ directory ,
45
- \ Magento \ Store \ Model \ StoreManagerInterface $ storeManager ,
46
- \ Drip \ Connect \ Model \ Http \ ClientFactory $ connectHttpClientFactory ,
47
- \ Drip \ Connect \ Model \ Configuration $ config ,
50
+ Logger $ logger ,
51
+ ScopeConfigInterface $ scopeConfig ,
52
+ WriterInterface $ configWriter ,
53
+ ArchiveFactory $ archiveFactory ,
54
+ DirectoryList $ directory ,
55
+ StoreManagerInterface $ storeManager ,
56
+ ClientFactory $ connectHttpClientFactory ,
57
+ Configuration $ config ,
48
58
$ endpoint ,
49
59
$ v3 = false
50
60
) {
@@ -55,17 +65,17 @@ public function __construct(
55
65
$ archiveFactory ,
56
66
$ directory
57
67
);
58
- /*
68
+ /*
59
69
* Since the Drip extension is sending data through the WooBase class
60
- * we are clearing this to prevent issues in other parts of the codebase.
70
+ * we are clearing this to prevent issues in other parts of the codebase.
61
71
*/
62
72
}
63
73
64
74
/**
65
75
* Call the API
66
76
*
67
77
* @param \Drip\Connect\Model\Restapi\Request $request
68
- * @throws \Zend_Http_Client_Exception
78
+ * @throws ExceptionInterface
69
79
*/
70
80
protected function _callApi ($ request )
71
81
{
@@ -76,39 +86,51 @@ protected function _callApi($request)
76
86
$ this ->_httpClient ->setParameterPost ($ request ->getParametersPost ());
77
87
}
78
88
if (!empty ($ request ->getRawData ())) {
79
- $ this ->_httpClient ->setRawData ($ request ->getRawData ());
89
+ $ this ->_httpClient ->setRawBody ($ request ->getRawData ());
80
90
}
81
91
82
92
$ response = $ this ->_httpClient ->request ($ request ->getMethod ());
83
93
84
94
$ this ->_lastRequestUrl = $ this ->_httpClient ->getUri ();
85
- $ this ->_lastRequest = $ this ->_httpClient ->getLastRequest ();
95
+ $ this ->_lastRequest = $ this ->_httpClient ->getRequest ();
86
96
87
97
return $ response ;
88
98
}
89
99
90
100
protected function _forceValidResponse ($ request )
91
101
{
92
- return new \Zend_Http_Response (200 , ["Content-type " => "application/json; charset=utf-8 " ], json_encode ([
102
+ $ response = new Response ();
103
+ $ response ->setStatusCode (200 );
104
+ $ response ->getHeaders ()->addHeaderLine ("Content-Type " , "application/json; charset=utf-8 " );
105
+ $ response ->setContent (json_encode ([
93
106
"Status " => "OK " ,
94
107
"Message " => "Forced Valid Response "
95
108
]));
109
+ return $ response ;
96
110
}
97
111
98
112
protected function _forceInvalidResponse ($ request )
99
113
{
100
- return new \Zend_Http_Response (200 , ["Content-type " => "application/json; charset=utf-8 " ], json_encode ([
114
+ $ response = new Response ();
115
+ $ response ->setStatusCode (200 );
116
+ $ response ->getHeaders ()->addHeaderLine ("Content-Type " , "application/json; charset=utf-8 " );
117
+ $ response ->setContent (json_encode ([
101
118
"Status " => "OK " ,
102
119
"Message " => "Forced Invalid Response "
103
120
]));
121
+ return $ response ;
104
122
}
105
123
106
124
protected function _forceError ($ request )
107
125
{
108
- return new \Zend_Http_Response (500 , ["Content-type " => "application/json; charset=utf-8 " ], json_encode ([
126
+ $ response = new Response ();
127
+ $ response ->setStatusCode (500 );
128
+ $ response ->getHeaders ()->addHeaderLine ("Content-Type " , "application/json; charset=utf-8 " );
129
+ $ response ->setContent (json_encode ([
109
130
"Status " => "Error " ,
110
131
"Message " => "Forced Error Message "
111
132
]));
133
+ return $ response ;
112
134
}
113
135
114
136
/**
0 commit comments