Documentation
¶
Overview ¶
Package mango is a library for the MangoPay service v2.
MangoPay is a platform that allows to accept payments and manage e-money using wallets. See http://www.mangopay.com.
First, create an account with a unique Id to authenticate to the service:
conf, err := mango.RegisterClient("myclientid", "My Company", "contact@company.com", mango.Sandbox) if err != nil { panic(err) }
Or use existing credentials:
conf, err := mango.NewConfig("myclientid", "My Company", "contact@company.com", "passwd", "sandbox")
Then, choose an authentication mode (OAuth2.0 or Basic) to use with the service:
service, err := mango.NewMangoPay(conf, mango.OAuth)
Index ¶
- Constants
- Variables
- func AuthMethod(auth AuthMode) option
- func Verbosity(v Level) option
- type AccountType
- type AuthMode
- type BankAccount
- type BankAccountList
- type BrowserInfo
- type Card
- type CardList
- type CardRegistration
- type Config
- type Consumer
- type ConsumerList
- type DirectPayIn
- type ErrPayInFailed
- type ErrPayOutFailed
- type ErrTransferFailed
- type Event
- type EventList
- type EventType
- type ExecEnvironment
- type IBANBankAccount
- type JsonObject
- type LegalUser
- type Level
- type MangoPay
- func (m *MangoPay) BankAccount(user Consumer, id string) (*BankAccount, error)
- func (m *MangoPay) BankAccounts(user Consumer) (BankAccountList, error)
- func (m *MangoPay) Card(id string) (*Card, error)
- func (m *MangoPay) Cards(user Consumer) (CardList, error)
- func (m *MangoPay) DeactivateCard(cardId string) (*Card, error)
- func (m *MangoPay) Events() (EventList, error)
- func (m *MangoPay) LegalUser(id string) (*LegalUser, error)
- func (m *MangoPay) NaturalUser(id string) (*NaturalUser, error)
- func (m *MangoPay) NewBankAccount(user Consumer, ownerName, ownerAddress string, t AccountType) (*BankAccount, error)
- func (m *MangoPay) NewCardRegistration(user Consumer, currency string) (*CardRegistration, error)
- func (m *MangoPay) NewDirectPayIn(from, to Consumer, src *Card, dst *Wallet, amount, fees Money, ...) (*DirectPayIn, error)
- func (m *MangoPay) NewDirectPayIn3DS2(from, to Consumer, src *Card, dst *Wallet, amount, fees Money, ...) (*DirectPayIn, error)
- func (m *MangoPay) NewLegalUser(name string, email string, personType string, ...) *LegalUser
- func (m *MangoPay) NewNaturalUser(first, last string, email string, birthday int64, nationality, country string) *NaturalUser
- func (m *MangoPay) NewPayOut(author Consumer, amount Money, fees Money, from *Wallet, to *BankAccount) (*PayOut, error)
- func (m *MangoPay) NewTransfer(author Consumer, amount Money, fees Money, from, to *Wallet) (*Transfer, error)
- func (m *MangoPay) NewWallet(owners ConsumerList, desc string, currency string) (*Wallet, error)
- func (m *MangoPay) NewWebPayIn(author Consumer, amount Money, fees Money, credit *Wallet, returnUrl string, ...) (*WebPayIn, error)
- func (m *MangoPay) NewWebPayIn3DS2(author Consumer, amount Money, fees Money, credit *Wallet, returnUrl string, ...) (*WebPayIn, error)
- func (m *MangoPay) Option(opts ...option)
- func (m *MangoPay) PayIn(id string) (*WebPayIn, error)
- func (m *MangoPay) PayOut(id string) (*PayOut, error)
- func (m *MangoPay) Refund(id string) (*Refund, error)
- func (m *MangoPay) Transfer(id string) (*Transfer, error)
- func (m *MangoPay) Transfers(user Consumer) (TransferList, error)
- func (m *MangoPay) User(id string) (*User, error)
- func (m *MangoPay) Users() (UserList, error)
- func (m *MangoPay) Wallet(id string) (*Wallet, error)
- func (m *MangoPay) Wallets(user Consumer) (WalletList, error)
- type Money
- type NaturalUser
- type PayIn
- type PayOut
- type ProcessIdent
- type ProcessReply
- type Refund
- type RefundList
- type TemplateUrlOptions
- type Transfer
- type TransferList
- type User
- type UserList
- type Wallet
- type WalletList
- type WebPayIn
Constants ¶
const ( // PayIn web errors ErrUserNotRedirected = "001031" ErrUserCancelledPayment = "001031" ErrUserFillingPaymentCardDetails = "001032" ErrUserNotRedirectedPaymentSessionExpired = "001033" ErrUserLetPaymentSessionExpireWithoutPaying = "001034" // Generic transaction errors ErrUserNotCompleteTransaction = "101001" ErrTransactionCancelledByUser = "101002" )
Variables ¶
var DefaultClient = &http.Client{ Transport: &http.Transport{ TLSClientConfig: &tls.Config{MaxVersion: tls.VersionTLS12}, }, }
The default HTTP client to use with the MangoPay api.
Functions ¶
func AuthMethod ¶
func AuthMethod(auth AuthMode) option
AuthMethod sets the preferred method for authenticating against the service.
Types ¶
type AccountType ¶
type AccountType int
Bank account type.
const ( IBAN AccountType = iota GB US CA OTHER )
type AuthMode ¶
type AuthMode int
AuthMode defines authentication methods for communicating with the service.
type BankAccount ¶
type BankAccount struct { ProcessIdent Type string // IBAN, GB, US, CA or OTHER OwnerName string OwnerAddress string UserId string // Required for IBAN type IBAN string BIC string // For IBAN, OTHER AccountNumber string // For GB, US, CA, OTHER // Required for GB type SortCode string // Required for US type ABA string // Required for CA type BankName string InstitutionNumber string BranchCode string // Required for OTHER type Country string // contains filtered or unexported fields }
BankAccount is an item mainly used for pay-out bank wire request. It is used as a generic bank account container for all supported account types: IBAN, GB, US, CA or OTHER.
This way, only one structure is used to unmarshal any JSON response related to bank accounts.
See http://docs.mangopay.com/api-references/bank-accounts/
func (*BankAccount) Save ¶
func (b *BankAccount) Save() error
Save sends the HTTP query to create the bank account.
func (*BankAccount) String ¶
func (b *BankAccount) String() string
type BrowserInfo ¶
type BrowserInfo struct { AcceptHeader string `json:",omitempty"` JavaEnabled bool `json:",omitempty"` Language string `json:",omitempty"` ColorDepth int `json:",omitempty"` ScreenHeight int `json:",omitempty"` ScreenWidth int `json:",omitempty"` TimeZoneOffset int `json:",omitempty"` //modified to int else the unmarshall in the save part does not work ? originally string UserAgent string `json:",omitempty"` JavascriptEnabled bool `json:",omitempty"` }
BrowserInfo holds the filed
type Card ¶
type Card struct { ProcessIdent ExpirationDate string // MMYY Alias string // Obfuscated card number, i.e 497010XXXXXX4414 CardProvider string // CB, VISA, MASTERCARD etc. CardType string // CB_VISA_MASTERCARD Product string BankCode string Active bool Currency string // Currency accepted in the waller, i.e EUR, USD etc. Validity string // UNKNOWN, VALID, INVALID // contains filtered or unexported fields }
Card holds all credit card details.
type CardRegistration ¶
type CardRegistration struct { ProcessReply // Id of the author. UserId string // Currency of the registered card. Currency string // Key sent with the card details and the PreregistrationData. AccessKey string // This passphrase is sent with the card details and the AccessKey. PreregistrationData string // The actual URL to POST the card details, the access key and the // PreregistrationData. CardRegistrationUrl string // Part of the reply, once the card details, the AccessKey and the // PreregistrationData has been sent. CardRegistrationData string CardType string // CardId if part of the reply, once the CardRegistration has been // edited with the CardRegistrationData. CardId string // contains filtered or unexported fields }
CardRegistration is used to register a credit card.
http://docs.mangopay.com/api-references/card-registration/
func (*CardRegistration) Init ¶
func (c *CardRegistration) Init() error
Init initiates the process of getting pre-registration data and access key from MangoPay to allow a user to post his credit card info to the c.CardRegistrationUrl (which is an external banking service).
User's card details must be sent directly through an HTML form to the c.CardRegistrationUrl.
The HTML form must have the following input fields:
- "data" (hidden) equals to c.PreregistrationData
- "accessKeyRef" (hidden) equals to c.AccessKey
- "cardNumber" equals to the user's credit card number
- "cardExpirationDate" equals to the user's card expiration date (format: MMYY)
- "cardCvx" equals to user's 3-digits cvx code
- "returnURL" so we can retrieve the final registration data token
A successful call to Init() will fill in the PreregistrationData and AccessKey fields of the current CardRegistration object automatically.
func (*CardRegistration) Register ¶
func (c *CardRegistration) Register(registrationData string) error
Register effectively registers the credit card against the MangoPay service. The registrationData value is returned by the external banking service that deals with the credit card information, and is obtained by submitting an HTML form to the external banking service.
func (*CardRegistration) String ¶
func (c *CardRegistration) String() string
type Config ¶
type Config struct { ClientId string Name string Email string Passphrase string Env string // contains filtered or unexported fields }
Config hold environment credentials required for using the API.
See http://docs.mangopay.com/api-references/sandbox-credentials/
func RegisterClient ¶
func RegisterClient(clientId, name, email string, env ExecEnvironment) (*Config, error)
RegisterClient asks MangoPay to create a new client account.
type Consumer ¶
type Consumer interface { // All user's wallets Wallets() (WalletList, error) // All user's transactions Transfers() (TransferList, error) }
A Consumer is a legal or natural user with zero, one or more wallets and tranfers.
type DirectPayIn ¶
type DirectPayIn struct { PayIn SecureModeReturnUrl string CardId string DebitedWalletId string SecureModeNeeded bool SecureModeRedirectUrl string // contains filtered or unexported fields }
DirectPayIn is used to process a payment with registered (tokenized) cards.
func (*DirectPayIn) Save ¶
func (p *DirectPayIn) Save() error
Save sends an HTTP query to create a direct payIn. Upon successful creation, it may return an ErrPayInFailed error if the payment has failed.
func (*DirectPayIn) String ¶
func (p *DirectPayIn) String() string
type ErrPayInFailed ¶
type ErrPayInFailed struct {
// contains filtered or unexported fields
}
Custom error returned in case of failed payIn.
func (*ErrPayInFailed) Error ¶
func (e *ErrPayInFailed) Error() string
type ErrPayOutFailed ¶
type ErrPayOutFailed struct {
// contains filtered or unexported fields
}
Custom error returned in case of failed payOut.
func (*ErrPayOutFailed) Error ¶
func (e *ErrPayOutFailed) Error() string
type ErrTransferFailed ¶
type ErrTransferFailed struct {
// contains filtered or unexported fields
}
Custom error returned in case of failed transaction.
func (*ErrTransferFailed) Error ¶
func (e *ErrTransferFailed) Error() string
type EventType ¶
type EventType int
const ( PAYIN_NORMAL_CREATED EventType = iota PAYIN_NORMAL_SUCCEEDED PAYIN_NORMAL_FAILED PAYOUT_NORMAL_CREATED PAYOUT_NORMAL_SUCCEEDED PAYOUT_NORMAL_FAILED TRANSFER_NORMAL_CREATED TRANSFER_NORMAL_SUCCEEDED TRANSFER_NORMAL_FAILED PAYIN_REFUND_CREATED PAYIN_REFUND_SUCCEEDED PAYIN_REFUND_FAILED PAYOUT_REFUND_CREATED PAYOUT_REFUND_SUCCEEDED PAYOUT_REFUND_FAILED TRANSFER_REFUND_CREATED TRANSFER_REFUND_SUCCEEDED TRANSFER_REFUND_FAILED )
type ExecEnvironment ¶
type ExecEnvironment int
Request execution environment (production or sandbox).
const ( Production ExecEnvironment = iota Sandbox )
type IBANBankAccount ¶
type IBANBankAccount struct { }
type LegalUser ¶
type LegalUser struct { User Name string LegalPersonType string HeadquartersAddress string LegalRepresentativeFirstName string LegalRepresentativeLastName string LegalRepresentativeAddress string LegalRepresentativeEmail string LegalRepresentativeBirthday int64 LegalRepresentativeNationality string LegalRepresentativeCountryOfResidence string Statute string ProofOfRegistration string // contains filtered or unexported fields }
LegalUser describes all the properties of a MangoPay legal user object.
func (*LegalUser) Save ¶
Save creates or updates a legal user. The Create API is used if the user's Id is an empty string. The Edit API is used when the Id is a non-empty string.
func (*LegalUser) Transfers ¶
func (u *LegalUser) Transfers() (TransferList, error)
Transfer gets all user's transaction.
func (*LegalUser) Wallets ¶
func (u *LegalUser) Wallets() (WalletList, error)
Wallets returns user's wallets.
type MangoPay ¶
type MangoPay struct {
// contains filtered or unexported fields
}
The Mangopay service.
func NewMangoPay ¶
NewMangoPay creates a suitable environment for accessing the web service. Default verbosity level is set to Info, which can be changed through the use of Option().
func (*MangoPay) BankAccount ¶
func (m *MangoPay) BankAccount(user Consumer, id string) (*BankAccount, error)
BankAccount returns a user's bank account.
func (*MangoPay) BankAccounts ¶
func (m *MangoPay) BankAccounts(user Consumer) (BankAccountList, error)
BankAccounts finds all user's bank accounts.
func (*MangoPay) DeactivateCard ¶
Save creates or updates a legal user. The Create API is used if the user's Id is an empty string. The Edit API is used when the Id is a non-empty string.
func (*MangoPay) Events ¶
Events returns a list of all financial events. This include PayIns, PayOuts and transfers.
TODO: add support for pagination and date range.
func (*MangoPay) NaturalUser ¶
func (m *MangoPay) NaturalUser(id string) (*NaturalUser, error)
NaturalUser finds a natural user using the user_id attribute.
func (*MangoPay) NewBankAccount ¶
func (m *MangoPay) NewBankAccount(user Consumer, ownerName, ownerAddress string, t AccountType) (*BankAccount, error)
NewBankAccount creates a new bank account. Note that depending on the account's type, some fields of the newly BankAccount instance must be filled (they are required) before a call to Save().
func (*MangoPay) NewCardRegistration ¶
func (m *MangoPay) NewCardRegistration(user Consumer, currency string) (*CardRegistration, error)
NewCardRegistration creates a new credit card registration object that can be used to register a new credit card for a given user.
Registering a new credit card involves the following workflow:
- Create a new CardRegistration object
- Call .Init() to pre-register the card against MangoPay services and get access tokens required to register the credit card againts an external banking service
- Insert those tokens in an HTML form submitted by the user directly to the external banking service
- Get the final token from the external banking service
- Call .Register() with this token to commit credit card registration at MangoPay
See http://docs.mangopay.com/api-references/card-registration/
Example:
user := NewNaturalUser(...) cr, err := NewCardRegistration(user, "EUR") if err != nil { log.Fatal(err) } if err := cr.Init(); err != nil { log.Fatal(err) }}
Now render an HTML form for user card details (see Init()). Once submitted, you get the final token as a string starting with "data=". Use this token to finally register the card:
if err := cr.Register(token); err != nil { log.Fatal(err) }}
func (*MangoPay) NewDirectPayIn ¶
func (m *MangoPay) NewDirectPayIn(from, to Consumer, src *Card, dst *Wallet, amount, fees Money, returnUrl string) (*DirectPayIn, error)
NewDirectPayIn creates a direct payment from a tokenized credit card.
- from : AuthorId value
- to : CreditedUserId value
- src : CardId value
- dst : CreditedWalletId value
- amount : DebitedFunds value
- fees : Fees value
- returnUrl: SecureModeReturnUrl value
See http://docs.mangopay.com/api-references/payins/payindirectcard/
func (*MangoPay) NewDirectPayIn3DS2 ¶
func (m *MangoPay) NewDirectPayIn3DS2(from, to Consumer, src *Card, dst *Wallet, amount, fees Money, returnUrl string, secureMode string, ipAddress string, browserInfo *BrowserInfo) (*DirectPayIn, error)
NewDirectPayIn3DS2 creates a direct payment from a tokenized credit card.
- from : AuthorId value
- to : CreditedUserId value
- src : CardId value
- dst : CreditedWalletId value
- amount : DebitedFunds value
- fees : Fees value
- returnUrl: SecureModeReturnUrl value
- secureMode: SecureMode value
- ipAddress : Ip Address of user
- browserInfo : User's browser info
See http://docs.mangopay.com/api-references/payins/payindirectcard/
func (*MangoPay) NewLegalUser ¶
func (m *MangoPay) NewLegalUser(name string, email string, personType string, legalFirstName, legalLastName string, birthday int64, nationality string, country string) *LegalUser
NewLegalUser creates a new legal user.
func (*MangoPay) NewNaturalUser ¶
func (m *MangoPay) NewNaturalUser(first, last string, email string, birthday int64, nationality, country string) *NaturalUser
NewNaturalUser creates a new natural user.
func (*MangoPay) NewPayOut ¶
func (m *MangoPay) NewPayOut(author Consumer, amount Money, fees Money, from *Wallet, to *BankAccount) (*PayOut, error)
NewPayOut creates a new bank wire.
func (*MangoPay) NewTransfer ¶
func (m *MangoPay) NewTransfer(author Consumer, amount Money, fees Money, from, to *Wallet) (*Transfer, error)
NewTransfer creates a new tranfer (or transaction).
func (*MangoPay) NewWallet ¶
NewWallet creates a new wallet. Owners must have a well-defined Id. Empty Ids will return an error.
func (*MangoPay) NewWebPayIn ¶
func (m *MangoPay) NewWebPayIn(author Consumer, amount Money, fees Money, credit *Wallet, returnUrl string, culture string, templateUrl *TemplateUrlOptions) (*WebPayIn, error)
NewWebPayIn creates a new payment.
func (*MangoPay) NewWebPayIn3DS2 ¶
func (m *MangoPay) NewWebPayIn3DS2(author Consumer, amount Money, fees Money, credit *Wallet, returnUrl string, culture string, templateUrl *TemplateUrlOptions, secureMode string) (*WebPayIn, error)
NewWebPayIn3DS2 creates a new payment.
func (*MangoPay) Option ¶
func (m *MangoPay) Option(opts ...option)
Option set various options like verbosity etc.
func (*MangoPay) Transfers ¶
func (m *MangoPay) Transfers(user Consumer) (TransferList, error)
Transfer finds all user's transactions. Provided for convenience.
type NaturalUser ¶
type NaturalUser struct { User FirstName, LastName string Address string Birthday int64 Nationality string CountryOfResidence string Occupation string IncomeRange string ProofOfIdentity string ProofOfAddress string // contains filtered or unexported fields }
NaturalUser describes all the properties of a MangoPay natural user object.
func (*NaturalUser) Save ¶
func (u *NaturalUser) Save() error
Save creates or updates a natural user. The Create API is used if the user's Id is an empty string. The Edit API is used when the Id is a non-empty string.
func (*NaturalUser) String ¶
func (u *NaturalUser) String() string
func (*NaturalUser) Transfers ¶
func (u *NaturalUser) Transfers() (TransferList, error)
Transfer gets all user's transaction.
func (*NaturalUser) Wallets ¶
func (u *NaturalUser) Wallets() (WalletList, error)
Wallets returns user's wallets.
type PayIn ¶
type PayIn struct { ProcessReply AuthorId string CreditedUserId string DebitedFunds Money Fees Money CreditedWalletId string SecureMode string CreditedFunds Money Type string // PAY_IN, PAY_OUT or TRANSFER Nature string // REGULAR, REFUND or REPUDIATION PaymentType string ExecutionType string // WEB or DIRECT (with tokenized card) IpAddress string `json:",omitempty"` BrowserInfo *BrowserInfo `json:",omitempty"` // contains filtered or unexported fields }
PayIn holds common fields to all MangoPay's supported payment means (through web, direct, preauthorized, bank wire).
func (*PayIn) CancelledByUser ¶
Cancelled returns true if the payment has been cancelled by user.
type PayOut ¶
type PayOut struct { ProcessReply AuthorId string CreditedUserId string DebitedFunds Money Fees Money Type string // PAY_IN, PAY_OUT or TRANSFER Nature string // REGULAR, REFUND or REPUDIATION PaymentType string DebitedWalletId string BankAccountId string CreditedFunds Money MeanOfPaymentType string // contains filtered or unexported fields }
A PayOut Bank wire is a request to withdraw money from a wallet to a registered bank account.
See http://docs.mangopay.com/api-references/pay-out-bank-wire/
type ProcessIdent ¶
ProcessIdent identifies the current operation.
type ProcessReply ¶
type ProcessReply struct { ProcessIdent Status string ResultCode string ResultMessage string ExecutionDate int64 }
ProcessReply holds commong fields part of MangoPay API replies.
type Refund ¶
type Refund struct { ProcessReply AuthorId string DebitedFunds Money Fees Money CreditedFunds Money Type string // PAY_IN, PAY_OUT or TRANSFER Nature string CreditedUserId string InitialTransactionId string InitialTransactionType string DebitedWalletId string CreditedWalletId string // contains filtered or unexported fields }
A refund is a request to pay a wallet back.
http://docs.mangopay.com/api-references/refund/%E2%80%A2-refund-a-transfer/
type TemplateUrlOptions ¶
type TemplateUrlOptions struct {
Payline string `json:"PAYLINE"`
}
type Transfer ¶
type Transfer struct { ProcessReply AuthorId string CreditedUserId string DebitedFunds Money Fees Money DebitedWalletId string CreditedWalletId string CreditedFunds Money // contains filtered or unexported fields }
Transfer hold details about relocating e-money from a wallet to another one.
type User ¶
type User struct { ProcessIdent PersonType string Email string }
User is used by the user activity API and describe common fields to both natural and legal users.
type Wallet ¶
type Wallet struct { ProcessIdent Owners []string Description string Currency string Balance Money // contains filtered or unexported fields }
Wallet stores all payins and tranfers from users in order to collect money.
func (*Wallet) Save ¶
Save creates or updates a legal user. The Create API is used if the user's Id is an empty string. The Edit API is used when the Id is a non-empty string.
func (*Wallet) Transactions ¶
func (w *Wallet) Transactions() (TransferList, error)
Transactions returns a wallet's transactions.
type WebPayIn ¶
type WebPayIn struct { PayIn ReturnUrl string TemplateURLOptions *TemplateUrlOptions `json:",omitempty"` TemplateURL string `json:",omitempty"` Culture string CardType string RedirectUrl string // contains filtered or unexported fields }
WebPayIn hold details about making a payment through a web interface.
See http://docs.mangopay.com/api-references/payins/payins-card-web/