Skip to main content

WhiskyPay Quickstart

This guide will help you quickly integrate WhiskyPay into your SaaS application to start accepting cryptocurrency payments on Solana.

Prerequisites

  • A React application (Next.js, Create React App, Vite, etc.)
  • Node.js 16+ installed
  • npm or yarn package manager
  • Solana wallet adapter installed in your application (recommended)

Step 1: Installation

Install the WhiskyPay SDK package:
npm install @whisky-peak/whisky-pay-sdk
# or
yarn add @whisky-peak/whisky-pay-sdk

Step 2: Register as a Merchant

Before you can accept payments, you need to register as a merchant:
  1. Visit pay.whiskypeak.com and sign up for an account
  2. Connect your Solana wallet (This will be your payment receiving address)
  3. Fill in your SaaS details (name, logo, callback URL)
  4. You will receive a saasId to use in your integration

Step 3: Create a Payment Page

Create a simple payment page in your application:
import React, { useState } from 'react';
import { createSession, PaymentModal } from '@whisky-peak/whisky-pay-sdk';

function CheckoutPage() {
  const [sessionId, setSessionId] = useState(null);
  const [loading, setLoading] = useState(false);
  
  const handleCheckout = async () => {
    setLoading(true);
    
    try {
      // Replace with your actual merchant ID from the dashboard
      const merchantId = 'your-saas-id-from-dashboard';
      
      // Create a payment session
      const session = await createSession(
        merchantId,
        'customer@example.com', // Customer's email
        'premium-plan'          // Plan identifier
      );
      
      if (session) {
        setSessionId(session);
      } else {
        alert('Failed to create payment session');
      }
    } catch (error) {
      console.error('Error creating session:', error);
      alert('An error occurred');
    } finally {
      setLoading(false);
    }
  };
  
  // When payment is complete, redirect to a thank you page
  const handlePaymentComplete = () => {
    window.location.href = '/thank-you';
  };
  
  return (
    <div>
      {!sessionId ? (
        <button 
          onClick={handleCheckout} 
          disabled={loading}
        >
          {loading ? 'Creating session...' : 'Pay with Crypto'}
        </button>
      ) : (
        <PaymentModal
          sessionId={sessionId}
          RPC_URL="https://api.mainnet-beta.solana.com"
          onRedirect={handlePaymentComplete}
        />
      )}
    </div>
  );
}

export default CheckoutPage;

Step 4: Handle Payment Notifications

When a payment is completed, WhiskyPay will:
  1. Call your webhook URL (specified in your merchant dashboard)
  2. Send email confirmations to both you and your customer
  3. Redirect the customer to your specified redirect URL
Create a webhook endpoint to receive payment notifications:
// Example webhook handler (Next.js API route)
export default async function handler(req, res) {
  if (req.method !== 'POST') {
    return res.status(405).end();
  }
  
  const { email, plan, price, status, timestamp } = req.body;
  
  // Validate the webhook signature (recommended)
  // Implementation depends on your server setup
  
  // Update your database to mark the subscription as active
  await activateUserSubscription(email, plan);
  
  // Return a 200 status to acknowledge receipt
  res.status(200).json({ success: true });
}

Step 5: Testing

To test your integration:
  1. Use a real Solana wallet with testnet or devnet SOL
  2. Set RPC_URL to a testnet or devnet endpoint during testing
  3. Verify webhook calls are received correctly
  4. Test the payment flow end to end

Next Steps