Use URL parameters to populate transaction information in your customer's order session.
Parameters are values that the SBL passes as part of the customer-facing URL. Add a JavaScript code to parse the URL and apply parameter values to SBL functions. Then, you can pass the following transaction data in the URL:
- Products
- Customer's first name
- Customer's last name
- Coupon code
For example, you can add similar code following the tag at the bottom of your page. Use URL parameters to add information to an existing cart session. If you specify the product in the URL, include the product path instead of the display name.
<script>
var params = new URLSearchParams(document.location.search);
var product = params.get("product");
var email = params.get("email");
var fname = params.get("fname");
var lname = params.get("lname");
var coupon = params.get("coupon");
var fscNext = params.get("fscNext"); //parameter is used when returning from a "wallet" provider like PayPal.
var s = {};
fastspring.builder.reset();
if (product) {
s = {
products: [
{
path: product,
quantity: 1,
},
],
};
if (email) {
s.paymentContact = {};
s.paymentContact.email = email;
if (fname && lname) {
s.paymentContact.firstName = fname;
s.paymentContact.lastName = lname;
}
}
if (coupon) {
s.coupon = coupon;
}
if (fscNext) {
//if fscNext exists, then buyer is returning from a "wallet" provider like PayPal, push() and checkout() should not be called.
console.log("Returning from a 'wallet' checkout like PayPal");
} else {
fastspring.builder.push(s);
fastspring.builder.checkout();
}
} else {
console.log("At least one product is required to start a checkout");
}
</script>
Example URLs
The following URLs format order-specific information following cart.html?. You can pass multiple pieces of information within one URL.
Pass the Product:
Following cart.html? pass product= and insert the product path or ID.
.../cart.html?product=8675309
Pass the Coupon Code:
Following cart.html? pass the ID or path of the product to which the coupon applies. Then, pass &coupon=' and insert the coupon code. FastSpring will apply the associated discount to the specified product.
.../cart.html?product=8675309&coupon=FALLSALE
Pass Customer Information:
To pass customer information, include the first name, last name, and email address following cart.html. The information will not pass if one of these fields is missing.
- fname= Add the first name.
- &lname= Add the last name.
- &email= Add the email address.
.../cart.html?fname=Leeroy&lname=Jenkins&[email protected]
Pass All Information
The following example includes the product, coupon, and customer information from the examples above.
.../cart.html?product=8675309&coupon=FALLSALE&fname=Leeroy&lname=Jenkins&[email protected]