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: v1.1.0 - Production ReadyCore authentication, merchant management, API keys, and payment intents with hosted checkout are fully functional.

Why Use the CLI?

Rapid Testing

Test payment flows without writing codeInstant feedback on API responses

Hosted Checkout

Create payment intents with browser checkoutReal-time payment status polling

Developer Friendly

Interactive prompts with validationColored output, tables, and progress indicators

Multi-Environment

Switch between development and productionProduction-first configuration

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/releases/latest/download/Payment-Gateway-linux-amd64

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

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

# Windows (PowerShell)
curl.exe -L -o payment-cli.exe https://github.com/rhaloubi/Payment-Gateway/releases/latest/download/Payment-Gateway_windows_amd64.zip
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.1.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 with production URLs
  • Sets up environment profiles (development, production)
  • Defaults to production environment
2

Verify Configuration

payment-cli config show
Output:
📋 Current Configuration
═══════════════════════════════════════

🌍 Environment Settings:
  Current Environment: production
  API URL:            https://paymentgateway.redahaloubi.com
  Auth URL:           https://paymentgateway.redahaloubi.com
  Payment URL:        https://paymentgateway.redahaloubi.com

🔐 Credentials:
  Access Token:       Not set
  User Email:         Not logged in
  Merchant ID:        Not set
  API Key:            Not set

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

📁 Config File:        /Users/john/.payment-cli/config.yaml
3

Register and Login

# Register new account
payment-cli auth register

# Login
payment-cli auth login

# Verify
payment-cli whoami

Core Commands

Authentication

Create a new user account:
payment-cli auth register
Interactive prompts:
Email: [email protected]
Full Name: John Merchant
Password: ********
Confirm Password: ********
Output:
✅ Account created successfully!
📧 Email: [email protected]
👤 Name: John Merchant
🆔 User ID: 550e8400-e29b-41d4-a716-446655440000

🚀 Next step: payment-cli auth login

Merchant Management

Create a new merchant profile:
payment-cli merchant create
Interactive prompts:
Business Name: Your Store Inc
Legal Name: Your Store Incorporated
all the business types: individual sole_proprietor partnership corporation non_profit
choose one of them
Business Type: corporation
Output:
✅ Merchant created!
🆔 ID: merchant_abc123def456
📧 Email: [email protected]
🏪 Business Name: Your Store Inc
🏢 Business Type: corporation
🔑 Status: pending
👤 Owner ID: 550e8400-e29b-41d4-a716-446655440000

💡 Next: payment-cli apikey create
Non-Interactive:
payment-cli merchant create \
  --business-name "Your Store Inc" \
  --legal-name "Your Store Incorporated" \
  --email "[email protected]"

API Key Management

Generate a new API key for payment processing:
payment-cli apikey create
Interactive prompt:
API Key Name: Production Server Key
Output:
✅ API key created!
🔑 API Key: Production Server Key
Please copy the plain key, it will not be shown again
🔑 Plain Key: pk_live_abc123def456ghi789jkl012mno345pqr678
IMPORTANT: Save this key immediately! It cannot be retrieved again.

Roles Management

List all available roles:
payment-cli roles view
Output:
🔑 Role ID: role_abc123
👤 Role: owner
📝 Description: Full access to merchant account
🔑 Role ID: role_def456
👤 Role: admin
📝 Description: Administrative access
🔑 Role ID: role_ghi789
👤 Role: developer
📝 Description: API access only

Configuration Management

Display complete configuration:
payment-cli config show
Output:
📋 Current Configuration
═══════════════════════════════════════

🌍 Environment Settings:
  Current Environment: production
  API URL:            https://paymentgateway.redahaloubi.com
  Auth URL:           https://paymentgateway.redahaloubi.com
  Payment URL:        https://paymentgateway.redahaloubi.com

🔐 Credentials:
  Access Token:       eyJhbGci...XVCJ9 (truncated)
  User Email:         [email protected]
  Merchant ID:        merchant_abc123def456
  API Key:            pk_live_ab...r678 (truncated)

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

📁 Config File:        /Users/john/.payment-cli/config.yaml

Payment Operations

Payment Intents (Hosted Checkout)

Payment Intents provide a hosted checkout page where customers can securely enter their payment details. The CLI opens the checkout in your browser and polls for completion.
Create a payment intent with hosted checkout:
payment-cli payment intent create
Interactive prompts:
💳 Create Payment Intent
═══════════════════════════════════════

Amount (in cents): 5000
Currency:
▸ USD
  EUR
  MAD
Description (optional, press enter to skip): Premium Plan Subscription
Customer Email (optional, press enter to skip): [email protected]
Capture Method:
▸ automatic
  manual
Output:
✅ Payment intent created!

