Skip to content

Commit 0979d7f

Browse files
committed
Add more ws options
1 parent 7a83d44 commit 0979d7f

File tree

2 files changed

+84
-6
lines changed

2 files changed

+84
-6
lines changed

src/Afip.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ var xmlParser = new xml2js.Parser({
1313
tagNameProcessors: [key => key.replace('soapenv:', '')]
1414
});
1515

16+
// Generic Web Service
17+
const AfipWebService = require('./Class/AfipWebService');
18+
19+
1620
// Available Web Services
1721
const ElectronicBilling = require('./Class/ElectronicBilling');
1822
const RegisterScopeFour = require('./Class/RegisterScopeFour');
@@ -252,4 +256,20 @@ Afip.prototype.CreateServiceTA = async function(service) {
252256
resolve();
253257
});
254258
}));
259+
}
260+
261+
/**
262+
* Create generic Web Service
263+
*
264+
* @param string service Web Service name
265+
* @param array options Web Service options
266+
*
267+
* @return AfipWebService Token Authorization for AFIP Web Service
268+
**/
269+
Afip.prototype.WebService = function (service, options)
270+
{
271+
options['service'] = service;
272+
options['generic'] = true;
273+
274+
return new AfipWebService({ afip: this }, options);
255275
}

src/Class/AfipWebService.js

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const path = require('path');
55
* Base class for AFIP web services
66
**/
77
module.exports = class AfipWebService {
8-
constructor(webServiceOptions){
8+
constructor(webServiceOptions, options = {}){
99
if (!webServiceOptions) {
1010
throw new Error('Missing Web Service Object');
1111
}
@@ -53,15 +53,73 @@ module.exports = class AfipWebService {
5353
**/
5454
this.afip = webServiceOptions.afip;
5555

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']
5897
}
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+
}
62106
}
63107
}
64108

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+
65123
/**
66124
* Send request to AFIP servers
67125
*

0 commit comments

Comments
 (0)