- Single-page-app with CRA that renders the Checkout injected to head via react-helmet, calling
POST /transactions
using axios with random invoice transaction populated with faker mock data where applicable. - Firebase cloud function that proxies the Balance API using rate-limited express, http-proxy-middleware, thereby safeguarding key in server-side environment variable.
- The configuration of the transaction (aka cart and payment terms) are randomly generated, so either refresh page to see different states or run locally and change it to check specific use-cases.
- Invoice will be sent to buyer's email upon completing the checkout flow, so make sure to use your own email.
- Use Test Data to fill in the forms and try out different scenarios.
To run this demo you must first get access to the Sandbox Dashboard and create an API
BALANCE_KEY
which you will use either locally or in the cloud function environment variables.
To run locally
- Change the
axios
config inApp.js
to be:
axios({
method: 'post',
url: 'https://api.sandbox.getbalance.com/transactions',
headers: {'x-balance-key': 'YOUR_BALANCE_KEY'},
data: transaction
})
- Run
yarn start
and change transaction config to the scenario you want to test out (seemockTransaction.js
)
To deploy to Firebase cloud solutions:
- Pre-requisite: install Firebase CLI, run
firebase login
- Create new firebase project in repo root by running
firebase init
and enabling hosting and functions (upgrade to Blaze plan) - Install modules by running
yarn
in root and in/function
directory - Run
yarn deploy --only functions
to build functions in the cloud - Edit the
balanceProxy
function in GCP Console toBALANCE_KEY
environment variable - Change the
BALANCE_PROXY_URL
in theconfig.js
to the URL of the deployed cloud function - Change the transaction config to the scenario you want to test out (see
mockTransaction.js
) - Run
yarn deploy --only hosting
to build app and visit hosting URL
This project server-side is inspired by the GCP Proxy Func repo.
Licensed under the MIT License.