mango

package module
v0.0.0-...-1f5bbe7 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: MIT Imports: 13 Imported by: 0

README

mangopay logo

GoDoc

Purpose

This project is a Go implementation of the MangoPay HTTP REST api version 2.

Installation

Use the api with

$ go get github.com/gotsunami/mangopay2-go-sdk

A command line tool is also available for testing the MangoPay service easily:

$ go get github.com/gotsunami/mangopay2-go-sdk/mangopay

Before using it, you must fill a JSON config file with your client credentials (get your sandbox environment credentials):

{
    "ClientId":"myclientid",
    "Name":"Your company name",
    "Email":"contact@company.com",
    "Passphrase":"AlOnGpAsSpHrAsE",
    "Env":"sandbox"
}

Now run mangopay from a terminal to get the list of supported actions:

Usage: ./mangopay [options] action configfile
 
where action is one of: 
  conf              show config
  events            list all events (PayIns, PayOuts, Transfers)
  users             list all users
  user*             fetch a user (natural or legal)

  addnatuser*       create a natural user
  editnatuser*      update natural user info
  natuser*          fetch natural user info

  addlegaluser*     create a legal user
  editlegaluser*    update legal user info
  legaluser*        fetch legal user info

  addwallet*        create a new wallet
  editwallet*       update wallet info
  trwallet*         fetch all wallet's transactions
  wallet*           fetch wallet info
  wallets*          list all user's wallet

  addtransfer*      create a new tranfer
  transfer*         fetch transfer info
  transfers*        list all user's transactions

  addwebpayin*      create a payIn through web interface
  adddirectpayin*   create a direct payIn (with tokenized card)
  payin*            fetch a payIn

  addcard*          register a credit card
  card*             fetch a credit card
  cards*            list all user's cards

  addrefund*        refund a payment (provide TransferId or PayInId)
  refund*           fetch a refund (transfer or payin)

  addaccount*       create an IBAN bank account
  account*          fetch a user's bank account
  accounts*         list all user's bank accounts

  addpayout*        create a bank wire
  payout*           fetch a bank wire

Actions with an asterisk(*) require input JSON data (-d).

Options:
  -d="": JSON data part of the HTTP request
  -v=0: Verbosity level (1 for debug)

API Docs

The API is available on GoDoc.

License

MIT, see LICENSE.

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

