Forhopp

ForhoppPay Connect - Integration Guide

For detailed request/response payloads verified against source code, see the per-feature docs: index.md (docs 01-14). This integration guide provides narrative walkthroughs and code examples.

Overview

This guide covers step-by-step integration of ForhoppPay Connect into your application. It includes server-side integration, client-side SDK usage, WordPress/WooCommerce plugin setup, and Shopify app installation.


Server-Side Integration (Any Language)

Step 1: Get API Keys

  1. Log in to your ForhoppPay merchant dashboard
  2. Navigate to Connect > API Keys
  3. Click "Create API Key"
  4. Select environment: live or test
  5. Store the secret key securely (shown only once)

Step 2: Create a Charge

curl -X POST https://api.pay.forhopp.com/connect/v1/charges \
  -H "Authorization: Bearer sk_live_your_secret_key" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order_12345_v1" \
  -d '{
    "amount": 5000,
    "currency": "usd",
    "description": "Order #12345",
    "metadata": {
      "order_id": "12345",
      "customer_email": "customer@example.com"
    },
    "return_url": "https://yoursite.com/payment/success",
    "cancel_url": "https://yoursite.com/payment/cancel"
  }'

Response:

{
  "id": "ch_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6",
  "object": "charge",
  "amount": 5000,
  "currency": "usd",
  "status": "pending",
  "checkout_url": "https://pay.forhopp.com/checkout/ch_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6",
  "return_url": "https://yoursite.com/payment/success",
  "cancel_url": "https://yoursite.com/payment/cancel",
  "expires_at": 1234654290,
  "created": 1234567890,
  "livemode": true
}

Step 3: Redirect Customer to Checkout

Redirect the customer to the checkout_url from the response:

// Node.js / Express
app.post('/create-payment', async (req, res) => {
  const charge = await forhopppay.charges.create({
    amount: req.body.amount,
    currency: 'usd',
    description: `Order #${req.body.orderId}`,
    return_url: `${process.env.BASE_URL}/payment/success`,
    cancel_url: `${process.env.BASE_URL}/payment/cancel`
  });
  
  res.redirect(charge.checkout_url);
});
# Python / Flask
@app.route('/create-payment', methods=['POST'])
def create_payment():
    charge = forhopppay.Charge.create(
        amount=request.form['amount'],
        currency='usd',
        description=f"Order #{request.form['order_id']}",
        return_url=f"{BASE_URL}/payment/success",
        cancel_url=f"{BASE_URL}/payment/cancel"
    )
    return redirect(charge['checkout_url'])
// Java / Spring Boot
@PostMapping("/create-payment")
public String createPayment(@RequestParam int amount, @RequestParam String orderId) {
    Map<String, Object> params = Map.of(
        "amount", amount,
        "currency", "usd",
        "description", "Order #" + orderId,
        "return_url", baseUrl + "/payment/success",
        "cancel_url", baseUrl + "/payment/cancel"
    );
    
    ConnectChargeResponse charge = connectClient.createCharge(params);
    return "redirect:" + charge.getCheckoutUrl();
}

How Live Payment Processing Works

The hosted checkout page uses the PayPal JS SDK to process all payment methods. Here's the flow:

  1. Customer visits checkout_url → frontend renders the checkout page with available payment methods
  2. For PayPal: Customer clicks PayPal button → approves on PayPal popup → frontend receives order_id
  3. For Card: Customer enters card details in PayPal-hosted fields (Advanced Checkout) → PayPal JS SDK creates an order → frontend receives order_id
  4. For Google Pay / Apple Pay: Customer taps wallet button → PayPal JS SDK creates an order with wallet payment source → frontend receives order_id
  5. Frontend calls POST /checkout/{chargeId}/complete with the order_id
  6. Backend calls PayPal's POST /v2/checkout/orders/{order_id}/capture to actually move the money
  7. On success, customer is redirected to return_url

Key point: All payment methods are processed through PayPal's Orders API. The frontend uses PayPal JS SDK buttons/hosted-fields which handle card tokenization, 3DS authentication, and wallet integrations. The backend only needs to capture the resulting order.

Supported payment methods: card, paypal, googlepay, applepay, forhopppay_balance

Step 4: Handle Payment Result

After payment, the customer is redirected to your return_url (success) or cancel_url (cancel).

On your success page, verify the charge status:

