DEV Community

Shahibur Rahman
Shahibur Rahman

Posted on

Automating Contract Signing and Payments in WordPress Using DocuSign + Stripe

If you want clients to sign a contract and pay right away inside your WordPress workflow, this setup shows exactly how to achieve a seamless WordPress DocuSign Stripe integration. This guide outlines how a custom plugin connects DocuSign for e-signatures and Stripe for payments. When the client signs, they're instantly redirected to a secure checkout page – no manual steps, no chasing invoices.

The integration is built around two core classes:

  • Plugin_DocuSign_Contract – e-signature engine
  • Plugin_Stripe_Processor – payment handler

Plugin Architecture Overview

The structure follows the WordPress Plugin Boilerplate for clear separation between admin, public, and core logic, essential for robust WordPress DocuSign Stripe integration.

my-wp-plugin/
├── my-wp-plugin.php
├── includes/
│ ├── class-main.php
│ ├── class-loader.php
│ ├── class-activator.php
│ └── class-deactivator.php
├── admin/
│ ├── class-admin.php
│ └── partials/
├── public/
│ └── class-public.php
├── assets/
│ ├── css/
│ ├── js/
│ └── images/
├── languages/
└── uninstall.php
Enter fullscreen mode Exit fullscreen mode

The DocuSign and Stripe integration lives inside includes/, handled by the two main classes.


How DocuSign → Stripe Works: The Automated Flow

This integration orchestrates a seamless hand-off between signing and payment. Here's a high-level overview of the process for automating contract signing and payments:

  • Plugin generates a DocuSign envelope: It prepares JWT authentication, builds the envelope with both client and admin signers, and temporarily stores relevant data (like envelope ID) in WordPress transients.
  • Client signs: The client uses an embedded signing experience via DocuSign's Recipient View, completing the signature process within DocuSign's UI.
  • DocuSign redirects back: Upon completion, DocuSign redirects the client back to a specified WordPress URL, passing crucial parameters.
  • Plugin retrieves stored data: Your plugin retrieves the previously stored envelope data from transients.
  • Plugin creates a Stripe Checkout Session: It dynamically generates a real-time product and price for the service, returning a unique Checkout URL.
  • Client completes payment: The client is redirected to the secure Stripe Checkout page to finalize the payment.
  • Plugin verifies payment: After successful payment, the plugin verifies the transaction status and triggers any necessary post-payment actions (e.g., updating contract status, sending confirmations).

Stripe Integration (Payment Engine)

This section details the Stripe integration for handling payments within your WordPress plugin.

1. Initialization

public function __construct($plugin_slug) {
    $this->plugin_slug = $plugin_slug;
    $this->load_stripe_library();
    $this->initialize_stripe();
}
Enter fullscreen mode Exit fullscreen mode

This method loads the Stripe PHP SDK and sets keys based on test/live mode.

2. Loading the Stripe Library

private function load_stripe_library() {
    $stripe_lib_path = MY_PLUGIN_PATH . 'vendor/stripe/stripe-php/init.php';
    if (file_exists($stripe_lib_path)) {
        require_once $stripe_lib_path;
    }
}
Enter fullscreen mode Exit fullscreen mode

3. Initializing Stripe Mode

private function initialize_stripe() {
    $this->stripe_mode = get_option('stripe_mode', 'test');
    $this->stripe_secret_key = $this->stripe_mode === 'live'
        ? get_option('stripe_live_secret_key')
        : get_option('stripe_test_secret_key');
    \Stripe\Stripe::setApiKey($this->stripe_secret_key);
}
Enter fullscreen mode Exit fullscreen mode

4. Creating a Checkout Session

$session = \Stripe\Checkout\Session::create([
    'payment_method_types' => ['card'],
    'line_items' => [[
        'price_data' => [
            'currency' => $currency,
            'product_data' => ['name' => "Service Agreement - $company_name"],
            'unit_amount' => $amount_cents,
        ],
        'quantity' => 1,
    ]],
    'mode' => 'payment',
    'success_url' => home_url('/payment-success/'),
    'cancel_url' => home_url('/payment-cancelled/')
]);
Enter fullscreen mode Exit fullscreen mode

