gomerchant

package module
v0.0.0-...-62f474b Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: MIT Imports: 5 Imported by: 19

README

Gomerchant

Gomerchant is an abstracted payment interface for Golang, it provides unified API for different payment gateways.

Usage

import "github.com/qor/gomerchant/gateways/stripe"

func main() {
  Stripe := stripe.New(&stripe.Config{
    Key: config.Key,
  })
}

GoDoc

Documentation

Index

Constants

View Source
const RAKUTEN_PAY_PRODUCT_ID = "WholeOrderAmount"

Variables

View Source
var (
	// Mostly copied from Stripe, might need to be modified when integrating other payment gateways.
	ErrInvalidNumber      = errors.New("gomerchant: the card number is not a valid credit card number.")
	ErrInvalidExpiryMonth = errors.New("gomerchant: the card's expiration month is invalid.")
	ErrInvalidExpiryYear  = errors.New("gomerchant: the card's expiration year is invalid.")
	ErrInvalidCVC         = errors.New("gomerchant: the card's security code is invalid.")
	ErrIncorrectNumber    = errors.New("gomerchant: the card number is incorrect.")
	ErrExpiredCard        = errors.New("gomerchant: the card has expired.")
	ErrIncorrectCVC       = errors.New("gomerchant: the card's security code is incorrect.")
	ErrIncorrectZip       = errors.New("gomerchant: the card's zip code failed validation.")
	ErrCardDeclined       = errors.New("gomerchant: the card was declined.")
	ErrMissing            = errors.New("gomerchant: there is no card on a customer that is being charged.")
	ErrProcessingError    = errors.New("gomerchant: an error occurred while processing the card.")
)
View Source
var Brands = map[string]*regexp.Regexp{
	`visa`:               regexp.MustCompile(`^4\d{12}(\d{3})?$`),
	`master`:             regexp.MustCompile(`^(5[1-5]\d{4}|677189)\d{10}$`),
	`discover`:           regexp.MustCompile(`^(6011|65\d{2}|64[4-9]\d)\d{12}|(62\d{14})$`),
	`american_express`:   regexp.MustCompile(`^3[47]\d{13}$`),
	`diners_club`:        regexp.MustCompile(`^3(0[0-5]|[68]\d)\d{11}$`),
	`jcb`:                regexp.MustCompile(`^35(27|28|29|[3-8]\d)\d{12}$`),
	`switch`:             regexp.MustCompile(`^6759\d{12}(\d{2,3})?$`),
	`solo`:               regexp.MustCompile(`^6767\d{12}(\d{2,3})?$`),
	`dankort`:            regexp.MustCompile(`^5019\d{12}$`),
	`maestro`:            regexp.MustCompile(`^(5[06-8]|6\d)\d{10,17}$`),
	`forbrugsforeningen`: regexp.MustCompile(`^600722\d{10}$`),
	`laser`:              regexp.MustCompile(`^(6304|6706|6771|6709)\d{8}(\d{4}|\d{6,7})?$`),
}
View Source
var ErrNotSupportedPaymentMethod = errors.New("not supported payment method")

Functions

This section is empty.

Types

type Address

type Address struct {
	Name     string
	Company  string
	Address1 string
	Address2 string
	City     string
	State    string
	Country  string
	ZIP      string
	Phone    string
}

type ApplicationParams

type ApplicationParams struct {
	MerchandiseType uint64
	PCMobileType    uint64
	ButtonType      string
	ReturnUrl       string
	CancelUrl       string
	Goods           []Good
	Params
}

type ApplicationResponse

type ApplicationResponse struct {
	TransactionID       string
	OrderCode           string
	TradeGenerationDate string
	RedirectHTML        string
	Params
}

type AuthorizeParams

type AuthorizeParams struct {
	Amount          uint64
	Currency        string
	Customer        string
	Description     string
	OrderID         string
	BillingAddress  *Address
	ShippingAddress *Address
	PaymentMethod   *PaymentMethod
	Params
}

AuthorizeParams authorize params

type AuthorizeResponse

type AuthorizeResponse struct {
	TransactionID  string
	HandleRequest  bool                                                   // need process request after authorize or not
	RequestHandler func(http.ResponseWriter, *http.Request, Params) error // process request
	Params
}

AuthorizeResponse authorize response

type CaptureParams

type CaptureParams struct {
	Params
}

CaptureParams capture params

type CaptureResponse

type CaptureResponse struct {
	TransactionID string
	Params
}

CaptureResponse capture response

type CompleteAuthorizeParams

type CompleteAuthorizeParams struct {
	Params
}

CompleteAuthorizeParams complete authorize params

type CompleteAuthorizeResponse

type CompleteAuthorizeResponse struct {
	Params
}

CompleteAuthorizeResponse complete authorize response

