<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ahmad Dzaki Afif on Medium]]></title>
        <description><![CDATA[Stories by Ahmad Dzaki Afif on Medium]]></description>
        <link>https://medium.com/@ahmaddzakiafif?source=rss-2079eafae088------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*eDnIzQPF1MiDOE6O.</url>
            <title>Stories by Ahmad Dzaki Afif on Medium</title>
            <link>https://medium.com/@ahmaddzakiafif?source=rss-2079eafae088------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 17:32:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ahmaddzakiafif/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Integrating Airwallex Hosted Payment Page with React Router 7: A Developer’s Journey]]></title>
            <link>https://medium.com/@ahmaddzakiafif/integrating-airwallex-hosted-payment-page-with-react-router-7-a-developers-journey-f0371c66da28?source=rss-2079eafae088------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0371c66da28</guid>
            <dc:creator><![CDATA[Ahmad Dzaki Afif]]></dc:creator>
            <pubDate>Wed, 24 Dec 2025 12:31:58 GMT</pubDate>
            <atom:updated>2025-12-24T12:31:58.878Z</atom:updated>
            <content:encoded><![CDATA[<p>Last week, I found myself staring at Airwallex’s documentation, trying to figure out how to integrate their hosted payment page into my React Router 7 application. The documentation was solid, but there was something missing — a complete example that tied everything together with modern React Router patterns.</p><p>So I did what any developer would do: I built it myself. And now I’m sharing what I learned.</p><h3>Why Airwallex?</h3><p>Before we jump into the code, let me explain why I choose Airwallex for this project. If you’re building a platform that handles international payments, you’ve probably felt the pain of dealing with multiple payment gateways, currency conversions, and compliance headaches. Airwallex simplifies all of that.</p><p>Their hosted payment page is particularly interesting because it handles the entire payment flow for you — PCI compliance, 3D Secure authentication, and a clean UI that doesn’t look like it crawled out of 2005. You redirect users to their page, they handle the payment, and they redirect back to your app. Simple.</p><h3>What We’re Building</h3><p>We’re going to create a payment flow that:</p><ul><li>Creates a payment intent on the server side</li><li>Redirects to Airwallex’s hosted payment page</li><li>Handles the return flow (both success and failure)</li><li>Shows appropriate feedback to the user</li></ul><p>The full code is available on <a href="https://github.com/dzakiafif/react-router-airwallex">GitHub</a>, so you can follow along or just grab what you need.</p><h3>Setting Up React Router 7</h3><p>First, React Router 7 is the latest iteration of React Router, and it comes with some nice improvements. If you’re starting fresh, here’s how to get going:</p><pre>npx create-react-router@latest my-app<br>cd my-app<br>npm install</pre><p>I’m using Bun as my package manager (because it’s blazingly fast), but npm or yarn work just as well.</p><h3>The Environment Variables Dance</h3><p>Every payment integration starts with API keys. Create a .env file in your root directory:</p><pre>AIRWALLEX_API_KEY=your_api_key_here<br>AIRWALLEX_CLIENT_ID=your_client_id_here</pre><p>Here’s a pro tip I learned the hard way: never, ever commit your real API keys to version control. I created a .env.example file in the repo with placeholder values. Your future self will thank you.</p><h3>Building the Payment Intent Endpoint</h3><p>The first real challenge was creating the payment intent. Airwallex requires you to authenticate and create an intent server-side. In React Router 7, we handle this through route actions.</p><p>Here’s the interesting part — I created a server-side action that handles the entire payment intent creation process:</p><pre>export async function action({ request }: Route.ActionArgs) {<br>  const formData = await request.formData();<br>  const amount = formData.get(&quot;amount&quot;);<br>  const currency = formData.get(&quot;currency&quot;);<br>  / Step 1: Authenticate with Airwallex<br>  const authResponse = await fetch(<br>    &quot;https://api-demo.airwallex.com/api/v1/authentication/login&quot;,<br>    {<br>      method: &quot;POST&quot;,<br>      headers: { &quot;Content-Type&quot;: &quot;application/json&quot; },<br>      body: JSON.stringify({<br>        client_id: process.env.AIRWALLEX_CLIENT_ID,<br>        api_key: process.env.AIRWALLEX_API_KEY,<br>      }),<br>    }<br>  );<br>  const { token } = await authResponse.json();<br>  // Step 2: Create payment intent<br>  const intentResponse = await fetch(<br>    &quot;https://api-demo.airwallex.com/api/v1/pa/payment_intents/create&quot;,<br>    {<br>      method: &quot;POST&quot;,<br>      headers: {<br>        &quot;Content-Type&quot;: &quot;application/json&quot;,<br>        Authorization: `Bearer ${token}`,<br>      },<br>      body: JSON.stringify({<br>        request_id: `req_${Date.now()}`,<br>        amount: parseFloat(amount as string),<br>        currency: currency,<br>        merchant_order_id: `order_${Date.now()}`,<br>        return_url: `${request.headers.get(&quot;origin&quot;)}/payment/callback`,<br>      }),<br>    }<br>  );<br>  const intent = await intentResponse.json();<br>  <br>  // Redirect to Airwallex hosted page<br>  return redirect(intent.url);<br>}</pre><p>What’s happening here? We’re making two API calls — one to authenticate and get a bearer token, then another to create the payment intent. The return_url is crucial because that&#39;s where Airwallex will send your users after they complete (or abandon) the payment.</p><h3>The Product Page</h3><p>I kept the product page simple. It’s just a form that submits to our action:</p><pre>export default function Product() {<br>  return (<br>    &lt;div className=&quot;container&quot;&gt;<br>      &lt;h1&gt;Premium Product&lt;/h1&gt;<br>      &lt;p className=&quot;price&quot;&gt;$99.99&lt;/p&gt;<br>      <br>      &lt;Form method=&quot;post&quot;&gt;<br>        &lt;input type=&quot;hidden&quot; name=&quot;amount&quot; value=&quot;99.99&quot; /&gt;<br>        &lt;input type=&quot;hidden&quot; name=&quot;currency&quot; value=&quot;USD&quot; /&gt;<br>        &lt;button type=&quot;submit&quot;&gt;<br>          Pay Now<br>        &lt;/button&gt;<br>      &lt;/Form&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>When users click “Pay Now,” React Router calls our action, which creates the payment intent and redirects them to Airwallex. No useState, no useEffect, no client-side API calls. Just clean, simple routing.</p><h3>Handling the Callback</h3><p>This is where it gets interesting. After the payment, Airwallex redirects users back to your app with query parameters that tell you what happened.</p><p>I created a callback route to handle this:</p><pre>export async function loader({ request }: Route.LoaderArgs) {<br>  const url = new URL(request.url);<br>  const status = url.searchParams.get(&quot;status&quot;);<br>  const paymentIntentId = url.searchParams.get(&quot;payment_intent_id&quot;);<br>  return {<br>    status,<br>    paymentIntentId,<br>  };<br>}<br>export default function PaymentCallback({ loaderData }: Route.ComponentProps) {<br>  const { status, paymentIntentId } = loaderData;<br>  if (status === &quot;SUCCESS&quot;) {<br>    return (<br>      &lt;div className=&quot;success&quot;&gt;<br>        &lt;h1&gt;Payment Successful!&lt;/h1&gt;<br>        &lt;p&gt;Payment ID: {paymentIntentId}&lt;/p&gt;<br>        &lt;Link to=&quot;/&quot;&gt;Return to Home&lt;/Link&gt;<br>      &lt;/div&gt;<br>    );<br>  }<br>  return (<br>    &lt;div className=&quot;error&quot;&gt;<br>      &lt;h1&gt;Payment Failed&lt;/h1&gt;<br>      &lt;p&gt;Something went wrong. Please try again.&lt;/p&gt;<br>      &lt;Link to=&quot;/&quot;&gt;Return to Home&lt;/Link&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>React Router’s loader pattern shines here. We parse the URL parameters on the server and pass them to the component. The component just focuses on rendering the appropriate UI.</p><h3>What I Learned</h3><p>Building this integration taught me a few things:</p><p><strong>Server-side actions are powerful.</strong> React Router 7’s action pattern made it easy to handle the payment intent creation without exposing API keys to the client.</p><p><strong>Keep the client simple.</strong> My components are mostly just presentation logic. All the heavy lifting happens server-side.</p><p><strong>The callback pattern works.</strong> Redirecting to an external payment page and handling the return flow is actually more straightforward than embedding payment forms. You don’t have to worry about PCI compliance or securing payment data.</p><h3>Running the Project</h3><p>If you want to try this yourself, clone the repo and:</p><p>bash</p><pre>git clone https://github.com/dzakiafif/react-router-airwallex<br>cd react-router-airwallex<br>cp .env.example .env<br># Add your Airwallex credentials to .env<br>bun install<br>bun run dev</pre><p>Visit http://localhost:5173 and you&#39;ll see the payment flow in action.</p><h3>Things to Improve</h3><p>This is a working example, but it’s not production-ready. Here are some things you’d want to add:</p><ul><li><strong>Error handling:</strong> Right now, failed API calls aren’t handled gracefully</li><li><strong>Webhooks:</strong> You should verify payment status via Airwallex webhooks, not just the redirect</li><li><strong>Database integration:</strong> Store payment intents and orders in a database</li><li><strong>Loading states:</strong> Add proper loading indicators during the redirect</li><li><strong>Testing:</strong> Write tests for the payment flow</li></ul><h3>Final Thoughts</h3><p>Integrating payment systems doesn’t have to be overwhelming. Airwallex’s hosted payment page handles the complex stuff, and React Router 7’s patterns make the integration clean and maintainable.</p><p>The key is keeping things simple. Let Airwallex handle the payment UI. Use server-side actions for API calls. Keep your components focused on rendering.</p><p>If you’re building a payment flow and this helped you, drop a comment below. And if you spot something I could improve in the implementation, I’m all ears — this is how we all get better.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0371c66da28" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>