stripe_local 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae0a73dda734ad56a0fef09489b79ea06f339b19
4
- data.tar.gz: 58b6831c0ef5cbbb834e68e4972f6958c45b60ae
3
+ metadata.gz: c55acbf30f1906db9db8f6a78582a497f71cd50e
4
+ data.tar.gz: 1abc73fdd8f218c39284ad658892563d8c12be6b
5
5
  SHA512:
6
- metadata.gz: 6ec4268e51a6f3db8fd413e8cce695269abf324041f26b2a64cfbb8fe9fd4ebbef1bb94c130642d9df95a73df4ae04a688159ae7ce8e38a52dc845c2e469f91e
7
- data.tar.gz: 7c46dd84d7a868e8001238461594e630ec5ae3d1c078649e897b206982cd8d4876367da076d2cedbf0f695545045b99474c461dad2c7a0841845851d9e17ec82
6
+ metadata.gz: 89dc83ce29cfbb60612eb36ff3edf98a7ea0104d1a79bc35a873f3f45b4d1fbb46bd1ce3c4203f9d4fc34cba992ce517f256b588ca75e918f0c695462cac5779
7
+ data.tar.gz: 7bff5d0a529f5204ea3bf95207b863a38c3ce31aa85d8c0f6e7f9c97419f3de5d3b711cb8453a58dd851450cbc97dced00cf79f40f6567fd01d06fe137f78346
data/README.md CHANGED
@@ -3,11 +3,57 @@
3
3
  A rails engine that maintains a local store of all your Stripe resources, keeping everything up to date with Stripe via their API and Webhook service.
4
4
  Manages the complexities of keeping two data sources in sync while providing the speed and simplicity of dealing with purely local data in a purely synchronous fashion.
5
5
 
6
- ## <b style="color:red;">[</b>UNDER CONSTRUCTION<b style="color:red;">]</b> Not in running condition!
6
+ ## <b style="color:red;">[</b>UNDER CONSTRUCTION<b style="color:red;">]</b>
7
+ ### Not in running condition!
7
8
 
