@@ -5,7 +5,7 @@ const path = require('path');
5
5
* Base class for AFIP web services
6
6
**/
7
7
module . exports = class AfipWebService {
8
- constructor ( webServiceOptions ) {
8
+ constructor ( webServiceOptions , options = { } ) {
9
9
if ( ! webServiceOptions ) {
10
10
throw new Error ( 'Missing Web Service Object' ) ;
11
11
}
@@ -53,15 +53,73 @@ module.exports = class AfipWebService {
53
53
**/
54
54
this . afip = webServiceOptions . afip ;
55
55
56
- if ( this . afip . options [ 'production' ] ) {
57
- this . WSDL = path . resolve ( __dirname , '../Afip_res' , this . WSDL ) ;
56
+ /**
57
+ * Options
58
+ *
59
+ * @var object
60
+ **/
61
+ this . options = options ;
62
+
63
+ if ( options [ 'generic' ] === true ) {
64
+ if ( typeof options [ 'WSDL' ] === 'undefined' ) {
65
+ throw new Error ( "WSDL field is required in options" ) ;
66
+ }
67
+
68
+ if ( typeof options [ 'URL' ] === 'undefined' ) {
69
+ throw new Error ( "URL field is required in options" ) ;
70
+ }
71
+
72
+ if ( typeof options [ 'WSDL_TEST' ] === 'undefined' ) {
73
+ throw new Error ( "WSDL_TEST field is required in options" ) ;
74
+ }
75
+
76
+ if ( typeof options [ 'URL_TEST' ] === 'undefined' ) {
77
+ throw new Error ( "URL_TEST field is required in options" ) ;
78
+ }
79
+
80
+ if ( typeof options [ 'service' ] === 'undefined' ) {
81
+ throw new Error ( "service field is required in options" ) ;
82
+ }
83
+
84
+ if ( this . afip . options [ 'production' ] === true ) {
85
+ this . WSDL = options [ 'WSDL' ] ;
86
+ this . URL = options [ 'URL' ] ;
87
+ } else {
88
+ this . WSDL = options [ 'WSDL_TEST' ] ;
89
+ this . URL = options [ 'URL_TEST' ] ;
90
+ }
91
+
92
+ if ( typeof options [ 'soapV1_2' ] === 'undefined' ) {
93
+ options [ 'soapV1_2' ] = true ;
94
+ }
95
+
96
+ this . soapv12 = options [ 'soapV1_2' ]
58
97
}
59
- else {
60
- this . WSDL = path . resolve ( __dirname , '../Afip_res' , this . WSDL_TEST ) ;
61
- this . URL = this . URL_TEST ;
98
+ else {
99
+ if ( this . afip . options [ 'production' ] ) {
100
+ this . WSDL = path . resolve ( __dirname , '../Afip_res' , this . WSDL ) ;
101
+ }
102
+ else {
103
+ this . WSDL = path . resolve ( __dirname , '../Afip_res' , this . WSDL_TEST ) ;
104
+ this . URL = this . URL_TEST ;
105
+ }
62
106
}
63
107
}
64
108
109
+ /**
110
+ * Get Web Service Token Authorization from WSAA
111
+ *
112
+ * @since 0.6
113
+ *
114
+ * @throws Error if an error occurs
115
+ *
116
+ * @return TokenAuthorization Token Authorization for AFIP Web Service
117
+ **/
118
+ async getTokenAuthorization ( )
119
+ {
120
+ return this . afip . GetServiceTA ( this . options [ 'service' ] ) ;
121
+ }
122
+
65
123
/**
66
124
* Send request to AFIP servers
67
125
*
0 commit comments