qiwi

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: MIT Imports: 8 Imported by: 0

README

qiwi-bill-payments-go-sdk GoDoc

Golang SDK for QIWI Payments.

Installation

go get github.com/RinatNamazov/qiwi-bill-payments-go-sdk

Example

package main

import (
	"fmt"
	"time"

	"github.com/RinatNamazov/qiwi-bill-payments-go-sdk"
	"github.com/google/uuid"
)

func main() {
	qiwiApi := qiwi.NewQiwiBillPaymentsAPI("SecretKey")

	billInfo := qiwi.CreateBillInfo{
		BillId:             uuid.New().String(),
		Comment:            "Donation for coffee.",
		ExpirationDateTime: time.Now().Add(time.Hour),
	}
	billInfo.Amount.SetValueNumber(100)
	billInfo.Amount.Currency = "RUB"

	billResp, err := qiwiApi.CreateBill(billInfo)
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println("Amount: " + billInfo.Amount.Value + " " + billInfo.Amount.Currency +
			"\nBill ID: " + billInfo.BillId +
			"\nFor payment follow the link:\n" + billResp.PayUrl)
	}
}

License

The code in this repository is licensed under MIT.

Copyright (c) 2021 RINWARES, Rinat Namazov

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

View Source
const (
	WAITING  = "WAITING"  // Invoice issued awaiting for payment.
	REJECTED = "REJECTED" // Invoice rejected by customer.
	EXPIRED  = "EXPIRED"  // Invoice expired. Invoice not paid.
)

Invoice Payment Statuses

View Source
const (
	PARTIAL = "PARTIAL" // The partial refund of the invoice amount.
	FULL    = "FULL"    // The full refund of the invoice amount.
)

The refund status enum.

Variables

This section is empty.

Functions

This section is empty.

Types

type BillResponse

type BillResponse struct {
	SiteId             string         `json:"siteId"`             // The merchant’s site identifier in API.
	BillId             string         `json:"billId"`             // The unique invoice identifier in the merchant’s system.
	Amount             MoneyAmount    `json:"amount"`             // The invoice amount info.
	Status             ResponseStatus `json:"status"`             // The invoice status info.
	Comment            string         `json:"comment"`            // The comment to the invoice.
	Customer           Customer       `json:"customer"`           // The customer info.
	CreationDateTime   time.Time      `json:"creationDateTime"`   // The dateTime of the invoice creation.
	ExpirationDateTime time.Time      `json:"expirationDateTime"` // The expiration date of the pay form link.
	PayUrl             string         `json:"payUrl"`             // The pay form link.
	CustomFields       CustomFields   `json:"customFields"`       // The invoice additional data.
}

BillResponse is the invoice response.

type CreateBillInfo

type CreateBillInfo struct {
	BillId             string      `json:"billId"`             // The unique invoice identifier in merchant's system.
	Amount             MoneyAmount `json:"amount"`             // The invoice amount info.
	Comment            string      `json:"comment"`            // The invoice commentary.
	ExpirationDateTime time.Time   `json:"expirationDateTime"` // The invoice due date.
	Customer           Customer    `json:"customer"`           // The customer's info.
	SuccessUrl         string      `json:"successUrl"`         // The URL to which the client will be redirected in case of successful payment.
	ThemeCode          string      `json:"-"`                  // The style theme code.
}

CreateBillInfo is create issue info.

func (*CreateBillInfo) GetCreateBillRequest

func (m *CreateBillInfo) GetCreateBillRequest() CreateBillRequest

GetCreateBillRequest returns a create invoice request.

type CreateBillRequest

type CreateBillRequest struct {
	Amount             MoneyAmount  `json:"amount"`             // The invoice amount witch currency.
	Comment            string       `json:"comment"`            // The invoice commentary.
	ExpirationDateTime time.Time    `json:"expirationDateTime"` // The invoice expiration date.
	Customer           Customer     `json:"customer"`           // The customer's info.
	CustomFields       CustomFields `json:"customFields"`       // The invoice additional data.
}

CreateBillRequest is create issue request.

type CustomFields

type CustomFields struct {
	ApiClient        string `json:"apiClient"`        // // The API client name.
	ApiClientVersion string `json:"apiClientVersion"` // The API client version.
	ThemeCode        string `json:"themeCode"`        // The style theme code.
}

CustomFields is the invoice additional data.

type Customer

type Customer struct {
	Email   string `json:"email"`   // The client's e-mail.
	Account string `json:"account"` // The client's identifier in merchant's system.
	Phone   string `json:"phone"`   // The phone number to which invoice issued.
}

Customer is the customer's info.

type ErrorResponse

