<?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: Omar Elgendy</title>
    <description>The latest articles on DEV Community by Omar Elgendy (@omarelgendy).</description>
    <link>https://dev.to/omarelgendy</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%2F4276790%2F2ec323f2-bd32-4791-9d8d-057bc08e9bd2.png</url>
      <title>DEV Community: Omar Elgendy</title>
      <link>https://dev.to/omarelgendy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/omarelgendy"/>
    <language>en</language>
    <item>
      <title>A timeout is not a failed payout: how to never send the same transfer twice</title>
      <dc:creator>Omar Elgendy</dc:creator>
      <pubDate>Tue, 01 Dec 2026 15:45:17 +0000</pubDate>
      <link>https://dev.to/omarelgendy/a-timeout-is-not-a-failed-payout-how-to-never-send-the-same-transfer-twice-2hg</link>
      <guid>https://dev.to/omarelgendy/a-timeout-is-not-a-failed-payout-how-to-never-send-the-same-transfer-twice-2hg</guid>
      <description>&lt;p&gt;The worst bug in a financial system is boring: the same transfer runs twice.&lt;/p&gt;

&lt;p&gt;It usually happens in one of two ways.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The payment API times out. Your app reads that as "failed" and retries. But the money had already moved.&lt;/li&gt;
&lt;li&gt;The same request is sent twice. A double click, a job retry, two workers picking up the same task.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I work on wallet and bank transfers in Egypt, and this is the part I trust least in any payout code. So I wrote a small open-source PHP package around it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 1: a timeout is "unknown", not "failed"
&lt;/h2&gt;

&lt;p&gt;If the API answers with a clear refusal, nothing was sent, and you can fix the input and try again. If it times out or returns a 5xx, you do not know. The package returns different states: successful, failed, and unknown (pending is separate). Unknown means: do not send again, check the status first.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$request&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;DisbursementRequest&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;vodafone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'01001234567'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;250.00&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Save $request-&amp;gt;clientReferenceId() in your database BEFORE sending.&lt;/span&gt;
&lt;span class="nv"&gt;$result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$paymob&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;disburse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$request&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="nv"&gt;$result&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;isSuccessful&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="c1"&gt;// money sent&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;elseif&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$result&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;isFailed&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="c1"&gt;// refused, nothing sent, safe to fix and retry&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// pending or unknown: DO NOT send again&lt;/span&gt;
    &lt;span class="nv"&gt;$later&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$paymob&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;transactionStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nv"&gt;$result&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;transactionId&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="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;clientReferenceId&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;Every request carries a unique client reference, so you can always look the payout up by your own id, not only the provider's.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 2: write before you call
&lt;/h2&gt;

&lt;p&gt;If the server dies in the middle of a payout, you need to know a payout was attempted. In the Laravel add-on, a record is written before the provider is called. A reconcile command then goes through the unknown ones and asks the provider what actually happened.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 3: the same reference is never paid twice
&lt;/h2&gt;

&lt;p&gt;In the Laravel layer, a second payout for the same reference is refused while the first one is successful, pending, unknown or in progress. This is what covers the double click and the two workers.&lt;/p&gt;

&lt;p&gt;To be clear about scope: this protection lives in the Laravel add-on. The plain PHP client does not have a database, so it cannot do this check for you. There, you save the reference before sending and check status before any retry.&lt;/p&gt;

&lt;h2&gt;
  
  
  Small things that matter
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Access tokens expire after 60 minutes. They are cached and renewed, including on a 401.&lt;/li&gt;
&lt;li&gt;Phone, card and national id numbers are masked in logs.&lt;/li&gt;
&lt;li&gt;Phone numbers are normalised, so +20 100 123 4567 and 01001234567 end up the same.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What it is
&lt;/h2&gt;

&lt;p&gt;It is built on Paymob's Payouts API (unofficial, not endorsed by Paymob) and sends to Egyptian mobile wallets, bank accounts, bank cards and Egypt Post. PHP 7.4 to 8.3, any framework, with an optional Laravel add-on. MIT license.&lt;/p&gt;

&lt;p&gt;GitHub: &lt;a href="https://github.com/omarRaafat/package-paymob-payouts" rel="noopener noreferrer"&gt;https://github.com/omarRaafat/package-paymob-payouts&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Install: &lt;code&gt;composer require omarraafat/paymob-payouts&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The project is early. If you have worked on payment gateways or fintech: what do you do when a payout times out? I would like to hear how you handle it.&lt;/p&gt;

</description>
      <category>php</category>
      <category>laravel</category>
      <category>fintech</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
