less than a minute read • Updated 2 hours ago
Offer one-click upsells on the receipt
How to show post-purchase upsell offers on the receipt page that customers can buy with one click, without logging in or re-entering their card.
After a customer completes checkout, you can show upsell offers on the receipt page and let them buy an offer without logging in or typing their card again. The receipt adds the offer to the cart and sends the customer back to checkout already signed in through single sign-on (SSO), with the card they just used. From there you can either let the customer confirm the payment, or submit the checkout automatically so the purchase takes a single click.
Each upsell is a new transaction. The original order has already been charged by the time the receipt shows, so an upsell can't be added to it. If an upsell is a subscription product, it becomes its own subscription, separate from any subscription in the original order. To add products to the same order before payment instead, see Add an upsell modal to the checkout.
Before you start
SSO is turned on for checkout. In the Foxy admin, go to Settings > Checkout and turn on Enable SSO, then enter your SSO endpoint. This needs an SSO secret or a universal store secret. See Set up single sign-on for checkout.
Customers check out with an account. Guest customers can't be signed in through SSO, so the upsell only shows to customers who created an account during checkout.
The customer's card is saved to their account during the first checkout, so it's available on the upsell checkout.
You're using a custom receipt template, since the upsell code goes into it. The token logic is the same as in Set up outgoing single sign-on on the receipt.
Steps
Add the upsell offer to the receipt
Add a button and script like this to your receipt template, one per offer. Clicking the button adds the product to the cart, then sends the customer to checkout with a fresh SSO token.
{% if first_receipt_display and not is_anonymous %}
{% set timestamp = checkout_timestamp + 120 %}
<button type="button" id="upsell-weekly-report">Add weekly reports for $250/month</button>
<script>
document.getElementById('upsell-weekly-report').addEventListener('click', function () {
FC.client.request('https://' + FC.settings.storedomain + '/cart?name=Weekly+report&price=250&code=upsell-weekly-report&sub_frequency=1m&empty=reset').done(function () {
window.location.href = 'https://' + FC.settings.storedomain + '/checkout?fc_auth_token={{ generate_sso_token(timestamp) }}×tamp={{ timestamp }}&fc_customer_id={{ customer_id }}';
});
});
</script>
{% endif %}Give every upsell product a code that starts with the same prefix (upsell- in this example). The automatic submit in the next section uses it to recognize an upsell checkout. empty=reset starts a fresh cart, so the upsell checkout only holds the upsell product. checkout_timestamp + 120 makes the token valid for two minutes after the original checkout.
Option 1: let the customer confirm the payment
No more setup is needed. The customer lands on checkout already signed in, with their saved card selected, and clicks to pay.
By default the checkout asks for the card security code even on a saved card. To change that, go to Settings > Payments and set Require CSC/CVC/CVV for to the option you want.
Option 2: submit the checkout automatically
To complete the upsell with no further clicks, have the checkout submit itself when the cart holds only upsell products.
<script>
FC.client.on('ready.done', function () {
var flag = 'fc_upsell_autosubmitted';
if (FC.json.context == 'receipt') {
try { sessionStorage.removeItem(flag); } catch (e) {}
return;
}
if (FC.json.context != 'checkout' || !FC.json.items.length) return;
var onlyUpsells = FC.json.items.every(function (item) {
return String(item.code).indexOf('upsell-') === 0;
});
var alreadyTried = false;
try { alreadyTried = sessionStorage.getItem(flag) === '1'; } catch (e) {}
if (onlyUpsells && !alreadyTried) {
try { sessionStorage.setItem(flag, '1'); } catch (e) {}
$('[data-fc-id="checkout-form"]').trigger('submit.fc');
}
});
</script>This runs the checkout's normal submit, including its validation. If the payment is declined or a required field is missing, the checkout shows the error as usual and the customer can finish by hand. The sessionStorage flag makes sure the checkout only tries to submit once per upsell, so a declined card doesn't retry by itself.
Notes
The SSO token in the receipt is generated on the first view of the receipt only, and expires two minutes after checkout in this example. Keep the expiry short, no more than a few minutes. If the customer clicks after it expires, Foxy sends them through your SSO endpoint first.
Once SSO is on, every checkout goes through your SSO endpoint first, including first-time customers who aren't logged in to your site. Your endpoint has to handle them too.
The Custom footer loads on the cart, checkout, and receipt, which is why the script checks
FC.json.contextand the product codes before submitting. Make sure the condition can't match a regular checkout.Changing Require CSC/CVC/CVV for applies to every checkout on your store, not just upsells.
If your store requires signed (HMAC) add-to-cart links, sign the upsell cart parameters as well.
If the upsell products need shipping, the customer may have to choose a shipping rate, which stops the automatic submit. This approach works best for digital products and subscriptions.
Test the whole flow on a test gateway before going live, including a declined card.