type ErrorResponse struct {
	ServiceName string    `json:"serviceName"` // The service name.
	ErrorCode   string    `json:"errorCode"`   // The error code.
	Description string    `json:"description"` // The description.
	UserMessage string    `json:"userMessage"` // The user message.
	DateTime    time.Time `json:"dateTime"`    // The dateTime.
	TraceId     string    `json:"traceId"`     // The trace ID.
}

ErrorResponse is the API error response.

func (ErrorResponse) Error

func (m ErrorResponse) Error() string

Error returns a formatted error string.

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient is HTTP client.

type MoneyAmount

type MoneyAmount struct {
	Value    string `json:"value"`    // The invoice amount value.
	Currency string `json:"currency"` // The invoice currency value.
}

MoneyAmount is the invoice amount info.

func (*MoneyAmount) GetValueNumber

func (m *MoneyAmount) GetValueNumber() float64

GetValueNumber returns the amount in float.

func (*MoneyAmount) SetValueNumber

func (m *MoneyAmount) SetValueNumber(value float64)

SetValueString sets the amount from a float.

func (*MoneyAmount) SetValueString

func (m *MoneyAmount) SetValueString(value string) error

SetValueString sets the amount from a string.

type Notification added in v1.1.0

type Notification struct {
	BillResponse
	Version string `json:"version"` // The notification version.
}

Notification is the invoice payment notification.

type PaymentInfo

type PaymentInfo struct {
	PublicKey  string      `json:"publicKey"`  // The merchant public key.
	Amount     MoneyAmount `json:"amount"`     // The invoice amount.
	BillId     string      `json:"billId"`     // Unique invoice identifier in merchant’s system.
	SuccessUrl string      `json:"successUrl"` // The URL to which the client will be redirected in case of successful payment.
	ThemeCode  string      `json:"-"`          // The style theme code..
}

PaymentInfo is the invoice data are put in Pay Form URL.

type QiwiBillPaymentsAPI

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

QiwiBillPaymentsAPI for rest v3.

func NewQiwiBillPaymentsAPI

func NewQiwiBillPaymentsAPI(secretKey string) *QiwiBillPaymentsAPI

NewQiwiBillPaymentsAPI creates a new QiwiBillPaymentsAPI instance.

func NewQiwiBillPaymentsAPIWithClient

func NewQiwiBillPaymentsAPIWithClient(secretKey string, httpClient HTTPClient) *QiwiBillPaymentsAPI

NewQiwiBillPaymentsAPIWithClient creates a new QiwiBillPaymentsAPI instance and allows you to pass a http.Client.

func (*QiwiBillPaymentsAPI) CancelBill

func (m *QiwiBillPaymentsAPI) CancelBill(billId string) (*BillResponse, error)

CancelBill cancelling unpaid bill.

func (*QiwiBillPaymentsAPI) CreateBill

func (m *QiwiBillPaymentsAPI) CreateBill(billInfo CreateBillInfo) (*BillResponse, error)

CreateBill creating bill.

func (*QiwiBillPaymentsAPI) CreatePaymentForm

func (m *QiwiBillPaymentsAPI) CreatePaymentForm(paymentInfo PaymentInfo) string

CreatePaymentForm creating checkout link.

func (*QiwiBillPaymentsAPI) GetBillInfo

func (m *QiwiBillPaymentsAPI) GetBillInfo(billId string) (*BillResponse, error)

GetBillInfo getting bill info.

func (*QiwiBillPaymentsAPI) GetRefundInfo added in v1.1.0

func (m *QiwiBillPaymentsAPI) GetRefundInfo(billId, refundId string) (*RefundResponse, error)

GetRefundInfo getting refund info. Method is not available for individuals.

func (*QiwiBillPaymentsAPI) Refund added in v1.1.0

func (m *QiwiBillPaymentsAPI) Refund(billId, refundId string, amount MoneyAmount) (*RefundResponse, error)

Refund paid bill. Method is not available for individuals.

func (*QiwiBillPaymentsAPI) SetSecretKey

func (m *QiwiBillPaymentsAPI) SetSecretKey(secretKey string)

SetSecretKey sets new secret key.

type RefundBillRequest added in v1.1.0

type RefundBillRequest struct {
	Amount MoneyAmount `json:"amount"` // The refund amount.
}

RefundBillRequest is the refund request.

type RefundResponse added in v1.1.0

type RefundResponse struct {
	Amount   MoneyAmount `json:"amount"`   // The invoice amount.
	DateTime time.Time   `json:"dateTime"` // The dateTime of refund processing.
	RefundId string      `json:"refundId"` // Unique refund identifier in merchant’s system.
	Status   string      `json:"status"`   // The refund status.
}

RefundResponse is the refund response.

type ResponseStatus

type ResponseStatus struct {
	Value           string    `json:"value"`           // The status value.
	ChangedDateTime time.Time `json:"changedDateTime"` // The status refresh dateTime.
}

ResponseStatus is the invoice status info.

Jump to

Keyboard shortcuts

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