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K,WAAW,SAElC,EAAI,SAAS,KAAK,EAC1B,IAGJ,EAAI,GAAG,OAAO,KACV,IACI,IAAI,EAAe,KAKnB,GAJG,EAAI,SAAS,OAAS,IACrB,EAAe,EAAI,SAAS,YAG7B,EAAI,YAAc,IACjB,QAAQ,IAAI,gCAAiC,EAAI,WAAY,GAC7D,EAAQ,OACL,CACH,QAAQ,IAAI,gCAAiC,EAAI,WAAY,GAC7D,MAAM,EAAQ,IAAI,MAAM,cAAc,EAAI,eAAe,EAAI,iBAC7D,EAAM,KAAmB,EAAI,WAC7B,EAAM,gBAAmB,EACzB,EAAM,aAAmB,KACzB,EAAM,KAAmB,EACzB,EAAO,EACX,CACJ,CAAE,MAAQ,GACN,EAAO,EACX,IACF,IAGN,EAAI,GAAG,SAAS,IACZ,EAAO,EAAM,IAGjB,EAAI,KAAK,GAEjB,EAGJ,OAAO,QAAU","file":"/npm/lhgetnet@1.0.5/lhgetnet.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/lhgetnet@1.0.5/lhgetnet.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\nconst https = require('https')\nconst querystring = require('querystring');\nconst zlib = require('zlib');\n\nclass LHGetNet {\n    constructor({ client_id, client_secret, seller_id, ambiente=null, debug=false }){\n        this.client_id = client_id;\n        this.client_secret = client_secret;\n        this.seller_id = seller_id;\n        this.authorization = null;\n        this.debug = debug;\n        \n        switch(ambiente || process.env.NODE_ENV){\n            case 'development':\n            case 'desenvolvimento': \n                this.baseUrl = 'https://api-sandbox.getnet.com.br'; \n                this.device_url = 'https://h.online-metrix.net/fp/tags.js?org_id=1snn5n9w&session_id=';\n                break;\n            case 'homologation': \n            case 'homologacao': \n                this.baseUrl = 'https://api-homologacao.getnet.com.br'; \n                this.device_url = 'https://h.online-metrix.net/fp/tags.js?org_id=1snn5n9w&session_id=';\n                break;\n            default: // Production\n                this.baseUrl = 'https://api.getnet.com.br';\n                this.device_url = 'https://h.online-metrix.net/fp/tags.js?org_id=k8vif92e&session_id=';\n        }\n    }\n\n    getOAuthToken(){\n        if(this.authorization){\n            return Promise.resolve(this.authorization);\n        }\n\n        return this.doApiRequest({\n            path: '/auth/oauth/v2/token',\n            headers: {\n                'Content-Type': 'application/x-www-form-urlencoded',\n                Authorization: 'Basic ' + Buffer.from(`${this.client_id}:${this.client_secret}`).toString('base64'),\n            },\n            data: querystring.stringify({\n                scope: 'oob',\n                grant_type: 'client_credentials'\n            })\n        }).then( resp => {\n            this.authorization = resp;\n            return resp;\n        });\n    }\n\n    tokenizarCartao({ card_number, customer_id }) {\n        return this.getOAuthToken().then(()=>{\n            return this.doApiRequest({\n                path: '/v1/tokens/card',\n                data: JSON.stringify({\n                    card_number, \n                    customer_id\n                })\n            });\n        });\n    }\n\n    armazenarCartaoCofre({ \n        number_token, brand, \n        cardholder_name, \n        expiration_month, expiration_year, \n        customer_id, cardholder_identification, \n        verify_card, security_code\n    }) {\n        return this.getOAuthToken().then(()=>{\n            return this.doApiRequest({\n                path: '/v1/cards',\n                data: JSON.stringify({\n                    number_token, \n                    brand, \n                    cardholder_name, \n                    expiration_month, \n                    expiration_year, \n                    customer_id, \n                    cardholder_identification, \n                    verify_card, \n                    security_code\n                })\n            });\n        });\n    }\n\n    listarCartoesCofre({ customer_id }) {\n        return this.getOAuthToken().then(()=>{\n            return this.doApiRequest({\n                method: 'GET',\n                path: `/v1/cards?customer_id=${customer_id}`,\n            });\n        });\n    }\n\n    obterCartaoCofre({ card_id }) {\n        return this.getOAuthToken().then(()=>{\n            return this.doApiRequest({\n                method: 'GET',\n                path: `/v1/cards/${card_id}`,\n            });\n        });\n    }\n\n    removerCartaoCofre({ card_id }) {\n        return this.getOAuthToken().then(()=>{\n            return this.doApiRequest({\n                method: 'DELETE',\n                path: `/v1/cards/${card_id}`,\n            });\n        });\n    }\n\n    verificarCartao({ \n        number_token, brand, cardholder_name, \n        expiration_month, expiration_year, security_code \n    }) {\n        return this.getOAuthToken().then(()=>{\n            return this.doApiRequest({\n                method: 'POST',\n                path: `/v1/cards/verification`,\n                data: JSON.stringify({\n                    number_token, brand, cardholder_name, \n                    expiration_month, expiration_year, security_code\n                })\n            });\n        });\n    }\n\n    pagarCartaoCredito({ \n        seller_id, amount, currency=\"BRL\",\n        order, customer, device, shippings=[], credit\n    }) {\n        return this.getOAuthToken().then(()=>{\n            return this.registerDeviceId({ \n                device_id: device.device_id \n            });\n        }).then(()=>{\n            return this.doApiRequest({\n                method: 'POST',\n                path: `/v1/payments/credit`,\n                data: JSON.stringify({\n                    seller_id: seller_id || this.seller_id,\n                    amount, currency, order, customer, \n                    device, shippings, credit\n                })\n            });\n        });\n    }\n\n    confirmarPagamentoCartaoCredito({ payment_id, amount }){\n        return this.getOAuthToken().then(()=>{\n            return this.doApiRequest({\n                method: 'POST',\n                path: `/v1/payments/credit/${payment_id}/confirm`,\n                data: JSON.stringify({ amount })\n            });\n        });\n    }\n\n    cancelarPagamento({ payment_id, cancel_amount }){\n        return this.getOAuthToken().then(()=>{\n            return this.doApiRequest({\n                method: 'POST',\n                path: `/v1/payments/cancel/request`,\n                data: JSON.stringify({\n                    payment_id,\n                    cancel_amount\n                })\n            });\n        });\n    }\n\n    cancelarPagamentoCartaoCredito({ payment_id }){\n        return this.getOAuthToken().then(()=>{\n            return this.doApiRequest({\n                method: 'POST',\n                path: `/v1/payments/credit/${payment_id}/cancel`,\n            });\n        });\n    }\n\n    finalizacaoPagamentoAutenticadoCartaoCredito({ payment_id, payer_authentication_response }){\n        return this.getOAuthToken().then(()=>{\n            return this.doApiRequest({\n                method: 'POST',\n                path: `/v1/payments/credit/${payment_id}/authenticated/finalize`,\n                data: JSON.stringify({ payer_authentication_response })\n            });\n        });\n    }\n\n    ajustarValorTransacaoCreditoPreAutorizada({ \n        payment_id, amount, currency=\"BRL\", \n        soft_descriptor, dynamic_mcc \n    }){\n        return this.getOAuthToken().then(()=>{\n            return this.doApiRequest({\n                method: 'POST',\n                path: `/v1/payments/credit/${payment_id}/adjustment`,\n                data: JSON.stringify({\n                    amount, currency, soft_descriptor, dynamic_mcc\n                })\n            });\n        });\n    }\n\n    pagarCartaoDebito({ \n        seller_id, amount, currency=\"BRL\",\n        order, customer, device, shippings=[], debit\n    }) {\n        return this.getOAuthToken().then(()=>{\n            return this.registerDeviceId({ \n                device_id: device.device_id \n            });\n        }).then(()=>{\n            return this.doApiRequest({\n                method: 'POST',\n                path: `/v1/payments/debit`,\n                data: JSON.stringify({\n                    seller_id: seller_id || this.seller_id,\n                    amount, currency, order, customer, \n                    device, shippings, debit\n                })\n            });\n        });\n    }\n\n    finalizacaoPagamentoAutenticadoCartaoDebito({ \n        payment_id, payer_authentication_response\n    }) {\n        return this.getOAuthToken().then(()=>{\n            return this.doApiRequest({\n                method: 'POST',\n                path: `/v1/payments/debit/${payment_id}/authenticated/finalize`,\n                data: JSON.stringify({\n                    payer_authentication_response\n                })\n            });\n        });\n    }\n\n    doApiRequest({ path, data=null, headers={}, method='POST' }){\n        const options = {\n            method,\n            headers: {\n                'Accept': 'application/json, text/plain, */*',\n                'Content-Type': \"application/json; charset=utf-8\",\n                'Authorization': this.authorization ? `${this.authorization.token_type} ${this.authorization.access_token}` : null,\n                'seller_id': this.seller_id,\n                ...headers\n            }\n        };\n\n        return new Promise((resolve, reject)=>{\n            const req = https.request(`${this.baseUrl}${path}`, options, res => {\n                res.lhbuffer = [];\n                res.on('data', d => {\n                    switch(res.headers[\"content-encoding\"]){\n                        case \"gzip\":\n                            res.lhbuffer.push(zlib.gunzipSync(d)); break;\n                        default:\n                            res.lhbuffer.push(d);\n                    }\n                });\n\n                res.on('end', () => {\n                    try {\n                        let responseData = null;\n                        if(res.lhbuffer.length > 0){\n                            responseData = JSON.parse(res.lhbuffer.toString());\n                        }\n\n                        if(res.statusCode <= 299) {\n                            resolve(responseData);\n                        } else {\n                            if(req.debug) {\n                                console.log(\"API PATH:\", path);\n                                console.log(\"OPTIONS :\", options);\n                                console.log(\"DATA    :\", data);\n                                console.log(\"REPLY   :\", responseData);\n                            }\n\n                            const error = new Error(`API ERROR [${res.statusCode}] ${res.statusMessage}`);\n                            error.code  = res.statusCode;\n                            error.request_options  = options;\n                            error.request_data     = data;\n                            error.data             = responseData;\n                            reject(error);\n                        }\n                    } catch ( E ) {\n                        reject(E);\n                    }\n                });\n            });\n\n            req.debug = this.debug;\n              \n            req.on('error', error => {\n                reject(error);\n            });\n            \n            if(data){\n                req.write(data)\n            }\n            req.end();\n        });\n    }\n\n    registerDeviceId({ device_id }){\n        const options = {\n            method: 'GET',\n            headers: {\n                'Accept': 'application/json, text/plain, */*',\n                'Content-Type': \"application/json; charset=utf-8\"\n            }\n        };\n\n        return new Promise((resolve, reject)=>{\n            console.log(\"## GETNET REGISTER DEVICE ID:\", `${this.device_url}${device_id}`);\n            const req = https.request(`${this.device_url}${device_id}`, options, res => {\n                res.lhbuffer = [];\n                res.on('data', d => {\n                    switch(res.headers[\"content-encoding\"]){\n                        case \"gzip\":\n                            res.lhbuffer.push(zlib.gunzipSync(d)); break;\n                        default:\n                            res.lhbuffer.push(d);\n                    }\n                });\n\n                res.on('end', () => {\n                    try {\n                        let responseData = null;\n                        if(res.lhbuffer.length > 0){\n                            responseData = res.lhbuffer.toString();\n                        }\n\n                        if(res.statusCode <= 299) {\n                            console.log(\"## GETNET REGISTER DEVICE ID:\", res.statusCode, responseData);\n                            resolve(responseData);\n                        } else {\n                            console.log(\"## GETNET REGISTER DEVICE ID:\", res.statusCode, res);\n                            const error = new Error(`API ERROR [${res.statusCode}] ${res.statusMessage}`);\n                            error.code             = res.statusCode;\n                            error.request_options  = options;\n                            error.request_data     = data;\n                            error.data             = responseData;\n                            reject(error);\n                        }\n                    } catch ( E ) {\n                        reject(E);\n                    }\n                });\n            });\n              \n            req.on('error', error => {\n                reject(error);\n            });\n            \n            req.end();\n        });\n    }\n}\n\nmodule.exports = LHGetNet;"]}