app.get('/payment/success', async (req, res) => {
  const chargeId = req.query.charge_id;
  const charge = await forhopppay.charges.retrieve(chargeId);
  
  if (charge.status === 'authorized' || charge.status === 'captured') {
    // Payment successful - fulfill order
    await fulfillOrder(charge.metadata.order_id);
    res.render('success', { charge });
  } else {
    res.render('pending', { charge });
  }
});

Step 5: Capture the Charge

If your flow uses authorization + capture (e.g., for shipping confirmation):

curl -X POST https://api.pay.forhopp.com/connect/v1/charges/ch_xxx/capture \
  -H "Authorization: Bearer sk_live_your_secret_key" \
  -H "Content-Type: application/json" \
  -d '{"amount": 5000}'

Step 6: Set Up Webhooks

Webhooks provide real-time notifications for payment events. This is the recommended way to handle payment confirmations.

curl -X POST https://api.pay.forhopp.com/connect/v1/webhooks \
  -H "Authorization: Bearer sk_live_your_secret_key" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://yoursite.com/webhooks/forhopppay",
    "events": ["charge.completed", "charge.failed", "charge.refunded"],
    "description": "Production webhook"
  }'

Store the secret from the response securely.

Step 7: Handle Webhook Events

const crypto = require('crypto');

app.post('/webhooks/forhopppay', express.raw({type: 'application/json'}), (req, res) => {
  const signature = req.headers['forhopppay-signature'];
  const payload = req.body.toString();
  
  // Verify signature
  if (!verifySignature(payload, signature, process.env.WEBHOOK_SECRET)) {
    return res.status(401).send('Invalid signature');
  }
  
  const event = JSON.parse(payload);
  
  switch (event.type) {
    case 'charge.completed':
      handleChargeCompleted(event.data.object);
      break;
    case 'charge.failed':
      handleChargeFailed(event.data.object);
      break;
    case 'charge.refunded':
      handleChargeRefunded(event.data.object);
      break;
    case 'charge.disputed':
      handleChargeDisputed(event.data.object);
      break;
  }
  
  res.status(200).send('OK');
});

function verifySignature(payload, header, secret) {
  const parts = {};
  header.split(',').forEach(part => {
    const [key, value] = part.split('=');
    parts[key] = value;
  });
  
  const timestamp = parts['t'];
  const signature = parts['v1'];
  
  // Check timestamp (5 minute tolerance)
  if (Math.abs(Date.now() / 1000 - parseInt(timestamp)) > 300) {
    return false;
  }
  
  const expectedSignature = crypto
    .createHmac('sha256', secret)
    .update(`${timestamp}.${payload}`)
    .digest('hex');
  
  return crypto.timingSafeEqual(
    Buffer.from(expectedSignature),
    Buffer.from(signature)
  );
}

JavaScript SDK Integration

Installation

Via CDN:

<script src="https://js.forhopppay.com/v1/forhopppay.js"></script>

Via npm:

npm install @forhopppay/js

Basic Usage

import { ForhoppPay } from '@forhopppay/js';

// Initialize with your publishable key
const forhopppay = new ForhoppPay('pk_live_your_publishable_key');

// Redirect to hosted checkout
document.getElementById('pay-button').addEventListener('click', async () => {
  // Create charge on your server first, then redirect
  const response = await fetch('/api/create-charge', { method: 'POST' });
  const { chargeId } = await response.json();
  
  forhopppay.redirectToCheckout({ chargeId });
});

Payment Button

const button = forhopppay.createPaymentButton({
  container: '#payment-button',
  amount: 5000,
  currency: 'usd',
  label: 'Pay $50.00',
  onSuccess: (charge) => {
    console.log('Payment successful:', charge.id);
    window.location.href = '/order-confirmation';
  },
  onError: (error) => {
    console.error('Payment failed:', error.message);
    showErrorMessage(error.message);
  }
});

TypeScript Support

import { ForhoppPay, Charge, CheckoutOptions, PaymentButtonOptions } from '@forhopppay/js';

const forhopppay = new ForhoppPay('pk_live_xxx');

const options: CheckoutOptions = {
  chargeId: 'ch_xxx'
};

await forhopppay.redirectToCheckout(options);

WordPress / WooCommerce Plugin

Installation

  1. Download the ForhoppPay plugin from your merchant dashboard
  2. Upload to WordPress: Plugins > Add New > Upload Plugin
  3. Activate the plugin

