Skip to content

Commit 52a3f65

Browse files
committed
refactor
1 parent 8210992 commit 52a3f65

File tree

4 files changed

+30
-33
lines changed

4 files changed

+30
-33
lines changed

dist/tillo-provider.js

+13-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/tillo-provider.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tillo-provider.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ function TilloProvider(this: any, options: TilloProviderOptions) {
8282
const path = "brands"
8383
const timestamp = new Date().getTime().toString()
8484

85-
const options: Map<string, string> = new Map([
85+
const signData: Map<string, string> = new Map([
8686
["apikey", this.shared.headers["API-Key"]],
8787
["method", "GET"],
8888
["path", path],
8989
["timestamp", timestamp],
9090
["apiSecret", this.shared.secret],
9191
])
9292

93-
this.shared.headers.Signature = getAuthSignature(options)
93+
this.shared.headers.Signature = getAuthSignature(signData)
9494
this.shared.headers.Timestamp = timestamp
9595
this.shared.headers.Accept = "application/json"
9696

@@ -103,45 +103,45 @@ function TilloProvider(this: any, options: TilloProviderOptions) {
103103
}
104104
}
105105
},
106-
digitalGC: {
106+
dgc: {
107107
cmd: {
108108
save: {
109109
action: async function(this: any, entize: any, msg: any) {
110110
const timestamp = new Date().getTime().toString()
111-
const clientRequestId = `${msg.q.user_id}-digitalissue-${timestamp}`
112-
const brand = msg.q.brand
113-
const currency = msg.q?.currency || "GBP"
114-
const value = msg.q.value
115-
const sector = msg.q?.sector || "other"
116111

117-
const options: Map<string, string> = new Map([
112+
const { clientRequestId, brand, currency, value, sector } = msg.q
113+
114+
const clientRId = clientRequestId || `${msg.q.user_id}-digitalissue-${timestamp}`
115+
const curr = currency || "GBP"
116+
117+
const signData: Map<string, string> = new Map([
118118
["apikey", this.shared.headers["API-Key"]],
119119
["method", "POST"],
120120
["path", "digital-issue"],
121-
["clientRequestId", clientRequestId],
121+
["clientRequestId", clientRId],
122122
["brand", brand],
123-
["currency", currency],
123+
["currency", curr],
124124
["value", value],
125125
["timestamp", timestamp],
126126
["apiSecret", this.shared.secret],
127127
])
128128

129-
this.shared.headers.Signature = getAuthSignature(options)
129+
this.shared.headers.Signature = getAuthSignature(signData)
130130
this.shared.headers.Timestamp = timestamp
131131
this.shared.headers.Accept = "application/json"
132132

133133
let json: any =
134134
await postJSON(makeUrl('digital/issue'), makeConfig({
135135
body: {
136-
client_request_id: clientRequestId,
136+
client_request_id: clientRId,
137137
brand: brand,
138138
face_value: {
139139
amount: value,
140-
currency,
140+
currency: curr,
141141
},
142142
delivery_method: 'url',
143143
fulfilment_by: 'partner',
144-
sector: sector
144+
sector: sector || "other"
145145
}
146146
}))
147147

test/tillo-provider.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('tillo-provider', () => {
5757
// if (!Config) return;
5858
// const seneca = await makeSeneca()
5959
//
60-
// const redeemTemplate = await seneca.entity("provider/tillo/digitalGC").save$({
60+
// const redeemTemplate = await seneca.entity("provider/tillo/dgc").save$({
6161
// user_id: "user01",
6262
// brand: "hobbycraft",
6363
// value: 10.00,

0 commit comments

Comments
 (0)