This project provides a centralized server to handle Twispay's Instant Payment Notifications (IPNs) and update Shopify orders based on payment status. This setup is ideal for clients using Shopify stores who want a secure, reliable solution for managing Twispay payment notifications without needing a dedicated server.
- Centralized IPN Handling: Handles IPNs from Twispay for multiple clients.
- Order Status Update: Automatically updates order status in Shopify based on payment status.
- Secure Credentials Storage: Manages each client’s Shopify API credentials securely.
- Easy Client Setup: Clients only need to configure Twispay to use this IPN server.
- Node.js (v14+ recommended)
- Express.js for routing IPN requests
- Shopify API credentials for each client
- Twispay Account with access to set IPN URL
-
Clone the Repository:
git clone https://github.com/your-repo/twispay-ipn-server.git cd twispay-ipn-server
-
Install Dependencies:
npm install
-
Configure Environment Variables:
-
Rename the
.env.example
file to.env
:cp .env.example .env
-
Open
.env
and configure the following variables:PORT=3000 TWISPAY_SECRET=your_twispay_secret_key TWISPAY_IPN_URL=https://yourdomain.com/ipn
-
Add Shopify API credentials for each client in the format:
SHOPIFY_API_KEY_client1=client1_shopify_api_key SHOPIFY_API_PASSWORD_client1=client1_shopify_api_password SHOPIFY_STORE_URL_client1=client1_shopify_store_url SHOPIFY_API_KEY_client2=client2_shopify_api_key SHOPIFY_API_PASSWORD_client2=client2_shopify_api_password SHOPIFY_STORE_URL_client2=client2_shopify_store_url
-
-
Start the Server:
npm start
- The server will run on the port specified in your
.env
file (default is3000
).
- The server will run on the port specified in your
-
Set IPN URL in Twispay:
- In each client's Twispay account, set the IPN URL to:
https://yourdomain.com/ipn
- In each client's Twispay account, set the IPN URL to:
-
IPN Receiving:
- When a payment is processed, Twispay sends an IPN to the configured IPN URL. The server validates the IPN, identifies the client based on the order ID, and verifies the IPN signature using
TWISPAY_SECRET
.
- When a payment is processed, Twispay sends an IPN to the configured IPN URL. The server validates the IPN, identifies the client based on the order ID, and verifies the IPN signature using
-
Order Status Update:
- Once the IPN is validated, the server retrieves the appropriate Shopify API credentials for the client and updates the order status in Shopify based on the payment outcome (e.g., "Paid", "Failed").
-
Add API Credentials:
- For each new client, add their Shopify API credentials to the
.env
file, using a unique identifier (e.g.,client3
):SHOPIFY_API_KEY_client3=client3_shopify_api_key SHOPIFY_API_PASSWORD_client3=client3_shopify_api_password SHOPIFY_STORE_URL_client3=client3_shopify_store_url
- For each new client, add their Shopify API credentials to the
-
Configure Twispay IPN:
- In the client’s Twispay account, set the IPN URL to:
https://yourdomain.com/ipn
- In the client’s Twispay account, set the IPN URL to:
-
Restart the Server:
- Restart the server to apply new credentials:
npm restart
- Restart the server to apply new credentials:
- IPN Verification Failure:
- Ensure
TWISPAY_SECRET
matches the Twispay secret key in your.env
file.
- Ensure
- Order Status Not Updating:
- Verify that each client’s Shopify API credentials are correctly set in
.env
. - Check server logs for any error messages.
- Verify that each client’s Shopify API credentials are correctly set in
- Store all API credentials securely and never expose them publicly.
- Use HTTPS for secure IPN communication.
- Regularly rotate Shopify API credentials and Twispay secret keys as a best practice.
This project is licensed under the MIT License. See LICENSE for more information.
- Renamed
redirect_example.js
toredirect_secure.js
and enhanced its logic. - Added a
styles/checkout.css
file for checkout styling.
- Added
config.js
for centralized configuration. - Updated
redirect_secure.js
to use modularized functions and the configuration file. - Improved
styles/checkout.css
with mobile responsiveness and success/error message styles. - Added a
sample_checkout.html
for testing and demonstration.