@sails-pay/paystack 0.0.1
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/LICENSE +21 -0
- package/adapter.js +6 -0
- package/helpers/fetch.js +31 -0
- package/helpers/parameters.js +21 -0
- package/machines/checkout.js +140 -0
- package/machines/index.js +3 -0
- package/package.json +35 -0
- package/sails-pay-paystack-0.0.1.tgz +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 The Sailscasts Company
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/adapter.js
ADDED
package/helpers/fetch.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const { fetch: undiciFetch } = require('undici')
|
|
2
|
+
|
|
3
|
+
const baseUrl = 'https://api.paystack.co'
|
|
4
|
+
const defaultHeaders = {
|
|
5
|
+
Accept: 'application/json',
|
|
6
|
+
'Content-Type': 'application/json'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const fetchImpl = undiciFetch
|
|
10
|
+
|
|
11
|
+
const fetch = async (path, options = {}) => {
|
|
12
|
+
const url = new URL(path, baseUrl).toString()
|
|
13
|
+
const mergedOptions = {
|
|
14
|
+
...options,
|
|
15
|
+
headers: {
|
|
16
|
+
...defaultHeaders,
|
|
17
|
+
...(options.headers || {})
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
const response = await fetchImpl(url, mergedOptions)
|
|
23
|
+
const jsonResponse = await response.json()
|
|
24
|
+
return jsonResponse
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error('Error occurred during fetch:', error)
|
|
27
|
+
throw error
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = fetch
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common input definitions (i.e. parameter definitions) that are shared by multiple files.
|
|
3
|
+
*
|
|
4
|
+
* @type {Dictionary}
|
|
5
|
+
* @constant
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
PAYSTACK_API_KEY: {
|
|
10
|
+
type: 'string',
|
|
11
|
+
friendlyName: 'API Key',
|
|
12
|
+
description: 'A valid Paystack API Key',
|
|
13
|
+
protect: true,
|
|
14
|
+
whereToGet: {
|
|
15
|
+
url: 'https://dashboard.paystack.com/#/settings/developers',
|
|
16
|
+
description: 'Generate an API key in your Paystack dashboard.',
|
|
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.'
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
const fetch = require('../helpers/fetch')
|
|
2
|
+
module.exports = require('machine').build({
|
|
3
|
+
friendlyName: 'Checkout',
|
|
4
|
+
description: 'Creates and return a checkout authorization URL',
|
|
5
|
+
moreInfoUrl: 'https://paystack.com/docs/api/transaction/#initialize',
|
|
6
|
+
inputs: {
|
|
7
|
+
apiKey: require('../helpers/parameters').PAYSTACK_API_KEY,
|
|
8
|
+
amount: {
|
|
9
|
+
type: 'number',
|
|
10
|
+
description: 'Amount should be in the subunit of the supported currency'
|
|
11
|
+
},
|
|
12
|
+
email: {
|
|
13
|
+
type: 'string',
|
|
14
|
+
description: "Customer's email address"
|
|
15
|
+
},
|
|
16
|
+
currency: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
description:
|
|
19
|
+
'The transaction currency. Defaults to your integration currency.'
|
|
20
|
+
},
|
|
21
|
+
reference: {
|
|
22
|
+
type: 'string',
|
|
23
|
+
description:
|
|
24
|
+
'Unique transaction reference. Only alphanumeric characters, hyphens (-), periods (.), and equal signs (=) are allowed.'
|
|
25
|
+
},
|
|
26
|
+
callbackUrl: {
|
|
27
|
+
type: 'string',
|
|
28
|
+
description:
|
|
29
|
+
'Fully qualified url, e.g. https://example.com. Use this to override the callback url provided on the dashboard for this transaction'
|
|
30
|
+
},
|
|
31
|
+
plan: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
description:
|
|
34
|
+
'If transaction is to create a subscription to a predefined plan, provide plan code here. This would invalidate the value provided in amount'
|
|
35
|
+
},
|
|
36
|
+
invoiceLimit: {
|
|
37
|
+
type: 'number',
|
|
38
|
+
description:
|
|
39
|
+
'Number of times to charge customer during subscription to plan'
|
|
40
|
+
},
|
|
41
|
+
metadata: {
|
|
42
|
+
type: 'string',
|
|
43
|
+
description: 'Stringified JSON object of custom data.',
|
|
44
|
+
moreInfoUrl: 'https://paystack.com/docs/payments/metadata/'
|
|
45
|
+
},
|
|
46
|
+
channels: {
|
|
47
|
+
type: 'ref',
|
|
48
|
+
description:
|
|
49
|
+
'An array of payment channels to control what channels you want to make available to the user to make a payment with.',
|
|
50
|
+
extendedDescription:
|
|
51
|
+
'Available channels include: ["card", "bank", "ussd", "qr", "mobile_money", "bank_transfer", "eft"]'
|
|
52
|
+
},
|
|
53
|
+
splitCode: {
|
|
54
|
+
type: 'string',
|
|
55
|
+
description: 'The split code of the transaction split.'
|
|
56
|
+
},
|
|
57
|
+
subaccount: {
|
|
58
|
+
type: 'string',
|
|
59
|
+
description: 'The code for the subaccount that owns the payment.'
|
|
60
|
+
},
|
|
61
|
+
transactionCharge: {
|
|
62
|
+
type: 'number',
|
|
63
|
+
description:
|
|
64
|
+
'An amount used to override the split configuration for a single split payment.',
|
|
65
|
+
extendedDescription:
|
|
66
|
+
'If set, the amount specified goes to the main account regardless of the split configuration.'
|
|
67
|
+
},
|
|
68
|
+
bearer: {
|
|
69
|
+
type: 'string',
|
|
70
|
+
description:
|
|
71
|
+
'Use this param to indicate who bears the transaction charges',
|
|
72
|
+
extendedDescription:
|
|
73
|
+
'Allowed values are: account or subaccount (defaults to account).'
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
exits: {
|
|
77
|
+
success: {
|
|
78
|
+
description: 'The checkout url.',
|
|
79
|
+
outputVariableName: 'checkoutUrl',
|
|
80
|
+
outputType: 'string'
|
|
81
|
+
},
|
|
82
|
+
couldNotCreateCheckoutUrl: {
|
|
83
|
+
description: 'Checkout URL could not be created.',
|
|
84
|
+
extendedDescription:
|
|
85
|
+
'This indicates that an error was encountered during checkout url creation.',
|
|
86
|
+
outputFriendlyName: 'Create checkout URL error report.',
|
|
87
|
+
outputVariableName: 'errors'
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
fn: async function (
|
|
91
|
+
{
|
|
92
|
+
apiKey,
|
|
93
|
+
amount,
|
|
94
|
+
email,
|
|
95
|
+
currency,
|
|
96
|
+
reference,
|
|
97
|
+
callbackUrl,
|
|
98
|
+
plan,
|
|
99
|
+
invoiceLimit,
|
|
100
|
+
metadata,
|
|
101
|
+
channels,
|
|
102
|
+
splitCode,
|
|
103
|
+
subaccount,
|
|
104
|
+
transactionCharge,
|
|
105
|
+
bearer
|
|
106
|
+
},
|
|
107
|
+
exits
|
|
108
|
+
) {
|
|
109
|
+
const adapterConfig = require('../adapter').config
|
|
110
|
+
const payload = JSON.stringify({
|
|
111
|
+
amount,
|
|
112
|
+
email,
|
|
113
|
+
currency,
|
|
114
|
+
reference,
|
|
115
|
+
callback_url: callbackUrl,
|
|
116
|
+
plan,
|
|
117
|
+
invoice_limit: invoiceLimit,
|
|
118
|
+
metadata,
|
|
119
|
+
channels,
|
|
120
|
+
split_code: splitCode,
|
|
121
|
+
subaccount,
|
|
122
|
+
transaction_charge: transactionCharge,
|
|
123
|
+
bearer
|
|
124
|
+
})
|
|
125
|
+
const checkout = await fetch('/transaction/initialize', {
|
|
126
|
+
method: 'POST',
|
|
127
|
+
headers: {
|
|
128
|
+
authorization: `Bearer ${apiKey || adapterConfig.apiKey}`
|
|
129
|
+
},
|
|
130
|
+
body: payload
|
|
131
|
+
})
|
|
132
|
+
if (!checkout.status) {
|
|
133
|
+
const errors = checkout
|
|
134
|
+
return exits.couldNotCreateCheckoutUrl(errors)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const checkoutUrl = checkout.data.authorization_url
|
|
138
|
+
return exits.success(checkoutUrl)
|
|
139
|
+
}
|
|
140
|
+
})
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sails-pay/paystack",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Paystack adapter for Sails Pay",
|
|
5
|
+
"main": "adapter.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "npm run test"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/sailscastshq/sails-pay.git",
|
|
12
|
+
"directory": "packages/sails-lemonsqueezy"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"Paystack",
|
|
16
|
+
"Sails",
|
|
17
|
+
"Pay",
|
|
18
|
+
"Payments",
|
|
19
|
+
"payment-gateway",
|
|
20
|
+
"online-payments",
|
|
21
|
+
"sails",
|
|
22
|
+
"sails.js",
|
|
23
|
+
"payment-integration"
|
|
24
|
+
],
|
|
25
|
+
"author": "Kelvin Omereshone <kelvin@sailscasts.com>",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/sailscastshq/sails-pay/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/sailscastshq/sails-pay#readme",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"machine": "^15.2.3",
|
|
33
|
+
"undici": "^6.19.2"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
Binary file
|