Welcome to the Astro Cake Shop demo project, showcasing how to integrate Snipcart for e-commerce functionality with the BlinkPay payment gateway. This project is built using Astro, Tailwind CSS, and deployed via Netlify, leveraging serverless Netlify Functions to handle the backend logic.
See the live site: BlinkPay Snipcart Demo
- Astro: A modern web framework to build fast and optimised websites.
- Tailwind CSS: Utility-first CSS framework for styling.
- Netlify Functions: Serverless functions to handle backend logic.
- Snipcart: A flexible e-commerce platform for seamless shopping cart integration.
- BlinkPay: A secure payment gateway to process payments.
Ensure you have the following tools installed:
- Node.js
- Netlify CLI (for local development and deployment)
- Snipcart Account (to manage your e-commerce)
- BlinkPay Account (to process payments)
git clone https://github.com/BlinkPay/BlinkPay-Snipcart-Demo
cd BlinkPay-Snipcart-Demo
First, you will need to have free accounts with Netlify, Snipcart and BlinkPay.
First, install the modules:
npm install
Create a site in Netlify.
One way to do this is to fork this demo repository into a new GitHub repository, and create your Netlify site based on this new repository.
Otherwise, the default set up settings should work for now. We will add environment variables later.
You can now set up netlify locally:
npx netlify init
And follow the instructions from the CLI.
You will need to set up your Redirect URL and retrieve your access key and secret from the BlinkPay Merchant Portal: https://merchants.blinkpay.co.nz/settings/api
Once you are logged in:
- Navigate to your Sandbox app (under Settings/API)
- Add a URL to your whitelist redirect URLs for your Netlify app name, e.g.
https://YOUR-SITE-NAME.netlify.app/
and click save - Copy the API key shown for your
.env
file as described below - Click
Rotate Secret
- your new API secret will display. Copy this for your.env
file too
First, set up your domain
- Head to your Snipcart dashboard and navigate to
Store Configurations
/Domains & URLs
- Enter your domain name e.g.
YOUR-SITE-NAME.netlify.app
- Click
Save
Then, you will need to set your region and currency in SnipCart:
- Head to your Snipcart dashboard and navigate to
Store Configurations
/Regional Settings
- Select
NZD
as your currency - Configure your store time zone and supported countries
- Click
Save
Now, retrieve your public cart key
- Head to your Snipcart dashboard and navigate to
Store Configurations
/Payment Gateway
- Copy your Snipcart API Key for your
.env
variables as described below
You will then need to configure Snipcart Custom Payment Gateway in your Snipcart dashboard. To do this:
- Head to your Snipcart dashboard and navigate to
Store Configurations
/Account
/API Keys
- Toggle
Custom Payment Gateway
toON
and hitConfigure
- Enter your netlify function URL for payment method under
Payment Methods API URL
. In this project, this likely to behttps://YOUR-SITE-NAME.netlify.app/.netlify/functions/payment-method
- Copy your Snipcart Gateway API Key for your
.env
variables as described below
Now you are ready to create a .env
file at the root of your project.
Note that your Blinkpay Debit URL depends if you are working in a sandbox or production environment. Use:
- For Non-production, use:
https://sandbox.debit.blinkpay.co.nz
- For production, use:
https://debit.blinkpay.co.nz
Add the following environment variables:
PUBLIC_BUSINESS_NAME=<your_business_name>
BLINKPAY_DEBIT_URL=<blinkpay_environment_url>
BLINKPAY_CLIENT_ID=<your_blinkpay_client_id>
BLINKPAY_CLIENT_SECRET=<your_blinkpay_secret>
PUBLIC_SNIPCART_API_KEY=<your_snipcart_public_api_key>
SNIPCART_GATEWAY_API_KEY=<your_snipcart_custom_gateway_api_key>
Now that you have these variables collected, copy these same variables into Netlify under your Site Configuration
/Variables
and click Add a variable
. You can then add the variables by copying the contents of your .env
file.
Before you will able to develop your store locally, you will first need to run a production netlify deploy. This is because Snipcart will be accessing our /.netlify/functions/payment-method
endpoint from the hosted netlify site, even if you are only running the application locally.
npm run netlify-deploy-prod
To develop locally, you will initially need Snipcart to crawl the web site for your products. To do this:
- Head to your Snipcart dashboard and navigate to
Products
- Click
Fetch them here
- Enter your live Netlify site URL e.g.
https://YOUR-SITE-NAME.netlify.app
and clickFetch from URL
Your products should then be populated.
To run the application locally, including netlify functions:
npm run netlify-dev
To build and deploy the project to your Netlify development environment:
npm run netlify-deploy-dev
To build and deploy the project to your Netlify production environment:
npm run netlify-deploy-prod
We welcome contributions from the community! Whether you're fixing bugs, improving documentation, or adding new features, we'd love to have you contribute. Please submit your pull requests, and our team will review them.
This project is licensed under the MIT License. Feel free to use and modify the code in this repository. See the LICENSE file for more details.