Skip to main content

Payment Gateway CLI

A powerful command-line interface for interacting with the Payment Gateway API. Perfect for testing, automation, and quick merchant operations without building a full integration.
Current Status: 80% CompleteCore authentication, merchant management, and API key features are fully functional. Payment operations coming soon.

Why Use the CLI?

Rapid Testing

Test payment flows without writing codeInstant feedback on API responses

Automation Ready

Script merchant setup and testingCI/CD integration for automated tests

Developer Friendly

Interactive prompts with validationColored output, tables, and progress indicators

Multi-Environment

Switch between dev, staging, productionIsolated configs per environment

Installation

Prerequisites

Go 1.23 or higherCheck your version:
go version
# Should output: go version go1.23.x
Install Go: Visit go.dev/dl or use your package manager.

1

Download Latest Release

Download the CLI binary for your operating system:Using curl:
# Linux (AMD64)
curl -L -o payment-cli https://github.com/rhaloubi/payment-gateway-cli/releases/latest/download/payment-cli-linux-amd64

# macOS (Intel)
curl -L -o payment-cli https://github.com/rhaloubi/payment-gateway-cli/releases/latest/download/payment-cli-darwin-amd64

# macOS (Apple Silicon)
curl -L -o payment-cli https://github.com/rhaloubi/payment-gateway-cli/releases/latest/download/payment-cli-darwin-arm64

# Windows (PowerShell)
curl.exe -L -o payment-cli.exe https://github.com/rhaloubi/payment-gateway-cli/releases/latest/download/payment-cli-windows-amd64.exe
2

Make Executable (Linux/macOS)

chmod +x payment-cli
3

Move to PATH

Linux/macOS:
sudo mv payment-cli /usr/local/bin/
Windows: Move payment-cli.exe to a directory in your PATH, or add its location to PATH.
4

Verify Installation

payment-cli --version
# Output: payment-cli version 1.0.0

Method 2: Build from Source

1

Clone Repository

git clone https://github.com/rhaloubi/payment-gateway-cli.git
cd payment-gateway-cli
2

Install Dependencies

go mod download
This installs:
  • cobra - CLI framework
  • color - Colored terminal output
  • tablewriter - Table formatting
  • spinner - Loading animations
  • promptui - Interactive prompts
  • yaml.v3 - Config file handling
3

Build Binary

Using Go:
go build -o payment-cli cmd/main.go
Using Makefile (if available):
make build
4

Install Globally (Optional)

# Linux/macOS
sudo mv payment-cli /usr/local/bin/

# Or use Makefile
make install

Quick Start

Initialize CLI

1

Run Init Command

payment-cli init
What it does:
  • Creates config directory: ~/.payment-cli/
  • Generates default config file
  • Sets up environment profiles (dev, staging, production)
2

Select Environment

