-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(authorizenet): create injection tokens with factory (#3234)
- Loading branch information
Showing
10 changed files
with
88 additions
and
85 deletions.
There are no files selected for viewing
7 changes: 5 additions & 2 deletions
7
libs/authorizenet/driver/src/interfaces/authorize-net-config.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 5 additions & 2 deletions
7
libs/authorizenet/driver/src/interfaces/authorize-net-payment-id.token.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import { InjectionToken } from '@angular/core'; | ||
import { createSingleInjectionToken } from '@daffodil/core'; | ||
|
||
export const DaffAuthorizeNetPaymentId = new InjectionToken<string>('DaffAuthorizeNetPaymentId'); | ||
export const { | ||
token: DaffAuthorizeNetPaymentId, | ||
provider: daffProvideAuthorizeNetPaymentId, | ||
} = createSingleInjectionToken<string>('DaffAuthorizeNetPaymentId'); |
7 changes: 5 additions & 2 deletions
7
libs/authorizenet/driver/src/interfaces/authorize-net-service.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 8 additions & 5 deletions
13
libs/authorizenet/driver/src/interfaces/payment-service.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 17 additions & 13 deletions
30
libs/authorizenet/src/services/accept-js-production.token.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
import { InjectionToken } from '@angular/core'; | ||
import { createSingleInjectionToken } from '@daffodil/core'; | ||
|
||
/** | ||
* A token that represents the version to use for Accept.JS calls. | ||
* A "true" value configures the package to use the production AcceptJs endpoint, | ||
* and a "false" value configures it to use the Sandbox AcceptJs endpoint. | ||
* By default, we assume you're using the sandbox (false). | ||
*/ | ||
export const DAFF_AUTHORIZENET_ACCEPT_JS_PRODUCTION = new InjectionToken< | ||
boolean | ||
>('DAFF_AUTHORIZENET_ACCEPT_JS_PRODUCTION', { | ||
providedIn: 'root', | ||
factory: () => false, | ||
}); | ||
export const { | ||
/** | ||
* A token that represents the version to use for Accept.JS calls. | ||
* A "true" value configures the package to use the production AcceptJs endpoint, | ||
* and a "false" value configures it to use the Sandbox AcceptJs endpoint. | ||
* By default, we assume you're using the sandbox (false). | ||
*/ | ||
token: DAFF_AUTHORIZENET_ACCEPT_JS_PRODUCTION, | ||
provider: daffProvideAuthorizenetAcceptJsProduction, | ||
} = createSingleInjectionToken<boolean>( | ||
'DAFF_AUTHORIZENET_ACCEPT_JS_PRODUCTION', | ||
{ | ||
providedIn: 'root', | ||
factory: () => false, | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,9 @@ | ||
import { | ||
InjectionToken, | ||
ValueProvider, | ||
} from '@angular/core'; | ||
import { createConfigInjectionToken } from '@daffodil/core'; | ||
|
||
import { daffAuthorizeNetStateDefaultConfig } from './default'; | ||
import { DaffAuthorizeNetStateConfig } from './type'; | ||
|
||
export const DAFF_AUTHORIZE_NET_STATE_CONFIG = new InjectionToken('DAFF_AUTHORIZE_NET_STATE_CONFIG', { factory: () => daffAuthorizeNetStateDefaultConfig }); | ||
|
||
export const provideDaffAuthorizeNetStateConfig = (config: DaffAuthorizeNetStateConfig): ValueProvider => ({ | ||
provide: DAFF_AUTHORIZE_NET_STATE_CONFIG, | ||
useValue: config, | ||
}); | ||
export const { | ||
token: DAFF_AUTHORIZE_NET_STATE_CONFIG, | ||
provider: provideDaffAuthorizeNetStateConfig, | ||
} = createConfigInjectionToken<DaffAuthorizeNetStateConfig>(daffAuthorizeNetStateDefaultConfig, 'DAFF_AUTHORIZE_NET_STATE_CONFIG'); |
8 changes: 5 additions & 3 deletions
8
libs/authorizenet/state/src/injection-tokens/error-matcher.token.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import { InjectionToken } from '@angular/core'; | ||
|
||
import { createSingleInjectionToken } from '@daffodil/core'; | ||
import { daffTransformErrorToStateError } from '@daffodil/core/state'; | ||
|
||
/** | ||
* Transforms `DaffError`s into `DaffStateError`s before they are serialized into state. | ||
* Can be used to further refine Daffodil errors into more specific app errors. | ||
*/ | ||
export const DAFF_AUTHORIZENET_ERROR_MATCHER = new InjectionToken<typeof daffTransformErrorToStateError>( | ||
export const { | ||
token: DAFF_AUTHORIZENET_ERROR_MATCHER, | ||
provider: daffProvideAuthorizenetErrorMatcher, | ||
} = createSingleInjectionToken<typeof daffTransformErrorToStateError>( | ||
'DAFF_AUTHORIZENET_ERROR_MATCHER', | ||
{ factory: () => daffTransformErrorToStateError }, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { DAFF_AUTHORIZENET_ERROR_MATCHER } from './error-matcher.token'; | ||
export * from './error-matcher.token'; |
61 changes: 25 additions & 36 deletions
61
libs/authorizenet/state/src/reducers/token/extra.token.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,31 @@ | ||
import { | ||
InjectionToken, | ||
Provider, | ||
} from '@angular/core'; | ||
import { ActionReducer } from '@ngrx/store'; | ||
|
||
import { createMultiInjectionToken } from '@daffodil/core'; | ||
|
||
import { DaffAuthorizeNetReducersState } from '../authorize-net-reducers.interface'; | ||
|
||
/** | ||
* A token to hold the injectable extra reducers. | ||
* | ||
* Prefer using {@link daffAuthorizeNetProvideExtraReducers}. | ||
*/ | ||
export const DAFF_AUTHORIZE_NET_EXTRA_REDUCERS = new InjectionToken<ActionReducer<DaffAuthorizeNetReducersState>[]>( | ||
export const { | ||
/** | ||
* A token to hold the injectable extra reducers. | ||
* | ||
* Prefer using {@link daffAuthorizeNetProvideExtraReducers}. | ||
*/ | ||
token: DAFF_AUTHORIZE_NET_EXTRA_REDUCERS, | ||
|
||
/** | ||
* Provides additional reducers that run after the standard Daffodil authorizenet reducers. | ||
* | ||
* ```ts | ||
* providers: [ | ||
* ...daffAuthorizeNetProvideExtraReducers( | ||
* myReducer1, | ||
* myReducer2 | ||
* ) | ||
* ] | ||
* ``` | ||
*/ | ||
provider: daffAuthorizeNetProvideExtraReducers, | ||
} = createMultiInjectionToken<ActionReducer<DaffAuthorizeNetReducersState>>( | ||
'DAFF_AUTHORIZE_NET_EXTRA_REDUCERS', | ||
{ | ||
factory: () => [], | ||
providedIn: 'any', | ||
}, | ||
{ providedIn: 'any' }, | ||
); | ||
|
||
/** | ||
* Provides additional reducers that run after the standard Daffodil authorizenet reducers. | ||
* | ||
* ```ts | ||
* providers: [ | ||
* ...daffAuthorizeNetProvideExtraReducers( | ||
* myReducer1, | ||
* myReducer2 | ||
* ) | ||
* ] | ||
* ``` | ||
*/ | ||
export function daffAuthorizeNetProvideExtraReducers( | ||
...reducers: ActionReducer<DaffAuthorizeNetReducersState>[] | ||
): Provider[] { | ||
return reducers.map(reducer => ({ | ||
provide: DAFF_AUTHORIZE_NET_EXTRA_REDUCERS, | ||
useValue: reducer, | ||
multi: true, | ||
})); | ||
} |
23 changes: 12 additions & 11 deletions
23
libs/authorizenet/state/src/reducers/token/reducers.token.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters