Setting Up the Payment Verification Endpoint
Thepayments.VerifyPaymentAPI() function from the KarmaGo package simplifies payment verification by returning a handler function that integrates seamlessly with the GoFiber framework. This endpoint is essential for validating payments after they are completed.
Prerequisites
Before setting up the verification endpoint, ensure:-
Environment Variables are Properly Configured
Set the
KARMAPAY_VERIFY_URLin your.envfile to the endpoint where you’ll handle payment verification. For example: -
GoFiber Installed
If GoFiber is not already installed in your project, add it using:
- KarmaPay PG Service is Running Ensure the KarmaPay PG Service is up and running with the correct environment variables.
Creating the Verification Endpoint
Thepayments.VerifyPaymentAPI() function provides a Fiber handler that validates the payment details. You just need to register it to your Fiber application.
Example Code
Here’s how you can set up the verification endpoint:How It Works
-
Route Handling
The route
/payments/verifylistens for POST requests. This should be the URL you set in theKARMAPAY_VERIFY_URLenvironment variable. -
Verification Logic
- The
payments.VerifyPaymentAPI()function handles the logic for validating the payment. - It ensures that the payment details match those stored temporarily in Redis (via the KarmaPay PG Service).
- The function also checks the payment status with the respective payment gateway.
- The
-
Environment Variable Linking
The
KARMAPAY_VERIFY_URLvariable connects your Go application to the KarmaPay service, ensuring the verification endpoint is properly registered.
Example .env File
Make sure your .env file includes the correct URL for verification:
Testing the Verification Endpoint
-
Simulate a Payment
Use the
CreatePaymentOrderfunction to generate a payment URL and complete a transaction. - Webhook Callback The payment gateway triggers the verification endpoint upon successful payment. Ensure the endpoint is reachable and correctly configured.
- Verify the Results Check the response from the verification API to confirm the payment is valid.
Notes for Beginners
- The
VerifyPaymentAPI()function is plug-and-play. You don’t need to write additional code to handle the verification logic unless you have custom requirements. - Ensure that your
WEBHOOK_SECRETis properly set and matches the configuration in your payment gateway to validate webhook authenticity.
Troubleshooting
- Invalid Payment State: Ensure Redis is accessible and properly configured.
- Incorrect URL: Verify the
KARMAPAY_VERIFY_URLis correct and points to your verification route. - Webhook Not Triggering: Double-check your payment gateway settings and webhook configuration.