How to Generate a Unique Payment URL with Stripe

How to Generate a Unique Payment URL with Stripe

There are two main ways to generate a unique payment URL with Stripe: using the Dashboard (no-code) or using the API (programmatic approach). I’ll explain both methods.

Method 1: Using Stripe Dashboard (No-Code)

  1. Log into your Stripe Dashboard at dashboard.stripe.com

  2. Navigate to Payment Links:

    • Click on “Products” in the left sidebar
    • Select “Payment links”
    • Click the “Create payment link” button
  3. Configure your payment link:

    • Add products: Click “Add product” and either select an existing product or create a new one
    • Set pricing: Enter the price for each product
    • Configure settings: Adjust shipping, tax rates, promotional codes, etc.
    • Customize branding: Add your logo and customize colors (optional)
    • Set checkout options: Configure receipt emails, redirect URLs, etc.
  4. Create and share your link:

    • Click “Create link” to generate your unique payment URL
    • Copy the URL from the next screen
    • Share with customers via email, text, social media, etc.

Method 2: Using Stripe API (Programmatic)

const stripe = require('stripe')('sk_test_your_secret_key');

async function createPaymentLink() {
  try {
    const paymentLink = await stripe.paymentLinks.create({
      line_items: [
        {
          price_data: {
            currency: 'usd',
            product_data: {
              name: 'Your Product',
              description: 'Description of your product or service'
            },
            unit_amount: 2000, // Amount in cents (e.g., $20.00)
          },
          quantity: 1,
        },
      ],
      // Optional: Configure what happens after payment
      after_completion: {
        type: 'redirect',
        redirect: {
          url: 'https://yourwebsite.com/thank-you',
        },
      },
    });
    
    console.log('Payment link created:', paymentLink.url);
    return paymentLink;
  } catch (error) {
    console.error('Error creating payment link:', error);
    throw error;
  }
}

// Call the function
createPaymentLink();

Additional Configuration Options

  • Expiration: Set an expiration date for your payment link
  • One-time use: Make links single-use only
  • Custom fields: Collect additional information from customers
  • Shipping address collection: Enable/disable shipping address collection
  • Custom amounts: Allow customers to pay what they want (donations)

Testing Your Payment Link

Before sharing with customers, test your payment link using Stripe’s test mode with these test card numbers:

  • Success: 4242 4242 4242 4242
  • Decline: 4000 0000 0000 0002

Remember to switch to “Live mode” when you’re ready to accept real payments.

Would you like me to explain any specific aspect of this process in more detail?