@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.
Files changed (98) hide show
  1. package/.eslintrc.js +52 -0
  2. package/README.md +11 -0
  3. package/driver/in-memory/ng-package.json +8 -0
  4. package/driver/in-memory/package.json +3 -0
  5. package/driver/in-memory/src/backend/payment.service.spec.ts +68 -0
  6. package/driver/in-memory/src/backend/payment.service.ts +55 -0
  7. package/driver/in-memory/src/driver/payment-driver.module.ts +33 -0
  8. package/driver/in-memory/src/driver/payment.service.spec.ts +70 -0
  9. package/driver/in-memory/src/driver/payment.service.ts +32 -0
  10. package/driver/in-memory/src/index.ts +1 -0
  11. package/driver/in-memory/src/public_api.ts +3 -0
  12. package/driver/ng-package.json +8 -0
  13. package/driver/package.json +3 -0
  14. package/driver/src/errors/invalid-api-response.ts +17 -0
  15. package/driver/src/errors/map.ts +11 -0
  16. package/driver/src/errors/public_api.ts +5 -0
  17. package/driver/src/index.ts +1 -0
  18. package/driver/src/interfaces/payment-service.interface.ts +24 -0
  19. package/driver/src/public_api.ts +6 -0
  20. package/driver/testing/ng-package.json +8 -0
  21. package/driver/testing/package.json +3 -0
  22. package/driver/testing/src/drivers/payment-driver.module.ts +31 -0
  23. package/driver/testing/src/drivers/payment.service.spec.ts +33 -0
  24. package/driver/testing/src/drivers/payment.service.ts +32 -0
  25. package/driver/testing/src/drivers/public_api.ts +2 -0
  26. package/driver/testing/src/index.ts +1 -0
  27. package/driver/testing/src/public_api.ts +1 -0
  28. package/karma.conf.js +11 -0
  29. package/ng-package.json +7 -0
  30. package/ng-package.prod.json +7 -0
  31. package/package.json +41 -0
  32. package/src/index.ts +1 -0
  33. package/src/injection-tokens/error-matcher.token.ts +12 -0
  34. package/src/injection-tokens/public_api.ts +1 -0
  35. package/src/models/public_api.ts +2 -0
  36. package/src/models/request.type.ts +13 -0
  37. package/src/models/response.type.ts +14 -0
  38. package/src/public_api.ts +2 -0
  39. package/state/ng-package.json +8 -0
  40. package/state/package.json +3 -0
  41. package/state/src/actions/payment.actions.ts +56 -0
  42. package/state/src/facades/payment/facade.spec.ts +70 -0
  43. package/state/src/facades/payment/facade.ts +43 -0
  44. package/state/src/facades/payment/interface.ts +21 -0
  45. package/state/src/facades/public_api.ts +2 -0
  46. package/state/src/index.ts +1 -0
  47. package/state/src/injection-tokens/available-processors.token.ts +29 -0
  48. package/state/src/injection-tokens/processor-collection.token.ts +22 -0
  49. package/state/src/injection-tokens/public_api.ts +5 -0
  50. package/state/src/models/available-processor.type.ts +23 -0
  51. package/state/src/models/processor-collection.type.ts +6 -0
  52. package/state/src/models/public_api.ts +2 -0
  53. package/state/src/payment.module.ts +15 -0
  54. package/state/src/public_api.ts +8 -0
  55. package/state/src/reducers/payment/adapter.spec.ts +89 -0
  56. package/state/src/reducers/payment/adapter.ts +46 -0
  57. package/state/src/reducers/payment/initial-state.ts +9 -0
  58. package/state/src/reducers/payment/interface.ts +16 -0
  59. package/state/src/reducers/payment/public_api.ts +4 -0
  60. package/state/src/reducers/payment/reducer.ts +35 -0
  61. package/state/src/reducers/public_api.ts +8 -0
  62. package/state/src/reducers/reducers.interface.ts +16 -0
  63. package/state/src/reducers/store-feature-key.ts +4 -0
  64. package/state/src/reducers/token/extra.token.spec.ts +35 -0
  65. package/state/src/reducers/token/extra.token.ts +42 -0
  66. package/state/src/reducers/token/public_api.ts +4 -0
  67. package/state/src/reducers/token/reducers.token.spec.ts +60 -0
  68. package/state/src/reducers/token/reducers.token.ts +36 -0
  69. package/state/src/selectors/feature.selector.ts +25 -0
  70. package/state/src/selectors/payment.selector.spec.ts +64 -0
  71. package/state/src/selectors/payment.selector.ts +57 -0
  72. package/state/src/selectors/public_api.ts +1 -0
  73. package/state/testing/ng-package.json +8 -0
  74. package/state/testing/package.json +3 -0
  75. package/state/testing/src/index.ts +1 -0
  76. package/state/testing/src/mock-payment-facade.ts +19 -0
  77. package/state/testing/src/payment-testing.module.ts +15 -0
  78. package/state/testing/src/public_api.ts +2 -0
  79. package/test.ts +23 -0
  80. package/testing/ng-package.json +8 -0
  81. package/testing/package.json +3 -0
  82. package/testing/src/factories/kind.factory.spec.ts +57 -0
  83. package/testing/src/factories/kind.factory.ts +37 -0
  84. package/testing/src/factories/payment-request.factory.spec.ts +37 -0
  85. package/testing/src/factories/payment-request.factory.ts +24 -0
  86. package/testing/src/factories/payment-response.factory.spec.ts +37 -0
  87. package/testing/src/factories/payment-response.factory.ts +24 -0
  88. package/testing/src/factories/public_api.ts +3 -0
  89. package/testing/src/index.ts +1 -0
  90. package/testing/src/injection-tokens/factories/kind.token.spec.ts +51 -0
  91. package/testing/src/injection-tokens/factories/kind.token.ts +43 -0
  92. package/testing/src/injection-tokens/public_api.ts +4 -0
  93. package/testing/src/public_api.ts +4 -0
  94. package/testing/src/testing.module.ts +18 -0
  95. package/tsconfig.json +32 -0
  96. package/tsconfig.lib.json +28 -0
  97. package/tsconfig.lib.prod.json +9 -0
  98. package/tsconfig.spec.json +17 -0
