GithubHelp home page GithubHelp logo

markheath / durable-functions-ecommerce-sample Goto Github PK

View Code? Open in Web Editor NEW
31.0 4.0 10.0 282 KB

Sample Durable Functions pipeline for processing an ecommerce order

C# 78.98% HTML 12.66% JavaScript 8.36%

durable-functions-ecommerce-sample's Introduction

Durable Functions E-Commerce Sample

In this sample application, when an order webhook is received (by the NewPurchaseWebhook function), we initiate an order processing workflow.

  • First, it stores a new row in our "database" (using Azure Table storage for simplicity).
  • Second, it requests approval if the value of the order is greater than a certain amount. This involves sending an email to an administrator and them using the "management" web-page to approve or reject the order.
  • Then in parallel it creates a 'PDF' (actually just text file) for each item ordered in a blob storage account and generates SAS tokens to download them.
  • Finally, it sends out an email to the purchaser containing the download SAS tokens.
    • (note you need your own SendGrid API key to actually send emails - use a key of "TEST" to avoid attempting to send emails)

Local Application Settings

To run the application locally, you'll need to set up your local.settings.json file, which is not checked into source control. An example is shown below:

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "SendGridKey": "<<your sendgrid API key here>>",
        "ApproverEmail": "[email protected]",
        "SenderEmail": "[email protected]",
        "Host": "http://localhost:7071",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    },
    "Host": {
        "CORS": "*"
    }
}

Using mailinator for testing and demos:

Running in the cloud

  • You need to run the static website (can run anywhere - Azure App Service is probably easiest).
  • You need to run the
  • You will need to update baseUrl in the JavaScript files to point to the fucntion app
  • You will need the Azure Function app to accept CORS requests from the website
  • You will need to set up Application Settings for the function app - SendGridKey, ApproverEmail, SenderEmail

Testing from the Web UI

Set both DurableECommerceWeb and DurableECommerceWorkflow projects as startup projects

Visiting https://localhost:5001/ will take you to a page where you can add items to your shopping cart and create an order.

By visiting https://localhost:5001/orderStatus.html?id=<orderId> you can view the current status of the order.

And visiting https://localhost:5001/admin takes you to an order management dashboard that lets administrators approve or reject orders for large amounts, as well as purge order history for completed orders.

Testing from PowerShell

Calling the starter function from PowerShell:

$orderInfo = "{ items: [{productId: 'azure-functions', amount:24}], purchaserEmail:'[email protected]' }"
$webhookUri = "http://localhost:7071/api/NewPurchaseWebhook"
$statusUris = Invoke-RestMethod -Method Post -Body $orderInfo -Uri $webhookUri

# check the status of the workflow
Invoke-RestMethod -Uri $statusUris.StatusQueryGetUri

To simulate an error in PDF generation, use:

$orderInfoErr = "{ items: [{productId: 'error', amount:24}], purchaserEmail:'[email protected]' }"

To simulate an order needing approval, use:

$orderInfo = "{ items: [{productId: 'durable-functions', amount:3000}], purchaserEmail:'[email protected]' }"

To send an approval to a specific orchestration:

function Approve-Order {
    Param ([String]$orchestrationId)
    $approvalResult = "{ orchestrationId: '" + $orchestrationId + "', approved:true }"
    $approveOrderUri = "http://localhost:7071/api/ApproveOrder"
    Invoke-RestMethod -Method Post -Body $approvalResult -Uri $approveOrderUri
}
Approve-Order -orchestrationId <<your-orchestration-id>>

durable-functions-ecommerce-sample's People

Contributors

markheath avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

durable-functions-ecommerce-sample's Issues

DurableECommerceWorkflowIsolated doesn't work

I created the local.settings.json file as per the example and tried to start the DurableECommerceWorkflowIsolated project but it doesn't work.

This is the error displayed:
Microsoft.Azure.WebJobs.Host: The host has not yet started.
Value cannot be null. (Parameter 'provider')

P.s. I really like this project ๐Ÿ’ฏ

GetAllOrders - GetStatusAsync obsolete

Hi, I'm trying your code and everything works, but at GetAllOrders function in visual studio I get the message that

var statuses = await client.GetStatusAsync(DateTime.Today.AddHours(-2.0), null, Enum.GetValues(typeof(OrchestrationRuntimeStatus)).Cast<OrchestrationRuntimeStatus>());

is obsolete. How do I fix? Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.