-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathx1.go
86 lines (78 loc) · 2.12 KB
/
x1.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) 2016 The Constantin Karataev. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd.
//
// Sending invoice from merchant to customer.
// https://wiki.wmtransfer.com/projects/webmoney/wiki/Interface_X1
//use in client
/*w = new WmClient {Wmid: "", Cert:"", Key:""}
s,_ := w.SendInvoice(new Invoice{
OrderId: "",
CustomerWmid:"",
....
})
s.Ts*/
package webmoney
import (
"encoding/xml"
)
type Invoice struct {
XMLName xml.Name `xml:"invoice"`
OrderId string `xml:"orderid"`
CustomerWmid string `xml:"customerwmid"`
StorePurse string `xml:"storepurse"`
Amount string `xml:"amount"`
Desc string `xml:"desc"`
Address string `xml:"address"`
Period string `xml:"period"`
Expiration string `xml:"expiration"`
OnlyAuth string `xml:"onlyauth"`
Lmi_shop_id string `xml:"lmi_shop_id"`
}
func (i Invoice) GetSignSource(reqn string) (string, error) {
desc, err := Utf8ToWin(i.Desc)
if err != nil {
return "", err
}
address, err := Utf8ToWin(i.Address)
if err != nil {
return "", err
}
return string(i.OrderId) +
i.CustomerWmid +
i.StorePurse +
i.Amount +
desc +
address +
i.Period +
i.Expiration +
reqn, nil
}
type InvoiceResponse struct {
Id string `xml:"id,attr"`
Ts string `xml:"ts,attr"`
OrderId string `xml:"orderid"`
CustomerWmid string `xml:"customerwmid"`
StorePurse string `xml:"storepurse"`
Amount string `xml:"amount"`
Desc string `xml:"desc"`
Address string `xml:"address"`
Period string `xml:"period"`
Expiration string `xml:"expiration"`
State string `xml:"state"`
DateCrt string `xml:"datecrt"`
DateUpd string `xml:"dateupd"`
WmTranId string `xml:"wmtranid"`
}
func (w *WmClient) SendInvoice(i Invoice) (InvoiceResponse, error) {
X := W3s{
Request: i,
Interface: XInterface{Name: "Invoice", Type: "w3s"},
Client: w,
}
result := InvoiceResponse{}
err := X.getResult(&result)
return result, err
}