Documentation ¶
Overview ¶
Package beanstream supplies the 3 APIs for processing payments:
PaymentsAPI ProfilesAPI ReportingAPI
Each API has its own Passcode and processes against your Merchant ID.
To start using an API you must create a Gateway and supply it the configuration it needs to run:
gateway := beanstream.Gateway{beanstream.Config{ "300200578", // merchant ID "4BaD82D9197b4cc4b70a221911eE9f70", // Payments Passcode "D97D3BE1EE964A6193D17A571D9FBC80", // Profiles Passcode "4e6Ff318bee64EA391609de89aD4CF5d", // Reporting Passcode "www", // url prefix "api", // url suffix "v1", // api version "-8:00"}} // timezone offset
The above values use a Beanstream Test account.
To Create a new payment (credit card, cash, cheque...) use the Payments API and supply it with a PaymentRrequest:
request := beanstream.PaymentRequest{ PaymentMethod: paymentMethods.CARD, OrderNumber: beanstream.Util_randOrderId(6), Amount: 12.99, Card: beanstream.CreditCard{ Name: "John Doe", Number: "5100000010001004", ExpiryMonth: "11", ExpiryYear: "19", Cvd: "123", Complete: true}} res, err := gateway.Payments().MakePayment(request)
For more details visit the documentation for each particular API.
Index ¶
- func AsDate(val string, config Config) time.Time
- func GenerateAuthCode(merchId string, apiKey string) string
- func LegatoTokenizeCard(cardNumber string, expMo string, expYr string, cvd string) (string, error)
- func Process(httpMethod string, url string, merchId string, apiKey string, ...) (interface{}, error)
- func ProcessBody(httpMethod string, url string, merchId string, apiKey string, data interface{}, ...) (interface{}, error)
- func ProcessMultiPart(httpMethod string, url string, merchId string, apiKey string, ...) (interface{}, error)
- func Util_randOrderId(num int) string
- func Util_randSeq(n int) string
- type Address
- type Adjustment
- type BatchAPI
- type BatchCriteria
- type BeanstreamApiException
- type Config
- type CreditCard
- type Criteria
- type CustomFields
- type ErrorDetail
- type Gateway
- type Link
- type PaymentRequest
- type PaymentResponse
- type PaymentsAPI
- func (api PaymentsAPI) CompletePayment(transId string, request PaymentRequest) (*PaymentResponse, error)
- func (api PaymentsAPI) GetTransaction(transId string) (*Transaction, error)
- func (api PaymentsAPI) MakePayment(transaction PaymentRequest) (*PaymentResponse, error)
- func (api PaymentsAPI) ReturnPayment(transId string, amount float32) (*PaymentResponse, error)
- func (api PaymentsAPI) VoidPayment(transId string, amount float32) (*PaymentResponse, error)
- type Profile
- func (p *Profile) AddCard(pAPI ProfilesAPI, card CreditCard) (*ProfileResponse, error)
- func (p *Profile) DeleteCard(pAPI ProfilesAPI, cardId int) (*ProfileResponse, error)
- func (p *Profile) GetCard(pAPI ProfilesAPI, cardId int) (*CreditCard, error)
- func (p *Profile) GetCards(pAPI ProfilesAPI) ([]CreditCard, error)
- func (p *Profile) UpdateCard(pAPI ProfilesAPI, card CreditCard) (*ProfileResponse, error)
- type ProfilePayment
- type ProfileResponse
- type ProfilesAPI
- func (api ProfilesAPI) AddCard(profileId string, card CreditCard) (*ProfileResponse, error)
- func (api ProfilesAPI) AddTokenizedCard(profileId string, cardholderName string, token string) (*ProfileResponse, error)
- func (api ProfilesAPI) CreateProfile(profile Profile) (*ProfileResponse, error)
- func (api ProfilesAPI) DeleteCard(profileId string, cardId int) (*ProfileResponse, error)
- func (api ProfilesAPI) DeleteProfile(profileId string) (*ProfileResponse, error)
- func (api ProfilesAPI) GetCard(profileId string, cardId int) (*CreditCard, error)
- func (api ProfilesAPI) GetCards(profileId string) ([]CreditCard, error)
- func (api ProfilesAPI) GetProfile(profileId string) (*Profile, error)
- func (api ProfilesAPI) UpdateCard(profileId string, card CreditCard) (*ProfileResponse, error)
- func (api ProfilesAPI) UpdateProfile(profile *Profile) (*ProfileResponse, error)
- type RecordsResult
- type ReportsAPI
- type Token
- type Transaction
- type TransactionRecord
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateAuthCode ¶
func LegatoTokenizeCard ¶
Turn a credit card into a single-use token. This should not be used from a production environment. The point of using a token is to not have the credit card info go to your server, thus increasing the scope of your PCI compliance. The token should be collected on the client-side app.
func ProcessBody ¶
func ProcessMultiPart ¶
func Util_randOrderId ¶
func Util_randSeq ¶
Types ¶
type Address ¶
type Address struct { Name string `json:"name,omitempty"` AddressLine1 string `json:"address_line1,omitempty"` AddressLine2 string `json:"address_line2,omitempty"` City string `json:"city,omitempty"` Province string `json:"province,omitempty"` Country string `json:"country,omitempty"` PostalCode string `json:"postal_code,omitempty"` PhoneNumber string `json:"phone_number,omitempty"` EmailAddress string `json:"email_address,omitempty"` }
Address is either a billing or shipping address
type Adjustment ¶
type Adjustment struct { Id int `json:"id,omitempty"` Type string `json:"type,omitempty"` Approval int `json:"approval,omitempty"` Message string `json:"message,omitempty"` Amount float32 `json:"amount,omitempty"` CreatedTime time.Time Url string `json:"url,omitempty"` // contains filtered or unexported fields }
Adjustment to a payment, often a return or void.
type BatchCriteria ¶
type BeanstreamApiException ¶
type BeanstreamApiException struct { Status int Code int Category int Message string Reference string Details []ErrorDetail }
func (*BeanstreamApiException) Error ¶
func (e *BeanstreamApiException) Error() string
func (*BeanstreamApiException) ErrorType ¶
func (e *BeanstreamApiException) ErrorType() string
func (BeanstreamApiException) String ¶
func (e BeanstreamApiException) String() string
type Config ¶
type Config struct { MerchantId string PaymentsApiKey string ProfilesApiKey string ReportingApiKey string UrlPrefix string //"www" UrlApi string //"api" UrlApiVersion string //"v1" TimezoneOffset string //eg -8:00 }
Configuration for the Beanstream Gateway. To get some default values call DefaultConfig()
func DefaultConfig ¶
func DefaultConfig() Config
Create a config object with the default details. You must still supply it with your merchant ID and API keys.
type CreditCard ¶
type CreditCard struct { Name string `json:"name"` Number string `json:"number"` ExpiryMonth string `json:"expiry_month"` ExpiryYear string `json:"expiry_year"` Cvd string `json:"cvd"` Complete bool `json:"complete"` Function string `json:"function,omitempty"` Type string `json:"card_type,omitempty"` Id int `json:"card_id,string,omitempty"` AvsResult string `json:"avs_result,omitempty"` CvdResult string `json:"cvd_result,omitempty"` }
CreditCard info for making a payment. You can pre-authorize a purchase by setting Complete to false.
type Criteria ¶
type Criteria struct { Field int `json:"field,omitempty"` Operator string `json:"operator,omitempty"` Value string `json:"value,omitempty"` }
Criteria let you narrow down your search results. Each criteria is ANDed together.
The Field is the field on a transaction record that you are testing against. The Operator is one of Equals, less than, Greater than, etc... The Value is what is being compared to.
For example if you want to search for amounts less than $100 you would set the Field as: fields.Amount the operator as: operators.LessThan and the value as: "100"
type CustomFields ¶
type CustomFields struct { Ref1 string `json:"ref1,omitempty"` Ref2 string `json:"ref2,omitempty"` Ref3 string `json:"ref3,omitempty"` Ref4 string `json:"ref4,omitempty"` Ref5 string `json:"ref5,omitempty"` }
CustomFields that can be added to a transaction on creation.
type ErrorDetail ¶
type Gateway ¶
type Gateway struct {
Config Config
}
Gateway is the entry point for making payments. It stores the configuration for your merchant account, such as merchant ID and passcode, in a Config struct.
The Gateway will give you access to the 3 APIs: Payments, Profiles, and Reporting. Each time you call one of those APIs you get a new API object. It is recommended that you always call these methods if you are going to process payments in a multi-threaded environment using go routines. Do not share them across threads if possible.
func (*Gateway) Payments ¶
func (v *Gateway) Payments() PaymentsAPI
Payments returns a new beanstream.PaymentsAPI type struct with the config set.
func (*Gateway) Profiles ¶
func (v *Gateway) Profiles() ProfilesAPI
Profiles returns a new beanstream.ProfilesAPI type struct with the config set.
func (*Gateway) Reports ¶
func (v *Gateway) Reports() ReportsAPI
Reports returns a new beanstream.ReportsAPI type struct with the config set.
type Link ¶
type Link struct { Rel string `json:"rel,omitempty"` Href string `json:"href,omitempty"` Method string `json:"method,omitempty"` }
Link for http access for returns and voids. Not useful with the SDK be here none the less.
type PaymentRequest ¶
type PaymentRequest struct { PaymentMethod string `json:"payment_method"` OrderNumber string `json:"order_number,omitempty"` Amount float32 `json:"amount"` Card CreditCard `json:"card,omitempty"` Token Token `json:"token,omitempty"` Profile ProfilePayment `json:"payment_profile,omitempty"` BillingAddress Address `json:"billing,omitempty"` ShippingAddress Address `json:"shipping,omitempty"` Comment string `json:"comments,omitempty"` Language string `json:"language,omitempty"` CustomerIp string `json:"customer_ip,omitempty"` TermUrl string `json:"term_url,omitempty"` Custom CustomFields `json:"custom,omitempty"` }
PaymentRequest is the main struct for making a payment. The mandatory fields are:
PaymentMethod Ordernumber Amount
For specific types of payments you will need: Card, Token, or Profile
type PaymentResponse ¶
type PaymentResponse struct { Approved int `json:"approved,string"` AuthCode string `json:"auth_code"` Card struct { AddressMatch int `json:"address_match"` CardType string `json:"card_type"` CvdMatch int `json:"cvd_match"` LastFour string `json:"last_four"` PostalResult int `json:"postal_result"` } `json:"card"` CreatedTime time.Time ID string `json:"id"` Links []struct { Href string `json:"href"` Method string `json:"method"` Rel string `json:"rel"` } `json:"links"` Message string `json:"message"` MessageID int `json:"message_id,string"` OrderNumber string `json:"order_number"` PaymentMethod string `json:"payment_method"` Type string `json:"type"` // contains filtered or unexported fields }
PaymentResponse is the response from a successful transaction. Some fields might be empty. To check if a transaction is approved you can call the method IsApproved().
func (*PaymentResponse) IsApproved ¶
func (t *PaymentResponse) IsApproved() bool
IsApproved will test if a Payment was approved
type PaymentsAPI ¶
type PaymentsAPI struct {
Config Config
}
Through the payments API you can create payments, get payments, return payments, void payments, as well as pre-authorize and complete payments.
func (PaymentsAPI) CompletePayment ¶
func (api PaymentsAPI) CompletePayment(transId string, request PaymentRequest) (*PaymentResponse, error)
Complete a pre-authorized payment for some or all of the pre-authorized amount.
func (PaymentsAPI) GetTransaction ¶
func (api PaymentsAPI) GetTransaction(transId string) (*Transaction, error)
GetTransaction retrieves a transaction and all adjustments that were performed on it.
func (PaymentsAPI) MakePayment ¶
func (api PaymentsAPI) MakePayment(transaction PaymentRequest) (*PaymentResponse, error)
Create a payment. Either a Credit Card, Profile, Cash, or Cheque payment request. Cash and Cheque payments are just for your own record keeping. You must supply it a PaymentRequest that is defined in this package
func (PaymentsAPI) ReturnPayment ¶
func (api PaymentsAPI) ReturnPayment(transId string, amount float32) (*PaymentResponse, error)
ReturnPayment returns the money to the customer for all or some of the original amount.
func (PaymentsAPI) VoidPayment ¶
func (api PaymentsAPI) VoidPayment(transId string, amount float32) (*PaymentResponse, error)
VoidPayment cancels a payment for all of the original amount. In order to void a payment you must not wait too long. The amount must equal the original amount.
type Profile ¶
type Profile struct { Id string Card CreditCard `json:"card,omitempty"` Token Token `json:"token,omitempty"` BillingAddress Address `json:"billing,omitempty"` Custom CustomFields `json:"custom,omitempty"` Language string `json:"language,omitempty"` Comment string `json:"comment,omitempty"` LastTransaction string `json:"last_transaction,omitempty"` Status string `json:"status,omitempty"` ModifiedDate time.Time // contains filtered or unexported fields }
Profile stores the information needed to make purchases and provide a means for saving this information when a customer returns to your store.
A profile can be created with a Credit Card or a single-use Legato token (thus making the single-use token multi-use).
Profiles can have more than one card stored on them. The amount of cards has a limit that is configurable in the Beanstream backoffice control panel of your account, located under the Profiles section.
func (*Profile) AddCard ¶
func (p *Profile) AddCard(pAPI ProfilesAPI, card CreditCard) (*ProfileResponse, error)
AddCard Add a card to a profile
func (*Profile) DeleteCard ¶
func (p *Profile) DeleteCard(pAPI ProfilesAPI, cardId int) (*ProfileResponse, error)
DeleteCard Deletes a card from a profile
func (*Profile) GetCard ¶
func (p *Profile) GetCard(pAPI ProfilesAPI, cardId int) (*CreditCard, error)
GetCard Get a single card from a profile. Cards are indexed starting with id 1 (not zero)
func (*Profile) GetCards ¶
func (p *Profile) GetCards(pAPI ProfilesAPI) ([]CreditCard, error)
GetCards Retrieves all cards from a profile
func (*Profile) UpdateCard ¶
func (p *Profile) UpdateCard(pAPI ProfilesAPI, card CreditCard) (*ProfileResponse, error)
UpdateCard Updates a card stored on a profile. This will NOT update the card number. To update a card number you must remove the old card and add the new one.
type ProfilePayment ¶
type ProfilePayment struct { ProfileId string `json:"customer_code"` CardId int `json:"card_id"` Complete bool `json:"complete"` }
ProfilePayment allows you to make a payment with a Payment Profile. You need the Profile ID as well as the Card id. If there is just one card on a profile use card ID = 1 You can pre-authorize a purchase by setting Complete to false.
type ProfileResponse ¶
type ProfileResponse struct { Id string `json:"customer_code,omitempty"` Code int `json:"code,omitempty"` Message string `json:"message,omitempty"` }
ProfileResponse is the response from profile CRUD operations.
func (ProfileResponse) String ¶
func (p ProfileResponse) String() string
type ProfilesAPI ¶
type ProfilesAPI struct {
Config Config
}
ProfilesAPI lets you store customer information so it can be re-used. When you create a payment profile you receive a customer code, also known as a multi-use token. You can then use this token to make payments. Profiles have standard CRUD operations available to them as well as the ability to add more credit cards to the profile.
func (ProfilesAPI) AddCard ¶
func (api ProfilesAPI) AddCard(profileId string, card CreditCard) (*ProfileResponse, error)
AddCard Add a card to a profile
func (ProfilesAPI) AddTokenizedCard ¶
func (api ProfilesAPI) AddTokenizedCard(profileId string, cardholderName string, token string) (*ProfileResponse, error)
AddTokenizedCard Add a tokenized card to a profile
func (ProfilesAPI) CreateProfile ¶
func (api ProfilesAPI) CreateProfile(profile Profile) (*ProfileResponse, error)
CreateProfile Creates a new profile.
func (ProfilesAPI) DeleteCard ¶
func (api ProfilesAPI) DeleteCard(profileId string, cardId int) (*ProfileResponse, error)
DeleteCard Deletes a card from a profile
func (ProfilesAPI) DeleteProfile ¶
func (api ProfilesAPI) DeleteProfile(profileId string) (*ProfileResponse, error)
DeleteProfile Deletes a profile
func (ProfilesAPI) GetCard ¶
func (api ProfilesAPI) GetCard(profileId string, cardId int) (*CreditCard, error)
GetCard Gets a single card from a profile. Cards are indexed starting with id 1 (not zero)
func (ProfilesAPI) GetCards ¶
func (api ProfilesAPI) GetCards(profileId string) ([]CreditCard, error)
GetCards gets all cards on a profile
func (ProfilesAPI) GetProfile ¶
func (api ProfilesAPI) GetProfile(profileId string) (*Profile, error)
GetProfile Retrieves a profile using the profile ID. This ID is returned when you create a profile.
func (ProfilesAPI) UpdateCard ¶
func (api ProfilesAPI) UpdateCard(profileId string, card CreditCard) (*ProfileResponse, error)
UpdateCard Updates a card stored on a profile. This will NOT update the card number. To update a card number you must remove the old card and add the new one.
func (ProfilesAPI) UpdateProfile ¶
func (api ProfilesAPI) UpdateProfile(profile *Profile) (*ProfileResponse, error)
UpdateProfile Updates a profile
type RecordsResult ¶
type RecordsResult struct {
Records []TransactionRecord `json:"records,omitempty"`
}
The query result that contains an array of Transaction records
type ReportsAPI ¶
type ReportsAPI struct {
Config Config
}
The Reports API lets you search for transactions based on date ranges and search criteria.
func (ReportsAPI) Query ¶
func (api ReportsAPI) Query(startTime time.Time, endTime time.Time, startRow int, endRow int, criteria ...Criteria) ([]TransactionRecord, error)
Search/Query for transactions. Transactions must be bounded by a date range. You must also supply a startRow and an endRow to page the results as there is a limit of 1000 results returned per query. Finally you can supply zero or more search Criteria. These Criteria are ANDed together.
Criteria have 3 parameters: field, operator, and value. For details on these refer to the Criteria struct's documentation.
For paging just one row, use the values: 1, 2. Paging index starts inclusively at the first number and non-inclusively at the 2nd number: [start,end). The lowest paging index number is 1.
type Token ¶
type Token struct { Token string `json:"code"` Name string `json:"name"` Complete bool `json:"complete"` }
Token is a single-use Legato token for making a payment. You can pre-authorize a purchase by setting Complete to false.
type Transaction ¶
type Transaction struct { Id int `json:"id,omitempty"` Approved int `json:"approved,omitempty"` MessageId int `json:"message_id,omitempty"` Message string `json:"message,omitempty"` AuthCode string `json:"auth_code,omitempty"` CreatedTime time.Time OrderNumber string `json:"order_number,omitempty"` Amount float32 `json:"amount,omitempty"` Type string `json:"type,omitempty"` Comment string `json:"comments,omitempty"` BatchNumber string `json:"batch_number,omitempty"` TotalRefunds float32 `json:"total_refunds,omitempty"` TotalCompletions float32 `json:"total_completions,omitempty"` PaymentMethod string `json:"payment_method,omitempty"` Card CreditCard `json:"card,omitempty"` BillingAddress Address `json:"billing,omitempty"` ShippingAddress Address `json:"shipping,omitempty"` Custom CustomFields `json:"custom,omitempty"` Adjustments []Adjustment `json:"adjusted_by,omitempty"` Links []Link `json:"links,omitempty"` // contains filtered or unexported fields }
Transaction is the struct you receive when you call GetTransaction(). To check if a transaction is approved you can call the method IsApproved()
func (*Transaction) IsApproved ¶
func (t *Transaction) IsApproved() bool
IsApproved will test if a Payment was approved
type TransactionRecord ¶
type TransactionRecord struct { RowId int `json:"row_id,omitempty"` TransactionId int `json:"trn_id,omitempty"` DateTime time.Time Type string `json:"trn_type,omitempty"` OrderNumber string `json:"trn_order_number,omitempty"` PaymentMethod string `json:"trn_payment_method,omitempty"` Comments string `json:"trn_comments,omitempty"` MaskedCard string `json:"trn_masked_card,omitempty"` Amount float32 `json:"trn_amount,string,omitempty"` Returns float32 `json:"trn_returns,string,omitempty"` Completions float32 `json:"trn_completions,string,omitempty"` Voided int `json:"trn_voided,omitempty"` Response int `json:"trn_response,omitempty"` CardType string `json:"trn_card_type,omitempty"` BatchNumber int `json:"trn_batch_no,omitempty"` AvsResult string `json:"trn_avs_result,omitempty"` CvdResult int `json:"trn_cvd_result,omitempty"` CardExpiry string `json:"trn_card_expiry,omitempty"` MessageId int `json:"message_id,omitempty"` MessageText string `json:"message_text,omitempty"` CardOwner string `json:"trn_card_owner,omitempty"` IpAddress string `json:"trn_ip,omitempty"` ApprovalCode string `json:"trn_approval_code,omitempty"` Reference int `json:"trn_reference,omitempty"` BillingName string `json:"b_name,omitempty"` BillingEmail string `json:"b_email,omitempty"` BillingPhone string `json:"b_phone,omitempty"` BillingAddress1 string `json:"b_address1,omitempty"` BillingAddress2 string `json:"b_address2,omitempty"` BillingCity string `json:"b_city,omitempty"` BillingProvince string `json:"b_province,omitempty"` BillingPostal string `json:"b_postal,omitempty"` BillingCountry string `json:"b_country,omitempty"` ShippingName string `json:"s_name,omitempty"` ShippingEmail string `json:"s_email,omitempty"` ShippingPhone string `json:"s_phone,omitempty"` ShippingAddress1 string `json:"s_address1,omitempty"` ShippingAddress2 string `json:"s_address2,omitempty"` ShippingCity string `json:"s_city,omitempty"` ShippingProvince string `json:"s_province,omitempty"` ShippingPostal string `json:"s_postal,omitempty"` ShippingCountry string `json:"s_country,omitempty"` Ref1 string `json:"ref1,omitempty"` Ref2 string `json:"ref2,omitempty"` Ref3 string `json:"ref3,omitempty"` Ref4 string `json:"ref4,omitempty"` Ref5 string `json:"ref5,omitempty"` ProductName string `json:"product_name,omitempty"` ProductId string `json:"product_id,omitempty"` CustomerCode string `json:"customer_code,omitempty"` // contains filtered or unexported fields }
The transaction in a query RecordsResult
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
The fields that can be queried from the Reporting API.
|
The fields that can be queried from the Reporting API. |
The operators that can be used in a query for the Reporting API.
|
The operators that can be used in a query for the Reporting API. |
The different kinds of payment methods that can be performed on the Payments API.
|
The different kinds of payment methods that can be performed on the Payments API. |