2pay-mcp-server

mcsacca/2pay-mcp-server

3.2

If you are the rightful owner of 2pay-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

The 2Pay MCP Server is a Model Context Protocol server designed to facilitate interactions with the 2Checkout/Verifone 2Pay.js payment API, enabling AI assistants to manage payment processing, subscriptions, and orders through natural language.

Tools
5
Resources
0
Prompts
0

2Pay MCP Server

npm version License: MIT

A Model Context Protocol (MCP) server for the 2Checkout/Verifone 2Pay.js payment API. This server enables AI assistants like Claude to interact with payment processing, subscription management, and order operations through natural language.

Table of Contents

Features

  • Order Management: Place orders with 2Pay.js tokens, retrieve order details, search orders, process refunds
  • Subscription Management: Full lifecycle management including renewals, upgrades, payment updates
  • Customer Management: Create, update, and manage customer records and their subscriptions
  • Product Catalog: Query and manage products, pricing configurations, and price options
  • Promotions: Create discounts, generate coupon codes, manage promotional campaigns

Prerequisites

  • Node.js 18 or higher
  • 2Checkout/Verifone merchant account
  • API credentials (merchant code and secret key)
  • For production: PCI DSS compliance awareness

Installation

Option 1: npm (Recommended)

npm install -g @mcsacca/2pay-mcp-server

Option 2: Using npx (No Installation)

You can run directly with npx - see Configuration below.

Option 3: From Source

git clone https://github.com/mcsacca/2pay-mcp-server.git
cd 2pay-mcp-server
npm install
npm run build

Configuration

Claude Desktop

Add to your Claude Desktop configuration file:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%\Claude\claude_desktop_config.json

Using npx (Recommended)
{
  "mcpServers": {
    "2pay": {
      "command": "npx",
      "args": ["-y", "@mcsacca/2pay-mcp-server"],
      "env": {
        "TWOCHECKOUT_MERCHANT_CODE": "your_merchant_code",
        "TWOCHECKOUT_SECRET_KEY": "your_secret_key",
        "TWOCHECKOUT_SANDBOX": "true"
      }
    }
  }
}
Using Global Installation
{
  "mcpServers": {
    "2pay": {
      "command": "2pay-mcp-server",
      "env": {
        "TWOCHECKOUT_MERCHANT_CODE": "your_merchant_code",
        "TWOCHECKOUT_SECRET_KEY": "your_secret_key",
        "TWOCHECKOUT_SANDBOX": "true"
      }
    }
  }
}
Using Local Build
{
  "mcpServers": {
    "2pay": {
      "command": "node",
      "args": ["/path/to/2pay-mcp-server/dist/index.js"],
      "env": {
        "TWOCHECKOUT_MERCHANT_CODE": "your_merchant_code",
        "TWOCHECKOUT_SECRET_KEY": "your_secret_key",
        "TWOCHECKOUT_SANDBOX": "true"
      }
    }
  }
}

Available Tools

Order Tools (7)

ToolDescription
place_orderPlace a new order using a 2Pay.js payment token
get_orderRetrieve order details by reference number
search_ordersSearch for orders with filters (date, status, customer)
refund_orderProcess a full or partial refund
get_payment_methodsGet available payment methods for a country
validate_order_referenceValidate order reference for 1-click purchase
get_invoiceGet invoice details for an order

Subscription Tools (22)

ToolDescription
get_subscriptionRetrieve subscription details by reference
search_subscriptionsSearch subscriptions with filters
enable_subscriptionEnable a disabled subscription
disable_subscriptionDisable an active subscription
cancel_subscriptionCancel a subscription
update_subscription_paymentUpdate payment method with 2Pay.js token
get_next_renewal_pricePreview next billing amount
get_subscription_historyGet transaction history
upgrade_subscriptionUpgrade to a higher-tier product/plan
downgrade_subscriptionDowngrade to a lower-tier product/plan
place_renewal_orderManually trigger a renewal
convert_trialConvert trial subscription to paid
pause_subscriptionTemporarily pause a subscription
resume_subscriptionResume a paused subscription
set_grace_periodSet grace period days for payment failures
enable_recurring_billingEnable automatic recurring billing
disable_recurring_billingDisable automatic recurring billing
get_subscription_payment_infoGet current payment method details
assign_subscription_to_customerTransfer subscription to different customer
get_upgrade_optionsGet available upgrade/downgrade paths
set_next_renewal_priceOverride the next renewal price
import_subscriptionImport subscription for migrations

Customer Tools (6)

ToolDescription
create_customerCreate a new customer record
get_customerGet customer by reference ID
get_customer_by_emailGet customer by email address
update_customerUpdate customer information
get_customer_subscriptionsList all subscriptions for a customer
delete_customerDelete a customer record