The client is then redirected to $session->url.


DocuSign Integration (Contract Engine)

This part handles authentication, envelope creation, embedded signing, and the crucial redirect to Stripe for the full WordPress DocuSign Stripe integration.

1. Required DocuSign Credentials

Here's a list of the constants and their descriptions you'll need for DocuSign integration:

  • DOCUSIGN_INTEGRATION_KEY: Your app's Client ID.
  • DOCUSIGN_USER_ID: The API user's GUID.
  • DOCUSIGN_ACCOUNT_ID: Your DocuSign account ID.
  • DOCUSIGN_AUTH_SERVER: The OAuth URL (e.g., account-d.docusign.com for demo, account.docusign.com for live).
  • DOCUSIGN_API_BASE_PATH: The API base URL (e.g., https://demo.docusign.net/restapi for demo).
  • DOCUSIGN_PRIVATE_KEY: The RSA private key generated for your app.
  • DOCUSIGN_IMPERSONATED_USER_GUID: Typically the same as DOCUSIGN_USER_ID.

2. Getting Your Credentials

To obtain these, you'll need to:

  • Create a DocuSign developer account (if you don't have one).
  • Add an app in your developer account settings and generate an Integration Key (Client ID).
  • Create an RSA keypair for JWT authentication.
  • Copy your User ID and Account ID from your account settings.
  • Add your plugin's redirect URL to your DocuSign app settings.

3. Authenticating Using JWT

The plugin creates a signed JSON Web Token (JWT) and exchanges it for an access token with DocuSign:

grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer
assertion=<signed-jwt>
Enter fullscreen mode Exit fullscreen mode

DocuSign then returns a bearer token, which is used for all subsequent API calls.

4. Creating and Sending the Envelope

The plugin dynamically builds a PDF envelope with both client and admin signers, then sends it via the DocuSign API:

POST /accounts/{ACCOUNT_ID}/envelopes
Enter fullscreen mode Exit fullscreen mode

This API call returns an envelopeId, which is essential for tracking and managing the signing process.

5. Generating the Signing URL

For embedded signing, where the client signs within your WordPress workflow (or an iframe), you'll generate a recipient view URL:

POST /envelopes/{envelopeId}/views/recipient
Enter fullscreen mode Exit fullscreen mode

DocuSign responds with a unique signing URL that you can open directly in a new window or embed.

6. Handling Completion → Starting Payment

Once the client completes signing, DocuSign redirects them back to your specified WordPress URL, typically including the envelopeId in the query parameters.

At this point, the plugin:

  • Retrieves any stored data associated with the envelopeId.
  • Calls the create_checkout_session() method from the Stripe integration.
  • Redirects the client directly to the Stripe Checkout page.

This ensures the client sees the payment page instantly after signing, making for a seamless transition.

7. Verifying Payment

After the client completes the payment on Stripe, you can verify its status using the Stripe API:

$session = \Stripe\Checkout\Session::retrieve($session_id);
if ($session->payment_status === 'paid') {
    // Update contract status, send confirmation emails, grant access, etc.
}
Enter fullscreen mode Exit fullscreen mode

End-to-End Flow Recap

Let's quickly summarize the entire automated process for WordPress contract automation:

  • Admin sends contract: An action within WordPress triggers the DocuSign envelope generation.
  • Plugin authenticates via JWT: Securely connects to DocuSign.
  • DocuSign sends envelope: The client receives the contract.
  • Client signs: Electronically signs the document within an embedded view.
  • Redirects to WordPress: DocuSign hands control back to your plugin.
  • Stripe Checkout starts: The client is immediately taken to the payment page.
  • Payment verified: Upon successful payment, your system updates records and triggers post-payment actions.

This entire sequence is fully automated from start to finish.


Why This Matters

Implementing this WordPress DocuSign Stripe integration offers significant advantages:

  • Smooth client experience: Clients can sign and pay in one continuous, guided flow, reducing friction.
  • Secure handling of signatures + payments: Leverage the robust security of DocuSign and Stripe.
  • Clear tracking: All contract and payment data is linked, providing a transparent audit trail.
  • Ideal for various use cases: Perfect for agencies onboarding new clients, freelancers securing projects, or SaaS businesses automating service agreement sign-ups.

Pro Tips

When building out your integration, keep these best practices in mind:

  • Use DocuSign Sandbox (demo.docusign.net): Always test in the demo environment before going live.
  • Use Stripe Test Mode (pk_test, sk_test): Similarly, use Stripe's test keys to avoid real charges during development.
  • Sanitize all input: Protect your application from malicious data.
  • Store envelope data in transients: WordPress transients are excellent for temporary storage of envelopeId and other session-specific data.
  • Swap demo URLs with production URLs when going live: Ensure all API endpoints and redirect URLs point to the correct production environments.

Source Code

GitHub logo d5b94396feba3 / wp-docusign-stripe

WordPress DocuSign & Stripe Integration Plugin

WordPress DocuSign & Stripe Integration Plugin

A WordPress plugin that seamlessly integrates DocuSign electronic signatures with Stripe payment processing. This plugin automates the contract signing and payment workflow, allowing clients to sign agreements via DocuSign and immediately proceed to secure payment processing through Stripe.

Built With

This plugin is built using the WP Plugin Boilerplate - a modern, object-oriented WordPress plugin boilerplate following WordPress coding standards. The boilerplate provides a clean, maintainable structure with separation of concerns, proper security measures, and WordPress best practices.

Stripe SDK

This plugin uses the official Stripe PHP SDK for payment processing. The Stripe SDK is loaded via Composer and provides secure, reliable access to Stripe's payment processing APIs. The SDK handles all Stripe API communications, including:

  • Product and Price creation
  • Checkout Session management
  • Payment verification
  • Error handling and API response parsing

Overview

This plugin provides a complete solution for businesses that need to:

  • Send…




GitHub logo d5b94396feba3 / WP-Plugin-Boilerplate

A modern, object-oriented WordPress plugin boilerplate following WordPress coding standards. Features a generic structure where you only need to change ONE FILE to create a completely new plugin.

WP Plugin Boilerplate

A modern, object-oriented WordPress plugin boilerplate following WordPress coding standards. Features a generic structure where you only need to change ONE FILE to create a completely new plugin.

🚀 Features

One-File Setup (True Dynamic Naming): Change only the main plugin file's header to rename the plugin, slug, version, menu items, and file handles across the entire codebase.

Object-Oriented Architecture: Clean, maintainable code structure.

WordPress Standards: Follows WordPress coding standards and best practices.

Security Ready: Built-in security measures and data sanitization.

Internationalization: Ready for translations with proper text domains.

Admin & Public Separation: Organized separation of backend and frontend functionality.

Hook Management: Centralized WordPress hook system.

Asset Management: Proper CSS/JS enqueuing for admin and public.

📁 Plugin Structure

my-wp-plugin/
├── 📄 my-wp-plugin.php                 # Main plugin file (ONLY FILE TO EDIT HEADER)
├── 📄 index.php
├── 📁 includes/                        # Core

Final Thoughts

Combining DocuSign with Stripe inside your own custom WordPress plugin creates a fast, automated pipeline for contracts and payments. Clients can sign and pay in minutes, and everything stays under your control – no external SaaS required. This powerful WordPress DocuSign Stripe integration empowers you to streamline your business operations and provide a top-tier experience for your clients.

What are your thoughts on automating contract and payment workflows? Share your experiences or questions in the comments below! If you found this guide helpful, consider following me for more technical content.

Top comments (0)