@sails-pay/paystack 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/adapter.js +2 -1
- package/machines/index.js +2 -1
- package/machines/verify.js +45 -0
- package/package.json +1 -1
package/adapter.js
CHANGED
package/machines/index.js
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const fetch = require('../helpers/fetch')
|
|
2
|
+
module.exports = require('machine').build({
|
|
3
|
+
friendlyName: 'Verify transaction',
|
|
4
|
+
description: 'Verifies the status of a Paystack transaction by its reference',
|
|
5
|
+
moreInfoUrl: 'https://paystack.com/docs/api/transaction/#verify',
|
|
6
|
+
inputs: {
|
|
7
|
+
secretKey: require('../helpers/parameters').PAYSTACK_SECRET_KEY,
|
|
8
|
+
reference: {
|
|
9
|
+
type: 'string',
|
|
10
|
+
required: true,
|
|
11
|
+
description: 'The transaction reference used to initiate the transaction.'
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
exits: {
|
|
15
|
+
success: {
|
|
16
|
+
description: 'Transaction verified successfully.',
|
|
17
|
+
outputVariableName: 'transaction',
|
|
18
|
+
outputType: 'ref'
|
|
19
|
+
},
|
|
20
|
+
couldNotVerifyTransaction: {
|
|
21
|
+
description: 'Transaction could not be verified.',
|
|
22
|
+
extendedDescription:
|
|
23
|
+
'This indicates that an error was encountered while verifying the transaction.',
|
|
24
|
+
outputFriendlyName: 'Verify transaction error report.',
|
|
25
|
+
outputVariableName: 'errors'
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
fn: async function ({ secretKey, reference }, exits) {
|
|
29
|
+
const adapterConfig = require('../adapter').config
|
|
30
|
+
const result = await fetch(
|
|
31
|
+
`/transaction/verify/${encodeURIComponent(reference)}`,
|
|
32
|
+
{
|
|
33
|
+
method: 'GET',
|
|
34
|
+
headers: {
|
|
35
|
+
authorization: `Bearer ${secretKey || adapterConfig.secretKey}`
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
)
|
|
39
|
+
if (!result.status) {
|
|
40
|
+
return exits.couldNotVerifyTransaction(result)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return exits.success(result.data)
|
|
44
|
+
}
|
|
45
|
+
})
|