Skip to content

Instantly share code, notes, and snippets.

@westonganger
Last active November 24, 2021 22:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westonganger/dd2daf8af68db062bca0fe9c73d0f300 to your computer and use it in GitHub Desktop.
Save westonganger/dd2daf8af68db062bca0fe9c73d0f300 to your computer and use it in GitHub Desktop.
Stripe Checkout Requirements (2021)

(Alternative) Payment Intents API

If checkout doesnt work well can use the payment intents API

Simple Difference Comparison: https://stripe.com/docs/payments/payment-intents/migration/charges Code Example: https://gist.github.com/westonganger/6ac28553b13a0bc7fe07dcf8d86ce3bd

(Preferred) Stripe Checkout

Seems to be usable for our cases and has a fairly simple code structure.

Documentation for line_items (See Ruby example for usage)

https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items

Prices & Products Guide:

https://stripe.com/docs/billing/prices-guide

Invoices:

https://stripe.com/docs/api/invoices

Customer Portal

https://stripe.com/docs/billing/subscriptions/customer-portal

Requirements:

One time setup for platform
gst_tax_rate = Stripe::TaxRate.create({
  display_name: ‘GST (Canada),
  description: 'GST Canada',
  jurisdiction: 'CA',
  percentage: 5,
  inclusive: false,
})

pst_tax_rate = Stripe::TaxRate.create({
  display_name: ‘PST (Canada),
  description: 'PST Canada',
  jurisdiction: 'CA',
  percentage: 7,
  inclusive: false,
})
Each Checkout - Goal: Not to be managing Products within stripe
Stripe::Checkout::Session.create({
  success_url: 'https://example.com/success',
  cancel_url: 'https://example.com/cancel',
  payment_method_types: ['card'],
  mode: 'payment',
  customer_email: “customer@example.com”,
  line_items: [
    {
      quantity: 1, 
      adjustable_quantity: {enabled: false},

      ### Documentation says if you don’t set a tax_code on a product, we apply your default product tax code
      ### Else
      tax_rates: [gst_tax_rate.id, pst_tax_rate.id],
      tax_behaviour: “exclusive”,
     
      price: price.id, ### if managing price info within Stripe,
      price_data: { ### OR adhoc pricing info
        Product: product.id, ### if managing product info with Stripe
        product_data: { ### OR adhoc product info
          name: “Product Name”,
          description: “The product description”, ### optional
          tax_code: “txcd_10103000”, ### optional, this example code is for SaaS
        },

        currency: “CAD”,

        unit_amount: “9999, ### in cents == $99.99
        ### OR
        unit_amount_decimal: “99.99,


        recurring: {
          interval: “month”,
          interval_count: 1, ### every 1 month
        },
      },
   
    },

    {
        Product 2 details ....
    },
  ],

});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment