Skip to content
Headers & Signing

Headers & Signing

HeaderBuilder assembles the mandatory SNAP header set for a transaction request and signs it in the process — it’s the one type every calling function takes.

HeaderBuilder

type HeaderBuilder struct {
	Method      string // HTTP method, e.g. "POST"
	EndpointURL string // full endpoint URL used in the signed string
	Body        []byte // exact request body bytes

	B2B2C                 bool   // whether this is a B2B2C request
	AccessToken           string // Authorization bearer token
	AuthorizationCustomer string // Authorization-Customer bearer token; mandatory when B2B2C is true
	DeviceID              string // X-DEVICE-ID; mandatory when B2B2C is true

	ClientKey  string
	PartnerID  string
	ExternalID string
	ChannelID  string

	Origin    string // optional; header omitted when empty
	IPAddress string
	Latitude  string
	Longitude string

	Profile Profile

	Symmetric    bool
	ClientSecret string        // used when Symmetric is true
	Signer       crypto.Signer // used when Symmetric is false
}

Symmetric selects which signing function is used, matching BuildStringToSignTransaction’s own parameter — supply exactly one of ClientSecret (HMAC) or Signer (RSA), matching whatever your integration agreed with the partner at registration.

Every domain package’s calling function sets Body itself, from the exact bytes it marshals the typed request into — you don’t set it yourself for a normal call.

Build()

func (b HeaderBuilder) Build() (http.Header, error)

Assembles the http.Header for the request, signing it via BuildStringToSignTransaction and SignSymmetric/SignAsymmetric per the Symmetric flag. You normally never call this directly — snap.Transport.Do calls it for you.

Profile — per-PJP customization hooks

The standard leaves two details up to each PJP (Payment Service Provider): how timestamps are formatted and how URL paths are built. Profile is the interface HeaderBuilder and TokenManager use for both:

type Profile interface {
	TimestampLayout() string
	BuildPath(serviceGroup, productType string) string
}

DefaultProfile implements the standard behavior exactly:

type DefaultProfile struct {
	Domain  string
	Version string
}
func (p DefaultProfile) TimestampLayout() string
func (p DefaultProfile) BuildPath(serviceGroup, productType string) string

TimestampLayout returns snap.DefaultTimestampLayout (the Go time layout equivalent to the standard’s yyyy-MM-ddTHH:mm:ss.SSSTZD). BuildPath returns /{domain}/{version}/{service-group}/{product-type}, with Version defaulting to "v1.0" when unset.

A bank-specific deviation is expressed as a small struct embedding DefaultProfile and overriding one method — not a fork of HeaderBuilder.

Next