DocsQuickstart

Quickstart

Accept your first crypto payment in under 5 minutes. This guide will walk you through the essential steps.

1

Create an Account

Sign up for a PayHub account to get your API keys. Start with the sandbox environment to test your integration.

2

Install the SDK

Install the official PayHub SDK for your platform. We support JavaScript/TypeScript out of the box.

Terminal
npm install @payhub/sdk
3

Create a Payment

Use the SDK to create a payment. The customer will receive a unique address to send their crypto payment.

create-payment.ts
import { PayHubClient } from '@payhub/sdk';

// Initialize the client
const client = new PayHubClient({
  apiKey: 'your-api-key',
  environment: 'sandbox', // Use 'production' for live payments
});

// Create a payment
const payment = await client.payments.create({
  amount: '10.00',
  currency: 'USDC',
  network: 'polygon',
  description: 'Order #12345',
  metadata: {
    orderId: '12345',
    customerEmail: 'customer@example.com',
  },
});

console.log('Payment created:', payment.id);
console.log('Pay to address:', payment.address);
console.log('Checkout URL:', payment.checkoutUrl);

Using cURL?

You can also use the REST API directly:

Terminal
curl -X POST https://api.payhub.work/v1/payments \
  -H "Authorization: Bearer your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": "10.00",
    "currency": "USDC",
    "network": "polygon",
    "description": "Order #12345"
  }'
4

Handle Webhooks

Set up a webhook endpoint to receive real-time notifications when payments are confirmed.

webhook-handler.ts
import { PayHubClient } from '@payhub/sdk';

const client = new PayHubClient({ apiKey: 'your-api-key' });

// Verify webhook signature
const isValid = client.webhooks.verifySignature({
  payload: req.body,
  signature: req.headers['x-payhub-signature'],
  secret: 'your-webhook-secret',
});

if (isValid) {
  const event = req.body;

  switch (event.type) {
    case 'payment.confirmed':
      // Payment confirmed - fulfill the order
      console.log('Payment confirmed:', event.data.id);
      break;
    case 'payment.completed':
      // Payment fully completed
      console.log('Payment completed:', event.data.id);
      break;
  }
}

Webhook Events

Key events you should handle:

  • payment.detected - Payment transaction detected on-chain
  • payment.confirmed - Payment has enough confirmations
  • payment.completed - Payment fully processed

You're Ready!

That's it! You're now ready to accept crypto payments. Test your integration in sandbox mode, then switch to production when you're ready to go live.