All Projects → svileng → Stripy

svileng / Stripy

Licence: mit
Micro wrapper for Stripe's REST API.

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to Stripy

pinax-stripe-light
a payments Django app for Stripe
Stars: ✭ 670 (+1267.35%)
Mutual labels:  stripe, stripe-api, payments
Stripe Connect Rocketrides
Sample on-demand platform built on Stripe: Connect onboarding for pilots, iOS app for passengers to request rides.
Stars: ✭ 426 (+769.39%)
Mutual labels:  stripe-api, stripe, payments
Pinax Stripe
a payments Django app for Stripe
Stars: ✭ 650 (+1226.53%)
Mutual labels:  stripe-api, stripe, payments
Dj Stripe
Django + Stripe Made Easy
Stars: ✭ 1,022 (+1985.71%)
Mutual labels:  stripe, payments
Elements Examples
Stripe Elements examples.
Stars: ✭ 874 (+1683.67%)
Mutual labels:  stripe, payments
Nest-Js-Boiler-Plate
Nest Js Boilerplate with JWT authentication, CRUD functions and payment gateways.
Stars: ✭ 14 (-71.43%)
Mutual labels:  stripe, stripe-api
Product-Site-101
Simple product site - demo for a talk
Stars: ✭ 33 (-32.65%)
Mutual labels:  stripe-api, payments
Servicebot
Open-source subscription management & billing automation system
Stars: ✭ 857 (+1648.98%)
Mutual labels:  stripe, payments
Stripe Webhook Monitor
Stripe Webhook Monitor provides a real-time feed and graph of Stripe events received via webhooks. 📈✨
Stars: ✭ 356 (+626.53%)
Mutual labels:  stripe-api, stripe
Gringotts
A complete payment library for Elixir and Phoenix Framework
Stars: ✭ 396 (+708.16%)
Mutual labels:  stripe, payments
Django Payments
Universal payment handling for Django.
Stars: ✭ 575 (+1073.47%)
Mutual labels:  stripe, payments
stripe-scala
Scala library for the Stripe API
Stars: ✭ 33 (-32.65%)
Mutual labels:  stripe, stripe-api
procesa-pagos-con-laravel
Código fuente resultado del curso "Procesa pagos con Laravel y las mejores plataformas de pagos"
Stars: ✭ 38 (-22.45%)
Mutual labels:  stripe, stripe-api
Laravel Stripe Webhooks
Handle Stripe webhooks in a Laravel application
Stars: ✭ 300 (+512.24%)
Mutual labels:  stripe, payments
stripe-course
Stripe Payments In Practice - Build your own online ecommerce store and subscription membership website
Stars: ✭ 31 (-36.73%)
Mutual labels:  stripe, stripe-api
Digota
ecommerce microservice
Stars: ✭ 382 (+679.59%)
Mutual labels:  stripe, payments
Vue Stripe Elements
A Vue 2 component collection for StripeElements
Stars: ✭ 498 (+916.33%)
Mutual labels:  stripe-api, stripe
Stripity stripe
An Elixir Library for Stripe
Stars: ✭ 597 (+1118.37%)
Mutual labels:  stripe-api, stripe
drf-stripe-subscription
An out-of-box Django REST framework solution for payment and subscription management using Stripe.
Stars: ✭ 42 (-14.29%)
Mutual labels:  stripe, payments
nuxt-stripejs
💳 NuxtJS module for Stripe.js which loads only when required and w/ retry mechanism
Stars: ✭ 17 (-65.31%)
Mutual labels:  stripe, stripe-api

Stripy hex.pm hexdocs.pm

Stripy is a micro wrapper intended to be used for sending requests to Stripe's REST API. It is made for developers who prefer to work directly with the official API and provide their own abstractions on top if such are needed.

Stripy takes care of setting headers, encoding the data, configuration settings, etc (the usual boring boilerplate); it also makes testing easy by letting you plug your own mock server (see Testing section below).

Some basic examples:

iex> Stripy.req(:get, "subscriptions")
{:ok, %HTTPoison.Response{...}}

iex> Stripy.req(:post, "customers", %{"email" => "[email protected]", "metadata[user_id]" => 1})
{:ok, %HTTPoison.Response{...}}

Where subscriptions and customers are REST API resources.

If you prefer to work with a higher-level library, check out "stripity_stripe" or "stripe_elixir" on Hex.

Installation

Add to your mix.exs as usual:

def deps do
  [{:stripy, "~> 2.0"}]
end

If you're not using application inference, then add :stripy to your applications list.

Then configure the stripy app per environment like so:

config :stripy,
  secret_key: "sk_test_xxxxxxxxxxxxx", # required
  endpoint: "https://api.stripe.com/v1/", # optional
  version: "2017-06-05", # optional
  httpoison: [recv_timeout: 5000, timeout: 8000] # optional

You may also use environment variables:

config :stripy,
  secret_key: {:system, "STRIPE_SECRET_KEY"},
  endpoint: {:system, "STRIPE_ENDPOINT"},
  version: {:system, "STRIPE_VERSION"}

Testing

You can disable actual calls to the Stripe API like so:

# Usually in your test.exs.
config :stripy,
  testing: true

All functions that use Stripy would receive response {:ok, %{status_code: 200, body: "{}"}}.

To provide your own responses, you need to configure a mock server:

config :stripy,
  testing: true,
  mock_server: MyApp.StripeMockServer

Here's an example mock server that mocks the /customer endpoint and returns a basic object for a customer with id cus_test

defmodule MyApp.StripeMockServer do
  @behaviour Stripy.MockServer

  @ok_res %{status_code: 200}

  @impl Stripy.MockServer
  def request(:get, "customers/cus_test", %{}) do
    body = Poison.encode!(%{"email" => "[email protected]"})
    {:ok, Map.put(@ok_res, :body, body)}
  end
end

Now let's quickly write a naive function that gets user's billing email:

def stripe_email(user) do
  {:ok, res} = Stripy.req(:get, "customers/#{user.stripe_id}")
  res["email"]
end

We can test it like so:

fake_user = %{stripe_id: "cus_test"}
assert stripe_email(fake_user) == "[email protected]"

Custom headers

You can add custom headers to the request by supplying a fourth parameter:

Stripy.req(:post, "charges", %{amount: 1000}, %{"Idempotency-Key" => "123456"})

License

  • Stripy: See LICENSE file.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].