This project is a demonstration sandbox for the Finix API, designed to simulate the Finix Sandbox Certification Steps. It provides a user interface to trigger various API events and view mock responses, helping developers understand and test the integration process.
- Simulate creating identities and authorizing payments.
- Mock successful and failed transaction scenarios.
- Demonstrate the passing of Fraud Session IDs and Idempotency IDs.
- Includes a mock tokenization form.
- Simulates dispute and refund flows.
- Open
index.htmlin your web browser. - Use the buttons and controls to simulate different API calls.
- Observe the mock API responses in the output area.
This sandbox now simulates the official three-step process for processing a payment via the Finix API.
The first step is to create an Identity to represent your buyer. This resource stores the buyer's personal data and is used to manage their payment methods and transactions. While all fields are optional, providing basic information is recommended.
API Request: POST /identities
{
"entity": {
"first_name": "John",
"last_name": "Doe",
"email": "john.doe@example.com"
},
"tags": {
"customer_id": "cust_123"
}
}Next, you create a Payment Instrument which represents the buyer's payment method (e.g., a credit card). This is done using a secure token obtained from one of Finix's client-side tokenization solutions. The Payment Instrument must be associated with the buyer's Identity from Step 1.
API Request: POST /payment_instruments
{
"identity": "IDxxxxxxxxxxxxxxxxxx",
"token": "TKNxxxxxxxxxxxxxxxxxx",
"type": "TOKEN",
"tags": {
"source": "web_checkout"
}
}Finally, you create a Transfer to charge the buyer. The Transfer uses the Payment Instrument ID as its source and requires a merchant ID to process the transaction. This is also where you would include a fraud_session_id and an idempotency_id.
API Request: POST /transfers
{
"source": "PIxxxxxxxxxxxxxxxxxx",
"merchant": "MUxxxxxxxxxxxxxxxxxxxxxxx",
"amount": 10000,
"currency": "USD",
"fraud_session_id": "FSxxxxxxxxxxxxxxxxxx",
"idempotency_id": "idem_xxxxxxxxxxxxxxxxx"
}The included demo project is a full-stack Next.js application that shows a more complete integration. To run it:
-
Navigate to the demo directory:
cd demo -
Install dependencies:
npm install
-
Run the development server:
npm run dev
The application will be available at
http://localhost:3000.
In the demo project, Google Pay and Apple Pay are integrated by loading their respective JavaScript SDKs globally in official-finix-example-project/src/app/layout.tsx. This makes the google and ApplePaySession objects available throughout the client-side application without explicit imports in individual components.
- Google Pay: The Google Pay JavaScript SDK is loaded via
<Script src="https://pay.google.com/gp/p/js/pay.js" strategy="afterInteractive" />. This script exposes the globalgoogle.payments.apiobject. - Apple Pay: The Apple Pay JS SDK is loaded via
<Script src="https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js" strategy="afterInteractive" />. This script exposes the globalApplePaySessionobject.
TypeScript recognizes these global objects through ambient type declarations, which are typically provided by @types packages or included within the libraries themselves.
You do not need a VM or VPN to test webhooks. A tool like ngrok can expose your local server to the internet.
-
Install ngrok: Follow the instructions on the ngrok website.
-
Start your local server: Run
npm run devin thedemodirectory. It will run on a port, typically3000. -
Start ngrok: Open a new terminal window and run the following command to create a tunnel to your local server's port:
ngrok http 3000
-
Get your public URL: ngrok will give you a public "Forwarding" URL that looks something like
https://<random-string>.ngrok.io. -
Configure the webhook in Finix: In your Finix Dashboard, go to the webhooks section and create a new webhook endpoint. Paste the public URL from ngrok into the URL field. Now, when events happen in your Finix sandbox account, they will be sent to your local application.
If you use Tailscale, you can use its "Funnel" feature as an alternative to ngrok.
-
Install and configure Tailscale: Make sure Tailscale is installed and running on your machine.
-
Start your local server: Run
npm run devin thedemodirectory to start the application on port3000. -
Enable the Funnel: Open a terminal and run the following command:
tailscale funnel 3000
-
Get your public URL: Tailscale will provide a public URL for your machine (e.g.,
https://your-machine-name.ts.net). This is the URL you can use in the Finix Dashboard for your webhook endpoint. The advantage is that this URL is stable and tied to your machine's name.
A common point of confusion is whether a separate server is needed for webhooks. The answer is no. Your existing web server (the one running the Next.js demo) can handle webhook requests.
The flow works like this:
- An event occurs in Finix (e.g., a payout is completed).
- Finix's server sends an HTTP POST request to the public URL you provided.
ngrokorTailscale Funnelreceives this request and securely forwards it to your local machine on the port you specified (e.g.,localhost:3000).- Your Next.js application receives the request at the specified path (e.g.,
/api/webhooks). You would create a new API route file atdemo/src/app/api/webhooks/route.tsto handle this logic. - Your code in that file then processes the event, for example, by updating a database or sending a notification.
Here is a simple diagram illustrating the process:
+-----------------+ 2. POST Request +-----------------+ 3. Forward Request +----------------------+
| |-------------------------->| ngrok / |---------------------------->| |
| Finix Servers | (to Public URL) | Tailscale Funnel| (to localhost:3000) | Your Next.js Server |
| | | | | (Handles API Routes) |
+-----------------+ +-----------------+ +----------------------+
^ |
| 1. Event Occurs | 4. Process Webhook
| (e.g., Payout SUCCEEDED) | (e.g., Update DB)
| v
+----------------------+
| Your Application\'s |
| Database |
+----------------------+
This repository also includes a new full-stack application in the frontend and backend directories that demonstrates a complete marketplace flow with merchant and buyer interactions.
-
Backend Setup:
cd backend npm install npm run devThe backend server will run on
http://localhost:3001. -
Frontend Setup:
cd frontend npm install npm run devThe frontend application will run on
http://localhost:3000.
The merchant section allows merchants to:
-
Create Items/Payment Links: Merchants should create items (products) with payment links in the merchant section. Each item represents a product or service that can be purchased.
-
Manage Inventory: Merchants can view and manage their created items.
-
Track Sales: Monitor transactions and sales for their items.
The buyer section provides the following flow:
-
Browse Items: Buyers can browse all available items created by merchants.
-
Select Items: Buyers can select items they want to purchase. These are the payment links created by merchants in the merchant section.
-
Purchase Flow:
- When a buyer clicks the "Buy" button on an item:
- A new buyer
Identityis created in the Finix system - The buyer's payment information is collected
- A
Payment Instrumentis created and associated with the buyer - A
Transferis initiated to complete the purchase
- A new buyer
- When a buyer clicks the "Buy" button on an item:
-
Transaction Completion: After successful payment, the buyer receives confirmation and the merchant is notified of the sale.
The application uses:
- Frontend: Next.js with TypeScript
- Backend: Node.js with Express
- Payment Processing: Finix API
- Real-time Updates: WebSockets for live transaction status
Make sure to set up your .env file with:
FINIX_USERNAME=your_username
FINIX_PASSWORD=your_password
FINIX_MERCHANT_ID=your_merchant_id