Skip to content

Commit

Permalink
Merge pull request #171 from phroca/rc-v3.4.2
Browse files Browse the repository at this point in the history
Add method giftCardBuyCode in order to create a dual-token gift card
  • Loading branch information
alplabin authored Oct 1, 2024
2 parents 3caca37 + f8d7d34 commit 83f9f46
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 3.4.2 - 2024-09-24
### Added
- Add GiftCard endpoint:
- `POST /sapi/v1/giftcard/buyCode` to create a dual-token gift card

## 3.4.1 - 2024-08-19
### Updated
- Updated dependencies
Expand Down
33 changes: 33 additions & 0 deletions __tests__/spot/gift_card/giftCardBuyCode.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* global describe, it, expect */
const MissingParameterError = require('../../../src/error/missingParameterError')
const { nockPostMock, buildQueryString, SpotClient } = require('../../testUtils/testSetup')

const {
mockResponse,
amount
} = require('../../testUtils/mockData')

const baseToken = 'USDT'
const faceToken = 'BNB'

describe('#giftCardBuyCode', () => {
it.each([
[undefined, undefined, undefined], ['', '', ''], [null, null, null],
[undefined, faceToken, undefined], ['', faceToken, ''], [null, faceToken, null],
[baseToken, undefined, undefined], [baseToken, '', ''], [baseToken, null, null],
[undefined, undefined, amount], ['', '', amount], [baseToken, faceToken, null]
])('should throw MissingParameterError given missing params', (baseToken, faceToken, amount) => {
expect(() => {
SpotClient.giftCardBuyCode(baseToken, faceToken, amount)
}).toThrow(MissingParameterError)
})

it('should return binance code info', () => {
nockPostMock(`/sapi/v1/giftcard/buyCode?${buildQueryString({ baseToken, faceToken, baseTokenAmount: amount })}`)(mockResponse)

return SpotClient.giftCardBuyCode(baseToken, faceToken, amount).then(response => {
expect(response).toBeDefined()
expect(response.data).toEqual(mockResponse)
})
})
})
10 changes: 10 additions & 0 deletions examples/spot/gift_card/giftCardBuyCode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict'

const Spot = require('../../../src/spot')

const apiKey = ''
const apiSecret = ''
const client = new Spot(apiKey, apiSecret)

client.giftCardBuyCode('BUSD', 'BNB', 10).then(response => client.logger.log(response.data))
.catch(error => client.logger.error(error))
24 changes: 24 additions & 0 deletions src/modules/restful/giftCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,30 @@ const GiftCard = superclass => class extends superclass {
)
}

/**
* Create a dual-token gift card (fixed value, discount feature) (TRADE)<br>
*
* POST /sapi/v1/giftcard/buyCode<br>
*
* {@link https://binance-docs.github.io/apidocs/spot/en/#create-a-dual-token-gift-card-fixed-value-discount-feature-trade}
*
* @param {baseToken} baseToken - The token you want to pay, example: BUSD
* @param {faceToken} faceToken - The token you want to buy, example: BNB. If faceToken = baseToken, it's the same as createCode endpoint.
* @param {baseTokenAmount} amount - The base token asset quantity
* @param {discount} discount - Stablecoin-denominated card discount percentage
* @param {object} [options]
* @param {number} [options.recvWindow] - The value cannot be greater than 60000
*/
giftCardBuyCode (baseToken, faceToken, baseTokenAmount, discount, options = {}) {
validateRequiredParameters({ baseToken, faceToken, baseTokenAmount })

return this.signRequest(
'POST',
'/sapi/v1/giftcard/buyCode',
Object.assign(options, { baseToken, faceToken, baseTokenAmount, discount })
)
}

/**
* Redeem a Binance Code (USER_DATA)<br>
*
Expand Down

0 comments on commit 83f9f46

Please sign in to comment.