Call: (727) 333 - 2552
Product List  

Stripe PHP Webhook Code for payment_intent.succeeded

Introducing the Ultimate Solution for Seamless Payment Integration

Simplify your e-commerce journey with our game-changing Stripe PHP Webhook Code designed specifically for payment_intent.succeeded events. Whether you're a PHP novice or exploring the intricacies of the Stripe API, this comprehensive code snippet is your passport to saving precious time on research, development, and testing. Our innovative webhook seamlessly processes data from Stripe's payment_intent.succeeded event, effortlessly logs essential product details through the Stripe PHP API, and then goes the extra mile by automating the delivery of purchased digital products directly to your customers via email attachments.

Use promo code 5OFF to save 5% site-wide on checkout. Expires Tu, Apr 30, 2024, 11:59EST

Note: Don't miss our related products – Email Blacklist Prevention - Automate .zip & .exe File Downloads and Power Duo: Stripe Webhook & Automated Digital Delivery.

Why Choose Our Stripe PHP Webhook?

  • Streamlined Automation: Never struggle with manual processes again. Our webhook automates the entire product delivery process, allowing you to focus on what truly matters – growing your business.
  • Effortless Data Retrieval: Leverage the power of the Stripe PHP API to effortlessly retrieve and store product data, ensuring you have all the information you need at your fingertips.
  • Comprehensive Logging: Keep track of purchase data and webhook execution progress effortlessly. Our webhook ensures that you're always in the loop and can troubleshoot with ease.
  • Top-Notch Tech Support: Say goodbye to generic support lines. We offer USA-based technical support via both phone and email, ensuring your questions are answered promptly and comprehensively.
  • Cost-Effective Solution: Bid farewell to pricey subscription-based third-party webhook services. Our webhook empowers you to take control and host the functionality on your existing web server without draining your budget.

Experience hassle-free implementation:

  • Dependencies Made Easy: Integrate the Stripe PHP library effortlessly via Composer. Running $ composer require stripe/stripe-php on your Linux web server is all it takes.
  • Secure Key Handling: Safely manage your Stripe Secret API Key using the PHP dotenv library. Our code demonstrates how to load this key from an external .env file for enhanced security.
  • Guided Integration: We've taken the guesswork out of implementation. Our provided code snippet uses Composer's autoload to ensure seamless binding of the Stripe PHP and phpdotenv libraries.
  • Personalized Product Delivery: Tailor the delivery process by setting up metadata for each product via the Stripe Dashboard. Our webhook's sendMail() function ensures your customers receive their purchased products as email attachments.

Revolutionize the way you handle payments and product deliveries with our Stripe PHP Webhook Code. Say goodbye to complexity and hello to efficiency. Ready to supercharge your e-commerce game? Get started now!

Get ahead in the world of seamless payments with our Stripe PHP Webhook – your gateway to innovation and efficiency. Try it today!

Benefits of Our Stripe PHP Webhook

  • Automate the Delivery of Products via Email Attachments
  • Save $$$ on Expensive Subscription Third-Party Webhook Services
  • Get Tech Support that is USA-based ( Call or Email Us!)
  • Lookup Product Data via the Stripe PHP API:
    • Retrieves customer_details from the current stripe session data object such as:
      • customer email
      • customer name
    • Retrieves the line_items collection from the current stripe session data object and processes purchase data such as:
      • id (line_item)
      • quantity
      • description
      • price object
        • id (product)
        • unit_amount
  • Log Webhook Execution Progress and Purchase Data:
    Sample Stripe Webhook Log File Name: log_26-Sep-2023.log

    26-Sep-2023 Stripe Log
    02:22:20pm - Starting execution.
    02:22:20pm - Response OK
    02:22:20pm - processing: payment_intent.succeeded event.
    02:22:25pm - Email: [email protected]
    02:22:25pm - Name: john doe
    02:22:25pm - Line Item Id: li_1Nuc8fA2CUhNBxyOeqZMYDSd
    02:22:25pm - Product Id: prod_N8dEoQ10mY8Bkk
    02:22:25pm - Qty: 1
    02:22:25pm - Desc: Maintenance Checklists in Excel
    02:22:25pm - Price: 149
    02:22:26pm - Product delivered automatically via Email or Link. Metadata product_email_filename: maint-checklists.zip
    02:22:26pm - Product delivered via Link
    02:22:26pm - Email accepted by server.
    02:22:26pm - Webhook completed OK

Implementation Guidelines for Our Stripe PHP Webhook

  1. The Stripe PHP library is required to provide access to the Stripe API. Installation of the Stripe PHP library is easy via Composer. For example, run $ composer require stripe/stripe-php to install on a Linux web server.
  2. Consider how you will store and access your Stripe Secret API Key. In our example, we make use of the PHP dotenv library to load the Stripe Secret API Key as an environment variable from a .env file that resides outside of our web server's public folder. Installation of PHP dotenv is easy via Composer. For example, run $ composer require vlucas/phpdotenv to install on a Linux web server.
    Note: Alternately, hard-coding the secret key directly in the PHP Webhook would be ok for the Test Mode Secret Key of the Stripe Secret API Key but significantly risky for the Live Mode Secret Key.
  3. For binding the Stripe PHP and phpdotenv libraries within our PHP Webhook, we use Composer's autoload: require_once 'vendor/autoload.php';
    Note: Alternately, the Stripe PHP library may be loaded without Composer but you must manually install the library and ensure that your web server has the required Stripe PHP library dependencies ( curl, json, and mbstring). phpinfo() may be used to check the status of extensions.
  4. Add a Metadata key, value pair via the Stripe Dashboard for each product you would like delivered via email. The key is "product_email_filename" and the value is the filename of the product you would like delivered via email upon checkout completion. In the case of this product it is "StripePHPWebhookCode.pdf". This Metadata will be used by the Stripe PHP Webhook's sendMail() function for attaching the product's file.
  5. Configure the Stripe PHP Webhook for your implementation.
    1. Set the Sender Information within the following code block of the sendMail() function:
      // Sender Information
      $from = ' [email protected] ';
      $fromName = ' Sender Name or Company Name ';
    2. Set the Webhook Log File Location and File Name Format within the logWebhookStatus() function. For security, we place the log file outside of the web server's public folder. See the following code block:
      // Webhook log file location and naming convention
      $log_file_dir = $_SERVER["DOCUMENT_ROOT"] . " /../stripe-logs ";
      $log_file_name = $log_file_dir . " /log_ " . date("d-M-Y") . ".log";
    3. Ensure the loading of the required dependencies: Stripe PHP Library and PHP dotenv. For security, we installed the libraries outside of the web server's public folder. See the following code block:
      // Load the dependencies installed via Composer (Stripe PHP Library and PHP dotenv)
      require " ../stripe-lib/vendor/autoload.php ";
    4. Store your Stripe API Secret Key in a .env file outside the web server's public folder. In this example, we store the key in custom.env located in a folder named secret within the parent folder of your public folder. The custom.env file should initially contain the following entry:
      SECRET_KEY=" sk_test_...... "
      Note: This key may be later set to the "sk_live_......" Live Secret Key after completion of testing.
    5. Ensure the path is correct for loading the Stripe API Secret Key within the following code block:
      // Load the Stripe API Secret Key into the environment variable SECRET_KEY via PHP dotenv from custom.env that is outside the web server's public folder
      $dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . " /../secret ", " custom.env ");
      $dotenv->load();
    6. Initialize the Stripe PHP Client with the API Secret Key stored as an environment variable. See the following code block:
      // Initialize the Stripe PHP Client with the API Secret Key stored as an environment variable
      $stripe = new \Stripe\StripeClient($_SERVER['SECRET_KEY']);
    7. Set the Stripe Webhook Signing Secret Key within the following code block:
      // Signing Secret Key for the Webhook
      $endpoint_secret = " whsec_...... ";
    8. Specify the path for products emailable as attachments. For security, we are using a folder outside of our web server's public folder. See the following code block:
      // Specify path to emailable products folder
      $path_emailable_products = $_SERVER["DOCUMENT_ROOT"] . " /../products-emailable/ ";
    9. Set the email signature for product deliveries within the following code block:
      // Construct the email signature
      $email_html_signature = ' <p>Best regards,<br />John Doe<br />Owner,<br />yourdomain.com<br />555-555-5555</p> ' ;
    10. Create your Stripe Webhook Endpoint for testing.
      1. Sign in to the Stripe Dashboard.
      2. Click Developers button.
      3. Switch the Test mode setting to the On Position (lit in orange).
      4. Click the Webhooks tab under the Developers pageframe.
      5. Click the Add endpoint button.
      6. Helpful sample code is displayed in the right-hand pane.
        Note, the Listen to Stripe events page also displays information and settings regarding testing on a local server which will not be covered in this guide.
      7. Enter the Endpoint URL which should point to the test version of your PHP Webhook hosted on your server.
        Example: https://www.yourdomcain.com/stripe-webhook-test.php
      8. Click the Select events button.
      9. Choose Payment Intent events.
      10. Mark the payment_intent.succeeded event.
      11. Click the Add events button.
      12. You should now have successfully created a Test Webhook Endpoint for the payment_intent.succeeded event.
    11. Please see Testing within the Stripe Docs for helpful information about Stripe Test mode and how to use test cards for the simulation of Stripe payments.
    12. Please Note: Within the Stripe Dashboard->Developers->Webhooks, you may click on a Hosted endpoint (webhook) and it will display a history of the associated events along with their status, date, time and data. The data is very useful for debugging. Most importantly, a Resend button is available which is extremely useful for testing and corrections.

 

Thank you for viewing our product. Please Contact Us with product questions or feedback.