DocumentationPaymentsPayment Buttons

Payment Buttons

Create customizable cryptocurrency payment buttons for your website or application.

Last updated: June 22, 2023Next: Checkout Links

Overview

ZenPay Payment Buttons are the simplest way to start accepting cryptocurrency payments on your website. With a simple copy-paste integration, you can add a customizable payment button that handles the entire payment flow, from cryptocurrency selection to payment confirmation.

Easy Integration

Simple to add to any website with just a few lines of code.

  • No backend code required
  • Works with any website platform
  • No complex API integration needed

Customizable Design

Tailor the button to match your brand and website design.

  • Custom colors and text
  • Multiple size options
  • Light and dark mode support

Flexible Pricing

Support various pricing models for your products or services.

  • Fixed price payments
  • Customer-defined amounts
  • Multi-currency support

Advanced Options

Additional features for more complex use cases.

  • Redirect URLs after payment
  • Webhook notifications
  • Custom metadata for tracking

Creating a Payment Button

Follow these steps to create and implement a payment button on your website:

1

Create a New Button

From your ZenPay dashboard, navigate to Payments → Payment Buttons → Create New Button.

2

Configure Basic Settings

Enter the basic information for your payment button:

  • Button name (for your reference)
  • Product or service name (displayed to customers)
  • Description (optional)
  • Price and currency
  • Success and cancel URLs (where to redirect after payment)
3

Customize Appearance

Personalize your button to match your website's design:

  • Button text
  • Primary color
  • Button size (small, medium, large)
  • Button style (filled, outlined, text-only)
  • Icons (optional)
4

Payment Options

Select which cryptocurrencies you want to accept. You can choose specific ones or accept all supported cryptocurrencies.

5

Get Your Button Code

After saving, you'll receive HTML code for your button. Copy this code to use on your website.

Example Payment Button Code
<script src="https://js.zenpay.io/v1/button.js"></script>
<div class="zenpay-button" 
  data-button-id="btn_1234567890"
  data-price="25.00"
  data-currency="USD"
  data-name="Premium Subscription"
  data-color="#4F46E5"
  data-size="medium"
  data-style="filled"
  data-text="Pay with Crypto">
</div>

Customization Options

ZenPay payment buttons can be customized using data attributes. Here's a comprehensive list of available customization options:

Core Attributes

AttributeDescriptionExample
data-button-idYour button ID from the dashboardbtn_1234567890
data-pricePayment amount25.00
data-currencyCurrency codeUSD
data-nameProduct/service namePremium Subscription

Appearance Options

AttributeDescriptionExample
data-textButton textPay with Crypto
data-colorPrimary color (hex)#4F46E5
data-sizeButton sizesmall, medium, large
data-styleButton stylefilled, outlined, text
data-themeButton themelight, dark, auto

Advanced Options

AttributeDescriptionExample
data-success-urlURL to redirect after successful paymenthttps://yourdomain.com/thank-you
data-cancel-urlURL to redirect after cancelled paymenthttps://yourdomain.com/checkout
data-customer-emailPre-filled customer emailuser@example.com
data-metadataCustom JSON metadata"order_id":"12345"

Dynamic Payment Buttons

For more dynamic use cases, you can create payment buttons programmatically using JavaScript:

Dynamic Payment Button Example
<script src="https://js.zenpay.io/v1/button.js"></script>
<div id="payment-container"></div>

<script>
  // Get product details from your page
  const product = {
    name: "Premium Plan",
    price: 49.99,
    currency: "USD"
  };
  
  // Create a payment button dynamically
  document.addEventListener('DOMContentLoaded', () => {
    const container = document.getElementById('payment-container');
    
    // Create button element
    const button = document.createElement('div');
    button.className = "zenpay-button";
    
    // Set attributes based on product
    button.setAttribute('data-button-id', 'btn_1234567890');
    button.setAttribute('data-name', product.name);
    button.setAttribute('data-price', product.price);
    button.setAttribute('data-currency', product.currency);
    button.setAttribute('data-color', '#4F46E5');
    button.setAttribute('data-text', 'Pay with Crypto');
    
    // Add to container
    container.appendChild(button);
    
    // Initialize button
    if (typeof ZenPay !== 'undefined') {
      ZenPay.buttons.initialize();
    }
  });
</script>

Handling Button Events

You can listen for payment events to trigger custom actions on your website:

Button Event Handling
<script src="https://js.zenpay.io/v1/button.js"></script>
<div class="zenpay-button" 
  data-button-id="btn_1234567890"
  data-price="25.00"
  data-currency="USD"
  data-name="Premium Subscription">
</div>

<script>
  document.addEventListener('DOMContentLoaded', () => {
    // Listen for payment initialization
    window.addEventListener('zenpay:payment-initiated', (event) => {
      console.log('Payment started', event.detail);
      // You could show a loading indicator, disable forms, etc.
    });
    
    // Listen for successful payments
    window.addEventListener('zenpay:payment-success', (event) => {
      console.log('Payment successful', event.detail);
      
      // Get payment details
      const { paymentId, amount, currency } = event.detail;
      
      // Show success message or redirect
      alert(`Thank you for your payment of ${amount} ${currency}!`);
      
      // Optional: Redirect to a thank you page
      // window.location.href = '/thank-you?payment_id=' + paymentId;
    });
    
    // Listen for payment cancellations
    window.addEventListener('zenpay:payment-cancel', (event) => {
      console.log('Payment cancelled', event.detail);
      // Handle cancellation
    });
    
    // Listen for payment errors
    window.addEventListener('zenpay:payment-error', (event) => {
      console.error('Payment error', event.detail);
      // Show error message
    });
  });
</script>

Best Practices

Follow these tips to optimize your payment button implementation:

Implementation Tips

1

Place buttons prominently

Make sure payment buttons are easy to find and clearly visible on your page.

2

Use clear button text

Make the purpose of the button obvious with text like "Pay Now" or "Subscribe with Crypto".

3

Set up webhooks

For critical payments, always implement webhooks to ensure your systems get notified about successful payments even if users close their browser.

4

Test thoroughly

Always test your payment buttons in test mode before going live with real payments.

Next Steps

After implementing payment buttons, explore these related features:

Checkout Links

Create shareable payment links for your customers

Webhooks

Set up webhooks to get real-time payment notifications