Skip to content

Commit 8f79a10

Browse files
committed
Merge branch 'feat/datastore-orderdesk' of github.com:Foxy/foxy-node-netlify-functions into polish/datastores
2 parents 2c8bb65 + 27cc24b commit 8f79a10

File tree

29 files changed

+15084
-12580
lines changed

29 files changed

+15084
-12580
lines changed

.eslintrc.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ module.exports = {
44
commonjs: true,
55
es2021: true,
66
},
7-
extends: "@foxy.io",
7+
extends: [
8+
"@foxy.io",
9+
"plugin:jsdoc/recommended"
10+
],
811
parserOptions: {
912
ecmaVersion: 12,
1013
},

.gitignore

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
node_modules
22
dist
33

4+
# Istanbul code coverage files and folders
5+
.nyc_output
6+
coverage
7+
8+
# ctags files
9+
tags
10+
411
# Local Netlify folder
512
.netlify
613

@@ -9,4 +16,17 @@ dist
916
.env
1017

1118
# VSCode and other editor-specific files
12-
tempCodeRunner*
19+
tempCodeRunner*
20+
21+
.idea
22+
23+
### Vim ###
24+
[._]*.s[a-v][a-z]
25+
[._]*.sw[a-p]
26+
[._]s[a-v][a-z]
27+
[._]sw[a-p]
28+
Session.vim
29+
.netrwhist
30+
*~
31+
.vimrc
32+
.vimlocal

README.md

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,66 @@
11
# Netlify Serverless Functions for the Foxy.io API
22

3-
This repository allows for easily creating serverless functions to work with the Foxy.io API, deployed using Netlify. The goal is to make this as approachable as possible, so we're avoiding unnecessary
3+
This repository allows you to (more) easily create serverless functions to work with the Foxy.io API, deployed using Netlify. The goal is to make this as approachable as possible, so we try to have reasonable default behaviours, and Netlify is a great choice because of the one-click deployment. Once you deploy to Netlify, you can modify your own GitHub files to customize as needed.
44

55
## Functions
66

7-
The functions provided in this repository can be used independently, or as a reference for building your own functinos.
8-
Be sure to check the README for each function in the functions folder.
7+
The functions provided in this repository can be used independently, or as a reference for building your own functions. Be sure to check the README for each function in the functions folder.
98

10-
- [cart](src/functions/cart): Converts a cart between recurring and non-recurring.
11-
- [idevaffiliate-marketplace](src/functions/idevaffiliate-marketplace):
12-
- [pre-payment-webhook-webflow](src/functions/pre-payment-webhook-webflow): Validates the price and/or availability of items against Webflow CMS collections before a payment is processed.
9+
- [cart](src/functions/cart): Converts a cart between recurring and non-recurring. Useful in an upsell flow.
10+
- [idevaffiliate-marketplace](src/functions/idevaffiliate-marketplace): A marketplace-style integration, using iDevAffiliate.
11+
- Datastore integrations:
12+
- [pre-payment-webhook-webflow](src/functions/pre-payment-webhook-webflow): Validates the price and/or availability of items against Webflow CMS collections before a payment is processed.
13+
- [datastore-integration-orderdesk](src/functions/datastore-integration-orderdesk): Validates the cart against OrderDesk and updates the inventory upon successful transaction.
14+
15+
### Data Store Integrations
16+
17+
Data store integrations allow you to verify the cart against a third-party Data Store.
18+
19+
Your customer workflow is basically unchanged.
20+
21+
The image below shows the order flow, with the gray steps showing the functionality provided by these functions (invisible to the customer). Notice that upon cart submit the pre-payment validation is triggered. The webhook makes a request to this function, which then gets the inventory and price information from your data store (Webflow or OrderDesk), and checks if the cart is valid.
22+
23+
![Data Store Integration workflow](https://github.com/Foxy/foxy-node-netlify-functions/blob/feat/datastore-orderdesk/images/datastore-integrations-workflow.png?raw=true)
24+
25+
- You may choose not to validate prices at all or for specific items.
26+
- You may choose not to validate the inventory.
27+
- Depending on your data store, you may have other configuration available.
28+
29+
30+
#### Available DataStores
31+
32+
- [OrderDesk](https://www.orderdesk.com)
33+
- [Webflow CMS](https://webflow.com)
34+
35+
#### The Foxy Pre-Payment Webhook
36+
37+
The pre-payment webhook fires before a transaction is submitted to the payment processor (Stripe, Authorize.net, PayPal, etc.). We'll use that with these functions to prevent overselling, and also to prevent product link/form tampering if you can't use Foxy's [link+form signing](https://wiki.foxycart.com/v/2.0/hmac_validation) (either directly or via [the Cloudflare Worker hmac signing function](https://github.com/Foxy/foxy-cloudflare-addtocart-signing) to do it automatically).
38+
39+
**It ignores existing subscriptions**. If a subscription start date is "today", the price will be checked. If it is in the past, the price is not checked.
40+
41+
#### Limitations
42+
43+
- It does not handle discounts.
44+
- It does not handle item options, such as `price_mod`.
45+
- Due to netlify time limit, and the need to make requests to the datastore, it
46+
may break against large product databases if the Datastore do not allow for
47+
requesting specific items directly. Check the README for your datastore
48+
integration about this issue.
49+
50+
#### Usage
51+
52+
1. Read the short **Configuration** section in the datastore integration page.
53+
- **Important**: Your datastore must meet some criteria for the webhook to work. Product items need a `code` field.
54+
1. Grab the credentials needed for integrating with your datastore. Check the details in your datastore integration page.
55+
1. Click the **deploy to Netlify** button at the end of this page.
56+
- Netlify will provide you with a form for you to provide your configuration.
57+
- The Webflow Prepayment Webhook requires only `FOXY_WEBFLOW_TOKEN`. The other settings are used for the other services in this repository.
58+
1. Grab the URL for your webhook in Netlify. Be sure to get the correct URL for your specific webhook.
59+
- To do this, after the deploy is finished, click the "functions" tab, look for your webhook function and copy the **Endpoint URL**.
60+
1. Configure your prepayment webhook using your endpoint. Check the docs here: https://wiki.foxycart.com/v/2.0/pre_payment_webhook
61+
62+
63+
# Development
1364

1465
## Localdev Setup
1566

doc/datastore-integration.dot

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
digraph G {
2+
node [shape = box];
3+
newrank=true;
4+
rankdir=TB;
5+
6+
7+
subgraph clusterCustomer {
8+
label="Customer\n\nYour customer workflow\nremains fluid.";
9+
chooseProduct[label="Choose\nproducts"];
10+
goToCart[label="Go to\ncart"];
11+
success[label="Success"];
12+
goToCart->success[style=invis];
13+
}
14+
15+
subgraph clusterFoxy {
16+
label="Foxy.io";
17+
cart[label="Cart"];
18+
cartSubmit[label="Cart\nSubmit"];
19+
cartProcess[label="Payment\nprocessing", color="gray"];
20+
}
21+
22+
subgraph clusterWebhook {
23+
label="Datastore Integration Webhook";
24+
color="gray";
25+
prepaymentValidation[label="Prepayment\ntransaction\nvalidation", color="gray"];
26+
transactionCreated[label="Transaction\nCreated", color="gray"];
27+
28+
prepaymentValidation->transactionCreated[style=invis];
29+
}
30+
31+
subgraph clusterDatastore {
32+
label="Datastore";
33+
color="gray";
34+
getInventory[label="get\nInventory", color="gray"];
35+
getPrice[label="get\nPrice", color="gray"];
36+
updateInventory[label="update\nInventory", color="gray"];
37+
}
38+
39+
chooseProduct->goToCart;
40+
41+
goToCart->cart;
42+
43+
cart->cartSubmit;
44+
45+
cartSubmit->prepaymentValidation[dir="both"; label="is trasaction valid?"; style="dashed", fontsize="10px"];
46+
47+
cartSubmit->cartProcess;
48+
49+
cartProcess->transactionCreated[label="successful transaction"; style="dashed", fontsize="10px"];
50+
51+
prepaymentValidation->getPrice[dir="both"; label="is price correct?", style="dashed", color=blue; fontcolor=blue; fontsize="10px"];
52+
prepaymentValidation->getInventory[dir="both"; label="is price correct?", style="dashed", color=blue; fontcolor=blue; fontsize="10px"];
53+
transactionCreated->updateInventory[label="update inventory", style="dashed", color=blue; fontcolor=blue; fontsize="10px"];
54+
55+
cartProcess->success;
56+
cartSubmit->cart[label="if invalid,\ntry again", fontsize="10px", color="red", style="dashed", fontcolor=red];
57+
58+
{rank=same;
59+
goToCart; cart;
60+
}
61+
62+
{rank=same;
63+
cartSubmit; prepaymentValidation;
64+
}
65+
66+
{rank=same;
67+
cartProcess; transactionCreated;
68+
}
69+
70+
{rank=same;
71+
chooseProduct; getInventory; updateInventory; getPrice
72+
}
73+
74+
}
55.1 KB
Loading

netlify.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
FOXY_API_CLIENT_ID = "Enter your Foxy.io API Client ID here."
88
FOXY_API_CLIENT_SECRET = "Enter your Foxy.io API Client Secret here."
99
FOXY_API_REFRESH_TOKEN = "Enter your Foxy.io API Refresh Token here."
10-
DEFAULT_AUTOSHIP_FREQUENCY = "Default autoship frequency (such as `1m`)"
11-
IDEV_SECRET_KEY = "iDevAffiliate secret key (from the API settings)"
12-
IDEV_API_URL = "iDevAffiliate API URL (from the API settings; should end in `sale.php`)"
13-
WEBFLOW_TOKEN = "Get this from Webflow's project settings, at the 'Integrations' tab."
10+
FOXY_DEFAULT_AUTOSHIP_FREQUENCY = "Default autoship frequency (such as `1m`)"
11+
FOXY_IDEV_SECRET_KEY = "iDevAffiliate secret key (from the API settings)"
12+
FOXY_IDEV_API_URL = "iDevAffiliate API URL (from the API settings; should end in `sale.php`)"
13+
FOXY_WEBFLOW_TOKEN = "Get this from Webflow's project settings, at the 'Integrations' tab."
14+
FOXY_DATASTORE_CREDENTIALS = "Datastore credentials"

0 commit comments

Comments
 (0)