📋 Payment Intent Details:
  ID:          pi_abc123def456ghi789
  Amount:      5000 USD ($50.00 USD)
  Status:      created
  Description: Premium Plan Subscription
  Expires:     2026-01-26 15:30:00

🌐 Checkout URL:
  https://checkout-page-amber.vercel.app/checkout/pi_abc123def456?client_secret=...

🚀 Opening checkout page in your browser...
💡 Complete the payment in your browser

⏳ Waiting for payment completion...
   (Press Ctrl+C to cancel polling)
After customer completes payment:
✅ Payment completed successfully!

📋 Payment Details:
  Intent ID:  pi_abc123def456ghi789
  Status:     authorized
  Payment ID: pay_xyz789uvw012rst345

🎉 Transaction complete!
How Payment Intent Polling Works:
  1. CLI creates payment intent via API
  2. Browser opens automatically with checkout URL
  3. Customer enters payment details on hosted page
  4. CLI polls payment status every 3 seconds
  5. Shows success/failure when payment completes
  6. Times out after 15 minutes if no completion
The checkout page handles all PCI compliance and security.

Direct Payment Authorization

Authorize a payment directly (without hosted checkout):
payment-cli payment authorize
Interactive prompts:
💳 Payment Authorization
-----------------------
Amount (in cents): 5000
Currency:
▸ USD
  EUR
  MAD
Card Number: 4242424242424242
Cardholder Name: John Doe
Expiration Month:
▸ 01 02 03 04 05 06 07 08 09 10 11 12
Expiration Year: 2027
CVV: ***
Customer Email: [email protected]
Output:
🧾 Payment details collected successfully
Authorization ID: pay_abc123def456
Status: authorized
Amount: 50 USD
Card Brand: visa
Card Last 4: •••• 4242
Auth Code: 123456
Fraud Decision: approve
Response Message: Approved
Transaction ID: txn_xyz789abc123

Transaction Management

View all transactions:
payment-cli payment transactions
Interactive prompts:
Limit (press enter for default): 10
Offset (press enter for default): 0
Filter by status:
▸ All (default)
  Authorized
  Voided
  Captured
  Refunded
Output:
Transaction ID: txn_abc123
Status: authorized
Amount: 50 USD
Card Brand: visa
Card Last 4: •••• 4242
-----------------------
Transaction ID: txn_def456
Status: captured
Amount: 75 EUR
Card Brand: mastercard
Card Last 4: •••• 5555
-----------------------

Advanced Features

Health Check

Verify API connectivity:
payment-cli health
Output:
✅ CLI is working!

Debug Mode

Enable verbose logging for troubleshooting:
payment-cli --debug merchant list
Or enable globally:
payment-cli config set debug_mode true

Output Formats

Human-readable tables:
payment-cli --output table merchant list

Example Workflows

Workflow 1: Complete Setup

From zero to payment-ready in 3 minutes:
# 1. Initialize
payment-cli init

# 2. Register account
payment-cli auth register

# 3. Login
payment-cli auth login

# 4. Create merchant
payment-cli merchant create

# 5. Generate API key
payment-cli apikey create

# 6. Store API key
payment-cli apikey store pk_live_your_key_here

# 7. Create test payment intent
payment-cli payment intent create

Workflow 2: Testing Payment Flow

Test a complete payment with hosted checkout:
# 1. Ensure you're logged in
payment-cli whoami

# 2. Verify API key is set
payment-cli config show

# 3. Create payment intent
payment-cli payment intent create

# 4. Complete payment in browser
# (CLI automatically opens checkout page)

# 5. View transaction
payment-cli payment transactions

Workflow 3: Environment Switching

Switch between development and production:
# Work on production
payment-cli config use production
payment-cli merchant create

# Switch to local dev
payment-cli config use development
payment-cli payment intent create

# Back to production
payment-cli config use production

Configuration File

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

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

# Credentials (auto-managed)
credentials:
  access_token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
  refresh_token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
  user_email: [email protected]
  merchant_id: merchant_abc123def456
  api_key: pk_live_abc123def456ghi789jkl012mno345pqr678

# User preferences
preferences:
  output_format: table  # table | json | yaml
  color_enabled: true
  debug_mode: false
Security Note:The config file contains your access token and API key. 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: Wrong environment or API server not reachableSolutions:Check environment:
payment-cli config show
# Verify API URL is correct
Switch to production:
payment-cli config use production
Test connectivity:
payment-cli health
Cause: Not logged in or token expiredSolution:
# Check login status
payment-cli whoami

# Login if needed
payment-cli auth login
Cause: No API key stored in configSolution:
# Create API key
payment-cli apikey create

# Store the key
payment-cli apikey store pk_live_your_key_here

# Verify
payment-cli config show
Cause: Platform not supported or browser not availableSolution: The checkout URL is displayed in the terminal. Copy and paste it into your browser manually. The CLI will still poll for payment completion.
Cause: Payment took longer than 15 minutesSolution: Check your merchant dashboard for payment status, or create a new payment intent.

