Skip to content

Migrate CLI framework from Vorpal to Oclif #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
33f6c75
update axios version
lukman-paystack Mar 16, 2021
658264b
migrate CLI framework from vorpal to oclif
lukman-paystack Apr 4, 2021
bae8515
add helper plugins
lukman-paystack Apr 4, 2021
831f3f9
Merge branch 'master' into version/2.0
lukman-paystack Apr 4, 2021
e850084
remove API keys from local DB
lukman-paystack Apr 13, 2021
d474311
Merge branch 'version/2.0' of github.com:PaystackOSS/paystack-cli int…
lukman-paystack Apr 13, 2021
a373a14
add info command
lukman-paystack Oct 27, 2021
c36a7cd
add info command
lukman-paystack Oct 27, 2021
61d52b4
migrate Oclif to V2
lukman-paystack Feb 15, 2022
5d97858
update oclif version
lukman-paystack Feb 23, 2022
d06fb7e
1.0.0-beta.1
lukman-paystack Feb 23, 2022
1b86870
update package name
lukman-paystack Feb 23, 2022
49b387c
1.0.0-beta.2
lukman-paystack Feb 23, 2022
44b7a9d
update package version
lukman-paystack Feb 23, 2022
bf262a0
1.0.0-nightly.0
lukman-paystack Feb 23, 2022
6135695
regenerate API commands from OpenAPI spec
lukman-paystack Mar 14, 2022
b83d862
some update sha
lukman-paystack Mar 15, 2022
7d513c5
build linux and windows packages
lukman-paystack Mar 17, 2022
ad1597f
add Open, Logout and WhoamI commands
lukman-paystack Mar 31, 2022
3e98f21
Merge branch 'version/2.0' of github.com:PaystackOSS/paystack-cli int…
lukman-paystack Mar 31, 2022
cbb5257
add logs
lukman-paystack Apr 28, 2022
3d94762
add logs to commands
lukman-paystack Apr 28, 2022
69831ea
remove rogue console.logs
lukman-paystack May 11, 2022
3af0523
remove rogue console.logs
lukman-paystack May 11, 2022
06a3607
Update Readme.MD
lukman-paystack Oct 31, 2023
7261f09
Update README.md
lukman-paystack Oct 31, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/
db.json
tmp/
.env
ios/
dist/
232 changes: 232 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@


