Skip to content
This repository was archived by the owner on Mar 1, 2024. It is now read-only.
/ qiwi Public archive
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ '1.14', '1.20' ]
go-version: [ '1.14', '1.21' ]

steps:
- name: Check out code into the Go module directory
Expand Down
6 changes: 6 additions & 0 deletions notify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ func TestHook(t *testing.T) {
t.Error("Amount is wrong", notify.Payment.Amount.Value, test.want.Payment.Amount.Value)
}

if notify.Type == RefundNotify {
if notify.Refund.RefundSplits[1].Commission.Amount.Value != 0.02 {
t.Error("Split refund amount is wrong")
}
}

}
}

Expand Down
51 changes: 26 additions & 25 deletions payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,32 @@ const (

// Payment main data structure, holds requests and responses on that requests from RSP.
type Payment struct {
token string `json:"-"` // Authtorisation token
apiLink string `json:"-"` // APILink sets payment gateway domain, no trailing slash
siteid string // Same as SiteID, but used for requests, as SiteID sets in responses
payid string // Same as BillID or PaymentID, but used only for requests, BillID sets in responses
PublicKey string `json:"-"` // Merchant identification key String +
SiteID string `json:"siteId,omitempty"` // RSP site identifier
BillID string `json:"billId,omitempty"` // Unique invoice identifier in merchant's system. It must be generated on your side with any means. It could be any sequence of digits and letters. Also you might use underscore _ and dash -. If not used, for each URL opening a new invoice is created. String(200) -
PaymentID string `json:"paymentId,omitempty"` // Payment operation unique identifier in RSP's system
CamptureID string `json:"captureId,omitempty"` // Capture operation unique identifier in RSP's system
RefundID string `json:"refundId,omitempty"` // Refund operation unique identifier in RSP's system
Amount Amount `json:"amount,omitempty"` // Amount of customer order rounded down to 2 digits (always in rubles)
PaymentMethod *PaymentMethod `json:"paymentMethod,omitempty"` // Payment method
Customer *Customer `json:"customer,omitempty"` // Information about the customer
Creation *Time `json:"creationDateTime,omitempty"`
NotifyDate *Time `json:"createddatetime,omitempty"` // Time used in Notify
Expiration *Time `json:"expirationDateTime,omitempty"`
Comment string `json:"comment,omitempty"` // Comment to the invoice
CallbackURL string `json:"callbackUrl,omitempty"` // Callback URL used to receive notification
SuccessURL string `json:"successUrl,omitempty"` // URL for redirect from the QIWI form in case of successful payment. URL should be within the merchant's site.
PayURL string `json:"payUrl,omitempty"` // Payment page on QIWI site
Req *Requirements `json:"requirements,omitempty"`
CustomField *CustomField `json:"customFields,omitempty"`
Flags []string `json:"flags,omitempty"`
Status *Status `json:"status,omitempty"`
Splits []*Split `json:"splits,omitempty"` // https://developer.qiwi.com/en/payments/#payments_split
token string `json:"-"` // Authtorisation token
apiLink string `json:"-"` // APILink sets payment gateway domain, no trailing slash
siteid string // Same as SiteID, but used for requests, as SiteID sets in responses
payid string // Same as BillID or PaymentID, but used only for requests, BillID sets in responses
PublicKey string `json:"-"` // Merchant identification key String +
SiteID string `json:"siteId,omitempty"` // RSP site identifier
BillID string `json:"billId,omitempty"` // Unique invoice identifier in merchant's system. It must be generated on your side with any means. It could be any sequence of digits and letters. Also you might use underscore _ and dash -. If not used, for each URL opening a new invoice is created. String(200) -
PaymentID string `json:"paymentId,omitempty"` // Payment operation unique identifier in RSP's system
CamptureID string `json:"captureId,omitempty"` // Capture operation unique identifier in RSP's system
RefundID string `json:"refundId,omitempty"` // Refund operation unique identifier in RSP's system
Amount Amount `json:"amount,omitempty"` // Amount of customer order rounded down to 2 digits (always in rubles)
PaymentMethod *PaymentMethod `json:"paymentMethod,omitempty"` // Payment method
Customer *Customer `json:"customer,omitempty"` // Information about the customer
Creation *Time `json:"creationDateTime,omitempty"`
NotifyDate *Time `json:"createddatetime,omitempty"` // Time used in Notify
Expiration *Time `json:"expirationDateTime,omitempty"`
Comment string `json:"comment,omitempty"` // Comment to the invoice
CallbackURL string `json:"callbackUrl,omitempty"` // Callback URL used to receive notification
SuccessURL string `json:"successUrl,omitempty"` // URL for redirect from the QIWI form in case of successful payment. URL should be within the merchant's site.
PayURL string `json:"payUrl,omitempty"` // Payment page on QIWI site
Req *Requirements `json:"requirements,omitempty"`
CustomField *CustomField `json:"customFields,omitempty"`
Flags []string `json:"flags,omitempty"`
Status *Status `json:"status,omitempty"`
Splits []*Split `json:"splits,omitempty"` // https://developer.qiwi.com/en/payments/#payments_split
RefundSplits []*RefundSplits `json:"refundSplits,omitempty"`

Error
}
Expand Down
13 changes: 13 additions & 0 deletions refund.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package qiwi

// RefundSplits contains split refund.
type RefundSplits struct {
Split
Commission *RefundSplitCommission `json:"splitCommissions,omitempty"`
}

// RefundSplitCommission contains commission information.
type RefundSplitCommission struct {
Amount *Amount `json:"merchantCms,omitempty"`
UserCms string `json:"userCms,omitempty"`
}
2 changes: 1 addition & 1 deletion request.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func init() {
// newRequest creates new http request to RSP.
func newRequest(ctx context.Context, method, link, apiToken string, payload []byte) (*http.Request, error) {
req, err := http.NewRequestWithContext(ctx, method, link, bytes.NewBuffer(payload))
req.Header.Set("User-Agent", userAgent+"/"+Version)
req.Header.Set("User-Agent", version())
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
req.Header.Set("Authorization", "Bearer "+apiToken)
Expand Down
2 changes: 1 addition & 1 deletion split.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Split struct {
Comment string `json:"comment,omitempty"` // string comment String Comment for the order (optional)
}

// AddSplit without optional fields, see SplitExtra.
// Split without optional fields, see SplitExtra.
func (p *Payment) Split(a Amount, merchid string) *Payment {
return p.SplitExtra(a, merchid, "", "")
}
Expand Down
17 changes: 16 additions & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
package qiwi

import "fmt"

// AppVersion sets version for main application.
var AppVersion string

const (
// Version string.
Version string = "0.3"
Version string = "1.0.0"
userAgent string = "Sendtips-QIWI-Go" // UserAgent name
)

func version() (s string) {
s = fmt.Sprintf("%s/%s", userAgent, Version)

if AppVersion != "" {
s = fmt.Sprintf("%s (%s)", AppVersion, s)
}

return s
}
21 changes: 21 additions & 0 deletions version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package qiwi

import (
"fmt"
"testing"
)

func TestVersion(t *testing.T) {
s := fmt.Sprintf("%s/%s", userAgent, Version)

if s != version() {
t.Error("Version string is invalid")
}

AppVersion = "somever/1.0"
s = fmt.Sprintf("%s (%s/%s)", AppVersion, userAgent, Version)

if s != version() {
t.Error("Version string is invalid")
}
}