Skip to content

Commit

Permalink
Merge pull request #131 from starkbank/fix/merchant-purchase-log
Browse files Browse the repository at this point in the history
Fix merchantPurchase log
  • Loading branch information
luistarkbank authored Jul 18, 2024
2 parents 80e95aa + 59290e1 commit 5cfc74f
Show file tree
Hide file tree
Showing 14 changed files with 252 additions and 12 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ Given a version number MAJOR.MINOR.PATCH, increment:
## [Unreleased]
### Added
- request methods to typescript
- query and get methods to merchantSession resource
### Fixed
- merchantPurchase log

## [2.27.0] - 2024-07-16
### Added
- query and get request methods
- query and get methods to merchantPurchase resource

## [2.26.0] - 2024-07-15
### Added
Expand Down
1 change: 1 addition & 0 deletions sdk/merchantPurchase/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ exports.log = require('./log');
exports.MerchantPurchase = merchantPurchase.MerchantPurchase;
exports.query = merchantPurchase.query;
exports.get = merchantPurchase.get;
exports.page = merchantPurchase.page;
1 change: 1 addition & 0 deletions sdk/merchantPurchase/log/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ const log = require('./log.js');

exports.get = log.get;
exports.query = log.query;
exports.page = log.page;
16 changes: 14 additions & 2 deletions sdk/merchantPurchase/log/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class Log extends Resource {
* Check out our API Documentation at https://starkbank.com/docs/api#merchant-purchase
*/

constructor({ created, type, errors, merchantPurchase, id }) {
constructor({ created, type, errors, purchase, id }) {
super(id);
this.created = check.datetime(created);
this.type = type;
this.errors = errors;
this.merchantPurchase = merchantPurchase;
this.purchase = purchase;
}
}

Expand All @@ -32,3 +32,15 @@ exports.query = async function ({ limit, after, before, user} = {}) {
};
return rest.getList(resource, query, user);
};

exports.page = async function ({ cursor, limit, after, before, types, purchaseIds, user } = {}) {
let query = {
cursor: cursor,
limit: limit,
after: after,
before: before,
types: types,
purchaseIds: purchaseIds,
};
return rest.getPage(resource, query, user);
};
19 changes: 16 additions & 3 deletions sdk/merchantPurchase/merchantPurchase.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ class MerchantPurchase extends Resource {
exports.MerchantPurchase = MerchantPurchase;
let resource = {'class': exports.MerchantPurchase, 'name': 'MerchantPurchase'};

exports.query = async function ({ limit, after, before, status, tags, ids, user} = {}) {
exports.get = async function (id, {user} = {}) {
return rest.getId(resource, id, user);
};

exports.query = async function ({ limit, after, before, status, tags, ids, user } = {}) {
let query = {
limit: limit,
after: check.date(after),
Expand All @@ -61,6 +65,15 @@ exports.query = async function ({ limit, after, before, status, tags, ids, user}
return rest.getList(resource, query, user);
};

exports.get = async function (id, {user} = {}) {
return rest.getId(resource, id, user);
exports.page = async function ({ cursor, limit, after, before, status, tags, ids, user } = {}) {
let query = {
cursor: cursor,
limit: limit,
after: check.date(after),
before: check.date(before),
status: status,
tags: tags,
ids: ids,
};
return rest.getPage(resource, query, user);
};
6 changes: 5 additions & 1 deletion sdk/merchantSession/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const merchantSession = require('./merchantSession.js');
exports.log = require('./log');
exports.MerchantSession = merchantSession.MerchantSession;
exports.create = merchantSession.create;
exports.purchase = merchantSession.purchase;
exports.purchase = merchantSession.purchase;
exports.query = merchantSession.query;
exports.get = merchantSession.get;
exports.page = merchantSession.page;
5 changes: 5 additions & 0 deletions sdk/merchantSession/log/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const log = require('./log.js');

exports.get = log.get;
exports.query = log.query;
exports.page = log.page;
46 changes: 46 additions & 0 deletions sdk/merchantSession/log/log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const rest = require('../../utils/rest.js');
const check = require('starkcore').check;
const Resource = require('../../utils/resource.js').Resource

class Log extends Resource {

/**
* Check out our API Documentation at https://starkbank.com/docs/api#merchant-session
*/

constructor({ created, type, errors, session, id }) {
super(id);
this.created = check.datetime(created);
this.type = type;
this.errors = errors;
this.session = session;
}
}

exports.Log = Log;
let resource = {'class': exports.Log, 'name': 'MerchantSessionLog'};

exports.get = async function (id, {user} = {}) {
return rest.getId(resource, id, user);
};

exports.query = async function ({ limit, after, before, user } = {}) {
let query = {
limit: limit,
after: after,
before: before
};
return rest.getList(resource, query, user);
};

exports.page = async function ({ cursor, limit, after, before, types, sessionIds, user } = {}) {
let query = {
cursor: cursor,
limit: limit,
after: after,
before: before,
types: types,
sessionIds: sessionIds,
};
return rest.getPage(resource, query, user);
};
33 changes: 31 additions & 2 deletions sdk/merchantSession/merchantSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MerchantSession extends Resource {
* 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}){
constructor({allowedFundingTypes, allowedInstallments, expiration, allowedIps=null, challengeMode=null, created=null, status=null, tags=null, updated=null, uuid=null, id=null}){
super(id)
this.allowedFundingTypes = allowedFundingTypes;
this.allowedInstallments = parseObjects(allowedInstallments, allowedInstallmentResource, AllowedInstallment);
Expand All @@ -35,7 +35,36 @@ exports.create = async function (merchantSession, {user} = {}) {
return rest.postSingle(resource=resource, query=merchantSession)
}

exports.purchase = async function ({uuid, amount, installmentCount, cardExpiration, cardNumber, cardSecurityCode, holderName, holderEmail, holderPhone, fundingType, billingCountryCode, billingCity, billingStateCode, billingStreetLine1, billingStreetLine2, billingZipCode, metadata, user} = {}) {
exports.get = async function (id, {user} = {}) {
return rest.getId(resource, id, user);
};

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.page = async function ({ cursor, limit, after, before, status, tags, ids, user } = {}) {
let query = {
cursor: cursor,
limit: limit,
after: check.date(after),
before: check.date(before),
status: status,
tags: tags,
ids: ids,
};
return rest.getPage(resource, query, user);
};

exports.purchase = async function ({ uuid, amount, installmentCount, cardExpiration, cardNumber, cardSecurityCode, holderName, holderEmail, holderPhone, fundingType, billingCountryCode, billingCity, billingStateCode, billingStreetLine1, billingStreetLine2, billingZipCode, metadata, user } = {}) {
payload = {
"amount": amount,
"installmentCount": installmentCount,
Expand Down
2 changes: 1 addition & 1 deletion sdk/merchantSession/purchase.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Purchase extends Resource {
* Check out our API Documentation at https://starkbank.com/merchant-purchase
*/

constructor({id, amount, installmentCount, cardExpiration, cardNumber, cardSecurityCode, holderName, holderEmail, holderPhone, fundingType, billingCountryCode, billingCity, billingStateCode, billingStreetLine1, billingStreetLine2, billingZipCode, metadata}){
constructor({amount, cardExpiration, cardNumber, cardSecurityCode, holderName, fundingType, holderEmail=null, holderPhone=null, billingCity=null, billingZipCode=null, billingStateCode=null, billingCountryCode=null, billingStreetLine1=null, billingStreetLine2=null, metadata=null, installmentCount=null, id=null}){
super(id)
this.amount = amount
this.installmentCount = installmentCount
Expand Down
24 changes: 22 additions & 2 deletions tests/testMerchantPurchase.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const starkbank = require('../index.js');

starkbank.user = require('./utils/user').exampleProject;

describe('MerchantSessionQuery', function(){
describe('MerchantPurchaseQuery', function(){
this.timeout(10000);
it('test_success', async () => {
let merchantPurchases = await starkbank.merchantPurchase.query({limit: 3});
Expand All @@ -13,7 +13,7 @@ describe('MerchantSessionQuery', function(){
});
});

describe('MerchantSessionGet', function(){
describe('MerchantPurchaseGet', function(){
this.timeout(10000);
it('test_success', async () => {
let merchantPurchases = await starkbank.merchantPurchase.query({limit: 3});
Expand All @@ -23,3 +23,23 @@ describe('MerchantSessionGet', function(){
}
});
});

describe('MerchantPurchasePage', function () {
this.timeout(10000);
it('test_success', async () => {
let ids = [];
let cursor = null;
let page = null;
for (let i = 0; i < 2; i++) {
[page, cursor] = await starkbank.merchantPurchase.page({ limit: 5, cursor: cursor });
for (let entity of page) {
assert(!ids.includes(entity.id));
ids.push(entity.id);
}
if (cursor == null) {
break;
}
}
assert(ids.length == 10);
});
});
20 changes: 20 additions & 0 deletions tests/testMerchantPurchaseLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,26 @@ describe('MerchantSessionQueryLog', function(){
});
});

describe('MerchantPurchasePageLog', function () {
this.timeout(10000);
it('test_success', async () => {
let ids = [];
let cursor = null;
let page = null;
for (let i = 0; i < 2; i++) {
[page, cursor] = await starkbank.merchantPurchase.log.page({ limit: 5, cursor: cursor });
for (let entity of page) {
assert(!ids.includes(entity.id));
ids.push(entity.id);
}
if (cursor == null) {
break;
}
}
assert(ids.length == 10);
});
});

describe('MerchantSessionGetLog', function(){
this.timeout(10000);
it('test_success', async () => {
Expand Down
41 changes: 41 additions & 0 deletions tests/testMerchantSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,47 @@ describe('MerchantSessionCreate', function(){
});
});

describe('MerchantSessionQuery', function(){
this.timeout(10000);
it('test_success', async () => {
let merchantSessions = await starkbank.merchantSession.query({limit: 3});
for await (let merchantSession of merchantSessions) {
assert(typeof merchantSession.id == 'string');
}
});
});

describe('MerchantSessionGet', function(){
this.timeout(10000);
it('test_success', async () => {
let merchantSessions = await starkbank.merchantSession.query({limit: 3});
for await (let session of merchantSessions) {
let merchantSession = await starkbank.merchantSession.get(session.id);
assert(typeof merchantSession.id == 'string');
}
});
});

describe('MerchantSessionPage', function () {
this.timeout(10000);
it('test_success', async () => {
let ids = [];
let cursor = null;
let page = null;
for (let i = 0; i < 2; i++) {
[page, cursor] = await starkbank.merchantSession.page({ limit: 5, cursor: cursor });
for (let entity of page) {
assert(!ids.includes(entity.id));
ids.push(entity.id);
}
if (cursor == null) {
break;
}
}
assert(ids.length == 10);
});
});

describe('MerchantSessionPurchase', function(){
this.timeout(10000);
it('test_success', async () => {
Expand Down
45 changes: 45 additions & 0 deletions tests/testMerchantSessionLog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const assert = require('assert');
const starkbank = require('../index.js');

starkbank.user = require('./utils/user').exampleProject;

describe('MerchantSessionQueryLog', function(){
this.timeout(10000);
it('test_success', async () => {
let merchantSessionLogs = await starkbank.merchantSession.log.query({limit: 3});
for await (let log of merchantSessionLogs) {
assert(typeof log.id == 'string');
}
});
});

describe('MerchantSessionGetLog', function(){
this.timeout(10000);
it('test_success', async () => {
let merchantSessionLogs = await starkbank.merchantSession.log.query({limit: 3});
for await (let log of merchantSessionLogs) {
log = await starkbank.merchantSession.log.get(log.id);
assert(typeof log.id == 'string');
}
});
});

describe('MerchantSessionPageLog', function () {
this.timeout(10000);
it('test_success', async () => {
let ids = [];
let cursor = null;
let page = null;
for (let i = 0; i < 2; i++) {
[page, cursor] = await starkbank.merchantSession.log.page({ limit: 5, cursor: cursor });
for (let entity of page) {
assert(!ids.includes(entity.id));
ids.push(entity.id);
}
if (cursor == null) {
break;
}
}
assert(ids.length == 10);
});
});

0 comments on commit 5cfc74f

Please sign in to comment.