Configuration

  1. Go to WooCommerce > Settings > Payments
  2. Click "ForhoppPay" to configure
  3. Enter your API keys:
    • Live Publishable Key: pk_live_xxx
    • Live Secret Key: sk_live_xxx
    • Test Publishable Key: pk_test_xxx
    • Test Secret Key: sk_test_xxx
  4. Enable/disable test mode
  5. Save changes

How It Works

  1. Customer selects ForhoppPay at checkout
  2. Plugin creates a charge via the Connect API
  3. Customer is redirected to pay.forhopp.com/checkout/{charge_id}
  4. After payment, customer returns to WooCommerce order confirmation
  5. Webhook updates order status automatically

Webhook Setup

The plugin automatically registers a webhook endpoint at:

https://yoursite.com/wp-json/forhopppay/v1/webhook

Configure this URL in your ForhoppPay dashboard.

Refunds

Refunds can be initiated from WooCommerce:

  1. Go to WooCommerce > Orders > [Order]
  2. Click "Refund"
  3. Enter amount and reason
  4. Click "Refund via ForhoppPay"

The plugin calls the Connect refund API automatically.

Plugin File Structure

forhopppay-woocommerce/
├── forhopppay-woocommerce.php          # Main plugin file
├── includes/
│   ├── class-forhopppay-gateway.php    # WC_Payment_Gateway implementation
│   ├── class-forhopppay-webhook.php    # Webhook handler
│   ├── class-forhopppay-api.php        # API client
│   └── class-forhopppay-logger.php     # Logging utility
├── assets/
│   ├── css/forhopppay-checkout.css
│   └── js/forhopppay-checkout.js
├── templates/
│   └── payment-form.php
└── readme.txt

Shopify App

Installation

  1. Install the ForhoppPay app from the Shopify App Store
  2. Authorize the app (OAuth flow)
  3. Link your ForhoppPay account
  4. Configure API keys in the app settings

OAuth Flow

The app uses Shopify's OAuth 2.0 flow:

  1. Merchant clicks "Install" in Shopify App Store
  2. App redirects to Shopify authorization page
  3. Merchant approves requested scopes: read_orders, write_orders, read_checkouts
  4. Shopify redirects back with authorization code
  5. App exchanges code for access token (stored encrypted)

Payment Flow

  1. Customer selects ForhoppPay at Shopify checkout
  2. App creates a charge via Connect API
  3. Customer completes payment on hosted checkout
  4. App resolves payment session with Shopify
  5. Order is marked as paid

Admin Dashboard

The embedded admin interface provides:

  • Recent transaction history
  • Connection status
  • API key configuration
  • Test mode toggle
  • Webhook configuration

App Structure

forhopppay-shopify/
├── src/
│   ├── index.ts                    # Express app entry
│   ├── routes/
│   │   ├── auth.ts                 # OAuth routes
│   │   ├── webhooks.ts             # Shopify webhooks
│   │   └── payments.ts             # Payment extension routes
│   ├── services/
│   │   ├── shopify.ts              # Shopify API client
│   │   └── forhopppay.ts           # ForhoppPay API client
│   └── ui/
│       └── pages/
│           ├── index.tsx           # Dashboard
│           └── settings.tsx        # Settings page
├── package.json
└── shopify.app.toml

Testing Your Integration

Use Test API Keys

Always use test keys (sk_test_*, pk_test_*) during development.

Test Card Numbers

Card Number Expected Result
4242424242424242 Payment succeeds
4000000000000002 Card declined
4000000000009995 Insufficient funds
4000000000000069 Expired card
4000000000000127 Incorrect CVC
4000000000000119 Processing error
4000000000003220 3D Secure required

Test PayPal Accounts

Email Expected Result
test-success@sandbox.paypal.com Payment succeeds
test-decline@sandbox.paypal.com Payment declined
test-pending@sandbox.paypal.com Payment pending

Webhook Testing

  1. Use a tool like ngrok to expose your local server
  2. Register your ngrok URL as a webhook endpoint using test keys
  3. Create test charges to trigger webhook events
  4. Verify your handler processes events correctly

Checklist Before Going Live

  • Switch from test keys to live keys
  • Verify webhook signature verification is working
  • Test the complete payment flow end-to-end
  • Implement idempotency keys for charge creation
  • Handle all webhook event types
  • Set up error handling and logging
  • Configure retry logic for API calls
  • Test refund flow
  • Verify return_url and cancel_url redirects work

