Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(payment): Make payment catalog mockable eliminating reliance on fjs #16471

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions libs/application/template-api-modules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,7 @@ import { SharedApi } from '@island.is/application/types'

## Enabling payment mocking

To enable payment mocking on dev and local you need to add `enableMockPayment: true` to the arguments object passed to the
`buildExternalDataProvider` function when constructing your `approveExternalData` field.
To enable payment mocking on dev and local you need to replace the `PaymentCatalogApi` with `MockablePaymentCatalogApi` in your application. You also need to make sure to update your template in the same manner

A simple example of this can be found in `libs/application/templates/example-payment/src/forms/draft.ts`

Expand All @@ -423,15 +422,49 @@ buildExternalDataProvider({
id: 'approveExternalData',
subTitle: m.draft.externalDataTitle,
checkboxLabel: m.draft.externalDataTitle,
enableMockPayment: true,
dataProviders: [
buildDataProviderItem({
provider: PaymentCatalogApi,
provider: MockablePaymentCatalogApi,
title: m.draft.feeInfo,
}),
],
}),

```

and `libs/application/templates/example-payment/src/lib/examplePaymentTemplate.ts`

```typescript
[States.DRAFT]: {
meta: {
status: 'draft',
name: 'Draft',
progress: 0.4,
lifecycle: EphemeralStateLifeCycle,
roles: [
{
id: Roles.APPLICANT,
formLoader: async () => (await import('../forms/draft')).draft,
actions: [
{
event: DefaultEvents.PAYMENT,
name: m.payUp,
type: 'primary',
},
],
write: 'all',
read: 'all',
api: [MockablePaymentCatalogApi, PaymentCatalogApi],
delete: true,
},
],
},
on: {
[DefaultEvents.PAYMENT]: {
target: States.PAYMENT,
},
},
},
```

This will cause a checkbox saying "Enable mock payment" to be shown that if checked will cause the payment step to be skipped.
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,46 @@ export class PaymentService extends BaseTemplateApiService {
}: TemplateApiModuleActionProps<PaymentCatalogParameters>): Promise<
PaymentCatalogItem[]
> {
if (!params?.organizationId) {
throw Error('Missing performing organization ID')
const { enableMockPayment } = application.externalData

if (enableMockPayment.data) {
return [
{
performingOrgID: params?.organizationId ?? 'string',
chargeType: 'string',
chargeItemCode: 'Payment',
chargeItemName: 'Mock',
priceAmount: 123123,
},
]
} else {
if (!params?.organizationId) {
throw Error('Missing performing organization ID')
}
const data =
await this.chargeFjsV2ClientService.getCatalogByPerformingOrg(
params.organizationId,
)

return data.item
}
const data = await this.chargeFjsV2ClientService.getCatalogByPerformingOrg(
params.organizationId,
)
}

return data.item
async mockPaymentCatalog({
params,
application,
}: TemplateApiModuleActionProps<PaymentCatalogParameters>): Promise<
PaymentCatalogItem[]
> {
return [
{
performingOrgID: params?.organizationId ?? 'string',
chargeType: 'string',
chargeItemCode: 'Payment',
chargeItemName: 'Mock',
priceAmount: 123123,
},
]
}

async createCharge({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
InstitutionNationalIds,
MockablePaymentCatalogApi,
PaymentCatalogApi,
defineTemplateApi,
} from '@island.is/application/types'
Expand All @@ -18,6 +19,14 @@ export const UtlendingastofnunPaymentCatalogApi = PaymentCatalogApi.configure({
externalDataId: 'payment',
})

export const MockableUtlendingastofnunPaymentCatalogApi =
MockablePaymentCatalogApi.configure({
params: {
organizationId: InstitutionNationalIds.UTLENDINGASTOFNUN,
},
externalDataId: 'payment',
})

export const ApplicantInformationApi = defineTemplateApi({
action: ApiActions.applicantInformation,
externalDataId: 'applicantInformation',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import {
NationalRegistrySpouseDetailsApi,
ResidenceInIcelandLastChangeDateApi,
UserProfileApi,
UtlendingastofnunPaymentCatalogApi,
TravelDocumentTypesApi,
ApplicantInformationApi,
MockableUtlendingastofnunPaymentCatalogApi,
} from '../../dataProviders'

export const Prerequisites: Form = buildForm({
Expand All @@ -46,7 +46,6 @@ export const Prerequisites: Form = buildForm({
subTitle: externalData.dataProvider.subTitle,
description: externalData.dataProvider.description,
checkboxLabel: externalData.dataProvider.checkboxLabel,
enableMockPayment: true,
submitField: buildSubmitField({
id: 'submit',
placement: 'footer',
Expand Down Expand Up @@ -108,7 +107,7 @@ export const Prerequisites: Form = buildForm({
title: '',
}),
buildDataProviderItem({
provider: UtlendingastofnunPaymentCatalogApi,
provider: MockableUtlendingastofnunPaymentCatalogApi,
title: '',
}),
buildDataProviderItem({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { ApiActions } from '../shared'
import { CitizenshipSchema } from './dataSchema'
import {
UserProfileApi,
UtlendingastofnunPaymentCatalogApi,
ChildrenCustodyInformationApi,
NationalRegistryParentsApi,
NationalRegistrySpouseDetailsApi,
Expand All @@ -33,6 +32,7 @@ import {
CountriesApi,
TravelDocumentTypesApi,
ApplicantInformationApi,
MockableUtlendingastofnunPaymentCatalogApi,
} from '../dataProviders'
import { buildPaymentState } from '@island.is/application/utils'
import { getChargeItemCodes } from '../utils'
Expand Down Expand Up @@ -93,7 +93,7 @@ const template: ApplicationTemplate<
UserProfileApi,
ResidenceInIcelandLastChangeDateApi,
CountriesApi,
UtlendingastofnunPaymentCatalogApi,
MockableUtlendingastofnunPaymentCatalogApi,
ApplicantInformationApi,
TravelDocumentTypesApi,
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
defineTemplateApi,
InstitutionNationalIds,
MockablePaymentCatalogApi,
PaymentCatalogApi,
} from '@island.is/application/types'
export {
Expand All @@ -21,6 +22,14 @@ export const SyslumadurPaymentCatalogApi = PaymentCatalogApi.configure({
externalDataId: 'payment',
})

export const MockableSyslumadurPaymentCatalogApi =
MockablePaymentCatalogApi.configure({
params: {
organizationId: InstitutionNationalIds.SYSLUMENN,
},
externalDataId: 'payment',
})

export const GlassesCheckApi = defineTemplateApi({
action: 'glassesCheck',
})
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from '@island.is/application/types'
import {
GlassesCheckApi,
MockableSyslumadurPaymentCatalogApi,
SyslumadurPaymentCatalogApi,
} from '../../dataProviders'
export const sectionExternalData = buildSubSection({
Expand All @@ -27,7 +28,6 @@ export const sectionExternalData = buildSubSection({
id: 'approveExternalData',
subTitle: m.externalDataSubTitle,
checkboxLabel: m.externalDataAgreement,
enableMockPayment: true,
dataProviders: [
buildDataProviderItem({
provider: NationalRegistryUserApi,
Expand Down Expand Up @@ -63,7 +63,7 @@ export const sectionExternalData = buildSubSection({
title: '',
}),
buildDataProviderItem({
provider: SyslumadurPaymentCatalogApi,
provider: MockableSyslumadurPaymentCatalogApi,
title: '',
}),
norda-gunni marked this conversation as resolved.
Show resolved Hide resolved
buildDataProviderItem({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ import {
} from './getApplicationFeatureFlags'
import { m } from './messages'
import { hasCompletedPrerequisitesStep } from './utils'
import { GlassesCheckApi, SyslumadurPaymentCatalogApi } from '../dataProviders'
import {
GlassesCheckApi,
MockableSyslumadurPaymentCatalogApi,
} from '../dataProviders'
import { buildPaymentState } from '@island.is/application/utils'

const getCodes = (application: Application) => {
Expand Down Expand Up @@ -146,7 +149,7 @@ const template: ApplicationTemplate<
NationalRegistryUserApi,
TeachersApi,
UserProfileApi,
SyslumadurPaymentCatalogApi,
MockableSyslumadurPaymentCatalogApi,
GlassesCheckApi,
JurisdictionApi,
CurrentLicenseApi.configure({
Expand Down
Loading
Loading