mercadopago

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2021 License: MIT Imports: 5 Imported by: 1

README ¶

Mercadopago

Idiomatic go client for MercadoPago

👀 Example

Create a new payment using a test user

package main

import (
	"fmt"
	"github.com/fabianMendez/mercadopago"
)

func main() {
	client := mercadopago.NewClient("https://api.mercadopago.com/v1", "TEST-PUBLIC-KEY", "TEST-ACCESS-TOKEN")

	buyer, err := client.NewTestUser(mercadopago.TestUserParams{SiteID: "MCO"})
	if err != nil {
		panic(err)
	}

	identification := mercadopago.Identification{Type:   "CC", Number: "19119119100"}

	cardToken, err := client.NewCardToken(mercadopago.CardTokenParams{
		ExpirationMonth: 11,
		ExpirationYear:  2025,
		Cardholder: mercadopago.Cardholder{Name: "APRO", Identification: identification},
		SecurityCode: "123",
		CardNumber:   "4013540682746260",
	})
	if err != nil {
		panic(err)
	}

	payment, err := client.NewPayment(mercadopago.PaymentParams{
		PaymentMethodID:   "visa",
		TransactionAmount: 1234.5,
		Payer: mercadopago.Payer{
			Email:          buyer.Email,
			Identification: identification,
		},
		Token:        cardToken.ID,
		Description:  "Test Payment",
		Installments: 1,
	})
	if err != nil {
		panic(err)
	}

	fmt.Println(payment.Status)
}

Documentation ¶

Index ¶

Constants ¶

View Source
const (
	// The user has not yet completed the payment process.
	StatusPending = "pending"
	// The payment has been approved and accredited.
	StatusApproved = "approved"
	// The payment has been authorized but not captured yet.
	StatusAuthorized = "authorized"
	// Payment is being reviewed.
	StatusInProcess = "in_process"
	// Users have initiated a dispute.
	StatusInMediation = "in_mediation"
	// Payment was rejected. The user may retry payment.
	StatusRejected = "rejected"
	// Payment was cancelled by one of the parties or because time for payment has expired
	StatusCancelled = "cancelled"
	// Payment was refunded to the user.
	StatusRefunded = "refunded"
	// Was made a chargeback in the buyer’s credit card.
	StatusChargedBack = "charged_back"
)

Variables ¶

This section is empty.

Functions ¶

This section is empty.

Types ¶

type Card ¶ added in v1.0.3

type Card struct {
	ID              interface{} `json:"id"`
	FirstSixDigits  string      `json:"first_six_digits"`
	LastFourDigits  string      `json:"last_four_digits"`
	ExpirationMonth int         `json:"expiration_month"`
	ExpirationYear  int         `json:"expiration_year"`
	DateCreated     string      `json:"date_created"`
	DateLastUpdated string      `json:"date_last_updated"`
	Cardholder      Cardholder  `json:"cardholder"`
}

type CardToken ¶

type CardToken struct {
	ID              string     `json:"id"`
	PublicKey       string     `json:"public_key"`
	Cardholder      Cardholder `json:"cardholder"`
	Status          string     `json:"status"`
	DateCreated     string     `json:"date_created"`
	DateLastUpdated string     `json:"date_last_updated"`
	DateDue         string     `json:"date_due"`
	LuhnValidation  bool       `json:"luhn_validation"`
	LiveMode        bool       `json:"live_mode"`
	RequireEsc      bool       `json:"require_esc"`
}

CardToken contains the information for a token which represents a card

type CardTokenParams ¶

type CardTokenParams struct {
	ExpirationMonth int        `json:"expiration_month"`
	ExpirationYear  int        `json:"expiration_year"`
	Cardholder      Cardholder `json:"cardholder"`
	SecurityCode    string     `json:"security_code"`
	CardNumber      string     `json:"card_number"`
}

CardTokenParams represent the params used to create or update a CardToken

type Cardholder ¶ added in v1.0.3

type Cardholder struct {
	Name           string         `json:"name"`
	Identification Identification `json:"identification"`
}

type Client ¶

