From 0bb11c2e985cfe34c1e591ba478eb3f77b5e4d90 Mon Sep 17 00:00:00 2001 From: luistarkbank Date: Tue, 16 Jul 2024 14:17:11 -0300 Subject: [PATCH] Add get and query methods --- CHANGELOG.md | 2 + index.js | 3 +- sdk/merchantPurchase/index.js | 1 + sdk/merchantPurchase/merchantPurchase.js | 66 ++++++++++++++++++++++++ sdk/merchantSession/merchantSession.js | 2 +- tests/testMerchantPurchase.js | 22 ++++++++ tests/testMerchantSession.js | 2 +- 7 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 sdk/merchantPurchase/index.js create mode 100644 sdk/merchantPurchase/merchantPurchase.js create mode 100644 tests/testMerchantPurchase.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bcf18e..a422a4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ Given a version number MAJOR.MINOR.PATCH, increment: ## [Unreleased] +### Added +- query and get request methods ## [2.26.0] - 2024-07-15 ### Added diff --git a/index.js b/index.js index 9be98dd..fc54780 100644 --- a/index.js +++ b/index.js @@ -64,6 +64,7 @@ exports.organization = require('./sdk/user/organization.js') exports.request = require('./sdk/request/request.js') exports.merchantSession = require('./sdk/merchantSession/merchantSession.js') exports.merchantSessionPurchase = require('./sdk/merchantSession/purchase.js') +exports.merchantPurchase = require('./sdk/merchantPurchase/merchantPurchase.js') // Classes @@ -102,4 +103,4 @@ exports.Event = exports.event.Event; exports.Institution = exports.institution.Institution; exports.PaymentPreview = exports.paymentPreview.PaymentPreview; exports.MerchantSession = exports.merchantSession.MerchantSession; -exports.MerchantSessionPurchase = exports.merchantSessionPurchase.MerchantSessionPurchase; +exports.MerchantPurchase = exports.merchantPurchase.MerchantPurchase; diff --git a/sdk/merchantPurchase/index.js b/sdk/merchantPurchase/index.js new file mode 100644 index 0000000..46ade7c --- /dev/null +++ b/sdk/merchantPurchase/index.js @@ -0,0 +1 @@ +const merchantPurchase = require('./merchantPurchase.js') \ No newline at end of file diff --git a/sdk/merchantPurchase/merchantPurchase.js b/sdk/merchantPurchase/merchantPurchase.js new file mode 100644 index 0000000..a86df56 --- /dev/null +++ b/sdk/merchantPurchase/merchantPurchase.js @@ -0,0 +1,66 @@ +const Resource = require('starkcore').Resource; +const rest = require('../utils/rest.js'); +const check = require('starkcore').check; + +class MerchantPurchase extends Resource { + + /** + * Check out our API Documentation at https://starkbank.com/docs/api#merchant-purchase + */ + + constructor({id, amount, installmentCount, cardExpiration, cardNumber, cardSecurityCode, + holderName, holderEmail, holderPhone, fundingType, billingCountryCode, billingCity, billingStateCode, + billingStreetLine1, billingStreetLine2, billingZipCode, metadata, cardEnding, cardId, challengeMode, + challengeUrl, created, currencyCode, endToEndId, fee, network, source, status, tags, updated + }){ + super(id) + this.amount = amount + this.installmentCount = installmentCount + this.cardExpiration = cardExpiration + this.cardNumber = cardNumber + this.cardSecurityCode = cardSecurityCode + this.holderName = holderName + this.holderEmail = holderEmail + this.holderPhone = holderPhone + this.fundingType = fundingType + this.billingCountryCode = billingCountryCode + this.billingCity = billingCity + this.billingStateCode = billingStateCode + this.billingStreetLine1 = billingStreetLine1 + this.billingStreetLine2 = billingStreetLine2 + this.billingZipCode = billingZipCode + this.metadata = metadata + this.cardEnding = cardEnding + this.cardId = cardId + this.challengeMode = challengeMode + this.challengeUrl = challengeUrl + this.created = created + this.currencyCode = currencyCode + this.endToEndId = endToEndId + this.fee = fee + this.network = network + this.source = source + this.status = status + this.tags = tags + this.updated = updated + } +} + +exports.MerchantPurchase = MerchantPurchase; +let resource = {'class': exports.MerchantPurchase, 'name': 'MerchantPurchase'}; + +exports.query = async function ({ limit, after, before, status, tags, ids, user} = {}) { + let query = { + limit: limit, + after: check.date(after), + before: check.date(before), + status: status, + tags: tags, + ids: ids, + }; + return rest.getList(resource, query, user); +}; + +exports.get = async function (id, {user} = {}) { + return rest.getId(resource, id, user); +}; diff --git a/sdk/merchantSession/merchantSession.js b/sdk/merchantSession/merchantSession.js index ba65e89..09b534a 100644 --- a/sdk/merchantSession/merchantSession.js +++ b/sdk/merchantSession/merchantSession.js @@ -10,7 +10,7 @@ const parseObjects = require('../utils/parse.js').parseObjects; class MerchantSession extends Resource { /** - * Check out our API Documentation at https://starkbank.com/merchant-session + * Check out our API Documentation at https://starkbank.com/docs/api#merchant-session */ constructor({id, allowedFundingTypes, allowedInstallments, allowedIps, challengeMode, created, expiration, status, tags, updated, uuid}){ diff --git a/tests/testMerchantPurchase.js b/tests/testMerchantPurchase.js new file mode 100644 index 0000000..6af6b42 --- /dev/null +++ b/tests/testMerchantPurchase.js @@ -0,0 +1,22 @@ +const assert = require('assert'); +const starkbank = require('../index.js'); + +starkbank.user = require('./utils/user').exampleProject; + +describe('MerchantSessionQuery', function(){ + this.timeout(10000); + it('test_success', async () => { + let merchantPurchases = await starkbank.merchantPurchase.query({limit: 3}); + for await (let merchantPurchase of merchantPurchases) { + assert(typeof merchantPurchase.id == 'string'); + } + }); +}); + +describe('MerchantSessionGet', function(){ + this.timeout(10000); + it('test_success', async () => { + let merchantPurchase = await starkbank.merchantPurchase.get(5019538395496448); + assert(typeof merchantPurchase.id == 'string'); + }); +}); \ No newline at end of file diff --git a/tests/testMerchantSession.js b/tests/testMerchantSession.js index 5b23b63..21a65f6 100644 --- a/tests/testMerchantSession.js +++ b/tests/testMerchantSession.js @@ -5,7 +5,7 @@ const generateExampleMerchantSessionPurchaseJson = require('./utils/merchantSess starkbank.user = require('./utils/user').exampleProject; -describe('MerchantSession', function(){ +describe('MerchantSessionCreate', function(){ this.timeout(10000); it('test_success', async () => { let merchantSessionJson = generateExampleMerchantSessionJson()