Skip to main content

Create Strategy

To create a Strategy first, you need to know some necessary flows that will be aligned with the business area:

  1. What services will be used?
  2. Which endpoints of each service will be consumed?
  3. What data does each endpoint need to be consumed?
  4. What is the sequence of each service endpoint that needs to be called?
  5. Is it necessary to consume a sequence of services for every new instance?
  6. Is it necessary to consume a sequence of services when canceling an instance?
  7. What is the periodicity of the strategy execution? (Monthly? Trimestraly? Annually?)
  8. Which steps should be retried due to an error?
  9. How many times does it need to be retried before being canceled?
  10. Should retried failed steps cancel or pause the subscription?

So those and more questions have to be discussed with the business area before begin creating the Strategy document.

To create a strategy isn’t necessary to send the Strategy-Secret header.

InformationDataDescription
URL-Provided by boltPay squad
Endpoint/execution-strategy-
MethodPOST-
Bodyapplication/jsonname: The strategy name, should be a slug name or kebab case, as strategy-name, another-name.
description: The strategy description.
secret: The strategy passphrase that will be used to match the orther requests with the Strategy-Secret header. Different from the Strategy-Secret header the secret is not base64 encoded.
settings: The strategy details: services details to be consumed, flows mapped, schedules configured, and more.

Request

POST /execution-strategy

Headers: { Content-Type: application/json, Authorization: Bearer asd123asdfd123.asdasd123.asda13213 }

