diff --git a/CHANGELOG.md b/CHANGELOG.md index 7603089..eb9acfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,11 @@ Given a version number MAJOR.MINOR.PATCH, increment: ## [Unreleased] +### Added +- installmentCount attribute to IssuingPurchase resource +- IssuingBillingInvoice resource +- IssuingBillingTransaction resource +- activationCode and url attributes to IssuingToken resource ## [0.18.0] - 2026-05-04 ### Added diff --git a/README.md b/README.md index b9937b0..5227ac9 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,8 @@ This SDK version is compatible with the Stark Infra API v2. - [Withdrawals](#create-issuingwithdrawals): Send money back to your Workspace from your issuing balance - [Balance](#get-your-issuingbalance): View your issuing balance - [Transactions](#query-issuingtransactions): View the transactions that have affected your issuing balance + - [BillingInvoices](#query-issuingbillinginvoices): View the invoices charged for your issuing usage + - [BillingTransactions](#query-issuingbillingtransactions): View the transactions of your issuing billing invoices - [Pix](#pix) - [PixRequests](#create-pixrequests): Create Pix transactions - [PixReversals](#create-pixreversals): Reverse Pix transactions @@ -1004,6 +1006,19 @@ await (async() => { })(); ``` +You may supply an `activationCode` received through the bank app or SMS when building one. + +```javascript +await (async() => { + let token = new starkinfra.IssuingToken({ + cardId: '5189831499972623', + activationCode: '481632' + }); + + console.log(token.activationCode); +})(); +``` + ### Update an IssuingToken You can update a specific token by its id. @@ -1147,6 +1162,21 @@ await (async() => { })(); ``` +### Update an IssuingPurchase + +You can update a purchase's tags and description by its id. + +```javascript +await (async() => { + let purchase = await starkinfra.issuingPurchase.update('5155165527080960', { + 'tags': ['tony', 'stark'], + 'description': 'Office Supplies' + }); + + console.log(purchase); +})(); +``` + ### Query IssuingPurchase logs Logs are pretty important to understand the life cycle of a purchase. @@ -1342,6 +1372,72 @@ await (async() => { })(); ``` +### Query IssuingBillingInvoices + +To view the invoices charged for your issuing usage, you can query them +according to filters. + +```javascript +await (async() => { + let invoices = await starkinfra.issuingBillingInvoice.query({ + after: '2020-01-01', + before: '2020-03-01' + }); + + for await (let invoice of invoices) { + console.log(invoice); + } +})(); +``` + +### Get an IssuingBillingInvoice + +You can get a specific billing invoice by its id: + +```javascript +await (async() => { + let invoice = await starkinfra.issuingBillingInvoice.get('5155165527080960'); + + console.log(invoice); +})(); +``` + +### Query IssuingBillingTransactions + +To view the transactions of your issuing billing invoices, you can query them +according to filters. + +```javascript +await (async() => { + let transactions = await starkinfra.issuingBillingTransaction.query({ + after: '2020-01-01', + before: '2020-03-01' + }); + + for await (let transaction of transactions) { + console.log(transaction); + } +})(); +``` + +### Query paginated IssuingBillingTransactions + +If your initial number of transactions is too large for a single query, you can page through +the results manually using the cursor returned on each call. + +```javascript +await (async() => { + let cursor = null; + let page = null; + do { + [page, cursor] = await starkinfra.issuingBillingTransaction.page({limit: 5, cursor: cursor}); + for (let transaction of page) { + console.log(transaction); + } + } while (cursor != null); +})(); +``` + ## Pix ### Create PixRequests diff --git a/index.js b/index.js index 2504f80..b69809c 100644 --- a/index.js +++ b/index.js @@ -54,6 +54,8 @@ exports.issuingTokenDesign = require('./sdk/issuingTokenDesign'); exports.issuingTokenRequest = require('./sdk/issuingTokenRequest'); exports.issuingWithdrawal = require('./sdk/issuingWithdrawal'); exports.issuingTransaction = require('./sdk/issuingTransaction'); +exports.issuingBillingInvoice = require('./sdk/issuingBillingInvoice'); +exports.issuingBillingTransaction = require('./sdk/issuingBillingTransaction'); exports.event = require('./sdk/event'); exports.webhook = require('./sdk/webhook'); exports.bacenId = require('./sdk/utils/bacenId.js'); @@ -110,5 +112,7 @@ exports.IssuingTokenDesign = exports.issuingTokenDesign.IssuingTokenDesign; exports.IssuingTokenRequest = exports.issuingTokenRequest.IssuingTokenRequest; exports.IssuingWithdrawal = exports.issuingWithdrawal.IssuingWithdrawal; exports.IssuingTransaction = exports.issuingTransaction.IssuingTransaction; +exports.IssuingBillingInvoice = exports.issuingBillingInvoice.IssuingBillingInvoice; +exports.IssuingBillingTransaction = exports.issuingBillingTransaction.IssuingBillingTransaction; exports.Event = exports.event.Event; exports.Webhook = exports.webhook.Webhook; diff --git a/sdk/issuingBalance/issuingBalance.js b/sdk/issuingBalance/issuingBalance.js index f6c5c80..bacaf2c 100644 --- a/sdk/issuingBalance/issuingBalance.js +++ b/sdk/issuingBalance/issuingBalance.js @@ -17,14 +17,18 @@ class IssuingBalance extends Resource { * @param id [string]: unique id returned when IssuingBalance is created. ex: '5656565656565656' * @param amount [integer]: current balance amount of the workspace in cents. ex: 200 (= R$ 2.00) * @param currency [string]: currency of the current workspace. Expect others to be added eventually. ex: 'BRL', 'USD' + * @param limit [integer]: Spending limit of the balance + * @param maxLimit [integer]: Maximum spending limit. This field is currently always equal to limit * @param updated [string]: datetime for the IssuingBalance. ex: '2020-03-10 10:30:00.000'u * */ - constructor(id, amount, currency, updated) { + constructor(id, amount, currency, limit, maxLimit, updated) { super(id); - + this.amount = amount; this.currency = currency; + this.limit = limit; + this.maxLimit = maxLimit; this.updated = check.datetime(updated); } } diff --git a/sdk/issuingBillingInvoice/index.js b/sdk/issuingBillingInvoice/index.js new file mode 100644 index 0000000..2bb086d --- /dev/null +++ b/sdk/issuingBillingInvoice/index.js @@ -0,0 +1,6 @@ +const issuingBillingInvoice = require('./issuingBillingInvoice.js'); + +exports.get = issuingBillingInvoice.get; +exports.query = issuingBillingInvoice.query; +exports.page = issuingBillingInvoice.page; +exports.IssuingBillingInvoice = issuingBillingInvoice.IssuingBillingInvoice; diff --git a/sdk/issuingBillingInvoice/issuingBillingInvoice.js b/sdk/issuingBillingInvoice/issuingBillingInvoice.js new file mode 100644 index 0000000..3a32f5f --- /dev/null +++ b/sdk/issuingBillingInvoice/issuingBillingInvoice.js @@ -0,0 +1,141 @@ +const rest = require('../utils/rest.js'); +const check = require('starkcore').check; +const Resource = require('starkcore').Resource; + + +class IssuingBillingInvoice extends Resource { + /** + * + * IssuingBillingInvoice object + * + * @description Displays the IssuingBillingInvoice objects created in your Workspace. + * + * Attributes (return-only): + * @param id [string]: unique id returned when IssuingBillingInvoice is created. ex: '5656565656565656' + * @param taxId [string]: payer tax ID. ex: '012.345.678-90' + * @param name [string]: payer name. ex: 'Tony Stark' + * @param fine [float]: Fine percentage applied when paid after the due date. ex: 2.0 + * @param interest [float]: Monthly interest percentage applied when paid after the due date. ex: 1.0 + * @param amount [integer]: invoice value in cents. ex: 1234 (= R$ 12.34) + * @param nominalAmount [integer]: nominal amount in cents. ex: 1234 (= R$ 12.34) + * @param status [string]: current IssuingBillingInvoice status. ex: 'paid' + * @param brcode [string]: BR Code for the invoice payment. ex: '00020101021226930014br.gov.bcb.pix' + * @param link [string]: public invoice webpage URL. ex: 'https://starkbank-card-issuer.sandbox.starkbank.com/billinginvoicelink/97de4d51e8984c459639a645ce920abb' + * @param due [string]: invoice due datetime. ex: '2020-03-10 10:30:00.000' + * @param start [string]: billing cycle start datetime. ex: '2020-03-10 10:30:00.000' + * @param end [string]: billing cycle end datetime. ex: '2020-03-10 10:30:00.000' + * @param created [string]: creation datetime for the IssuingBillingInvoice. ex: '2020-03-10 10:30:00.000' + * @param updated [string]: latest update datetime for the IssuingBillingInvoice. ex: '2020-03-10 10:30:00.000' + * + */ + constructor({ + id = null, taxId = null, name = null, fine = null, interest = null, amount = null, + nominalAmount = null, status = null, brcode = null, link = null, due = null, + start = null, end = null, created = null, updated = null + }) { + super(id); + + this.taxId = taxId; + this.name = name; + this.fine = fine; + this.interest = interest; + this.amount = amount; + this.nominalAmount = nominalAmount; + this.status = status; + this.brcode = brcode; + this.link = link; + this.due = check.datetime(due); + this.start = check.datetime(start); + this.end = check.datetime(end); + this.created = check.datetime(created); + this.updated = check.datetime(updated); + } +} + +exports.IssuingBillingInvoice = IssuingBillingInvoice; +let resource = {'class': exports.IssuingBillingInvoice, 'name': 'IssuingBillingInvoice'}; + +exports.get = async function (id, {user} = {}) { + /** + * + * Retrieve a specific IssuingBillingInvoice + * + * @description Receive a single IssuingBillingInvoice object previously created in the Stark Infra API by its id + * + * Parameters (required): + * @param id [string]: object unique id. ex: '5656565656565656' + * + * Parameters (optional): + * @param user [Organization/Project object, default null]: Organization or Project object. Not necessary if starkinfra.user was set before function call + * + * Return: + * @returns IssuingBillingInvoice object with updated attributes + * + */ + return rest.getId(resource, id, user); +}; + +exports.query = async function ({limit, after, before, status, tags, ids, user} = {}) { + /** + * + * Retrieve IssuingBillingInvoices + * + * @description Receive a generator of IssuingBillingInvoice objects previously created in the Stark Infra API + * + * Parameters (optional): + * @param limit [integer, default null]: maximum number of objects to be retrieved. Unlimited if null. ex: 35 + * @param after [string, default null]: date filter for objects created only after specified date. ex: '2020-04-03' + * @param before [string, default null]: date filter for objects created only before specified date. ex: '2020-04-03' + * @param status [list of strings, default null]: filter for status of retrieved objects. ex: ['paid'] + * @param tags [list of strings, default null]: tags to filter retrieved objects. ex: ['tony', 'stark'] + * @param ids [list of strings, default null]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545'] + * @param user [Organization/Project object, default null]: Project object. Not necessary if starkinfra.user was set before function call + * + * Return: + * @returns generator of IssuingBillingInvoice objects with updated attributes + * + */ + let query = { + limit: limit, + after: after, + before: 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} = {}) { + /** + * + * Retrieve paged IssuingBillingInvoices + * + * @description Receive a list of up to 100 IssuingBillingInvoice objects previously created in the Stark Infra API and the cursor to the next page. + * Use this function instead of query if you want to manually page your requests. + * + * Parameters (optional): + * @param cursor [string, default null]: cursor returned on the previous page function call + * @param limit [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 35 + * @param after [string, default null]: date filter for objects created only after specified date. ex: '2020-04-03' + * @param before [string, default null]: date filter for objects created only before specified date. ex: '2020-04-03' + * @param status [list of strings, default null]: filter for status of retrieved objects. ex: ['paid'] + * @param tags [list of strings, default null]: tags to filter retrieved objects. ex: ['tony', 'stark'] + * @param ids [list of strings, default null]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545'] + * @param user [Organization/Project object, default null]: Project object. Not necessary if starkinfra.user was set before function call + * + * Return: + * @returns list of IssuingBillingInvoice objects with updated attributes and cursor to retrieve the next page of IssuingBillingInvoice objects + * + */ + let query = { + cursor: cursor, + limit: limit, + after: after, + before: before, + status: status, + tags: tags, + ids: ids, + }; + return rest.getPage(resource, query, user); +}; diff --git a/sdk/issuingBillingTransaction/index.js b/sdk/issuingBillingTransaction/index.js new file mode 100644 index 0000000..7aab3c6 --- /dev/null +++ b/sdk/issuingBillingTransaction/index.js @@ -0,0 +1,5 @@ +const issuingBillingTransaction = require('./issuingBillingTransaction.js'); + +exports.query = issuingBillingTransaction.query; +exports.page = issuingBillingTransaction.page; +exports.IssuingBillingTransaction = issuingBillingTransaction.IssuingBillingTransaction; diff --git a/sdk/issuingBillingTransaction/issuingBillingTransaction.js b/sdk/issuingBillingTransaction/issuingBillingTransaction.js new file mode 100644 index 0000000..7dc12fa --- /dev/null +++ b/sdk/issuingBillingTransaction/issuingBillingTransaction.js @@ -0,0 +1,120 @@ +const rest = require('../utils/rest.js'); +const check = require('starkcore').check; +const Resource = require('starkcore').Resource; + + +class IssuingBillingTransaction extends Resource { + /** + * + * IssuingBillingTransaction object + * + * @description Displays the IssuingBillingTransaction objects created in your Workspace. + * + * Attributes (return-only): + * @param id [string]: unique id returned when IssuingBillingTransaction is created. ex: '5656565656565656' + * @param amount [integer]: transaction amount in cents. ex: 1234 (= R$ 12.34) + * @param invoiceId [string]: parent billing invoice id. May be null. ex: '5656565656565656' + * @param installment [integer]: installment number. ex: 1 + * @param installmentCount [integer]: total installment count. ex: 12 + * @param balance [integer]: remaining balance in cents. ex: 1234 (= R$ 12.34) + * @param holderName [string]: card holder name. ex: 'Tony Stark' + * @param source [string]: transaction source. ex: 'issuing-purchase' + * @param externalId [string]: external transaction id. ex: 'my-external-id-123456' + * @param description [string]: transaction description. ex: 'Office Supplies' + * @param cardEnding [string]: last 4 digits of the card number. ex: '1234' + * @param tax [integer]: IOF amount in cents applied to the transaction + * @param rate [float]: Conversion rate applied to international transactions + * @param merchantAmount [integer]: merchant amount in cents. ex: 1234 (= R$ 12.34) + * @param merchantCurrencyCode [string]: merchant currency code (ISO 4217). ex: 'USD' + * @param created [string]: creation datetime for the IssuingBillingTransaction. ex: '2020-03-10 10:30:00.000' + * + */ + constructor({ + id = null, amount = null, invoiceId = null, installment = null, installmentCount = null, + balance = null, holderName = null, source = null, externalId = null, description = null, + cardEnding = null, tax = null, rate = null, merchantAmount = null, merchantCurrencyCode = null, + created = null + }) { + super(id); + + this.amount = amount; + this.invoiceId = invoiceId; + this.installment = installment; + this.installmentCount = installmentCount; + this.balance = balance; + this.holderName = holderName; + this.source = source; + this.externalId = externalId; + this.description = description; + this.cardEnding = cardEnding; + this.tax = tax; + this.rate = rate; + this.merchantAmount = merchantAmount; + this.merchantCurrencyCode = merchantCurrencyCode; + this.created = check.datetime(created); + } +} + +exports.IssuingBillingTransaction = IssuingBillingTransaction; +let resource = {'class': exports.IssuingBillingTransaction, 'name': 'IssuingBillingTransaction'}; + +exports.query = async function ({limit, after, before, invoiceId, tags, user} = {}) { + /** + * + * Retrieve IssuingBillingTransactions + * + * @description Receive a generator of IssuingBillingTransaction objects previously created in the Stark Infra API + * + * Parameters (optional): + * @param limit [integer, default null]: maximum number of objects to be retrieved. Unlimited if null. ex: 35 + * @param after [string, default null]: date filter for objects created only after specified date. ex: '2020-04-03' + * @param before [string, default null]: date filter for objects created only before specified date. ex: '2020-04-03' + * @param invoiceId [string, default null]: filter for transactions of a specific billing invoice. ex: '5656565656565656' + * @param tags [list of strings, default null]: tags to filter retrieved objects. ex: ['tony', 'stark'] + * @param user [Organization/Project object, default null]: Project object. Not necessary if starkinfra.user was set before function call + * + * Return: + * @returns generator of IssuingBillingTransaction objects with updated attributes + * + */ + let query = { + limit: limit, + after: after, + before: before, + invoiceId: invoiceId, + tags: tags, + }; + return rest.getList(resource, query, user); +}; + +exports.page = async function ({cursor, limit, after, before, invoiceId, tags, user} = {}) { + /** + * + * Retrieve paged IssuingBillingTransactions + * + * @description Receive a list of up to 100 IssuingBillingTransaction objects previously created in the Stark Infra API and the cursor to the next page. + * Use this function instead of query if you want to manually page your requests. + * + * Parameters (optional): + * @param cursor [string, default null]: cursor returned on the previous page function call + * @param limit [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 35 + * @param after [string, default null]: date filter for objects created only after specified date. ex: '2020-04-03' + * @param before [string, default null]: date filter for objects created only before specified date. ex: '2020-04-03' + * @param invoiceId [string, default null]: filter for transactions of a specific billing invoice. ex: '5656565656565656' + * @param tags [list of strings, default null]: tags to filter retrieved objects. ex: ['tony', 'stark'] + * @param user [Organization/Project object, default null]: Project object. Not necessary if starkinfra.user was set before function call + * + * Return: + * @returns list of IssuingBillingTransaction objects with updated attributes and cursor to retrieve the next page of IssuingBillingTransaction objects + * + */ + let query = { + cursor: cursor, + limit: limit, + after: after, + before: before, + invoiceId: invoiceId, + tags: tags, + }; + return rest.getPage(resource, query, user); +}; diff --git a/sdk/issuingCard/issuingCard.js b/sdk/issuingCard/issuingCard.js index cd59622..e8be005 100644 --- a/sdk/issuingCard/issuingCard.js +++ b/sdk/issuingCard/issuingCard.js @@ -35,6 +35,7 @@ class IssuingCard extends Resource { * @param holderId [string]: cardholder unique id. ex: '5656565656565656' * @param type [string]: card type. ex: 'virtual' * @param status [string]: current IssuingCard status. Options: 'active', 'blocked', 'canceled', 'expired' + * @param isPinDefined [boolean]: Whether the card has a PIN defined. Returned only when "expand=isPinDefined" is informed in the request * @param number [string]: [EXPANDABLE] masked card number. ex: '1234 5678 1234 5678' * @param securityCode [string]: [EXPANDABLE] masked card verification value (cvv). Expand to unmask the value. ex: '123'. * @param expiration [string]: [EXPANDABLE] masked card expiration datetime. ex: '2020-03-10 10:30:00.000' @@ -46,8 +47,8 @@ class IssuingCard extends Resource { holderName, holderTaxId, holderExternalId, displayName=null, rules=null, productId=null, tags=null, streetLine1=null, streetLine2=null, district=null, city=null, stateCode=null, zipCode=null, id=null, - holderId=null, type=null, status=null, number=null, securityCode=null, - expiration=null, created=null, updated=null + holderId=null, type=null, status=null, isPinDefined=null, number=null, securityCode=null, + expiration=null, created=null, updated=null }) { super(id); @@ -67,6 +68,7 @@ class IssuingCard extends Resource { this.holderId = holderId; this.type = type; this.status = status; + this.isPinDefined = isPinDefined; this.number = number; this.securityCode = securityCode; this.expiration = check.datetime(expiration); diff --git a/sdk/issuingProduct/issuingProduct.js b/sdk/issuingProduct/issuingProduct.js index 3956389..0bcf26c 100644 --- a/sdk/issuingProduct/issuingProduct.js +++ b/sdk/issuingProduct/issuingProduct.js @@ -17,19 +17,21 @@ class IssuingProduct extends Resource { * @param fundingType [string]: type of funding used for payment. ex: 'credit', 'debit' * @param holderType [string]: holder type. ex: 'business', 'individual' * @param code [string]: internal code from card flag informing the product. ex: 'MRW', 'MCO', 'MWB', 'MCS' + * @param customerType [string]: Same as holderType. Kept for backward compatibility * @param created [string]: creation datetime for the IssuingProduct. ex: '2020-03-10 10:30:00.000' * */ - constructor({ - id=null, network=null, fundingType=null, holderType=null, - code=null, created=null + constructor({ + id=null, network=null, fundingType=null, holderType=null, + code=null, customerType=null, created=null }) { super(id); - + this.network = network; this.fundingType = fundingType; this.holderType = holderType; this.code = code; + this.customerType = customerType; this.created = check.datetime(created); } } diff --git a/sdk/issuingPurchase/issuingPurchase.js b/sdk/issuingPurchase/issuingPurchase.js index 373323c..c787ba8 100644 --- a/sdk/issuingPurchase/issuingPurchase.js +++ b/sdk/issuingPurchase/issuingPurchase.js @@ -18,6 +18,7 @@ class IssuingPurchase extends Resource { * @param cardId [string]: unique id returned when IssuingCard is created. ex: '5656565656565656' * @param cardEnding [string]: last 4 digits of the card number. ex: '1234' * @param purpose [string]: purchase purpose. ex: 'purchase' + * @param installmentCount [integer]: quantity of installments to be confirmed. Minimum = 1. ex: 12 * @param amount [integer]: IssuingPurchase value in cents. Minimum = 0. ex: 1234 (= R$ 12.34) * @param tax [integer]: IOF amount taxed for international purchases. ex: 1234 (= R$ 12.34) * @param issuerAmount [integer]: issuer amount. ex: 1234 (= R$ 12.34) @@ -28,6 +29,7 @@ class IssuingPurchase extends Resource { * @param merchantCurrencySymbol [string]: merchant currency symbol. ex: '$' * @param merchantCategoryCode [string]: merchant category code. ex: 'eatingPlacesRestaurants' * @param merchantCategoryType [string]: merchant category type. ex: 'food' + * @param merchantCategoryNumber [integer]: MCC number of the merchant category. ex: 5814 * @param merchantCountryCode [string]: merchant country code. ex: 'USA' * @param acquirerId [string]: acquirer ID. ex: '5656565656565656' * @param merchantId [string]: merchant ID. ex: '5656565656565656' @@ -43,6 +45,7 @@ class IssuingPurchase extends Resource { * @param id [string]: unique id returned when IssuingPurchase is created. ex: '5656565656565656' * @param issuingTransactionIds [string]: ledger transaction ids linked to this Purchase * @param status [string]: current IssuingCard status. Options: 'approved', 'canceled', 'denied', 'confirmed' or 'voided' + * @param confirmed [string]: Confirmation datetime. Null until the purchase is confirmed. ex: '2020-03-10 10:30:00.000' * @param description [string]: IssuingPurchase description. ex: 'Office Supplies' * @param metadata [dictionary object]: dictionary object used to store additional information about the IssuingPurchase object. ex: { authorizationId: 'OjZAqj' }. * @param zipCode [string]: zip code of the merchant location. ex: '02101234' @@ -57,14 +60,14 @@ class IssuingPurchase extends Resource { * */ constructor({ - holderName=null, productId=null, cardId=null, cardEnding=null, purpose=null, - amount=null, tax=null, issuerAmount=null, issuerCurrencyCode=null, + holderName=null, productId=null, cardId=null, cardEnding=null, purpose=null, + installmentCount=null, amount=null, tax=null, issuerAmount=null, issuerCurrencyCode=null, issuerCurrencySymbol=null, merchantAmount=null, merchantCurrencyCode=null, - merchantCurrencySymbol=null, merchantCategoryCode=null, merchantCategoryType=null, - merchantCountryCode=null, acquirerId=null, merchantId=null, merchantName=null, - merchantFee=null, walletId=null, methodCode=null, score=null, endToEndId=null, - tags=null, id=null, issuingTransactionIds=null, status=null, description=null, - metadata=null, zipCode=null, created=null, updated=null, isPartialAllowed=null, + merchantCurrencySymbol=null, merchantCategoryCode=null, merchantCategoryType=null, + merchantCategoryNumber=null, merchantCountryCode=null, acquirerId=null, merchantId=null, merchantName=null, + merchantFee=null, walletId=null, methodCode=null, score=null, endToEndId=null, + tags=null, id=null, issuingTransactionIds=null, status=null, confirmed=null, description=null, + metadata=null, zipCode=null, created=null, updated=null, isPartialAllowed=null, cardTags=null, holderId=null, holderTags=null }) { super(id); @@ -74,6 +77,7 @@ class IssuingPurchase extends Resource { this.cardId = cardId; this.cardEnding = cardEnding; this.purpose = purpose; + this.installmentCount = installmentCount; this.amount = amount; this.tax = tax; this.issuerAmount = issuerAmount; @@ -84,6 +88,7 @@ class IssuingPurchase extends Resource { this.merchantCurrencySymbol = merchantCurrencySymbol; this.merchantCategoryCode = merchantCategoryCode; this.merchantCategoryType = merchantCategoryType; + this.merchantCategoryNumber = merchantCategoryNumber; this.merchantCountryCode = merchantCountryCode; this.acquirerId = acquirerId; this.merchantId = merchantId; @@ -96,6 +101,7 @@ class IssuingPurchase extends Resource { this.tags = tags; this.issuingTransactionIds = issuingTransactionIds; this.status = status; + this.confirmed = check.datetime(confirmed); this.description = description; this.metadata = metadata; this.zipCode = zipCode; @@ -208,7 +214,7 @@ exports.page = async function ({ cursor, ids, cardIds, holderIds, endToEndIds, l return rest.getPage(resource, query, user); }; -exports.update = async function (id, {tags, description, user}) { +exports.update = async function (id, {tags, description, user} = {}) { /** * *Update an IssuingPurchase by passing id. diff --git a/sdk/issuingRule/issuingRule.js b/sdk/issuingRule/issuingRule.js index 8329449..104af05 100644 --- a/sdk/issuingRule/issuingRule.js +++ b/sdk/issuingRule/issuingRule.js @@ -31,15 +31,17 @@ class IssuingRule extends Resource { * @param counterAmount [integer]: current rule spent amount. ex: 1000 * @param currencySymbol [string]: currency symbol. ex: 'R$' * @param currencyName [string]: currency name. ex: 'Brazilian Real' + * @param schedule [string]: Optional schedule dictating when the rule can be used. Some examples: 'everyday from 09:00 to 18:00 in America/Sao_Paulo' - every day, 09:00-18:00 Sao Paulo time; 'every monday, wednesday, friday from 08:00 to 12:00 in America/Sao_Paulo' - only those weekdays, mornings; 'every saturday, sunday' - weekends, all day, in UTC + * @param purposes [list of strings]: Optional list of transaction purposes the rule applies to. Options: 'purchase', 'withdrawal', 'verification'. The rule then limits only purchases of those purposes; omit it to allow any purposes. Example: ['purchase', 'verification'] if you want us to automatically deny withdrawal. * */ - constructor({ - name, amount, id=null, interval=null, currencyCode=null, - categories=null, countries=null, methods=null, counterAmount=null, - currencySymbol=null, currencyName=null + constructor({ + name, amount, id=null, interval=null, currencyCode=null, + categories=null, countries=null, methods=null, counterAmount=null, + currencySymbol=null, currencyName=null, schedule=null, purposes=null }) { super(id); - + this.name = name; this.amount = amount; this.interval = interval; @@ -50,6 +52,8 @@ class IssuingRule extends Resource { this.counterAmount = counterAmount; this.currencySymbol = currencySymbol; this.currencyName = currencyName; + this.schedule = schedule; + this.purposes = purposes; } } diff --git a/sdk/issuingStock/issuingStock.js b/sdk/issuingStock/issuingStock.js index 58dcf3c..5f30b6f 100644 --- a/sdk/issuingStock/issuingStock.js +++ b/sdk/issuingStock/issuingStock.js @@ -1,4 +1,5 @@ const rest = require('../utils/rest.js'); +const check = require('starkcore').check; const Resource = require('starkcore').Resource; @@ -14,20 +15,22 @@ class IssuingStock extends Resource { * @param balance [integer]: [EXPANDABLE] current stock balance. ex: 1000 * @param designId [string]: IssuingDesign unique id. ex: "5656565656565656" * @param embosserId [string]: Embosser unique id. ex: "5656565656565656" - * @param updated [string]: latest update datetime for the CreditNote. ex: '2020-03-10 10:30:00.000' + * @param embosserName [string]: Name of the embosser that holds this stock + * @param updated [string]: latest update datetime for the CreditNote. ex: '2020-03-10 10:30:00.000' * @param created [string]: creation datetime for the IssuingDesign. ex: '2020-03-10 10:30:00.000' * */ - constructor({ - id = null, balance = null, designId = null, embosserId = null, - updated = null, created = null + constructor({ + id = null, balance = null, designId = null, embosserId = null, + embosserName = null, updated = null, created = null }) { super(id); this.balance = balance; this.designId = designId; this.embosserId = embosserId; - this.updated = updated; - this.created = created; + this.embosserName = embosserName; + this.updated = check.datetime(updated); + this.created = check.datetime(created); } } diff --git a/sdk/issuingToken/issuingToken.js b/sdk/issuingToken/issuingToken.js index a88fd3f..fd77ad6 100644 --- a/sdk/issuingToken/issuingToken.js +++ b/sdk/issuingToken/issuingToken.js @@ -17,7 +17,9 @@ class IssuingToken extends Resource { * @param walletId [string]: wallet provider which the token is bounded to. ex: 'google' * @param walletName [string]: wallet name. ex: 'GOOGLE' * @param merchantId [string]: merchant unique id. ex: '5656565656565656' - * + * @param walletDeviceScore [number]: Device score informed by the digital wallet. + * @param walletAccountScore [number]: Account score informed by the digital wallet + * * Attributes (IssuingToken only): * @param id [string]: unique id returned when IssuingToken is created. ex: '5656565656565656' * @param externalId [string]: a unique string among all your IssuingTokens, used to avoid resource duplication. ex: 'DSHRMC00002626944b0e3b539d4d459281bdba90c2588791' @@ -25,11 +27,12 @@ class IssuingToken extends Resource { * @param status [string]: current IssuingToken status. ex: 'active', 'blocked', 'canceled', 'frozen' or 'pending' * @param created [string]: creation datetime for the IssuingToken. ex: '2020-03-10 10:30:00.000' * @param updated [string]: latest update datetime for the IssuingToken. ex: '2020-03-10 10:30:00.000' - * + * * Attributes (Authorization request only): + * @param activationCode [string]: activation code received through the bank app or sms. ex: '481632' * @param methodCode [string]: provisioning method. Options: 'app', 'token', 'manual', 'server' or 'browser' * @param deviceType [string]: device type used for tokenization. ex: 'Phone' - * @param deviceName [string]: device name used for tokenization. ex: 'My phone' + * @param deviceName [string]: device name used for tokenization. ex: 'My phone' * @param deviceSerialNumber [string]: device serial number used for tokenization. ex: '2F6D63' * @param deviceOsName [string]: device operational system name used for tokenization. ex: 'Android' * @param deviceOsVersion [string]: device operational system version used for tokenization. ex: '4.4.4' @@ -37,10 +40,11 @@ class IssuingToken extends Resource { * @param walletInstanceId [string]: unique id referred to the wallet app in the current device. ex: '71583be4777eb89aaf0345eebeb82594f096615ed17862d0' * */ - constructor({ - cardId=null, walletId=null, walletName=null, merchantId=null, id=null, externalId=null, - tags=null, status=null, created=null, updated=null, methodCode=null, deviceType=null, - deviceName=null, deviceSerialNumber=null, deviceOsName=null, deviceOsVersion=null, + constructor({ + cardId=null, walletId=null, walletName=null, merchantId=null, walletDeviceScore=null, + walletAccountScore=null, id=null, externalId=null, + tags=null, status=null, created=null, updated=null, activationCode=null, methodCode=null, + deviceType=null, deviceName=null, deviceSerialNumber=null, deviceOsName=null, deviceOsVersion=null, deviceImei=null, walletInstanceId=null }) { super(id); @@ -49,11 +53,14 @@ class IssuingToken extends Resource { this.walletId = walletId; this.walletName = walletName; this.merchantId = merchantId; + this.walletDeviceScore = walletDeviceScore; + this.walletAccountScore = walletAccountScore; this.externalId = externalId; this.tags = tags; this.status = status; this.created = check.datetime(created); this.updated = check.datetime(updated); + this.activationCode = activationCode; this.methodCode = methodCode; this.deviceType = deviceType; this.deviceName = deviceName; @@ -229,7 +236,7 @@ exports.parse = async function (content, signature, {user} = {}) { return parse.parseAndVerify(resource, content, signature, user); }; -exports.responseAuthorization = async function (status, { reason, activationMethods, designId, tags } = {}) { +exports.responseAuthorization = async function ({ status, reason = null, activationMethods = null, designId = null, tags = null }) { /** * * Helps you respond IssuingToken authorization requests @@ -264,7 +271,7 @@ exports.responseAuthorization = async function (status, { reason, activationMeth return JSON.stringify(response); }; -exports.responseActivation = async function (status, { reason, tags } = {}) { +exports.responseActivation = async function ({ status, reason = null, tags = null }) { /** * * Helps you respond IssuingToken activation requests diff --git a/sdk/merchantCategory/merchantCategory.js b/sdk/merchantCategory/merchantCategory.js index 7f498e5..16a0c6e 100644 --- a/sdk/merchantCategory/merchantCategory.js +++ b/sdk/merchantCategory/merchantCategory.js @@ -19,17 +19,19 @@ class MerchantCategory extends SubResource { * Attributes (return-only): * @param name [string]: category's name. ex: 'Veterinary services', 'Fast food restaurants' * @param number [string]: category's number. ex: '742', '5814' + * @param group [string]: category's group. ex: 'pets', 'food' * */ - constructor({ - code=null, type=null, name=null, number=null + constructor({ + code=null, type=null, name=null, number=null, group=null }) { super(); - + this.code = code this.type = type this.name = name this.number = number + this.group = group } } diff --git a/tests/testIssuingBillingInvoice.js b/tests/testIssuingBillingInvoice.js new file mode 100644 index 0000000..76e5ba9 --- /dev/null +++ b/tests/testIssuingBillingInvoice.js @@ -0,0 +1,156 @@ +const assert = require('assert'); +const starkinfra = require('../index.js'); + +starkinfra.user = require('./utils/user').exampleProject; + + +describe('TestIssuingBillingInvoiceGet', function () { + this.timeout(10000); + it('test_success', async () => { + let i = 0; + const invoices = await starkinfra.issuingBillingInvoice.query({limit: 5}); + for await (let invoice of invoices) { + assert(typeof invoice.id == 'string'); + i += 1; + } + assert(i === 5); + }); +}); + + +describe('TestIssuingBillingInvoiceInfoGet', function () { + this.timeout(10000); + it('test_success', async () => { + let invoices = await starkinfra.issuingBillingInvoice.query({limit: 1}); + for await (let invoice of invoices) { + assert(typeof invoice.id == 'string'); + invoice = await starkinfra.issuingBillingInvoice.get(invoice.id); + assert(typeof invoice.id == 'string'); + } + }); + + it('test_success_ids', async () => { + let invoices = await starkinfra.issuingBillingInvoice.query({limit: 10}); + let idsExpected = []; + for await (let invoice of invoices) { + idsExpected.push(invoice.id); + } + + let invoicesResult = await starkinfra.issuingBillingInvoice.query({ids: idsExpected}); + let idsResult = []; + for await (let invoice of invoicesResult) { + idsResult.push(invoice.id); + } + + idsExpected.sort(); + idsResult.sort(); + assert(idsExpected.length === idsResult.length); + for (let i = 0; i < idsExpected.length; i++) { + assert(idsExpected[i] === idsResult[i]); + } + }); +}); + + +describe('TestIssuingBillingInvoiceGetPage', 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 starkinfra.issuingBillingInvoice.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('TestIssuingBillingInvoiceFields', function () { + this.timeout(10000); + it('test_success', async () => { + let i = 0; + const invoices = await starkinfra.issuingBillingInvoice.query({limit: 5}); + for await (let invoice of invoices) { + assert(typeof invoice.id == 'string'); + assert('taxId' in invoice); + assert('name' in invoice); + assert('fine' in invoice); + assert('interest' in invoice); + assert('amount' in invoice); + assert('nominalAmount' in invoice); + assert('status' in invoice); + assert('brcode' in invoice); + assert('link' in invoice); + assert('due' in invoice); + assert('start' in invoice); + assert('end' in invoice); + assert('created' in invoice); + assert('updated' in invoice); + i += 1; + } + assert(i > 0); + }); + + it('test_success_datetime', async () => { + let invoices = await starkinfra.issuingBillingInvoice.query({limit: 1}); + for await (let invoice of invoices) { + invoice = await starkinfra.issuingBillingInvoice.get(invoice.id); + if (invoice.created != null) { + assert(invoice.created); + } + if (invoice.updated != null) { + assert(invoice.updated); + } + if (invoice.due != null) { + assert(invoice.due); + } + if (invoice.start != null) { + assert(invoice.start); + } + if (invoice.end != null) { + assert(invoice.end); + } + } + }); +}); + + +describe('TestIssuingBillingInvoiceQueryParams', function () { + this.timeout(10000); + it('test_success', async () => { + const invoices = await starkinfra.issuingBillingInvoice.query({ + limit: 2, + after: '2020-04-01', + before: '2021-04-30', + status: 'paid', + tags: ['travel', 'food'], + ids: ['1', '2'], + }); + assert(invoices.length === undefined); + }); +}); + + +describe('TestIssuingBillingInvoicePageParams', function () { + this.timeout(10000); + it('test_success', async () => { + let cursor = null; + let invoices = null; + [invoices, cursor] = await starkinfra.issuingBillingInvoice.page({ + limit: 2, + after: '2020-04-01', + before: '2021-04-30', + status: 'paid', + tags: ['travel', 'food'], + }); + assert(invoices.length === 0); + }); +}); diff --git a/tests/testIssuingBillingTransaction.js b/tests/testIssuingBillingTransaction.js new file mode 100644 index 0000000..db6ec13 --- /dev/null +++ b/tests/testIssuingBillingTransaction.js @@ -0,0 +1,96 @@ +const assert = require('assert'); +const starkinfra = require('../index.js'); + +starkinfra.user = require('./utils/user').exampleProject; + + +describe('TestIssuingBillingTransactionGet', function () { + this.timeout(10000); + it('test_success', async () => { + let i = 0; + const transactions = await starkinfra.issuingBillingTransaction.query({limit: 5}); + for await (let transaction of transactions) { + assert(typeof transaction.id == 'string'); + i += 1; + } + assert(i === 5); + }); + + it('test_success_datetime', async () => { + const transactions = await starkinfra.issuingBillingTransaction.query({limit: 5}); + for await (let transaction of transactions) { + assert(typeof transaction.id == 'string'); + if (transaction.created != null) { + assert(transaction.created); + } + } + }); +}); + + +describe('TestIssuingBillingTransactionGetPage', 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 starkinfra.issuingBillingTransaction.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('TestIssuingBillingTransactionQueryParams', function () { + this.timeout(10000); + it('test_success', async () => { + const transactions = await starkinfra.issuingBillingTransaction.query({ + limit: 2, + after: '2020-04-01', + before: '2021-04-30', + tags: ['travel', 'food'], + }); + assert(transactions.length === undefined); + }); + + it('test_success_invoice_id', async () => { + let invoiceId = null; + const invoices = await starkinfra.issuingBillingInvoice.query({limit: 1}); + for await (let invoice of invoices) { + invoiceId = invoice.id; + } + if (invoiceId != null) { + let i = 0; + const transactions = await starkinfra.issuingBillingTransaction.query({limit: 5, invoiceId: invoiceId}); + for await (let transaction of transactions) { + assert(typeof transaction.id == 'string'); + i += 1; + } + assert(i >= 0); + } + }); +}); + + +describe('TestIssuingBillingTransactionPageParams', function () { + this.timeout(10000); + it('test_success', async () => { + let cursor = null; + let transactions = null; + [transactions, cursor] = await starkinfra.issuingBillingTransaction.page({ + limit: 2, + after: '2020-04-01', + before: '2021-04-30', + tags: ['travel', 'food'], + }); + assert(transactions.length === 0); + }); +}); diff --git a/tests/testIssuingPurchase.js b/tests/testIssuingPurchase.js index 6ce1ef7..a437538 100644 --- a/tests/testIssuingPurchase.js +++ b/tests/testIssuingPurchase.js @@ -28,6 +28,37 @@ describe('TestIssuingPurchaseGet', function() { }); }); +describe('TestIssuingPurchaseInstallmentCount', function() { + this.timeout(10000); + it('test_success', async () => { + let i = 0; + let purchases = await starkinfra.issuingPurchase.query({'limit': 10}); + for await (let purchase of purchases) { + assert(typeof purchase.id == 'string'); + assert('installmentCount' in purchase); + if (purchase.installmentCount != null) { + assert(typeof purchase.installmentCount == 'number'); + assert(Number.isInteger(purchase.installmentCount)); + } + i += 1; + } + assert(i > 0); + }); + + it('test_success_get', async () => { + let purchases = await starkinfra.issuingPurchase.query({'limit': 1}); + for await (let purchase of purchases) { + assert(typeof purchase.id == 'string'); + purchase = await starkinfra.issuingPurchase.get(purchase.id); + assert('installmentCount' in purchase); + if (purchase.installmentCount != null) { + assert(typeof purchase.installmentCount == 'number'); + assert(Number.isInteger(purchase.installmentCount)); + } + } + }); +}); + describe('TestIssuingPurchasePatch', function() { this.timeout(10000); it('test_success', async () => { diff --git a/tests/testIssuingToken.js b/tests/testIssuingToken.js index 0ecfe5c..f1bbde3 100644 --- a/tests/testIssuingToken.js +++ b/tests/testIssuingToken.js @@ -4,7 +4,7 @@ const starkinfra = require('../index.js'); starkinfra.user = require('./utils/user').exampleProject; -describe('TestIssuingTokenQuery', function() { +describe('TestIssuingTokenGet', function() { this.timeout(10000); it('test_success', async () => { let tokens = await starkinfra.issuingToken.query({'limit': 5}); @@ -14,7 +14,7 @@ describe('TestIssuingTokenQuery', function() { }); }); -describe('TestIssuingTokenPage', function() { +describe('TestIssuingTokenGetPage', function() { this.timeout(10000); it('test_success', async () => { let ids = []; @@ -30,10 +30,11 @@ describe('TestIssuingTokenPage', function() { break; } } + assert(ids.length === 10); }); }); -describe('TestIssuingTokenGet', function() { +describe('TestIssuingTokenInfoGet', function() { this.timeout(10000); it('test_success', async () => { let tokens = await starkinfra.issuingToken.query({'limit': 1}); @@ -45,7 +46,7 @@ describe('TestIssuingTokenGet', function() { }); }); -describe('TestIssuingTokenPatch', function(){ +describe('TestIssuingTokenInfoPatch', function(){ this.timeout(10000); it('test_success', async () => { let tokens = await starkinfra.issuingToken.query({'limit': 1, 'status': 'active'}); @@ -125,3 +126,21 @@ describe('TestIssuingTokenResponseActivation', function() { assert(typeof token === 'string'); }); }); + +describe('TestIssuingTokenActivationCode', function() { + this.timeout(10000); + it('test_success', async () => { + let token = new starkinfra.IssuingToken({ + cardId: '5189831499972623', + activationCode: '481632' + }); + assert(token.activationCode === '481632'); + }); + + it('test_success_default_null', async () => { + let token = new starkinfra.IssuingToken({ + cardId: '5189831499972623' + }); + assert(token.activationCode === null); + }); +});