cp_go

package module
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2022 License: MIT Imports: 8 Imported by: 0

README

CloudPayments Golang Client

Client for the Cloud Payments payment service allows access the Cloud Payments API from Golang code.

Install

go get github.com/Miha-ha/cp-go

Config

Property Type Description Default Required
ApiSecret string Secret key (you can get it in your personal account) empty string true
PublicId string Public key (you can get it in your personal account) empty string true
Timeout time.Duration Request timeout 30 * time.Second false

Usage


import cp "github.com/Miha-ha/cp-go"

client := cp.NewClient(cp.Config{
    ApiSecret: "api_secret",
    PublicId:  "public_id",
    Timeout:   30 * time.Second,
})

response, err := client.Ping()
...

Test method description

response, err := client.Ping()

If successful, it returns a map[string]interface{} else returns error.

Client API

Method Description Documentation Link
ChargeCryptogramPayment Payment by cryptogram https://developers.cloudpayments.ru/#oplata-po-kriptogramme
AuthorizeCryptogramPayment Payment by cryptogram (authorization) https://developers.cloudpayments.ru/#oplata-po-kriptogramme
ChargeTokenPayment Payment by token https://developers.cloudpayments.ru/#oplata-po-tokenu-rekarring
AuthorizeTokenPayment Payment by token (authorization) https://developers.cloudpayments.ru/#oplata-po-tokenu-rekarring
Confirm3DSPayment 3-D Secure Processing https://developers.cloudpayments.ru/#obrabotka-3-d-secure
ConfirmPayment Payment confirmation https://developers.cloudpayments.ru/#podtverzhdenie-oplaty
RefundPayment Refund money https://developers.cloudpayments.ru/#vozvrat-deneg
VoidPayment Cancellation of payment https://developers.cloudpayments.ru/#otmena-oplaty
Payment Viewing operation information(todo) https://developers.cloudpayments.ru/#prosmotr-tranzaktsii
FindPaymentByInvoiceId Checking the payment status(todo) https://developers.cloudpayments.ru/#proverka-statusa-platezha
GetPaymentsList List of transactions(todo) https://developers.cloudpayments.ru/#vygruzka-spiska-tranzaktsiy
CreateOrder Creating an invoice to send by mail https://developers.cloudpayments.ru/#sozdanie-scheta-dlya-otpravki-po-pochte
CreateSubscription Creating a subscription https://developers.cloudpayments.ru/#sozdanie-podpiski-na-rekurrentnye-platezhi
UpdateSubscription Changing a subscription https://developers.cloudpayments.ru/#izmenenie-podpiski-na-rekurrentnye-platezhi
CancelSubscription Cancellation of subscription https://developers.cloudpayments.ru/#izmenenie-podpiski-na-rekurrentnye-platezhi
GetSubscription Request for subscription information https://developers.cloudpayments.ru/#zapros-informatsii-o-podpiske
GetSubscriptionsList Search subscriptions https://developers.cloudpayments.ru/#poisk-podpisok
ChargeCryptogramPayout Payout by cryptogram(todo) https://developers.cloudpayments.ru/#vyplata-po-kriptogramme
ChargeTokenPayout Payout by token(todo) https://developers.cloudpayments.ru/#vyplata-po-tokenu

TODO

  • Receipt
  • Notification handlers?
  • Finish (todo) marked methods

Problems and improvements

  • Create issue
  • Create pull-request

License

MIT

Documentation

Index

Constants