View Source
const (
	// PayIn web errors
	ErrUserNotRedirected                        = "001031"
	ErrUserCancelledPayment                     = "001031"
	ErrUserFillingPaymentCardDetails            = "001032"
	ErrUserNotRedirectedPaymentSessionExpired   = "001033"
	ErrUserLetPaymentSessionExpireWithoutPaying = "001034"

	// Generic transaction errors
	ErrUserNotCompleteTransaction = "101001"
	ErrTransactionCancelledByUser = "101002"
	ErrTransactionAmountTooHigh   = "001011"

	// 3DSecure errors
	Err3DSNotAvailable         = "101399"
	Err3DSSessionExpired       = "101304"
	Err3DSCardNotCompatible    = "101303"
	Err3DSCardNotEnrolled      = "101302"
	Err3DSAuthenticationFailed = "101301"
)
View Source
const (
	EventPayinNormalCreated             EventType = "PAYIN_NORMAL_CREATED"
	EventPayinNormalSucceeded                     = "PAYIN_NORMAL_SUCCEEDED"
	EventPayinNormalFailed                        = "PAYIN_NORMAL_FAILED"
	EventPayoutNormalCreated                      = "PAYOUT_NORMAL_CREATED"
	EventPayoutNormalSucceeded                    = "PAYOUT_NORMAL_SUCCEEDED"
	EventPayoutNormalFailed                       = "PAYOUT_NORMAL_FAILED"
	EventTransferNormalCreated                    = "TRANSFER_NORMAL_CREATED"
	EventTransferNormalSucceeded                  = "TRANSFER_NORMAL_SUCCEEDED"
	EventTransferNormalFailed                     = "TRANSFER_NORMAL_FAILED"
	EventPayinRefundCreated                       = "PAYIN_REFUND_CREATED"
	EventPayinRefundSucceeded                     = "PAYIN_REFUND_SUCCEEDED"
	EventPayinRefundFailed                        = "PAYIN_REFUND_FAILED"
	EventPayoutRefundCreated                      = "PAYOUT_REFUND_CREATED"
	EventPayoutRefundSucceeded                    = "PAYOUT_REFUND_SUCCEEDED"
	EventPayoutRefundFailed                       = "PAYOUT_REFUND_FAILED"
	EventTransferRefundCreated                    = "TRANSFER_REFUND_CREATED"
	EventTransferRefundSucceeded                  = "TRANSFER_REFUND_SUCCEEDED"
	EventTransferRefundFailed                     = "TRANSFER_REFUND_FAILED"
	EventPayinRepudiationCreated                  = "PAYIN_REPUDIATION_CREATED"
	EventPayinRepudiationSucceeded                = "PAYIN_REPUDIATION_SUCCEEDED"
	EventPayinRepudiationFailed                   = "PAYIN_REPUDIATION_FAILED"
	EventKycCreated                               = "KYC_CREATED"
	EventKycSucceeded                             = "KYC_SUCCEEDED"
	EventKycFailed                                = "KYC_FAILED"
	EventKycValidationAsked                       = "KYC_VALIDATION_ASKED"
	EventDisputeDocumentCreated                   = "DISPUTE_DOCUMENT_CREATED"
	EventDisputeDocumentValidationAsked           = "DISPUTE_DOCUMENT_VALIDATION_ASKED"
	EventDisputeDocumentSucceeded                 = "DISPUTE_DOCUMENT_SUCCEEDED"
	EventDisputeDocumentFailed                    = "DISPUTE_DOCUMENT_FAILED"
	EventDisputeCreated                           = "DISPUTE_CREATED"
	EventDisputeSubmitted                         = "DISPUTE_SUBMITTED"
	EventDisputeActionRequired                    = "DISPUTE_ACTION_REQUIRED"
	EventDisputeFurtherActionRequired             = "DISPUTE_FURTHER_ACTION_REQUIRED"
	EventDisputeClosed                            = "DISPUTE_CLOSED"
	EventDisputeSentToBank                        = "DISPUTE_SENT_TO_BANK"
	EventTransferSettlementCreated                = "TRANSFER_SETTLEMENT_CREATED"
	EventTransferSettlementSucceeded              = "TRANSFER_SETTLEMENT_SUCCEEDED"
	EventTransferSettlementFailed                 = "TRANSFER_SETTLEMENT_FAILED"
	EventMandateCreated                           = "MANDATE_CREATED"
	EventMandatedFailed                           = "MANDATED_FAILED"
	EventMandateActivated                         = "MANDATE_ACTIVATED"
	EventMandateSubmitted                         = "MANDATE_SUBMITTED"
)
View Source
const (
	TransactionNatureRegular     = "REGULAR"
	TransactionNatureRepudiation = "REPUDIATION"
	TransactionNatureRefund      = "REFUND"
	TransactionNature            = "SETTLEMENT"
)
View Source
const (
	TransactionStatusCreated   = "CREATED"
	TransactionStatusSucceeded = "SUCCEEDED"
	TransactionStatusFailed    = "FAILED"
)
View Source
const (
	TransactionTypePayIn    = "PAYIN"
	TransactionTypeTransfer = "TRANSFER"
	TransactionTypePayOut   = "PAYOUT"
)
View Source
const (
	PayInPaymentTypeCard          = "CARD"
	PayInPaymentTypeDirectDebit   = "DIRECT_DEBIT"
	PayInPaymentTypePreauthorized = "PREAUTHORIZED"
	PayInPaymentTypeBankWire      = "BANK_WIRE"
)
View Source
const (
	PayInExecutionTypeWeb    = "WEB"
	PayInExecutionTypeDirect = "DIRECT"
)
View Source
const (
	CardTypeCBVisaMasterCard = "CB_VISA_MASTERCARD"
	CardTypeAmex             = "AMEX"
	CardTypeDiners           = "DINERS"
	CardTypeMasterPass       = "MASTERPASS"
	CardTypeMaestro          = "MAESTRO"
	CardTypeP24              = "P24"
	CardTypeIdeal            = "IDEAL"
	CardTypeBcMC             = "BCMC"
	CardTypePaylib           = "PAYLIB"
)
View Source
const (
	SecureModeDefault = "DEFAULT"
	SecureModeForce   = "FORCE"
)
View Source
const (
	DirectDebitTypeSofort  = "SOFORT"
	DirectDebitTypeELV     = "ELV"
	DirectDebitTypeGiroPay = "GIROPAY"
)
View Source
const (
	RefundReasonInitializedByClient                   = "INITIALIZED_BY_CLIENT"
	RefundReasonBankaccountIncorrect                  = "BANKACCOUNT_INCORRECT"
	RefundReasonOwnerDoNotMatchBankaccount            = "OWNER_DOT_NOT_MATCH_BANKACCOUNT"
	RefundReasonBankaccountHasBeenClosed              = "BANKACCOUNT_HAS_BEEN_CLOSED"
	RefundReasonWithdrawalImpossibleOnSavingsAccounts = "WITHDRAWAL_IMPOSSIBLE_ON_SAVINGS_ACCOUNTS"
	RefundReasonOther                                 = "OTHER"
)
View Source
const (
	KYCLevelLight   = "LIGHT"
	KYCLevelRegular = "REGULAR"
)
View Source
const (
	PersonTypeNatural = "NATURAL"
	PersonTypeLegal   = "LEGAL"
)
View Source
const (
	FundsTypeDefault = "DEFAULT"
	FundsTypeFees    = "FEES"
	FundsTypeCreadit = "CREDIT"
)
View Source
const PayinFailedAmountTooHigh = "Transaction amount is higher than maximum permitted amount"

