Skip to content

Commit

Permalink
fix(auth): update auth and create transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
wisley7l committed Aug 28, 2023
1 parent 3347084 commit 6bf1907
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
3 changes: 1 addition & 2 deletions functions/lib/banrisul/auth/create-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module.exports = function (clientId, clientSecret, storeId, firestoreColl = 'ban
const self = this

let documentRef
// const hashLogin = Buffer.from(`${galaxpayId}:${galaxpayHash}`).toString('base64')

if (firestoreColl) {
documentRef = require('firebase-admin')
Expand All @@ -16,7 +15,7 @@ module.exports = function (clientId, clientSecret, storeId, firestoreColl = 'ban
this.preparing = new Promise((resolve, reject) => {
const authenticate = (accessToken, documentRef) => {
self.axios = createAxios(accessToken)
self.documentRef = documentRef
// self.documentRef = documentRef
if (documentRef) {
documentRef
.set({ accessToken }, { merge: true })
Expand Down
2 changes: 1 addition & 1 deletion functions/lib/banrisul/auth/create-axios.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const axios = require('axios')
module.exports = (accessToken, isGetToken) => {
const isSandbox = false // TODO:
const isSandbox = false // TODO: false

const headers = {
'Content-Type': 'application/json'
Expand Down
18 changes: 10 additions & 8 deletions functions/routes/ecom/modules/create-transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,20 @@ exports.post = async ({ appSdk, admin }, req, res) => {
}

if (params.payment_method.code === 'banking_billet') {
const banrisul = new Banrisul(appData.client_id, appData.client_secret, storeId)
try {
const banrisul = new Banrisul(appData.client_id, appData.client_secret, storeId)
console.log('>> s: ', storeId, ' beneficiary Code: ', appData.beneficiary_code)
if (appData.beneficiary_code) {
await banrisul.preparing

const documentRef = banrisul.documentRef && await banrisul.documentRef.get()
const docAuthBarisul = documentRef?.data()
const lastBilletNumber = (docAuthBarisul?.lastBilletNumber || 0) + 1
//
// const documentRef = banrisul.documentRef && await banrisul.documentRef.get()
// const docAuthBarisul = documentRef?.data()
// const lastBilletNumber = (docAuthBarisul?.lastBilletNumber || 0) + 1
const banrisulAxios = banrisul.axios

const ourNumber = getOurNumber(lastBilletNumber)
const body = createBodyToBillet(appData, params, ourNumber)
// const ourNumber = getOurNumber(lastBilletNumber)
const body = createBodyToBillet(appData, params)

console.log('>>body ', JSON.stringify(body))
redirectToPayment = false
Expand Down Expand Up @@ -72,8 +74,8 @@ exports.post = async ({ appSdk, admin }, req, res) => {

await collectionBillet.doc(orderId).set({ ...data, storeId, isHomologation: appData.is_homologation })

banrisul.documentRef.set({ lastBilletNumber }, { merge: true })
.catch(console.error)
// banrisul.documentRef.set({ lastBilletNumber }, { merge: true })
// .catch(console.error)

res.send({
redirect_to_payment: redirectToPayment,
Expand Down

0 comments on commit 6bf1907

Please sign in to comment.