type Client interface {
	// NewCardToken creates a new CardToken
	NewCardToken(params CardTokenParams) (*CardToken, error)

	// GetIdentificationTypes returns all available identification types
	GetIdentificationTypes() (IdentificationTypes, error)

	// GetPaymentMethods returns all available payment methods
	GetPaymentMethods() (PaymentMethods, error)

	// GetPaymentMethodsForBin returns all available payment methods for the given bin
	GetPaymentMethodsForBin(bin string) (PaymentMethods, error)

	// GetInstallments returns all available installments for the given
	// payment method, amount and issuer
	GetInstallments(params GetInstallmentsParams) (Installments, error)

	// GetCardIssuers returns all available issuers for the given payment method
	GetCardIssuers(paymentMethodID string) (Issuers, error)

	// NewPayment creates a new Payment
	NewPayment(params PaymentParams) (*Payment, error)

	// NewTestUser creates a new test user
	NewTestUser(params TestUserParams) (*TestUser, error)
}

Client is the api client

func NewClient ¶

func NewClient(baseURL, publicKey, accessToken string) Client

NewClient creates a new Client

type Error ¶

type Error struct {
	Message   string       `json:"message"`
	ErrorCode string       `json:"error"`
	Status    int          `json:"status"`
	Cause     []ErrorCause `json:"cause"`
}

Error represents an error returned by the api

func (Error) Error ¶

func (e Error) Error() string

Error returns the string representation of the error

type ErrorCause ¶

type ErrorCause struct {
	// int/string
	Code        interface{} `json:"code"`
	Description string      `json:"description"`
	Data        interface{} `json:"data"`
}

type FeeDetail ¶ added in v1.0.3

type FeeDetail struct {
	Type     string  `json:"type"`
	Amount   float64 `json:"amount"`
	FeePayer string  `json:"fee_payer"`
}

type FeeDetails ¶ added in v1.0.3

type FeeDetails []FeeDetail

type GetInstallmentsParams ¶

type GetInstallmentsParams struct {
	PaymentMethodID string  `json:"payment_method_id"`
	Amount          float64 `json:"amount"`
	IssuerID        string  `json:"issuer_id"`
}

type Identification ¶

type Identification struct {
	Type   string `json:"type"`
	Number string `json:"number"`
}

type IdentificationType ¶

type IdentificationType struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	Type      string `json:"type"`
	MinLength int    `json:"min_length"`
	MaxLength int    `json:"max_length"`
}

type IdentificationTypes ¶

type IdentificationTypes []IdentificationType

type Installment ¶

type Installment struct {
	PaymentMethodID string `json:"payment_method_id"`
	PaymentTypeID   string `json:"payment_type_id"`
	Issuer          struct {
		ID              string `json:"id"`
		Name            string `json:"name"`
		SecureThumbnail string `json:"secure_thumbnail"`
		Thumbnail       string `json:"thumbnail"`
	} `json:"issuer"`
	ProcessingMode    string      `json:"processing_mode"`
	MerchantAccountID interface{} `json:"merchant_account_id"`
	PayerCosts        []struct {
		Installments             int           `json:"installments"`
		InstallmentRate          int           `json:"installment_rate"`
		DiscountRate             int           `json:"discount_rate"`
		ReimbursementRate        interface{}   `json:"reimbursement_rate"`
		Labels                   []interface{} `json:"labels"`
		InstallmentRateCollector []string      `json:"installment_rate_collector"`
		MinAllowedAmount         float64       `json:"min_allowed_amount"`
		MaxAllowedAmount         float64       `json:"max_allowed_amount"`
		RecommendedMessage       string        `json:"recommended_message"`
		InstallmentAmount        float64       `json:"installment_amount"`
		TotalAmount              float64       `json:"total_amount"`
		PaymentMethodOptionID    string        `json:"payment_method_option_id"`
	} `json:"payer_costs"`
	Agreements interface{} `json:"agreements"`
}

type Installments ¶

type Installments []Installment

type Issuer ¶

type Issuer struct {
	ID                string      `json:"id"`
	Name              string      `json:"name"`
	SecureThumbnail   string      `json:"secure_thumbnail"`
	Thumbnail         string      `json:"thumbnail"`
	ProcessingMode    string      `json:"processing_mode"`
	MerchantAccountID interface{} `json:"merchant_account_id"`
}

type Issuers ¶

type Issuers []Issuer

type Payer ¶

type Payer struct {
	Email          string         `json:"email"`
	Identification Identification `json:"identification"`
	FirstName      string         `json:"first_name,omitempty"`
	LastName       string         `json:"last_name,omitempty"`
	Phone          *Phone         `json:"phone,omitempty"`
	Type           string         `json:"type,omitempty"`
	EntityType     interface{}    `json:"entity_type,omitempty"`
	ID             interface{}    `json:"id,omitempty"`
}