PayinFailedAmountTooHigh is ErrPayInFailed.Msg value when transaction amount is too high.

Variables

View Source
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.

func NewDefaultHTTPClientRetryWrap

func NewDefaultHTTPClientRetryWrap(client httpClient) *httpClientRetryWrap

func Verbosity

func Verbosity(v Level) option

Sets verbosity level. Default verbosity level is Info.

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.

const (
	// Basic Access Authentication
	BasicAuth AuthMode = iota
	// OAuth 2.0, token based authentication
	OAuth
)

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 BankAccountList

type BankAccountList []*BankAccount

List of bank accounts.

type BankingAlias

type BankingAlias struct {
	ProcessIdent

	CreditedUserId string
	WalletId       string
	Type           string // IBAN
	Country        string
	OwnerName      string
	Active         bool
	IBAN           string
	BIC            string
	// contains filtered or unexported fields
}

func (*BankingAlias) Save

func (b *BankingAlias) Save() error

Save sends the HTTP query to create the bank alias.

type BankingAliasList

type BankingAliasList []*BankingAlias

List of banking aliases.

type BankwireDirectPayIn

type BankwireDirectPayIn struct {
	PayIn
	DeclaredDebitedFunds Money
	DeclaredFees         Money
	WireReference        string            `json:",omitempty"`
	BankAccount          map[string]string `json:",omitempty"`
}

func (*BankwireDirectPayIn) Save

func (t *BankwireDirectPayIn) Save() error

func (*BankwireDirectPayIn) String

func (p *BankwireDirectPayIn) String() string

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
}

Card holds all credit card details.

func (*Card) String

func (c *Card) String() string

type CardList

type CardList []*Card

List of cards.

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 NewConfig

func NewConfig(clientId, name, email, passwd, env string) (*Config, error)

NewConfig creates a config suitable for NewMangoPay().

func RegisterClient

func RegisterClient(clientId, name, email string, env ExecEnvironment) (*Config, error)

RegisterClient asks MangoPay to create a new client account.

func (*Config) String

func (c *Config) String() string

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 ConsumerList

type ConsumerList []Consumer

List of wallet's owners.

type DirectDebitWebPayIn

type DirectDebitWebPayIn struct {
	PayIn
	RedirectURL        string `json:,omitempty`
	ReturnURL          string
	DirectDebitType    string
	Culture            string
	TemplateURLOptions *TemplateUrlOptions `json:",omitempty"`
	TemplateURL        string              `json:",omitempty"`
}

func (*DirectDebitWebPayIn) Save

func (t *DirectDebitWebPayIn) Save() error

func (*DirectDebitWebPayIn) String

func (p *DirectDebitWebPayIn) String() string

type DirectPayIn