type CreateCreditCardParams

type CreateCreditCardParams struct {
	CustomerID string
	CreditCard *CreditCard
}

CreateCreditCard Params

type CreditCard

type CreditCard struct {
	Name     string
	Number   string
	ExpMonth uint
	ExpYear  uint
	CVC      string
}

func (CreditCard) Brand

func (creditCard CreditCard) Brand() string

func (CreditCard) ValidNumber

func (creditCard CreditCard) ValidNumber() bool

https://en.wikipedia.org/wiki/Luhn_algorithm

type CreditCardManager

type CreditCardManager interface {
	CreateCreditCard(creditCardParams CreateCreditCardParams) (CreditCardResponse, error)
	GetCreditCard(creditCardParams GetCreditCardParams) (GetCreditCardResponse, error)
	ListCreditCards(listCreditCardsParams ListCreditCardsParams) (ListCreditCardsResponse, error)
	DeleteCreditCard(deleteCreditCardParams DeleteCreditCardParams) (DeleteCreditCardResponse, error)
}

CreditCardManager interface

type CreditCardResponse

type CreditCardResponse struct {
	CustomerID   string
	CreditCardID string
	Params
}

type CustomerCreditCard

type CustomerCreditCard struct {
	CustomerID   string
	CustomerName string
	CreditCardID string
	MaskedNumber string
	ExpMonth     uint
	ExpYear      uint
	Brand        string
	Params
}

CustomerCreditCard CustomerCard defination

type DeleteCreditCardParams

type DeleteCreditCardParams struct {
	CustomerID   string
	CreditCardID string
}

Delete Credit Cards Params

type DeleteCreditCardResponse

type DeleteCreditCardResponse struct {
	Params
}

type GetCreditCardParams

type GetCreditCardParams struct {
	CustomerID   string
	CreditCardID string
}

Get Credit Cards Params

type GetCreditCardResponse

type GetCreditCardResponse struct {
	CreditCard *CustomerCreditCard
	Params
}

type Good

type Good struct {
	ID     string
	Name   string
	Price  float64
	Amount uint64
}

type InquiryResponse

type InquiryResponse struct {
	TransactionID     string
	TradingID         string
	PaymentNoticeID   string
	PaymentInitDate   string
	PaymentChangeDate string
	PaymentAmount     string
	BasePaymentID     string
	PaymentStatus     string
	SuccessCode       string
	SuccessDetail     string
	Params
}

type IntegrationGateway

type IntegrationGateway interface {
}

IntegrationGateway integration gateway

type ListCreditCardsParams

type ListCreditCardsParams struct {
	CustomerID string
}

List Credit Cards Params

type ListCreditCardsResponse

type ListCreditCardsResponse struct {
	CreditCards []*CustomerCreditCard
	Params
}

type Params

type Params map[string]interface{}

func (Params) Get

func (params Params) Get(key string) (interface{}, bool)

func (Params) IgnoreBlankFields

func (params Params) IgnoreBlankFields() Params

func (Params) Set

func (params Params) Set(key string, value interface{})

type PaymentGateway

type PaymentGateway interface {
	Authorize(amount uint64, params AuthorizeParams) (AuthorizeResponse, error)
	CompleteAuthorize(paymentID string, params CompleteAuthorizeParams) (CompleteAuthorizeResponse, error)
	Capture(transactionID string, params CaptureParams) (CaptureResponse, error)
	Refund(transactionID string, amount uint, params RefundParams) (RefundResponse, error)
	Void(transactionID string, params VoidParams) (VoidResponse, error)

	Query(transactionID string) (Transaction, error)
}

PaymentGateway interface

type PaymentMethod

type PaymentMethod struct {
	SavedCreditCard *SavedCreditCard
	CreditCard      *CreditCard
}

type RefundParams

type RefundParams struct {
	Captured bool
	Params
}

RefundParams refund params

type RefundResponse

type RefundResponse struct {
	TransactionID string
	Params
}

RefundResponse refund response

type SavedCreditCard

type SavedCreditCard struct {
	CustomerID   string
	CreditCardID string
	CVC          string
}

type Transaction

type Transaction struct {
	ID        string
	Amount    int
	Currency  string
	Captured  bool
	Paid      bool // if authorized or captured
	Cancelled bool
	Status    string
	CreatedAt *time.Time
	Params
}

type VoidParams

type VoidParams struct {
	Captured bool
	Params
}

VoidParams void params

type VoidResponse

type VoidResponse struct {
	TransactionID string
	Params
}

VoidResponse void response

Directories

Path Synopsis
gateways
stripe
Package stripe implements GoMerchant payment gateway for Stripe.
Package stripe implements GoMerchant payment gateway for Stripe.

Jump to

Keyboard shortcuts

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