View Source
const (
	ReferToCardIssuer = 5001 // Отказ эмитента проводить онлайн операцию

	// DoNotHonor Отказ эмитента без объяснения причин
	// Данный код возвращается по следующим причинам:
	// — неверно указан код CVV на картах MasterCard;
	// — внутренние ограничения банка, выпустившего карту;
	// — карта заблокирована или еще не активирована;
	// — на карте не включены интернет-платежи или не подключен 3DS.
	DoNotHonor = 5005

	Error                    = 5006 // Отказ сети проводить операцию или неправильный CVV код
	InvalidTransaction       = 5012 // Карта не предназначена для онлайн платежей
	AmountError              = 5013 // Слишком маленькая или слишком большая сумма операции
	FormatError              = 5030 // Ошибка на стороне эквайера — неверно сформирована транзакция
	BankNotSupportedBySwitch = 5031 // Неизвестный эмитент карты
	SuspectedFraud           = 5034 // Отказ эмитента — подозрение на мошенничество
	LostCard                 = 5041 // Карта потеряна
	StolenCard               = 5043 // Карта украдена
	InsufficientFunds        = 5051 // Недостаточно средств
	ExpiredCard              = 5054 // Карта просрочена или неверно указан срок действия

	// TransactionNotPermitted Ограничение на карте
	// Данный код возвращается по следующим причинам:
	//  — внутренние ограничения банка, выпустившего карту;
	//  — карта заблокирована или еще не активирована;
	//  — на карте не включены интернет-платежи или не подключен 3DS.
	TransactionNotPermitted = 5057

	ExceedWithdrawalFrequency = 5065 // Превышен лимит операций по карте
	IncorrectCVV              = 5082 // Неверный CVV код
	Timeout                   = 5091 // Эмитент недоступен
	CannotReachNetwork        = 5092 // Эмитент недоступен
	SystemError               = 5096 // Ошибка банка-эквайера или сети
	UnableToProcess           = 5204 // Операция не может быть обработана по прочим причинам
	AuthenticationFailed      = 5206 // 3-D Secure авторизация не пройдена
	AuthenticationUnavailable = 5207 // 3-D Secure авторизация недоступна
	AntiFraud                 = 5300 // Лимиты эквайера на проведение операций
)
View Source
const (
	SUCCESS            = 0
	UNKNOWN_INVOICE_ID = 10
	INVALID_ACCOUNT_ID = 11
	INVALID_AMOUNT     = 12
	REJECTED           = 13
	EXPIRED            = 20
)
View Source
const (
	KZT = "KZT"
	RUB = "RUB"
	EUR = "EUR"
	USD = "USD"
	GBP = "GBP"
	UAH = "UAH"
	BYR = "BYR"
	BYN = "BYN"
	AZN = "AZN"
	CHF = "CHF"
	CZK = "CZK"
	CAD = "CAD"
	PLN = "PLN"
	SEK = "SEK"
	TRY = "TRY"
	CNY = "CNY"
	INR = "INR"
)
View Source
const (
	DefaultRequestTimeout = 30 * time.Second
)

Variables

This section is empty.

Functions

func ComputeHmac256

func ComputeHmac256(message, secret []byte) string

func ErrorStatusText

func ErrorStatusText(code int) string

ErrorStatusText returns a text of error codes that determine the reason for the refusal to make a payment string if the code is unknown.

Types

type AccountRequest

type AccountRequest struct {
	AccountId string
	Email     string
}

type BaseRequest

type BaseRequest struct {
	CultureName string
	RequestID   *string
}

type BaseResponse

type BaseResponse struct {
	Success bool   `json:"Success,omitempty"`
	Message string `json:"Message,omitempty"`
}

type Client

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

func NewClient

func NewClient(cfg ...Config) *Client

func (*Client) AuthorizeCryptogramPayment

func (c *Client) AuthorizeCryptogramPayment(cpr CryptogramPaymentRequest) (*Payment3DSResponse, error)

AuthorizeCryptogramPayment two-stage payment

func (*Client) AuthorizeTokenPayment

func (c *Client) AuthorizeTokenPayment(tpr TokenPaymentRequest) (*PaymentResponse, error)

AuthorizeTokenPayment authorize token payment

func (*Client) CancelSubscription

func (c *Client) CancelSubscription(sur SubscriptionUpdateRequest) (*BaseResponse, error)

CancelSubscription cancel subscription

func (*Client) ChargeCryptogramPayment

func (c *Client) ChargeCryptogramPayment(cpr *CryptogramPaymentRequest) (*PaymentResponse, error)

ChargeCryptogramPayment Payment by cryptogram

func (*Client) ChargeCryptogramPayout

func (c *Client) ChargeCryptogramPayout()

func (*Client) ChargeTokenPayment

func (c *Client) ChargeTokenPayment(tpr TokenPaymentRequest) (*PaymentResponse, error)

ChargeTokenPayment payment by token

func (*Client) ChargeTokenPayout

func (c *Client) ChargeTokenPayout()

func (*Client) Confirm3DSPayment

func (c *Client) Confirm3DSPayment(confirm3DS Confirm3DSRequest) (*PaymentResponse, error)

Confirm3DSPayment Confirm a 3DS payment

func (*Client) ConfirmPayment

