I’m integrating FastSpring with my WordPress plugin, and I’m using a webhook like this: https://example.com/wp-json/v1/webhook
Whenever a payment is completed in FastSpring, a webhook is triggered — for example, to example.com/wp-json/v1/webhook. This webhook can be called from anywhere, and I can use the data as needed.
Is there any way to insert custom data into this webhook — like siteURL or userID?
For instance, in the plugin code provided, can I somehow get the URL of the site where the plugin is installed, or the current user’s ID, from within the webhook handler?
<?php
/**
* Plugin Name: Order Info
* Description: Handle FastSpring payment.
* Version: 1.0
* Author: test
*/
if (!defined('ABSPATH')) exit;
/**
* Admin Menu Page
*/
add_action('admin_menu', function () {
add_menu_page(
'Payment Manager',
'Payment',
'manage_options',
'employee-payment-manager',
'employee_payment_manager_page',
'dashicons-admin-users',
6
);
});
/**
* Admin Page Callback
*/
function employee_payment_manager_page() {
ob_start();
?>
<script
id="fsc-api"
src="https://d1f8f9xcsvx3ha.cloudfront.net/sbl/0.9.0/fastspring-builder.min.js"
type="text/javascript"
data-popup-webhook-received="dataPopupWebhookReceived"
data-storefront="bwdplugins.test.onfastspring.com/popup-bwdplugins">
</script>
<div class="wrap">
<h1>Payment Manager</h1>
<p>
<button onclick="addVariationAndCheckout('pcm-monthly')" class="wpcv-price-btn">
Pay Monthly per User
</button>
</p>
</div>
<script>
function dataPopupWebhookReceived(data) {
console.log("Webhook received:", data);
}
function addVariationAndCheckout(variation) {
fastspring.builder.reset();
switch (variation) {
case 'pcm-monthly':
fastspring.builder.add('pcm-monthly');
break;
default:
break;
}
fastspring.builder.checkout();
}
</script>
<?php
echo ob_get_clean();
}
