This Sails hook exposes methods for interacting with the Paystack API. Internally it uses the machinepack-paystack package
npm i sails-hook-paystack --save
After installation, you can access the methods to interact with Paystack API as helpers in your Sails application. Like so:
// api/controllers/admin/create-plan
// ...
const createdPlan = await sails.helpers.paystack.createPlan.with({
name: 'Plan from Sails Hook',
amount: 10000,
interval: 'monthly'
})
exits.success({createdPlan})
Note you didn't need to specify your Paystack secret key because this hook look for your secret key if not defined in the call to the helper in 3 places
- In
config/local.js
viasails.config.paystackSecret
- In
config/custom.js
(which you can override in yourenv/production.js
orenv/staging.js
) viasails.config.custom.paystackSecret
- In your app environment via
process.env.PAYSTACK_SECRET
To run the test in this machine, rename env.example
to .env
then replace the content with your Paystack test API Key
Now run test simply with:
npm test
Alternatively you can run tests by
PAYSTACK_API_KEY_FOR_TESTS=YOUR_PAYSTACK_TEST_API_KEY npm test