Last active
May 16, 2017 08:41
-
-
Save nvhbk16k53/36fd3db4aae15c2c6218b33e5737c918 to your computer and use it in GitHub Desktop.
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
func newOrderInfo(cardType string, value int64, quantity int) string { | |
orderInfo := []map[string]interface{}{ | |
{ | |
"type": cardType, | |
"value": strconv.FormatInt(value, 10), | |
"quantity": quantity, | |
}, | |
} | |
orderData, err := json.Marshal(orderInfo) | |
if err != nil { | |
panic(err) // Impossible to failed. | |
} | |
return string(orderData) | |
} | |
func (c *DealerClient) BuyCards( | |
cardType string, value int64, quantity int, | |
) (*CardsResponse, error) { | |
transID, err := newDeveloperTransID() | |
if err != nil { | |
log.WithError(err).Error("Could not generate developer transaction ID") | |
return nil, err | |
} | |
orderInfo := newOrderInfo(cardType, value, quantity) | |
payload := url.Values{} | |
payload.Add("apiKey", c.apiKey) | |
payload.Add("orderInfo", orderInfo) | |
payload.Add("transID", transID) | |
payload.Add("signature", crypto.SumSHA1(c.apiKey+transID+orderInfo+c.secretKey)) | |
resp, err := c.PostForm(c.buyCardsEndpoint(), payload) | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment