@@ -118,13 +118,13 @@ function ($x) {
118
118
119
119
if ((isset ($ opts ["https " ]) || isset ($ opts ["http " ]))) {
120
120
121
- try {
122
121
$ client = new Client (['request.options ' => ['exceptions ' => false ,]]);
123
122
124
123
$ url = isset ($ opts ["https " ]) ? 'https: ' . $ opts ["https " ] : 'http: ' . $ opts ["http " ];
125
124
$ response = null ;
126
125
127
- if ("List-Unsubscribe=One-Click " === $ unsubPost ) {
126
+ try {
127
+ if ($ unsubPost ) {
128
128
$ response = $ client ->request (
129
129
'POST ' ,
130
130
$ url ,
@@ -136,13 +136,16 @@ function ($x) {
136
136
$ response = $ client ->request ('GET ' , $ url );
137
137
}
138
138
139
+ $ code = $ response ->getStatusCode ();
140
+
139
141
140
142
$ body = $ response ->getBody ();
141
143
142
144
$ conversation ->setMeta ("List-Unsubscribe-Submitted " , ["status " => $ response ->getStatusCode (), "reason " => $ response ->getReasonPhrase ()]);
143
145
144
146
$ auth_user = auth ()->user ();
145
- $ created_by_user_id = $ auth_user ->id ;
147
+ error_log ($ auth_user );
148
+ $ created_by_user_id = (gettype ($ auth_user ) == "object " ) ? $ auth_user ->id : $ auth_user ;
146
149
\App \Thread::create (
147
150
$ conversation , Thread::TYPE_LINEITEM ,
148
151
'' ,
@@ -154,15 +157,20 @@ function ($x) {
154
157
'source_type ' => \App \Thread::SOURCE_TYPE_WEB ,
155
158
'body ' => $ body ,
156
159
'meta ' => [
157
- 'code ' => $ response -> getStatusCode () ,
160
+ 'code ' => $ code ,
158
161
'message ' => $ response ->getReasonPhrase ()
159
162
]
160
163
]
161
164
);
165
+
166
+ if ($ code >=200 && $ code <=299 ) {
167
+ $ conversation ->changeStatus (Conversation::STATUS_CLOSED ,$ auth_user , false );
168
+ }
169
+
162
170
} catch (ConnectException $ e ) {
163
171
164
172
$ auth_user = auth ()->user ();
165
- $ created_by_user_id = $ auth_user ->id ;
173
+ $ created_by_user_id = ( gettype ( $ auth_user) == " object " ) ? $ auth_user ->id : $ auth_user ;
166
174
\App \Thread::create (
167
175
$ conversation , Thread::TYPE_LINEITEM ,
168
176
'' ,
@@ -172,17 +180,22 @@ function ($x) {
172
180
'action_type ' => self ::ACTION_TYPE_UNSUBSCRIBE ,
173
181
'source_via ' => \App \Thread::PERSON_USER ,
174
182
'source_type ' => \App \Thread::SOURCE_TYPE_WEB ,
175
- 'body ' => "Something went wrong " ,
183
+ 'body ' => "Something went wrong. " . print_r ([ ' url ' => $ url , ' opts ' => $ opts , ]) ,
176
184
'meta ' => [
177
185
'code ' => 501 ,
178
- 'message ' => "Sorry, something went wrong: " . $ e ->getMessage ()
186
+ 'message ' => "Sorry, something went wrong: " . $ e ->getMessage (),
187
+ 'lineNumber ' => $ e ->getLine (),
188
+ 'trace ' =>$ e ->getTraceAsString (),
189
+ 'method ' => ($ unsubPost ) ? 'POST ' : "GET " ,
190
+ 'url ' => $ url ,
191
+ 'opts ' => $ opts ,
179
192
]
180
193
]
181
194
);
182
195
} catch (\Exception $ e ) {
183
196
184
197
$ auth_user = auth ()->user ();
185
- $ created_by_user_id = $ auth_user ->id ;
198
+ $ created_by_user_id = ( gettype ( $ auth_user) == " object " ) ? $ auth_user ->id : $ auth_user ;
186
199
\App \Thread::create (
187
200
$ conversation , Thread::TYPE_LINEITEM ,
188
201
'' ,
@@ -195,7 +208,13 @@ function ($x) {
195
208
'body ' => "Something went wrong " ,
196
209
'meta ' => [
197
210
'code ' => 501 ,
198
- 'message ' => "Sorry, something went wrong: " . $ e ->getMessage ()
211
+ 'message ' => "Sorry, something went wrong: " . $ e ->getMessage (),
212
+ 'lineNumber ' => $ e ->getLine (),
213
+ 'trace ' =>$ e ->getTraceAsString (),
214
+ 'method ' => ($ unsubPost ) ? 'POST ' : "GET " ,
215
+ 'user ' => json_encode ($ auth_user ),
216
+ 'url ' => $ url ,
217
+ 'opts ' => $ opts ,
199
218
]
200
219
]
201
220
);
@@ -326,4 +345,4 @@ function ($carry, $key) {
326
345
return $ headers ?? [];
327
346
}
328
347
329
- }
348
+ }
0 commit comments