logoSellhub
Sellhub API
Sellhub API
Payment Plugins

This guide about payment plugins allows you to handle incoming webhooks from various payment gateway providers.

Handle Webhook

POST
Handle an incoming webhook from a payment provider.

POST https://dash.sellhub.cx/api/paymentPlugins

Request Parameters

  • pluginName: string - The name of the payment plugin
  • storeId: string - The ID of the store

Request Body

The request body should contain the raw webhook payload as received from the payment provider.

Example request:

POST https://dash.sellhub.cx/api/paymentPlugins?pluginName=stripe&storeId=store_123
Content-Type: application/json

{
  "type": "checkout.session.completed",
  "data": {
    "object": {
      "client_reference_id": "85732252-bfa2-45ea-a87d-3e15781d0c29"
    }
  }
}

Lua Environment

When working with this API in Lua, the following features and functions are available:

  1. HTTP Requests: Use the fetch function for making HTTP requests.
  2. JSON Parsing: The dkjson library is built into the Lua environment.
  3. HMAC Signing: Use the hmacShaSign function for creating HMAC signatures.
  4. Logging: Use the insertLog function to log messages.

Available Lua Functions

-- HMAC Signing
hmacShaSign(secretKey: string, dataToSign: string, hash: string)
 
-- Logging
insertLog(description: string, type: string)
-- 'type' can be one of: 'info', 'error', 'warning'

Response

Your Lua should process the webhook and return a response based on the payment plugin's handling of transaction. The response should include:

Required Response

The Invoice ID is required only if the status is pushInvoice or disputeInvoice.

{
  "status": "pushInvoice" | "disputeInvoice" | "ignore",
  "invoiceId": "string"
}
  • status: Indicates the action to be taken based on the webhook
  • invoiceId: The ID of the invoice (if applicable)

Based on the status, the API will perform one of the following actions:

  • pushInvoice: Complete the invoice
  • disputeInvoice: Mark the invoice as disputed
  • ignore: No action taken

The webhook will return the response along with the appropriate HTTP status code.

Testing Your Plugin

Before going live, thoroughly test your plugin:

  • Simulate webhooks to ensure webhook processes them correctly.
  • Test the checkout process to verify payments work as expected.
  • Confirm that invoices are updated correctly based on your plugin's responses.

Security Considerations

  • Securely store API keys and secrets for your payment provider.
  • Validate all incoming data in your Lua functions.
  • Implement proper error handling and logging.

On this page