Collapse Menu
Documentation
FastSpring App
Contact Support

Browser Scripts

Overview

Overview of Browser Scripts and how to add one to your Store

Browser scripts (previously called "browser webhooks") are custom-defined JavaScript functions that run inside the browser window. For Web Storefronts, browser scripts will be executed inside the sandbox. For Popup Storefronts, browser scripts will be executed inside the sandbox and passed to the container page via the callback defined using the JavaScript API. For Popup Storefronts, you can leave function () empty if you only want the event to be passed to the container page and not run inside the sandbox.

Function

A browser script is defined as a JavaScript function similar to this:

  • function(event) {      
      /* Custom Code Here */
    }

Load External Scripts

It is common to require external scripts within the hook. To load external scripts, use the following approach within the function:

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

Add a Browser Script

  1. Click Add Browser Script. The Add Browser Script popup dialog appears.
  2. In the Name field, optionally enter an internal name for the script to help you identify it if you create more than one.
  3. In the Events section, select browser.order.completed.
  4. In the Function text area, enter or paste your JavaScript code.
  5. Click Add.

Example:

BROWSER.ORDER.COMPLETED - fired upon successful order completion after fulfillment actions were performed.

 
  • {  
       "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
    }