Last Updated: March 2026


Recurring Subscriptions Integration

ForhoppPay Connect supports full recurring billing. Merchants create plans/prices, subscribe customers, and ForhoppPay handles all automatic charging, dunning, and payouts.

Step 1: Create a Plan and Price

# Create plan
curl -X POST https://api.pay.forhopp.com/api/v1/connect/plans \
  -H "Authorization: Bearer sk_live_xxx" \
  -H "Content-Type: application/json" \
  -d '{"name": "Pro Plan", "description": "Full access"}'

# Create price on the plan
curl -X POST https://api.pay.forhopp.com/api/v1/connect/plans/plan_xxx/prices \
  -H "Authorization: Bearer sk_live_xxx" \
  -H "Content-Type: application/json" \
  -d '{"amount_cents": 2000, "currency": "USD", "interval": "monthly", "interval_count": 1}'

Step 2: Create a Customer

curl -X POST https://api.pay.forhopp.com/api/v1/connect/customers \
  -H "Authorization: Bearer sk_live_xxx" \
  -H "Content-Type: application/json" \
  -d '{"email": "user@example.com", "name": "John Doe"}'

Step 3: Collect Payment via Hosted Checkout

Create a charge with metadata.intent: "subscription" to flag it for subscription creation after payment:

curl -X POST https://api.pay.forhopp.com/api/v1/connect/charges \
  -H "Authorization: Bearer sk_live_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 2000,
    "currency": "usd",
    "description": "Pro Plan - Monthly",
    "customerEmail": "user@example.com",
    "metadata": {"customer_id": "cus_xxx", "price_id": "price_xxx", "intent": "subscription"},
    "returnUrl": "https://yoursite.com/success",
    "cancelUrl": "https://yoursite.com/pricing"
  }'

Redirect customer to checkout_url. After payment completes, you receive a charge.captured webhook.

Step 4: Create Subscription After Payment

In your webhook handler, when you receive charge.captured with metadata.intent == "subscription":

curl -X POST https://api.pay.forhopp.com/api/v1/connect/subscriptions \
  -H "Authorization: Bearer sk_live_xxx" \
  -H "Content-Type: application/json" \
  -d '{"customer_id": "cus_xxx", "price_id": "price_xxx"}'

ForhoppPay now handles all recurring billing automatically.

Step 5: Handle Recurring Webhooks

Subscribe to these events for subscription lifecycle:

{
  "url": "https://yoursite.com/webhooks/forhopppay",
  "events": [
    "charge.captured",
    "subscription.created",
    "invoice.paid",
    "invoice.payment_failed",
    "subscription.canceled"
  ]
}
Event Action
invoice.paid Confirm access continues (no action needed)
invoice.payment_failed Show warning banner to user
subscription.canceled Revoke access

Step 6: Manage Subscriptions

# List all subscriptions
curl https://api.pay.forhopp.com/api/v1/connect/subscriptions \
  -H "Authorization: Bearer sk_live_xxx"

# Cancel a subscription at period end
curl -X POST https://api.pay.forhopp.com/api/v1/connect/subscriptions/sub_xxx/cancel?at_period_end=true \
  -H "Authorization: Bearer sk_live_xxx"

# Pause a subscription
curl -X POST https://api.pay.forhopp.com/api/v1/connect/subscriptions/sub_xxx/pause \
  -H "Authorization: Bearer sk_live_xxx"

# Resume a subscription
curl -X POST https://api.pay.forhopp.com/api/v1/connect/subscriptions/sub_xxx/resume \
  -H "Authorization: Bearer sk_live_xxx"

Subscription Add-Ons (Items)

Add extra line items to an existing subscription mid-cycle. ForhoppPay prorates charges automatically.

Add an Item

curl -X POST https://api.pay.forhopp.com/api/v1/connect/subscriptions/sub_xxx/items \
  -H "Authorization: Bearer sk_live_xxx" \
  -H "Content-Type: application/json" \
  -d '{"priceId": "price_addon_xxx", "quantity": 2, "prorationBehavior": "defer_to_next_cycle"}'

Update Quantity

curl -X PATCH https://api.pay.forhopp.com/api/v1/connect/subscriptions/sub_xxx/items/si_item_xxx \
  -H "Authorization: Bearer sk_live_xxx" \
  -H "Content-Type: application/json" \
  -d '{"quantity": 5}'

