-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
152 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,95 @@ | ||
package qiwiP2P | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"time" | ||
) | ||
|
||
type Bill struct { | ||
Currency string | ||
Value float32 | ||
Comment string | ||
ExpirationDateTime time.Time | ||
CustomerPhone string | ||
CustomerEmail string | ||
CustomerAccount string | ||
CustomFields map[string]string | ||
Amount Amount `json:"amount"` | ||
Comment string `json:"comment"` | ||
ExpirationDateTime string `json:"expirationDateTime"` | ||
Customer Customer `json:"customer"` | ||
CustomFields map[string]string `json:"customFields"` | ||
} | ||
|
||
type Amount struct { | ||
Currency string `json:"currency"` | ||
Value string `json:"value"` | ||
} | ||
|
||
type Status struct { | ||
Value string `json:"value"` | ||
ChangedDateTime string `json:"changedDateTime"` | ||
} | ||
|
||
type Customer struct { | ||
Phone string `json:"phone"` | ||
Email string `json:"email"` | ||
Account string `json:"account"` | ||
} | ||
|
||
func CreateBill() *Bill { | ||
return &Bill{ | ||
Currency: "RUB", | ||
Value: 1, | ||
ExpirationDateTime: time.Now().UTC().Add(time.Hour * 3), | ||
Amount: Amount{}, | ||
Customer: Customer{}, | ||
ExpirationDateTime: time.Now().UTC().Add(time.Hour * 3).Format("2006-01-02T15:01:05+00:00"), | ||
CustomFields: make(map[string]string), | ||
} | ||
} | ||
|
||
func (b *Bill) SetTheme(theme string) *Bill { | ||
b.CustomFields["themeCode"] = theme | ||
return b | ||
} | ||
|
||
func (b *Bill) SetPaySourcesFilter(filter string) *Bill { | ||
b.CustomFields["paySourcesFilter"] = filter | ||
return b | ||
} | ||
|
||
func (b *Bill) SetCurrency(currency string) *Bill { | ||
b.Currency = currency | ||
b.Amount.Currency = currency | ||
return b | ||
} | ||
|
||
func (b *Bill) SetValue(value float32) *Bill { | ||
b.Value = value | ||
b.Amount.Value = fmt.Sprintf("%.2f", value) | ||
return b | ||
} | ||
|
||
func (b *Bill) SetComment(comment string) *Bill { | ||
b.Comment = comment | ||
return b | ||
} | ||
|
||
func (b *Bill) SetExpirationDateTime(time time.Time) *Bill { | ||
b.ExpirationDateTime = time.UTC().Format("2006-01-02T15:01:05+00:00") | ||
return b | ||
} | ||
|
||
func (b *Bill) SetCustomerPhone(phone string) *Bill { | ||
b.Customer.Phone = phone | ||
return b | ||
} | ||
|
||
func (b *Bill) SetCustomerEmail(email string) *Bill { | ||
b.Customer.Email = email | ||
return b | ||
} | ||
|
||
func (b *Bill) SetCustomerAccount(account string) *Bill { | ||
b.Customer.Account = account | ||
return b | ||
} | ||
|
||
func (b *Bill) SetCustomField(field string, value string) *Bill { | ||
b.CustomFields[field] = value | ||
return b | ||
} | ||
|
||
func (b *Bill) toJSON() string { | ||
return fmt.Sprintf( | ||
"{\"amount\":{\"currency\":\"%s\",\"value\": \"%.2f\"}," + | ||
"\"expirationDateTime\": \"%s\"}", | ||
b.Currency, | ||
b.Value, | ||
b.ExpirationDateTime.Format("2006-01-02T15:01:05+00:00")) | ||
arr, _ := json.Marshal(b) | ||
return string(arr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package qiwiP2P | ||
|
||
type BillResponse struct { | ||
SiteId string `json:"siteId"` | ||
BillId string `json:"billId"` | ||
Amount Amount `json:"amount"` | ||
Status Status `json:"status"` | ||
Customer Customer `json:"customer"` | ||
CustomFields map[string]string `json:"customFields"` | ||
Comment string `json:"comment"` | ||
CreationDateTime string `json:"creationDateTime"` | ||
ExpirationDateTime string `json:"expirationDateTime"` | ||
PayUrl string `json:"payUrl"` | ||
} | ||
|
||
type RequestError struct { | ||
ServiceName string `json:"serviceName"` | ||
ErrorCode string `json:"errorCode"` | ||
Description string `json:"description"` | ||
UserMessage string `json:"userMessage"` | ||
DateTime string `json:"dateTime"` | ||
TraceId string `json:"traceId"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.