? Select environment:
  ▸ development (http://localhost:8080)
    staging (https://staging.paymentgateway.com)
    production (https://paymentgateway.redahaloubi.com)
For testing, select production (live API server).
3

Confirm Configuration

payment-cli config show
Output:
📋 Current Configuration
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Environment:     production
API URL:         https://paymentgateway.redahaloubi.com
Output Format:   table
Color Enabled:   true

Core Commands

Authentication

Create a new user account:
payment-cli register
Interactive prompts:
? Enter your name: John Merchant
? Enter email: [email protected]
? Enter password: ********
? Confirm password: ********
Output:
✅ Registration successful!

User Details:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ID:     550e8400-e29b-41d4-a716-446655440000
Name:   John Merchant
Email:  [email protected]
Status: pending_verification

ℹ️  Please verify your email to access all features.

Merchant Management

Create a new merchant profile:
payment-cli merchant create
Interactive prompts:
? Business name: Your Store Inc
? Business email: [email protected]
? Business type:
  ▸ corporation
    llc
    sole_proprietorship
    partnership
? Website (optional): https://yourstore.com
Output:
✅ Merchant created successfully!

┌──────────────────────────────────────┬─────────────────────┐
│ Field                                │ Value               │
├──────────────────────────────────────┼─────────────────────┤
│ ID                                   │ merchant_abc123     │
│ Code                                 │ mch_xyz789def456    │
│ Business Name                        │ Your Store Inc      │
│ Email                                │ [email protected]
│ Status                               │ pending_review      │
│ Created                              │ 2026-01-24 10:00:00 │
└──────────────────────────────────────┴─────────────────────┘

ℹ️  Save the merchant ID for API key creation
Non-Interactive:
payment-cli merchant create \
  --name "Your Store Inc" \
  --email "[email protected]" \
  --type corporation \
  --website "https://yourstore.com"

API Key Management

Generate a new API key for payment processing:
payment-cli apikey create --merchant-id merchant_abc123
Interactive prompt:
? Enter key name: Production Server Key
Output:
✅ API Key created successfully!

⚠️  SAVE THIS KEY - IT WON'T BE SHOWN AGAIN!

┌─────────────────────────────────────────────────────────────────┐
│                                                                 │
│  pk_live_abc123def456ghi789jkl012mno345pqr678stu901vwx234yz   │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

Key Details:
  ID:      apikey_xyz789
  Name:    Production Server Key
  Prefix:  pk_live_
  Created: 2026-01-24 10:00:00

💡 Add to your environment:
export PAYMENT_GATEWAY_API_KEY="pk_live_abc123def456..."
Non-Interactive:
payment-cli apikey create \
  --merchant-id merchant_abc123 \
  --name "Production Server Key"

Configuration Management

View Configuration

payment-cli config show
Output:
📋 Configuration
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Current Environment: production

Environments:
  development
    API URL:  http://localhost:8080
    
  staging
    API URL:  https://staging.paymentgateway.com
    
  production ⭐
    API URL:  https://paymentgateway.redahaloubi.com

Preferences:
  Output Format: table
  Color Enabled: true
  Debug Mode:    false

Authentication:
  Logged in:  ✅ Yes
  User:       [email protected]
  Expires:    2026-01-25 10:00:00

Switch Environment

payment-cli config use staging
Output:
🔄 Switching environment...

From: production
To:   staging

✅ Environment switched to staging

New API URL: https://staging.paymentgateway.com

⚠️  You'll need to login again for this environment

Edit Preferences

# Set output format
payment-cli config set output json

# Enable debug mode
payment-cli config set debug true

# Disable colors
payment-cli config set color false

Advanced Usage

Health Check

Verify API connectivity:
payment-cli health
Output:
🏥 Health Check
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Checking: https://paymentgateway.redahaloubi.com/health

✅ API Gateway:     healthy
✅ Auth Service:    healthy
✅ Merchant Service: healthy
✅ Payment Service: healthy

Response Time: 145ms

All systems operational 🎉

Debug Mode

Enable verbose logging for troubleshooting:
payment-cli --debug merchant list
Output includes:
🐛 DEBUG: Loading config from /Users/john/.payment-cli/config.yaml
🐛 DEBUG: Current environment: production
🐛 DEBUG: API URL: https://paymentgateway.redahaloubi.com
🐛 DEBUG: Sending GET request to /api/v1/merchants
🐛 DEBUG: Authorization: Bearer eyJhbGci...
🐛 DEBUG: Response status: 200 OK
🐛 DEBUG: Response time: 234ms

📋 Your Merchants (2)
...

Output Formats

Pretty tables for readability:
payment-cli merchant list --format table
┌─────────────────┬────────────────┬────────────────┐
│ ID              │ Name           │ Status         │
├─────────────────┼────────────────┼────────────────┤
│ merchant_abc123 │ Your Store Inc │ active         │
└─────────────────┴────────────────┴────────────────┘

Example Workflows

Workflow 1: Initial Setup

Complete merchant onboarding from scratch:
# 1. Initialize CLI
payment-cli init

# 2. Register account
payment-cli register

# 3. Login
payment-cli login

# 4. Create merchant
payment-cli merchant create

# 5. Generate API key
payment-cli apikey create --merchant-id {merchant_id}

# 6. Test API connectivity
payment-cli health
Time: ~2 minutes

Workflow 2: Quick Testing

Test a new payment flow:
# 1. Login (if not already logged in)
payment-cli login

# 2. List your merchants
payment-cli merchant list

# 3. Get API key
payment-cli apikey list --merchant-id {merchant_id}

# 4. Test payment (coming soon)
payment-cli payment authorize \
  --amount 5000 \
  --currency USD \
  --card "4242424242424242"

Workflow 3: Team Onboarding

Add team member to existing merchant:
# 1. Admin logs in
payment-cli login

# 2. Invite team member (via Merchant API)
# Currently requires API call directly

# 3. New user registers
payment-cli register

# 4. New user can access merchant
payment-cli merchant list

Configuration File Structure

The CLI stores configuration in ~/.payment-cli/config.yaml:
# Current active environment
current_env: production

# Authentication token (auto-managed)
auth_token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

# Token expiry timestamp
token_expires_at: "2026-01-25T10:00:00Z"

# User information (cached)
current_user:
  id: "550e8400-e29b-41d4-a716-446655440000"
  name: "John Merchant"
  email: "[email protected]"

# Environment definitions
environments:
  development:
    api_url: http://localhost:8080
    
  staging:
    api_url: https://staging.paymentgateway.com
    
  production:
    api_url: https://paymentgateway.redahaloubi.com

# User preferences
preferences:
  output_format: table  # table | json | yaml
  color_enabled: true
  debug_mode: false
  auto_update_check: true
Security Note: The config file contains your access token. Protect it like a password:
# Set restrictive permissions (Linux/macOS)
chmod 600 ~/.payment-cli/config.yaml

# Don't commit to version control
echo ".payment-cli/" >> ~/.gitignore

Troubleshooting

Cause: Binary not in PATHSolutions:Option 1: Move to PATH
sudo mv payment-cli /usr/local/bin/
Option 2: Run from current directory
./payment-cli --help
Option 3: Add to PATH
export PATH=$PATH:$(pwd)
Cause: CLI not initializedSolution:
payment-cli init
Verify:
ls -la ~/.payment-cli/
# Should show config.yaml
Cause: API server not reachableSolutions:Check environment:
payment-cli config show
# Verify API URL is correct
Test connectivity:
curl https://paymentgateway.redahaloubi.com/health
Switch environment if needed:
payment-cli config use production
Cause: Token expired or invalidSolution:
# Check token status
payment-cli whoami

# If expired, login again
payment-cli login
Cause: Missing dependenciesSolution:
# Download all dependencies
go mod download

# Clean and rebuild
go clean
go mod tidy
go build -o payment-cli cmd/main.go

Coming Soon

Payment Commands (In Development)

# Authorize payment
payment-cli payment authorize \
  --amount 5000 \
  --currency USD \
  --card "4242424242424242" \
  --exp "12/2027" \
  --cvv "123"

# Capture payment
payment-cli payment capture {payment_id} --amount 5000

# Void payment
payment-cli payment void {payment_id} --reason "Customer requested"

# Refund payment
payment-cli payment refund {payment_id} \
  --amount 2500 \
  --reason "Partial refund"

# Get payment details
payment-cli payment get {payment_id}

# List payments
payment-cli payment list --status captured --limit 20

Interactive Mode (Planned)

# Start interactive shell
payment-cli interactive

# Output:
💳 Payment Gateway CLI (Interactive Mode)
Type 'help' for available commands, 'exit' to quit

payment-cli> merchant list
payment-cli> payment authorize --amount 5000
payment-cli> exit

Scripting & Automation

Bash Script Example

#!/bin/bash

# Setup script for new merchant
echo "🚀 Setting up new merchant..."

# Login
payment-cli login --email $ADMIN_EMAIL --password $ADMIN_PASSWORD

# Create merchant
MERCHANT_ID=$(payment-cli merchant create \
  --name "New Store" \
  --email "[email protected]" \
  --format json | jq -r '.data.merchant.id')

echo "✅ Merchant created: $MERCHANT_ID"

# Generate API key
API_KEY=$(payment-cli apikey create \
  --merchant-id $MERCHANT_ID \
  --name "Production Key" \
  --format json | jq -r '.data.plain_key')

echo "✅ API Key generated"
echo "🔑 Export to your server:"
echo "export PAYMENT_GATEWAY_API_KEY=\"$API_KEY\""

CI/CD Integration

# GitHub Actions example
name: Test Payment Integration

on: [push]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Install Payment CLI
        run: |
          curl -L -o payment-cli https://github.com/rhaloubi/payment-gateway-cli/releases/latest/download/payment-cli-linux-amd64
          chmod +x payment-cli
          sudo mv payment-cli /usr/local/bin/
      
      - name: Configure CLI
        run: |
          payment-cli init
          payment-cli config use production
      
      - name: Test Authentication
        run: |
          payment-cli login --email ${{ secrets.TEST_EMAIL }} --password ${{ secrets.TEST_PASSWORD }}
          payment-cli whoami
      
      - name: Verify Merchant Access
        run: |
          payment-cli merchant list --format json

Command Reference

Global Flags


Available Commands

Initialize CLI configurationUsage: payment-cli initOptions:
  • --force: Overwrite existing config
Register new user accountUsage: payment-cli register [--email EMAIL] [--name NAME] [--password PASSWORD]Interactive: If flags omitted, prompts for input
Authenticate userUsage: payment-cli login [--email EMAIL] [--password PASSWORD]Interactive: If flags omitted, prompts for input
Revoke current sessionUsage: payment-cli logout
Show current user infoUsage: payment-cli whoami
Create new merchantUsage: payment-cli merchant create [FLAGS]Flags:
  • --name: Business name
  • --email: Business email
  • --type: Business type (corporation, llc, etc.)
  • --website: Website URL
List all merchantsUsage: payment-cli merchant list [--format FORMAT]
Get merchant detailsUsage: payment-cli merchant get {merchant_id}
Create new API keyUsage: payment-cli apikey create --merchant-id {id} [--name NAME]
List merchant API keysUsage: payment-cli apikey list --merchant-id {id}
Show current configurationUsage: payment-cli config show
Switch environmentUsage: payment-cli config use {environment}Environments: development, staging, production
Check API healthUsage: payment-cli health

Tips & Best Practices

Store sensitive data in environment variables:
# Create .env file
cat > ~/.payment-cli/.env << EOF
[email protected]
PAYMENT_CLI_PASSWORD=SecurePass123!
EOF

# Load in your shell
source ~/.payment-cli/.env

# Use in commands
payment-cli login --email $PAYMENT_CLI_EMAIL --password $PAYMENT_CLI_PASSWORD
Never commit sensitive data to version control:
# Add to .gitignore
echo ".env" >> .gitignore

Questions? Contact support at [email protected]