Product Tools (7)

ToolDescription
get_productGet product details by code
get_product_by_idGet product details by ID
search_productsSearch product catalog
enable_productEnable a product
disable_productDisable a product
get_product_pricingGet pricing configurations
get_price_optionsGet price options for a product

Promotion Tools (7)

ToolDescription
create_promotionCreate a new promotion/discount
get_promotionGet promotion details by code
update_promotionUpdate a promotion
delete_promotionDelete a promotion
search_promotionsSearch promotions
generate_couponsGenerate coupon codes for a promotion
get_couponsGet coupon codes for a promotion

Usage Tools (5)

ToolDescription
report_usageReport usage/consumption for metered billing subscriptions
get_usageRetrieve usage records for a subscription
delete_usageDelete a usage record
trigger_usage_billingTrigger immediate billing before normal cycle
import_usageBatch import multiple usage records

Lead Tools (5)

ToolDescription
create_leadCreate a lead for cart abandonment tracking
get_leadGet a lead by code
update_leadUpdate an existing lead
search_leadsSearch leads with filters
mark_leads_as_usedMark leads as used and stop follow-ups

Campaign Tools (8)

ToolDescription
create_cross_sell_campaignCreate a cross-sell campaign
get_cross_sell_campaignGet cross-sell campaign by code
update_cross_sell_campaignUpdate a cross-sell campaign
search_cross_sell_campaignsSearch cross-sell campaigns
create_upsell_campaignCreate an upsell campaign
update_upsell_campaignUpdate an upsell campaign
delete_upsell_campaignDelete an upsell campaign
search_upsell_campaignsSearch upsell campaigns

Shipping Tools (3)

ToolDescription
mark_order_shippedMark order as shipped with tracking
search_shipping_methodsSearch available shipping methods
get_shipping_priceGet shipping price for products

SKU Tools (4)

ToolDescription
set_sku_codeSet SKU code for a product
search_sku_codesSearch SKU codes
delete_sku_codeDelete a SKU code
generate_sku_schemaGenerate SKU schema for product

Account Tools (5)

ToolDescription
get_account_balanceGet current account balance
search_payoutsSearch historical payouts
get_countriesGet list of available countries
get_currenciesGet list of available currencies
get_account_timezoneGet account timezone

SSO Tools (4)

ToolDescription
sso_cartGenerate SSO token for cart
sso_by_customer_referenceSSO by customer reference
sso_by_subscription_referenceSSO by subscription reference
get_customer_info_by_sso_tokenGet customer info from SSO token

Internationalization Tools (5)

ToolDescription
add_promotion_translationAdd translation for a promotion
remove_promotion_translationsRemove promotion translations
set_cross_sell_campaign_textSet localized text for cross-sell campaign
get_cross_sell_campaign_textsGet all translations for campaign
set_sso_languageSet myAccount UI language for SSO

Resources & Prompts

Resources

  • 2pay://config - Current configuration status and API endpoints
  • 2pay://error-codes - Common error codes and their meanings

Prompts

  • create-order - Guided workflow for creating an order with a 2Pay.js token
  • manage-subscription - Guided workflow for subscription management operations
  • troubleshoot-payment - Diagnose and resolve payment issues

Usage Examples

Place an Order with 2Pay.js Token

{
  "token": "190f2d9c-0bbc-4ad0-a902-770adb8e7f90",
  "currency": "USD",
  "country": "US",
  "customerIP": "192.168.1.1",
  "items": [
    {
      "code": "PRODUCT_CODE",
      "quantity": 1
    }
  ],
  "billingDetails": {
    "firstName": "John",
    "lastName": "Doe",
    "email": "john@example.com",
    "phone": "+1234567890",
    "address1": "123 Main St",
    "city": "New York",
    "state": "NY",
    "zip": "10001",
    "countryCode": "US"
  },
  "externalReference": "ORDER-12345"
}

Place an Order with Dynamic Products

{
  "token": "your-2pay-token",
  "currency": "USD",
  "country": "US",
  "items": [
    {
      "name": "Custom Service",
      "quantity": 1,
      "price": 99.99,
      "isDynamic": true
    }
  ],
  "billingDetails": {
    "firstName": "Jane",
    "lastName": "Smith",
    "email": "jane@example.com",
    "address1": "456 Oak Ave",
    "city": "Los Angeles",
    "zip": "90001",
    "countryCode": "US"
  }
}

Search Orders

{
  "startDate": "2024-01-01",
  "endDate": "2024-12-31",
  "customerEmail": "customer@example.com",
  "status": "COMPLETE",
  "page": 1,
  "limit": 50
}

