Skip to content

Instantly share code, notes, and snippets.

@nvhbk16k53
Last active May 16, 2017 08:41
Show Gist options
  • Save nvhbk16k53/36fd3db4aae15c2c6218b33e5737c918 to your computer and use it in GitHub Desktop.
Save nvhbk16k53/36fd3db4aae15c2c6218b33e5737c918 to your computer and use it in GitHub Desktop.
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