gocryptomus

package module
v0.0.0-...-05ebd53 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: MIT Imports: 11 Imported by: 0

README

Golang Wrapper for cryptomus payment API

Install

go get github.com/chaindead/go-cryptomus

Check signature

package main

import (
	"bytes"
	"net/http"
	
	gocryptomus "github.com/chaindead/go-cryptomus"
)

func main(){
	httpClient := http.Client{}
	merchant := "replace with your merchant id"
	paymentAPIKey := "replace with your payment API key"
	payoutAPIKey := "replace with your payout API key"
	client := gocryptomus.New(&httpClient, merchant, paymentAPIKey, payoutAPIKey)

	// c.Request().Body - handler logic
	buf := new(bytes.Buffer)
	buf.ReadFrom(c.Request().Body)
	body := buf.Bytes()

	isSigValid := client.VerifySignature(body)
	if !isSigValid{
		return
    }
}

Documentation

Index

Constants

View Source
const (
	CallbackStatusPaid         = "paid"
	CallbackStatusPaidOver     = "paid_over"
	CallbackStatusCancel       = "cancel"
	CallbackStatusConfirmCheck = "confirm_check"
)
View Source
const APIURL = "https://api.cryptomus.com/v1"

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockAddressRequest

type BlockAddressRequest struct {
	WalletUUID    string `json:"uuid,omitempty"`
	OrderId       string `json:"order_id,omitempty"`
	IsForceRefund bool   `json:"is_force_refund,omitempty"`
}

type BlockAddressResponse

type BlockAddressResponse struct {
	WalletUUID string `json:"uuid"`
	Status     string `json:"status"`
}

type BlockedAddressRefundRequest

type BlockedAddressRefundRequest struct {
	WalletUUID string `json:"uuid,omitempty"`
	OrderId    string `json:"order_id,omitempty"`
	Address    string `json:"address"`
}

type BlockedAddressRefundResponse

type BlockedAddressRefundResponse struct {
	Commision string `json:"commision"`
	Amount    string `json:"amount"`
}

type Callback

type Callback struct {
	Type              string      `json:"type"`
	Uuid              string      `json:"uuid"`
	OrderId           string      `json:"order_id"`
	Amount            string      `json:"amount"`
	PaymentAmount     string      `json:"payment_amount"`
	PaymentAmountUsd  string      `json:"payment_amount_usd"`
	MerchantAmount    string      `json:"merchant_amount"`
	Commission        string      `json:"commission"`
	IsFinal           bool        `json:"is_final"`
	Status            string      `json:"status"`
	From              string      `json:"from"`
	WalletAddressUuid interface{} `json:"wallet_address_uuid"`
	Network           string      `json:"network"`
	Currency          string      `json:"currency"`
	PayerCurrency     string      `json:"payer_currency"`
	AdditionalData    interface{} `json:"additional_data"`
	Convert           struct {
		ToCurrency string      `json:"to_currency"`
		Commission interface{} `json:"commission"`
		Rate       string      `json:"rate"`
		Amount     string      `json:"amount"`
	} `json:"convert"`
	Txid string `json:"txid"`
	Sign string `json:"sign"`
}

func (Callback) String

func (c Callback) String() string

type Cryptomus

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

func New

func New(client *http.Client, merchant, paymentApiKey, payoutApiKey string) *Cryptomus

func (*Cryptomus) BlockAddress

func (c *Cryptomus) BlockAddress(blockAddressReq *BlockAddressRequest) (*BlockAddressResponse, error)

func (*Cryptomus) BlockedAddressRefund

func (c *Cryptomus) BlockedAddressRefund(refundRequest *BlockedAddressRefundRequest) (*BlockedAddressRefundResponse, error)

func (*Cryptomus) CreateInvoice

func (c *Cryptomus) CreateInvoice(invoiceReq *InvoiceRequest) (*Payment, error)

func (*Cryptomus) CreateStaticWallet

func (c *Cryptomus) CreateStaticWallet(staticWalletReq *StaticWalletRequest) (*StaticWalletResponse, error)

func (*Cryptomus) GeneratePaymentQRCode

func (c *Cryptomus) GeneratePaymentQRCode(paymentUUID string) (string, error)

func (*Cryptomus) GenerateStaticWalletQRCode

func (c *Cryptomus) GenerateStaticWalletQRCode(walletUUID string) (string, error)

func (*Cryptomus) GetPaymentHistory

func (c *Cryptomus) GetPaymentHistory(dateFrom, dateTo time.Time) (*PaymentHistoryResponse, error)

func (*Cryptomus) GetPaymentInfo

func (c *Cryptomus) GetPaymentInfo(paymentInfoReq *PaymentInfoRequest) (*Payment, error)

func (*Cryptomus) Refund

func (c *Cryptomus) Refund(refundRequest *RefundRequest) (bool, error)

func (*Cryptomus) ResendWebhook

func (c *Cryptomus) ResendWebhook(resendRequest *ResendWebhookRequest) (bool, error)

func (*Cryptomus) VerifySignature

