Referral Rocket
HomeDashboard
  • What is Referral Rocket?
  • Referral Program Examples
  • Getting Started
    • Campaigns
      • Campaign Types
      • Campaigns Details
        • Milestone Details
        • Reward Details
        • Referrer Widget
        • Invitee Widget
      • Installing/Tracking your Referral Campaign
        • Option 1: Hosted Solution (No/Low Code)
        • Option 2: Custom Solution
          • Simple Referral Program Redirect: Quick Setup Guide
          • Redirect user to hosted campaign
          • Embed Referral Rocket Widget
          • Integrate the referral program inside your webapp for logged in user
        • Referral Tracking
          • Track referral on Sign Up page
          • Track referral on Payments
      • Reward Management
      • Campaign Participants
      • Campaign Dashboards
  • Developer Tooks
    • Javascript SDK
    • REST API
      • API Endpoint
    • Webhooks
      • Setup
      • Testing
      • Events
  • Integrations
    • Stripe
      • How to setup Stripe?
        • Stripe Settings
      • Referral Tracking with Stripe
        • Promo Code Referral Tracking with Stripe
        • Setup Stripe Pricing Table
        • Setup Stripe Payment Links
        • Setup Stripe Payment Button
        • Stripe Checkout Sessions
    • Cashfree
    • Razorpay
    • MemberSpace
    • Outseta
    • Shopify
      • How to setup Shopify?
      • Add Referral Widget on Shopify Stor
      • Popup Script to Display Discount Codes
    • ScoreApp
  • Rewards
    • Tremendous
      • How to integrate Tremendous?
        • Tremendous Settings
      • How to issue rewards with Tremendous?
    • PayPal Mass Payments
    • Wise Batch Payments
    • Stripe
    • Shopify
    • RazorPayX
    • Paypal
  • Affiliate Hub
    • Affiliate Program Hub
  • Product Updates
    • December 2024
  • Trust Center
  • Contact Us
  • FAQ
    • Where to find Campaign ID?
    • Understanding the Test Plan: Perfect for Testing, Limited for Production
Powered by GitBook
On this page
  • Local Development and Testing
  • Security: Signature Verification
  1. Developer Tooks
  2. Webhooks

Testing

PreviousSetupNextEvents

Last updated 3 months ago

Local Development and Testing

For local development, you can use Ngrok to create a secure tunnel to your local environment:

  1. Download Ngrok from the official website for your operating system

  2. Extract and navigate to the Ngrok directory in your terminal

  3. Run the command: ./ngrok http PORT_NUMBER

    • Replace PORT_NUMBER with your local server port (e.g., 8080 for default Spring Boot applications)

  4. Copy the generated Ngrok URL to use as your webhook endpoint

Security: Signature Verification

Every webhook request includes an X-RR-Signature header to verify authenticity. This signature is generated using the endpoint's secret key and the payload.

Verification Process

  1. The signature is provided as a hexadecimal string in the X-RR-Signature header

  2. Generate your own signature using the received payload and your secret key

  3. Compare the generated signature with the received signature

  4. If they match, the payload is verified as coming from Rocket Referral

Implementation Examples

Java Implementation

javaCopyimport javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.HexFormat;

public String signedPayload(String message, String key) 
    throws NoSuchAlgorithmException, InvalidKeyException {
    Mac hmacSHA256 = Mac.getInstance("HmacSHA256");
    SecretKeySpec secretKeySpec = new SecretKeySpec(
        key.getBytes(StandardCharsets.UTF_8),
        "HmacSHA256"
    );
    hmacSHA256.init(secretKeySpec);
    return HexFormat.of().formatHex(
        hmacSHA256.doFinal(message.getBytes(StandardCharsets.UTF_8))
    );
}

JavaScript Implementation

javascriptCopyconst crypto = require('crypto');

function signed_payload(clientKey, msg) {
    const key = new Buffer(clientKey, 'hex');
    return crypto.createHmac('sha256', key)
        .update(msg)
        .digest('hex');
}