Remove an Item

curl -X DELETE "https://api.pay.forhopp.com/api/v1/connect/subscriptions/sub_xxx/items/si_item_xxx?immediate=false" \
  -H "Authorization: Bearer sk_live_xxx"

Proration Behaviors

Behavior Description
defer_to_next_cycle Proration added to next invoice (default)
charge_immediately Charge proration invoice now
none No proration, starts next cycle

Invoices

Invoices are generated automatically each billing cycle.

# List all invoices
curl https://api.pay.forhopp.com/api/v1/connect/invoices \
  -H "Authorization: Bearer sk_live_xxx"

# Get specific invoice
curl https://api.pay.forhopp.com/api/v1/connect/invoices/si_xxx \
  -H "Authorization: Bearer sk_live_xxx"

Balance & Earnings

Check your available balance at any time:

curl https://api.pay.forhopp.com/api/v1/connect/balance \
  -H "Authorization: Bearer sk_live_xxx"

Response:

{
  "object": "balance",
  "available": {"amount_cents": 19120, "currency": "USD"},
  "pending": {"amount_cents": 20000, "currency": "USD"},
  "fees_cents": 880,
  "refunds_cents": 0,
  "disputed_cents": 0,
  "minimum_payout_cents": 2500,
  "payout_eligible": true,
  "last_payout_at": 1750000000,
  "livemode": true
}

Payouts happen automatically on your configured schedule (daily/weekly/monthly) once balance exceeds $25.


Complete API Endpoint Reference

Authentication & Keys

Method Endpoint Description
POST /api/v1/connect/keys Create API key pair
GET /api/v1/connect/keys List API keys
DELETE /api/v1/connect/keys/{id} Revoke API key

Charges

Method Endpoint Description
POST /api/v1/connect/charges Create charge
GET /api/v1/connect/charges List charges
GET /api/v1/connect/charges/{id} Retrieve charge
POST /api/v1/connect/charges/{id}/capture Capture charge
POST /api/v1/connect/charges/{id}/refunds Refund charge

Webhooks

Method Endpoint Description
POST /api/v1/connect/webhooks Create webhook
GET /api/v1/connect/webhooks List webhooks
DELETE /api/v1/connect/webhooks/{id} Delete webhook

Plans & Prices

Method Endpoint Description
POST /api/v1/connect/plans Create plan
GET /api/v1/connect/plans List plans
GET /api/v1/connect/plans/{planId} Retrieve plan
POST /api/v1/connect/plans/{planId}/prices Create price

Customers

Method Endpoint Description
POST /api/v1/connect/customers Create customer
GET /api/v1/connect/customers List customers
GET /api/v1/connect/customers/{id} Retrieve customer
PATCH /api/v1/connect/customers/{id} Update customer

Subscriptions

Method Endpoint Description
POST /api/v1/connect/subscriptions Create subscription
GET /api/v1/connect/subscriptions List subscriptions
GET /api/v1/connect/subscriptions/{subId} Retrieve subscription
PATCH /api/v1/connect/subscriptions/{subId} Update (change price)
POST /api/v1/connect/subscriptions/{subId}/cancel Cancel
POST /api/v1/connect/subscriptions/{subId}/pause Pause
POST /api/v1/connect/subscriptions/{subId}/resume Resume

Subscription Items (Add-Ons)

Method Endpoint Description
POST /api/v1/connect/subscriptions/{subId}/items Add item
GET /api/v1/connect/subscriptions/{subId}/items List items
PATCH /api/v1/connect/subscriptions/{subId}/items/{itemId} Update quantity
DELETE /api/v1/connect/subscriptions/{subId}/items/{itemId} Remove item

Invoices

Method Endpoint Description
GET /api/v1/connect/invoices List invoices
GET /api/v1/connect/invoices/{invoiceId} Retrieve invoice

Balance

Method Endpoint Description
GET /api/v1/connect/balance Get merchant balance

Tax Rates

Method Endpoint Description
POST /api/v1/connect/tax-rates Create tax rate
GET /api/v1/connect/tax-rates List tax rates

Customer Portal

Method Endpoint Description
POST /api/v1/connect/portal-sessions Create portal session

Last Updated: July 2026

Was this page helpful?

Edit this page