func (c *Client) ConfirmPayment(confirm ConfirmPaymentRequest) (*BaseResponse, error)

ConfirmPayment confirm an authorized payment

func (*Client) CreateOrder

func (c *Client) CreateOrder(lpr LinkPaymentRequest) (*BaseResponse, error)

CreateOrder to send by email

func (*Client) CreateSubscription

func (c *Client) CreateSubscription(scr SubscriptionCreateRequest) (*SubscriptionResponse, error)

CreateSubscription create subscription

func (*Client) FindPaymentByInvoiceID

func (c *Client) FindPaymentByInvoiceID(fpr FindPaymentRequest) (*PaymentResponse, error)

FindPaymentByInvoiceID

func (*Client) GetSubscription

func (c *Client) GetSubscription(sgr SubscriptionGetRequest) (*SubscriptionResponse, error)

GetSubscription get subscription by ID of transaction

func (*Client) GetSubscriptionsList

func (c *Client) GetSubscriptionsList(slr SubscriptionListRequest) (*SubscriptionsListResponse, error)

GetSubscriptionsList get subscription list by AccountId

func (*Client) Payment

func (c *Client) Payment(gpr GetPaymentRequest) (*PaymentResponse, error)

Payment getting pyment by transaction id

func (*Client) PaymentsList

func (c *Client) PaymentsList()

PaymentsList

func (*Client) Ping

func (c *Client) Ping() (map[string]interface{}, error)

func (*Client) RefundPayment

func (c *Client) RefundPayment(rpp RefundPaymentRequest) (*BaseResponse, error)

RefundPayment refund

func (*Client) UpdateSubscription

func (c *Client) UpdateSubscription(sur SubscriptionUpdateRequest) (*SubscriptionResponse, error)

UpdateSubscription update subscription

func (*Client) VoidPayment

func (c *Client) VoidPayment(vpr VoidPaymentRequest) (*BaseResponse, error)

VoidPayment cancellation of payment

type Config

type Config struct {
	ApiSecret string
	PublicId  string
	Timeout   time.Duration
}

type Confirm3DSRequest

type Confirm3DSRequest struct {
	BaseRequest
	TransactionId string
	PaRes         string
}

type ConfirmPaymentRequest

type ConfirmPaymentRequest struct {
	BaseRequest
	TransactionId int
	Amount        float64
	JsonData      *string
}

type CryptogramPaymentRequest

type CryptogramPaymentRequest struct {
	PaymentRequest
	CardCryptogramPacket string
	AccountId            *string
}

type FindPaymentRequest

type FindPaymentRequest struct {
	BaseRequest
	InvoiceId string
}

type GetPaymentRequest

type GetPaymentRequest struct {
	BaseRequest
	TransactionId int
}

type LinkPaymentRequest

type LinkPaymentRequest struct {
	BaseRequest
	Amount      int
	Currency    string // ValidCurrency
	JsonData    *string
	Description string
	// contains filtered or unexported fields
}

type Payment3DSModel

type Payment3DSModel struct {
	PaReq             string `json:"PaReq,omitempty"`
	AcsUrl            string `json:"AcsUrl,omitempty"`
	ThreeDsCallbackId string `jsno:"ThreeDsCallbackId,omitempty"`
	AuthDate          string `json:"AuthDate,omitempty"`
	AuthDateIso       string `json:"AuthDateIso,omitempty"`
	AuthCode          string `json:"AuthCode,omitempty"`
	ConfirmDate       string `json:"ConfirmDate,omitempty"`
	ConfirmDateIso    string `json:"ConfirmDateIso,omitempty"`
}

type Payment3DSResponse

type Payment3DSResponse struct {
	BaseResponse
	Model struct {
		PaymentModel
		Payment3DSModel
	}
}

type PaymentModel

