paytm

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2026 License: MIT Imports: 4 Imported by: 0

README

paytm-go

Go SDK for the Paytm Payment Gateway APIs.

Package Role
merchant Detail models / builders (PaymentDetail, RefundDetail, …)
pg Process APIs (Payment, Refund), signed HTTP, checksum, errors
constants URLs, headers, field names

Requirements

  • Go 1.21+
go get github.com/timslabs/paytm-go

Authentication

Paytm PG uses a merchant checksum (SHA256 + AES-128-CBC) on every API call. Create the client with credentials from the Paytm dashboard:

import (
	paytm "github.com/timslabs/paytm-go"
)

client := paytm.NewClient(
	paytm.STAGING_ENVIRONMENT, // or paytm.PRODUCTION_ENVIRONMENT
	os.Getenv("PAYTM_MID"),
	os.Getenv("PAYTM_MERCHANT_KEY"),
	os.Getenv("PAYTM_CLIENT_ID"),
	os.Getenv("PAYTM_WEBSITE"),
)
client.SetCallbackURL("https://merchant.example/callback")

Quick start

package main

import (
	"fmt"
	"log"
	"os"

	paytm "github.com/timslabs/paytm-go"
	"github.com/timslabs/paytm-go/merchant"
)

func main() {
	client := paytm.NewClient(
		paytm.STAGING_ENVIRONMENT,
		os.Getenv("PAYTM_MID"),
		os.Getenv("PAYTM_MERCHANT_KEY"),
		os.Getenv("PAYTM_CLIENT_ID"),
		os.Getenv("PAYTM_WEBSITE"),
	)
	client.SetCallbackURL("https://merchant.example/callback")

	detail := merchant.NewPaymentDetailBuilder(
		paytm.CHANNEL_WEB,
		"ORDER_001",
		merchant.NewMoney("1.00", paytm.CURRENCY_INR),
		merchant.UserInfo{CustID: "CUST_001"},
	).Build()

	resp, err := client.Payment.CreateTxnToken(detail)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("txnToken: %v\n", resp.Body()["txnToken"])

	status, err := client.Payment.GetPaymentStatus(
		merchant.NewPaymentStatusDetailBuilder("ORDER_001").Build(),
	)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%v\n", status.Response)
}

Successful calls return *merchant.SDKResponse. Failed HTTP responses return typed errors from pg/errors (BadRequestError, ServerError). Missing mandatory parameters return SDKError from the process API methods.

Configuration

client := paytm.NewClient(paytm.STAGING_ENVIRONMENT, mid, key, clientID, website)
client.SetTimeout(60) // seconds
client.SetUserAgent("MyApp/1.0")
client.SetCallbackURL("https://merchant.example/callback")
client.AddHeaders(map[string]string{"X-Custom": "value"})
client.SetEnvironment(paytm.PRODUCTION_ENVIRONMENT)
client.SetBaseURL(constants.STAGING_BASE_URL) // override (tests)
Environment Base URL
STAGING_ENVIRONMENT constants.STAGING_BASE_URL
PRODUCTION_ENVIRONMENT constants.PRODUCTION_BASE_URL

SDK APIs

Class Method HTTP Description
Payment CreateTxnToken POST /order/initiate Create transaction token
Payment GetPaymentStatus POST /v3/order/status Get payment status
Refund InitiateRefund POST /refund/apply Initiate refund
Refund GetRefundStatus POST /v2/refund/status Get refund status

Documentation

Doc Coverage
documents/auth.md Merchant setup
documents/payment.md PaymentDetail / CreateTxnToken / GetPaymentStatus
documents/refund.md RefundDetail / InitiateRefund / GetRefundStatus
documents/checksum.md Generate / verify signatures and callbacks

Official Paytm API docs:

Package layout

paytm-go/
  client.go                 # NewClient facade
  version.go
  constants/                # URLs, headers, field names
  merchant/                 # PaymentDetail, RefundDetail, SDKResponse, Money, UserInfo
  pg/
    payment.go              # CreateTxnToken, GetPaymentStatus
    refund.go               # InitiateRefund, GetRefundStatus
    request.go              # Signed HTTP POST
    checksum_api.go         # Client checksum helpers
    checksum/               # SHA256 + AES-128-CBC
    errors/                 # BadRequestError, ServerError, SDKError
  documents/
  testdata/
  utils/                    # Test helpers

Tests

go test ./...
go test ./pg -run TestCreateTxnToken -v

Reference

License

MIT

Documentation

Index

Constants

View Source
const (
	STAGING_ENVIRONMENT    = constants.STAGING_ENVIRONMENT
	PRODUCTION_ENVIRONMENT = constants.PRODUCTION_ENVIRONMENT

	CHANNEL_WEB = constants.CHANNEL_WEB
	CHANNEL_WAP = constants.CHANNEL_WAP

	CURRENCY_INR = constants.CURRENCY_INR

	REQUEST_TYPE_PAYMENT = constants.REQUEST_TYPE_PAYMENT
	DEFAULT_WEBSITE      = constants.DEFAULT_WEBSITE
)

Common constants re-exported for callers.

View Source
const SDKName = "paytm-go"

SDKName is the name of this SDK.

View Source
const SDKVersion = "1.0.0"

SDKVersion is the current package version.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*pg.Request
	Payment  *pg.Payment
	Refund   *pg.Refund
	Checksum *pg.Checksum
}

Client provides helper methods to call Paytm Payment Gateway APIs.

  • merchant/ detail models and builders (PaymentDetail, RefundDetail, …)
  • pg/ process APIs, request signing, checksum, errors
  • constants/ URLs, headers, field names

func NewClient

func NewClient(env constants.Environment, mid, merchantKey, clientID, website string) *Client

NewClient creates a Paytm PG client (instance-based MerchantProperties).

env should be Staging or Production. mid, merchantKey, clientID, and website are required merchant credentials from the Paytm dashboard.

func (*Client) AddHeaders

func (client *Client) AddHeaders(headers map[string]string)

AddHeaders adds additional headers to all subsequent requests.

func (*Client) SetBaseURL

func (client *Client) SetBaseURL(baseURL string)

SetBaseURL overrides the API host (useful in tests).

func (*Client) SetCallbackURL

func (client *Client) SetCallbackURL(callbackURL string)

SetCallbackURL sets the default callback URL for CreateTxnToken.

func (*Client) SetEnvironment

func (client *Client) SetEnvironment(env constants.Environment)

SetEnvironment switches between staging and production hosts.

func (*Client) SetTimeout

func (client *Client) SetTimeout(timeout int16)

SetTimeout sets the HTTP timeout in seconds.

func (*Client) SetUserAgent

func (client *Client) SetUserAgent(userAgent string)

SetUserAgent sets a custom User-Agent prefix.

Directories

Path Synopsis
pg
checksum
Package checksum implements Paytm's SHA256 + AES-128-CBC signature helpers.
Package checksum implements Paytm's SHA256 + AES-128-CBC signature helpers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL