Browser Scripts

Run custom-defined JavaScript functions inside the browser window.

Browser scripts are custom-defined JavaScript functions that are located inside of your browser window. You can use the following example to load an external script within the associated function.

this.load('https://scripturl';, callback);  //"callback" is a function() to execute after the script has been successfully loaded.

Add a Browser Script

  1. Navigate to Developer Tools > Webhooks. On the webhook event, click Add Browser Script. A popup appears.
  2. In the Name field, enter an internal name for the script.
  3. In the Events section, select browser.order.completed.
  4. In the Function text area, enter or paste your JavaScript code.
  5. Click Add.

❗️

When using webhooks, you can execute browser scripts within the sandbox. However, if you are using a Popup Storefront, FastSpring will pass it to the container page using an API Callback function. To only pass the event to the container page, leave the function () empty.

Example

The example below fires browser.order.completed after FastSpring processes a transaction and sends the fulfillment.

{  
   "id":"ZxcLBaJaR2i7N2DYAo7PbQ",                    // hook id - do not use
   "created":1475702220909,                          // created timestamp, in milliseconds
   "type":"browser.order.completed",                 // type of event
   "live":false,                                     // true if not a test order
   "data":{                                          // order data
      "id":"8nEf7SIgR4SjUUspka4oWQ",                 // FastSpring-internal order ID to be used for all order-related requests
      "reference":"KYR161005-9065-20156",            // customer-facing order ID
      "live":false,                                  // true if not a test order
      "currency":"USD",
      "total":15,                                    // order total
      "totalDisplay":"USD 15.00",                    // order total, formatted for display
      "totalInPayoutCurrency":"15",                  // order total in payout currency
      "totalInPayoutCurrencyDisplay":"USD 15.00",    // order total in payout currency, formatted for display
      "tax":0,
      "taxDisplay":"USD 0.00",
      "taxInPayoutCurrency":"0"
      "taxInPayoutCurrencyDisplay":"USD 0.00",
      "subtotal":15,
      "subtotalDisplay":"USD 15.00",
      "subtotalInPayoutCurrency":"15",
      "subtotalInPayoutCurrencyDisplay":"USD 15.00",
      "discount":0,
      "discountDisplay":"USD 0.00",
      "discountInPayoutCurrency":0,
      "discountInPayoutCurrencyDisplay":"USD 0.00",
      "discountWithTax":0,
      "discountWithTaxDisplay":"USD 0.00",
      "discountWithTaxInPayoutCurrency":0,
      "discountWithTaxInPayoutCurrencyDisplay":"USD 0.00",
      "payoutCurrency":"USD",
      "payment":{  
         "type":"test",
         "cardEnding":"4242"
      },
      "total":15,
      "totalDisplay":"USD 15.00",
      "totalInPayoutCurrency":15,
      "totalInPayoutCurrencyDisplay":"USD 15.00",
      "account":"FwlUjl4DSkOnZY8OqORkTw",
      "tags": {
        "key1":"value1"                              // custom order-level tags defined via Store Builder Library or Custom Orders
      },
      "items":[                                      // array of items in the order
         {  
            "product":"subRegular",
            "quantity":1,
            "subtotal":10,
            "subtotalDisplay":"USD 10.00",
            "subtotalInPayoutCurrency":"10",
            "subtotalinPayoutCurrencyDisplay":"USD 10.00",
            "coupon":null,
            "sku":null,
            "discount":0,
            "discountDisplay":"USD 0.00",
            "discountInPayoutCurrency":0,
            "discountInPayoutCurrencyDisplay":"USD 0.00",
            "subscription":"bZ3zfvNgRiycCGNNDao2Cw",
            "fulfillments":{  
            }
         },
         {  
            "product":"jason-s-test-product",
            "quantity":1,
            "subtotal":5,
            "subtotalDisplay":"USD 5.00",
            "subtotalInPayoutCurrency":5,
            "subtotalInPayoutCurrencyDisplay":"USD 5.00",
            "coupon":null,
            "sku":null,
            "discount":0,
            "discountDisplay":"USD 0.00",
            "discountInPayoutCurrency":0,
            "discountInPayoutCurrencyDisplay":"USD 0.00",
            "fulfillments":{  
               "jason-s-test-product_license_0":[  
                  {  
                     "license":"asdf",
                     "display":"License Key",
                     "type":"license"
                  }
               ],
               "instructions":"<p><br/> License Key: asdf<br/></p>"
            }
         }
      ]
   },
   "hook":"5e1d04bb4f8110f1e35008ab37ebfc7b557eca795cc0fd974b4aaef4a73241c6",
   "digest":null                                     // digest checksum
}