Skip to content

Commit

Permalink
Merge pull request #300 from commercetools/prepare_4.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmetoz authored Jun 3, 2020
2 parents 633c863 + 76098d2 commit ab86a45
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 100 deletions.
2 changes: 1 addition & 1 deletion extension/docs/DevelopmentAndDeploymentGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ with the UI (e.g. credit card 3ds). In such cases, we use Cypress.io. Run `npm r

For deployment to lambda zip the extensions folder and specify `src/lambda.handler` as the entry point for the function

When deploying the lambda, it will NOT create the custom types for you. These are required for the extension to operate correctly. Please add [payment custom types](../resources/payment-custom-types.json) and [payment interface interaction types](../resources/payment-interface-interaction-types.json) manually.
When deploying the lambda, it will NOT create the custom types for you. These are required for the extension to operate correctly. Please add [payment custom types](../resources/payment-custom-type.json) and [payment interface interaction types](../resources/payment-interface-interaction-type.json) manually.
You can create these by running the command `npm run create-custom-types` and providing the `CTP_PROJECT_KEY`, `CTP_CLIENT_ID` and `CTP_CLIENT_SECRET` environment variables.

Example command (bash): `CTP_PROJECT_KEY="project_key" CTP_CLIENT_ID="client_id" CTP_CLIENT_SECRET="client_secret" npm run create-custom-types`
Expand Down
4 changes: 2 additions & 2 deletions extension/docs/IntegrationGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ Other used terms in the documentation:
## Requirements for CTP project
All the requirements below are automatically created by the Extension module.
1. [API Extension subscription to Extension module endpoints](../resources/api-extension.json)
1. [Custom types for payments](../resources/payment-custom-types.json)
1. [Custom types for interface interactions](../resources/payment-interface-interaction-types.json)
1. [Custom types for payments](../resources/payment-custom-type.json)
1. [Custom types for interface interactions](../resources/payment-interface-interaction-type.json)

**Note**: Extension module will not create if there are already resources with same key in the CTP project. In this case, you have to synchronize by yourself.

Expand Down
77 changes: 77 additions & 0 deletions extension/resources/payment-interface-interaction-type.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"key": "ctp-adyen-integration-interaction",
"name": {
"en": "ctp-adyen-integration-interaction"
},
"resourceTypeIds": [
"payment-interface-interaction"
],
"fieldDefinitions": [
{
"name": "createdAt",
"label": {
"en": "createdAt"
},
"required": true,
"type": {
"name": "DateTime"
},
"inputHint": "SingleLine"
},
{
"name": "transactionId",
"label": {
"en": "transactionId"
},
"required": false,
"type": {
"name": "String"
},
"inputHint": "SingleLine"
},
{
"name": "request",
"label": {
"en": "request"
},
"required": true,
"type": {
"name": "String"
},
"inputHint": "MultiLine"
},
{
"name": "response",
"label": {
"en": "response"
},
"required": true,
"type": {
"name": "String"
},
"inputHint": "MultiLine"
},
{
"name": "type",
"label": {
"en": "type"
},
"required": true,
"type": {
"name": "String"
},
"inputHint": "SingleLine"
},
{
"name": "status",
"label": {
"en": "status"
},
"required": false,
"type": {
"name": "String"
},
"inputHint": "SingleLine"
}
]
}
79 changes: 0 additions & 79 deletions extension/resources/payment-interface-interaction-types.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
const Promise = require('bluebird')
const utils = require('../../utils')
const interfaceInteractionType = require('../../../resources/payment-interface-interaction-type.json')

const interfaceInteractionTypes = require('../../../resources/payment-interface-interaction-types.json')
const utils = require('../../utils')

const logger = utils.getLogger()

async function ensureInterfaceInteractionCustomType (ctpClient) {
await Promise.map(interfaceInteractionTypes, async (type) => {
try {
const { body } = await ctpClient.fetch(ctpClient.builder.types.where(`key="${type.key}"`))
if (body.results.length === 0) {
await ctpClient.create(ctpClient.builder.types, type)
logger.info('Successfully created an interfaceInteraction type')
}
} catch (e) {
logger.error(e, 'Error when creating interface interaction custom type, skipping...')
try {
const { body } = await ctpClient.fetch(ctpClient.builder.types.where(`key="${interfaceInteractionType.key}"`))
if (body.results.length === 0) {
await ctpClient.create(ctpClient.builder.types, interfaceInteractionType)
logger.info('Successfully created an interfaceInteraction type')
}
}, { concurrency: 3 })
} catch (e) {
logger.error(e, 'Error when creating interface interaction custom type, skipping...')
}
}

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion extension/src/config/init/ensure-payment-custom-type.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const paymentCustomType = require('../../../resources/payment-custom-types.json')
const paymentCustomType = require('../../../resources/payment-custom-type.json')

const utils = require('../../utils')

Expand Down
2 changes: 1 addition & 1 deletion extension/src/config/init/ensure-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function ensureCustomTypes () {
}

function ensureResources () {
let config = configLoader.load()
const config = configLoader.load()
if (!config.ensureResources) return Promise.resolve()
return Promise.all([
ensureCustomTypes(),
Expand Down
6 changes: 4 additions & 2 deletions extension/src/lambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ exports.handler = async function (event) {

return {
responseType: paymentResult.success ? 'UpdateRequest' : 'FailedValidation',
errors: paymentResult.data.errors,
actions: paymentResult.data.actions
// Null check around paymentResult.data,
// which can be null if paymentHandler short circuits when not an adyen payment
errors: paymentResult.data ? paymentResult.data.errors : undefined,
actions: paymentResult.data ? paymentResult.data.actions : undefined
}
} catch (e) {
logger.error(e, `Unexpected error when processing event ${JSON.stringify(event)}`)
Expand Down
10 changes: 10 additions & 0 deletions extension/test/unit/lambda.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ describe('Lambda handler', () => {
expect(result.actions).to.equal(undefined)
})

it('does not throw unhandled exception when handlePayment data is null', async () => {
sinon.stub(paymentHandler, 'handlePayment').returns({ success: true, data: null })

const result = await handler(event)

expect(result.responseType).equals('UpdateRequest')
expect(result.errors).equals(undefined)
expect(result.actions).to.equal(undefined)
})

it('logs and throws unhandled exceptions', async () => {
const logSpy = sinon.spy()
utils.getLogger().error = logSpy
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const paymentCustomType = require('../../resources/payment-custom-types.json')
const paymentCustomType = require('../../resources/payment-custom-type.json')

const utils = require('../../../src/utils/logger')

Expand Down

0 comments on commit ab86a45

Please sign in to comment.