Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
lmscunha committed Nov 28, 2024
1 parent 8210992 commit 52a3f65
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 33 deletions.
29 changes: 13 additions & 16 deletions dist/tillo-provider.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/tillo-provider.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions src/tillo-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ function TilloProvider(this: any, options: TilloProviderOptions) {
const path = "brands"
const timestamp = new Date().getTime().toString()

const options: Map<string, string> = new Map([
const signData: Map<string, string> = new Map([
["apikey", this.shared.headers["API-Key"]],
["method", "GET"],
["path", path],
["timestamp", timestamp],
["apiSecret", this.shared.secret],
])

this.shared.headers.Signature = getAuthSignature(options)
this.shared.headers.Signature = getAuthSignature(signData)
this.shared.headers.Timestamp = timestamp
this.shared.headers.Accept = "application/json"

Expand All @@ -103,45 +103,45 @@ function TilloProvider(this: any, options: TilloProviderOptions) {
}
}
},
digitalGC: {
dgc: {
cmd: {
save: {
action: async function(this: any, entize: any, msg: any) {
const timestamp = new Date().getTime().toString()
const clientRequestId = `${msg.q.user_id}-digitalissue-${timestamp}`
const brand = msg.q.brand
const currency = msg.q?.currency || "GBP"
const value = msg.q.value
const sector = msg.q?.sector || "other"

const options: Map<string, string> = new Map([
const { clientRequestId, brand, currency, value, sector } = msg.q

const clientRId = clientRequestId || `${msg.q.user_id}-digitalissue-${timestamp}`
const curr = currency || "GBP"

const signData: Map<string, string> = new Map([
["apikey", this.shared.headers["API-Key"]],
["method", "POST"],
["path", "digital-issue"],
["clientRequestId", clientRequestId],
["clientRequestId", clientRId],
["brand", brand],
["currency", currency],
["currency", curr],
["value", value],
["timestamp", timestamp],
["apiSecret", this.shared.secret],
])

this.shared.headers.Signature = getAuthSignature(options)
this.shared.headers.Signature = getAuthSignature(signData)
this.shared.headers.Timestamp = timestamp
this.shared.headers.Accept = "application/json"

let json: any =
await postJSON(makeUrl('digital/issue'), makeConfig({
body: {
client_request_id: clientRequestId,
client_request_id: clientRId,
brand: brand,
face_value: {
amount: value,
currency,
currency: curr,
},
delivery_method: 'url',
fulfilment_by: 'partner',
sector: sector
sector: sector || "other"
}
}))

Expand Down
2 changes: 1 addition & 1 deletion test/tillo-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('tillo-provider', () => {
// if (!Config) return;
// const seneca = await makeSeneca()
//
// const redeemTemplate = await seneca.entity("provider/tillo/digitalGC").save$({
// const redeemTemplate = await seneca.entity("provider/tillo/dgc").save$({
// user_id: "user01",
// brand: "hobbycraft",
// value: 10.00,
Expand Down

0 comments on commit 52a3f65

Please sign in to comment.