Skip to content

Commit

Permalink
Merge pull request #129 from starkbank/feature/merchant-session-reque…
Browse files Browse the repository at this point in the history
…st-methods

Add get and query methods
  • Loading branch information
luistarkbank authored Jul 16, 2024
2 parents f0ae7aa + 0bb11c2 commit 46764f7
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
1 change: 1 addition & 0 deletions sdk/merchantPurchase/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const merchantPurchase = require('./merchantPurchase.js')
66 changes: 66 additions & 0 deletions sdk/merchantPurchase/merchantPurchase.js
Original file line number Diff line number Diff line change
@@ -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);
};
2 changes: 1 addition & 1 deletion sdk/merchantSession/merchantSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}){
Expand Down
22 changes: 22 additions & 0 deletions tests/testMerchantPurchase.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
2 changes: 1 addition & 1 deletion tests/testMerchantSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 46764f7

Please sign in to comment.