How to integrate online payments to Rails app?

Step-by-step tutorial about how to combine Stripe and Ruby on Rails app
08 August 2017   914

Online payments are widely used in large amount of web products. Every day billions of dollars, euro and other popular currency "flows" through the web. So how a Ruby on Rails (RoR) developer should add online payments for his project? Stripe will help.

What is Stripe? 

Stripe is the software platform for running an internet business. It handles billions of dollars every year for forward-thinking businesses around the world. 

Stripe builds the  powerful and flexible tools for internet commerce. Whether you’re creating a subscription service, an on-demand marketplace, an e-commerce store, or a crowdfunding platform, Stripe’s meticulously-designed APIs and unmatched functionality help you create the best possible product for your users. Hundreds of thousands of the world’s most innovative technology companies are scaling faster and more efficiently by building their businesses on Stripe.

Main features of Stripe:

    Stripe team believe that payments is a problem rooted in code, not finance. They obsessively seek out elegant, composable abstractions that enable robust, scalable, flexible integrations. Because they eliminate needless complexity and extraneous details, you can get up and running with Stripe in just a couple of minutes.
    Stripe is an always-improving toolchain that gains new features every month. Our world-class engineering team constantly iterates upon every facet of the Stripe stack. And from Apple Pay to Bitcoin, building on Stripe means you get early access to the latest technologies.
    100,000+ businesses in 100+ countries and across nearly every industry uses Stripe. Headquartered in San Francisco, Stripe has 9 global offices and hundreds of people working to help transform how modern businesses are built and run.

How to combine Stripe and Rails app? 

Stripe is PCI-compliant, which is very convenient. Stripe automatically saves critical payment data on its own servers and implements necessary security standards, such as encryption of credit card data.

To add the Stripe Checkout gateway to your Rails app, follow these steps:

  • Create a developer account on Stripe’s website.
  • Install the Stripe gem in your project using Bundler.
  • Configure Stripe keys.
  • Create routes, the charges controller, and the Stripe charges service object.

Learn more at Ruby Garage

DateTime, Timestamp, Time and Date in Rails

Learn about key differenece between DateTime, Timestamp, Time and Date in Rails
31 October 2017   609

The difference between different date/time formats in ActiveRecord have little to do with Rails and everything to do with whatever database you're using.

Using MySQL as an example (if for no other reason because it's most popular), you have DATEDATETIMETIME and TIMESTAMP column data types; just as you have CHARVARCHARFLOATand INTEGER.

So, main differences: DATE only stores a date, TIME only stores a time of day, while DATETIME stores both.

The difference between DATETIME and TIMESTAMP is a bit more subtle: DATETIME is formatted as YYYY-MM-DD HH:MM:SS. Valid ranges go from the year 1000 to the year 9999 and everything in between. While TIMESTAMP looks similar when you fetch it from the database, it's really a just a front for a unix timestamp. Its valid range goes from 1970 to 2038. The difference here, aside from the various built-in functions within the database engine, is storage space. Because DATETIMEstores every digit in the year, month day, hour, minute and second, it uses up a total of 8 bytes. As TIMESTAMP only stores the number of seconds since 1970-01-01, it uses 4 bytes.

You can read more about the differences between time formats in MySQL here.

In the end, it comes down to what you need your date/time column to do. Do you need to store dates and times before 1970 or after 2038? Use DATETIME. Do you need to worry about database size and you're within that timerange? Use TIMESTAMP. Do you only need to store a date? Use DATE. Do you only need to store a time? Use TIME.

Having said all of this, Rails actually makes some of these decisions for you. Both :timestamp and :datetime will default to DATETIME, while :date and :time corresponds to DATE and TIME, respectively.