Search

Index

Revindex Storefront

How to email external license key

Last updated on 2021-06-16 1 mins. to read

If you sell software or any product that needs to generate a license key or serial number from an external system, you can use the Place order action rule to retrieve external resources. Please see Actions for more information.

The following example shows how to create a Place order action rule that calls an external URL to retrieve the generated license key and send it to the customer by email.

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
  <xsl:template match="/">
    <!--  Craft our URL to retrieve the license key passing any query parameter  -->
    <xsl:variable name="url" select="concat('http://a.com/gen.asp?o=', /in/salesOrder/salesOrderNumber)"/>
    <!--  Expect license key in plain text. Use document() function to return complex XML instead.  -->
    <xsl:variable name="key" select="unparsed-text($url)"/>
    <out>
      <!--  Send email to customer with their license key  -->
      <sendMail>
        <mailFrom>support@company.com</mailFrom>
        <mailTo>
          <xsl:value-of select="/in/user/email"/>
        </mailTo>
        <subject>Your license key</subject>
        <htmlBody>
          <h1>
            <xsl:value-of select="$key"/>
          </h1>
        </htmlBody>
      </sendMail>
    </out>
  </xsl:template>
</xsl:transform>

Comments


Powered by Revindex Wiki