<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Gamingty</title>
    <description>The latest articles on DEV Community by Gamingty (@gamingty).</description>
    <link>https://dev.to/gamingty</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4284646%2F5ac794f5-c6d6-4840-bbd4-82d57be21c87.png</url>
      <title>DEV Community: Gamingty</title>
      <link>https://dev.to/gamingty</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gamingty"/>
    <language>en</language>
    <item>
      <title>How Digital Gift Card Delivery Works: A Developer's Guide</title>
      <dc:creator>Gamingty</dc:creator>
      <pubDate>Sat, 05 Dec 2026 12:08:29 +0000</pubDate>
      <link>https://dev.to/gamingty/how-digital-gift-card-delivery-works-a-developers-guide-1cp0</link>
      <guid>https://dev.to/gamingty/how-digital-gift-card-delivery-works-a-developers-guide-1cp0</guid>
      <description>&lt;p&gt;Ever wondered what happens between clicking "Pay" and receiving a digital gift card code in your inbox? From the outside it looks instant and simple. Behind the scenes, it is a chain of steps where one small mistake can mean a lost sale, a double delivery, or a leaked code.&lt;/p&gt;

&lt;p&gt;In this guide, I'll walk through the typical flow and the practical lessons developers should keep in mind when building it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The basic flow
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Order placed:&lt;/strong&gt; The customer picks a product and starts checkout.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Payment confirmed:&lt;/strong&gt; The payment gateway sends a confirmation, usually through a webhook.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code allocated:&lt;/strong&gt; The store reserves a code from its stock or requests one from a supplier.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Delivery:&lt;/strong&gt; The code is emailed or shown in the customer's account.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Redemption:&lt;/strong&gt; The customer enters the code on the platform, such as Steam, PlayStation, or Roblox.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  1. Confirm payment on the server, not in the browser
&lt;/h2&gt;

&lt;p&gt;A common beginner mistake is delivering the code when the customer lands on the "success" page. That page can be reached, refreshed, or faked. Only release a code after your server receives a verified confirmation from the payment gateway.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Verify and deduplicate webhooks
&lt;/h2&gt;

&lt;p&gt;Gateways can retry a webhook or send the same event more than once. If your code handles each call as a new payment, one order could deliver two codes.&lt;/p&gt;

&lt;p&gt;Here is a simplified example (Node.js style pseudocode):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/webhook"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// 1. Verify the signature using your gateway's official library&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;verifyWebhookSignature&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// 2. Skip events we have already processed&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;alreadyDone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;processedEvents&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;alreadyDone&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sendStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// 3. Allocate and deliver inside one transaction&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;codes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;allocate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;orderId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;markPaid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;orderId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;processedEvents&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;queueEmail&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;orderId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sendStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The key ideas are signature verification, a stored event ID, and a transaction so that allocation and order status never get out of sync.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Protect codes at rest
&lt;/h2&gt;

&lt;p&gt;Gift card codes are as good as cash. Treat them that way:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Store them encrypted.&lt;/li&gt;
&lt;li&gt;Never write full codes to logs or error trackers.&lt;/li&gt;
&lt;li&gt;Limit which parts of your system and which staff can view them.&lt;/li&gt;
&lt;li&gt;Mask codes in admin screens where possible.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4. Handle stock and failures gracefully
&lt;/h2&gt;

&lt;p&gt;What if the supplier is slow, or stock runs out right after payment? Plan for it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reserve a code at checkout and release it if payment fails or times out.&lt;/li&gt;
&lt;li&gt;Retry delivery safely without creating duplicates.&lt;/li&gt;
&lt;li&gt;Show the order status clearly in the customer's account.&lt;/li&gt;
&lt;li&gt;Give customers an order ID so support can find their purchase quickly.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5. Add basic fraud checks
&lt;/h2&gt;

&lt;p&gt;Digital goods are a common target for fraud because delivery is instant. Simple checks go a long way:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Watch for many orders from one IP or device in a short time.&lt;/li&gt;
&lt;li&gt;Flag mismatched billing and location data for review.&lt;/li&gt;
&lt;li&gt;Rate limit order and login endpoints.&lt;/li&gt;
&lt;li&gt;Review unusual high-value orders before delivery.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  6. Be clear with customers
&lt;/h2&gt;

&lt;p&gt;Good communication reduces support tickets and builds trust:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Show clear delivery and refund policies before payment.&lt;/li&gt;
&lt;li&gt;Explain how to redeem the code on the official platform.&lt;/li&gt;
&lt;li&gt;Remind buyers never to share their codes.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Quick checklist
&lt;/h2&gt;

&lt;p&gt;Payment verified server-side&lt;br&gt;
Webhook signature checked&lt;br&gt;
Duplicate events ignored&lt;br&gt;
Allocation and order update in one transaction&lt;br&gt;
Codes encrypted and kept out of logs&lt;br&gt;
Retry and failure handling in place&lt;br&gt;
Basic fraud checks and rate limits enabled&lt;/p&gt;

&lt;h2&gt;
  
  
  Final thoughts
&lt;/h2&gt;

&lt;p&gt;Digital delivery feels effortless to the customer, but it relies on careful payment handling, secure storage, and solid error handling. Get these basics right and you will avoid most of the painful bugs.&lt;/p&gt;

&lt;p&gt;What's the trickiest part of e-commerce development you've faced? Share it in the comments!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I work on a digital gift card store, &lt;a href="https://gamingty.com/" rel="noopener noreferrer"&gt;Gamingty&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>programming</category>
      <category>python</category>
      <category>career</category>
    </item>
  </channel>
</rss>