type PaymentModel struct {
	TransactionId     int     `json:"TransactionId,omitempty"`
	Amount            float64 `json:"Amount,omitempty"`
	Currency          string  `json:"Currency,omitempty"`
	CurrencyCode      int     `json:"CurrencyCode,omitempty"`
	InvoiceID         string  `json:"InvoiceID,omitempty"`
	AccountID         string  `json:"AccountID,omitempty"`
	Email             string  `json:"Email,omitempty"`
	Description       string  `json:"Description,omitempty"`
	Data              []byte  `json:"Data,omitempty"`
	TestMode          bool    `json:"TestMode,omitempty"`
	IpAddress         string  `json:"IpAddress,omitempty"`
	IpCountry         string  `json:"IpCountry,omitempty"`
	IpCity            string  `json:"IpCity,omitempty"`
	IpRegion          string  `json:"IpRegion,omitempty"`
	IpDistrict        string  `json:"IpDistrict,omitempty"`
	IpLatitude        float64 `json:"IpLatitude,omitempty"`
	IpLongitude       float64 `json:"IpLongitude,omitempty"`
	CardFirstSix      string  `json:"CardFirstSix,omitempty"`
	CardLastFour      string  `json:"CardLastFour,omitempty"`
	CardExpiredMonth  int     `json:"CardExpiredMonth,omitempty"`
	CardExpiredYear   int     `json:"CardExpiredYear,omitempty"`
	CardType          string  `json:"CardType,omitempty"`
	CardTypeCode      int     `json:"CardTypeCode,omitempty"`
	Issuer            string  `json:"Issuer,omitempty"`
	IssuerBankCountry string  `json:"IssuerBankCountry,omitempty"`
	Status            string  `json:"Status,omitempty"`
	StatusCode        int     `json:"StatusCode,omitempty"`
	Reason            string  `json:"Reason,omitempty"`
	ReasonCode        int     `json:"ReasonCode,omitempty"`
	CardHolderMessage string  `json:"CardHolderMessage,omitempty"`
	CardHolderName    string  `json:"CardHolderName,omitempty"`
	Token             string  `json:"Token,omitempty"`
	JsonData          string  `json:"JsonData,omitempty"`
	Name              string  `json:"Name,omitempty"`
}

type PaymentRequest

type PaymentRequest struct {
	BaseRequest
	Amount      float64
	Currency    string
	IpAddress   string
	Name        string
	InvoiceId   string
	Description string
	Email       string
	JsonData    string
}

type PaymentResponse

type PaymentResponse struct {
	BaseResponse
	Model struct {
		PaymentModel
		Payment3DSModel
	}
}

type PaymentStatus

type PaymentStatus string
const (
	PaymentStatusAwaitingAuthentication PaymentStatus = "AwaitingAuthentication"
	PaymentStatusAuthorized             PaymentStatus = "Authorized"
	PaymentStatusCompleted              PaymentStatus = "Completed"
	PaymentStatusCancelled              PaymentStatus = "Cancelled"
	PaymentStatusDeclined               PaymentStatus = "Declined"
)

type RefundPaymentRequest

type RefundPaymentRequest struct {
	BaseRequest
	TransactionId int
	Amount        float64
	JsonData      *string
}

type SubscriptionBase

type SubscriptionBase struct {
	BaseRequest
	AccountRequest
	Description         string
	Amount              float64
	Currency            string
	RequireConfirmation bool
	StartDate           string
	Interval            string
	Period              int
	MaxPeriods          int
}

type SubscriptionCreateRequest

type SubscriptionCreateRequest struct {
	SubscriptionBase
	Token string
}

type SubscriptionGetRequest

type SubscriptionGetRequest struct {
	BaseRequest
	Id string
}

type SubscriptionListRequest

type SubscriptionListRequest struct {
	BaseRequest
	AccountId string
}

type SubscriptionModel

type SubscriptionModel struct {
	Id                           string
	CurrencyCode                 int
	StartDateIso                 string
	IntervalCode                 int
	StatusCode                   int
	Status                       string
	SuccessfulTransactionsNumber int
	FailedTransactionsNumber     int
	LastTransactionDate          string
	LastTransactionDateIso       string
	NextTransactionDate          string
	NextTransactionDateIso       string
}

type SubscriptionResponse

type SubscriptionResponse struct {
	BaseResponse
	Model SubscriptionModel
}

type SubscriptionUpdateRequest

type SubscriptionUpdateRequest struct {
	SubscriptionBase
	Id string
}

type SubscriptionsListResponse

type SubscriptionsListResponse struct {
	BaseResponse
	Model []SubscriptionModel
}

type TokenPaymentRequest

type TokenPaymentRequest struct {
	PaymentRequest
	AccountId string
	Token     string
}

type VoidPaymentRequest

type VoidPaymentRequest struct {
	BaseRequest
	TransactionId int
}

Jump to

Keyboard shortcuts

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