Stripe API wrapper for Crystal.
Add this to your application's shard.yml
:
dependencies:
stripe:
github: confact/stripe.cr
require "stripe"
stripe = Stripe.new("YOUR_API_TOKEN")
token = stripe.create_card_token(card: {
number: "4242424242424242",
exp_month: 12,
exp_year: 2019,
cvc: 123,
})
customer = stripe.create_customer(source: token)
charge = stripe.create_charge(amount: 1000, currency: "usd", customer: customer)
You can set custom api version if needed.
require "stripe"
stripe = Stripe.new("YOUR_API_TOKEN", "2019-03-29")
Here is a simple way to setup a subscription by using setupintent.
- First create setup intent to get a secret we will give the frontend:
intent = stripe.create_setup_intent
- Use stripe elements.js or checkout with the setup intent secret (
client_secret
). - After the form is filled and stripe send the token to back to us with the card token, lets start create the stuff for that token.
- create a customer with that token:
token = params['StripeToken'] # or what the param for the token is called for you.
intent = stripe.retrieve_setup_intent(token)
customer = stripe.create_customer(email: user.email,
description: user.name,
payment_method: intent.payment_method,
invoice_settings: { default_payment_method: intent.payment_method })
- create a subscription with that customer
subscription = stripe.create_subscription(customer: customer, off_session: true, plan: STRIPE_PLAN_ID, trial_end: team.trial_due_at)
-
Retrieve balance
-
Retrieve a balance transaction
-
List all balance history
-
Create a charge
-
Retrieve a charge
-
Update a charge
-
Capture a charge
-
List all charges
-
Create a Subscription
-
Retrieve a Subscription
-
Update a Subscription
-
Delete a Subscription
-
List all Subscriptions
-
Create a Setup Intent
-
Retrieve a Setup Intent
-
Confirm a Setup Intent
-
Update a Setup Intent
-
Delete a Setup Intent
-
List all Setup Intents
-
Create a customer
-
Retrieve a customer
-
Update a customer
-
Delete a customer
-
List all customers
-
Create a card token
-
Create a bank account token
-
Create a PII token
-
Create an account token
-
Retrieve a token
-
Create a invoice
-
Retrieve a invoice
-
Update a invoice
-
Delete a invoice
-
List all invoices
-
Balance
-
Balance transaction
-
Charge
-
Customer
-
Dispute
-
Dispute evidence
-
Event
-
File
-
File link
-
Payout
-
Product
-
Refund
-
Token
-
Bank account
-
Card
-
Source
-
Account
-
Login link
-
Application fee refund
-
Application fee
-
Country spec
-
Top-up
-
Transfer
-
Transfer reversal
TODO: Write development instructions here
- Fork it (https://github.com/confact/stripe.cr/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request