Documentation ¶
Overview ¶
Package be2bill implements client access to the Be2bill merchant API defined at http://developer.be2bill.com/API.
Form Client ¶
Every initial transaction is made using a secure form. The Form Client API exposes methods that return the HTML code for payment or authorization buttons.
The first step is to build a client for the given environment, using your credentials:
client := be2bill.BuildSandboxFormClient("test", "password")
To build a payment form button, call:
button := client.BuildPaymentFormButton( be2bill.SingleAmount(15235), // amount in cents "order_1412327697", // order ID "6328_john.smith@example.org", // user ID "Fashion jacket", // order description be2bill.Options{ be2bill.HTMLOptionSubmit: be2bill.Options{ "value": "Pay with be2bill", "class": "flatButton", }, be2bill.HTMLOptionForm: be2bill.Options{"id": "myform"}, }, // HTML options for the form be2bill.Options{ be2bill.ParamClientEmail: "john.smith@example.org", be2bill.Param3DSecure: "yes", }, // additional platform options )
Authorization form buttons are created similarly, except that the method to call is `BuildAuthorizationFormButton` that takes the same parameters. An authorization must be captured using the `Capture` method of the Direct Link Client API.
Direct Link Client ¶
All operations that do not require interactive data input from the client can be made using HTTP POST calls to the be2bill servers. The Direct Link Client API is an abstraction layer for these calls.
Just like the Form Client API, the first step is to build a client for the given environment, using your credentials:
client := be2bill.BuildSandboxDirectLinkClient("test", "password")
Then, for example to capture a previously authorized transaction, call:
result, err := client.Capture( "A151621", "order_1423675675", "capture_transaction_A151621", be2bill.Options{}, )
Please note that access to the Direct Link Client API is not enabled by default. This service can only be activated by your account manager based on specific criteria. Please contact him or the support team for more information.
Index ¶
- Constants
- Variables
- func CheckHash(hasher Hasher, password string, params Options) bool
- type Amount
- type Credentials
- type DirectLinkClient
- func (p *DirectLinkClient) Authorization(cardPan, cardDate, cardCryptogram, cardFullName string, amount int, ...) (Result, error)
- func (p *DirectLinkClient) Capture(transactionID, orderID, description string, options Options) (Result, error)
- func (p *DirectLinkClient) Credit(cardPan, cardDate, cardCryptogram, cardFullName string, amount int, ...) (Result, error)
- func (p *DirectLinkClient) ExportChargebacks(startDate, endDate, destination, compression string, options Options) (Result, error)
- func (p *DirectLinkClient) ExportReconciledTransactions(date, destination, compression string, options Options) (Result, error)
- func (p *DirectLinkClient) ExportReconciliation(date, destination, compression string, options Options) (Result, error)
- func (p *DirectLinkClient) ExportTransactions(startDate, endDate, destination, compression string, options Options) (Result, error)
- func (p *DirectLinkClient) GetTransactionsByOrderID(orderIDs []string, destination, compression string) (Result, error)
- func (p *DirectLinkClient) GetTransactionsByTransactionID(transactionIDs []string, destination, compression string) (Result, error)
- func (p *DirectLinkClient) OneClickAuthorization(alias string, amount int, ...) (Result, error)
- func (p *DirectLinkClient) OneClickPayment(alias string, amount Amount, ...) (Result, error)
- func (p *DirectLinkClient) Payment(cardPan, cardDate, cardCryptogram, cardFullName string, amount Amount, ...) (Result, error)
- func (p *DirectLinkClient) RedirectForPayment(amount int, ...) (Result, error)
- func (p *DirectLinkClient) Refund(transactionID, orderID, description string, options Options) (Result, error)
- func (p *DirectLinkClient) StopNTimes(scheduleID string, options Options) (Result, error)
- func (p *DirectLinkClient) SubscriptionAuthorization(alias string, amount int, ...) (Result, error)
- func (p *DirectLinkClient) SubscriptionPayment(alias string, amount Amount, ...) (Result, error)
- type Environment
- type FormClient
- type FragmentedAmount
- type Hasher
- type Options
- type Renderer
- type Result
- type SingleAmount
Examples ¶
Constants ¶
const ( HTMLOptionForm = "FORM" HTMLOptionSubmit = "SUBMIT" )
These constants represent the available keys for the htmlOptions parameters.
const ( Param3DSecure = "3DSECURE" Param3DSecureDisplayMode = "3DSECUREDISPLAYMODE" ParamAlias = "ALIAS" ParamAliasMode = "ALIASMODE" ParamAmount = "AMOUNT" ParamAmounts = "AMOUNTS" ParamBillingAddress = "BILLINGADDRESS" ParamBillingCountry = "BILLINGCOUNTRY" ParamBillingFirstName = "BILLINGFIRSTNAME" ParamBillingLastName = "BILLINGLASTNAME" ParamBillingPhone = "BILLINGPHONE" ParamBillingPostalCode = "BILLINGPOSTALCODE" ParamCallbackURL = "CALLBACKURL" ParamCardCode = "CARDCODE" ParamCardCVV = "CARDCVV" ParamCardFullName = "CARDFULLNAME" ParamCardValidityDate = "CARDVALIDITYDATE" ParamClientAddress = "CLIENTADDRESS" ParamClientDOB = "CLIENTDOB" ParamClientEmail = "CLIENTEMAIL" ParamClientIdent = "CLIENTIDENT" ParamClientIP = "CLIENTIP" ParamClientReferrer = "CLIENTREFERRER" ParamClientUserAgent = "CLIENTUSERAGENT" ParamCompression = "COMPRESSION" ParamCreateAlias = "CREATEALIAS" ParamDate = "DATE" ParamDay = "DAY" ParamDescription = "DESCRIPTION" ParamDisplayCreateAlias = "DISPLAYCREATEALIAS" ParamEndDate = "ENDDATE" ParamExtraData = "EXTRADATA" ParamHash = "HASH" ParamHideCardFullName = "HIDECARDFULLNAME" ParamHideClientEmail = "HIDECLIENTEMAIL" ParamIdentifier = "IDENTIFIER" ParamLanguage = "LANGUAGE" ParamMailTo = "MAILTO" ParamMetadata = "METADATA" ParamOperationType = "OPERATIONTYPE" ParamOrderID = "ORDERID" ParamScheduleID = "SCHEDULEID" ParamShipToAddress = "SHIPTOADDRESS" ParamShipToCountry = "SHIPTOCOUNTRY" ParamShipToFirstName = "SHIPTOFIRSTNAME" ParamShipToLastName = "SHIPTOLASTNAME" ParamShipToPhone = "SHIPTOPHONE" ParamShipToPostalCode = "SHIPTOPOSTALCODE" ParamStartDate = "STARTDATE" ParamTimeZone = "TIMEZONE" ParamTransactionID = "TRANSACTIONID" ParamVersion = "VERSION" ParamVME = "VME" )
These constants represent the possible keys for the options parameters. See https://developer.be2bill.com/annexes/parameters for more information.
const ( OperationTypeAuthorization = "authorization" OperationTypeCapture = "capture" OperationTypeCredit = "credit" OperationTypePayment = "payment" OperationTypeRefund = "refund" OperationTypeStopNTimes = "stopntimes" OperationTypeGetTransactions = "getTransactions" OperationTypeExportTransactions = "exportTransactions" OperationTypeExportChargebacks = "exportChargebacks" OperationTypeExportReconciliation = "exportReconciliation" OperationTypeExportReconciledTransactions = "exportReconciledTransactions" )
These constants represent the operation codes supported by the be2bill API calls.
const ( CompressionZip = "ZIP" CompressionGzip = "GZIP" CompressionBzip = "BZIP" )
These constants represent the compression formats supported by the export methods.
const ( ResultParamOperationType = "OPERATIONTYPE" ResultParamTransactionID = "TRANSACTIONID" ResultParamExecCode = "EXECCODE" ResultParamMessage = "MESSAGE" ResultParamDescriptor = "DESCRIPTOR" ResultParamAmount = "AMOUNT" ResultParamRedirectHTML = "REDIRECTHTML" )
These constants represent the possible keys for the API calls' result maps.
const ( ExecCodeSuccess = "0000" ExecCode3DSecureRequired = "0001" ExecCodeAlternateRedirectRequired = "0002" ExecCodeMissingParameter = "1001" ExecCodeInvalidParameter = "1002" ExecCodeInvalidHash = "1003" ExecCodeUnsupportedProtocol = "1004" ExecCodeAliasNotFound = "2001" ExecCodeTransactionNotFound = "2002" ExecCodeUnsuccessfulTransaction = "2003" ExecCodeTransactionNotRefundable = "2004" ExecCodeAuthorizationNotCapturable = "2005" ExecCodeIncompleteTransaction = "2006" ExecCodeInvalidCaptureAmount = "2007" ExecCodeInvalidRefundAmount = "2008" ExecCodeAuthorizationTimeout = "2009" ExecCodeScheduleNotFound = "2010" ExecCodeInterruptedSchedule = "2011" ExecCodeScheduleFinished = "2012" ExecCodeAccountDeactivated = "3001" ExecCodeTransactionRefusedBank = "4001" ExecCodeUnsufficientFunds = "4002" ExecCodeCardRefused = "4003" ExecCodeTransactionAbandoned = "4004" ExecCodeSuspectedFraud = "4005" ExecCodeCardLost = "4006" ExecCodeCardStolen = "4007" ExecCode3DSecureAuthenticationFailed = "4008" ExecCode3DSecureAuthenticationTimeout = "4009" ExecCodeInvalidTransaction = "4010" ExecCodeDuplicateTransaction = "4011" ExecCodeInvalidCardData = "4012" ExecCodeTransactionNotAuthorized = "4013" ExecCodeCard3DSecureNotSupported = "4014" ExecCodeTransactionTimeout = "4015" ExecCodeTransactionRefusedByTerminal = "4016" ExecCodeExchangeProtocolError = "5001" ExecCodeBankNetworkError = "5002" ExecCodeHandlerTimeout = "5004" ExecCode3DSecureDisplayError = "5005" ExecCodeTransactionRefusedMerchant = "6001" ExecCodeTransactionRefusedUnknown = "6002" ExecCodeTransactionChallenged = "6003" ExecCodeTransactionRefusedMerchantRules = "6004" )
These constants represent the possible values for the exec code result field. See https://developer.be2bill.com/annexes/execcodes for more information.
const APIVersion = "2.0"
APIVersion represents the currently supported version of the API. It is sent to the server as part of the various API calls in order to ensure compatibility.
Variables ¶
var ( // ErrTimeout is returned by DirectClient operations if the request // encounters a timeout and cannot finish. ErrTimeout = errors.New("timeout") // ErrURLMissing is returned by DirectClient operations if the current // environment has no URL specified. ErrURLMissing = errors.New("no URL provided") // ErrServerError is returned by DirectClient operations if the request // encounters a server-side error. ErrServerError = errors.New("server error") )
Functions ¶
Types ¶
type Amount ¶
type Amount interface { // Immediate returns true if the amount is due immediately. Immediate() bool // Options returns the amount as an Options object suitable // for use as parameter for server calls. // This is only relevant if the amount is not immediate. Options() Options }
An Amount represents a sum of money as understood by the platform. Amounts are usually immediate but can also be fragmented, for example if several payments are scheduled for future dates.
type Credentials ¶
type Credentials struct {
// contains filtered or unexported fields
}
Credentials represent the information that is necessary for the clients to identify themselves to the API.
func ProductionUser ¶
func ProductionUser(identifier string, password string) *Credentials
ProductionUser returns new Credentials using the given client identifiers and the production environment.
func SandboxUser ¶
func SandboxUser(identifier string, password string) *Credentials
SandboxUser returns new Credentials using the given client identifiers and the sandbox environment.
func User ¶
func User(identifier string, password string, environment Environment) *Credentials
User returns new Credentials using the given client identifiers and environment.
type DirectLinkClient ¶
type DirectLinkClient struct { // RequestTimeout is the duration after which requests time out // and return an ErrTimeout error. // The default timeout is 30 seconds. RequestTimeout time.Duration // contains filtered or unexported fields }
A DirectLinkClient represent an access to the Direct Link Be2bill API that allows a merchant to perform direct calls to the Be2bill servers without the need for a graphical interface such as a web page. It supports a variety of operations used to perform payments, captures, or getting informations about past transactions.
func BuildProductionDirectLinkClient ¶
func BuildProductionDirectLinkClient(identifier, password string) *DirectLinkClient
BuildProductionDirectLinkClient returns a new DirectLinkClient using the given client identifier and password for the production environment.
func BuildSandboxDirectLinkClient ¶
func BuildSandboxDirectLinkClient(identifier, password string) *DirectLinkClient
BuildSandboxDirectLinkClient returns a new DirectLinkClient using the given client identifier and password for the sandbox environment.
func NewDirectLinkClient ¶
func NewDirectLinkClient(credentials *Credentials) *DirectLinkClient
NewDirectLinkClient returns a new DirectLinkClient using the given credentials.
func (*DirectLinkClient) Authorization ¶
func (p *DirectLinkClient) Authorization( cardPan, cardDate, cardCryptogram, cardFullName string, amount int, orderID, clientID, clientEmail, clientIP, description, clientUserAgent string, options Options, ) (Result, error)
Authorization performs an authorization operation using the given card holder information.
func (*DirectLinkClient) Capture ¶
func (p *DirectLinkClient) Capture(transactionID, orderID, description string, options Options) (Result, error)
Capture performs a capture operation on a previous authorization. The capture allows to collect the carholder's funds up to 7 days after the authorization has been made.
An optional amount can be specified in the options parameter. It will replace the authorized amount so the capture will be partial. Only an amount inferior to the original can be used.
See https://developer.be2bill.com/functions/capture
Example ¶
// build client client := be2bill.BuildSandboxDirectLinkClient("test", "password") result, err := client.Capture( "A151621", "order_1423675675", "capture_transaction_A151621", be2bill.Options{}, ) if err == nil { fmt.Println(result) }
Output:
func (*DirectLinkClient) Credit ¶
func (p *DirectLinkClient) Credit( cardPan, cardDate, cardCryptogram, cardFullName string, amount int, orderID, clientID, clientEmail, clientIP, description, clientUserAgent string, options Options, ) (Result, error)
Credit performs a credit operation using the given card holder information.
func (*DirectLinkClient) ExportChargebacks ¶
func (p *DirectLinkClient) ExportChargebacks(startDate, endDate, destination, compression string, options Options) (Result, error)
ExportChargebacks retrieves a list of chargebacks given a date or interval of dates, and sends the given list as a file to a destination which can be a HTTP URL or an email address. The file is compressed used the specified compression scheme, as specified in the be2bill.Compression* constants.
Dates can be specified as a month (YYYY-MM), or as a day (YYYY-MM-DD). If endDate is an empty string, transactions at startDate will be retrieved, otherwise transactions between startDate and endDate will be retrieved.
See https://developer.be2bill.com/functions/exportChargebacks
func (*DirectLinkClient) ExportReconciledTransactions ¶
func (p *DirectLinkClient) ExportReconciledTransactions(date, destination, compression string, options Options) (Result, error)
ExportReconciledTransactions retrieves the collected transactions for a given day and sends it as a file to a destination which can be a HTTP URL or an email address. The file is compressed used the specified compression scheme, as specified in the be2bill.Compression* constants.
The date can only be specified as a day (YYYY-MM-DD).
See https://developer.be2bill.com/functions/exportReconciledTransactions
func (*DirectLinkClient) ExportReconciliation ¶
func (p *DirectLinkClient) ExportReconciliation(date, destination, compression string, options Options) (Result, error)
ExportReconciliation retrieves the final reconciliation for a given a date and sends it as a file to a destination which can be a HTTP URL or an email address. The file is compressed used the specified compression scheme, as specified in the be2bill.Compression* constants.
The date can be specified as a month (YYYY-MM), or as a day (YYYY-MM-DD).
See https://developer.be2bill.com/functions/exportReconciliation
func (*DirectLinkClient) ExportTransactions ¶
func (p *DirectLinkClient) ExportTransactions(startDate, endDate, destination, compression string, options Options) (Result, error)
ExportTransactions retrieves a list of transactions given a date or interval of dates, and sends the given list as a file to a destination which can be a HTTP URL or an email address. The file is compressed used the specified compression scheme, as specified in the be2bill.Compression* constants.
Dates can be specified as a month (YYYY-MM), or as a day (YYYY-MM-DD). If endDate is an empty string, transactions at startDate will be retrieved, otherwise transactions between startDate and endDate will be retrieved.
See https://developer.be2bill.com/functions/exportTransactions
func (*DirectLinkClient) GetTransactionsByOrderID ¶
func (p *DirectLinkClient) GetTransactionsByOrderID(orderIDs []string, destination, compression string) (Result, error)
GetTransactionsByOrderID retrieves a list of transactions given a list of order identifiers, and sends the given list as a file to a destination which can be a HTTP URL or an email address. The file is compressed used the specified compression scheme, as specified in the be2bill.Compression* constants.
See https://developer.be2bill.com/functions/getTransactionsByOrderId
func (*DirectLinkClient) GetTransactionsByTransactionID ¶
func (p *DirectLinkClient) GetTransactionsByTransactionID(transactionIDs []string, destination, compression string) (Result, error)
GetTransactionsByTransactionID retrieves a list of transactions given a list of transaction identifiers, and sends the given list as a file to a destination which can be a HTTP URL or an email address. The file is compressed used the specified compression scheme, as specified in the be2bill.Compression* constants.
See https://developer.be2bill.com/functions/getTransactionsByTransactionId
func (*DirectLinkClient) OneClickAuthorization ¶
func (p *DirectLinkClient) OneClickAuthorization( alias string, amount int, orderID, clientID, clientEmail, clientIP, description, clientUserAgent string, options Options, ) (Result, error)
OneClickAuthorization performs an authorization operation for an already registered client. Card data must be present for the given client ID using an alias created in a previous payment or authorization operation. Only immediate amounts are supported for this method.
See https://developer.be2bill.com/functions/oneClickAuthorization
func (*DirectLinkClient) OneClickPayment ¶
func (p *DirectLinkClient) OneClickPayment( alias string, amount Amount, orderID, clientID, clientEmail, clientIP, description, clientUserAgent string, options Options, ) (Result, error)
OneClickPayment performs a payment operation for an already registered client. Card data must be present for the given client ID using an alias created in a previous payment or authorization operation. Immediate and fragmented amounts are supported for this method.
func (*DirectLinkClient) Payment ¶
func (p *DirectLinkClient) Payment( cardPan, cardDate, cardCryptogram, cardFullName string, amount Amount, orderID, clientID, clientEmail, clientIP, description, clientUserAgent string, options Options, ) (Result, error)
Payment performs a payment operation using the given card holder information. Immediate and fragmented amounts are supported for this method.
func (*DirectLinkClient) RedirectForPayment ¶
func (p *DirectLinkClient) RedirectForPayment( amount int, orderID, clientID, clientEmail, clientIP, description, clientUserAgent string, options Options, ) (Result, error)
RedirectForPayment returns HTML code used to to redirect the customer to an alternative payment service such as PayPal once his cart is validated. The result object contains a field named `be2bill.ResultParamRedirectHTML` representing a Base64 representation of the HTML code that must be inserted into a page to perform the redirection.
For example:
result, err := client.RedirectForPayment( 100, "order_1446456185", "6328_john.smith", "6328_john.smith@gmail.com", "123.123.123.123", "be2bill_transaction_processed_by_PayPal", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36", ); str := result.StringValue(be2bill.ResultParamRedirectHTML) htmlCode, err := base64.StdEncoding.DecodeString(str)
See https://developer.be2bill.com/functions/redirectForPayment
func (*DirectLinkClient) Refund ¶
func (p *DirectLinkClient) Refund(transactionID, orderID, description string, options Options) (Result, error)
Refund performs a refund operation over a given previous transaction. If a refund is done the same day as the initial payment, it will be a simple payment cancellation and no remote collection will be made.
func (*DirectLinkClient) StopNTimes ¶
func (p *DirectLinkClient) StopNTimes(scheduleID string, options Options) (Result, error)
StopNTimes cancels future scheduled payments when a transaction has been made using a fragmented amount. The initial transaction identifier is used as parameter.
func (*DirectLinkClient) SubscriptionAuthorization ¶
func (p *DirectLinkClient) SubscriptionAuthorization( alias string, amount int, orderID, clientID, clientEmail, clientIP, description, clientUserAgent string, options Options, ) (Result, error)
SubscriptionAuthorization performs an authorization operation for an already registered client. This is used for periodic payments like monthly billing for a continuous service. Card data must be present for the given client ID using an alias created in a previous payment or authorization operation. Only immediate amounts are supported for this method.
See https://developer.be2bill.com/functions/subscriptionAuthorization
func (*DirectLinkClient) SubscriptionPayment ¶
func (p *DirectLinkClient) SubscriptionPayment( alias string, amount Amount, orderID, clientID, clientEmail, clientIP, description, clientUserAgent string, options Options, ) (Result, error)
SubscriptionPayment performs a payment operation for an already registered client. This is used for periodic payments like monthly billing for a continuous service. Card data must be present for the given client ID using an alias created in a previous payment or authorization operation. Only immediate amounts are supported for this method.
See https://developer.be2bill.com/functions/subscriptionPayment
type Environment ¶
type Environment []string
An Environment is the set of URLs that represent a be2bill endpoint. There are currently two existing environments, production and sandbox.
The production environment is where real transactions and sales take place.
The sandbox can be used for testing and no real operations occur.
var ( // EnvProduction represents the production servers where real operations take place. EnvProduction Environment // EnvSandbox represents the testing server where operations are simulated. EnvSandbox Environment )
func (Environment) SwitchURLs ¶
func (p Environment) SwitchURLs()
SwitchURLs reverses the order of URLs defined in the environment. This is useful to test the failover URLs.
type FormClient ¶
type FormClient struct {
// contains filtered or unexported fields
}
A FormClient builds various forms to be embedded on a merchant website to use Be2bill to process payments or authorizations.
func BuildProductionFormClient ¶
func BuildProductionFormClient(identifier, password string) *FormClient
BuildProductionFormClient returns a new FormClient using the given client identifier and password for the production environment.
func BuildSandboxFormClient ¶
func BuildSandboxFormClient(identifier, password string) *FormClient
BuildSandboxFormClient returns a new FormClient using the given client identifier and password for the sandbox environment.
func NewFormClient ¶
func NewFormClient(credentials *Credentials) *FormClient
NewFormClient returns a new FormClient using the given credentials.
func (*FormClient) BuildAuthorizationFormButton ¶
func (p *FormClient) BuildAuthorizationFormButton(amount int, orderID, clientID, description string, htmlOptions, options Options) string
BuildAuthorizationFormButton returns an authorization form ready to be embedded on a merchant website.
As opposed to BuildPaymentFormButton, the amount parameter is an integer, because it can only be immediate.
See https://developer.be2bill.com/functions/buildAuthorizationFormButton.
Example (Complete) ¶
// build client client := be2bill.BuildSandboxFormClient("test", "password") // create payment button button := client.BuildAuthorizationFormButton( 15235, "order_1412327697", "6328_john.smith@example.org", "Fashion jacket", be2bill.Options{ be2bill.HTMLOptionSubmit: be2bill.Options{ "value": "Pay with be2bill", "class": "flatButton", }, be2bill.HTMLOptionForm: be2bill.Options{"id": "myform"}, }, be2bill.Options{ be2bill.ParamClientEmail: "toto@example.org", be2bill.Param3DSecure: "yes", }, ) // display the button's source code fmt.Println(button)
Output: <form method="post" action="https://secure-test.be2bill.com/front/form/process" id="myform"> <input type="hidden" name="3DSECURE" value="yes" /> <input type="hidden" name="AMOUNT" value="15235" /> <input type="hidden" name="CLIENTEMAIL" value="toto@example.org" /> <input type="hidden" name="CLIENTIDENT" value="6328_john.smith@example.org" /> <input type="hidden" name="DESCRIPTION" value="Fashion jacket" /> <input type="hidden" name="HASH" value="5c22b8f55c84b21e6e6c213b8e4ef554779f785abee2ca8361096b6b0d95a9fd" /> <input type="hidden" name="IDENTIFIER" value="test" /> <input type="hidden" name="OPERATIONTYPE" value="authorization" /> <input type="hidden" name="ORDERID" value="order_1412327697" /> <input type="hidden" name="VERSION" value="2.0" /> <input type="submit" class="flatButton" value="Pay with be2bill" /> </form>
Example (Simple) ¶
// build client client := be2bill.BuildSandboxFormClient("test", "password") // create payment button button := client.BuildAuthorizationFormButton( 15235, "order_1412327697", "6328_john.smith@example.org", "Fashion jacket", be2bill.Options{}, be2bill.Options{}, ) // display the button's source code fmt.Println(button)
Output: <form method="post" action="https://secure-test.be2bill.com/front/form/process"> <input type="hidden" name="AMOUNT" value="15235" /> <input type="hidden" name="CLIENTIDENT" value="6328_john.smith@example.org" /> <input type="hidden" name="DESCRIPTION" value="Fashion jacket" /> <input type="hidden" name="HASH" value="01ccdb73b31de50567aa699642dad2e566a9c676d74d359efb4c849c13012427" /> <input type="hidden" name="IDENTIFIER" value="test" /> <input type="hidden" name="OPERATIONTYPE" value="authorization" /> <input type="hidden" name="ORDERID" value="order_1412327697" /> <input type="hidden" name="VERSION" value="2.0" /> <input type="submit" /> </form>
func (*FormClient) BuildPaymentFormButton ¶
func (p *FormClient) BuildPaymentFormButton(amount Amount, orderID, clientID, description string, htmlOptions, options Options) string
BuildPaymentFormButton returns a payment form ready to be embedded on a merchant website.
The amount parameter can either be immediate or fragmented.
See https://developer.be2bill.com/functions/buildPaymentFormButton.
Example (Complete) ¶
// build client client := be2bill.BuildSandboxFormClient("test", "password") // create payment button button := client.BuildPaymentFormButton( be2bill.FragmentedAmount{"2010-05-14": 15235, "2012-06-04": 14723}, "order_1412327697", "6328_john.smith@example.org", "Fashion jacket", be2bill.Options{ be2bill.HTMLOptionSubmit: be2bill.Options{ "value": "Pay with be2bill", "class": "flatButton", }, be2bill.HTMLOptionForm: be2bill.Options{"id": "myform"}, }, be2bill.Options{ be2bill.ParamClientEmail: "toto@example.org", be2bill.Param3DSecure: "yes", }, ) // display the button's source code fmt.Println(button)
Output: <form method="post" action="https://secure-test.be2bill.com/front/form/process" id="myform"> <input type="hidden" name="3DSECURE" value="yes" /> <input type="hidden" name="AMOUNTS[2010-05-14]" value="15235" /> <input type="hidden" name="AMOUNTS[2012-06-04]" value="14723" /> <input type="hidden" name="CLIENTEMAIL" value="toto@example.org" /> <input type="hidden" name="CLIENTIDENT" value="6328_john.smith@example.org" /> <input type="hidden" name="DESCRIPTION" value="Fashion jacket" /> <input type="hidden" name="HASH" value="e4e3c4ab88774536108b85ccd62735bf1c1a6825a87d0fcbd7efa2ece12670e2" /> <input type="hidden" name="IDENTIFIER" value="test" /> <input type="hidden" name="OPERATIONTYPE" value="payment" /> <input type="hidden" name="ORDERID" value="order_1412327697" /> <input type="hidden" name="VERSION" value="2.0" /> <input type="submit" class="flatButton" value="Pay with be2bill" /> </form>
Example (Simple) ¶
// build client client := be2bill.BuildSandboxFormClient("test", "password") // create payment button button := client.BuildPaymentFormButton( be2bill.SingleAmount(15235), "order_1412327697", "6328_john.smith@example.org", "Fashion jacket", be2bill.Options{}, be2bill.Options{}, ) // display the button's source code fmt.Println(button)
Output: <form method="post" action="https://secure-test.be2bill.com/front/form/process"> <input type="hidden" name="AMOUNT" value="15235" /> <input type="hidden" name="CLIENTIDENT" value="6328_john.smith@example.org" /> <input type="hidden" name="DESCRIPTION" value="Fashion jacket" /> <input type="hidden" name="HASH" value="fab8f17da3e0f8315168cffc87c5cc28dbd29698c102d19e9f548bec42d16029" /> <input type="hidden" name="IDENTIFIER" value="test" /> <input type="hidden" name="OPERATIONTYPE" value="payment" /> <input type="hidden" name="ORDERID" value="order_1412327697" /> <input type="hidden" name="VERSION" value="2.0" /> <input type="submit" /> </form>
type FragmentedAmount ¶
type FragmentedAmount Options
A FragmentedAmount is a map of future dates, expressed as "YYYY-MM-DD" strings, to numeric amounts in cents. It will be typically initialized like this:
amount := be2bill.FragmentedAmount{"2016-05-14": 15235, "2016-06-14": 14723}
func (FragmentedAmount) Immediate ¶
func (FragmentedAmount) Immediate() bool
Immediate always returns false for fragmented amounts.
func (FragmentedAmount) Options ¶
func (p FragmentedAmount) Options() Options
Options returns the fragmented amount as an Options instance.
type Hasher ¶
type Hasher interface { // ComputeHash returns a hash string computed from the given password and options. ComputeHash(password string, options Options) string }
A Hasher is used to sign a request to the API.
All be2bill API requests, in the Form and DirectLink clients, are represented as a map of parameters stored in an Options object.
Before a request is sent to the Be2bill server, the parameters are hashed using your Be2bill account's password as a salt, and the resulting hash is then inserted in the parameters so any further modification of the parameters will render the request invalid.
The default Be2bill hasher uses the SHA-256 algorithm.
type Options ¶
type Options map[string]interface{}
Options is a map of name/value parameters used to represent a request to the Be2bill API.
Options are also used to pass optional parameters for various methods. Internally, all method calls will use this type so a hash can be computed to protect the request from modification.
The be2bill.Param* constants represent the names supported by the plateform. Each operation supports a different set of parameters, as described in the platform documentation.
type Renderer ¶
type Renderer interface { // Render returns a string representation for the given parameters and // options. Render(params, options Options) string }
A Renderer is used to encode a Be2bill request into an appropriate representation as a string.
This is used for example to generate the code for secure HTML forms.
type Result ¶
type Result map[string]interface{}
A Result represents the return value from a call to an operation of the DirectLink API. It is a map of key/values where keys are strings and values are generic.
See the Notification Parameters at https://developer.be2bill.com/annexes/parameters for the supported keys.
func (Result) ExecCode ¶
ExecCode returns the execution code that represents the success status of the operation.
See https://developer.be2bill.com/annexes/execcodes for a list of supported execution codes.
func (Result) Message ¶
Message returns the textual message associated with the result's execution code.
func (Result) OperationType ¶
OperationType returns the name of the operation that returned this object.
func (Result) StringValue ¶
StringValue returns the value for the given property of a Result object. The value must be of string type, otherwise an empty string is returned instead.
func (Result) TransactionID ¶
TransactionID returns the identifier of the transaction associated with the current operation.
type SingleAmount ¶
type SingleAmount int
A SingleAmount is a simple amount expressed in cents. It will be typically initialized like this:
amount := be2bill.SingleAmount(2350)
func (SingleAmount) Immediate ¶
func (SingleAmount) Immediate() bool
Immediate always returns true for single amounts.
func (SingleAmount) Options ¶
func (SingleAmount) Options() Options
Options always returns nil for single amounts.