type Payment ¶

type Payment struct {
	ID                        int                `json:"id"`
	DateCreated               string             `json:"date_created"`
	DateApproved              string             `json:"date_approved"`
	DateLastUpdated           string             `json:"date_last_updated"`
	DateOfExpiration          interface{}        `json:"date_of_expiration"`
	MoneyReleaseDate          string             `json:"money_release_date"`
	OperationType             string             `json:"operation_type"`
	IssuerID                  string             `json:"issuer_id"`
	PaymentMethodID           string             `json:"payment_method_id"`
	PaymentTypeID             string             `json:"payment_type_id"`
	Status                    string             `json:"status"`
	StatusDetail              string             `json:"status_detail"`
	CurrencyID                string             `json:"currency_id"`
	Description               string             `json:"description"`
	LiveMode                  bool               `json:"live_mode"`
	SponsorID                 interface{}        `json:"sponsor_id"`
	AuthorizationCode         interface{}        `json:"authorization_code"`
	MoneyReleaseSchema        interface{}        `json:"money_release_schema"`
	TaxesAmount               float64            `json:"taxes_amount"`
	CounterCurrency           interface{}        `json:"counter_currency"`
	ShippingAmount            float64            `json:"shipping_amount"`
	PosID                     interface{}        `json:"pos_id"`
	StoreID                   interface{}        `json:"store_id"`
	CollectorID               int                `json:"collector_id"`
	Payer                     Payer              `json:"payer"`
	Metadata                  struct{}           `json:"metadata"`
	AdditionalInfo            interface{}        `json:"additional_info"`
	Order                     struct{}           `json:"order"`
	ExternalReference         string             `json:"external_reference"`
	TransactionAmount         float64            `json:"transaction_amount"`
	TransactionAmountRefunded float64            `json:"transaction_amount_refunded"`
	CouponAmount              float64            `json:"coupon_amount"`
	DifferentialPricingID     interface{}        `json:"differential_pricing_id"`
	DeductionSchema           interface{}        `json:"deduction_schema"`
	TransactionDetails        TransactionDetails `json:"transaction_details"`
	FeeDetails                FeeDetails         `json:"fee_details"`
	Captured                  bool               `json:"captured"`
	BinaryMode                bool               `json:"binary_mode"`
	CallForAuthorizeID        interface{}        `json:"call_for_authorize_id"`
	StatementDescriptor       string             `json:"statement_descriptor"`
	Installments              int                `json:"installments"`
	Card                      Card               `json:"card"`
	NotificationURL           string             `json:"notification_url"`
	Refunds                   []interface{}      `json:"refunds"`
	ProcessingMode            string             `json:"processing_mode"`
	MerchantAccountID         interface{}        `json:"merchant_account_id"`
	Acquirer                  interface{}        `json:"acquirer"`
	MerchantNumber            interface{}        `json:"merchant_number"`
	AcquirerReconciliation    []interface{}      `json:"acquirer_reconciliation"`
}

type PaymentMethod ¶