{
"name": "strategy-name",
"description": "Execution strategy for Device Protection, using Subscription Service v3",
"secret": "ex@mpl3_oF_c0MpL3xY_P@as5",
"settings": {
"config": {
"timezone": "Europe/Lisbon"
},
"instanceValidation": {
"type": "object",
"properties": {
"service_contract_number": {
"type": "string",
"minLength": 1
},
"recurring_id": {
"type": "string",
"minLength": 1
}
},
"required": ["service_contract_number", "recurring_id"],
"additionalProperties": true
},
"schedule": {
"calendars": [
{
"key": "flow",
"task": "execute-flow",
"scheduleAfter": {
"unit": "months",
"amount": 1,
"resetTo": {
"hour": 12,
"minute": 0
}
}
}
]
},
"services": [
{
"key": "crmz",
"baseUrls": [
{
"environment": "development",
"url": "http://localhost:3000/crmz"
}
],
"authorization": [
{
"environment": "development",
"url": "http://localhost:3001/auth",
"headers": {
"content-type": "application/json"
},
"data": {
"grant_type": "client_credentials",
"client_id": "1234",
"client_secret": "qweasd123321dsaewq"
},
"noCache": true
}
],
"credentialPath": "access_token",
"credentialType": "bearer",
"methods": [
{
"key": "crmz-renewal",
"url": "/order/renewal",
"method": "post"
},
{
"key": "get-payment-info",
"url": "/order?partner_code=LBDEVPROEMANA01",
"method": "get"
},
{
"key": "create-payment-info",
"url": "/integration/payment-notification",
"method": "post"
},
{
"key": "get-contract-info",
"url": "/contract/service_contract/list",
"method": "post",
"responseValidation": {
"type": "object",
"required": ["result"],
"additionalProperties": true,
"properties": {
"result": {
"type": "array",
"minItems": 1,
"items": [
{
"type": "object",
"required": ["service_contract_status"],
"additionalProperties": true,
"properties": {
"service_contract_status": {
"const": "Active"
}
}
}
]
}
}
}
},
{
"key": "update-partner-contract-id",
"url": "/contract/customercontracts?partner_code=LBDEVPROEMANA01&partner_contract_number={service_contract_number}",
"method": "put"
}
]
},
{
"key": "crmz-notification",
"baseUrls": [
{
"environment": "development",
"url": "http://localhost:3000/crmz-notification"
}
],
"authorization": [
{
"environment": "development",
"url": "http://localhost:3000/auth",
"method": "post",
"headers": {
"content-type": "application/json",
"bolt-country-code": "PT"
},
"data": {
"userName": "test",
"password": "ex@mpl3"
}
}
],
"credentialPath": "jwtToken.accessToken",
"credentialType": "Bearer",
"methods": [
{
"key": "send-subscription-cancelled-email",
"url": "/integration/subscription/notification?partner_code=LBDEVPROEMANA01&template_id=sambenub-policy-cancelled",
"method": "post"
},
{
"key": "send-payment-failure-email",
"url": "/integration/subscription/notification?partner_code=LBDEVPROEMANA01&template_id=sambenub-payment-failed",
"method": "post"
}
]
},
{
"key": "payment-gateway",
"baseUrls": [
{
"environment": "development",
"url": "http://localhost:3000/payment-gateway"
}
],
"authorization": [
{
"environment": "development",
"url": "http://localhost:3000/auth",
"method": "post",
"headers": {
"content-type": "application/x-www-form-urlencoded"
},
"data": {
"client_id": "123",
"client_secret": "asdzxcqwe123ase",
"grant_type": "client_credentials",
"scope": "openid accountId username roles permissions status entityUser"
}
}
],
"credentialPath": "access_token",
"methods": [
{
"key": "execute-payment",
"url": "/recurring/{recurring_id}",
"method": "post",
"responseValidation": {
"type": "object",
"required": ["result", "status"],
"additionalProperties": true,
"properties": {
"status": {
"const": true
},
"result": {
"type": "object",
"required": ["success", "status", "paymentId"],
"additionalProperties": true,
"properties": {
"success": {
"const": true
},
"status": {
"enum": ["CONFIRMED", "PRE_AUTHORIZED"]
},
"paymentId": {
"type": "string",
"minLength": 1
}
}
}
}
}
}
]
}
],
"tasks": [
{
"key": "execute-flow",
"retryConfig": {
"times": 6,
"pauseBeforeCancel": true,
"retryAfter": {
"unit": "minutes",
"amount": 30
}
},
"steps": [
{
"key": "validate-contract-step",
"action": "validate-contract-action",
"repeatOnRetry": true,
"nextStep": "validate-payment-step"
},
{
"key": "validate-payment-step",
"action": "validate-payment-action",
"repeatOnRetry": true,
"nextStep": "execute-payment-step"
},
{
"key": "execute-payment-step",
"action": "execute-payment-action",
"retryConfig": {
"times": 3,
"pauseBeforeCancel": true,
"retryAfter": {
"unit": "days",
"amount": 24,
"retryEventCallback": "(context) => {\n return context.step.retryConfig.retryStrategy[context.event.attempt - 1]; \n}",
"resetTo": {
"hour": 12,
"minute": 0
}
},
"retryStrategy": [
{
"unit": "days",
"amount": 4
},
{
"unit": "days",
"amount": 10
},
{
"unit": "days",
"amount": 9
}
]
},
"nextStep": "create-payment-info-success-step",
"nextStepRules": [
{
"if": "onBeforeRetry",
"nextStep": "payment-failure-email-step"
},
{
"if": "onBeforePause",
"nextStep": "crmz-update-contract-onhold-step"
}
]
},
{
"key": "create-payment-info-success-step",
"action": "crmz-payment-result-action",
"nextStep": "crmz-renewal-step"
},
{
"key": "crmz-renewal-step",
"action": "crmz-renewal-action",
"nextStep": "crmz-update-contract-active-step"
},
{
"key": "crmz-update-contract-active-step",
"action": "crmz-update-contract-active-action",
"final": true
},
{
"key": "payment-failure-email-step",
"action": "payment-failure-email-action",
"nextStep": "create-payment-info-fail-step"
},
{
"key": "crmz-update-contract-onhold-step",
"action": "crmz-update-contract-onhold-action",
"nextStep": "create-payment-info-fail-step"
},
{
"key": "create-payment-info-fail-step",
"action": "crmz-payment-result-action",
"final": true
}
],
"initialStep": "validate-contract-step"
}
],
"actions": [
{
"key": "validate-contract-action",
"service": "crmz",
"method": "get-contract-info",
"headers": {
"content-type": "application/json",
"bolt-country-code": "PT",
"bolt-tenant-id": "00000000-1a10-1234-12ab-1a2b3c4d5e6f",
"bolt-language-code": "EN"
},
"params": {
"policyNumber": "{instance.attributes.service_contract_number}"
},
"data": {
"service_contract_number": "{instance.attributes.service_contract_number}"
}
},
{
"key": "validate-payment-action",
"service": "crmz",
"method": "get-payment-info",
"headers": {
"content-type": "application/json",
"bolt-country-code": "PT",
"bolt-tenant-id": "00000000-1a10-1234-12ab-1a2b3c4d5e6f",
"bolt-language-code": "EN"
},
"params": {
"order_id": "{instance.attributes.order_id}"
}
},
{
"key": "execute-payment-action",
"service": "payment-gateway",
"method": "execute-payment",
"headers": {
"content-type": "application/json"
},
"attributes": {
"recurring_id": "{stack.validate-payment-step.recurring_id}"
},
"data": {
"paymentAccount": "recurring-account",
"callbackBackendEndpoint": "",
"callbackFrontendEndpoint": "",
"amount": "(context, helper) => { return lodash.get(context.stack, 'validate-payment-step.amount').replace('.','').padStart(12, '0');}"
}
},
{
"key": "crmz-renewal-action",
"service": "crmz",
"method": "crmz-renewal",
"headers": {
"content-type": "application/json",
"bolt-country-code": "PT",
"bolt-tenant-id": "00000000-1a10-1234-12ab-1a2b3c4d5e6f",
"bolt-language-code": "EN"
},
"data": {
"product_id": "(context, helper) => { return lodash.get(context.stack, 'validate-contract-step.result.0.product_id');}",
"plan_id": "(context, helper) => { return lodash.get(context.stack, 'validate-contract-step.result.0.plan_id');}",
"partner_code": "LBDEVPROEMANA01",
"billing_cycle": "{instance.cycle}",
"service_contract_number": "(context, helper) => { return lodash.get(context.stack, 'validate-contract-step.result.0.service_contract_number');}",
"payment_transaction_id": "{stack.execute-payment-step.result.paymentId}",
"payment_currency": "EUR",
"payment_amount": "{stack.execute-payment-step.result.amount}",
"payment_timestamp": "(context, helper) => { return new Date();null; }"
}
},
{
"key": "crmz-update-contract-onhold-action",
"service": "crmz",
"method": "update-partner-contract-id",
"headers": {
"content-type": "application/json",
"bolt-country-code": "PT",
"bolt-tenant-id": "00000000-1a10-1234-12ab-1a2b3c4d5e6f",
"bolt-language-code": "EN"
},
"data": {
"customer_contract_status": "OnHold"
},
"attributes": {
"service_contract_number": "{instance.attributes.service_contract_number}"
}
},
{
"key": "crmz-update-contract-active-action",
"service": "crmz",
"method": "update-partner-contract-id",
"headers": {
"content-type": "application/json",
"bolt-country-code": "PT",
"bolt-tenant-id": "00000000-1a10-1234-12ab-1a2b3c4d5e6f",
"bolt-language-code": "EN"
},
"data": {
"customer_contract_status": "Active"
},
"attributes": {
"service_contract_number": "{instance.attributes.service_contract_number}"
}
},
{
"key": "crmz-payment-result-action",
"service": "crmz",
"method": "create-payment-info",
"headers": {
"content-type": "application/json",
"bolt-country-code": "PT",
"bolt-tenant-id": "00000000-1a10-1234-12ab-1a2b3c4d5e6f",
"bolt-language-code": "EN"
},
"data": {
"success": "{stack.execute-payment-step.result.success}",
"status": "{stack.execute-payment-step.result.status}",
"invoiceNumber": "{stack.execute-payment-step.result.invoiceNumber}",
"provider": {
"returnCode": "{stack.execute-payment-step.result.provider.returnCode}",
"message": "{stack.execute-payment-step.result.provider.message}"
},
"billing_cycle": "{instance.cycle}",
"customFields1": "{instance.attributes.order_id}",
"paymentId": "{stack.execute-payment-step.result.paymentId}",
"currencyCode": "{stack.execute-payment-step.result.currencyCode}",
"amount": "{stack.execute-payment-step.result.amount}",
"paymentMethod": "{stack.execute-payment-step.result.paymentMethod}"
}
},
{
"key": "payment-failure-email-action",
"service": "crmz-notification",
"method": "send-payment-failure-email",
"headers": {
"content-type": "application/json"
},
"data": {
"service_contract_number": "{instance.attributes.service_contract_number}"
}
},
{
"key": "create-payment-info-action",
"service": "crmz",
"method": "create-payment-info",
"headers": {
"content-type": "application/json",
"bolt-country-code": "PT",
"bolt-tenant-id": "00000000-1a10-1234-12ab-1a2b3c4d5e6f",
"bolt-language-code": "EN"
},
"data": {
"order_id": "{instance.attributes.order_id}",
"partner_code": "LBDEVPROEMANA01",
"service_contract_number": "{instance.attributes.service_contract_number}",
"billing_cycle": "{instance.cycle}",
"payment_amount": "{stack.execute-payment-step.result.amount}",
"payment_timestamp": "(context, helper) => { return new Date(); }",
"payment_status": "{stack.execute-payment-step.result.status}",
"payment_invoice_number": "{stack.execute-payment-step.result.invoiceNumber}",
"payment_transaction_id": "{stack.execute-payment-step.result.paymentId}",
"payment_currency": "EUR"
}
},
{
"key": "subscription-cancelled-email-action",
"service": "crmz-notification",
"method": "send-subscription-cancelled-email",
"headers": {
"content-type": "application/json"
},
"data": {
"service_contract_number": "{instance.attributes.service_contract_number}"
}
}
]
}
}

Response

{
"version": 1,
"description": "Execution strategy for Device Protection, using Subscription Service v3",
"name": "strategy-name",
"sid": "7b75ce51-bb2a-4fe2-9008-ecc5b257dfd8",
"createdAt": "2024-06-04T10:15:16.046Z"
}