mirror of
https://github.com/valitydev/koffing.git
synced 2024-11-06 01:05:19 +00:00
Add prettier (#238)
This commit is contained in:
parent
5edaae6cc4
commit
0db853e7cc
5
.prettierignore
Normal file
5
.prettierignore
Normal file
@ -0,0 +1,5 @@
|
||||
package.json
|
||||
package-lock.json
|
||||
node_modules
|
||||
dist
|
||||
build_utils
|
8
.prettierrc
Normal file
8
.prettierrc
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"printWidth": 100,
|
||||
"singleQuote": true,
|
||||
"useTabs": false,
|
||||
"tabWidth": 4,
|
||||
"semi": true,
|
||||
"bracketSpacing": true
|
||||
}
|
5
Makefile
5
Makefile
@ -35,7 +35,7 @@ submodules: $(SUBTARGETS)
|
||||
init:
|
||||
npm install
|
||||
|
||||
build:
|
||||
build: check
|
||||
npm run build
|
||||
|
||||
clean:
|
||||
@ -46,3 +46,6 @@ clean:
|
||||
|
||||
test: .state
|
||||
docker run --rm $(SERVICE_IMAGE_NAME):$(shell cat .state) nginx -T -c /etc/nginx/nginx.conf
|
||||
|
||||
check:
|
||||
npm run check
|
@ -1,9 +1,11 @@
|
||||
# Koffing
|
||||
|
||||
[![Build Status](http://ci.rbkmoney.com/buildStatus/icon?job=rbkmoney_private/koffing/master)](http://ci.rbkmoney.com/job/rbkmoney_private/view/Frontend/job/koffing/job/master/)
|
||||
|
||||
Личный кабинет мерчанта
|
||||
|
||||
## Настройка
|
||||
|
||||
Конфигурация приложения происходит в файле [appConfig.json](/config/runtime/appConfig.json)
|
||||
|
||||
Конфигурация keycloak происходит в файле [authConfig.json](/config/runtime/authConfig.json)
|
||||
@ -13,11 +15,11 @@
|
||||
Например в случае с nginx, json файлы нужно положить в `/usr/share/nginx/html`
|
||||
|
||||
## Установка и запуск
|
||||
Для загрузки зависимостей выполнить: `npm i `
|
||||
|
||||
Для загрузки зависимостей выполнить: `npm i`
|
||||
|
||||
Далее будут доступны следующие опции:
|
||||
|
||||
`npm start` - запуск приложения на локальном сервере. По умолчанию будет доступен на порту ```8000```. Порт задается в [package.json](/package.json)
|
||||
`npm start` - запуск приложения на локальном сервере. По умолчанию будет доступен на порту `8000`. Порт задается в [package.json](/package.json)
|
||||
|
||||
`npm build` - сборка prod версии статики.
|
||||
|
||||
|
@ -1,12 +1,10 @@
|
||||
const webpackConfig = require('./webpack.test');
|
||||
|
||||
module.exports = function (config) {
|
||||
module.exports = function(config) {
|
||||
config.set({
|
||||
basePath: __dirname,
|
||||
frameworks: ['jasmine'],
|
||||
files: [
|
||||
{pattern: 'karma-test-shim.js', watched: false}
|
||||
],
|
||||
files: [{ pattern: 'karma-test-shim.js', watched: false }],
|
||||
preprocessors: {
|
||||
'karma-test-shim.js': ['webpack', 'sourcemap']
|
||||
},
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"realm" : "external",
|
||||
"auth-server-url" : "http://auth.rbk.test:8080/auth/",
|
||||
"ssl-required" : "external",
|
||||
"resource" : "koffing",
|
||||
"public-client" : true
|
||||
"realm": "external",
|
||||
"auth-server-url": "http://auth.rbk.test:8080/auth/",
|
||||
"ssl-required": "external",
|
||||
"resource": "koffing",
|
||||
"public-client": true
|
||||
}
|
||||
|
@ -8,28 +8,25 @@ const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
entry: {
|
||||
'polyfills': './src/polyfills.ts',
|
||||
'vendor': './src/vendor.ts',
|
||||
'vendorjs': [
|
||||
polyfills: './src/polyfills.ts',
|
||||
vendor: './src/vendor.ts',
|
||||
vendorjs: [
|
||||
'./node_modules/jquery/dist/jquery.js',
|
||||
'./node_modules/bootstrap/dist/js/bootstrap.js',
|
||||
'./node_modules/keycloak-js/dist/keycloak.js',
|
||||
'./node_modules/suggestions-jquery/dist/js/jquery.suggestions.js',
|
||||
'./node_modules/xlsx-style/dist/xlsx.core.min.js'
|
||||
],
|
||||
'app': './src/main.ts'
|
||||
app: './src/main.ts'
|
||||
},
|
||||
|
||||
resolve: {
|
||||
modules: [
|
||||
path.join(__dirname, 'src'),
|
||||
'node_modules'
|
||||
],
|
||||
modules: [path.join(__dirname, 'src'), 'node_modules'],
|
||||
alias: {
|
||||
'Keycloak': 'keycloak-js/dist/keycloak.js',
|
||||
'jquery': 'jquery/dist/jquery',
|
||||
'suggestions': 'suggestions-jquery/dist/js/jquery.suggestions.js',
|
||||
'koffing': __dirname + '/../src/app'
|
||||
Keycloak: 'keycloak-js/dist/keycloak.js',
|
||||
jquery: 'jquery/dist/jquery',
|
||||
suggestions: 'suggestions-jquery/dist/js/jquery.suggestions.js',
|
||||
koffing: __dirname + '/../src/app'
|
||||
},
|
||||
extensions: ['.ts', '.js']
|
||||
},
|
||||
@ -55,12 +52,18 @@ module.exports = {
|
||||
{
|
||||
test: /\.css$/,
|
||||
exclude: helpers.root('src', 'app'),
|
||||
use: ExtractTextPlugin.extract({fallback: 'style-loader', use: 'css-loader?sourceMap'})
|
||||
use: ExtractTextPlugin.extract({
|
||||
fallback: 'style-loader',
|
||||
use: 'css-loader?sourceMap'
|
||||
})
|
||||
},
|
||||
{
|
||||
test: /\.less$/,
|
||||
exclude: helpers.root('src', 'app'),
|
||||
use: ExtractTextPlugin.extract({fallback: 'style-loader', use: ['css-loader?sourceMap', 'less-loader']})
|
||||
use: ExtractTextPlugin.extract({
|
||||
fallback: 'style-loader',
|
||||
use: ['css-loader?sourceMap', 'less-loader']
|
||||
})
|
||||
},
|
||||
{
|
||||
test: /\.less$/,
|
||||
@ -107,8 +110,10 @@ module.exports = {
|
||||
filename: 'index.html',
|
||||
template: 'src/index.pug'
|
||||
}),
|
||||
new CopyWebpackPlugin([{
|
||||
new CopyWebpackPlugin([
|
||||
{
|
||||
from: 'config/runtime'
|
||||
}])
|
||||
}
|
||||
])
|
||||
]
|
||||
};
|
@ -13,9 +13,7 @@ module.exports = webpackMerge(commonConfig, {
|
||||
chunkFilename: '[id].chunk.js'
|
||||
},
|
||||
|
||||
plugins: [
|
||||
new ExtractTextPlugin('[name].css')
|
||||
],
|
||||
plugins: [new ExtractTextPlugin('[name].css')],
|
||||
|
||||
devServer: {
|
||||
historyApiFallback: true,
|
||||
|
@ -4,7 +4,7 @@ const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||
const commonConfig = require('./webpack.common.js');
|
||||
const helpers = require('./helpers');
|
||||
|
||||
const ENV = process.env.NODE_ENV = process.env.ENV = 'production';
|
||||
const ENV = (process.env.NODE_ENV = process.env.ENV = 'production');
|
||||
|
||||
module.exports = webpackMerge(commonConfig, {
|
||||
output: {
|
||||
@ -27,7 +27,7 @@ module.exports = webpackMerge(commonConfig, {
|
||||
new ExtractTextPlugin('[name].[hash].css'),
|
||||
new webpack.DefinePlugin({
|
||||
'process.env': {
|
||||
'ENV': JSON.stringify(ENV)
|
||||
ENV: JSON.stringify(ENV)
|
||||
}
|
||||
}),
|
||||
new webpack.LoaderOptionsPlugin({
|
||||
|
@ -6,12 +6,9 @@ module.exports = {
|
||||
devtool: 'inline-source-map',
|
||||
|
||||
resolve: {
|
||||
modules: [
|
||||
path.join(__dirname, 'src'),
|
||||
'node_modules'
|
||||
],
|
||||
modules: [path.join(__dirname, 'src'), 'node_modules'],
|
||||
alias: {
|
||||
'koffing': __dirname + '/../src/app'
|
||||
koffing: __dirname + '/../src/app'
|
||||
},
|
||||
extensions: ['.ts', '.js']
|
||||
},
|
||||
|
9190
package-lock.json
generated
Normal file
9190
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -6,7 +6,9 @@
|
||||
"scripts": {
|
||||
"start": "webpack-dev-server --config config/webpack.dev.js --inline --progress --port 8000",
|
||||
"build": "rimraf dist && webpack --config config/webpack.prod.js --progress --profile --bail",
|
||||
"test": "karma start config/karma.conf.js"
|
||||
"test": "karma start config/karma.conf.js",
|
||||
"prettier": "prettier \"**/*.{html,js,ts,css,md,json,prettierrc,svg}\" --write",
|
||||
"check": "prettier \"**/*.{html,js,ts,css,md,json,prettierrc,svg}\" --list-different"
|
||||
},
|
||||
"licenses": [],
|
||||
"dependencies": {
|
||||
@ -67,12 +69,14 @@
|
||||
"less": "~2.7.2",
|
||||
"less-loader": "~4.0.4",
|
||||
"null-loader": "~0.1.1",
|
||||
"prettier": "~1.16.2",
|
||||
"pug-html-loader": "~1.1.5",
|
||||
"raw-loader": "~0.5.1",
|
||||
"rimraf": "~2.6.1",
|
||||
"script-loader": "~0.7.0",
|
||||
"style-loader": "~0.18.2",
|
||||
"tslint": "~5.8.0",
|
||||
"tslint-config-prettier": "^1.17.0",
|
||||
"tslint-loader": "~3.5.3",
|
||||
"typescript": "~2.5",
|
||||
"url-loader": "~0.5.9",
|
||||
|
@ -17,8 +17,6 @@ import { AccountComponent } from './account.component';
|
||||
}
|
||||
])
|
||||
],
|
||||
exports: [
|
||||
RouterModule
|
||||
]
|
||||
exports: [RouterModule]
|
||||
})
|
||||
export class AccountRoutingModule {}
|
||||
|
@ -11,14 +11,10 @@ import { AuthService } from 'koffing/auth/auth.service';
|
||||
styleUrls: ['./account.component.less']
|
||||
})
|
||||
export class AccountComponent implements OnInit {
|
||||
|
||||
public accountFrameUrl: SafeResourceUrl;
|
||||
public accountRouterLinks: object[];
|
||||
|
||||
constructor(
|
||||
private sanitizer: DomSanitizer,
|
||||
private route: ActivatedRoute
|
||||
) {}
|
||||
constructor(private sanitizer: DomSanitizer, private route: ActivatedRoute) {}
|
||||
|
||||
public ngOnInit() {
|
||||
this.initAccountRouterLinks();
|
||||
@ -28,8 +24,11 @@ export class AccountComponent implements OnInit {
|
||||
}
|
||||
|
||||
private getAccountFrameUrl(params: Params): SafeResourceUrl {
|
||||
const accountPath = (params['path'] === 'edit') ? '' : params['path'];
|
||||
const url = `${trimEnd(AuthService.getAccountInfo().authUrl, '/')}/realms/external/account/${accountPath}`;
|
||||
const accountPath = params['path'] === 'edit' ? '' : params['path'];
|
||||
const url = `${trimEnd(
|
||||
AuthService.getAccountInfo().authUrl,
|
||||
'/'
|
||||
)}/realms/external/account/${accountPath}`;
|
||||
return this.sanitizer.bypassSecurityTrustResourceUrl(url);
|
||||
}
|
||||
|
||||
@ -58,7 +57,7 @@ export class AccountComponent implements OnInit {
|
||||
{
|
||||
routePath: 'log',
|
||||
label: 'Логи'
|
||||
},
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -6,13 +6,7 @@ import { AccountRoutingModule } from './account-routing.module';
|
||||
import { CommonModule } from 'koffing/common/common.module';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
AccountRoutingModule,
|
||||
BrowserModule
|
||||
],
|
||||
declarations: [
|
||||
AccountComponent
|
||||
]
|
||||
imports: [CommonModule, AccountRoutingModule, BrowserModule],
|
||||
declarations: [AccountComponent]
|
||||
})
|
||||
export class AccountModule { }
|
||||
export class AccountModule {}
|
||||
|
@ -11,8 +11,6 @@ import { AnalyticsComponent } from './analytics.component';
|
||||
}
|
||||
])
|
||||
],
|
||||
exports: [
|
||||
RouterModule
|
||||
]
|
||||
exports: [RouterModule]
|
||||
})
|
||||
export class AnalyticsRoutingModule { }
|
||||
export class AnalyticsRoutingModule {}
|
||||
|
@ -16,10 +16,14 @@ import { AnalyticsService } from 'koffing/analytics/analytics.service';
|
||||
providers: [AnalyticsService]
|
||||
})
|
||||
export class AnalyticsComponent implements OnInit {
|
||||
|
||||
public shopID: string;
|
||||
public fromTime: Date = moment().subtract(1, 'day').startOf('day').toDate();
|
||||
public toTime: Date = moment().endOf('day').toDate();
|
||||
public fromTime: Date = moment()
|
||||
.subtract(1, 'day')
|
||||
.startOf('day')
|
||||
.toDate();
|
||||
public toTime: Date = moment()
|
||||
.endOf('day')
|
||||
.toDate();
|
||||
public profit: number = 0;
|
||||
|
||||
public panelData: Subject<PanelData> = new Subject();
|
||||
@ -32,11 +36,12 @@ export class AnalyticsComponent implements OnInit {
|
||||
public loadStatistic: Subject<null> = new Subject();
|
||||
private requestCount = 5;
|
||||
|
||||
constructor(private route: ActivatedRoute,
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private accountsService: AccountsService,
|
||||
private shopService: ShopService,
|
||||
private analyticsService: AnalyticsService) {
|
||||
}
|
||||
private analyticsService: AnalyticsService
|
||||
) {}
|
||||
|
||||
public ngOnInit() {
|
||||
this.route.parent.params.subscribe((params: Params) => {
|
||||
@ -62,21 +67,23 @@ export class AnalyticsComponent implements OnInit {
|
||||
}
|
||||
|
||||
private loadPaymentMethod(shopID: string, fromTime: Date, toTime: Date) {
|
||||
this.analyticsService.getPaymentMethodChartData(shopID, fromTime, toTime).subscribe((data) => {
|
||||
this.analyticsService
|
||||
.getPaymentMethodChartData(shopID, fromTime, toTime)
|
||||
.subscribe(data => {
|
||||
this.paymentMethodChartData.next(data);
|
||||
this.loadStatistic.next();
|
||||
});
|
||||
}
|
||||
|
||||
private loadRate(shopID: string, from: Date, to: Date) {
|
||||
this.analyticsService.getUniqueCount(shopID, from, to).subscribe((count) => {
|
||||
this.panelData.next({uniqueCount: count});
|
||||
this.analyticsService.getUniqueCount(shopID, from, to).subscribe(count => {
|
||||
this.panelData.next({ uniqueCount: count });
|
||||
this.loadStatistic.next();
|
||||
});
|
||||
}
|
||||
|
||||
private loadConversionStat(shopID: string, from: Date, to: Date) {
|
||||
this.analyticsService.getPaymentConversionData(shopID, from, to).subscribe((data) => {
|
||||
this.analyticsService.getPaymentConversionData(shopID, from, to).subscribe(data => {
|
||||
this.panelData.next({
|
||||
successfulCount: data.paymentCount.successfulCount,
|
||||
unfinishedCount: data.paymentCount.unfinishedCount
|
||||
@ -87,14 +94,14 @@ export class AnalyticsComponent implements OnInit {
|
||||
}
|
||||
|
||||
private loadGeoChartData(shopID: string, from: Date, to: Date) {
|
||||
this.analyticsService.getPaymentGeoChartData(shopID, from, to).subscribe((data) => {
|
||||
this.analyticsService.getPaymentGeoChartData(shopID, from, to).subscribe(data => {
|
||||
this.geoChartData.next(data);
|
||||
this.loadStatistic.next();
|
||||
});
|
||||
}
|
||||
|
||||
private loadRevenueStat(shopID: string, from: Date, to: Date) {
|
||||
this.analyticsService.getPaymentRevenueData(shopID, from, to).subscribe((data) => {
|
||||
this.analyticsService.getPaymentRevenueData(shopID, from, to).subscribe(data => {
|
||||
this.profit = data.profit;
|
||||
this.revenueChartData.next(data.revenueChartData);
|
||||
this.loadStatistic.next();
|
||||
@ -102,9 +109,9 @@ export class AnalyticsComponent implements OnInit {
|
||||
}
|
||||
|
||||
private loadAccounts(shopID: string) {
|
||||
this.shopService.getShopByID(shopID).subscribe((shop) => {
|
||||
this.accountsService.getAccountByID(shop.account.settlementID).subscribe((account) => {
|
||||
this.panelData.next({settlementBalance: account.ownAmount});
|
||||
this.shopService.getShopByID(shopID).subscribe(shop => {
|
||||
this.accountsService.getAccountByID(shop.account.settlementID).subscribe(account => {
|
||||
this.panelData.next({ settlementBalance: account.ownAmount });
|
||||
this.loadStatistic.next();
|
||||
});
|
||||
});
|
||||
|
@ -12,13 +12,7 @@ import { CommonModule } from 'koffing/common/common.module';
|
||||
import { BackendModule } from 'koffing/backend/backend.module';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
AnalyticsRoutingModule,
|
||||
BrowserModule,
|
||||
FormsModule,
|
||||
CommonModule,
|
||||
BackendModule
|
||||
],
|
||||
imports: [AnalyticsRoutingModule, BrowserModule, FormsModule, CommonModule, BackendModule],
|
||||
declarations: [
|
||||
AnalyticsComponent,
|
||||
BaseChartDirective,
|
||||
@ -27,4 +21,4 @@ import { BackendModule } from 'koffing/backend/backend.module';
|
||||
StatisticPanelComponent
|
||||
]
|
||||
})
|
||||
export class AnalyticsModule { }
|
||||
export class AnalyticsModule {}
|
||||
|
@ -11,35 +11,55 @@ import { PaymentRevenueData } from './stats-data/payment-revenue-data';
|
||||
|
||||
@Injectable()
|
||||
export class AnalyticsService {
|
||||
constructor(
|
||||
private analyticsService: AnalyticsBackendService,
|
||||
private locationService: LocationService
|
||||
) {}
|
||||
|
||||
constructor(private analyticsService: AnalyticsBackendService,
|
||||
private locationService: LocationService) {
|
||||
}
|
||||
|
||||
public getPaymentMethodChartData(shopID: string, from: Date, to: Date): Observable<DoughnutChartData> {
|
||||
return this.analyticsService.getPaymentMethodStats(shopID, from, to)
|
||||
.map((paymentMethodStats) => StatsDataConverter.toPaymentMethodChartData(paymentMethodStats));
|
||||
public getPaymentMethodChartData(
|
||||
shopID: string,
|
||||
from: Date,
|
||||
to: Date
|
||||
): Observable<DoughnutChartData> {
|
||||
return this.analyticsService
|
||||
.getPaymentMethodStats(shopID, from, to)
|
||||
.map(paymentMethodStats =>
|
||||
StatsDataConverter.toPaymentMethodChartData(paymentMethodStats)
|
||||
);
|
||||
}
|
||||
|
||||
public getUniqueCount(shopID: string, from: Date, to: Date): Observable<number> {
|
||||
return this.analyticsService.getPaymentRateStats(shopID, from, to)
|
||||
.map((paymentRateStat) => paymentRateStat ? paymentRateStat.uniqueCount : 0);
|
||||
return this.analyticsService
|
||||
.getPaymentRateStats(shopID, from, to)
|
||||
.map(paymentRateStat => (paymentRateStat ? paymentRateStat.uniqueCount : 0));
|
||||
}
|
||||
|
||||
public getPaymentConversionData(shopID: string, from: Date, to: Date): Observable<PaymentConversionData> {
|
||||
return this.analyticsService.getPaymentConversionStats(shopID, from, to).map((paymentConversionStat) => {
|
||||
public getPaymentConversionData(
|
||||
shopID: string,
|
||||
from: Date,
|
||||
to: Date
|
||||
): Observable<PaymentConversionData> {
|
||||
return this.analyticsService
|
||||
.getPaymentConversionStats(shopID, from, to)
|
||||
.map(paymentConversionStat => {
|
||||
const paymentCount = StatsDataConverter.toPaymentCountInfo(paymentConversionStat);
|
||||
const conversionChartData = StatsDataConverter.toConversionChartData(from, paymentConversionStat);
|
||||
return {paymentCount, conversionChartData};
|
||||
const conversionChartData = StatsDataConverter.toConversionChartData(
|
||||
from,
|
||||
paymentConversionStat
|
||||
);
|
||||
return { paymentCount, conversionChartData };
|
||||
});
|
||||
}
|
||||
|
||||
public getPaymentGeoChartData(shopID: string, from: Date, to: Date): Observable<DoughnutChartData> {
|
||||
public getPaymentGeoChartData(
|
||||
shopID: string,
|
||||
from: Date,
|
||||
to: Date
|
||||
): Observable<DoughnutChartData> {
|
||||
return Observable.create((observer: Observer<DoughnutChartData>) => {
|
||||
this.analyticsService.getPaymentGeoStats(shopID, from, to).subscribe((paymentGeoStat) => {
|
||||
this.analyticsService.getPaymentGeoStats(shopID, from, to).subscribe(paymentGeoStat => {
|
||||
const data = StatsDataConverter.toGeoChartData(paymentGeoStat);
|
||||
this.locationService.getLocationsNames(data.labels)
|
||||
.subscribe((locationNames) => {
|
||||
this.locationService.getLocationsNames(data.labels).subscribe(locationNames => {
|
||||
data.labels = locationNames.map(locationName => locationName.name);
|
||||
observer.next(data);
|
||||
});
|
||||
@ -47,11 +67,20 @@ export class AnalyticsService {
|
||||
});
|
||||
}
|
||||
|
||||
public getPaymentRevenueData(shopID: string, from: Date, to: Date): Observable<PaymentRevenueData> {
|
||||
return this.analyticsService.getPaymentRevenueStats(shopID, from, to).map((paymentRevenueStat) => {
|
||||
public getPaymentRevenueData(
|
||||
shopID: string,
|
||||
from: Date,
|
||||
to: Date
|
||||
): Observable<PaymentRevenueData> {
|
||||
return this.analyticsService
|
||||
.getPaymentRevenueStats(shopID, from, to)
|
||||
.map(paymentRevenueStat => {
|
||||
const profit = StatsDataConverter.toTotalProfit(paymentRevenueStat);
|
||||
const revenueChartData = StatsDataConverter.toRevenueChartData(from, paymentRevenueStat);
|
||||
return {profit, revenueChartData};
|
||||
const revenueChartData = StatsDataConverter.toRevenueChartData(
|
||||
from,
|
||||
paymentRevenueStat
|
||||
);
|
||||
return { profit, revenueChartData };
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import { DoughnutChartData } from 'koffing/analytics/stats-data/doughnut-chart-d
|
||||
templateUrl: './doughnut-chart.component.pug'
|
||||
})
|
||||
export class DoughnutChartComponent implements OnInit {
|
||||
|
||||
@Input()
|
||||
public chartData: Observable<DoughnutChartData>;
|
||||
|
||||
@ -24,8 +23,9 @@ export class DoughnutChartComponent implements OnInit {
|
||||
}
|
||||
};
|
||||
|
||||
public chartColors = [{
|
||||
backgroundColor : [
|
||||
public chartColors = [
|
||||
{
|
||||
backgroundColor: [
|
||||
'#ddf0e1',
|
||||
'#cee9f6',
|
||||
'#fddadb',
|
||||
@ -43,7 +43,8 @@ export class DoughnutChartComponent implements OnInit {
|
||||
'#f8f8f8',
|
||||
'#ccfaf6'
|
||||
]
|
||||
}];
|
||||
}
|
||||
];
|
||||
|
||||
public ngOnInit() {
|
||||
this.chartData.subscribe((chartData: DoughnutChartData) => {
|
||||
|
@ -8,7 +8,6 @@ import { LineChartData } from 'koffing/analytics/stats-data/line-chart-data';
|
||||
templateUrl: './line-chart.component.pug'
|
||||
})
|
||||
export class LineChartComponent implements OnInit {
|
||||
|
||||
@Input()
|
||||
public chartData: Observable<LineChartData>;
|
||||
|
||||
@ -23,28 +22,34 @@ export class LineChartComponent implements OnInit {
|
||||
}
|
||||
},
|
||||
scales: {
|
||||
yAxes: [{
|
||||
yAxes: [
|
||||
{
|
||||
stacked: true
|
||||
}],
|
||||
xAxes: [{
|
||||
}
|
||||
],
|
||||
xAxes: [
|
||||
{
|
||||
ticks: {
|
||||
fontSize: 11
|
||||
}
|
||||
}]
|
||||
}
|
||||
]
|
||||
},
|
||||
legend: {
|
||||
display: false
|
||||
}
|
||||
};
|
||||
|
||||
public chartColors = [{
|
||||
public chartColors = [
|
||||
{
|
||||
backgroundColor: 'rgba(148,159,177,0.2)',
|
||||
borderColor: '#73879C',
|
||||
pointBackgroundColor: '#73879C',
|
||||
pointBorderColor: '#fff',
|
||||
pointHoverBackgroundColor: '#79909c',
|
||||
pointHoverBorderColor: '#fff',
|
||||
}];
|
||||
pointHoverBorderColor: '#fff'
|
||||
}
|
||||
];
|
||||
|
||||
public ngOnInit() {
|
||||
this.chartData.subscribe((chartData: LineChartData) => {
|
||||
|
@ -9,7 +9,6 @@ import { PanelData } from 'koffing/analytics/statistic-panel/panel-data';
|
||||
templateUrl: './statistic-panel.component.pug'
|
||||
})
|
||||
export class StatisticPanelComponent implements OnInit {
|
||||
|
||||
@Input()
|
||||
public data: Observable<PanelData>;
|
||||
|
||||
|
@ -11,11 +11,12 @@ import { Dataset } from './dataset';
|
||||
import { DoughnutChartData } from './doughnut-chart-data';
|
||||
|
||||
export class StatsDataConverter {
|
||||
|
||||
public static toPaymentMethodChartData(stat: PaymentMethodStat[]): DoughnutChartData {
|
||||
const group = groupBy(stat, 'paymentSystem');
|
||||
const paymentSystems = keys(group);
|
||||
const data = paymentSystems.map((system) => group[system].reduce((acc, item) => acc + item.totalCount, 0));
|
||||
const data = paymentSystems.map(system =>
|
||||
group[system].reduce((acc, item) => acc + item.totalCount, 0)
|
||||
);
|
||||
const labels = paymentSystems.map(system => {
|
||||
let result = system;
|
||||
if (system === 'visa') {
|
||||
@ -27,32 +28,46 @@ export class StatsDataConverter {
|
||||
}
|
||||
return result;
|
||||
});
|
||||
return {data, labels};
|
||||
return { data, labels };
|
||||
}
|
||||
|
||||
public static toGeoChartData(stat: PaymentGeoStat[]): DoughnutChartData {
|
||||
const group = groupBy(stat, 'geoID');
|
||||
const labels = keys(group);
|
||||
const data = labels.map(geoID => group[geoID].reduce((acc, item) => acc + item.profit, 0) / 100);
|
||||
return {data, labels};
|
||||
const data = labels.map(
|
||||
geoID => group[geoID].reduce((acc, item) => acc + item.profit, 0) / 100
|
||||
);
|
||||
return { data, labels };
|
||||
}
|
||||
|
||||
public static toRevenueChartData(from: Date, stat: PaymentRevenueStat[]): LineChartData {
|
||||
const labels = stat.map((item) => moment(from).add(item.offset, 's').format('DD.MM HH:mm'));
|
||||
const datasets: Dataset[] = [{
|
||||
const labels = stat.map(item =>
|
||||
moment(from)
|
||||
.add(item.offset, 's')
|
||||
.format('DD.MM HH:mm')
|
||||
);
|
||||
const datasets: Dataset[] = [
|
||||
{
|
||||
label: 'Оборот',
|
||||
data: stat.map((item) => round(item.profit / 100, 2))
|
||||
}];
|
||||
return {labels, datasets};
|
||||
data: stat.map(item => round(item.profit / 100, 2))
|
||||
}
|
||||
];
|
||||
return { labels, datasets };
|
||||
}
|
||||
|
||||
public static toConversionChartData(from: Date, stat: PaymentConversionStat[]): LineChartData {
|
||||
const labels = stat.map((item) => moment(from).add(item.offset, 's').format('DD.MM HH:mm'));
|
||||
const datasets: Dataset[] = [{
|
||||
const labels = stat.map(item =>
|
||||
moment(from)
|
||||
.add(item.offset, 's')
|
||||
.format('DD.MM HH:mm')
|
||||
);
|
||||
const datasets: Dataset[] = [
|
||||
{
|
||||
label: 'Конверсия',
|
||||
data: stat.map((item) => round(item.conversion * 100, 0))
|
||||
}];
|
||||
return {labels, datasets};
|
||||
data: stat.map(item => round(item.conversion * 100, 0))
|
||||
}
|
||||
];
|
||||
return { labels, datasets };
|
||||
}
|
||||
|
||||
public static toTotalProfit(stat: PaymentRevenueStat[]): number {
|
||||
@ -60,11 +75,14 @@ export class StatsDataConverter {
|
||||
}
|
||||
|
||||
public static toPaymentCountInfo(stat: PaymentConversionStat[]): PaymentCount {
|
||||
return stat.reduce((acc, item) => {
|
||||
return stat.reduce(
|
||||
(acc, item) => {
|
||||
return {
|
||||
successfulCount: acc.successfulCount + item.successfulCount,
|
||||
unfinishedCount: acc.unfinishedCount + (item.totalCount - item.successfulCount)
|
||||
};
|
||||
}, {successfulCount: 0, unfinishedCount: 0});
|
||||
},
|
||||
{ successfulCount: 0, unfinishedCount: 0 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -8,10 +8,7 @@ import { ContainerComponent } from './root/components/container/container.compon
|
||||
import { RootModule } from './root/root.module';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
HttpModule,
|
||||
RootModule
|
||||
],
|
||||
imports: [HttpModule, RootModule],
|
||||
providers: [
|
||||
{
|
||||
provide: KoffingHttp,
|
||||
@ -31,4 +28,4 @@ import { RootModule } from './root/root.module';
|
||||
],
|
||||
bootstrap: [ContainerComponent]
|
||||
})
|
||||
export class AppModule { }
|
||||
export class AppModule {}
|
||||
|
@ -3,16 +3,17 @@ import { AuthInfo } from './auth-info';
|
||||
declare const Keycloak: any;
|
||||
|
||||
export class AuthService {
|
||||
|
||||
public static authInstance: any;
|
||||
|
||||
public static init(): Promise<any> {
|
||||
const auth: any = new Keycloak('authConfig.json');
|
||||
return new Promise((resolve, reject) => {
|
||||
auth.init({onLoad: 'login-required'}).success(() => {
|
||||
auth.init({ onLoad: 'login-required' })
|
||||
.success(() => {
|
||||
this.authInstance = auth;
|
||||
resolve();
|
||||
}).error(() => reject());
|
||||
})
|
||||
.error(() => reject());
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -7,13 +7,11 @@ import { Account } from './model';
|
||||
|
||||
@Injectable()
|
||||
export class AccountsService {
|
||||
|
||||
constructor(
|
||||
private http: KoffingHttp,
|
||||
private config: ConfigService
|
||||
) { }
|
||||
constructor(private http: KoffingHttp, private config: ConfigService) {}
|
||||
|
||||
public getAccountByID(accountID: number): Observable<Account> {
|
||||
return this.http.get(`${this.config.capiUrl}/processing/accounts/${accountID}`).map(res => res.json());
|
||||
return this.http
|
||||
.get(`${this.config.capiUrl}/processing/accounts/${accountID}`)
|
||||
.map(res => res.json());
|
||||
}
|
||||
}
|
||||
|
@ -16,57 +16,84 @@ import {
|
||||
|
||||
@Injectable()
|
||||
export class AnalyticsService {
|
||||
constructor(private http: KoffingHttp, private config: ConfigService) {}
|
||||
|
||||
constructor(private http: KoffingHttp,
|
||||
private config: ConfigService) {
|
||||
}
|
||||
|
||||
public getPaymentMethodStats(shopID: string, from: Date, to: Date, splitUnit?: string, splitSize?: number, paymentMethod?: string): Observable<PaymentMethodStat[]> {
|
||||
public getPaymentMethodStats(
|
||||
shopID: string,
|
||||
from: Date,
|
||||
to: Date,
|
||||
splitUnit?: string,
|
||||
splitSize?: number,
|
||||
paymentMethod?: string
|
||||
): Observable<PaymentMethodStat[]> {
|
||||
const search = new URLSearchParams();
|
||||
search.set('fromTime', this.toUTC(from));
|
||||
search.set('toTime', this.toUTC(to));
|
||||
search.set('splitUnit', splitUnit || 'minute');
|
||||
search.set('splitSize', this.getSplitSize(splitSize));
|
||||
search.set('paymentMethod', paymentMethod || 'bankCard');
|
||||
return this.http.get(`${this.getEndpoint(shopID, 'customers')}/payment_method`, {search})
|
||||
.map((res) => res.json());
|
||||
return this.http
|
||||
.get(`${this.getEndpoint(shopID, 'customers')}/payment_method`, { search })
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
public getPaymentRateStats(shopID: string, from: Date, to: Date): Observable<PaymentRateStat> {
|
||||
const search = new URLSearchParams();
|
||||
search.set('fromTime', this.toUTC(from));
|
||||
search.set('toTime', this.toUTC(to));
|
||||
return this.http.get(`${this.getEndpoint(shopID, 'customers')}/rate`, {search})
|
||||
.map((res) => res.json());
|
||||
return this.http
|
||||
.get(`${this.getEndpoint(shopID, 'customers')}/rate`, { search })
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
public getPaymentConversionStats(shopID: string, from: Date, to: Date, splitUnit?: string, splitSize?: number): Observable<PaymentConversionStat[]> {
|
||||
public getPaymentConversionStats(
|
||||
shopID: string,
|
||||
from: Date,
|
||||
to: Date,
|
||||
splitUnit?: string,
|
||||
splitSize?: number
|
||||
): Observable<PaymentConversionStat[]> {
|
||||
const search = new URLSearchParams();
|
||||
search.set('fromTime', this.toUTC(from));
|
||||
search.set('toTime', this.toUTC(to));
|
||||
search.set('splitUnit', splitUnit || 'minute');
|
||||
search.set('splitSize', this.getSplitSize(splitSize));
|
||||
return this.http.get(`${this.getEndpoint(shopID, 'payments')}/conversion`, {search})
|
||||
.map((res) => res.json());
|
||||
return this.http
|
||||
.get(`${this.getEndpoint(shopID, 'payments')}/conversion`, { search })
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
public getPaymentGeoStats(shopID: string, from: Date, to: Date, splitUnit?: string, splitSize?: number): Observable<PaymentGeoStat[]> {
|
||||
public getPaymentGeoStats(
|
||||
shopID: string,
|
||||
from: Date,
|
||||
to: Date,
|
||||
splitUnit?: string,
|
||||
splitSize?: number
|
||||
): Observable<PaymentGeoStat[]> {
|
||||
const search = new URLSearchParams();
|
||||
search.set('fromTime', this.toUTC(from));
|
||||
search.set('toTime', this.toUTC(to));
|
||||
search.set('splitUnit', splitUnit || 'day');
|
||||
search.set('splitSize', this.getSplitSize(splitSize));
|
||||
return this.http.get(`${this.getEndpoint(shopID, 'payments')}/geo`, {search})
|
||||
.map((res) => res.json());
|
||||
return this.http
|
||||
.get(`${this.getEndpoint(shopID, 'payments')}/geo`, { search })
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
public getPaymentRevenueStats(shopID: string, from: Date, to: Date, splitUnit?: string, splitSize?: number): Observable<PaymentRevenueStat[]> {
|
||||
public getPaymentRevenueStats(
|
||||
shopID: string,
|
||||
from: Date,
|
||||
to: Date,
|
||||
splitUnit?: string,
|
||||
splitSize?: number
|
||||
): Observable<PaymentRevenueStat[]> {
|
||||
const search = new URLSearchParams();
|
||||
search.set('fromTime', this.toUTC(from));
|
||||
search.set('toTime', this.toUTC(to));
|
||||
search.set('splitUnit', splitUnit || 'minute');
|
||||
search.set('splitSize', this.getSplitSize(splitSize));
|
||||
return this.http.get(`${this.getEndpoint(shopID, 'payments')}/revenue`, {search})
|
||||
return this.http
|
||||
.get(`${this.getEndpoint(shopID, 'payments')}/revenue`, { search })
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
@ -75,7 +102,9 @@ export class AnalyticsService {
|
||||
}
|
||||
|
||||
private toUTC(date: Date): string {
|
||||
return moment(date).utc().format();
|
||||
return moment(date)
|
||||
.utc()
|
||||
.format();
|
||||
}
|
||||
|
||||
private getSplitSize(splitSize: number) {
|
||||
|
@ -37,4 +37,4 @@ import { DownloadService } from './download.service';
|
||||
DownloadService
|
||||
]
|
||||
})
|
||||
export class BackendModule { }
|
||||
export class BackendModule {}
|
||||
|
@ -7,19 +7,15 @@ import { Category } from './model';
|
||||
|
||||
@Injectable()
|
||||
export class CategoryService {
|
||||
|
||||
private endpoint = `${this.config.capiUrl}/processing/categories`;
|
||||
|
||||
constructor(
|
||||
private http: KoffingHttp,
|
||||
private config: ConfigService
|
||||
) { }
|
||||
constructor(private http: KoffingHttp, private config: ConfigService) {}
|
||||
|
||||
public getCategories(): Observable<Category[]> {
|
||||
return this.http.get(this.endpoint).map((res) => res.json());
|
||||
return this.http.get(this.endpoint).map(res => res.json());
|
||||
}
|
||||
|
||||
public getCategoryByID(categoryID: number): Observable<Category> {
|
||||
return this.http.get(`${this.endpoint}/${categoryID}`).map((res) => res.json());
|
||||
return this.http.get(`${this.endpoint}/${categoryID}`).map(res => res.json());
|
||||
}
|
||||
}
|
||||
|
@ -8,38 +8,47 @@ import { Claim, PartyModification } from './model';
|
||||
|
||||
@Injectable()
|
||||
export class ClaimService {
|
||||
|
||||
private endpoint = `${this.config.capiUrl}/processing/claims`;
|
||||
|
||||
constructor(private http: KoffingHttp,
|
||||
private config: ConfigService) {
|
||||
}
|
||||
constructor(private http: KoffingHttp, private config: ConfigService) {}
|
||||
|
||||
public getClaims(claimStatus?: string): Observable<Claim[]> {
|
||||
const search = new URLSearchParams();
|
||||
if (claimStatus) {
|
||||
search.set('claimStatus', claimStatus);
|
||||
}
|
||||
return this.http.get(this.endpoint, {search}).map((res) => res.json());
|
||||
return this.http.get(this.endpoint, { search }).map(res => res.json());
|
||||
}
|
||||
|
||||
public createClaim(claimChangeset: PartyModification[]): Observable<Claim> {
|
||||
return this.http.post(this.endpoint, claimChangeset).map((res) => res.json());
|
||||
return this.http.post(this.endpoint, claimChangeset).map(res => res.json());
|
||||
}
|
||||
|
||||
public getClaimByID(claimID: number): Observable<Claim> {
|
||||
return this.http.get(`${this.endpoint}/${claimID}`).map((res) => res.json());
|
||||
return this.http.get(`${this.endpoint}/${claimID}`).map(res => res.json());
|
||||
}
|
||||
|
||||
public revokeClaimByID(claimID: number, claimRevision: number, reason: string): Observable<void> {
|
||||
public revokeClaimByID(
|
||||
claimID: number,
|
||||
claimRevision: number,
|
||||
reason: string
|
||||
): Observable<void> {
|
||||
const search = new URLSearchParams();
|
||||
search.set('claimRevision', String(claimRevision));
|
||||
return this.http.put(`${this.endpoint}/${claimID}/revoke`, {reason}, {search}).map((res) => res.json());
|
||||
return this.http
|
||||
.put(`${this.endpoint}/${claimID}/revoke`, { reason }, { search })
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
public updateClaimByID(claimID: number, claimRevision: number, claimChangeset: PartyModification[]): Observable<void> {
|
||||
public updateClaimByID(
|
||||
claimID: number,
|
||||
claimRevision: number,
|
||||
claimChangeset: PartyModification[]
|
||||
): Observable<void> {
|
||||
const search = new URLSearchParams();
|
||||
search.set('claimRevision', String(claimRevision));
|
||||
return this.http.post(`${this.endpoint}/${claimID}/update`, claimChangeset, {search}).map((res) => res.json());
|
||||
return this.http
|
||||
.post(`${this.endpoint}/${claimID}/update`, claimChangeset, { search })
|
||||
.map(res => res.json());
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable()
|
||||
export class ConfigService {
|
||||
|
||||
public capiUrl: string;
|
||||
public wapiUrl: string;
|
||||
public checkoutUrl: string;
|
||||
@ -11,11 +10,13 @@ export class ConfigService {
|
||||
public supportEmail: string;
|
||||
public shortenUrlEndpoint: string;
|
||||
|
||||
constructor(private http: Http) { }
|
||||
constructor(private http: Http) {}
|
||||
|
||||
public load() {
|
||||
return new Promise(resolve => {
|
||||
this.http.get(`appConfig.json?timestamp=${new Date().getTime()}`).map(res => res.json())
|
||||
this.http
|
||||
.get(`appConfig.json?timestamp=${new Date().getTime()}`)
|
||||
.map(res => res.json())
|
||||
.subscribe(data => {
|
||||
this.capiUrl = `${data.capiEndpoint}/v2`;
|
||||
this.wapiUrl = `${data.capiEndpoint}/wallet/v0`;
|
||||
|
@ -7,19 +7,15 @@ import { Contract } from './model';
|
||||
|
||||
@Injectable()
|
||||
export class ContractService {
|
||||
|
||||
private endpoint: string = `${this.config.capiUrl}/processing/contracts`;
|
||||
|
||||
constructor(
|
||||
private http: KoffingHttp,
|
||||
private config: ConfigService
|
||||
) { }
|
||||
constructor(private http: KoffingHttp, private config: ConfigService) {}
|
||||
|
||||
public getContracts(): Observable<Contract[]> {
|
||||
return this.http.get(this.endpoint).map((res) => res.json());
|
||||
return this.http.get(this.endpoint).map(res => res.json());
|
||||
}
|
||||
|
||||
public getContractByID(contractID: string): Observable<Contract> {
|
||||
return this.http.get(`${this.endpoint}/${contractID}`).map((res) => res.json());
|
||||
return this.http.get(`${this.endpoint}/${contractID}`).map(res => res.json());
|
||||
}
|
||||
}
|
||||
|
@ -7,15 +7,11 @@ import { Customer } from './model';
|
||||
|
||||
@Injectable()
|
||||
export class CustomerService {
|
||||
|
||||
private endpoint: string = `${this.config.capiUrl}/processing/customers`;
|
||||
|
||||
constructor(
|
||||
private http: KoffingHttp,
|
||||
private config: ConfigService
|
||||
) { }
|
||||
constructor(private http: KoffingHttp, private config: ConfigService) {}
|
||||
|
||||
public getCustomerById(customerID: string): Observable<Customer> {
|
||||
return this.http.get(`${this.endpoint}/${customerID}`).map((res) => res.json());
|
||||
return this.http.get(`${this.endpoint}/${customerID}`).map(res => res.json());
|
||||
}
|
||||
}
|
||||
|
@ -7,14 +7,19 @@ import { ReportLink } from 'koffing/backend/model';
|
||||
|
||||
@Injectable()
|
||||
export class DownloadService {
|
||||
constructor(private http: KoffingHttp, private config: ConfigService) {}
|
||||
|
||||
constructor(
|
||||
private http: KoffingHttp,
|
||||
private config: ConfigService
|
||||
) { }
|
||||
|
||||
public downloadReport(shopID: string, reportID: number, fileID: string): Observable<ReportLink> {
|
||||
return this.http.get(`${this.config.capiUrl}/shops/${shopID}/reports/${reportID}/files/${fileID}/download`)
|
||||
.map((response) => response.json());
|
||||
public downloadReport(
|
||||
shopID: string,
|
||||
reportID: number,
|
||||
fileID: string
|
||||
): Observable<ReportLink> {
|
||||
return this.http
|
||||
.get(
|
||||
`${
|
||||
this.config.capiUrl
|
||||
}/shops/${shopID}/reports/${reportID}/files/${fileID}/download`
|
||||
)
|
||||
.map(response => response.json());
|
||||
}
|
||||
}
|
||||
|
@ -8,20 +8,22 @@ import { Event } from './model';
|
||||
|
||||
@Injectable()
|
||||
export class EventService {
|
||||
|
||||
private endpoint: string = `${this.config.capiUrl}/processing/invoices`;
|
||||
|
||||
constructor(
|
||||
private http: KoffingHttp,
|
||||
private config: ConfigService
|
||||
) { }
|
||||
constructor(private http: KoffingHttp, private config: ConfigService) {}
|
||||
|
||||
public getInvoiceEvents(invoiceID: string, limit: number, eventID?: number): Observable<Event[]> {
|
||||
public getInvoiceEvents(
|
||||
invoiceID: string,
|
||||
limit: number,
|
||||
eventID?: number
|
||||
): Observable<Event[]> {
|
||||
const search = new URLSearchParams();
|
||||
search.set('limit', String(limit));
|
||||
if (eventID) {
|
||||
search.set('eventID', String(eventID));
|
||||
}
|
||||
return this.http.get(`${this.endpoint}/${invoiceID}/events`, {search}).map((res) => res.json());
|
||||
return this.http
|
||||
.get(`${this.endpoint}/${invoiceID}/events`, { search })
|
||||
.map(res => res.json());
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
export function applyMixins(derivedCtor: any, baseCtors: any[]) {
|
||||
baseCtors.forEach((baseCtor) => {
|
||||
Object.getOwnPropertyNames(baseCtor.prototype).forEach((name) => {
|
||||
baseCtors.forEach(baseCtor => {
|
||||
Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => {
|
||||
derivedCtor.prototype[name] = baseCtor.prototype[name];
|
||||
});
|
||||
});
|
||||
|
@ -8,31 +8,42 @@ import { InvoiceTemplate, InvoiceTemplateAndToken, PaymentMethod } from './model
|
||||
|
||||
@Injectable()
|
||||
export class InvoiceTemplateService {
|
||||
|
||||
private invoiceTemplatesUrl: string = `${this.config.capiUrl}/processing/invoice-templates`;
|
||||
|
||||
constructor(
|
||||
private http: KoffingHttp,
|
||||
private config: ConfigService
|
||||
) {}
|
||||
constructor(private http: KoffingHttp, private config: ConfigService) {}
|
||||
|
||||
public getInvoiceTemplateByID(invoiceTemplateID: string): Observable<InvoiceTemplate> {
|
||||
return this.http.get(`${this.invoiceTemplatesUrl}/${invoiceTemplateID}`).map(res => res.json());
|
||||
return this.http
|
||||
.get(`${this.invoiceTemplatesUrl}/${invoiceTemplateID}`)
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
public createInvoiceTemplate(params: InvoiceTemplateParams): Observable<InvoiceTemplateAndToken> {
|
||||
public createInvoiceTemplate(
|
||||
params: InvoiceTemplateParams
|
||||
): Observable<InvoiceTemplateAndToken> {
|
||||
return this.http.post(this.invoiceTemplatesUrl, params).map(res => res.json());
|
||||
}
|
||||
|
||||
public updateInvoiceTemplate(invoiceTemplateID: string, params: InvoiceTemplateParams): Observable<InvoiceTemplate> {
|
||||
return this.http.put(`${this.invoiceTemplatesUrl}/${invoiceTemplateID}`, params).map(res => res.json());
|
||||
public updateInvoiceTemplate(
|
||||
invoiceTemplateID: string,
|
||||
params: InvoiceTemplateParams
|
||||
): Observable<InvoiceTemplate> {
|
||||
return this.http
|
||||
.put(`${this.invoiceTemplatesUrl}/${invoiceTemplateID}`, params)
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
public deleteInvoiceTemplate(invoiceTemplateID: string): Observable<any> {
|
||||
return this.http.delete(`${this.invoiceTemplatesUrl}/${invoiceTemplateID}`).map(res => res.json());
|
||||
return this.http
|
||||
.delete(`${this.invoiceTemplatesUrl}/${invoiceTemplateID}`)
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
public getInvoiceTemplatePaymentMethods(invoiceTemplateID: string): Observable<PaymentMethod[]> {
|
||||
return this.http.get(`${this.invoiceTemplatesUrl}/${invoiceTemplateID}/payment-methods`).map(res => res.json());
|
||||
public getInvoiceTemplatePaymentMethods(
|
||||
invoiceTemplateID: string
|
||||
): Observable<PaymentMethod[]> {
|
||||
return this.http
|
||||
.get(`${this.invoiceTemplatesUrl}/${invoiceTemplateID}/payment-methods`)
|
||||
.map(res => res.json());
|
||||
}
|
||||
}
|
||||
|
@ -10,46 +10,51 @@ import { PaymentRefund } from 'koffing/backend/model';
|
||||
|
||||
@Injectable()
|
||||
export class InvoiceService {
|
||||
|
||||
private endpoint = `${this.config.capiUrl}/processing/invoices`;
|
||||
|
||||
constructor(
|
||||
private http: KoffingHttp,
|
||||
private config: ConfigService
|
||||
) {}
|
||||
constructor(private http: KoffingHttp, private config: ConfigService) {}
|
||||
|
||||
public createInvoice(params: InvoiceParams): Observable<InvoiceAndToken> {
|
||||
return this.http.post(this.endpoint, params)
|
||||
.map(res => res.json());
|
||||
return this.http.post(this.endpoint, params).map(res => res.json());
|
||||
}
|
||||
|
||||
public createInvoiceAccessToken(invoiceID: string): Observable<InvoiceAccessToken> {
|
||||
return this.http.post(`${this.endpoint}/${invoiceID}/access-tokens`, {})
|
||||
.map((res) => res.json());
|
||||
return this.http
|
||||
.post(`${this.endpoint}/${invoiceID}/access-tokens`, {})
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
public capturePayment(invoiceID: string, paymentID: string, reason: string): Observable<void> {
|
||||
return this.http.post(`${this.endpoint}/${invoiceID}/payments/${paymentID}/capture`, {reason})
|
||||
.map((res) => null);
|
||||
return this.http
|
||||
.post(`${this.endpoint}/${invoiceID}/payments/${paymentID}/capture`, { reason })
|
||||
.map(res => null);
|
||||
}
|
||||
|
||||
public cancelPayment(invoiceID: string, paymentID: string, reason: string): Observable<void> {
|
||||
return this.http.post(`${this.endpoint}/${invoiceID}/payments/${paymentID}/cancel`, {reason})
|
||||
.map((res) => null);
|
||||
return this.http
|
||||
.post(`${this.endpoint}/${invoiceID}/payments/${paymentID}/cancel`, { reason })
|
||||
.map(res => null);
|
||||
}
|
||||
|
||||
public refundPayment(invoiceID: string, paymentID: string, params: RefundParams): Observable<PaymentRefund> {
|
||||
return this.http.post(`${this.endpoint}/${invoiceID}/payments/${paymentID}/refunds`, {...params})
|
||||
.map((res) => res.json());
|
||||
public refundPayment(
|
||||
invoiceID: string,
|
||||
paymentID: string,
|
||||
params: RefundParams
|
||||
): Observable<PaymentRefund> {
|
||||
return this.http
|
||||
.post(`${this.endpoint}/${invoiceID}/payments/${paymentID}/refunds`, { ...params })
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
public getRefunds(invoiceID: string, paymentID: string): Observable<PaymentRefund[]> {
|
||||
return this.http.get(`${this.endpoint}/${invoiceID}/payments/${paymentID}/refunds`)
|
||||
return this.http
|
||||
.get(`${this.endpoint}/${invoiceID}/payments/${paymentID}/refunds`)
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
public getInvoicePaymentMethods(invoiceID: string): Observable<PaymentMethod[]> {
|
||||
return this.http.get(`${this.endpoint}/${invoiceID}/payment-methods`)
|
||||
return this.http
|
||||
.get(`${this.endpoint}/${invoiceID}/payment-methods`)
|
||||
.map(res => res.json());
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,18 @@
|
||||
import { Http, ConnectionBackend, RequestOptions, Request, RequestOptionsArgs, Response, Headers } from '@angular/http';
|
||||
import {
|
||||
Http,
|
||||
ConnectionBackend,
|
||||
RequestOptions,
|
||||
Request,
|
||||
RequestOptionsArgs,
|
||||
Response,
|
||||
Headers
|
||||
} from '@angular/http';
|
||||
import { Observable, Observer } from 'rxjs';
|
||||
|
||||
import { HttpErrorBroadcaster } from 'koffing/broadcaster';
|
||||
import { AuthService } from 'koffing/auth/auth.service';
|
||||
|
||||
export class KoffingHttp extends Http {
|
||||
|
||||
constructor(
|
||||
connectionBackend: ConnectionBackend,
|
||||
defaultOptions: RequestOptions,
|
||||
@ -57,30 +64,37 @@ export class KoffingHttp extends Http {
|
||||
const tokenUpdateObservable: Observable<any> = Observable.create((observer: any) => {
|
||||
if (!options) {
|
||||
const headers = new Headers();
|
||||
options = new RequestOptions({headers});
|
||||
options = new RequestOptions({ headers });
|
||||
}
|
||||
this.setHeaders(options);
|
||||
observer.next();
|
||||
observer.complete();
|
||||
});
|
||||
const requestObservable: Observable<Response> = Observable.create((observer: Observer<any>) => {
|
||||
const requestObservable: Observable<Response> = Observable.create(
|
||||
(observer: Observer<any>) => {
|
||||
let result: any;
|
||||
if (body) {
|
||||
result = f.apply(this, [url, body, options]);
|
||||
} else {
|
||||
result = f.apply(this, [url, options]);
|
||||
}
|
||||
result.subscribe((response: any) => {
|
||||
result.subscribe(
|
||||
(response: any) => {
|
||||
observer.next(response);
|
||||
observer.complete();
|
||||
}, (error: any) => {
|
||||
},
|
||||
(error: any) => {
|
||||
this.httpErrorBroadcaster.fire(error.status);
|
||||
observer.error(error);
|
||||
});
|
||||
});
|
||||
return <Observable<Response>> Observable
|
||||
.merge(tokenObservable, tokenUpdateObservable, requestObservable, 1)
|
||||
.filter((response) => response instanceof Response);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
return <Observable<Response>>(
|
||||
Observable.merge(tokenObservable, tokenUpdateObservable, requestObservable, 1).filter(
|
||||
response => response instanceof Response
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private getToken(): Promise<string> {
|
||||
@ -107,7 +121,9 @@ export class KoffingHttp extends Http {
|
||||
|
||||
private guid(): string {
|
||||
function s4() {
|
||||
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
|
||||
return Math.floor((1 + Math.random()) * 0x10000)
|
||||
.toString(16)
|
||||
.substring(1);
|
||||
}
|
||||
return `${s4()}${s4()}-${s4()}-${s4()}`;
|
||||
}
|
||||
|
@ -10,11 +10,7 @@ import { LocationName } from './model';
|
||||
|
||||
@Injectable()
|
||||
export class LocationService {
|
||||
|
||||
constructor(
|
||||
private http: KoffingHttp,
|
||||
private config: ConfigService
|
||||
) { }
|
||||
constructor(private http: KoffingHttp, private config: ConfigService) {}
|
||||
|
||||
public getLocationsNames(geoIDs: string[], language?: string): Observable<LocationName[]> {
|
||||
if (isNil(geoIDs) || geoIDs.length === 0) {
|
||||
@ -26,6 +22,8 @@ export class LocationService {
|
||||
const search = new URLSearchParams();
|
||||
search.set('geoIDs', geoIDs.join(','));
|
||||
search.set('language', language || 'ru');
|
||||
return this.http.get(`${this.config.capiUrl}/reference/geo/location/names`, {search}).map((res) => res.json());
|
||||
return this.http
|
||||
.get(`${this.config.capiUrl}/reference/geo/location/names`, { search })
|
||||
.map(res => res.json());
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { Claim } from './claim';
|
||||
|
||||
export class ClaimAccepted extends Claim {
|
||||
|
||||
public acceptedAt: string;
|
||||
|
||||
constructor() {
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { Claim } from './claim';
|
||||
|
||||
export class ClaimDenied extends Claim {
|
||||
|
||||
public reason: string;
|
||||
|
||||
constructor() {
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { Claim } from './claim';
|
||||
|
||||
export class ClaimPending extends Claim {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.status = 'ClaimPending';
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { Claim } from './claim';
|
||||
|
||||
export class ClaimRevoked extends Claim {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.status = 'ClaimRevoked';
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { ContractModification } from './contract-modification';
|
||||
|
||||
export class ContractAdjustmentCreation extends ContractModification {
|
||||
|
||||
public adjustmentID: string;
|
||||
|
||||
constructor() {
|
||||
|
@ -2,7 +2,6 @@ import { ContractModification } from './contract-modification';
|
||||
import { Contractor } from '../../../contract/contractor/contractor';
|
||||
|
||||
export class ContractCreation extends ContractModification {
|
||||
|
||||
public contractor: Contractor;
|
||||
public paymentInstitutionID: number;
|
||||
|
||||
|
@ -2,7 +2,6 @@ import { ContractModification } from './contract-modification';
|
||||
import { LegalAgreement } from '../../../contract/legal-agreement';
|
||||
|
||||
export class ContractLegalAgreementBinding extends ContractModification {
|
||||
|
||||
public legalAgreement: LegalAgreement;
|
||||
|
||||
constructor() {
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { PartyModification } from '../party-modification';
|
||||
|
||||
export abstract class ContractModification extends PartyModification {
|
||||
|
||||
public contractID: string;
|
||||
public contractModificationType: string;
|
||||
|
||||
|
@ -2,12 +2,16 @@ import { ContractModification } from './contract-modification';
|
||||
import { PayoutToolDetails } from '../../../payout-tool/payout-tool-details/payout-tool-details';
|
||||
|
||||
export class ContractPayoutToolCreation extends ContractModification {
|
||||
|
||||
public payoutToolID: string;
|
||||
public currency: string;
|
||||
public details: PayoutToolDetails;
|
||||
|
||||
constructor(currency: string, contractID: string, payoutToolID: string, details: PayoutToolDetails) {
|
||||
constructor(
|
||||
currency: string,
|
||||
contractID: string,
|
||||
payoutToolID: string,
|
||||
details: PayoutToolDetails
|
||||
) {
|
||||
super();
|
||||
this.currency = currency;
|
||||
this.contractModificationType = 'ContractPayoutToolCreation';
|
||||
|
@ -1,12 +1,10 @@
|
||||
import { ContractModification } from './contract-modification';
|
||||
|
||||
export class ContractTermination extends ContractModification {
|
||||
|
||||
public reason: string;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.contractModificationType = 'ContractTermination';
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { ShopModification } from './shop-modification';
|
||||
|
||||
export class ShopAccountCreation extends ShopModification {
|
||||
|
||||
public currency: string;
|
||||
|
||||
constructor() {
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { ShopModification } from './shop-modification';
|
||||
|
||||
export class ShopCategoryChange extends ShopModification {
|
||||
|
||||
public categoryID: number;
|
||||
|
||||
constructor() {
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { ShopModification } from './shop-modification';
|
||||
|
||||
export class ShopContractBinding extends ShopModification {
|
||||
|
||||
public contractID: string;
|
||||
public payoutToolID: string;
|
||||
|
||||
|
@ -3,18 +3,17 @@ import { ShopLocation } from '../../../shop/shop-location/shop-location';
|
||||
import { ShopDetails } from '../../../shop/shop-details';
|
||||
|
||||
export class ShopCreation extends ShopModification {
|
||||
|
||||
public location: ShopLocation;
|
||||
public details: ShopDetails;
|
||||
public contractID: string;
|
||||
public payoutToolID: string;
|
||||
|
||||
constructor(options: {
|
||||
shopID: string,
|
||||
location: ShopLocation,
|
||||
details: ShopDetails,
|
||||
contractID: string,
|
||||
payoutToolID: string
|
||||
shopID: string;
|
||||
location: ShopLocation;
|
||||
details: ShopDetails;
|
||||
contractID: string;
|
||||
payoutToolID: string;
|
||||
}) {
|
||||
super();
|
||||
this.shopModificationType = 'ShopCreation';
|
||||
|
@ -2,7 +2,6 @@ import { ShopModification } from './shop-modification';
|
||||
import { ShopDetails } from './../../../shop/shop-details';
|
||||
|
||||
export class ShopDetailsChange extends ShopModification {
|
||||
|
||||
public details: ShopDetails;
|
||||
|
||||
constructor() {
|
||||
|
@ -2,7 +2,6 @@ import { ShopModification } from './shop-modification';
|
||||
import { ShopLocation } from 'koffing/backend/model/shop/shop-location/shop-location';
|
||||
|
||||
export class ShopLocationChange extends ShopModification {
|
||||
|
||||
public location: ShopLocation;
|
||||
|
||||
constructor() {
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { PartyModification } from '../party-modification';
|
||||
|
||||
export abstract class ShopModification extends PartyModification {
|
||||
|
||||
public shopID: string;
|
||||
public shopModificationType: string;
|
||||
|
||||
|
@ -10,11 +10,11 @@ export class InternationalLegalEntity extends LegalEntity {
|
||||
public bankAccount: BankAccount;
|
||||
|
||||
constructor(options: {
|
||||
legalName: string,
|
||||
registeredOffice: string,
|
||||
tradingName?: string,
|
||||
principalPlaceOfBusiness?: string
|
||||
bankAccount: BankAccount
|
||||
legalName: string;
|
||||
registeredOffice: string;
|
||||
tradingName?: string;
|
||||
principalPlaceOfBusiness?: string;
|
||||
bankAccount: BankAccount;
|
||||
}) {
|
||||
super();
|
||||
this.entityType = LegalEntityTypeEnum.InternationalLegalEntity;
|
||||
|
@ -1,8 +1,7 @@
|
||||
import { Contractor } from './contractor';
|
||||
import {LegalEntityTypeEnum} from './legal-entity-type-enum';
|
||||
import { LegalEntityTypeEnum } from './legal-entity-type-enum';
|
||||
|
||||
export abstract class LegalEntity extends Contractor {
|
||||
|
||||
public entityType: LegalEntityTypeEnum;
|
||||
|
||||
constructor() {
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { Contractor } from './contractor';
|
||||
|
||||
export class RegisteredUser extends Contractor {
|
||||
|
||||
public email: string;
|
||||
|
||||
constructor() {
|
||||
|
@ -3,7 +3,6 @@ import { BankAccount } from 'koffing/backend';
|
||||
import { LegalEntityTypeEnum } from './legal-entity-type-enum';
|
||||
|
||||
export class RussianLegalEntity extends LegalEntity {
|
||||
|
||||
public registeredName: string;
|
||||
public registeredNumber: string;
|
||||
public inn: string;
|
||||
@ -15,15 +14,15 @@ export class RussianLegalEntity extends LegalEntity {
|
||||
public bankAccount: BankAccount;
|
||||
|
||||
constructor(options: {
|
||||
registeredName: string,
|
||||
registeredNumber: string,
|
||||
inn: string,
|
||||
actualAddress: string,
|
||||
postAddress: string,
|
||||
representativePosition: string,
|
||||
representativeFullName: string,
|
||||
representativeDocument: string,
|
||||
bankAccount: BankAccount
|
||||
registeredName: string;
|
||||
registeredNumber: string;
|
||||
inn: string;
|
||||
actualAddress: string;
|
||||
postAddress: string;
|
||||
representativePosition: string;
|
||||
representativeFullName: string;
|
||||
representativeDocument: string;
|
||||
bankAccount: BankAccount;
|
||||
}) {
|
||||
super();
|
||||
this.entityType = LegalEntityTypeEnum.RussianLegalEntity;
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { InvoiceLineTaxMode } from './invoice-line-tax-mode';
|
||||
|
||||
export class InvoiceLineTaxVAT extends InvoiceLineTaxMode {
|
||||
|
||||
public rate: string;
|
||||
|
||||
constructor(rate: string) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { InvoiceLineTaxMode } from './invoice-line-tax-mode';
|
||||
|
||||
export class InvoiceLine {
|
||||
|
||||
public product: string;
|
||||
public quantity: number;
|
||||
public price: number;
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { InvoiceTemplateLineCost } from './invoice-template-line-cost';
|
||||
|
||||
export class InvoiceTemplateLineCostFixed extends InvoiceTemplateLineCost {
|
||||
|
||||
public amount: number;
|
||||
public currency: string;
|
||||
|
||||
|
@ -2,7 +2,6 @@ import { InvoiceTemplateLineCost } from './invoice-template-line-cost';
|
||||
import { CostAmountRange } from './cost-amount-range';
|
||||
|
||||
export class InvoiceTemplateLineCostRange extends InvoiceTemplateLineCost {
|
||||
|
||||
public range: CostAmountRange;
|
||||
public currency: string;
|
||||
|
||||
|
@ -2,7 +2,6 @@ import { InvoiceTemplateDetails } from './invoice-template-details';
|
||||
import { InvoiceLine } from '../invoice-cart/invoice-line';
|
||||
|
||||
export class InvoiceTemplateMultiLine extends InvoiceTemplateDetails {
|
||||
|
||||
public cart: InvoiceLine[];
|
||||
public currency: string;
|
||||
|
||||
|
@ -3,7 +3,6 @@ import { InvoiceTemplateLineCost } from './invoice-template-line-cost';
|
||||
import { InvoiceLineTaxMode } from '../invoice-cart/invoice-line-tax-mode';
|
||||
|
||||
export class InvoiceTemplateSingleLine extends InvoiceTemplateDetails {
|
||||
|
||||
public product: string;
|
||||
public price: InvoiceTemplateLineCost;
|
||||
public taxMode?: InvoiceLineTaxMode;
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { Payer } from './payer';
|
||||
|
||||
export class CustomerPayer extends Payer {
|
||||
|
||||
public customerID: string;
|
||||
|
||||
constructor() {
|
||||
|
@ -4,7 +4,6 @@ import { ClientInfo } from '../client-info';
|
||||
import { ContactInfo } from '../contact-info';
|
||||
|
||||
export class PaymentResourcePayer extends Payer {
|
||||
|
||||
public paymentToolToken: string;
|
||||
public paymentSession: string;
|
||||
public paymentToolDetails: PaymentToolDetails;
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { PaymentMethod } from './payment-method';
|
||||
|
||||
export class PaymentMethodBankCard extends PaymentMethod {
|
||||
|
||||
public paymentSystems: string[];
|
||||
public tokenProviders: string[];
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { PaymentMethod } from './payment-method';
|
||||
|
||||
export class PaymentMethodTerminal extends PaymentMethod {
|
||||
|
||||
public providers: string[];
|
||||
|
||||
constructor() {
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { PaymentMethod } from './payment-method';
|
||||
|
||||
export class PaymentMethodWallets extends PaymentMethod {
|
||||
|
||||
public providers: string[];
|
||||
|
||||
constructor() {
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { PaymentToolDetails } from './payment-tool-details';
|
||||
|
||||
export class PaymentToolDetailsBankCard extends PaymentToolDetails {
|
||||
|
||||
public cardNumberMask: string;
|
||||
public bin: string;
|
||||
public lastDigits: string;
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { PaymentToolDetails } from './payment-tool-details';
|
||||
|
||||
export class PaymentToolDetailsPaymentTerminal extends PaymentToolDetails {
|
||||
|
||||
public provider: string;
|
||||
|
||||
constructor() {
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { PaymentFlow } from 'koffing/backend/model/payment/payment-flow';
|
||||
|
||||
export class PaymentFlowHold extends PaymentFlow {
|
||||
|
||||
public onHoldExpiration: string;
|
||||
|
||||
public heldUntil: string;
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { PaymentFlow } from 'koffing/backend/model/payment/payment-flow';
|
||||
|
||||
export class PaymentFlowInstant extends PaymentFlow {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.type = 'PaymentFlowInstant';
|
||||
|
@ -3,7 +3,6 @@ import { BankAccount } from 'koffing/backend/model/bank-account';
|
||||
import { PayoutToolDetails } from './payout-tool-details';
|
||||
|
||||
export class PayoutToolDetailsBankAccount implements BankAccount, PayoutToolDetails {
|
||||
|
||||
public detailsType: string;
|
||||
public account: string;
|
||||
public bankName: string;
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { ShopLocation } from './shop-location';
|
||||
|
||||
export class ShopLocationUrl extends ShopLocation {
|
||||
|
||||
public url: string;
|
||||
|
||||
constructor(url: string) {
|
||||
|
@ -7,14 +7,10 @@ import { PaymentInstitution } from 'koffing/backend';
|
||||
|
||||
@Injectable()
|
||||
export class PaymentInstitutionService {
|
||||
|
||||
constructor(
|
||||
private http: KoffingHttp,
|
||||
private config: ConfigService
|
||||
) { }
|
||||
constructor(private http: KoffingHttp, private config: ConfigService) {}
|
||||
|
||||
public getPaymentInstitutions(): Observable<PaymentInstitution[]> {
|
||||
return this.http.get(this.getEndpoint()).map((res) => res.json());
|
||||
return this.http.get(this.getEndpoint()).map(res => res.json());
|
||||
}
|
||||
|
||||
private getEndpoint(): string {
|
||||
|
@ -8,22 +8,22 @@ import { CreatePayoutParams } from './requests/create-payout-request';
|
||||
|
||||
@Injectable()
|
||||
export class PayoutToolService {
|
||||
|
||||
constructor(
|
||||
private http: KoffingHttp,
|
||||
private config: ConfigService
|
||||
) { }
|
||||
constructor(private http: KoffingHttp, private config: ConfigService) {}
|
||||
|
||||
public getPayoutTools(contractID: string): Observable<PayoutTool[]> {
|
||||
return this.http.get(this.getEndpoint(contractID)).map((res) => res.json());
|
||||
return this.http.get(this.getEndpoint(contractID)).map(res => res.json());
|
||||
}
|
||||
|
||||
public getPayoutToolByID(contractID: string, payoutToolID: string): Observable<PayoutTool> {
|
||||
return this.http.get(`${this.getEndpoint(contractID)}/${payoutToolID}`).map((res) => res.json());
|
||||
return this.http
|
||||
.get(`${this.getEndpoint(contractID)}/${payoutToolID}`)
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
public createPayout(body: CreatePayoutParams): Observable<Payout> {
|
||||
return this.http.post(`${this.config.capiUrl}/processing/payouts`, body).map((res) => res.json());
|
||||
return this.http
|
||||
.post(`${this.config.capiUrl}/processing/payouts`, body)
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
private getEndpoint(contractID: string): string {
|
||||
|
@ -10,33 +10,38 @@ import { Report } from './model';
|
||||
|
||||
@Injectable()
|
||||
export class ReportsService {
|
||||
|
||||
constructor(
|
||||
private http: KoffingHttp,
|
||||
private config: ConfigService
|
||||
) {
|
||||
}
|
||||
constructor(private http: KoffingHttp, private config: ConfigService) {}
|
||||
|
||||
public createReport(shopID: string, reportParams: CreateReportParams): Observable<Report> {
|
||||
return this.http.post(`${this.config.capiUrl}/shops/${shopID}/reports`, this.toCreateParams(reportParams))
|
||||
.map((res) => res.json());
|
||||
return this.http
|
||||
.post(
|
||||
`${this.config.capiUrl}/shops/${shopID}/reports`,
|
||||
this.toCreateParams(reportParams)
|
||||
)
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
private toCreateParams(params: object): object {
|
||||
return reduce(params, (acc, value, key) => {
|
||||
return reduce(
|
||||
params,
|
||||
(acc, value, key) => {
|
||||
if (value) {
|
||||
if (isDate(value)) {
|
||||
return {...acc, [key]: this.toUTC(value)};
|
||||
return { ...acc, [key]: this.toUTC(value) };
|
||||
} else {
|
||||
return {...acc, [key]: value};
|
||||
return { ...acc, [key]: value };
|
||||
}
|
||||
} else {
|
||||
return acc;
|
||||
}
|
||||
}, {});
|
||||
},
|
||||
{}
|
||||
);
|
||||
}
|
||||
|
||||
private toUTC(date: Date): string {
|
||||
return moment(date).utc().format();
|
||||
return moment(date)
|
||||
.utc()
|
||||
.format();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
export class SearchReportParams {
|
||||
|
||||
public fromTime: Date;
|
||||
public toTime: Date;
|
||||
|
||||
|
@ -28,57 +28,73 @@ import {
|
||||
|
||||
@Injectable()
|
||||
export class SearchService {
|
||||
constructor(private http: KoffingHttp, private config: ConfigService) {}
|
||||
|
||||
constructor(
|
||||
private http: KoffingHttp,
|
||||
private config: ConfigService
|
||||
) { }
|
||||
|
||||
public searchInvoices(shopID: string, invoiceParams: SearchInvoicesParams): Observable<InvoiceSearchResult> {
|
||||
public searchInvoices(
|
||||
shopID: string,
|
||||
invoiceParams: SearchInvoicesParams
|
||||
): Observable<InvoiceSearchResult> {
|
||||
const search = this.toSearchParams(invoiceParams);
|
||||
return this.http.get(`${this.getCapiEndpoint(shopID)}/invoices`, {search})
|
||||
.map((res) => res.json());
|
||||
return this.http
|
||||
.get(`${this.getCapiEndpoint(shopID)}/invoices`, { search })
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
public searchPayments(shopID: string, paymentsParams: SearchPaymentsParams): Observable<PaymentSearchResult> {
|
||||
public searchPayments(
|
||||
shopID: string,
|
||||
paymentsParams: SearchPaymentsParams
|
||||
): Observable<PaymentSearchResult> {
|
||||
const search = this.toSearchParams(paymentsParams);
|
||||
return this.http.get(`${this.getCapiEndpoint(shopID)}/payments`, {search})
|
||||
.map((res) => res.json());
|
||||
return this.http
|
||||
.get(`${this.getCapiEndpoint(shopID)}/payments`, { search })
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
public searchRefunds(shopID: string, refundsParams: SearchRefundsParams): Observable<RefundsSearchResult> {
|
||||
public searchRefunds(
|
||||
shopID: string,
|
||||
refundsParams: SearchRefundsParams
|
||||
): Observable<RefundsSearchResult> {
|
||||
const search = this.toSearchParams(refundsParams);
|
||||
return this.http.get(`${this.getCapiEndpoint(shopID)}/refunds`, {search})
|
||||
.map((res) => res.json());
|
||||
return this.http
|
||||
.get(`${this.getCapiEndpoint(shopID)}/refunds`, { search })
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
public searchPayouts(shopID: string, payoutsParams: SearchPayoutsParams): Observable<PayoutSearchResult> {
|
||||
public searchPayouts(
|
||||
shopID: string,
|
||||
payoutsParams: SearchPayoutsParams
|
||||
): Observable<PayoutSearchResult> {
|
||||
const search = this.toSearchParams(payoutsParams);
|
||||
return this.http.get(`${this.getCapiEndpoint(shopID)}/payouts`, {search})
|
||||
.map((res) => res.json());
|
||||
return this.http
|
||||
.get(`${this.getCapiEndpoint(shopID)}/payouts`, { search })
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
public getReports(shopID: string, reportParams: SearchReportParams): Observable<Report[]> {
|
||||
const search = this.toSearchParams(reportParams);
|
||||
return this.http.get(`${this.config.capiUrl}/shops/${shopID}/reports`, {search})
|
||||
.map((res) => res.json());
|
||||
return this.http
|
||||
.get(`${this.config.capiUrl}/shops/${shopID}/reports`, { search })
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
public searchWalletWithdrawals(withdrawalsParams: SearchWalletWithdrawals): Observable<WithdrawalSearchResult> {
|
||||
public searchWalletWithdrawals(
|
||||
withdrawalsParams: SearchWalletWithdrawals
|
||||
): Observable<WithdrawalSearchResult> {
|
||||
const search = this.toSearchParams(withdrawalsParams);
|
||||
return this.http.get(`${this.config.wapiUrl}/withdrawals`, {search})
|
||||
.map((res) => res.json());
|
||||
return this.http
|
||||
.get(`${this.config.wapiUrl}/withdrawals`, { search })
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
public searchWalletWithdrawal(withdrawalID: string): Observable<Withdrawal> {
|
||||
return this.http.get(`${this.config.wapiUrl}/withdrawals/${withdrawalID}`)
|
||||
.map((res) => res.json());
|
||||
return this.http
|
||||
.get(`${this.config.wapiUrl}/withdrawals/${withdrawalID}`)
|
||||
.map(res => res.json());
|
||||
}
|
||||
|
||||
public searchWallets(walletsParams: SearchWalletsParams): Observable<WalletsSearchResult> {
|
||||
const search = this.toSearchParams(walletsParams);
|
||||
return this.http.get(`${this.config.wapiUrl}/wallets`, {search})
|
||||
.map((res) => res.json());
|
||||
return this.http.get(`${this.config.wapiUrl}/wallets`, { search }).map(res => res.json());
|
||||
}
|
||||
|
||||
private getCapiEndpoint(shopID: string): string {
|
||||
@ -102,6 +118,8 @@ export class SearchService {
|
||||
}
|
||||
|
||||
private toUTC(date: Date): string {
|
||||
return moment(date).utc().format();
|
||||
return moment(date)
|
||||
.utc()
|
||||
.format();
|
||||
}
|
||||
}
|
||||
|
@ -7,27 +7,23 @@ import { Shop } from './model';
|
||||
|
||||
@Injectable()
|
||||
export class ShopService {
|
||||
|
||||
private endpoint: string = `${this.config.capiUrl}/processing/shops`;
|
||||
|
||||
constructor(
|
||||
private http: KoffingHttp,
|
||||
private config: ConfigService
|
||||
) { }
|
||||
constructor(private http: KoffingHttp, private config: ConfigService) {}
|
||||
|
||||
public getShops(): Observable<Shop[]> {
|
||||
return this.http.get(this.endpoint).map((res) => res.json());
|
||||
return this.http.get(this.endpoint).map(res => res.json());
|
||||
}
|
||||
|
||||
public getShopByID(shopID: string): Observable<Shop> {
|
||||
return this.http.get(`${this.endpoint}/${shopID}`).map((res) => res.json());
|
||||
return this.http.get(`${this.endpoint}/${shopID}`).map(res => res.json());
|
||||
}
|
||||
|
||||
public activateShop(shopID: string): Observable<void> {
|
||||
return this.http.put(`${this.endpoint}/${shopID}/activate`, {}).map((res) => res.json());
|
||||
return this.http.put(`${this.endpoint}/${shopID}/activate`, {}).map(res => res.json());
|
||||
}
|
||||
|
||||
public suspendShop(shopID: string): Observable<void> {
|
||||
return this.http.put(`${this.endpoint}/${shopID}/suspend`, {}).map((res) => res.json());
|
||||
return this.http.put(`${this.endpoint}/${shopID}/suspend`, {}).map(res => res.json());
|
||||
}
|
||||
}
|
||||
|
@ -7,13 +7,11 @@ import { KoffingHttp } from './koffing-http.service';
|
||||
|
||||
@Injectable()
|
||||
export class UrlShortenerService {
|
||||
|
||||
constructor(private http: KoffingHttp,
|
||||
private config: ConfigService) {
|
||||
}
|
||||
constructor(private http: KoffingHttp, private config: ConfigService) {}
|
||||
|
||||
public shorten(sourceUrl: string, expiresAt: string): Observable<UrlShortenerResult> {
|
||||
return this.http.post(`${this.config.shortenUrlEndpoint}/v1/shortened-urls`, {sourceUrl, expiresAt})
|
||||
return this.http
|
||||
.post(`${this.config.shortenUrlEndpoint}/v1/shortened-urls`, { sourceUrl, expiresAt })
|
||||
.map(res => res.json());
|
||||
}
|
||||
}
|
||||
|
@ -7,16 +7,11 @@ import { WalletAccount } from 'koffing/backend/model';
|
||||
|
||||
@Injectable()
|
||||
export class WalletService {
|
||||
|
||||
private endpoint = `${this.config.wapiUrl}/wallets`;
|
||||
|
||||
constructor(
|
||||
private http: KoffingHttp,
|
||||
private config: ConfigService
|
||||
) {}
|
||||
constructor(private http: KoffingHttp, private config: ConfigService) {}
|
||||
|
||||
public getWalletAccount(walletID: string): Observable<WalletAccount> {
|
||||
return this.http.get(`${this.endpoint}/${walletID}/account`)
|
||||
.map(res => res.json());
|
||||
return this.http.get(`${this.endpoint}/${walletID}/account`).map(res => res.json());
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import { Subject } from 'rxjs';
|
||||
|
||||
@Injectable()
|
||||
export class WarningsService {
|
||||
|
||||
public loginWarnings: Subject<string[]> = new Subject();
|
||||
|
||||
private isLoaded = false;
|
||||
@ -16,7 +15,9 @@ export class WarningsService {
|
||||
}
|
||||
|
||||
private init() {
|
||||
this.http.get(`warningConfig.json?timestamp=${ new Date().getTime() }`).map(res => res.json())
|
||||
this.http
|
||||
.get(`warningConfig.json?timestamp=${new Date().getTime()}`)
|
||||
.map(res => res.json())
|
||||
.subscribe(data => {
|
||||
this.loginWarnings.next(data.loginWarnings);
|
||||
this.isLoaded = true;
|
||||
|
@ -8,13 +8,9 @@ import { WebhookParams } from './requests';
|
||||
|
||||
@Injectable()
|
||||
export class WebhooksService {
|
||||
|
||||
private endpoint = `${this.config.capiUrl}/processing/webhooks`;
|
||||
|
||||
constructor(
|
||||
private http: KoffingHttp,
|
||||
private config: ConfigService
|
||||
) { }
|
||||
constructor(private http: KoffingHttp, private config: ConfigService) {}
|
||||
|
||||
public createWebhook(params: WebhookParams): Observable<Webhook> {
|
||||
return this.http.post(this.endpoint, params).map(res => res.json());
|
||||
|
@ -16,4 +16,4 @@ import { BreadcrumbBroadcaster } from './services/breadcrumb.broadcaster';
|
||||
BreadcrumbBroadcaster
|
||||
]
|
||||
})
|
||||
export class BroadcasterModule { }
|
||||
export class BroadcasterModule {}
|
||||
|
@ -5,7 +5,6 @@ import { BreadcrumbConfig } from './breadcrumb-config';
|
||||
|
||||
@Injectable()
|
||||
export class BreadcrumbBroadcaster {
|
||||
|
||||
constructor(private broadcaster: Broadcaster) {}
|
||||
|
||||
public fire(config: BreadcrumbConfig[]) {
|
||||
|
@ -4,7 +4,6 @@ import 'rxjs/add/operator/filter';
|
||||
import 'rxjs/add/operator/map';
|
||||
|
||||
export class Broadcaster {
|
||||
|
||||
private eventBus: Subject<any>;
|
||||
|
||||
constructor() {
|
||||
@ -12,12 +11,13 @@ export class Broadcaster {
|
||||
}
|
||||
|
||||
public broadcast(key: any, data?: any) {
|
||||
this.eventBus.next({key, data});
|
||||
this.eventBus.next({ key, data });
|
||||
}
|
||||
|
||||
public on<T>(key: any): Observable<T> {
|
||||
return this.eventBus.asObservable()
|
||||
return this.eventBus
|
||||
.asObservable()
|
||||
.filter(event => event.key === key)
|
||||
.map((event: any) => <T> event.data);
|
||||
.map((event: any) => <T>event.data);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import { Broadcaster } from './broadcaster.service';
|
||||
|
||||
@Injectable()
|
||||
export class ClaimReceiveBroadcaster {
|
||||
|
||||
constructor(private broadcaster: Broadcaster) {}
|
||||
|
||||
public fire() {
|
||||
|
@ -4,7 +4,6 @@ import { Broadcaster } from './broadcaster.service';
|
||||
|
||||
@Injectable()
|
||||
export class ClaimRevokeBroadcaster {
|
||||
|
||||
constructor(private broadcaster: Broadcaster) {}
|
||||
|
||||
public fire() {
|
||||
|
@ -4,7 +4,6 @@ import { Broadcaster } from './broadcaster.service';
|
||||
|
||||
@Injectable()
|
||||
export class HttpErrorBroadcaster {
|
||||
|
||||
constructor(private broadcaster: Broadcaster) {}
|
||||
|
||||
public fire(status: number) {
|
||||
|
@ -4,7 +4,6 @@ import { Broadcaster } from './broadcaster.service';
|
||||
|
||||
@Injectable()
|
||||
export class ToggleMenuBroadcaster {
|
||||
|
||||
constructor(private broadcaster: Broadcaster) {}
|
||||
|
||||
public fire() {
|
||||
|
@ -13,7 +13,6 @@ import { PaymentMethodInfo, ManagePaymentMethodsService } from './manage-payment
|
||||
providers: [ManagePaymentMethodsService]
|
||||
})
|
||||
export class CheckoutConfigFormComponent implements OnInit, OnChanges {
|
||||
|
||||
@Input()
|
||||
public methods: PaymentMethod[];
|
||||
|
||||
@ -25,9 +24,10 @@ export class CheckoutConfigFormComponent implements OnInit, OnChanges {
|
||||
|
||||
public isHoldAvailable: boolean = true;
|
||||
|
||||
constructor(private checkoutConfigFormService: CheckoutConfigFormService,
|
||||
private managePaymentMethodsService: ManagePaymentMethodsService) {
|
||||
}
|
||||
constructor(
|
||||
private checkoutConfigFormService: CheckoutConfigFormService,
|
||||
private managePaymentMethodsService: ManagePaymentMethodsService
|
||||
) {}
|
||||
|
||||
public ngOnInit() {
|
||||
this.form = this.checkoutConfigFormService.form;
|
||||
@ -55,13 +55,26 @@ export class CheckoutConfigFormComponent implements OnInit, OnChanges {
|
||||
|
||||
private updateMethods() {
|
||||
if (this.form && this.methods) {
|
||||
this.additionalMethodConfigs = this.managePaymentMethodsService.getAdditionalMethodsConfig(this.methods);
|
||||
this.managePaymentMethodsService.handleAdditionalMethods(this.additionalMethodConfigs, this.form);
|
||||
this.additionalMethodConfigs = this.managePaymentMethodsService.getAdditionalMethodsConfig(
|
||||
this.methods
|
||||
);
|
||||
this.managePaymentMethodsService.handleAdditionalMethods(
|
||||
this.additionalMethodConfigs,
|
||||
this.form
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private handleHoldAvailable() {
|
||||
const { bankCard, terminals, wallets, applePay, googlePay, samsungPay } = this.form.getRawValue();
|
||||
this.isHoldAvailable = (bankCard || applePay || googlePay || samsungPay) && !(terminals || wallets);
|
||||
const {
|
||||
bankCard,
|
||||
terminals,
|
||||
wallets,
|
||||
applePay,
|
||||
googlePay,
|
||||
samsungPay
|
||||
} = this.form.getRawValue();
|
||||
this.isHoldAvailable =
|
||||
(bankCard || applePay || googlePay || samsungPay) && !(terminals || wallets);
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import { HOLD_EXPIRATION } from 'koffing/backend/constants/hold-expiration';
|
||||
|
||||
@Injectable()
|
||||
export class CheckoutConfigFormService {
|
||||
|
||||
public form: FormGroup;
|
||||
|
||||
constructor(private fb: FormBuilder) {
|
||||
|
@ -15,13 +15,16 @@ interface FormControls {
|
||||
|
||||
@Injectable()
|
||||
export class ManagePaymentMethodsService {
|
||||
|
||||
public getAdditionalMethodsConfig(methods: PaymentMethod[]): PaymentMethodInfo[] {
|
||||
return methods.map((item) => {
|
||||
return methods
|
||||
.map(item => {
|
||||
switch (item.method) {
|
||||
case 'BankCard':
|
||||
const bankCard = item as PaymentMethodBankCard;
|
||||
if (Array.isArray(bankCard.tokenProviders) && bankCard.tokenProviders.length) {
|
||||
if (
|
||||
Array.isArray(bankCard.tokenProviders) &&
|
||||
bankCard.tokenProviders.length
|
||||
) {
|
||||
switch (bankCard.tokenProviders[0]) {
|
||||
case TOKEN_PROVIDER.applepay:
|
||||
return {
|
||||
@ -63,12 +66,13 @@ export class ManagePaymentMethodsService {
|
||||
default:
|
||||
throw new Error('Unhandled PaymentMethod');
|
||||
}
|
||||
}).sort((item) => item.order);
|
||||
})
|
||||
.sort(item => item.order);
|
||||
}
|
||||
|
||||
public handleAdditionalMethods(info: PaymentMethodInfo[], form: FormGroup) {
|
||||
const controlsMap = this.infoToControlMap(info, form.controls);
|
||||
form.valueChanges.subscribe((values) => {
|
||||
form.valueChanges.subscribe(values => {
|
||||
const activityMap = this.infoToActivityMap(info, values);
|
||||
this.disable(activityMap, controlsMap);
|
||||
});
|
||||
@ -78,9 +82,12 @@ export class ManagePaymentMethodsService {
|
||||
});
|
||||
}
|
||||
|
||||
private infoToControlMap(info: PaymentMethodInfo[], controls: FormControls): Map<string, AbstractControl> {
|
||||
private infoToControlMap(
|
||||
info: PaymentMethodInfo[],
|
||||
controls: FormControls
|
||||
): Map<string, AbstractControl> {
|
||||
const result = new Map<string, AbstractControl>();
|
||||
info.forEach((item) => {
|
||||
info.forEach(item => {
|
||||
result.set(item.formControlName, controls[item.formControlName]);
|
||||
});
|
||||
return result;
|
||||
@ -88,7 +95,7 @@ export class ManagePaymentMethodsService {
|
||||
|
||||
private infoToActivityMap(info: PaymentMethodInfo[], formValues: any): Map<string, boolean> {
|
||||
const result = new Map<string, boolean>();
|
||||
info.forEach((item) => {
|
||||
info.forEach(item => {
|
||||
result.set(item.formControlName, formValues[item.formControlName]);
|
||||
});
|
||||
return result;
|
||||
@ -115,7 +122,10 @@ export class ManagePaymentMethodsService {
|
||||
}
|
||||
}
|
||||
|
||||
private excludeInitiator(initiatorControlName: string, controls: Map<string, AbstractControl>): AbstractControl[] {
|
||||
private excludeInitiator(
|
||||
initiatorControlName: string,
|
||||
controls: Map<string, AbstractControl>
|
||||
): AbstractControl[] {
|
||||
const result: AbstractControl[] = [];
|
||||
controls.forEach((value, key) => {
|
||||
if (key !== initiatorControlName) {
|
||||
@ -127,7 +137,7 @@ export class ManagePaymentMethodsService {
|
||||
|
||||
private enable(controls: AbstractControl[], value: boolean) {
|
||||
if (value) {
|
||||
controls.forEach((control) => control.disabled && control.enable());
|
||||
controls.forEach(control => control.disabled && control.enable());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,21 +8,9 @@ import { CheckoutConfigFormComponent } from './checkout-config-form/checkout-con
|
||||
import { PaymentLinkService } from './payment-link/payment-link.service';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
BrowserModule,
|
||||
FormsModule,
|
||||
ReactiveFormsModule,
|
||||
BackendModule
|
||||
],
|
||||
declarations: [
|
||||
CheckoutConfigFormComponent
|
||||
],
|
||||
providers: [
|
||||
CheckoutConfigFormService,
|
||||
PaymentLinkService
|
||||
],
|
||||
exports: [
|
||||
CheckoutConfigFormComponent
|
||||
]
|
||||
imports: [BrowserModule, FormsModule, ReactiveFormsModule, BackendModule],
|
||||
declarations: [CheckoutConfigFormComponent],
|
||||
providers: [CheckoutConfigFormService, PaymentLinkService],
|
||||
exports: [CheckoutConfigFormComponent]
|
||||
})
|
||||
export class CheckoutModule { }
|
||||
export class CheckoutModule {}
|
||||
|
@ -12,29 +12,38 @@ import * as moment from 'moment';
|
||||
|
||||
@Injectable()
|
||||
export class PaymentLinkService {
|
||||
|
||||
constructor(private configService: ConfigService,
|
||||
constructor(
|
||||
private configService: ConfigService,
|
||||
private urlShortenerService: UrlShortenerService,
|
||||
private invoiceService: InvoiceService) {
|
||||
}
|
||||
private invoiceService: InvoiceService
|
||||
) {}
|
||||
|
||||
public getInvoicePaymentLink(invoice: Invoice, formValue: any): Observable<string> {
|
||||
return this.createInvoiceAccessToken(invoice.id)
|
||||
.map((accessToken) => this.prepareInvoiceUrl(formValue, invoice, accessToken))
|
||||
.switchMap((url) => this.urlShortenerService.shorten(url, invoice.dueDate))
|
||||
.map((response) => response.shortenedUrl);
|
||||
.map(accessToken => this.prepareInvoiceUrl(formValue, invoice, accessToken))
|
||||
.switchMap(url => this.urlShortenerService.shorten(url, invoice.dueDate))
|
||||
.map(response => response.shortenedUrl);
|
||||
}
|
||||
|
||||
public getInvoiceTemplatePaymentLink(templateAndToken: InvoiceTemplateAndToken, formValue: any): Observable<string> {
|
||||
public getInvoiceTemplatePaymentLink(
|
||||
templateAndToken: InvoiceTemplateAndToken,
|
||||
formValue: any
|
||||
): Observable<string> {
|
||||
this.prepareExpiresAtDateForTemplate(templateAndToken);
|
||||
return this.urlShortenerService
|
||||
.shorten(this.prepareInvoiceTemplateUrl(formValue, templateAndToken), this.prepareExpiresAtDateForTemplate(templateAndToken))
|
||||
.map((response) => response.shortenedUrl);
|
||||
.shorten(
|
||||
this.prepareInvoiceTemplateUrl(formValue, templateAndToken),
|
||||
this.prepareExpiresAtDateForTemplate(templateAndToken)
|
||||
)
|
||||
.map(response => response.shortenedUrl);
|
||||
}
|
||||
|
||||
private prepareExpiresAtDateForTemplate(templateAndToken: InvoiceTemplateAndToken): any {
|
||||
const lifetimeDuration = moment.duration(templateAndToken.invoiceTemplate.lifetime);
|
||||
return moment(new Date()).add(lifetimeDuration).utc().format();
|
||||
return moment(new Date())
|
||||
.add(lifetimeDuration)
|
||||
.utc()
|
||||
.format();
|
||||
}
|
||||
|
||||
private prepareInvoiceUrl(formValue: any, invoice: Invoice, accessToken: string): string {
|
||||
@ -58,7 +67,11 @@ export class PaymentLinkService {
|
||||
return `${this.configService.checkoutUrl}/v1/checkout.html?${args}`;
|
||||
}
|
||||
|
||||
private toInvoiceTemplatePaymentLinkArgs(formValue: any, templateID: string, accessToken: string): PaymentLinkArguments {
|
||||
private toInvoiceTemplatePaymentLinkArgs(
|
||||
formValue: any,
|
||||
templateID: string,
|
||||
accessToken: string
|
||||
): PaymentLinkArguments {
|
||||
const args = new PaymentLinkArguments();
|
||||
args.invoiceTemplateID = templateID;
|
||||
args.invoiceTemplateAccessToken = accessToken;
|
||||
@ -66,7 +79,11 @@ export class PaymentLinkService {
|
||||
return Object.assign(commonArgs, args);
|
||||
}
|
||||
|
||||
private toInvoicePaymentLinkArgs(formValue: any, invoiceID: string, accessToken: string): PaymentLinkArguments {
|
||||
private toInvoicePaymentLinkArgs(
|
||||
formValue: any,
|
||||
invoiceID: string,
|
||||
accessToken: string
|
||||
): PaymentLinkArguments {
|
||||
const args = new PaymentLinkArguments();
|
||||
args.invoiceID = invoiceID;
|
||||
args.invoiceAccessToken = accessToken;
|
||||
@ -94,6 +111,8 @@ export class PaymentLinkService {
|
||||
}
|
||||
|
||||
private createInvoiceAccessToken(invoiceID: string): Observable<string> {
|
||||
return this.invoiceService.createInvoiceAccessToken(invoiceID).map((response) => response.payload);
|
||||
return this.invoiceService
|
||||
.createInvoiceAccessToken(invoiceID)
|
||||
.map(response => response.payload);
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user