paymentwall

package module
v0.0.0-...-0a78124 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2025 License: MIT Imports: 13 Imported by: 0

README

About Paymentwall

Paymentwall is the leading digital payments platform for globally monetizing digital goods and services. Paymentwall assists game publishers, dating sites, rewards sites, SaaS companies and many other verticals to monetize their digital content and services. Merchants can plug in Paymentwall’s API to accept payments from over 100 different methods including credit cards, debit cards, bank transfers, SMS/Mobile payments, prepaid cards, eWallets, landline payments and others.

To sign up for a Paymentwall Merchant Account, click here.

Paymentwall Golang Library

This library allows developers to use Paymentwall APIs (Virtual Currency, Digital Goods featuring recurring billing, and Virtual Cart).

To use Paymentwall, all you need to do is to sign up for a Paymentwall Merchant Account so you can setup an Application designed for your site. To open your merchant account and set up an application, you can sign up here.


Installation

Requires Go 1.18+ (modules)

go get github.com/paymentwall/paymentwall-go

In your code:

import "github.com/paymentwall/paymentwall-go"

Code Samples

Checkout API & Digital Goods API

Web API details for API Checkout
Web API details for API Goods

Initializing Paymentwall
client := paymentwall.NewClient(
  "YOUR_APPLICATION_KEY",
  "YOUR_SECRET_KEY",
  paymentwall.APIGoods, // Digital Goods API
)
Widget Call

Web API details for Checkout
Web API details for Goods

The widget is a payment page hosted by Paymentwall that embeds the entire payment flow: selecting the payment method, completing the billing details, and providing customer support via the Help section. You can redirect the users to this page or embed it via iframe. Below is an example that renders an iframe with Paymentwall Widget.

// 1) Create a Product (for checkout API)
prod, err := paymentwall.NewProduct(
  "product301",               // external ID
  12.12,                      // amount
  "USD",                      // currency
  "Test Product",             // name
  paymentwall.ProductTypeFixed, // type
  0, "", false, nil,
)
if err != nil {
  panic(err)
}

// 2) Build the Widget
widget := paymentwall.NewWidget(
  client,
  "user4522",                 // your end-user ID
  "pw",                       // widget code from Merchant Area
  []*paymentwall.Product{prod}, // Checkout API require 1 product, let empty for digital good API
  map[string]any{"email":"[email protected]"},
)

// 3) Get iframe HTML
html, err := widget.GetHTMLCode(nil)
if err != nil {
  panic(err)
}
fmt.Println(html)
Pingback Processing

The Pingback is a webhook notifying about a payment being made. Pingbacks are sent via HTTP/HTTPS to your servers. To process pingbacks use the following guide:

// pingback
pb := paymentwall.NewPingback(client, "query params", "remote_address")
if !pb.Validate(false) {
  // handle validation errors
  fmt.Println(pb.ErrorSummary())
  return
}

if pb.IsDeliverable() {
  // deliver the product
} else if pb.IsCancelable() {
  // withdraw the product
}

Virtual Currency API

Web API details

client := paymentwall.NewClient("APP_KEY", "SECRET_KEY", paymentwall.APIVC)

widget := paymentwall.NewWidget(
  client,
  "user40012",
  "vc_widget_code",
  []*paymentwall.Product{},              // always empty
  map[string]any{"email":"[email protected]"},
)
fmt.Println(widget.GetHTMLCode(nil))
// pingback
pb := paymentwall.NewPingback(client, "query params", "remote_address")
if !pb.Validate(false) {
  // handle validation errors
  fmt.Println(pb.ErrorSummary())
  return
}

if pb.IsDeliverable() {
  // deliver the product
} else if pb.IsCancelable() {
  // withdraw the product
}

Cart API

Web API details

client := paymentwall.NewClient("APP_KEY", "SECRET_KEY", paymentwall.APICart)

prod1, _ := paymentwall.NewProduct("product301", 3.33, "EUR", "Item A", paymentwall.ProductTypeFixed, 0, "", false, nil)
prod2, _ := paymentwall.NewProduct("product607", 7.77, "EUR", "Item B", paymentwall.ProductTypeFixed, 0, "", false, nil)

widget := paymentwall.NewWidget(
  client,
  "user40012",
  "cart_widget_code",
  []*paymentwall.Product{prod1, prod2},
  map[string]any{"email":"[email protected]"},
)
fmt.Println(widget.GetHTMLCode(nil))
// pingback
pb := paymentwall.NewPingback(client, "query params", "remote_address")
if !pb.Validate(false) {
  // handle validation errors
  fmt.Println(pb.ErrorSummary())
  return
}

if pb.IsDeliverable() {
  // deliver the product
} else if pb.IsCancelable() {
  // withdraw the product
}

Contributing & Support


Documentation

Overview

Package paymentwall provides a Go SDK for interacting with the Paymentwall APIs.

Package paymentwall provides a Go SDK for interacting with the Paymentwall APIs.

Package paymentwall provides a Go SDK for interacting with the Paymentwall APIs.

Package paymentwall provides a Go SDK for interacting with the Paymentwall APIs.

Index

Constants

View Source
const (
	VCController    = "ps"
	GoodsController = "subscription"
	CartController  = "cart"
	BaseURL         = "https://api.paymentwall.com/api"
	VersionString   = "0.1.1"
)
View Source
const (
	ProductTypeFixed        = "fixed"
	ProductTypeSubscription = "subscription"
)

ProductType constants

View Source
const (
	PeriodDay   = "day"
	PeriodWeek  = "week"
	PeriodMonth = "month"
	PeriodYear  = "year"
)

PeriodType constants

Variables

This section is empty.

Functions

This section is empty.

Types

type APIType

