-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpayment.go
62 lines (59 loc) · 1.77 KB
/
payment.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
package irankish
import (
"errors"
"fmt"
)
type Payment struct {
Amount string
merchantId string
InvoiceId string
PaymentId string
SpecialPaymentId string
CallbackUrl string
Description string
ExtraParameter1 string
ExtraParameter2 string
ExtraParameter3 string
ExtraParameter4 string
}
func (p *Payment) getTags() (tagsArray []string, err error) {
tags := map[string]string{
"amount": "<ns1:amount>%s</ns1:amount>",
"merchantId": "<ns1:merchantId>%s</ns1:merchantId>",
"invoiceId": "<ns1:invoiceNo>%s</ns1:invoiceNo>",
"revertUrl": "<ns1:revertURL>%s</ns1:revertURL>",
"paymentId": "<ns1:paymentId>%s</ns1:paymentId>",
"specialPaymentId": "<ns1:specialPaymentId>%s</ns1:specialPaymentId>",
"description": "<ns1:description>%s</ns1:description>",
}
if p.Amount == "" {
err = errors.New("empty_amount")
return
}
if p.merchantId == "" {
err = errors.New("empty_merchant_id")
return
}
if p.InvoiceId == "" {
err = errors.New("empty_invoice_id")
return
}
if p.CallbackUrl == "" {
err = errors.New("empty_callback_url")
return
}
tagsArray = append(tagsArray, fmt.Sprintf(tags["amount"], p.Amount))
tagsArray = append(tagsArray, fmt.Sprintf(tags["merchantId"], p.merchantId))
tagsArray = append(tagsArray, fmt.Sprintf(tags["invoiceId"], p.InvoiceId))
tagsArray = append(tagsArray, fmt.Sprintf(tags["revertUrl"], p.CallbackUrl))
if p.PaymentId != "" {
tagsArray = append(tagsArray, fmt.Sprintf(tags["paymentId"], p.PaymentId))
}
if p.SpecialPaymentId != "" {
tagsArray = append(tagsArray, fmt.Sprintf(tags["specialPaymentId"], p.SpecialPaymentId))
}
if p.Description != "" {
tagsArray = append(tagsArray, fmt.Sprintf(tags["description"], p.Description))
}
return
}