[![Paystack Logo](https://res.cloudinary.com/drps6uoe4/image/upload/c_scale,w_200/v1584835701/Paystack-CeruleanBlue-StackBlue-HL_2_neik7g.png)](https://paystack.com)

# Paystack CLI


## About

As a developer, your most powerful tools - from basic bash commands, to version control and deployment tools - sit in your terminal. The Paystack CLI to makes it easier to set up, test, and manage your Paystack integrations right from that very same terminal.

With the CLI, you can:

1. Ping your preset webhook URL with sample event data
2. Tunnel Paystack events directly to your local server without installing third party software
3. Set up sample applications with fully integrated payment channels
4. Interact with Paystack API
5. *Interpret Paystack API Errors*

## Installing the Paystack CLI

### Install with npm


Paystack requires **[Node.js](https://nodejs.org/)** v16+ to run, To install with npm, run

`$ npm install -g @paystack-oss/dev-cli`

## Verify your installation

Check that your installation was successful by running

`$ paystack --version`

The output should look like

`> @paystack-oss/dev-cli/1.0.0-nightly.0 darwin-x64 node-v16.14.0`

## Getting started with the Paystack CLI

Now that you’re all setup, to access your Paystack account and execute commands, run

`$ paystack login`

You’ll be required to enter your credentials and choose the business you want to execute commands on its behalf.

### Commands

Run `$ paystack —help` to see a list of all commands you can use on the CLI. By default, all commands are run in test mode. To switch to live, append *`--domain live`* to the end of your command.

Read on for more information on what you can do with the CLI.

### Manage Webhooks

Whenever actions are carried out on your Paystack account, we trigger events which your application can listen and respond to. Before now, to implement webhook routes like these, you had to:

1. Ping your preset webhook URL with sample event data
2. Login to your Paystack Dashboard and set the webhook URL
3. Make a test payment or transfer
4. Review logs
5. Repeat

The CLI lets you listen to real-time webhook events on your integration and reduces all these steps are reduced to running a single command —

`$ paystack webhook listen localhost:8080/webhook`

This command tunnels all your test webhook events to your local server running on port 8080, making it possible for you to run end-to-end tests on your Paystack integration while in development mode.

You can also run health checks on your webhook URL by sending a sample webhook payload to your server. To do this, run:

`$ paystack webhook ping --event transfer.success --domain test`

Check our [documentation](https://paystack.com/docs/payments/webhooks/#supported-events) for a list of supported events.

### Use Sample Apps

We’ve built several sample apps showcasing different use cases and how to integrate Paystack with different programming languages.

You can set up any of the sample apps on your local machine — To do this, run:

`$ paystack sample sample_react ~/Work/Desktop`

### Interact with Paystack APIs

All Paystack public API endpoints are accessible via the Paystack CLI, and you can try out different API calls from the terminal before you start integrating. In this guide, you’ll learn how to

1. Initialize a transaction and get a checkout URL.
2. Verify a transaction
3. Charge a saved card.

First, we’ll call the [Initialize Transaction **API](https://paystack.com/docs/api#transaction-initialize)** to generate a checkout link. The command to do this is

```bash
$ paystack transaction initialize --email [email protected] --amount 10000 \
--callback_url https://paystack.com/docs
```

Your output should look like this

```bash
Authorization URL created
{
authorization_url: 'https://checkout.paystack.com/sf69sk0l6d5iuqm',
access_code: 'sf69sk0l6d5iuqm',
reference: 'kpu5vxesc5'
}
```

Great! We’ve created the transaction and can grab the `authorization_url` from the terminal and open it in a browser to complete the transaction.

Now that’s done, let’s verify the transaction by running

`$ paystack transaction verify --reference kpu5vxesc5`

Your output should look like this

```bash
Verification successful
{
id: 1693453689,
domain: 'test',
status: 'success',
reference: 'kpu5vxesc5',
amount: 10000,
metadata: '',
log: {
...
},
fees: 150,
authorization: {
authorization_code: 'AUTH_5uy1wm1940',
bin: '408408',
last4: '4081',
exp_month: '12',
exp_year: '2030',
channel: 'card',
card_type: 'visa ',
bank: 'TEST BANK',
country_code: 'NG',
brand: 'visa',
reusable: true,
signature: 'SIG_oIPc9Xyv8RuejFCaUi4i',
account_name: null
},
customer: {
...
email: '[email protected]',
customer_code: 'CUS_gnguwml5r732p7y',
...
},
plan: null,
split: {},
order_id: null,
paidAt: '2022-03-18T14:56:20.000Z',
createdAt: '2022-03-18T14:54:51.000Z',
requested_amount: 10000,
...
}
```

So far, so good! Now one more thing, we want to recurringly charge the card that was used for this transaction. To do that, we’ll need the customer’s email and authorization code from the verify transaction response. Grab those from ***customer.email*** and **authorization.authorization_code** in the JSON response respectively.

The command to run will be:

```bash
$ paystack transaction charge_authorization --email [email protected] \

--authorization_code AUTH_5uy1wm1940 --amount 1000
```

Output from this command should look like

```bash
Charge attempted
{
amount: 10000,
currency: 'NGN',
transaction_date: '2022-03-21T15:25:01.000Z',
status: 'success',
reference: 'h5ijyl88fau8b1l',
domain: 'test',
metadata: '',
gateway_response: 'Approved',
message: null,
channel: 'card',
ip_address: null,
log: null,
fees: 150,
authorization: {
authorization_code: 'AUTH_5uy1wm1940',
bin: '408408',
last4: '4081',
exp_month: '12',
exp_year: '2030',
channel: 'card',
card_type: 'visa ',
bank: 'TEST BANK',
country_code: 'NG',
brand: 'visa',
reusable: true,
signature: 'SIG_oIPc9Xyv8RuejFCaUi4i',
account_name: null
},
customer: {
id: 8072602,
first_name: null,
last_name: null,
email: '[email protected]',
customer_code: 'CUS_gnguwml5r732p7y',
phone: null,
metadata: null,
risk_action: 'deny',
international_format_phone: null
},
plan: null,
id: 1700095471
}
```

... and boom! we’re done.

You can test out all other public endpoints from the CLI. Request body and query parameters should be passed as flags to the command, for example, the Create Customer API requires and `email` param, and optional `phone`, `first_name` and `last_name` params, we can represent this as a command line argument in the following format:

```bash
$ paystack customer create --email [email protected] --first_name Jane --last_name Doe
```

Use our API reference to check the required parameters for any of the endpoints.

## Uninstall the CLI

`$ npm uninstall -g @paystack-oss/dev-cli`
13 changes: 13 additions & 0 deletions SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Auto generate API commands from Open API spec

Clean UP

check command names if properly formatted, commands that require changes start with '***'

Check for missing parameters, search `"params": []`

Remove BVN commands

oclif pack tarballs --targets=linux-arm

Notarize mac package
17 changes: 17 additions & 0 deletions bin/dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env node

const oclif = require('@oclif/core')

const path = require('path')
// const project = path.join(__dirname, '..', 'tsconfig.json')

// In dev mode -> use ts-node and dev plugins
process.env.NODE_ENV = 'development'

// require('ts-node').register({project})

// In dev mode, always show stack traces
oclif.settings.debug = true;

// Start the CLI
oclif.run().then(oclif.flush).catch(oclif.Errors.handle)
3 changes: 3 additions & 0 deletions bin/dev.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\dev" %*
5 changes: 5 additions & 0 deletions bin/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

const oclif = require('@oclif/core')

oclif.run().then(require('@oclif/core/flush')).catch(require('@oclif/core/handle'))
3 changes: 3 additions & 0 deletions bin/run.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\run" %*
21 changes: 0 additions & 21 deletions cli.js

This file was deleted.

46 changes: 0 additions & 46 deletions commands/api.js

This file was deleted.

Loading