@@ -16,17 +16,40 @@ public function __construct()
1616 $ this ->config = new ConfigService ();
1717 $ this ->client = new HttpRequest (
1818 $ this ->config ->getApiUrl (),
19- ['Content-Type: application/json ' , 'Api-Token: ' . $ this ->config ->getApiSecret ()]
19+ [
20+ 'Content-Type: application/json ' ,
21+ 'Api-Token: ' . $ this ->config ->getApiSecret (),
22+ 'x-plugin-name: ' . $ this ->config ->getPluginName (),
23+ 'x-plugin-version: ' .$ this ->config ->getPluginVersion ()
24+ ]
2025 );
2126 }
2227
28+ public function logEvent ($ object )
29+ {
30+ try {
31+ $ data = $ object ->getExceptionData ();
32+
33+ $ this ->client ->post ('plugin/events ' , [
34+ 'plugin ' => $ this ->config ->getPluginName (),
35+ 'version ' => $ this ->config ->getPluginVersion (),
36+ 'response_status ' => strval ($ data ->response_code ),
37+ 'response_body ' => json_decode ($ data ->response_body ) ?: null ,
38+ 'request_body ' => $ data ->request_body ?: null ,
39+ 'origin_event ' => $ data ->request_url
40+ ]);
41+ }
42+ catch (\Exception $ e ) { }
43+ }
44+
2345 public function createOrder (array $ data = []): ?array
2446 {
2547 try {
2648 $ order = $ this ->client ->post ('orders ' , $ data );
2749 return $ order ;
2850 }
2951 catch (InvalidRequestException $ e ) {
52+ $ this ->logEvent ($ e );
3053 return ['error ' => true ];
3154 }
3255 }
@@ -39,6 +62,7 @@ public function cancelOrder(array $data = []): ?array
3962 return $ order ;
4063 }
4164 catch (InvalidRequestException $ e ) {
65+ $ this ->logEvent ($ e );
4266 return ['error ' => true ];
4367 }
4468 }
@@ -51,6 +75,7 @@ public function cancelInvoice(array $data = []): ?array
5175 return $ order ;
5276 }
5377 catch (InvalidRequestException $ e ) {
78+ $ this ->logEvent ($ e );
5479 return ['error ' => true ];
5580 }
5681 }
@@ -63,6 +88,7 @@ public function createInvoice(array $data = []): ?array
6388 return $ invoice ;
6489 }
6590 catch (InvalidRequestException $ e ) {
91+ $ this ->logEvent ($ e );
6692 return ['error ' => true ];
6793 }
6894 }
@@ -75,6 +101,7 @@ public function getPaymentMethods(): ?array
75101 return $ paymentMethods ;
76102 }
77103 catch (InvalidRequestException $ e ) {
104+ $ this ->logEvent ($ e );
78105 return ['error ' => true ];
79106 }
80107 }
@@ -87,6 +114,7 @@ public function getNetTerms(): ?array
87114 return $ paymentTerms ;
88115 }
89116 catch (InvalidRequestException $ e ) {
117+ $ this ->logEvent ($ e );
90118 return ['error ' => true ];
91119 }
92120 }
@@ -99,6 +127,7 @@ public function updateExternalInfo(array $data = []): ?array
99127 return $ order ;
100128 }
101129 catch (InvalidRequestException $ e ) {
130+ $ this ->logEvent ($ e );
102131 return ['error ' => true ];
103132 }
104133 }
0 commit comments