Documentation ¶
Index ¶
- Constants
- func FormatCardNumber(number string) string
- func FormatMonthYear[T time.Month | int](month T, year int) (string, string)
- func PubKeyFromBytes(b []byte, publicExponent ...int) *rsa.PublicKey
- type AdyenVersion
- type Encrypter
- func (enc *Encrypter) EncryptField(key, value string) (string, error)
- func (enc *Encrypter) EncryptFields(fields map[string]string) (string, error)
- func (enc *Encrypter) EncryptMarshal(payload interface{}) (string, error)
- func (enc *Encrypter) EncryptPlaintext(plaintext []byte) (string, error)
- func (enc *Encrypter) Reset() (err error)
- type GenerationTimeFunc
Constants ¶
const ( // GenerationTimeKey is the JSON key for the generated time. GenerationTimeKey = "generationtime" // GenerationTimeFormat is the time format. // This is identical to time.RFC3339Nano except there is only three trailing zeros. GenerationTimeFormat = "2006-01-02T15:04:05.000Z07:00" )
Variables ¶
This section is empty.
Functions ¶
func FormatCardNumber ¶
FormatCardNumber formats the given card number into the Adyen format. Numbers less than 15 digits (excluding white space) are ignored.
Examples:
0123456789012345 -> 0123 4567 8901 2345
0123 4567 8901 2345 -> (no change)
0123 456789012345 -> 0123 4567 8901 2345
func FormatMonthYear ¶
FormatMonthYear formats a card expiry month and year into the Adyen format. It is assumed that the given year is the fully-qualified year, like "2020" (instead of "20".)
Examples:
5, 2024 -> "05", "2024"
12, 2024 -> "12", "2024"
Types ¶
type AdyenVersion ¶
type AdyenVersion string
var ( Version118 AdyenVersion = "0_1_18" Version121 AdyenVersion = "0_1_21" )
type Encrypter ¶
type Encrypter struct { // Version is the Adyen version that this Encrypter will // seal plaintext for. Version AdyenVersion // GetGenerationTime gets the time.Time to use for the // required "generationtime" JSON field. The default is // time.Now. // // This may be modified by the caller to return custom times // that differ from the default. GetGenerationTime GenerationTimeFunc // contains filtered or unexported fields }
An Encrypter encrypts content into the Adyen format using an RSA public key and AES-256.
func NewEncrypter ¶
func NewEncrypter(version AdyenVersion, pubKey *rsa.PublicKey) (enc *Encrypter, err error)
NewEncrypter creates a new Encrypter with the given version and RSA public key.
Calls to Encrypter.EncryptPlaintext will panic if pubKey == nil.
func (*Encrypter) EncryptField ¶
EncryptField encrypts a single key and value.
func (*Encrypter) EncryptFields ¶
EncryptFields encrypts a map.
func (*Encrypter) EncryptMarshal ¶
func (*Encrypter) EncryptPlaintext ¶
EncryptPlaintext seals the given plaintext and returns the sealed content in the Adyen format.
Most callers should use Encrypt, EncryptField or EncryptFields instead.
type GenerationTimeFunc ¶
GenerationTimeFunc is a function responsible for returning the time that a payload was generated at.