Skip to content

Instantly share code, notes, and snippets.

View petercossey's full-sized avatar

Peter Cossey petercossey

View GitHub Profile
@petercossey
petercossey / external-payment-flow.md
Last active April 11, 2025 06:21
Payment Middleware API Flow for External Payment Integrations

Payment Middleware API Flow for External Payment Integrations

Overview

This document outlines the required API flow for a payment middleware service that integrates an external payment provider with BigCommerce using a custom payment form.

The flow is also referenced in the following screencast: Replacing payment section of default checkout and loading order confirmation page (Loom video 5mins)

This app also provides a demo of the flow in the "External Payment" section of the checkout explorer UI: https://bigcommerce-checkout-external-payment.replit.app/

@petercossey
petercossey / xhr-interceptor.html
Created March 4, 2025 19:32
XHR interceptor to add your own business logic at key points in the request lifecycle
<script>
(function() {
// Store the original XMLHttpRequest
const OriginalXHR = window.XMLHttpRequest;
// Store the original fetch (we'll use this for our side requests)
const originalFetch = window.fetch;
// Create a unique ID for this interceptor
const interceptorId = 'xhr-' + Math.random().toString(36).substr(2, 9);
@petercossey
petercossey / composable-commerce-spectrum.svg
Created January 16, 2025 06:41
Composable Commerce Spectrum Diagram
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@petercossey
petercossey / stacked-architecture.svg
Created January 16, 2025 06:07
Stacked Architecture Visualization
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@petercossey
petercossey / day-1.md
Created January 15, 2025 21:41
SCRATCHPAD - Neovim cheatsheet

Neovim Day 1 Cheatsheet

Modes

  • ESC - Return to NORMAL mode
  • i - Enter INSERT mode (insert before cursor)
  • v - Enter VISUAL mode
  • A - Enter INSERT mode at end of line

Basic Movement (in NORMAL mode)

  • h j k l - Left, down, up, right
@petercossey
petercossey / order-processing-state-dagram-simple.mermaid
Last active January 8, 2025 06:50
Order Processing State Diagram — REST Management API
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@petercossey
petercossey / absolute-adjustment.md
Last active December 2, 2024 09:23
Override the existing inventory levels for an inventory item at a location.

Absolute Adjustment Example

PUT https://api.bigcommerce.com/stores/{{store_hash}}/v3/inventory/adjustments/absolute

{
    "reason": "hourly sync 20241204-2014",
    "items": [
        {
 "location_id": 1,
@petercossey
petercossey / fetch-inventory-per-location.gql
Created December 2, 2024 09:11
Fetch inventory for product variants at each location
query productById($productId: Int!) {
site {
product(entityId: $productId) {
id
entityId
name
sku
variants {
edges {
node {
@petercossey
petercossey / pick-list-prices.html
Created June 27, 2023 02:09
Render catalog price for products in a pick-list option modifier using client-side Storefront GraphQL API
{{#partial "page_bottom"}}
<script>
// Get product IDs for GraphQL query on product prices.
const pickListProductIds = []
{{#each product.options}}
{{#if partial '===' 'product-list'}}
pickListProductIds.push({{pluck values 'data'}})
{{/if}}
{{/each}}
@petercossey
petercossey / get-a-cart-async.js
Last active September 8, 2022 21:26
Javascript snippet for loading a cart in a BigCommerce Stencil environment
const storefrontCartUrl = "https://peters-everything-store.mybigcommerce.com/api/storefront/carts"
const getCart = async (url) => {
try {
const response = await fetch(url, {
"method": "GET",
"headers": {
"Content-Type": "application/json"
}});
const json = await response.json();
return json;