type DirectPayIn struct {
	PayIn
	SecureModeReturnUrl   string
	SecureModeRedirectURL string
	CardId                string
	DebitedWalletId       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 Document

type Document struct {
	ProcessIdent
	UserId               string
	Status               DocumentStatus
	Type                 DocumentType
	RefusedReasonMessage string
	RefusedReasonType    DocumentRefusedReasonType
	// contains filtered or unexported fields
}

func (*Document) CreatePage

func (d *Document) CreatePage(file []byte) error

func (*Document) Submit

func (d *Document) Submit(status DocumentStatus, tag string) error

type DocumentList

type DocumentList []*Document

type DocumentRefusedReasonType

type DocumentRefusedReasonType string
const (
	DocumentRefusedReasonTypeUnreadable          DocumentRefusedReasonType = "DOCUMENT_UNREADABLE"
	DocumentRefusedReasonTypeNotAccepted         DocumentRefusedReasonType = "DOCUMENT_NOT_ACCEPTED"
	DocumentRefusedReasonTypeHasExpired          DocumentRefusedReasonType = "DOCUMENT_HAS_EXPIRED"
	DocumentRefusedReasonTypeIncomplete          DocumentRefusedReasonType = "DOCUMENT_INCOMPLETE"
	DocumentRefusedReasonTypeNotMatchUserData    DocumentRefusedReasonType = "DOCUMENT_DO_NOT_MATCH_USER_DATA"
	DocumentRefusedReasonTypeNotMatchAccountData DocumentRefusedReasonType = "DOCUMENT_DO_NOT_MATCH_ACCOUNT_DATA"
	DocumentRefusedReasonTypeFalsified           DocumentRefusedReasonType = "DOCUMENT_FALSIFIED"
	DocumentRefusedReasonTypeUnderagePerson      DocumentRefusedReasonType = "UNDERAGE PERSON"
	DocumentRefusedReasonTypeSpecificCase        DocumentRefusedReasonType = "SPECIFIC_CASE"
)

type DocumentStatus

type DocumentStatus string
const (
	DocumentStatusCreated         DocumentStatus = "CREATED"
	DocumentStatusValidationAsked DocumentStatus = "VALIDATION_ASKED"
	DocumentStatusValidated       DocumentStatus = "VALIDATED"
	DocumentStatusRefused         DocumentStatus = "REFUSED"
)

type DocumentType

type DocumentType string
const (
	IdentityProof          DocumentType = "IDENTITY_PROOF"
	RegistrationProof      DocumentType = "REGISTRATION_PROOF"
	ArticlesOfAssociation  DocumentType = "ARTICLES_OF_ASSOCIATION"
	ShareholderDeclaration DocumentType = "SHAREHOLDER_DECLARATION"
	AddressProof           DocumentType = "ADDRESS_PROOF"
)

type ErrPayInFailed

type ErrPayInFailed struct {
	ID   string
	Msg  string
	Code string
}

ErrPayInFailed is 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 Event

type Event struct {
	ResourceId string    `json:"RessourceId"` // ReSSource - Mistake in MangoPay API
	Type       EventType `json:"EventType"`
	Date       time.Time
}

An event ressource.

func NewEventFromRequest

func NewEventFromRequest(req *http.Request) (*Event, error)

type EventList

type EventList []Event

type EventType

type EventType string

type ExecEnvironment

type ExecEnvironment int

Request execution environment (production or sandbox).

const (
	Production ExecEnvironment = iota
	Sandbox
)

type HTTPError

type HTTPError struct {
	Code    int
	Message string
	Details map[string]interface{}
}

func (HTTPError) Error

func (e HTTPError) Error() string

type Hook

type Hook struct {
	ProcessIdent
	Url       string
	EventType EventType
	Status    string
	Validity  string
	// contains filtered or unexported fields
}

func (*Hook) Save

func (h *Hook) Save() error

func (*Hook) String

func (h *Hook) String() string

type HookList

type HookList []*Hook

type IBANBankAccount

type IBANBankAccount struct {
}

type JsonObject

type JsonObject map[string]interface{}

JsonObject is used to manage JSON data.

type LegalUser

type LegalUser struct {
	User
	Name                                  string
	LegalPersonType                       string
	UserCategory                          string
	HeadquartersAddress                   string
	LegalRepresentativeFirstName          string
	LegalRepresentativeLastName           string
	LegalRepresentativeAddress            string
	LegalRepresentativeEmail              string
	LegalRepresentativeBirthday           int64
	LegalRepresentativeNationality        string
	LegalRepresentativeCountryOfResidence string
	Statute                               string
	ProofOfRegistration                   string
	ShareholderDeclaration                string
	CompanyNumber                         string
	TermsAndConditionsAccepted            bool
	// contains filtered or unexported fields
}

LegalUser describes all the properties of a MangoPay legal user object.

func (*LegalUser) Save

func (u *LegalUser) Save() error

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) String

