diff --git a/package-lock.json b/package-lock.json index e24bd4c..77b8c05 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10492,6 +10492,50 @@ "resolved": "https://verdaccio.lossless.one/tslib/-/tslib-1.13.0.tgz", "integrity": "sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q==" }, + "tslint": { + "version": "6.1.3", + "resolved": "https://verdaccio.lossless.one/tslint/-/tslint-6.1.3.tgz", + "integrity": "sha512-IbR4nkT96EQOvKE2PW/djGz8iGNeJ4rF2mBfiYaR/nvUWYKJhLwimoJKgjIFEIDibBtOevj7BqCRL4oHeWWUCg==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.0.0", + "builtin-modules": "^1.1.1", + "chalk": "^2.3.0", + "commander": "^2.12.1", + "diff": "^4.0.1", + "glob": "^7.1.1", + "js-yaml": "^3.13.1", + "minimatch": "^3.0.4", + "mkdirp": "^0.5.3", + "resolve": "^1.3.2", + "semver": "^5.3.0", + "tslib": "^1.13.0", + "tsutils": "^2.29.0" + }, + "dependencies": { + "builtin-modules": { + "version": "1.1.1", + "resolved": "https://verdaccio.lossless.one/builtin-modules/-/builtin-modules-1.1.1.tgz", + "integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=", + "dev": true + } + } + }, + "tslint-config-prettier": { + "version": "1.18.0", + "resolved": "https://verdaccio.lossless.one/tslint-config-prettier/-/tslint-config-prettier-1.18.0.tgz", + "integrity": "sha512-xPw9PgNPLG3iKRxmK7DWr+Ea/SzrvfHtjFt5LBl61gk2UBG/DB9kCXRjv+xyIU1rUtnayLeMUVJBcMX8Z17nDg==", + "dev": true + }, + "tsutils": { + "version": "2.29.0", + "resolved": "https://verdaccio.lossless.one/tsutils/-/tsutils-2.29.0.tgz", + "integrity": "sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==", + "dev": true, + "requires": { + "tslib": "^1.8.1" + } + }, "tty-browserify": { "version": "0.0.0", "resolved": "https://verdaccio.lossless.one/tty-browserify/-/tty-browserify-0.0.0.tgz", diff --git a/package.json b/package.json index 7da55be..1e1da6a 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,9 @@ "@gitzone/tsbuild": "^2.1.25", "@gitzone/tstest": "^1.0.44", "@pushrocks/qenv": "^4.0.10", - "@pushrocks/tapbundle": "^3.2.9" + "@pushrocks/tapbundle": "^3.2.9", + "tslint": "^6.1.3", + "tslint-config-prettier": "^1.18.0" }, "dependencies": { "@pushrocks/smartrequest": "^1.1.47", diff --git a/test/test.ts b/test/test.ts index 46239a1..087076f 100644 --- a/test/test.ts +++ b/test/test.ts @@ -16,7 +16,10 @@ tap.test('should create a valid paypal instance', async () => { }); tap.test('should get an access token', async () => { - const transactions = await paypal.PayPalTransaction.getTransactionFor30days(testPayPalInstance, smarttime.ExtendedDate.fromHyphedDate('2020-05-01').getTime()); + const transactions = await testPayPalInstance.getTransactionsFromTo( + smarttime.ExtendedDate.fromHyphedDate('2020-01-01').getTime(), + smarttime.ExtendedDate.fromHyphedDate('2020-08-01').getTime(), + ); console.log(transactions); }); diff --git a/ts/index.ts b/ts/index.ts index 554615d..157d616 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1,2 +1,2 @@ -export * from './paypal.classes.paypal'; +export * from './paypal.classes.account'; export * from './paypal.classes.transaction'; diff --git a/ts/paypal.classes.paypal.ts b/ts/paypal.classes.account.ts similarity index 72% rename from ts/paypal.classes.paypal.ts rename to ts/paypal.classes.account.ts index d07e2c1..2e1659c 100644 --- a/ts/paypal.classes.paypal.ts +++ b/ts/paypal.classes.account.ts @@ -1,4 +1,5 @@ import * as plugins from './paypal.plugins'; +import { PayPalTransaction } from './paypal.classes.transaction'; export interface IPayPalOptions { clientId: string; @@ -16,6 +17,16 @@ export class PayPalAccount { this.options = optionsArg; } + public async getTransactionsFromTo (fromTimeMillisArg: number, toTimeMillisArg: number) { + let returnTransactions: PayPalTransaction[] = []; + do { + const transactions = await PayPalTransaction.getTransactionFor30days(this, fromTimeMillisArg); + returnTransactions = returnTransactions.concat(transactions); + fromTimeMillisArg = fromTimeMillisArg + plugins.smarttime.getMilliSecondsFromUnits({days: 30}); + } while (fromTimeMillisArg < toTimeMillisArg); + return returnTransactions; + } + public async request(methodArg: 'GET' | 'POST', routeArg: string, payloadArg: any) { if (!this.apiToken || this.apiTokenExpirationTime < Date.now()) { const authHeader = `Basic ${plugins.smartstring.base64.encode( diff --git a/ts/paypal.classes.transaction.ts b/ts/paypal.classes.transaction.ts index c50b6e1..02dd849 100644 --- a/ts/paypal.classes.transaction.ts +++ b/ts/paypal.classes.transaction.ts @@ -1,5 +1,5 @@ import * as plugins from './paypal.plugins'; -import { PayPalAccount } from './paypal.classes.paypal'; +import { PayPalAccount } from './paypal.classes.account'; export interface IPayPalOriginTransactionApiObject { paypal_account_id: string; @@ -33,8 +33,7 @@ export class PayPalTransaction { const endDate = startDate + plugins.smarttime.units.days(30); const startDateIso = plugins.smarttime.ExtendedDate.fromMillis(startDate).toISOString(); const endDateIso = plugins.smarttime.ExtendedDate.fromMillis(endDate).toISOString(); - console.log(endDateIso); - console.log(startDateIso); + console.log(`getting PayPal transactions from ${startDateIso} + ${endDateIso}`); const response = await paypalInstanceArg.request( 'GET', `/v1/reporting/transactions?start_date=${startDateIso}&end_date=${endDateIso}`,