type APIType int

APIType identifies the Paymentwall API mode.

const (
	APIVC    APIType = 1 // Virtual Currency
	APIGoods APIType = 2 // Digital Goods
	APICart  APIType = 3 // Cart API
)

type Client

type Client struct {
	APIType   APIType
	AppKey    string
	SecretKey string
	Errors    []string
}

Client holds global configuration and error state for the SDK.

func NewClient

func NewClient(appKey, secretKey string, api APIType) *Client

NewClient initializes a Paymentwall Client with the given keys and API type.

func (*Client) AppendError

func (c *Client) AppendError(err string)

AppendError records an error message in the client's error list.

func (*Client) CalculateSignature

func (c *Client) CalculateSignature(
	params map[string]any,
	version SignatureVersion,
) (string, error)

CalculateSignature builds a signature string based on the provided parameters and version. It implements SigV1, SigV2, and SigV3 signature algorithms as per Paymentwall's documentation.

func (*Client) ErrorSummary

func (c *Client) ErrorSummary() string

ErrorSummary returns all recorded errors as a single string.

func (*Client) SetAPIType

func (c *Client) SetAPIType(api APIType)

SetAPIType allows overriding the API type on an existing client.

type Pingback

type Pingback struct {
	Client    *Client
	Params    map[string]any
	IPAddress string
	Errors    []string
}

Pingback represents a Paymentwall webhook notification validator.

func NewPingback

func NewPingback(client *Client, params map[string]any, ip string) *Pingback

NewPingback constructs a Pingback with given params and source IP.

func (*Pingback) ErrorSummary

func (p *Pingback) ErrorSummary() string

ErrorSummary returns accumulated errors.

func (*Pingback) GetPingbackUniqueID

func (p *Pingback) GetPingbackUniqueID() string

GetPingbackUniqueID returns a unique ID composed of ref and type, e.g. "REF123_0".

func (*Pingback) GetProduct

func (p *Pingback) GetProduct() (*Product, error)

GetProduct reconstructs a Product from pingback parameters.

func (*Pingback) GetProductID

func (p *Pingback) GetProductID() string

GetProductID returns the product ID from "goodsid".

func (*Pingback) GetProducts

func (p *Pingback) GetProducts() ([]*Product, error)

GetProducts returns a slice of Products for Cart API.

func (*Pingback) GetReferenceID

func (p *Pingback) GetReferenceID() string

GetReferenceID returns the "ref" parameter.

func (*Pingback) GetType

func (p *Pingback) GetType() (int, error)

GetType returns the pingback type as int.

func (*Pingback) GetUserID

func (p *Pingback) GetUserID() string

GetUserID returns the "uid" parameter.

func (*Pingback) GetVCAmount

func (p *Pingback) GetVCAmount() string

GetVCAmount returns the "currency" parameter for virtual currency.

func (*Pingback) IsCancelable

func (p *Pingback) IsCancelable() bool

IsCancelable returns true if pingback type indicates cancellation.

func (*Pingback) IsDeliverable

func (p *Pingback) IsDeliverable() bool

IsDeliverable returns true if pingback type indicates delivery.

func (*Pingback) IsUnderReview

func (p *Pingback) IsUnderReview() bool

IsUnderReview returns true if pingback type indicates under review.

func (*Pingback) Validate

func (p *Pingback) Validate(skipIPWhitelist bool) bool

Validate runs parameter, IP whitelist, and signature checks. skipIPWhitelist allows bypassing the IP check (for testing).

type Product

type Product struct {
	ID           string   // Unique identifier for the product
	Amount       float64  // Price, rounded to two decimals
	CurrencyCode string   // ISO currency code, e.g., "USD"
	Name         string   // Human-readable name
	Type         string   // Product type: fixed or subscription
	PeriodLength int      // Subscription period length
	PeriodType   string   // Subscription period unit: day, week, month, year
	Recurring    bool     // Whether subscription auto-renews
	TrialProduct *Product // Trial period product; non-nil only for recurring subscriptions
}

Product represents a one-time or subscription-based item in the Paymentwall SDK.

func NewProduct

func NewProduct(
	id string,
	amount float64,
	currencyCode, name, prodType string,
	periodLength int,
	periodType string,
	recurring bool,
	trial *Product,
) (*Product, error)

NewProduct constructs and validates a Product, rounding amount to two decimals. Returns an error if prodType or periodType is invalid.

func (*Product) IsRecurring

func (p *Product) IsRecurring() bool

IsRecurring returns true if the product is a recurring subscription.

type SignatureVersion

type SignatureVersion int

SignatureVersion denotes the version of the signature algorithm.

const (
	SigV1 SignatureVersion = 1 // MD5(params + secret)
	SigV2 SignatureVersion = 2 // MD5(sorted params + secret)
	SigV3 SignatureVersion = 3 // SHA256(sorted params + secret)
)

type Widget

type Widget struct {
	Client      *Client
	UserID      string
	WidgetCode  string
	Products    []*Product
	ExtraParams map[string]any
}

Widget builds Paymentwall widget URLs and HTML.

func NewWidget

func NewWidget(client *Client, userID, widgetCode string, products []*Product, extra map[string]any) *Widget

NewWidget initializes a new Widget.

func (*Widget) GetHTMLCode

func (w *Widget) GetHTMLCode(attrs map[string]string) (string, error)

GetHTMLCode returns the iframe HTML code for the widget.

func (*Widget) GetParams

func (w *Widget) GetParams() (map[string]any, error)

GetParams constructs the parameter map for the widget, including signature.

func (*Widget) GetURL

func (w *Widget) GetURL() (string, error)

GetURL builds the full widget URL.

Jump to

Keyboard shortcuts

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