func (u *LegalUser) String() 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 Level

type Level int
const (
	Info Level = iota
	Debug
)

type MangoPay

type MangoPay struct {
	// contains filtered or unexported fields
}

The Mangopay service.

func NewMangoPay

func NewMangoPay(auth *Config, mode AuthMode) (*MangoPay, error)

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) BankingAlias

func (m *MangoPay) BankingAlias(id string) (*BankingAlias, error)

BankingAlias returns a user's banking alias.

func (*MangoPay) BankingAliases

func (m *MangoPay) BankingAliases(wallet Wallet) (BankAccountList, error)

BankingAliases finds all user's bank aliases.

func (*MangoPay) Card

func (m *MangoPay) Card(id string) (*Card, error)

Card fetches a registered credit card.

func (*MangoPay) Cards

func (m *MangoPay) Cards(user Consumer) (CardList, error)

Card finds all user's cards.

func (*MangoPay) Document

func (m *MangoPay) Document(id string) (*Document, error)

func (*MangoPay) Documents

func (m *MangoPay) Documents(user Consumer) (DocumentList, error)

func (*MangoPay) Events

func (m *MangoPay) Events() (EventList, error)

Events returns a list of all financial events. This include PayIns, PayOuts and transfers.

TODO: add support for pagination and date range.

func (*MangoPay) Hook

func (m *MangoPay) Hook(id string) (*Hook, error)

func (*MangoPay) HookByEventType

func (m *MangoPay) HookByEventType(eventType EventType) (*Hook, error)

HookByEventType returns the only hook for given event type. see https://docs.mangopay.com/endpoints/v2.01/hooks#e247_create-a-hook

func (*MangoPay) Hooks

func (m *MangoPay) Hooks() (HookList, error)

func (*MangoPay) LegalUser

func (m *MangoPay) LegalUser(id string) (*LegalUser, error)

LegalUser finds a legal user using the user_id attribute.

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().

See http://docs.mangopay.com/api-references/bank-accounts/

func (*MangoPay) NewBankingAlias

func (m *MangoPay) NewBankingAlias(wallet Wallet, ownerName string, country string) (*BankingAlias, error)

NewBankingAlias creates a new banking alias.

See https://docs.mangopay.com/endpoints/v2.01/banking-aliases

func (*MangoPay) NewBankwireDirectPayIn

func (m *MangoPay) NewBankwireDirectPayIn(author Consumer, credited *Wallet, amount, fees Money) (*BankwireDirectPayIn, error)

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:

  1. Create a new CardRegistration object
  2. 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
  3. Insert those tokens in an HTML form submitted by the user directly to the external banking service
  4. Get the final token from the external banking service
  5. 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) NewDirectDebitWebPayIn

func (m *MangoPay) NewDirectDebitWebPayIn(author Consumer, credited *Wallet, amount, fees Money, returnURL, directDebitType, culture string) (*DirectDebitWebPayIn, error)

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 (optional, defaults to dst owner)
  • 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) NewDocument

func (m *MangoPay) NewDocument(user Consumer, docType DocumentType, tag string) (*Document, error)

func (*MangoPay) NewHook

func (m *MangoPay) NewHook(eventType EventType, url string) (*Hook, error)

func (*MangoPay) NewLegalUser

func (m *MangoPay) NewLegalUser(name string, email string, userCategory string, address string, companyNumber string, personType string, legalFirstName string, legalLastName string, birthday int64, nationality string, country string, terms bool) *LegalUser

NewLegalUser creates a new legal user.

func (*MangoPay) NewNaturalUser

func (m *MangoPay) NewNaturalUser(first, last string, email string, userCategory string, birthday int64, nationality, country string, terms bool) *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

func (m *MangoPay) NewWallet(owners ConsumerList, desc string, currency string) (*Wallet, error)

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, cardType string, culture string, templateUrl *TemplateUrlOptions) (*WebPayIn, error)

NewWebPayIn creates a new payment.

func (*MangoPay) Option

func (m *MangoPay) Option(opts ...option)

Option set various options like verbosity etc.

func (*MangoPay) PayIn

func (m *MangoPay) PayIn(id string) (*WebPayIn, error)

PayIn finds a payment.

func (*MangoPay) PayOut

func (m *MangoPay) PayOut(id string) (*PayOut, error)

PayOut finds a bank wire.

func (*MangoPay) Refund

