From 782260019e3e7107d9837d9d4ff7b40663ac4841 Mon Sep 17 00:00:00 2001 From: "Igor A. Melekhine" Date: Tue, 8 Aug 2023 11:18:47 +0300 Subject: [PATCH 1/9] appver --- request.go | 2 +- version.go | 17 ++++++++++++++++- version_test.go | 22 ++++++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 version_test.go diff --git a/request.go b/request.go index 50552b0..25cf257 100644 --- a/request.go +++ b/request.go @@ -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) diff --git a/version.go b/version.go index f53dfe4..3157cf7 100644 --- a/version.go +++ b/version.go @@ -1,7 +1,22 @@ package qiwi +import "fmt" + +// AppVersion for version string of main application version +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 +} diff --git a/version_test.go b/version_test.go new file mode 100644 index 0000000..d041b5f --- /dev/null +++ b/version_test.go @@ -0,0 +1,22 @@ +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") + } + +} From 071915b201ddb07064f23d0cd982c59322bcd071 Mon Sep 17 00:00:00 2001 From: "Igor A. Melekhine" Date: Tue, 8 Aug 2023 11:21:28 +0300 Subject: [PATCH 2/9] comment --- version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.go b/version.go index 3157cf7..ec03d7c 100644 --- a/version.go +++ b/version.go @@ -2,7 +2,7 @@ package qiwi import "fmt" -// AppVersion for version string of main application version +// AppVersion sets version for main application. var AppVersion string const ( From 68d85bf64d30aad35d68f69353174296f639a109 Mon Sep 17 00:00:00 2001 From: "Igor A. Melekhine" Date: Tue, 8 Aug 2023 11:30:39 +0300 Subject: [PATCH 3/9] gofmt --- version.go | 4 ++-- version_test.go | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/version.go b/version.go index ec03d7c..d622a25 100644 --- a/version.go +++ b/version.go @@ -13,10 +13,10 @@ const ( func version() (s string) { s = fmt.Sprintf("%s/%s", userAgent, Version) - + if AppVersion != "" { s = fmt.Sprintf("%s (%s)", AppVersion, s) } - + return s } diff --git a/version_test.go b/version_test.go index d041b5f..76b9ed8 100644 --- a/version_test.go +++ b/version_test.go @@ -7,16 +7,15 @@ import ( 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") } - } From 6a4314169e9686c616391cd4e8500167d679ee47 Mon Sep 17 00:00:00 2001 From: "Igor A. Melekhine" Date: Tue, 8 Aug 2023 13:25:03 +0300 Subject: [PATCH 4/9] RefundSplits --- payment.go | 51 ++++++++++++++++++++++++++------------------------- refund.go | 12 ++++++++++++ split.go | 2 +- 3 files changed, 39 insertions(+), 26 deletions(-) create mode 100644 refund.go diff --git a/payment.go b/payment.go index 57c058e..90c2f1f 100644 --- a/payment.go +++ b/payment.go @@ -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 } diff --git a/refund.go b/refund.go new file mode 100644 index 0000000..a0ab3f8 --- /dev/null +++ b/refund.go @@ -0,0 +1,12 @@ +package qiwi + +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"` +} diff --git a/split.go b/split.go index 0362e9c..b0cdb42 100644 --- a/split.go +++ b/split.go @@ -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, "", "") } From babbc719b2752da0e85dd422c7e9456f4dd150c3 Mon Sep 17 00:00:00 2001 From: "Igor A. Melekhine" Date: Tue, 8 Aug 2023 13:26:56 +0300 Subject: [PATCH 5/9] lint --- refund.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/refund.go b/refund.go index a0ab3f8..cf5a5b4 100644 --- a/refund.go +++ b/refund.go @@ -1,11 +1,12 @@ package qiwi +// RefundSplits contains split refund. type RefundSplits struct { Split Commission *RefundSplitCommission `json:"splitCommissions,omitempty"` } -// RefundSplitCommission contains commission information +// RefundSplitCommission contains commission information. type RefundSplitCommission struct { Amount *Amount `json:"merchantCms,omitempty"` UserCms string `json:"userCms,omitempty"` From b17c5b0f6e3c5b41391e601d8bac26b273f4774e Mon Sep 17 00:00:00 2001 From: "Igor A. Melekhine" Date: Tue, 8 Aug 2023 13:34:13 +0300 Subject: [PATCH 6/9] refund test --- notify_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/notify_test.go b/notify_test.go index c92b444..9116a47 100644 --- a/notify_test.go +++ b/notify_test.go @@ -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 refuns amount is wrong") + } + } + } } From d06766efda36aa64a016e27509e98a4916fddec7 Mon Sep 17 00:00:00 2001 From: "Igor A. Melekhine" Date: Wed, 9 Aug 2023 10:43:33 +0300 Subject: [PATCH 7/9] typo --- notify_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notify_test.go b/notify_test.go index 9116a47..26c3fc3 100644 --- a/notify_test.go +++ b/notify_test.go @@ -211,7 +211,7 @@ func TestHook(t *testing.T) { if notify.Type == RefundNotify { if notify.Refund.RefundSplits[1].Commission.Amount.Value != 0.02 { - t.Error("Split refuns amount is wrong") + t.Error("Split refunds amount is wrong") } } From 8a36ed8aac13b4b593455de1c6910d58636e3ba7 Mon Sep 17 00:00:00 2001 From: "Igor A. Melekhine" Date: Wed, 9 Aug 2023 10:44:03 +0300 Subject: [PATCH 8/9] typo --- notify_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notify_test.go b/notify_test.go index 26c3fc3..6eacb28 100644 --- a/notify_test.go +++ b/notify_test.go @@ -211,7 +211,7 @@ func TestHook(t *testing.T) { if notify.Type == RefundNotify { if notify.Refund.RefundSplits[1].Commission.Amount.Value != 0.02 { - t.Error("Split refunds amount is wrong") + t.Error("Split refund amount is wrong") } } From ac817f7818bc3c80f2d234926ac7492c1490654d Mon Sep 17 00:00:00 2001 From: "Igor A. Melekhine" Date: Wed, 9 Aug 2023 10:44:52 +0300 Subject: [PATCH 9/9] v1.21 --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 8d0cb78..52aac0a 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -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