Skip to content

Instantly share code, notes, and snippets.

View cjavilla-stripe's full-sized avatar

CJ Avilla cjavilla-stripe

View GitHub Profile
@cjavilla-stripe
cjavilla-stripe / index.ts
Created February 14, 2022 19:45
Stripe Deno + Begin example
import Stripe from "https://esm.sh/stripe?target=deno";
const stripe = Stripe(Deno.env.get("STRIPE_API_KEY"), {
// This is needed to use the Fetch API rather than relying on the Node http
// package.
httpClient: Stripe.createFetchHttpClient(),
});
export async function handler (req: object) {
@cjavilla-stripe
cjavilla-stripe / Program.cs
Created December 27, 2021 17:46
Stripe webhook handler for .NET 6 minimal API
using Stripe;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapPost("/webhook", async (HttpRequest request) =>
{
var json = await new StreamReader(request.Body).ReadToEndAsync();
const string signingSecret = "whsec_...";
@cjavilla-stripe
cjavilla-stripe / upload.rb
Created September 8, 2021 22:04
Example uploading json products to the Stripe API
require 'json'
require 'stripe'
Stripe.api_key = '<your-api-key>'
# {
# "Id": "selinazawacki-shirt",
# "Maker": "selinazawacki",
# "Image": "https://user-images.githubusercontent.com/41929050/61567058-142c1c80-aa33-11e9-89fb-b4f30d84d69d.png",
# "Url": "https://www.instagram.com/p/BEXlpiZCnJ3",
@cjavilla-stripe
cjavilla-stripe / value-based-saas-pricing-seed.json
Last active January 28, 2023 14:46
Stripe CLI fixture for creating value based pricing Stripe test data
{
"_meta": {
"template_version": 0
},
"fixtures": [
{
"name": "startup_product",
"path": "/v1/products",
"method": "post",
"params": {
Stripe::Checkout::Session.create({
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
payment_method_types: ['card'],
line_items: [{
price: recurring_price_id,
quantity: 1
}, {
price: one_time_price_id,
quantity: 1
@cjavilla-stripe
cjavilla-stripe / custom-portal-config-prices.rb
Created June 16, 2021 17:05
Pass specific prices to choose between for the BillingPortal
config = Stripe::BillingPortal::Configuration.create({
features: {
customer_update: {
allowed_updates: ['email', 'tax_id'],
enabled: true,
},
subscription_update: {
enabled: true,
default_allowed_updates: ['price'],
products: [{
@cjavilla-stripe
cjavilla-stripe / airtable-script.js
Created June 4, 2021 17:28
Expand line items with Airtable script
// Stripe Secret API key pulled from the Stripe Dashboard
const STRIPE_API_KEY = 'sk_test_...';
// The checkoutSessionId is pulled out of the input from the previous action which was "webhook received"
const {checkoutSessionId} = input.config();
// Use the Checkout Session ID to construct a URL for making a GET API request to Stripe
// Note that we're passing `expand[]=line_items` and `expand[]=customer` so that
// the data returned from the API includes all of the related line item and customer data.
let response = await fetch(`https://api.stripe.com/v1/checkout/sessions/${checkoutSessionId}?expand[]=line_items&expand[]=customer`, {
@cjavilla-stripe
cjavilla-stripe / PaymentsController.cs
Created May 7, 2021 22:02
ACSS Debit PaymentIntent creation with Mandate options
var options = new PaymentIntentCreateOptions
{
Amount = 1999,
Currency = req.Currency,
PaymentMethodTypes = new List<string>
{
req.PaymentMethodType,
},
};
(async () => {
const customer = await stripe.customers.create({
payment_method: 'pm_card_chargeCustomerFail',
invoice_settings: {
default_payment_method: 'pm_card_chargeCustomerFail'
}
})
const subscription = await stripe.subscriptions.create({
customer: customer.id,
items: [{ plan: '802836528202eb82f5552bc0ddc0278d144e5182' }], // 802836528202eb82f5552bc0ddc0278d144e5182
@cjavilla-stripe
cjavilla-stripe / helpers.sh
Created January 22, 2021 23:37
Tools for working with Stripe samples locally
server_langs_for_integration () {
integration=${1:-main}
jq -r ".integrations[] | select(.name==\"${integration}\") | .servers | .[]"
}
# 1. Create a .env in the root of the sample
# 2. Run `copy_env <sample name>` to copy into all of the server directories.
copy_env() {
# accepts the path to the sample as the first arg.