payment

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2021 License: MIT Imports: 2 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterPrepaidGateway added in v0.0.3

func RegisterPrepaidGateway(instanceID string, gateway PrepaidGateway)

func RegisterPrepaidGatewayGenerator added in v0.1.11

func RegisterPrepaidGatewayGenerator(gatewayTypeName string, genFunc PrepaidGatewayGen)

func Setup added in v0.1.1

func Setup(d *sql.DB, sqlTblPrefix string) error

func TblPrefix added in v0.1.1

func TblPrefix() string

Types

type P

type P map[string]interface{}

P stands for Parameters and is a shortcut for map[string]interface{}

var (
	// Here's an example of gatewayConfigTemplate
	// the frontend should display a form as
	// specified by the template
	// For possible InputType, see as defined in types.go
	ExampleGatewayConfigTemplate P = P{
		"api_user": P{
			"FriendlyName": "API Username",
			"InputType":    "text",
			"Default":      "user",
			"Description":  "Specify your API Username. Not your email address",
			"Optional":     false,
		},
		"api_token": P{
			"FriendlyName": "API Token",
			"InputType":    "password",
		},
		"api_version": P{
			"FriendlyName": "API Version",
			"InputType":    "number",
			"Default":      3,
		},
		"api_certificate": P{
			"FriendlyName": "API Certificate",
			"InputType":    "textarea",
			"Optional":     true,
		},
		"auth_mode": P{
			"FriendlyName": "Auth Mode",
			"InputType":    "radiogroup",

			"Items": P{
				"auth_once": P{
					"FriendlyName": "Auth Once",
				},
				"auth_always": P{
					"FriendlyName": "Auth Always",
				},
			},
		},
		"vendor_select": P{
			"FriendlyName": "Vendor Select",
			"InputType":    "dropdown",
			"Items": P{
				"tunnelwork": P{
					"FriendlyName": "Tunnel.Work (Default)",
				},
				"gaukaswang": P{
					"FriendlyName": "Gaukas.Wang (50% Off!)",
				},
			},
		},
	}

	// This is an example for gatewayConfig corresponding to the template
	// provided above.
	// Note that all types are string.
	ExampleGatewayConfig P = P{
		"api_user":    "user",
		"api_token":   "THISISAFAKETOKENFORDEMONSTRATION",
		"apr_version": "3",
		"api_certificate": `mDMEYTlFghYJKwYBBAHaRw8BAQdA/uS2O1VY4krn4ocmQNcslLHCYPhk3/MaKoUh
		3/QCMv20EkdhdWthcyA8aUBnYXVrLmFzPoiQBBMWCAA4FiEEBduM/AI5+aeDTX3t
		ni+Jhtdvi10FAmE5RYICGyMFCwkIBwIGFQoJCAsCBBYCAwECHgECF4AACgkQni+J
		htdvi11TEAD/WuVpN/MwPZHrhdMfjy0vftvGqCeMxnMYOMqO7dqWu/EA/jgDsJO6
		9tmLgWiGJFvp5q6C6/h2Z/h+dLEliBFvhyIJtBtHYXVrYXMgV2FuZyA8aUBnYXVr
		YXMud2FuZz6IkAQTFggAOBYhBAXbjPwCOfmng0197Z4viYbXb4tdBQJhOUWwAhsj
		BQsJCAcCBhUKCQgLAgQWAgMBAh4BAheAAAoJEJ4viYbXb4tdtHcA/jinVl583X5H
		/uqWntniOVP/H/Y8BIGKA7VKixvpRoYrAQDHXgNudx55zBvxhs8uwbx50pFyKSJl
		pURMd+1CKNipD7g4BGE5RYISCisGAQQBl1UBBQEBB0Dwmfyi3YWai/M9HnGN42LX
		R+mvWH3695DHZQwzm87FZwMBCAeIeAQYFggAIBYhBAXbjPwCOfmng0197Z4viYbX
		b4tdBQJhOUWCAhsMAAoJEJ4viYbXb4tddukA/AgGRVfY8bnJJh/xfS6CzJHkvU20
		GEO3wpxOrQHqIk7vAP9SQ4BDLnDjFrTyxNOWpWuHFcvlAbdGwrKmUjq2U74WAQ==
		=8i6d`,
		"auth_mode":     "auth_once",
		"vendor_select": "tunnelwork",
	}

	ExampleOrderCreationParams P = P{
		"ReferenceID": "TunnelWork-#109",
		"Amount": P{
			"Value":    "4.20",
			"Currency": "USD",
		},
		"GatewayType": "GatewayBillable",
	}

	// Will not be parsed, used for debugging purposes.
	ExampleOrderDetails P = P{
		"OrderID": "0xDEADC0DE",
		"Amount": P{
			"Value":    "4.20",
			"Currency": "USD",
		},
		"GatewaySpecificField1": "Some Data",
		"GatewaySpecificField2": "Some More Data",
		"GatewaySpecificField3": "Even More Data",
	}

	// Will be parsed and also recorded
	ExampleOrderStatus P = P{
		"OrderID": "0xDEADC0DE",
		"Status":  "UNPAID",
		"Payer":   "i@gaukas.wang",
	}

	ExampleOrderFormTemplate P = P{
		"Type": "OnSite",
		"OnSiteParams": P{
			"card_holder": P{
				"FriendlyName": "Card Holder",
				"InputType":    "text",
				"Description":  "Name on card",
			},
			"card_number": P{
				"FriendlyName": "Card Number",
				"InputType":    "text",
			},
			"cvv": P{
				"FriendlyName": "CVV",
				"InputType":    "password",
				"Description":  "The 3-digit security number on your card",
			},
			"network_selection": P{
				"FriendlyName": "CC Network Selection",
				"InputType":    "dropdown",
				"Items": P{
					"mastercard": P{
						"FriendlyName": "MasterCard",
					},
					"visa": P{
						"FriendlyName": "VISA",
					},
					"jcb": P{
						"FriendlyName": "JCB",
					},
				},
			},
		},
		"ButtomParams": P{
			"btn_type":        "text",
			"image_url":       "./assets/img/paynow.png",
			"btn_target_attr": "_blank",
			"btn_href":        "https://example.com/pay?id=0xDEADC0DE&merchant=0x12345678",
		},
	}

	ExampleOnSiteOrderForm P = P{
		"OrderID": "0xDEADC0DE",
		"OrderForm": P{
			"card_holder":       "Gaukas Wang",
			"card_number":       "4800333344445555",
			"cvv":               "123",
			"network_selection": "visa",
		},
	}

	ExampleOrderRefundParams P = P{
		"OrderID": "0xDEADC0DE",
		"Amount": P{
			"Value":    "0.69",
			"Currency": "USD",
		},
	}
)

Examples

type PaymentRequest added in v0.0.3

type PaymentRequest struct {
	Item PaymentUnit
}

PaymentRequest is an extra layer as a wrapper to provider extendability in the future

type PaymentResult added in v0.0.4

type PaymentResult struct {
	Status PaymentStatus
	Unit   PaymentUnit
	Msg    string
}

type PaymentStatus added in v0.0.3

type PaymentStatus uint8
const (
	UNPAID PaymentStatus = iota
	CLOSED
	UNKNOWN
)

OrderStatus

type PaymentUnit added in v0.0.3

type PaymentUnit struct {
	// A caller-generated special ID used for order to track the payment
	ReferenceID string `json:"reference_id"`

	// The 3-letter currency code following ISO 4217
	// https://en.wikipedia.org/wiki/ISO_4217#Active_codes
	Currency string `json:"currency"`

	// A floating number written as a string. Precision should be limited to prevent payment issues
	Price float64 `json:"price"`
}

PaymentUnit defines a single item or order to be paid

type PrepaidGateway added in v0.0.3

type PrepaidGateway interface {
	/**** Pay ****/
	CheckoutForm(pr PaymentRequest) (formRenderParams map[string]interface{}, err error)

	/**** Status ****/
	// PaymentResult() checks for a referenceID
	// this function should be called once a customer CLAIMS the payment has been made
	PaymentResult(referenceID string) (result PaymentResult, err error)

	/**** Refund ****/
	// IsRefundable() checks for refundability for a referenceID
	// It should always return false for a gateway without Refund() capability
	IsRefundable(referenceID string) bool

	// Refund() returns nil if successfully refunded.
	Refund(rr RefundRequest) error

	/**** Callback Setup ****/
	// OnStatusChange() sets the function to be called once the referenceID's payment status is changed
	// returns error when doesn't have such callback functionality
	OnStatusChange(PtrUpdateHandler *func(referenceID string, newResult PaymentResult)) error
}

PrepaidGateway allows user to pay based on their purchase or deposit order.

func GetPrepaidGateway added in v0.1.11

func GetPrepaidGateway(instanceID string) (PrepaidGateway, error)

func NewPrepaidGateway added in v0.0.3

func NewPrepaidGateway(gatewayTypeName, instanceID string, initConf interface{}) (PrepaidGateway, error)

NewPrepaidGateway() creates a PrepaidGateway in the type of gatewayTypeName with the specified instanceID, which supports the duplicapability for each gatewayType. Note: it is caller's responsibility to make sure the *sql.DB is alive.

type PrepaidGatewayGen added in v0.0.3

type PrepaidGatewayGen func(db *sql.DB, instanceID string, initConf interface{}) (PrepaidGateway, error)

A PrepaidGatewayGen is a generator function creates PrepaidGateway typically called NewXXXGateway() or CreateXXXGateway()

type RefundRequest added in v0.0.3

type RefundRequest struct {
	Item PaymentUnit
}

Jump to

Keyboard shortcuts

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