@@ -0,0 +1,13 @@
1
+ /**
2
+ * A payment request that can be used to generate a token or additional data for use with an ecommerce platform.
3
+ */
4
+ export interface DaffPaymentRequest<T = unknown> {
5
+ /**
6
+ * The payment kind. A constant identifying the payment processor and payment method.
7
+ */
8
+ kind: string;
9
+ /**
10
+ * The payment data that will be used to generate a payment token or additional data.
11
+ */
12
+ data?: T;
13
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * A payment response that can be sent to an ecommerce platform to set payment information for the provided method.
3
+ */
4
+ export interface DaffPaymentResponse<T = unknown> {
5
+ /**
6
+ * The payment method.
7
+ * This can be specific to the platform in use and should not be considered a constant.
8
+ */
9
+ method: string;
10
+ /**
11
+ * The payment data that represents validated payment information.
12
+ */
13
+ data?: T;
14
+ }
@@ -0,0 +1,2 @@
1
+ export * from './models/public_api';
2
+ export * from './injection-tokens/public_api';
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
3
+ "dest": "../../dist/payment/state",
4
+ "deleteDestPath": false,
5
+ "lib": {
6
+ "entryFile": "src/index.ts"
7
+ }
8
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "name": "@daffodil/payment/state"
3
+ }
@@ -0,0 +1,56 @@
1
+ import { Action } from '@ngrx/store';
2
+
3
+ import { DaffIdentifiable } from '@daffodil/core';
4
+ import { DaffStateError } from '@daffodil/core/state';
5
+ import { DaffPersonalAddress } from '@daffodil/geography';
6
+ import {
7
+ DaffPaymentRequest,
8
+ DaffPaymentResponse,
9
+ } from '@daffodil/payment';
10
+
11
+ /**
12
+ * The payment action types enum.
13
+ */
14
+ export enum DaffPaymentActionTypes {
15
+ GenerateTokenSuccessAction = '[@daffodil/payment] Generate Token Success Action',
16
+ GenerateTokenFailureAction = '[@daffodil/payment] Generate Token Failure Action',
17
+ }
18
+
19
+ /**
20
+ * Generates a payment token.
21
+ *
22
+ * @param query The payment query.
23
+ */
24
+ export interface DaffPaymentGenerateToken<T extends DaffPaymentRequest = DaffPaymentRequest> extends Action {
25
+ readonly request: T;
26
+ readonly address?: DaffPersonalAddress | DaffIdentifiable;
27
+ }
28
+
29
+ /**
30
+ * Indicates a successful generation of a payment token.
31
+ */
32
+ export class DaffPaymentGenerateTokenSuccess<T extends DaffPaymentResponse = DaffPaymentResponse> implements Action {
33
+ readonly type = DaffPaymentActionTypes.GenerateTokenSuccessAction;
34
+
35
+ constructor(public payload: T) {}
36
+ }
37
+
38
+ /**
39
+ * A failed payment with the error message.
40
+ */
41
+ export class DaffPaymentGenerateTokenFailure implements Action {
42
+ readonly type = DaffPaymentActionTypes.GenerateTokenFailureAction;
43
+
44
+ constructor(public payload: DaffStateError) {}
45
+ }
46
+
47
+ /**
48
+ * A union of the payment action types.
49
+ */
50
+ export type DaffPaymentActions<
51
+ T extends DaffPaymentResponse = DaffPaymentResponse,
52
+ R extends DaffPaymentRequest = DaffPaymentRequest,
53
+ > =
54
+ | DaffPaymentGenerateToken<R>
55
+ | DaffPaymentGenerateTokenSuccess<T>
56
+ | DaffPaymentGenerateTokenFailure;
@@ -0,0 +1,70 @@
1
+ import { TestBed } from '@angular/core/testing';
2
+ import {
3
+ combineReducers,
4
+ Store,
5
+ StoreModule,
6
+ } from '@ngrx/store';
7
+ import { cold } from 'jasmine-marbles';
8
+
9
+ import {
10
+ daffPaymentReducerFactory,
11
+ DaffPaymentReducersState,
12
+ DaffPaymentStateRootSlice,
13
+ DAFF_PAYMENT_STORE_FEATURE_KEY,
14
+ } from '@daffodil/payment/state';
15
+
16
+ import { DaffPaymentPageFacade } from './facade';
17
+
18
+ describe('@daffodil/payment/state | DaffPaymentPageFacade', () => {
19
+ let store: Store<DaffPaymentStateRootSlice>;
20
+ let facade: DaffPaymentPageFacade;
21
+
22
+ let errors: string[];
23
+
24
+ beforeEach(() => {
25
+ TestBed.configureTestingModule({
26
+ imports: [
27
+ StoreModule.forRoot({
28
+ [DAFF_PAYMENT_STORE_FEATURE_KEY]: combineReducers<DaffPaymentReducersState>({
29
+ payment: daffPaymentReducerFactory([]),
30
+ }),
31
+ }),
32
+ ],
33
+ providers: [
34
+ DaffPaymentPageFacade,
35
+ ],
36
+ });
37
+
38
+ store = TestBed.inject(Store);
39
+ facade = TestBed.inject(DaffPaymentPageFacade);
40
+
41
+ errors = [];
42
+ });
43
+
44
+ it('should be created', () => {
45
+ expect(facade).toBeTruthy();
46
+ });
47
+
48
+ it('should be able to dispatch an action to the store', () => {
49
+ spyOn(store, 'dispatch');
50
+ const action = { type: 'SOME_TYPE' };
51
+
52
+ facade.dispatch(action);
53
+ expect(store.dispatch).toHaveBeenCalledWith(action);
54
+ expect(store.dispatch).toHaveBeenCalledTimes(1);
55
+ });
56
+
57
+ describe('loading$', () => {
58
+ it('should be false if the payment is not loading', () => {
59
+ const expected = cold('a', { a: false });
60
+ expect(facade.loading$).toBeObservable(expected);
61
+ });
62
+ });
63
+
64
+ describe('errors$', () => {
65
+ it('should initially be an empty array', () => {
66
+ const expected = cold('a', { a: errors });
67
+ expect(facade.errors$).toBeObservable(expected);
68
+ });
69
+ });
70
+ });
@@ -0,0 +1,43 @@
1
+ import { Injectable } from '@angular/core';
2
+ import {
3
+ Action,
4
+ Store,
5
+ select,
6
+ } from '@ngrx/store';
7
+ import { Observable } from 'rxjs';
8
+
9
+ import { DaffStateError } from '@daffodil/core/state';
10
+
11
+ import { DaffPaymentStateRootSlice } from '../../reducers/public_api';
12
+ import { daffPaymentGetSelectors } from '../../selectors/public_api';
13
+ import { DaffPaymentPageFacadeInterface } from './interface';
14
+
15
+ /**
16
+ * @inheritdoc
17
+ *
18
+ * Serves as the base for a payment facade.
19
+ * Extend this class and pass in the selectors for the specific state you wish to target.
20
+ */
21
+ @Injectable({
22
+ providedIn: 'root',
23
+ })
24
+ export class DaffPaymentPageFacade implements DaffPaymentPageFacadeInterface {
25
+ loading$: Observable<boolean>;
26
+ errors$: Observable<DaffStateError[]>;
27
+
28
+ constructor(
29
+ private store: Store<DaffPaymentStateRootSlice>,
30
+ ) {
31
+ const {
32
+ selectPaymentLoading,
33
+ selectPaymentErrors,
34
+ } = daffPaymentGetSelectors();
35
+
36
+ this.loading$ = this.store.pipe(select(selectPaymentLoading));
37
+ this.errors$ = this.store.pipe(select(selectPaymentErrors));
38
+ }
39
+
40
+ dispatch(action: Action) {
41
+ this.store.dispatch(action);
42
+ }
43
+ }
@@ -0,0 +1,21 @@
1
+ import { Action } from '@ngrx/store';
2
+ import { Observable } from 'rxjs';
3
+
4
+ import {
5
+ DaffStoreFacade,
6
+ DaffStateError,
7
+ } from '@daffodil/core/state';
8
+
9
+ /**
10
+ * Exposes the payment state selectors.
11
+ */
12
+ export interface DaffPaymentPageFacadeInterface extends DaffStoreFacade<Action> {
13
+ /**
14
+ * Whether there is a pending payment operation.
15
+ */
16
+ loading$: Observable<boolean>;
17
+ /**
18
+ * A list of payment errors, if any.
19
+ */
20
+ errors$: Observable<DaffStateError[]>;
21
+ }
@@ -0,0 +1,2 @@
1
+ export { DaffPaymentPageFacadeInterface } from './payment/interface';
2
+ export { DaffPaymentPageFacade } from './payment/facade';
@@ -0,0 +1 @@
1
+ export * from './public_api';
@@ -0,0 +1,29 @@
1
+ import {
2
+ InjectionToken,
3
+ ValueProvider,
4
+ } from '@angular/core';
5
+
6
+ import { DaffPaymentAvailableProcessor } from '../models/public_api';
7
+
8
+ /**
9
+ * A multi-provider injection token for registering payment processors.
10
+ */
11
+ export const DAFF_PAYMENT_AVAILABLE_PROCESSORS = new InjectionToken<DaffPaymentAvailableProcessor[]>(
12
+ 'DAFF_PAYMENT_AVAILABLE_PROCESSORS',
13
+ {
14
+ factory: () => [],
15
+ providedIn: 'any',
16
+ },
17
+ );
18
+
19
+ /**
20
+ * Provides a payment processor registration.
21
+ *
22
+ * See {@link DaffPaymentAvailableProcessor}.
23
+ */
24
+ export const daffPaymentProvideAvailableProcessors = (...processors: DaffPaymentAvailableProcessor[]): ValueProvider[] =>
25
+ processors.map(processor => ({
26
+ provide: DAFF_PAYMENT_AVAILABLE_PROCESSORS,
27
+ useValue: processor,
28
+ multi: true,
29
+ }));
@@ -0,0 +1,22 @@
1
+ import {
2
+ inject,
3
+ InjectionToken,
4
+ } from '@angular/core';
5
+
6
+ import { daffArrayToDict } from '@daffodil/core';
7
+
8
+ import { DaffPaymentProcessorCollection } from '../models/public_api';
9
+ import { DAFF_PAYMENT_AVAILABLE_PROCESSORS } from './available-processors.token';
10
+
11
+ /**
12
+ * An internal token to combine the available payment processors into a single collection.
13
+ */
14
+ export const DAFF_PAYMENT_PROCESSOR_COLLECTION = new InjectionToken<DaffPaymentProcessorCollection>(
15
+ 'DAFF_PAYMENT_PROCESSOR_COLLECTION',
16
+ {
17
+ factory: () => {
18
+ const processors = inject(DAFF_PAYMENT_AVAILABLE_PROCESSORS);
19
+ return daffArrayToDict(processors, ({ kind }) => kind);
20
+ },
21
+ },
22
+ );
@@ -0,0 +1,5 @@
1
+ export {
2
+ DAFF_PAYMENT_AVAILABLE_PROCESSORS,
3
+ daffPaymentProvideAvailableProcessors,
4
+ } from './available-processors.token';
5
+ export { DAFF_PAYMENT_PROCESSOR_COLLECTION } from './processor-collection.token';
@@ -0,0 +1,23 @@
1
+ import { InjectionToken } from '@angular/core';
2
+
3
+ import { DaffPaymentRequest } from '@daffodil/payment';
4
+ import { DaffPaymentDriverInterface } from '@daffodil/payment/driver';
5
+
6
+ /**
7
+ * A representation of an available payment processor.
8
+ */
9
+ export interface DaffPaymentAvailableProcessor {
10
+ /**
11
+ * The processor kind.
12
+ */
13
+ kind: DaffPaymentRequest['kind'];
14
+ /**
15
+ * The action type string that triggers token generation.
16
+ */
17
+ action: string;
18
+ /**
19
+ * An injection token of the driver that can perform token generation
20
+ * for this specific payment processor.
21
+ */
22
+ driver: InjectionToken<DaffPaymentDriverInterface>;
23
+ }
@@ -0,0 +1,6 @@
1
+ import { DaffPaymentAvailableProcessor } from './available-processor.type';
2
+
3
+ /**
4
+ * A collection of {@link DaffPaymentAvailableProcessor}s.
5
+ */
6
+ export type DaffPaymentProcessorCollection = Record<DaffPaymentAvailableProcessor['kind'], DaffPaymentAvailableProcessor>;
@@ -0,0 +1,2 @@
1
+ export { DaffPaymentAvailableProcessor } from './available-processor.type';
2
+ export { DaffPaymentProcessorCollection } from './processor-collection.type';
@@ -0,0 +1,15 @@
1
+ import { NgModule } from '@angular/core';
2
+ import { StoreModule } from '@ngrx/store';
3
+
4
+ import { DAFF_PAYMENT_STORE_FEATURE_KEY } from './reducers/public_api';
5
+ import { DAFF_PAYMENT_REDUCERS } from './reducers/token/reducers.token';
6
+
7
+ /**
8
+ * Creates the payment feature store.
9
+ */
10
+ @NgModule({
11
+ imports: [
12
+ StoreModule.forFeature(DAFF_PAYMENT_STORE_FEATURE_KEY, DAFF_PAYMENT_REDUCERS),
13
+ ],
14
+ })
15
+ export class DaffPaymentStateModule {}
@@ -0,0 +1,8 @@
1
+ export * from './actions/payment.actions';
2
+ export * from './reducers/public_api';
3
+ export * from './selectors/public_api';
4
+ export * from './facades/public_api';
5
+ export * from './injection-tokens/public_api';
6
+ export * from './models/public_api';
7
+
8
+ export * from './payment.module';
@@ -0,0 +1,89 @@
1
+ import { DaffStateError } from '@daffodil/core/state';
2
+ import {
3
+ daffPaymentInitialState,
4
+ daffPaymentInitialState as initialState,
5
+ DaffPaymentReducerState,
6
+ } from '@daffodil/payment/state';
7
+ import { DaffPaymentResponseFactory } from '@daffodil/payment/testing';
8
+
9
+ import { DaffPaymentStateReducerAdapter } from './adapter';
10
+
11
+ describe('@daffodil/payment/state | DaffPaymentStateReducerAdapter', () => {
12
+ let adapter: DaffPaymentStateReducerAdapter;
13
+
14
+ beforeEach(() => {
15
+ adapter = new DaffPaymentStateReducerAdapter();
16
+ });
17
+
18
+ describe('generateToken', () => {
19
+ let result: DaffPaymentReducerState;
20
+
21
+ beforeEach(() => {
22
+ result = adapter.generateToken(daffPaymentInitialState);
23
+ });
24
+
25
+ it('sets loading state to true', () => {
26
+ expect(result.loading).toEqual(true);
27
+ });
28
+ });
29
+
30
+ describe('tokenGenerated', () => {
31
+ let mockError: DaffStateError;
32
+ let result: DaffPaymentReducerState;
33
+ let state: DaffPaymentReducerState;
34
+
35
+ beforeEach(() => {
36
+ mockError = {
37
+ code: 'error code',
38
+ message: 'error message',
39
+ };
40
+ state = {
41
+ ...initialState,
42
+ loading: true,
43
+ errors: [mockError],
44
+ };
45
+
46
+ result = adapter.tokenGenerated(state);
47
+ });
48
+
49
+ it('sets loading to false', () => {
50
+ expect(result.loading).toEqual(false);
51
+ });
52
+
53
+ it('should reset errors', () => {
54
+ expect(result.errors).toEqual([]);
55
+ });
56
+ });
57
+
58
+ describe('storeError', () => {
59
+ let result;
60
+ let state: DaffPaymentReducerState;
61
+ let mockError: DaffStateError;
62
+
63
+ beforeEach(() => {
64
+ mockError = {
65
+ code: 'error code',
66
+ message: 'error message',
67
+ };
68
+ state = {
69
+ ...initialState,
70
+ loading: true,
71
+ errors: [
72
+ { code: 'firstErrorCode', message: 'firstErrorMessage' },
73
+ ],
74
+ };
75
+
76
+
77
+ result = adapter.storeError(mockError, state);
78
+ });
79
+
80
+ it('adds the error in action.payload to state.errors', () => {
81
+ expect(result.errors).toContain(mockError);
82
+ expect(result.errors.length).toEqual(2);
83
+ });
84
+
85
+ it('sets loading to false', () => {
86
+ expect(result.loading).toEqual(false);
87
+ });
88
+ });
89
+ });
@@ -0,0 +1,46 @@
1
+ import { DaffStateError } from '@daffodil/core/state';
2
+
3
+ import { DaffPaymentReducerState } from './interface';
4
+
5
+ /**
6
+ * Manages {@link DaffPaymentReducerState}.
7
+ */
8
+ export class DaffPaymentStateReducerAdapter {
9
+
10
+ /**
11
+ * Begins the payment operation flow.
12
+ * Sets loading to true.
13
+ */
14
+ generateToken(state: DaffPaymentReducerState): DaffPaymentReducerState {
15
+ return {
16
+ ...state,
17
+ loading: true,
18
+ };
19
+ }
20
+
21
+ /**
22
+ * Sets loading to false and resets errors.
23
+ */
24
+ tokenGenerated(state: DaffPaymentReducerState): DaffPaymentReducerState {
25
+ return {
26
+ ...state,
27
+ loading: false,
28
+ errors: [],
29
+ };
30
+ }
31
+
32
+ /**
33
+ * Stores the from a failed payment.
34
+ * Also sets loading to false.
35
+ */
36
+ storeError(error: DaffStateError, state: DaffPaymentReducerState): DaffPaymentReducerState {
37
+ return {
38
+ ...state,
39
+ errors: [
40
+ ...state.errors,
41
+ error,
42
+ ],
43
+ loading: false,
44
+ };
45
+ }
46
+ }
@@ -0,0 +1,9 @@
1
+ import { DaffPaymentReducerState } from './interface';
2
+
3
+ /**
4
+ * The initial state for the main payment state, see {@link DaffPaymentReducerState}.
5
+ */
6
+ export const daffPaymentInitialState: DaffPaymentReducerState = {
7
+ loading: false,
8
+ errors: [],
9
+ };
@@ -0,0 +1,16 @@
1
+ import { DaffStateError } from '@daffodil/core/state';
2
+
3
+ /**
4
+ * The main payment state.
5
+ * Contains info about the current or most recent payment operation.
6
+ */
7
+ export interface DaffPaymentReducerState {
8
+ /**
9
+ * Whether there is a pending payment operation.
10
+ */
11
+ loading: boolean;
12
+ /**
13
+ * A list of payment errors, if any.
14
+ */
15
+ errors: DaffStateError[];
16
+ }
@@ -0,0 +1,4 @@
1
+ export { DaffPaymentStateReducerAdapter } from './adapter';
2
+ export { DaffPaymentReducerState } from './interface';
3
+ export { daffPaymentInitialState } from './initial-state';
4
+ export { daffPaymentReducerFactory } from './reducer';
@@ -0,0 +1,35 @@
1
+ import { DaffPaymentResponse } from '@daffodil/payment';
2
+
3
+ import {
4
+ DaffPaymentGenerateToken,
5
+ DaffPaymentActionTypes,
6
+ DaffPaymentActions,
7
+ DaffPaymentGenerateTokenFailure,
8
+ } from '../../actions/payment.actions';
9
+ import { DaffPaymentStateReducerAdapter } from './adapter';
10
+ import { daffPaymentInitialState } from './initial-state';
11
+ import { DaffPaymentReducerState } from './interface';
12
+
13
+ /**
14
+ * The reducer for the payment page state, see {@link DaffPaymentReducerState}.
15
+ */
16
+ export const daffPaymentReducerFactory = <T extends DaffPaymentResponse = DaffPaymentResponse>(actions: DaffPaymentGenerateToken['type'][]) =>
17
+ (
18
+ state = daffPaymentInitialState,
19
+ action: DaffPaymentActions<T>,
20
+ ): DaffPaymentReducerState => {
21
+ const adapter = new DaffPaymentStateReducerAdapter();
22
+ switch (true) {
23
+ case actions.includes(action.type):
24
+ return adapter.generateToken(state);
25
+
26
+ case action.type === DaffPaymentActionTypes.GenerateTokenSuccessAction:
27
+ return adapter.tokenGenerated(state);
28
+
29
+ case action.type === DaffPaymentActionTypes.GenerateTokenFailureAction:
30
+ return adapter.storeError((<DaffPaymentGenerateTokenFailure>action).payload, state);
31
+
32
+ default:
33
+ return state;
34
+ }
35
+ };
@@ -0,0 +1,8 @@
1
+ export {
2
+ DaffPaymentReducersState,
3
+ DaffPaymentStateRootSlice,
4
+ } from './reducers.interface';
5
+ export { DAFF_PAYMENT_STORE_FEATURE_KEY } from './store-feature-key';
6
+
7
+ export * from './token/public_api';
8
+ export * from './payment/public_api';
@@ -0,0 +1,16 @@
1
+ import { DaffPaymentReducerState } from './payment/public_api';
2
+ import { DAFF_PAYMENT_STORE_FEATURE_KEY } from './store-feature-key';
3
+
4
+ /**
5
+ * The feature state for payment.
6
+ */
7
+ export interface DaffPaymentReducersState {
8
+ payment: DaffPaymentReducerState;
9
+ }
10
+
11
+ /**
12
+ * The footprint of payment feature state in the root application state.
13
+ */
14
+ export interface DaffPaymentStateRootSlice {
15
+ [DAFF_PAYMENT_STORE_FEATURE_KEY]: DaffPaymentReducersState;
16
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * The key under which the payment feature state will be stored.
3
+ */
4
+ export const DAFF_PAYMENT_STORE_FEATURE_KEY = 'daffPayment';
@@ -0,0 +1,35 @@
1
+ import { TestBed } from '@angular/core/testing';
2
+ import { ActionReducer } from '@ngrx/store';
3
+
4
+ import { DaffPaymentReducersState } from '@daffodil/payment/state';
5
+
6
+ import {
7
+ daffPaymentProvideExtraReducers,
8
+ DAFF_PAYMENT_EXTRA_REDUCERS,
9
+ } from './extra.token';
10
+
11
+ describe('daffPaymentProvideExtraReducers', () => {
12
+ let reducers: ActionReducer<DaffPaymentReducersState>[];
13
+ let result: ActionReducer<DaffPaymentReducersState>[];
14
+
15
+ beforeEach(() => {
16
+ reducers = [
17
+ (state, action) => state,
18
+ (state, action) => state,
19
+ ];
20
+
21
+ TestBed.configureTestingModule({
22
+ providers: [
23
+ ...daffPaymentProvideExtraReducers(...reducers),
24
+ ],
25
+ });
26
+
27
+ result = TestBed.inject(DAFF_PAYMENT_EXTRA_REDUCERS);
28
+ });
29
+
30
+ it('should provide the reducers to the token', () => {
31
+ reducers.forEach(reducer => {
32
+ expect(result).toContain(reducer);
33
+ });
34
+ });
35
+ });