Search Subscriptions

{
  "customerEmail": "customer@example.com",
  "status": "Active",
  "recurringEnabled": true,
  "page": 1,
  "limit": 10
}

Update Subscription Payment Method

{
  "subscriptionReference": "SUB123456789",
  "eesToken": "new-2pay-token-from-frontend",
  "holderName": "John Doe"
}

Create a Promotion

{
  "name": "Summer Sale 2024",
  "description": "20% off all products",
  "startDate": "2024-06-01",
  "endDate": "2024-08-31",
  "discountType": "PERCENT",
  "discountValue": 20,
  "couponType": "SINGLE",
  "couponCode": "SUMMER20",
  "productCodes": ["PROD1", "PROD2"],
  "maximumOrders": 1000,
  "applyRecurring": false
}

Report Usage for Metered Billing

{
  "subscriptionReference": "SUB123456789",
  "optionCode": "API_CALLS",
  "units": 1500,
  "usageStart": "2024-01-01",
  "usageEnd": "2024-01-31",
  "description": "January API usage"
}

Pause a Subscription

{
  "subscriptionReference": "SUB123456789",
  "pauseDays": 30
}

Import a Subscription (Migration)

{
  "customerEmail": "customer@example.com",
  "productCode": "PREMIUM_PLAN",
  "startDate": "2024-01-01",
  "expirationDate": "2025-01-01",
  "recurringEnabled": true,
  "quantity": 1,
  "externalCustomerReference": "LEGACY-CUST-123"
}

Set Next Renewal Price

{
  "subscriptionReference": "SUB123456789",
  "price": 19.99,
  "currency": "USD"
}

Architecture

src/
├── index.ts              # MCP server entry point & tool handlers
├── auth/
│   └── authentication.ts # REST header & JSON-RPC session auth
├── tools/
│   ├── orders.ts         # Order management tools
│   ├── subscriptions.ts  # Subscription management tools
│   ├── customers.ts      # Customer management tools
│   ├── products.ts       # Product catalog tools
│   ├── promotions.ts     # Promotion management tools
│   ├── usage.ts          # Usage/metered billing tools
│   ├── leads.ts          # Lead management tools
│   ├── campaigns.ts      # Cross-sell/upsell campaigns
│   ├── shipping.ts       # Shipping management tools
│   ├── sku.ts            # SKU code management
│   ├── account.ts        # Account info tools
│   ├── sso.ts            # Single sign-on tools
│   └── i18n.ts           # Internationalization tools
├── types/
│   └── 2checkout.ts      # TypeScript type definitions
└── utils/
    └── api-client.ts     # REST & JSON-RPC API client

Authentication

The server supports two authentication methods:

  1. REST API: Uses X-Avangate-Authentication header with HMAC-SHA256 hash
  2. JSON-RPC API: Uses login method to obtain session ID (cached for 30 minutes)

Both methods use SHA-256 by default (MD5 deprecated).

Environment Variables

VariableRequiredDescription
TWOCHECKOUT_MERCHANT_CODEYesYour 2Checkout merchant code
TWOCHECKOUT_SECRET_KEYYesYour 2Checkout API secret key
TWOCHECKOUT_SANDBOXNoSet to true for sandbox environment
TWOCHECKOUT_BASE_URLNoOverride the API base URL

Security

Important Security Considerations

  • Never expose secret keys in client-side code or logs
  • Use environment variables for credentials, never hardcode them
  • Tokens expire after 30 minutes - generate fresh tokens for each transaction
  • EES_TOKEN_PAYMENT has no test mode - tokens must be generated from valid card data
  • PCI DSS compliance - Be aware of your compliance requirements when handling payment data

Best Practices

  1. Always use HTTPS endpoints
  2. Implement proper error handling
  3. Log transaction references, not payment details
  4. Use sandbox mode during development
  5. Regularly rotate API keys

Troubleshooting

Common Errors

ErrorCauseSolution
TOKEN_EXPIRED2Pay.js token older than 30 minutesGenerate a fresh token
INVALID_PAYMENTInvalid payment detailsVerify token and payment type
SUBSCRIPTION_NOT_FOUNDInvalid subscription referenceCheck the reference ID
CARD_DECLINEDBank declined the transactionCustomer should contact bank
INSUFFICIENT_FUNDSNot enough balanceCustomer needs different payment

Debug Mode

For development, check the configuration resource:

Use the 2pay://config resource to verify your setup

Session Issues

If you encounter session-related errors, the client automatically handles session refresh. If problems persist, restart the MCP server.

API Documentation

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

MIT License - see the file for details.


Built with the Model Context Protocol SDK.