@daffodil/payment 0.0.0-PLACEHOLDER
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +52 -0
- package/README.md +11 -0
- package/driver/in-memory/ng-package.json +8 -0
- package/driver/in-memory/package.json +3 -0
- package/driver/in-memory/src/backend/payment.service.spec.ts +68 -0
- package/driver/in-memory/src/backend/payment.service.ts +55 -0
- package/driver/in-memory/src/driver/payment-driver.module.ts +33 -0
- package/driver/in-memory/src/driver/payment.service.spec.ts +70 -0
- package/driver/in-memory/src/driver/payment.service.ts +32 -0
- package/driver/in-memory/src/index.ts +1 -0
- package/driver/in-memory/src/public_api.ts +3 -0
- package/driver/ng-package.json +8 -0
- package/driver/package.json +3 -0
- package/driver/src/errors/invalid-api-response.ts +17 -0
- package/driver/src/errors/map.ts +11 -0
- package/driver/src/errors/public_api.ts +5 -0
- package/driver/src/index.ts +1 -0
- package/driver/src/interfaces/payment-service.interface.ts +24 -0
- package/driver/src/public_api.ts +6 -0
- package/driver/testing/ng-package.json +8 -0
- package/driver/testing/package.json +3 -0
- package/driver/testing/src/drivers/payment-driver.module.ts +31 -0
- package/driver/testing/src/drivers/payment.service.spec.ts +33 -0
- package/driver/testing/src/drivers/payment.service.ts +32 -0
- package/driver/testing/src/drivers/public_api.ts +2 -0
- package/driver/testing/src/index.ts +1 -0
- package/driver/testing/src/public_api.ts +1 -0
- package/karma.conf.js +11 -0
- package/ng-package.json +7 -0
- package/ng-package.prod.json +7 -0
- package/package.json +41 -0
- package/src/index.ts +1 -0
- package/src/injection-tokens/error-matcher.token.ts +12 -0
- package/src/injection-tokens/public_api.ts +1 -0
- package/src/models/public_api.ts +2 -0
- package/src/models/request.type.ts +13 -0
- package/src/models/response.type.ts +14 -0
- package/src/public_api.ts +2 -0
- package/state/ng-package.json +8 -0
- package/state/package.json +3 -0
- package/state/src/actions/payment.actions.ts +56 -0
- package/state/src/facades/payment/facade.spec.ts +70 -0
- package/state/src/facades/payment/facade.ts +43 -0
- package/state/src/facades/payment/interface.ts +21 -0
- package/state/src/facades/public_api.ts +2 -0
- package/state/src/index.ts +1 -0
- package/state/src/injection-tokens/available-processors.token.ts +29 -0
- package/state/src/injection-tokens/processor-collection.token.ts +22 -0
- package/state/src/injection-tokens/public_api.ts +5 -0
- package/state/src/models/available-processor.type.ts +23 -0
- package/state/src/models/processor-collection.type.ts +6 -0
- package/state/src/models/public_api.ts +2 -0
- package/state/src/payment.module.ts +15 -0
- package/state/src/public_api.ts +8 -0
- package/state/src/reducers/payment/adapter.spec.ts +89 -0
- package/state/src/reducers/payment/adapter.ts +46 -0
- package/state/src/reducers/payment/initial-state.ts +9 -0
- package/state/src/reducers/payment/interface.ts +16 -0
- package/state/src/reducers/payment/public_api.ts +4 -0
- package/state/src/reducers/payment/reducer.ts +35 -0
- package/state/src/reducers/public_api.ts +8 -0
- package/state/src/reducers/reducers.interface.ts +16 -0
- package/state/src/reducers/store-feature-key.ts +4 -0
- package/state/src/reducers/token/extra.token.spec.ts +35 -0
- package/state/src/reducers/token/extra.token.ts +42 -0
- package/state/src/reducers/token/public_api.ts +4 -0
- package/state/src/reducers/token/reducers.token.spec.ts +60 -0
- package/state/src/reducers/token/reducers.token.ts +36 -0
- package/state/src/selectors/feature.selector.ts +25 -0
- package/state/src/selectors/payment.selector.spec.ts +64 -0
- package/state/src/selectors/payment.selector.ts +57 -0
- package/state/src/selectors/public_api.ts +1 -0
- package/state/testing/ng-package.json +8 -0
- package/state/testing/package.json +3 -0
- package/state/testing/src/index.ts +1 -0
- package/state/testing/src/mock-payment-facade.ts +19 -0
- package/state/testing/src/payment-testing.module.ts +15 -0
- package/state/testing/src/public_api.ts +2 -0
- package/test.ts +23 -0
- package/testing/ng-package.json +8 -0
- package/testing/package.json +3 -0
- package/testing/src/factories/kind.factory.spec.ts +57 -0
- package/testing/src/factories/kind.factory.ts +37 -0
- package/testing/src/factories/payment-request.factory.spec.ts +37 -0
- package/testing/src/factories/payment-request.factory.ts +24 -0
- package/testing/src/factories/payment-response.factory.spec.ts +37 -0
- package/testing/src/factories/payment-response.factory.ts +24 -0
- package/testing/src/factories/public_api.ts +3 -0
- package/testing/src/index.ts +1 -0
- package/testing/src/injection-tokens/factories/kind.token.spec.ts +51 -0
- package/testing/src/injection-tokens/factories/kind.token.ts +43 -0
- package/testing/src/injection-tokens/public_api.ts +4 -0
- package/testing/src/public_api.ts +4 -0
- package/testing/src/testing.module.ts +18 -0
- package/tsconfig.json +32 -0
- package/tsconfig.lib.json +28 -0
- package/tsconfig.lib.prod.json +9 -0
- package/tsconfig.spec.json +17 -0
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
extends: '../../.eslintrc.js',
|
|
3
|
+
ignorePatterns: [
|
|
4
|
+
'!**/*'
|
|
5
|
+
],
|
|
6
|
+
overrides: [
|
|
7
|
+
{
|
|
8
|
+
files: [
|
|
9
|
+
'*.ts'
|
|
10
|
+
],
|
|
11
|
+
parserOptions: {
|
|
12
|
+
project: [
|
|
13
|
+
'libs/payment/tsconfig.lib.json',
|
|
14
|
+
'libs/payment/tsconfig.spec.json'
|
|
15
|
+
],
|
|
16
|
+
createDefaultProgram: true
|
|
17
|
+
},
|
|
18
|
+
rules: {
|
|
19
|
+
'@angular-eslint/component-class-suffix': [
|
|
20
|
+
'error',
|
|
21
|
+
{
|
|
22
|
+
suffixes: [
|
|
23
|
+
'Component'
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
'@angular-eslint/component-selector': [
|
|
28
|
+
'error',
|
|
29
|
+
{
|
|
30
|
+
type: 'element',
|
|
31
|
+
prefix: 'lib',
|
|
32
|
+
style: 'kebab-case'
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
'@angular-eslint/directive-selector': [
|
|
36
|
+
'error',
|
|
37
|
+
{
|
|
38
|
+
type: 'attribute',
|
|
39
|
+
prefix: 'lib',
|
|
40
|
+
style: 'camelCase'
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
files: [
|
|
47
|
+
'*.html'
|
|
48
|
+
],
|
|
49
|
+
rules: {}
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
}
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @daffodil/payment
|
|
2
|
+
|
|
3
|
+
`@daffodil/payment` contains the main features required to support payment in an Angular app. `@daffodil/payment` doesn't inherently support any particular payment methods but instead provides base models and extension points that are utilized by other libraries.
|
|
4
|
+
|
|
5
|
+
See [`@daffodil/authorizenet`](../authorizenet/README.md) for an example of such a library.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
npm install @daffodil/payment --save
|
|
11
|
+
```
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
import { TestBed } from '@angular/core/testing';
|
|
3
|
+
import {
|
|
4
|
+
RequestInfo,
|
|
5
|
+
STATUS,
|
|
6
|
+
} from 'angular-in-memory-web-api';
|
|
7
|
+
import {
|
|
8
|
+
Observable,
|
|
9
|
+
of,
|
|
10
|
+
} from 'rxjs';
|
|
11
|
+
|
|
12
|
+
import { DaffPaymentResponse } from '@daffodil/payment';
|
|
13
|
+
import {
|
|
14
|
+
DaffPaymentResponseFactory,
|
|
15
|
+
DaffPaymentTestingModule,
|
|
16
|
+
} from '@daffodil/payment/testing';
|
|
17
|
+
|
|
18
|
+
import { DaffPaymentInMemoryBackendService } from './payment.service';
|
|
19
|
+
|
|
20
|
+
describe('@daffodil/payment/driver/in-memory | DaffPaymentInMemoryBackendService', () => {
|
|
21
|
+
let service: DaffPaymentInMemoryBackendService;
|
|
22
|
+
let resultFactory: DaffPaymentResponseFactory;
|
|
23
|
+
let mockResults1: DaffPaymentResponse[];
|
|
24
|
+
let mockResults2: DaffPaymentResponse[];
|
|
25
|
+
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
TestBed.configureTestingModule({
|
|
28
|
+
imports: [
|
|
29
|
+
DaffPaymentTestingModule,
|
|
30
|
+
],
|
|
31
|
+
providers: [
|
|
32
|
+
DaffPaymentInMemoryBackendService,
|
|
33
|
+
],
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
service = TestBed.inject(DaffPaymentInMemoryBackendService);
|
|
37
|
+
resultFactory = TestBed.inject(DaffPaymentResponseFactory);
|
|
38
|
+
|
|
39
|
+
mockResults1 = resultFactory.createMany(3, { kind: 'TestBackend1' });
|
|
40
|
+
mockResults2 = resultFactory.createMany(3, { kind: 'TestBackend2' });
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should be created', () => {
|
|
44
|
+
expect(service).toBeTruthy();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('get', () => {
|
|
48
|
+
let reqInfoStub;
|
|
49
|
+
let result: Observable<any>;
|
|
50
|
+
|
|
51
|
+
beforeEach(() => {
|
|
52
|
+
reqInfoStub = {
|
|
53
|
+
utils: {
|
|
54
|
+
createResponse$: (func) => of(func()),
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
result = service.get(reqInfoStub);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should return a payment response', done => {
|
|
62
|
+
result.subscribe(res => {
|
|
63
|
+
expect(res.body).toBeDefined();
|
|
64
|
+
done();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
import {
|
|
3
|
+
InMemoryDbService,
|
|
4
|
+
RequestInfoUtilities,
|
|
5
|
+
ParsedRequestUrl,
|
|
6
|
+
STATUS,
|
|
7
|
+
RequestInfo,
|
|
8
|
+
} from 'angular-in-memory-web-api';
|
|
9
|
+
|
|
10
|
+
import { DaffPaymentResponseKindFactory } from '@daffodil/payment/testing';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* An in-memory service that delegates payment queries to child backends
|
|
14
|
+
* via the {@link DAFF_PAYMENT_IN_MEMORY_BACKENDS}.
|
|
15
|
+
*/
|
|
16
|
+
@Injectable({
|
|
17
|
+
providedIn: 'root',
|
|
18
|
+
})
|
|
19
|
+
export class DaffPaymentInMemoryBackendService implements InMemoryDbService {
|
|
20
|
+
constructor(
|
|
21
|
+
private factory: DaffPaymentResponseKindFactory,
|
|
22
|
+
) {}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Automatically called as part of the InMemoryDbService to parse incoming urls to match the InMemory backend urls.
|
|
26
|
+
*
|
|
27
|
+
* @param url initial url
|
|
28
|
+
* @param utils utility to parse url
|
|
29
|
+
* @returns ParsedRequestUrl
|
|
30
|
+
* @docs-private
|
|
31
|
+
*/
|
|
32
|
+
parseRequestUrl(url: string, utils: RequestInfoUtilities): ParsedRequestUrl {
|
|
33
|
+
return utils.parseRequestUrl(url);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @docs-private
|
|
38
|
+
*/
|
|
39
|
+
createDb(): any {
|
|
40
|
+
return {};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Generates a token from a processor backend.
|
|
45
|
+
*
|
|
46
|
+
* @param reqInfo request object
|
|
47
|
+
* @returns An http response object
|
|
48
|
+
*/
|
|
49
|
+
get(reqInfo: RequestInfo) {
|
|
50
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
51
|
+
status: STATUS.OK,
|
|
52
|
+
body: this.factory.create(),
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CommonModule } from '@angular/common';
|
|
2
|
+
import {
|
|
3
|
+
NgModule,
|
|
4
|
+
ModuleWithProviders,
|
|
5
|
+
} from '@angular/core';
|
|
6
|
+
|
|
7
|
+
import { DaffPaymentDriver } from '@daffodil/payment/driver';
|
|
8
|
+
import { DaffPaymentTestingModule } from '@daffodil/payment/testing';
|
|
9
|
+
|
|
10
|
+
import { DaffPaymentInMemoryDriver } from './payment.service';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Provides the {@link DaffPaymentInMemoryDriver} as the {@link DaffPaymentDriver}.
|
|
14
|
+
*/
|
|
15
|
+
@NgModule({
|
|
16
|
+
imports: [
|
|
17
|
+
CommonModule,
|
|
18
|
+
DaffPaymentTestingModule,
|
|
19
|
+
],
|
|
20
|
+
})
|
|
21
|
+
export class DaffPaymentInMemoryDriverModule {
|
|
22
|
+
static forRoot(): ModuleWithProviders<DaffPaymentInMemoryDriverModule> {
|
|
23
|
+
return {
|
|
24
|
+
ngModule: DaffPaymentInMemoryDriverModule,
|
|
25
|
+
providers: [
|
|
26
|
+
{
|
|
27
|
+
provide: DaffPaymentDriver,
|
|
28
|
+
useExisting: DaffPaymentInMemoryDriver,
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HttpTestingController,
|
|
3
|
+
HttpClientTestingModule,
|
|
4
|
+
} from '@angular/common/http/testing';
|
|
5
|
+
import { TestBed } from '@angular/core/testing';
|
|
6
|
+
import { Observable } from 'rxjs';
|
|
7
|
+
|
|
8
|
+
import { DaffPaymentResponse } from '@daffodil/payment';
|
|
9
|
+
import {
|
|
10
|
+
DaffPaymentRequestFactory,
|
|
11
|
+
DaffPaymentResponseFactory,
|
|
12
|
+
} from '@daffodil/payment/testing';
|
|
13
|
+
|
|
14
|
+
import { DaffPaymentInMemoryDriver } from './payment.service';
|
|
15
|
+
|
|
16
|
+
describe('@daffodil/payment/driver/in-memory | DaffPaymentInMemoryDriver', () => {
|
|
17
|
+
let service: DaffPaymentInMemoryDriver;
|
|
18
|
+
let httpMock: HttpTestingController;
|
|
19
|
+
let paymentRequestFactory: DaffPaymentRequestFactory;
|
|
20
|
+
let paymentResponseFactory: DaffPaymentResponseFactory;
|
|
21
|
+
let mockResponse: DaffPaymentResponse;
|
|
22
|
+
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
TestBed.configureTestingModule({
|
|
25
|
+
imports: [
|
|
26
|
+
HttpClientTestingModule,
|
|
27
|
+
],
|
|
28
|
+
providers: [
|
|
29
|
+
DaffPaymentInMemoryDriver,
|
|
30
|
+
],
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
httpMock = TestBed.inject(HttpTestingController);
|
|
34
|
+
service = TestBed.inject(DaffPaymentInMemoryDriver);
|
|
35
|
+
paymentRequestFactory = TestBed.inject(DaffPaymentRequestFactory);
|
|
36
|
+
paymentResponseFactory = TestBed.inject(DaffPaymentResponseFactory);
|
|
37
|
+
|
|
38
|
+
mockResponse = paymentResponseFactory.create();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
afterEach(() => {
|
|
42
|
+
httpMock.verify();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should be created', () => {
|
|
46
|
+
expect(service).toBeTruthy();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('generateToken', () => {
|
|
50
|
+
let url: string;
|
|
51
|
+
let result: Observable<DaffPaymentResponse>;
|
|
52
|
+
|
|
53
|
+
beforeEach(() => {
|
|
54
|
+
url = service.url;
|
|
55
|
+
result = service.generateToken(paymentRequestFactory.create());
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should send a get request and return a token response', done => {
|
|
59
|
+
result.subscribe((resp) => {
|
|
60
|
+
expect(resp).toBeDefined();
|
|
61
|
+
done();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const req = httpMock.expectOne(url);
|
|
65
|
+
expect(req.request.method).toBe('GET');
|
|
66
|
+
|
|
67
|
+
req.flush(mockResponse);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { HttpClient } from '@angular/common/http';
|
|
2
|
+
import { Injectable } from '@angular/core';
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
DaffPaymentRequest,
|
|
7
|
+
DaffPaymentResponse,
|
|
8
|
+
} from '@daffodil/payment';
|
|
9
|
+
import { DaffPaymentDriverInterface } from '@daffodil/payment/driver';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The payment inmemory driver to mock the payment backend service.
|
|
13
|
+
*
|
|
14
|
+
* @inheritdoc
|
|
15
|
+
*/
|
|
16
|
+
@Injectable({
|
|
17
|
+
providedIn: 'root',
|
|
18
|
+
})
|
|
19
|
+
export class DaffPaymentInMemoryDriver implements DaffPaymentDriverInterface {
|
|
20
|
+
/**
|
|
21
|
+
* @docs-private
|
|
22
|
+
*/
|
|
23
|
+
url = '/api/payment';
|
|
24
|
+
|
|
25
|
+
constructor(
|
|
26
|
+
private http: HttpClient,
|
|
27
|
+
) {}
|
|
28
|
+
|
|
29
|
+
generateToken(request: DaffPaymentRequest): Observable<DaffPaymentResponse> {
|
|
30
|
+
return this.http.get<DaffPaymentResponse>(this.url);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './public_api';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DaffError,
|
|
3
|
+
DaffInheritableError,
|
|
4
|
+
} from '@daffodil/core';
|
|
5
|
+
|
|
6
|
+
export const DAFF_PAYMENT_INVALID_API_RESPONSE_ERROR_CODE = 'DAFF_PAYMENT_INVALID_API_RESPONSE';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A general error indicating that the platform returned a response which cannot be processed.
|
|
10
|
+
*/
|
|
11
|
+
export class DaffPaymentInvalidAPIResponseError extends DaffInheritableError implements DaffError {
|
|
12
|
+
public readonly code: string = DAFF_PAYMENT_INVALID_API_RESPONSE_ERROR_CODE;
|
|
13
|
+
|
|
14
|
+
constructor(public message: string) {
|
|
15
|
+
super(message);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DaffPaymentInvalidAPIResponseError,
|
|
3
|
+
DAFF_PAYMENT_INVALID_API_RESPONSE_ERROR_CODE,
|
|
4
|
+
} from './invalid-api-response';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A mapping from error codes to error class constructors.
|
|
8
|
+
*/
|
|
9
|
+
export const DaffPaymentDriverErrorMap = {
|
|
10
|
+
[DAFF_PAYMENT_INVALID_API_RESPONSE_ERROR_CODE]: DaffPaymentInvalidAPIResponseError,
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './public_api';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
DaffPaymentRequest,
|
|
6
|
+
DaffPaymentResponse,
|
|
7
|
+
} from '@daffodil/payment';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* An injection token for the payment driver.
|
|
11
|
+
*/
|
|
12
|
+
export const DaffPaymentDriver = new InjectionToken<DaffPaymentDriverInterface>('DaffPaymentDriver');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The payment driver is responsible for taking user payment input and generating a token for use with the platform.
|
|
16
|
+
*/
|
|
17
|
+
export interface DaffPaymentDriverInterface<
|
|
18
|
+
T extends DaffPaymentResponse = DaffPaymentResponse,
|
|
19
|
+
> {
|
|
20
|
+
/**
|
|
21
|
+
* Generate a payment token.
|
|
22
|
+
*/
|
|
23
|
+
generateToken(request: DaffPaymentRequest): Observable<T>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { CommonModule } from '@angular/common';
|
|
2
|
+
import {
|
|
3
|
+
NgModule,
|
|
4
|
+
ModuleWithProviders,
|
|
5
|
+
} from '@angular/core';
|
|
6
|
+
|
|
7
|
+
import { DaffPaymentDriver } from '@daffodil/payment/driver';
|
|
8
|
+
|
|
9
|
+
import { DaffPaymentTestingDriver } from './payment.service';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Provides the {@link DaffPaymentTestingDriver} as the {@link DaffPaymentDriver}.
|
|
13
|
+
*/
|
|
14
|
+
@NgModule({
|
|
15
|
+
imports: [
|
|
16
|
+
CommonModule,
|
|
17
|
+
],
|
|
18
|
+
})
|
|
19
|
+
export class DaffPaymentTestingDriverModule {
|
|
20
|
+
static forRoot(): ModuleWithProviders<DaffPaymentTestingDriverModule> {
|
|
21
|
+
return {
|
|
22
|
+
ngModule: DaffPaymentTestingDriverModule,
|
|
23
|
+
providers: [
|
|
24
|
+
{
|
|
25
|
+
provide: DaffPaymentDriver,
|
|
26
|
+
useExisting: DaffPaymentTestingDriver,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { TestBed } from '@angular/core/testing';
|
|
2
|
+
import { cold } from 'jasmine-marbles';
|
|
3
|
+
|
|
4
|
+
import { DaffPaymentRequestFactory } from '@daffodil/payment/testing';
|
|
5
|
+
|
|
6
|
+
import { DaffPaymentTestingDriver } from './payment.service';
|
|
7
|
+
|
|
8
|
+
describe('@daffodil/driver/testing | DaffPaymentTestingDriver', () => {
|
|
9
|
+
let service: DaffPaymentTestingDriver;
|
|
10
|
+
let requestFactory: DaffPaymentRequestFactory;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
TestBed.configureTestingModule({
|
|
14
|
+
providers: [
|
|
15
|
+
DaffPaymentTestingDriver,
|
|
16
|
+
],
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
service = TestBed.inject(DaffPaymentTestingDriver);
|
|
20
|
+
requestFactory = TestBed.inject(DaffPaymentRequestFactory);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should be created', () => {
|
|
24
|
+
expect(service).toBeTruthy();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('generateToken', () => {
|
|
28
|
+
it('should return a DaffPaymentResponse', () => {
|
|
29
|
+
const expected = cold('(a|)', { a: jasmine.notEmpty() });
|
|
30
|
+
expect(service.generateToken(requestFactory.create())).toBeObservable(expected);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
import {
|
|
3
|
+
Observable,
|
|
4
|
+
of,
|
|
5
|
+
} from 'rxjs';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
DaffPaymentRequest,
|
|
9
|
+
DaffPaymentResponse,
|
|
10
|
+
} from '@daffodil/payment';
|
|
11
|
+
import { DaffPaymentDriverInterface } from '@daffodil/payment/driver';
|
|
12
|
+
import { DaffPaymentResponseKindFactory } from '@daffodil/payment/testing';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A basic payment driver that creates mock payment results of different kinds.
|
|
16
|
+
* For testing purposes.
|
|
17
|
+
*
|
|
18
|
+
* @inheritdoc
|
|
19
|
+
*/
|
|
20
|
+
@Injectable({
|
|
21
|
+
providedIn: 'root',
|
|
22
|
+
})
|
|
23
|
+
export class DaffPaymentTestingDriver implements DaffPaymentDriverInterface {
|
|
24
|
+
|
|
25
|
+
constructor(
|
|
26
|
+
private paymentResponseFactory: DaffPaymentResponseKindFactory,
|
|
27
|
+
) {}
|
|
28
|
+
|
|
29
|
+
generateToken(request: DaffPaymentRequest): Observable<DaffPaymentResponse> {
|
|
30
|
+
return of(this.paymentResponseFactory.create());
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './public_api';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './drivers/public_api';
|
package/karma.conf.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
baseConfiguration = require('../../tools/karma/karma.conf');
|
|
2
|
+
|
|
3
|
+
module.exports = function (config) {
|
|
4
|
+
baseConfiguration(config);
|
|
5
|
+
config.set({
|
|
6
|
+
coverageIstanbulReporter: {
|
|
7
|
+
dir: require('path').join(__dirname, '../../coverage/libs/payment'),
|
|
8
|
+
},
|
|
9
|
+
restartOnFileChange: true
|
|
10
|
+
});
|
|
11
|
+
};
|
package/ng-package.json
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@daffodil/payment",
|
|
3
|
+
"version": "0.0.0-PLACEHOLDER",
|
|
4
|
+
"description": "A client-side Angular package for managing ecommerce payments agnostic to the ecommerce platform.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/graycoreio/daffodil"
|
|
8
|
+
},
|
|
9
|
+
"author": "Graycore LLC",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/graycoreio/daffodil/issues"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "ng build payment --prod",
|
|
16
|
+
"lint": "cd ../.. && ng lint payment",
|
|
17
|
+
"lint:fix": "npm run lint -- --fix",
|
|
18
|
+
"test": "ng test payment --watch=false --browsers=ChromeHeadless",
|
|
19
|
+
"prepublish": "cd ../../dist/payment",
|
|
20
|
+
"publish": "npm publish --access=public"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/graycoreio/daffodil",
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@angular/common": "0.0.0-PLACEHOLDER",
|
|
25
|
+
"@angular/core": "0.0.0-PLACEHOLDER",
|
|
26
|
+
"@daffodil/core": "0.0.0-PLACEHOLDER",
|
|
27
|
+
"@ngrx/effects": "0.0.0-PLACEHOLDER",
|
|
28
|
+
"@ngrx/store": "0.0.0-PLACEHOLDER",
|
|
29
|
+
"rxjs": "0.0.0-PLACEHOLDER"
|
|
30
|
+
},
|
|
31
|
+
"optionalDependencies": {
|
|
32
|
+
"@apollo/client": "0.0.0-PLACEHOLDER",
|
|
33
|
+
"@daffodil/driver": "0.0.0-PLACEHOLDER",
|
|
34
|
+
"apollo-angular": "0.0.0-PLACEHOLDER",
|
|
35
|
+
"@faker-js/faker": "0.0.0-PLACEHOLDER"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@daffodil/core": "0.0.0-PLACEHOLDER",
|
|
39
|
+
"@daffodil/geography": "0.0.0-PLACEHOLDER"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './public_api';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
import { daffTransformErrorToStateError } from '@daffodil/core/state';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Transforms `DaffError`s into `DaffStateError`s before they are serialized into state.
|
|
7
|
+
* Can be used to further refine Daffodil errors into more specific app errors.
|
|
8
|
+
*/
|
|
9
|
+
export const DAFF_PAYMENT_ERROR_MATCHER = new InjectionToken<typeof daffTransformErrorToStateError>(
|
|
10
|
+
'DAFF_PAYMENT_ERROR_MATCHER',
|
|
11
|
+
{ factory: () => daffTransformErrorToStateError },
|
|
12
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DAFF_PAYMENT_ERROR_MATCHER } from './error-matcher.token';
|