type PaymentMethod struct {
	ID              string `json:"id"`
	Name            string `json:"name"`
	PaymentTypeID   string `json:"payment_type_id"`
	Status          string `json:"status"`
	SecureThumbnail string `json:"secure_thumbnail"`
	Thumbnail       string `json:"thumbnail"`
	DeferredCapture string `json:"deferred_capture"`
	Settings        []struct {
		CardNumber struct {
			Validation string `json:"validation"`
			Length     int    `json:"length"`
		} `json:"card_number"`
		Bin struct {
			Pattern             string `json:"pattern"`
			InstallmentsPattern string `json:"installments_pattern"`
			ExclusionPattern    string `json:"exclusion_pattern"`
		} `json:"bin"`
		SecurityCode struct {
			Length       int    `json:"length"`
			CardLocation string `json:"card_location"`
			Mode         string `json:"mode"`
		} `json:"security_code"`
	} `json:"settings"`
	AdditionalInfoNeeded  []string `json:"additional_info_needed"`
	MinAllowedAmount      float64  `json:"min_allowed_amount"`
	MaxAllowedAmount      float64  `json:"max_allowed_amount"`
	AccreditationTime     int      `json:"accreditation_time"`
	FinancialInstitutions []struct {
		ID          string `json:"id"`
		Description string `json:"description"`
	} `json:"financial_institutions"`
	ProcessingModes []string `json:"processing_modes"`
	// from the search response only
	PayerCosts []struct {
		InstallmentRate       int           `json:"installment_rate"`
		DiscountRate          int           `json:"discount_rate"`
		MinAllowedAmount      float64       `json:"min_allowed_amount"`
		Labels                []interface{} `json:"labels"`
		Installments          int           `json:"installments"`
		ReimbursementRate     interface{}   `json:"reimbursement_rate"`
		MaxAllowedAmount      float64       `json:"max_allowed_amount"`
		PaymentMethodOptionID string        `json:"payment_method_option_id"`
	} `json:"payer_costs"`
	Issuer struct {
		Default bool   `json:"default"`
		Name    string `json:"name"`
		ID      int    `json:"id"`
	} `json:"issuer"`
	TotalFinancialCost   interface{}   `json:"total_financial_cost"`
	MinAccreditationDays int           `json:"min_accreditation_days"`
	MaxAccreditationDays int           `json:"max_accreditation_days"`
	MerchantAccountID    interface{}   `json:"merchant_account_id"`
	Bins                 []interface{} `json:"bins"`
	Marketplace          string        `json:"marketplace"`
	Agreements           []interface{} `json:"agreements"`
	Labels               []string      `json:"labels"`
	FinancingDeals       struct {
		Legals         interface{} `json:"legals"`
		Installments   interface{} `json:"installments"`
		ExpirationDate interface{} `json:"expiration_date"`
		StartDate      interface{} `json:"start_date"`
		Status         string      `json:"status"`
	} `json:"financing_deals"`
	SiteID         string `json:"site_id"`
	ProcessingMode string `json:"processing_mode"`
}

type PaymentMethods ¶

type PaymentMethods []PaymentMethod

type PaymentParams ¶

type PaymentParams struct {
	TransactionAmount   float64     `json:"transaction_amount"`
	PaymentMethodID     string      `json:"payment_method_id"`
	Payer               Payer       `json:"payer"`
	Token               string      `json:"token"`
	Description         string      `json:"description"`
	Installments        int         `json:"installments"`
	NotificationURL     string      `json:"notification_url,omitempty"`
	SponsorID           interface{} `json:"sponsor_id"`
	BinaryMode          bool        `json:"binary_mode"`
	ExternalReference   string      `json:"external_reference"`
	StatementDescriptor string      `json:"statement_descriptor"`
	AdditionalInfo      interface{} `json:"additional_info"`
}

type Phone ¶ added in v1.0.3

type Phone struct {
	AreaCode  string `json:"area_code"`
	Number    string `json:"number"`
	Extension string `json:"extension"`
}

type TestUser ¶

type TestUser struct {
	ID         int    `json:"id"`
	Nickname   string `json:"nickname"`
	Password   string `json:"password"`
	SiteStatus string `json:"site_status"`
	Email      string `json:"email"`
}

type TestUserParams ¶

type TestUserParams struct {
	SiteID string `json:"site_id"`
}

type TransactionDetails ¶ added in v1.0.3

type TransactionDetails struct {
	PaymentMethodReferenceID interface{} `json:"payment_method_reference_id"`
	NetReceivedAmount        float64     `json:"net_received_amount"`
	TotalPaidAmount          float64     `json:"total_paid_amount"`
	OverpaidAmount           float64     `json:"overpaid_amount"`
	ExternalResourceURL      interface{} `json:"external_resource_url"`
	InstallmentAmount        float64     `json:"installment_amount"`
	FinancialInstitution     interface{} `json:"financial_institution"`
	PayableDeferralPeriod    interface{} `json:"payable_deferral_period"`
	AcquirerReference        interface{} `json:"acquirer_reference"`
}

type WebhookEvent ¶ added in v1.0.4

type WebhookEvent struct {
	Action      string      `json:"action"`
	APIVersion  string      `json:"api_version"`
	Data        interface{} `json:"data"`
	DateCreated time.Time   `json:"date_created"`
	ID          int64       `json:"id"`
	LiveMode    bool        `json:"live_mode"`
	Type        string      `json:"type"`
	UserID      string      `json:"user_id"`
}

Jump to

Keyboard shortcuts

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