Scripting & Automation

Bash Script Example

#!/bin/bash

# Automated merchant setup script
echo "🚀 Setting up new merchant..."

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

# Create merchant
echo "Creating merchant..."
payment-cli merchant create \
  --business-name "New Store" \
  --legal-name "New Store LLC" \
  --email "[email protected]"

# Create API key
echo "Generating API key..."
payment-cli apikey create

echo "✅ Setup complete!"
echo "💡 Don't forget to store your API key:"
echo "payment-cli apikey store <your_key>"

CI/CD Integration

# GitHub Actions example
name: Test Payment Integration

on: [push]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      
      - 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: Initialize CLI
        run: |
          payment-cli init
          payment-cli config use production
      
      - name: Test Authentication
        run: |
          payment-cli auth login \
            --email ${{ secrets.TEST_EMAIL }} \
            --password ${{ secrets.TEST_PASSWORD }}
          payment-cli whoami
      
      - name: Verify Merchant Access
        run: |
          payment-cli merchant get

Command Reference

Complete Command List

Initialize CLI configurationUsage: payment-cli initCreates config directory and default settings file.
Register new user accountUsage: payment-cli auth register [--email EMAIL] [--name NAME] [--password PASSWORD]Interactive: If flags omitted, prompts for input
Authenticate userUsage: payment-cli auth login [--email EMAIL] [--password PASSWORD]Interactive: If flags omitted, prompts for input
Revoke current sessionUsage: payment-cli auth logout
Show current user infoUsage: payment-cli whoami
Show detailed user profileUsage: payment-cli auth profile
Change user passwordUsage: payment-cli auth change-password [--old-password OLD] [--new-password NEW]
Create new merchantUsage: payment-cli merchant create [FLAGS]Flags:
  • --business-name: Business name
  • --legal-name: Legal name
  • --email: Business email
Get merchant detailsUsage: payment-cli merchant get
Access merchant accountsUsage: payment-cli merchant access-accounts [--merchant-id ID]
List team membersUsage: payment-cli merchant team
Invite team memberUsage: payment-cli merchant invite
List pending invitationsUsage: payment-cli merchant invitations
View merchant settingsUsage: payment-cli merchant setting
Create new API keyUsage: payment-cli apikey create
Store API key locallyUsage: payment-cli apikey store <plain_key>
View all available rolesUsage: payment-cli roles view
Create payment intent with hosted checkoutUsage: payment-cli payment intent create [FLAGS]Flags:
  • --amount, -a: Amount in cents
  • --currency, -c: Currency (USD, EUR, MAD)
  • --email, -e: Customer email
  • --description, -d: Payment description
  • --capture: Capture method (automatic/manual)
  • --order-id: Your internal order ID
Authorize payment directlyUsage: payment-cli payment authorize
List transactionsUsage: payment-cli payment transactions
Capture payment (dashboard only)Usage: payment-cli payment capture
Void payment (dashboard only)Usage: payment-cli payment void
Refund payment (dashboard only)Usage: payment-cli payment refund
Show current configurationUsage: payment-cli config show
Set configuration valueUsage: payment-cli config set <key> <value>Keys: output_format, color_enabled, debug_mode
Switch environmentUsage: payment-cli config use <environment>Environments: production, development
Reset configuration to defaultsUsage: payment-cli config reset
Check CLI and API healthUsage: payment-cli health

Global Flags


Tips & Best Practices

The CLI defaults to production environment for safety. If you’re testing locally:
payment-cli config use development
Never commit API keys to version control:
# Add to .gitignore
echo ".payment-cli/" >> .gitignore
echo "*.key" >> .gitignore
For CI/CD, use environment variables instead of storing credentials in config:
export PAYMENT_CLI_EMAIL=john@yourstore.com
export PAYMENT_CLI_PASSWORD=SecurePass123!

payment-cli auth login --email $PAYMENT_CLI_EMAIL --password $PAYMENT_CLI_PASSWORD
Use test card numbers for testing payment intents:
  • Success: 4242 4242 4242 4242
  • Decline: 4000 0000 0000 0002
  • Expired: 4000 0000 0000 0069
Any future expiry date and any 3-digit CVV will work.
The CLI polls payment status automatically, but you can also check your merchant dashboard for real-time updates.

What’s New in v1.1.0

Payment Intents

Create payment intents with hosted checkoutBrowser-based payment flow with automatic polling

Enhanced Config

Production-first configurationEasy environment switching

Better UX

Improved error messages and feedbackReal-time status updates

More Commands

Config set/use/reset commandsRoles management

Support

Need help? We’re here for you:

License

MIT License - See LICENSE file for details.
**Built with ❤️ for **Reda haloubi