8
- StripeLocal is an attempt at extracting a framework for Stripe Integration that I have found myself building into several large scale CRM projects. It is my first Rails Engine and I am still learning the ends and outs of Engine building. If you find something I am doing terribly wrong, please bring it to my attention by opening an issue. I appreciate your help.
9
+ I had considered waiting to open source this project untill it was something I would be proud to put my name on. However, my free time is limited and there is no telling how long it might have taken me.
10
+
11
+ My hope is that some of you will see some potential and dig in to help me get it working. Please don't be shy, I don't claim to be an expert and I am open to your ideas for improvement.
12
+
13
+ StripeLocal is an extraction of a framework for Stripe Integration that I have built into several large CRM projects. There are likely some places in the code that still rely on the application it was extracted from. If you find such code please create an issue or fix it yourself and submit a pull request.
14
+
15
+ This is my first Rails Engine and I am still learning the ends and outs of building an engine. If you find something I am doing terribly wrong, please bring it to my attention by opening an issue. I appreciate your help.
16
+
17
+
18
+ ### Pull Requests are highly encouraged!
19
+ Feel free to fork and hack. You are of course welcome to do want you want with the code. However, I do plan to stay active in developing this code base and would like to see it become a real community effort.
20
+
21
+ ### How I see it
22
+
23
+ The gem is hosted at [Rubygems.org](https://rubygems.org/gems/stripe_local) like any other gem and is available for use in a Rails project by including it in your gem file
24
+
25
+ gem 'stripe_local'
26
+
27
+ After a `bundle install` you'll need to generate, and run the migrations..
28
+
29
+ rake stripe_local:install:migrations && rake db:migrate
30
+
31
+ Stripe\_local integrates with your application via a _customer class_
32
+
33
+ The _customer class_ does not need to be named *Customer*. It just needs to be an active record class and contain a call to a special class macro in its definition
34
+
35
+ class ClassName < ActiveRecord::Base
36
+ stripe_customer
37
+ end
38
+
39
+ this essentially mixes in a few modules which add a one-to-one relationship with a `Stripe::Customer` and form a `SimpleDelegator` *like* relationship.
40
+
41
+ Once one of your *customers* has a `Stripe::Customer` you may call methods on your object as if it were itself a `Stripe::Customer`
42
+
43
+ Use the generated `signup` instance method to create a `Stripe::Customer` for the object
44
+
45
+ my_client.signup({
46
+ card: "card_token",
47
+ plan: "plan_id",
48
+ coupon: "if you want",
49
+ lines: [
50
+ [10099, "this will be a line item on the initial invoice"],
51
+ [100, "optional array of (amount,description) tuples"]
52
+ ]
53
+ })
54
+
55
+ my_client.account_balance #=> 0
9
56
 
10
- #### Feel free to fork and hack. I'm also happy to accept pull requests...
11
57
 
12
58
 
13
59
 
@@ -4,7 +4,7 @@ module StripeLocal
4
4
 
5
5
  self.primary_key = :id
6
6
 
7
- has_one :model, inverse_of: :customer, class_name: "::#{StripeLocal::model_class}"
7
+ belongs_to :model, inverse_of: :customer, class_name: "::#{StripeLocal::model_class}"
8
8
 
9
9
  has_many :cards, inverse_of: :customer
10
10
 
@@ -14,7 +14,9 @@ module StripeLocal
14
14
 
15
15
  has_one :subscription, inverse_of: :customer
16
16
 
17
- has_one :plan, through: :subscription, source: :plan
17
+ has_one :plan, through: :subscription,
18
+ inverse_of: :members,
19
+ source: :plan
18
20
 
19
21
  class<<self
20
22
  #=!=#>>>
@@ -91,6 +93,7 @@ module StripeLocal
91
93
  # t.string :description
92
94
  # t.string :email
93
95
  # t.text :metadata
96
+ # t.integer :model_id
94
97
  # t.timestamps
95
98
 
96
99
  #=¡=>>>
@@ -5,6 +5,9 @@ module StripeLocal
5
5
  self.primary_key = :id
6
6
 
7
7
  has_many :subscriptions, inverse_of: :plan
8
+ has_many :members, through: :subscriptions,
9
+ inverse_of: :plan,
10
+ source: :customer
8
11
 
9
12
  class<<self
10
13
  def create object
@@ -0,0 +1,7 @@
1
+ module StripeLocal
2
+ class JobQueue
3
+
4
+
5
+
6
+ end
7
+ end
@@ -7,11 +7,13 @@ class LoadStripeTables < ActiveRecord::Migration
7
7
  t.boolean :delinquent
8
8
  t.string :description
9
9
  t.string :email
10
+ t.integer :model_id
10
11
  t.text :metadata
11
12
 
12
13
  t.timestamps
13
14
  end
14
15
  add_index :stripe_local_customers, :id, unique: true
16
+ add_index :stripe_local_customers, :model_id
15
17
 
16
18
  create_table :stripe_local_cards, id: false do |t|
17
19
  t.string :id, primary_key: true
@@ -1,3 +1,3 @@
1
1
  module StripeLocal
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20131122104223) do
14
+ ActiveRecord::Schema.define(version: 20131122063517) do
15
15
 
16
16
  # These are extensions that must be enabled in order to support this database
17
17
  enable_extension "plpgsql"
@@ -22,7 +22,6 @@ ActiveRecord::Schema.define(version: 20131122104223) do
22
22
  t.string "password"
23
23
  t.datetime "created_at"
24
24
  t.datetime "updated_at"
25
- t.string "stripe_customer_id"
26
25
  end
27
26
 
28
27
  create_table "stripe_local_balances", force: true do |t|
@@ -99,12 +98,14 @@ ActiveRecord::Schema.define(version: 20131122104223) do
99
98
  t.boolean "delinquent"
100
99
  t.string "description"
101
100
  t.string "email"
101
+ t.integer "model_id"
102
102
  t.text "metadata"
103
103
  t.datetime "created_at"
104
104
  t.datetime "updated_at"
105
105
  end
106
106
 
107
107
  add_index "stripe_local_customers", ["id"], name: "index_stripe_local_customers_on_id", unique: true, using: :btree
108
+ add_index "stripe_local_customers", ["model_id"], name: "index_stripe_local_customers_on_model_id", using: :btree
108
109
 
109
110
  create_table "stripe_local_discounts", force: true do |t|
110
111
  t.string "coupon_id"
@@ -1288,3 +1288,99 @@ Migrating to AddStripeCustomerIdToClients (20131122104223)
1288
1288
  StripeLocal::Customer Load (1.0ms) SELECT "stripe_local_customers".* FROM "stripe_local_customers" WHERE "stripe_local_customers"."id" = $1 ORDER BY "stripe_local_customers"."id" ASC LIMIT 1 [["id", "cus_2zIbb2qmfw4KLn"]]
1289
1289
  StripeLocal::Invoice Load (2.4ms) SELECT "stripe_local_invoices".* FROM "stripe_local_invoices" WHERE "stripe_local_invoices"."customer_id" = $1 [["customer_id", "cus_2zIbb2qmfw4KLn"]]