func (m *MangoPay) Refund(id string) (*Refund, error)

Refund fetches a refund (tranfer or payin).

func (*MangoPay) Transfer

func (m *MangoPay) Transfer(id string) (*Transfer, error)

Transfer finds a transaction by id.

func (*MangoPay) Transfers

func (m *MangoPay) Transfers(user Consumer) (TransferList, error)

Transfer finds all user's transactions. Provided for convenience.

func (*MangoPay) User

func (m *MangoPay) User(id string) (*User, error)

User fetch a user (natural or legal) using the Id attribute.

func (*MangoPay) Users

func (m *MangoPay) Users() (UserList, error)

Users returns a list of all registered users, either natural or legal.

func (*MangoPay) Wallet

func (m *MangoPay) Wallet(id string) (*Wallet, error)

Wallet finds a legal user using the user_id attribute.

func (*MangoPay) Wallets

func (m *MangoPay) Wallets(user Consumer) (WalletList, error)

Wallet finds all user's wallets. Provided for convenience.

type Money

type Money struct {
	Currency string
	Amount   int // in cents, i.e 120 for 1.20 EUR
}

Money specifies which currency and amount (in cents!) to use in a payment transaction.

func (Money) String

func (b Money) String() string

type NaturalUser

type NaturalUser struct {
	User
	FirstName, LastName        string
	Address                    string
	UserCategory               string
	TermsAndConditionsAccepted bool
	Birthday                   int64
	Nationality                string
	CountryOfResidence         string
	Occupation                 string
	IncomeRange                int
	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 `json:",omitempty"`
	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)
	// 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

func (p *PayIn) CancelledByUser() bool

Cancelled returns true if the payment has been cancelled by user.

func (*PayIn) Refund

func (p *PayIn) Refund() (*Refund, error)

Refund allows to refund a pay-in. Call the Refund's Save() method to make a request to reimburse a user on his payment card.

func (*PayIn) String

func (p *PayIn) String() string

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
	BankWireRef       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/

func (*PayOut) Save

func (p *PayOut) Save() error

Save sends an HTTP query to create a bank wire. It may return an ErrPayOutFailed error if the payment has failed.

func (*PayOut) String

func (p *PayOut) String() string

type ProcessIdent

type ProcessIdent struct {
	Id           string
	Tag          string
	CreationDate int64
}

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
	RefundReason           RefundReason
	// 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/

func (*Refund) String

func (r *Refund) String() string

type RefundList

type RefundList []*Refund

List of refunds.

type RefundReason

type RefundReason struct {
	RefundReasonType    string
	RefundReasonMessage string
}

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.

See http://docs.mangopay.com/api-references/transfers/.

func (*Transfer) Refund

func (t *Transfer) Refund() (*Refund, error)

func (*Transfer) Save

func (t *Transfer) Save() error

Save sends an HTTP query to create a transfer. Upon successful creation, it may return an ErrTransferFailed error if the transaction has been rejected (unsufficient wallet balance for example).

func (*Transfer) String

func (t *Transfer) String() string

type TransferList

type TransferList []*Transfer

List of transactions.

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.

func (*User) String

func (u *User) String() string

type UserList

type UserList []*User

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

func (w *Wallet) Save() error

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) String

func (u *Wallet) String() string

func (*Wallet) Transactions

func (w *Wallet) Transactions() (TransferList, error)

Transactions returns a wallet's transactions.

type WalletList

type WalletList []*Wallet

List of wallets.

type WebPayIn

type WebPayIn struct {
	PayIn
	ReturnUrl          string
	TemplateURLOptions *TemplateUrlOptions `json:",omitempty"`
	TemplateURL        string              `json:",omitempty"`
	Culture            string
	CardType           string
	RedirectUrl        string
	DirectDebitType    string          `json:",omitempty"`
	WireReference      string          `json:",omitempty"`
	BankAccount        json.RawMessage `json:",omitempty"`
	Tag                string          `json:",omitempty"`
	// 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/

func (*WebPayIn) Save

func (t *WebPayIn) Save() error

Save sends an HTTP query to create a payIn. Upon successful creation, it may return an ErrPayInFailed error if the payment has failed.

func (*WebPayIn) String

func (p *WebPayIn) String() string

Directories

Path Synopsis
bin
mangopay
Package mango is a library for the MangoPay service v2.
Package mango is a library for the MangoPay service v2.

Jump to

Keyboard shortcuts

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