Stripe API wrapper for Crystal.
This version (>1.0) is changed to follow Ruby's method and class structure. We will follow Stripe::Class.method
but follow crystal parameters to take care of the types automatically.
This api wrapper was tested on api version 2020-03-02
but have been trying to make it flexible with String?
and correspondent in the types.
Add this to your application's shard.yml
:
dependencies:
stripe:
github: confact/stripe.cr
require "stripe"
Stripe.api_key = "YOUR_API_TOKEN"
token = Stripe::Token.create(card: {
number: "4242424242424242",
exp_month: 12,
exp_year: 2019,
cvc: 123,
})
customer = Stripe::Customer.create(source: token)
charge = Stripe::Charge.create(amount: 1000, currency: "usd", customer: customer)
You can set custom api version if needed. Version need to be set before first api call is called. otherwise it won't be used.
require "stripe"
Stripe.api_key = "YOUR_API_TOKEN"
Stripe.version = "2019-03-29"
Here is a simple way to setup a subscription by using payment_method.
Follow the instruction for setting up an subscription at stripe: https://stripe.com/docs/billing/subscriptions/set-up-subscription
When the step is at server code, check the code below that is corresponding towards the ruby code for same step.
Setting up an customer:
token = params['StripeToken'] # or what the param for the token is called for you.
customer = Stripe::Customer.create(email: email,
description: name, # just example
payment_method: token, # or token.payment_method.id
# depends what you do in the frontend to handle the token.
invoice_settings: { default_payment_method: token })
create a subscription with that customer:
Stripe::Subscription.create(customer: customer,
expand: ["latest_invoice.payment_intent"]) # yes - create_subscription support expand.
The rest is frontend to check SCA and more. You should not need to do more than this on the backend.
But follow https://stripe.com/docs/billing/subscriptions/set-up-subscription for the frontend part to make sure it works for SCA and other things.
-
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 source
-
Retrieve a source
-
Attach a source to customer
-
Detach a source from customer
-
Update a source
-
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
-
Cancel a Setup Intent
-
Delete a Setup Intent
-
List all Setup Intents
-
Create a Payment Intent
-
Retrieve a Payment Intent
-
Confirm a Payment Intent
-
Update a Payment Intent
-
Cancel a Payment Intent
-
Delete a Payment Intent
-
List all Payment Intents
-
Create a customer
-
Retrieve a customer
-
Update a customer
-
Delete a customer
-
List all customers
-
Create a customer tax ID
-
Retrieve a customer tax ID
-
Delete a customer tax ID
-
Create a refund
-
Retrieve a refund
-
Update a refund
-
List all refunds
-
Create a tax rate
-
retrieve a tax rate
-
Update a tax rate
-
List all tax rates
-
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
-
Create a file
-
Retrieve a file
-
Update a file
-
List all files
-
Create a file link
-
Retrieve a file link
-
Update a file link
-
List all file links
-
Balance
-
Balance transaction
-
Charge
-
Product
-
Customer
-
Customer Tax ID
-
Subscription
-
Invoice
-
Dispute
-
Dispute evidence
-
Event
-
File
-
File link
-
Payout
-
Refund
-
Tax Rate
-
Token
-
Payment Intent
-
Setup Intent
-
Payment Method
-
Bank account
-
Card
-
Source
-
Attach a payment method to a customer
-
Account
-
Login link
-
Application fee refund
-
Application fee
-
Country spec
-
Top-up
-
Transfer
-
Transfer reversal
-
Create a price
-
Retrieve a price
-
Update a price
-
List all prices
-
Create a product
-
Retrieve a product
-
Update a product
-
List all products
-
Create a discount
-
Retrieve a discount
-
Update a discount
-
List all discounts
-
Create a promotion code
-
Retrieve a promotion code
-
Update a promotion codes
-
List all promotion codes
-
Create a coupon
-
Retrieve a coupon
-
Update a coupon
-
List all coupons
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