func (c *Cryptomus) VerifySignature(body []byte) bool

type Currency

type Currency struct {
	Currency string `json:"currency"`
	Network  string `json:"network,omitempty"`
}

type InvoiceRequest

type InvoiceRequest struct {
	Amount   string `json:"amount"`
	Currency string `json:"currency"`
	OrderId  string `json:"order_id"`
	*InvoiceRequestOptions
}

type InvoiceRequestOptions

type InvoiceRequestOptions struct {
	Network                string     `json:"network,omitempty"`
	UrlReturn              string     `json:"url_return,omitempty"`
	UrlSuccess             string     `json:"url_success,omitempty"`
	UrlCallback            string     `json:"url_callback,omitempty"`
	IsPaymentMultiple      bool       `json:"is_payment_multiple,omitempty"`
	Lifetime               uint16     `json:"lifetime,omitempty"`
	ToCurrency             string     `json:"to_currency,omitempty"`
	Subtract               uint8      `json:"subtract,omitempty"`
	AccuarcyPaymentPercent uint8      `json:"accuarcy_payment_percent,omitempty"`
	AdditionalData         string     `json:"additional_data,omitempty"`
	Currencies             []Currency `json:"currencies,omitempty"`
	ExceptCurrencies       []Currency `json:"except_currencies,omitempty"`
	CourseSource           string     `json:"course_source,omitempty"`
	FromReferralCode       string     `json:"from_referral_code,omitempty"`
	DiscountPercent        int8       `json:"discount_percent,omitempty"`
	IsRefresh              bool       `json:"is_refresh,omitempty"`
}

type Payment

type Payment struct {
	UUID                    string    `json:"uuid"`
	OrderId                 string    `json:"order_id"`
	Amount                  string    `json:"amount"`
	PaymentAmount           string    `json:"payment_amount,omitempty"`
	PaymentAmountUSD        string    `json:"payment_amount_usd,omitempty"`
	PayerAmount             string    `json:"payer_amount,omitempty"`
	PayerAmountExchangeRate string    `json:"payer_amount_exchange_rate,omitempty"`
	DiscountPercent         int8      `json:"discount_percent,omitempty"`
	Discount                string    `json:"discount,omitempty"`
	PayerCurrency           string    `json:"payer_currency,omitempty"`
	Currency                string    `json:"currency"`
	MerchantAmount          string    `json:"merchant_amount,omitempty"`
	Network                 string    `json:"network,omitempty"`
	Address                 string    `json:"address,omitempty"`
	From                    string    `json:"from,omitempty"`
	TxId                    string    `json:"txid,omitempty"`
	PaymentStatus           string    `json:"payment_status"`
	Status                  string    `json:"status,omitempty"`
	Url                     string    `json:"url"`
	ExpiredAt               float64   `json:"expired_at"`
	IsFinal                 bool      `json:"is_final"`
	AdditionalData          string    `json:"additional_data,omitempty"`
	Comments                string    `json:"comments,omitempty"`
	CreatedAt               time.Time `json:"created_at"`
	UpdatedAt               time.Time `json:"updated_at"`
}

type PaymentHistoryPaginate

type PaymentHistoryPaginate struct {
	Count          int16  `json:"count"`
	HasPages       bool   `json:"hasPages"`
	NextCursor     string `json:"nextCursor,omitempty"`
	PreviousCursor string `json:"previousCursor,omitempty"`
	PerPage        int16  `json:"perPage"`
}

type PaymentHistoryResponse

type PaymentHistoryResponse struct {
	Payments []*Payment
	Paginate *PaymentHistoryPaginate
}

type PaymentInfoRequest

type PaymentInfoRequest struct {
	PaymentUUID string `json:"uuid,omitempty"`
	OrderId     string `json:"order_id,omitempty"`
}

type RefundRequest

type RefundRequest struct {
	Address     string `json:"address"`
	IsSubtract  bool   `json:"is_subtract"`
	PaymentUUID string `json:"uuid,omitempty"`
	OrderId     string `json:"order_id,omitempty"`
}

type ResendWebhookRequest

type ResendWebhookRequest struct {
	PaymentUUID string `json:"uuid,omitempty"`
	OrderId     string `json:"order_id,omitempty"`
}

type StaticWalletRequest

type StaticWalletRequest struct {
	Currency string `json:"currency"`
	Network  string `json:"network"`
	OrderId  string `json:"order_id"`
	*StaticWalletRequestOptions
}

type StaticWalletRequestOptions

type StaticWalletRequestOptions struct {
	UrlCallback      string `json:"url_callback,omitempty"`
	FromReferralCode string `json:"from_referral_code,omitempty"`
}

type StaticWalletResponse

type StaticWalletResponse struct {
	OrderId    string `json:"order_id"`
	WalletUUID string `json:"wallet_uuid"`
	UUID       string `json:"uuid"`
	Address    string `json:"address"`
	Network    string `json:"network"`
	Currency   string `json:"currency"`
	Url        string `json:"url"`
}

Jump to

Keyboard shortcuts

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