Add REST API stitching
This commit is contained in:
@ -1,3 +1,2 @@
|
||||
class ApplicationController < ActionController::Base
|
||||
before_action :authenticate_user!
|
||||
end
|
||||
|
@ -1,4 +1,5 @@
|
||||
class ProductsController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
before_action :set_product, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
# GET /products
|
||||
|
55
rails-app/app/controllers/stripe_controller.rb
Normal file
55
rails-app/app/controllers/stripe_controller.rb
Normal file
@ -0,0 +1,55 @@
|
||||
class StripeController < ApplicationController
|
||||
# GET /stripe/1
|
||||
# GET /stripe/1.json
|
||||
def show
|
||||
data = '{ "data": [
|
||||
{
|
||||
"id": 1,
|
||||
"customer_id": "$id",
|
||||
"object": "charge",
|
||||
"amount": 100,
|
||||
"amount_refunded": 0,
|
||||
"date": "01/01/2019",
|
||||
"application": null,
|
||||
"billing_details": {
|
||||
"address": "1 Infinity Drive",
|
||||
"zipcode": "94024"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"customer_id": "$id",
|
||||
"object": "charge",
|
||||
"amount": 150,
|
||||
"amount_refunded": 0,
|
||||
"date": "02/18/2019",
|
||||
"billing_details": {
|
||||
"address": "1 Infinity Drive",
|
||||
"zipcode": "94024"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"customer_id": "$id",
|
||||
"object": "charge",
|
||||
"amount": 150,
|
||||
"amount_refunded": 50,
|
||||
"date": "03/21/2019",
|
||||
"billing_details": {
|
||||
"address": "1 Infinity Drive",
|
||||
"zipcode": "94024"
|
||||
}
|
||||
}
|
||||
],
|
||||
"data_type": "charges",
|
||||
"total_count": 3,
|
||||
"next_cursor": null
|
||||
}'
|
||||
|
||||
data.gsub!("$id", params[:id])
|
||||
result = JSON.parse(data)
|
||||
|
||||
render json: result
|
||||
|
||||
end
|
||||
end
|
@ -4,5 +4,7 @@ Rails.application.routes.draw do
|
||||
resources :products
|
||||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
||||
|
||||
get '/stripe/:id', to: 'stripe#show', as: 'stripe'
|
||||
|
||||
root to: "products#index"
|
||||
end
|
||||
|
@ -5,6 +5,7 @@ class DeviseCreateCustomers < ActiveRecord::Migration[5.2]
|
||||
create_table :customers do |t|
|
||||
t.string :full_name, null: false
|
||||
t.string :phone
|
||||
t.string :stripe_id
|
||||
|
||||
## Database authenticatable
|
||||
t.string :email, null: false, default: ""
|
||||
|
@ -18,6 +18,7 @@ ActiveRecord::Schema.define(version: 2019_04_05_042247) do
|
||||
create_table "customers", force: :cascade do |t|
|
||||
t.string "full_name", null: false
|
||||
t.string "phone"
|
||||
t.string "stripe_id"
|
||||
t.string "email", default: "", null: false
|
||||
t.string "encrypted_password", default: "", null: false
|
||||
t.string "reset_password_token"
|
||||
|
@ -41,6 +41,7 @@ end
|
||||
|
||||
customer_count.times do |i|
|
||||
customer = Customer.create(
|
||||
stripe_id: "cus_" + [*('A'..'Z'),*('a'..'z'),*('0'..'9')].shuffle[0,10].join,
|
||||
full_name: Faker::Name.name,
|
||||
phone: Faker::PhoneNumber.cell_phone,
|
||||
email: Faker::Internet.email,
|
||||
|
Reference in New Issue
Block a user