| Attribute | Details |
|---|---|
| Dapr runtime version | 1.11.0 |
| Language | C# |
| Environment | Local |
An example of using Dapr Workflows with the new feature for invoking non-Dapr enabled endpoints
- .NET 7 SDK
- Dapr CLI
- Ensure that you're using v1.11 of the Dapr runtime and the CLI, since there have been breaking changes to the Workflow API from v1.10 to v1.11.
- A REST client, such as cURL, or the VSCode REST client extension (recommended).
- Square Developer account
- Navigate to the Square Developer website and click "Get started"
- If you don't already have an account, select "Sign up". Otherwise, enter existing credentials.
- Add a new application and call it
workflow-payment-appor select your own unique identifier. - Select "Skip" on the subsequent blades.
- On the Credentials page, ensure
Sandboxis selected in the top slider > findSandbox Access token> Click "show" > Copy the Access Token value. - Navigate to the directory titled "Resources" and select the "httpEndpoint.yaml" file. Replace
{SQUARE_SANDBOX_TOKEN}with the API token retrieved. - Return to the Square Developer portal and underneath the
Sandbox Access Tokensection referenced above, copy the value forSandbox API versionand replace{SQUARE_API_VERSION}in the "httpEndpoint.yaml" manifest.
Once you have completed the above steps, you are ready to connect to the Square Payment API from your Dapr Workflow!
NOTE: The application code calls out to the Square Payment API and will randomly select a failing test card or a successful test card to simulate various workflow paths.
Navigate to the Run and Debug tab and select Debug Checkout. This will launch the CheckoutService application along with the Dapr sidecar and attach a debugger.
-
Navigate to the
CheckoutServicedirectory and build the ASP.NET app:cd CheckoutService dotnet build -
Run the app using the Dapr CLI:
dapr run --app-id checkout --app-port 5000 --dapr-http-port 3500 --resources-path ../Resources dotnet run
Ensure the --app-port is the same as the port specified in the launchSettings.json file.
-
Start the
CheckoutWorkflowby sending a cURL request to the Workflow API, or use the test.rest file if you are using VSCode with the REST client:curl -i -X POST http://localhost:3500/v1.0-alpha1/workflows/dapr/CheckoutWorkflow/start?instanceID=1234a \ -H "Content-Type: application/json" \ -d '{ "Name": "TestUser", "OrderItem": { "Name": "item1", "Quantity": 4 }}'
Note that
1234ain the URL is the workflow instance ID. This can be any string you want.Expected result:
{ "instanceID": "<WORKFLOW_ID>" } -
Check the workflow status via Workflow HTTP API:
curl -i -X GET http://localhost:3500/v1.0-alpha1/workflows/dapr/1234a
The Workflow should either be "COMPLETED" with a "Payment Failed" custom status:
{ "instanceID": "50b8ce61-e6b3-416d-a33e-3cec1e7bed1f", "workflowName": "CheckoutWorkflow", "createdAt": "2023-07-29T01:29:34.337735Z", "lastUpdatedAt": "2023-07-29T01:29:44.973235Z", "runtimeStatus": "COMPLETED", "properties": { "dapr.workflow.custom_status": "\"Payment failed\"", "dapr.workflow.input": "{ \"Name\": \"TestUser\", \"OrderItem\": { \"Name\": \"Item1\", \"Quantity\": 4 } }", "dapr.workflow.output": "{\"Processed\":false}" } }OR "COMPLETED" with a "Payment Succeeded" message:
{ "instanceID": "176da304-38ea-4691-9b48-752a2f0a18ef", "workflowName": "CheckoutWorkflow", "createdAt": "2023-07-29T01:40:03.069401Z", "lastUpdatedAt": "2023-07-29T01:40:18.946546Z", "runtimeStatus": "COMPLETED", "properties": { "dapr.workflow.custom_status": "\"Checkout completed\"", "dapr.workflow.input": "{ \"Name\": \"TestUser\", \"OrderItem\": { \"Name\": \"Item1\", \"Quantity\": 4 } }", "dapr.workflow.output": "{\"Processed\":true}" } }