Skip to main content

Getting Started with KarmaPay Integration

KarmaPay simplifies online payment integrations by providing a unified API to interact with multiple payment gateways such as Razorpay, Stripe, and PhonePe. Follow this guide to set up and start using the KarmaPay package in your Go project.

Prerequisites

Before you begin, ensure you have the following:
  1. Redis KarmaPay relies on Redis for managing order states temporarily. Ensure Redis is installed and accessible in your environment.
  2. Self-host KarmaPay PG Service Clone and self-host the KarmaPay PG Service. This service acts as the backend for managing payment orders. Configure it with proper Redis environment variables.
  3. Environment Variables Set up the required environment variables in your Go project. Here are the variables and their purposes: Example .env file:

Installation

Install the KarmaPay package in your Go project:

Creating a Payment Order

To create a payment order, use the payments.CreatePaymentOrder() function. This function generates a dynamic payment URL that redirects users to the payment gateway.

Parameters

The payments.CreatePaymentOrder() function accepts the following fields:
  • OrderAmount (int32): Total amount for the payment.
  • OrderCurrency (string): Currency code (e.g., INR).
  • OrderDescription (string): Description of the order or purpose of payment.
  • OrderMode (string): The payment gateway enum (RAZORPAY, STRIPE, PHONEPE) set in your environment variables.
  • WebhookURL (string): The webhook URL to handle payment gateway callbacks.
  • RedirectURL (string): A URL where users are redirected post-payment (optional).
  • Registration (string): Set to "no" if registration is not required.

Example Code

Here’s how you can create a payment order in your Go application:

Next Steps

  1. Verify Payment Once the payment is completed, use the payments.VerifyPayment() function to validate the transaction.
  2. Handle Webhooks Implement the webhook handler in your project to process real-time payment notifications from the payment gateway.
  3. Explore More Refer to the KarmaPay GitHub repository for advanced usage and additional configurations.

Troubleshooting

If you encounter any issues, check:
  • Redis connectivity (REDIS_URL).
  • Proper configuration of environment variables.
  • Correct hosting of the KarmaPay PG Service.
  • Gateway-specific requirements (e.g., domain verification).
Feel free to reach out for support or contribute to the project to help us improve KarmaPay!