Skip to content

The official Balance checkout demo using proxy cloud function

Notifications You must be signed in to change notification settings

GetBalanceDev/balance-checkout-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Balance Checkout Demo

What's Included

  • 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.

Important Notes

  • 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.

Usage

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

  1. Change the axios config in App.js to be:
axios({
  method: 'post',
  url: 'https://api.sandbox.getbalance.com/transactions',
  headers: {'x-balance-key': 'YOUR_BALANCE_KEY'},
  data: transaction
})
  1. Run yarn start and change transaction config to the scenario you want to test out (see mockTransaction.js)

To deploy to Firebase cloud solutions:

  1. Pre-requisite: install Firebase CLI, run firebase login
  2. Create new firebase project in repo root by running firebase init and enabling hosting and functions (upgrade to Blaze plan)
  3. Install modules by running yarn in root and in /function directory
  4. Run yarn deploy --only functions to build functions in the cloud
  5. Edit the balanceProxy function in GCP Console to BALANCE_KEY environment variable
  6. Change the BALANCE_PROXY_URL in the config.js to the URL of the deployed cloud function
  7. Change the transaction config to the scenario you want to test out (see mockTransaction.js)
  8. Run yarn deploy --only hosting to build app and visit hosting URL

Contributors

This project server-side is inspired by the GCP Proxy Func repo.

License

Licensed under the MIT License.

About

The official Balance checkout demo using proxy cloud function

Topics

Resources

Stars

Watchers

Forks