1290
1290
  StripeLocal::Plan Load (1.3ms) SELECT "stripe_local_plans".* FROM "stripe_local_plans" INNER JOIN "stripe_local_subscriptions" ON "stripe_local_plans"."id" = "stripe_local_subscriptions"."plan_id" WHERE "stripe_local_subscriptions"."customer_id" = $1 ORDER BY "stripe_local_plans"."id" ASC LIMIT 1 [["customer_id", "cus_2zIbb2qmfw4KLn"]]
1291
+ ActiveRecord::SchemaMigration Load (2.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
1292
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
1293
+ Migrating to AddStripeCustomerIdToClients (20131122104223)
1294
+  (0.1ms) BEGIN
1295
+  (8.1ms) ALTER TABLE "clients" DROP "stripe_customer_id"
1296
+ SQL (2.5ms) DELETE FROM "schema_migrations" WHERE "schema_migrations"."version" = '20131122104223'
1297
+  (0.5ms) COMMIT
1298
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
1299
+ ActiveRecord::SchemaMigration Load (0.3ms) SELECT "schema_migrations".* FROM "schema_migrations"
1300
+ ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
1301
+ Migrating to LoadStripeTables (20131122063517)
1302
+  (0.1ms) BEGIN
1303
+  (6.0ms) DROP TABLE "stripe_local_balances"
1304
+  (0.1ms) DROP INDEX "index_transactions_on_source_id_and_source_type"
1305
+  (0.1ms) DROP INDEX "index_stripe_local_transactions_on_status"
1306
+  (0.1ms) DROP INDEX "index_stripe_local_transactions_on_id"
1307
+  (0.4ms) DROP TABLE "stripe_local_transactions"
1308
+  (0.1ms) DROP INDEX "index_stripe_local_transfers_on_transaction_id"
1309
+  (0.1ms) DROP INDEX "index_stripe_local_transfers_on_status"
1310
+  (0.1ms) DROP INDEX "index_stripe_local_transfers_on_id"
1311
+  (0.3ms) DROP TABLE "stripe_local_transfers"
1312
+  (0.1ms) DROP INDEX "index_stripe_local_charges_on_transaction_id"
1313
+  (0.1ms) DROP INDEX "index_stripe_local_charges_on_invoice_id"
1314
+  (0.1ms) DROP INDEX "index_stripe_local_charges_on_customer_id"
1315
+  (0.1ms) DROP INDEX "index_stripe_local_charges_on_card_id"
1316
+  (0.1ms) DROP INDEX "index_stripe_local_charges_on_id"
1317
+  (0.5ms) DROP TABLE "stripe_local_charges"
1318
+  (0.1ms) DROP INDEX "index_stripe_local_line_items_on_invoice_id"
1319
+  (0.1ms) DROP INDEX "index_stripe_local_line_items_on_id"
1320
+  (0.5ms) DROP TABLE "stripe_local_line_items"
1321
+  (0.1ms) DROP INDEX "index_stripe_local_invoices_on_customer_id"
1322
+  (0.2ms) DROP INDEX "index_stripe_local_invoices_on_id"
1323
+  (2.1ms) DROP TABLE "stripe_local_invoices"
1324
+  (0.2ms) DROP INDEX "index_stripe_local_subscriptions_on_plan_id"
1325
+  (0.1ms) DROP INDEX "index_stripe_local_subscriptions_on_customer_id"
1326
+  (0.6ms) DROP TABLE "stripe_local_subscriptions"
1327
+  (0.2ms) DROP INDEX "index_stripe_local_discounts_on_coupon_id_and_subscription_id"
1328
+  (0.5ms) DROP TABLE "stripe_local_discounts"
1329
+  (0.2ms) DROP INDEX "index_stripe_local_coupons_on_id"
1330
+  (0.4ms) DROP TABLE "stripe_local_coupons"
1331
+  (0.1ms) DROP INDEX "index_stripe_local_plans_on_id"
1332
+  (1.0ms) DROP TABLE "stripe_local_plans"
1333
+  (0.2ms) DROP INDEX "index_stripe_local_cards_on_customer_id"
1334
+  (0.1ms) DROP INDEX "index_stripe_local_cards_on_id"
1335
+  (0.3ms) DROP TABLE "stripe_local_cards"
1336
+  (0.1ms) DROP INDEX "index_stripe_local_customers_on_id"
1337
+  (0.3ms) DROP TABLE "stripe_local_customers"
1338
+ SQL (0.3ms) DELETE FROM "schema_migrations" WHERE "schema_migrations"."version" = '20131122063517'
1339
+  (53.7ms) COMMIT
1340
+ ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
1341
+ ActiveRecord::SchemaMigration Load (0.3ms) SELECT "schema_migrations".* FROM "schema_migrations"
1342
+ Migrating to LoadStripeTables (20131122063517)
1343
+  (0.1ms) BEGIN
1344
+  (5.3ms) CREATE TABLE "stripe_local_customers" ("id" character varying(255), "account_balance" integer, "default_card" character varying(255), "delinquent" boolean, "description" character varying(255), "email" character varying(255), "model_id" integer, "metadata" text, "created_at" timestamp, "updated_at" timestamp) 
1345
+  (0.6ms) CREATE UNIQUE INDEX "index_stripe_local_customers_on_id" ON "stripe_local_customers" ("id")
1346
+  (0.5ms) CREATE INDEX "index_stripe_local_customers_on_model_id" ON "stripe_local_customers" ("model_id")
1347
+  (1.1ms) CREATE TABLE "stripe_local_cards" ("id" character varying(255), "customer_id" character varying(255), "name" character varying(255), "exp_month" integer, "exp_year" integer, "brand" character varying(255), "last4" character varying(255), "cvc_check" character varying(255), "created_at" timestamp, "updated_at" timestamp)
1348
+  (0.4ms) CREATE UNIQUE INDEX "index_stripe_local_cards_on_id" ON "stripe_local_cards" ("id")
1349
+  (0.5ms) CREATE INDEX "index_stripe_local_cards_on_customer_id" ON "stripe_local_cards" ("customer_id")
1350
+  (2.0ms) CREATE TABLE "stripe_local_plans" ("id" character varying(255), "name" character varying(255), "amount" integer, "interval" character varying(255), "interval_count" integer DEFAULT 1, "trial_period_days" integer DEFAULT 0, "currency" character varying(255) DEFAULT 'usd', "synced" boolean DEFAULT 'f', "created_at" timestamp, "updated_at" timestamp) 
1351
+  (0.6ms) CREATE UNIQUE INDEX "index_stripe_local_plans_on_id" ON "stripe_local_plans" ("id")
1352
+  (1.3ms) CREATE TABLE "stripe_local_coupons" ("id" character varying(255), "percent_off" integer, "amount_off" integer, "currency" character varying(255) DEFAULT 'usd', "duration" character varying(255), "redeem_by" timestamp, "max_redemptions" integer, "times_redeemed" integer DEFAULT 0, "duration_in_months" integer, "synced" boolean DEFAULT 'f', "created_at" timestamp, "updated_at" timestamp) 
1353
+  (0.6ms) CREATE UNIQUE INDEX "index_stripe_local_coupons_on_id" ON "stripe_local_coupons" ("id")
1354
+  (5.5ms) CREATE TABLE "stripe_local_discounts" ("id" serial primary key, "coupon_id" character varying(255), "subscription_id" character varying(255), "start" timestamp, "end" timestamp, "created_at" timestamp, "updated_at" timestamp) 
1355
+  (0.6ms) CREATE INDEX "index_stripe_local_discounts_on_coupon_id_and_subscription_id" ON "stripe_local_discounts" ("coupon_id", "subscription_id")
1356
+  (2.1ms) CREATE TABLE "stripe_local_subscriptions" ("id" serial primary key, "customer_id" character varying(255), "plan_id" character varying(255), "status" character varying(255), "quantity" integer DEFAULT 1, "start" timestamp, "canceled_at" timestamp, "ended_at" timestamp, "current_period_start" timestamp, "current_period_end" timestamp, "trial_start" timestamp, "trial_end" timestamp, "created_at" timestamp, "updated_at" timestamp) 
1357
+  (0.6ms) CREATE INDEX "index_stripe_local_subscriptions_on_customer_id" ON "stripe_local_subscriptions" ("customer_id")
1358
+  (0.8ms) CREATE INDEX "index_stripe_local_subscriptions_on_plan_id" ON "stripe_local_subscriptions" ("plan_id")
1359
+  (1.6ms) CREATE TABLE "stripe_local_invoices" ("id" character varying(255), "customer_id" character varying(255), "amount_due" integer, "subtotal" integer, "total" integer, "attempted" boolean, "attempt_count" integer, "paid" boolean, "closed" boolean, "date" timestamp, "period_start" timestamp, "period_end" timestamp, "currency" character varying(255) DEFAULT 'usd', "starting_balance" integer, "ending_balance" integer, "charge_id" character varying(255), "discount" integer DEFAULT 0, "application_fee" integer, "next_payment_attempt" timestamp, "created_at" timestamp, "updated_at" timestamp)
1360
+  (0.5ms) CREATE UNIQUE INDEX "index_stripe_local_invoices_on_id" ON "stripe_local_invoices" ("id")
1361
+  (0.5ms) CREATE INDEX "index_stripe_local_invoices_on_customer_id" ON "stripe_local_invoices" ("customer_id")
1362
+  (1.4ms) CREATE TABLE "stripe_local_line_items" ("id" character varying(255), "invoice_id" character varying(255), "subscription" boolean DEFAULT 't', "amount" integer, "currency" character varying(255) DEFAULT 'usd', "proration" boolean, "period_start" timestamp, "period_end" timestamp, "quantity" integer, "plan_id" character varying(255), "description" character varying(255), "metadata" text, "created_at" timestamp, "updated_at" timestamp) 
1363
+  (0.6ms) CREATE UNIQUE INDEX "index_stripe_local_line_items_on_id" ON "stripe_local_line_items" ("id")
1364
+  (0.6ms) CREATE INDEX "index_stripe_local_line_items_on_invoice_id" ON "stripe_local_line_items" ("invoice_id")
1365
+  (1.5ms) CREATE TABLE "stripe_local_charges" ("id" character varying(255), "card_id" character varying(255), "customer_id" character varying(255), "invoice_id" character varying(255), "transaction_id" character varying(255), "amount" integer, "captured" boolean DEFAULT 't', "refunded" boolean DEFAULT 'f', "paid" boolean, "created" timestamp, "currency" character varying(255) DEFAULT 'usd', "amount_refunded" integer DEFAULT 0, "description" character varying(255), "failure_code" character varying(255), "failure_message" character varying(255), "metadata" text, "created_at" timestamp, "updated_at" timestamp)
1366
+  (0.5ms) CREATE UNIQUE INDEX "index_stripe_local_charges_on_id" ON "stripe_local_charges" ("id")
1367
+  (0.5ms) CREATE INDEX "index_stripe_local_charges_on_card_id" ON "stripe_local_charges" ("card_id")
1368
+  (0.5ms) CREATE INDEX "index_stripe_local_charges_on_customer_id" ON "stripe_local_charges" ("customer_id")
1369
+  (0.6ms) CREATE INDEX "index_stripe_local_charges_on_invoice_id" ON "stripe_local_charges" ("invoice_id")
1370
+  (0.6ms) CREATE INDEX "index_stripe_local_charges_on_transaction_id" ON "stripe_local_charges" ("transaction_id")
1371
+  (1.0ms) CREATE TABLE "stripe_local_transfers" ("id" character varying(255), "amount" integer, "date" timestamp, "status" character varying(255), "transaction_id" character varying(255), "description" character varying(255), "metadata" text, "created_at" timestamp, "updated_at" timestamp)
1372
+  (0.7ms) CREATE UNIQUE INDEX "index_stripe_local_transfers_on_id" ON "stripe_local_transfers" ("id")
1373
+  (0.8ms) CREATE INDEX "index_stripe_local_transfers_on_status" ON "stripe_local_transfers" ("status")
1374
+  (0.5ms) CREATE INDEX "index_stripe_local_transfers_on_transaction_id" ON "stripe_local_transfers" ("transaction_id")
1375
+  (1.4ms) CREATE TABLE "stripe_local_transactions" ("id" character varying(255), "amount" integer, "available_on" timestamp, "created" timestamp, "fee" integer, "net" integer, "source_id" character varying(255), "source_type" character varying(255), "status" character varying(255), "description" character varying(255), "created_at" timestamp, "updated_at" timestamp)
1376
+  (0.5ms) CREATE UNIQUE INDEX "index_stripe_local_transactions_on_id" ON "stripe_local_transactions" ("id")
1377
+  (0.5ms) CREATE INDEX "index_stripe_local_transactions_on_status" ON "stripe_local_transactions" ("status")
1378
+  (0.5ms) CREATE INDEX "index_transactions_on_source_id_and_source_type" ON "stripe_local_transactions" ("source_id", "source_type")
1379
+  (1.3ms) CREATE TABLE "stripe_local_balances" ("id" serial primary key, "available" integer, "pending" integer, "created_at" timestamp, "updated_at" timestamp)
1380
+ SQL (0.8ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20131122063517"]]
1381
+  (1.0ms) COMMIT
1382
+ ActiveRecord::SchemaMigration Load (0.3ms) SELECT "schema_migrations".* FROM "schema_migrations"
1383
+ ActiveRecord::SchemaMigration Load (0.3ms) SELECT "schema_migrations".* FROM "schema_migrations"
1384
+ ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
1385
+ ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
1386
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"