@sails-pay/paystack 0.0.1 → 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 CHANGED
@@ -2,5 +2,6 @@ const methods = require('./machines')
2
2
  module.exports = {
3
3
  identity: 'sails-paystack',
4
4
  config: {},
5
- checkout: methods.checkout
5
+ checkout: methods.checkout,
6
+ verify: methods.verify
6
7
  }
@@ -6,16 +6,34 @@
6
6
  */
7
7
 
8
8
  module.exports = {
9
- PAYSTACK_API_KEY: {
9
+ PAYSTACK_SECRET_KEY: {
10
10
  type: 'string',
11
- friendlyName: 'API Key',
12
- description: 'A valid Paystack API Key',
11
+ friendlyName: 'Secret Key',
12
+ description: 'A valid Paystack Secret Key',
13
13
  protect: true,
14
14
  whereToGet: {
15
15
  url: 'https://dashboard.paystack.com/#/settings/developers',
16
- description: 'Generate an API key in your Paystack dashboard.',
16
+ description: 'Generate a secret key in your Paystack dashboard.',
17
17
  extendedDescription:
18
- 'To generate an API key, you will first need to log in to your Paystack account, or sign up for one if you have not already done so.'
18
+ 'To generate a secret key, you will first need to log in to your Paystack account, or sign up for one if you have not already done so.'
19
19
  }
20
+ },
21
+ PAYSTACK_PUBLIC_KEY: {
22
+ type: 'string',
23
+ friendlyName: 'Public Key',
24
+ description: 'A valid Paystack Public Key',
25
+ whereToGet: {
26
+ url: 'https://dashboard.paystack.com/#/settings/developers',
27
+ description: 'Get your public key from your Paystack dashboard.',
28
+ extendedDescription:
29
+ 'To get your public key, you will first need to log in to your Paystack account, or sign up for one if you have not already done so.'
30
+ }
31
+ },
32
+ PAYSTACK_CALLBACK_URL: {
33
+ type: 'string',
34
+ friendlyName: 'Callback URL',
35
+ description: 'The default callback URL for Paystack transactions',
36
+ extendedDescription:
37
+ 'This URL will be used as the default callback for all transactions unless overridden per request.'
20
38
  }
21
39
  }
@@ -4,7 +4,7 @@ module.exports = require('machine').build({
4
4
  description: 'Creates and return a checkout authorization URL',
5
5
  moreInfoUrl: 'https://paystack.com/docs/api/transaction/#initialize',
6
6
  inputs: {
7
- apiKey: require('../helpers/parameters').PAYSTACK_API_KEY,
7
+ secretKey: require('../helpers/parameters').PAYSTACK_SECRET_KEY,
8
8
  amount: {
9
9
  type: 'number',
10
10
  description: 'Amount should be in the subunit of the supported currency'
@@ -89,7 +89,7 @@ module.exports = require('machine').build({
89
89
  },
90
90
  fn: async function (
91
91
  {
92
- apiKey,
92
+ secretKey,
93
93
  amount,
94
94
  email,
95
95
  currency,
@@ -107,12 +107,13 @@ module.exports = require('machine').build({
107
107
  exits
108
108
  ) {
109
109
  const adapterConfig = require('../adapter').config
110
+ const resolvedCallbackUrl = callbackUrl || adapterConfig.callbackUrl
110
111
  const payload = JSON.stringify({
111
112
  amount,
112
113
  email,
113
114
  currency,
114
115
  reference,
115
- callback_url: callbackUrl,
116
+ ...(resolvedCallbackUrl && { callback_url: resolvedCallbackUrl }),
116
117
  plan,
117
118
  invoice_limit: invoiceLimit,
118
119
  metadata,
@@ -125,7 +126,7 @@ module.exports = require('machine').build({
125
126
  const checkout = await fetch('/transaction/initialize', {
126
127
  method: 'POST',
127
128
  headers: {
128
- authorization: `Bearer ${apiKey || adapterConfig.apiKey}`
129
+ authorization: `Bearer ${secretKey || adapterConfig.secretKey}`
129
130
  },
130
131
  body: payload
131
132
  })
package/machines/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  module.exports = {
2
- checkout: require('./checkout')
2
+ checkout: require('./checkout'),
3
+ verify: require('./verify')
3
4
  }
@@ -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
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sails-pay/paystack",
3
- "version": "0.0.1",
3
+ "version": "0.2.0",
4
4
  "description": "Paystack adapter for Sails Pay",
5
5
  "main": "adapter.js",
6
6
  "scripts": {
Binary file