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