pay 0.0.2 → 1.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of pay might be problematic. Click here for more details.

Files changed (51) hide show
  1. checksums.yaml +5 -5
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +256 -29
  4. data/Rakefile +1 -6
  5. data/app/controllers/pay/webhooks/braintree_controller.rb +56 -0
  6. data/app/jobs/pay/email_sync_job.rb +12 -0
  7. data/app/mailers/pay/user_mailer.rb +42 -0
  8. data/app/models/pay/charge.rb +31 -0
  9. data/app/models/pay/subscription.rb +77 -0
  10. data/app/views/pay/user_mailer/receipt.html.erb +20 -0
  11. data/app/views/pay/user_mailer/refund.html.erb +21 -0
  12. data/app/views/pay/user_mailer/subscription_renewing.html.erb +6 -0
  13. data/config/routes.rb +3 -1
  14. data/db/migrate/20170205020145_create_subscriptions.rb +1 -1
  15. data/db/migrate/20170503131610_add_fields_to_users.rb +3 -2
  16. data/db/migrate/20170727235816_create_charges.rb +17 -0
  17. data/lib/generators/pay/email_views_generator.rb +13 -0
  18. data/lib/pay.rb +65 -1
  19. data/lib/pay/billable.rb +54 -24
  20. data/lib/pay/billable/sync_email.rb +41 -0
  21. data/lib/pay/braintree.rb +16 -0
  22. data/lib/pay/braintree/api.rb +30 -0
  23. data/lib/pay/braintree/billable.rb +219 -0
  24. data/lib/pay/braintree/charge.rb +27 -0
  25. data/lib/pay/braintree/subscription.rb +173 -0
  26. data/lib/pay/engine.rb +14 -1
  27. data/lib/pay/receipts.rb +37 -0
  28. data/lib/pay/stripe.rb +17 -0
  29. data/lib/pay/stripe/api.rb +13 -0
  30. data/lib/pay/stripe/billable.rb +143 -0
  31. data/lib/pay/stripe/charge.rb +30 -0
  32. data/lib/pay/stripe/subscription.rb +48 -0
  33. data/lib/pay/stripe/webhooks.rb +39 -0
  34. data/lib/pay/stripe/webhooks/charge_refunded.rb +25 -0
  35. data/lib/pay/stripe/webhooks/charge_succeeded.rb +47 -0
  36. data/lib/pay/stripe/webhooks/customer_deleted.rb +31 -0
  37. data/lib/pay/stripe/webhooks/customer_updated.rb +19 -0
  38. data/lib/pay/stripe/webhooks/source_deleted.rb +19 -0
  39. data/lib/pay/stripe/webhooks/subscription_created.rb +46 -0
  40. data/lib/pay/stripe/webhooks/subscription_deleted.rb +21 -0
  41. data/lib/pay/stripe/webhooks/subscription_renewing.rb +25 -0
  42. data/lib/pay/stripe/webhooks/subscription_updated.rb +35 -0
  43. data/lib/pay/version.rb +1 -1
  44. metadata +124 -30
  45. data/app/models/subscription.rb +0 -59
  46. data/config/initializers/pay.rb +0 -3
  47. data/config/initializers/stripe.rb +0 -1
  48. data/db/development.sqlite3 +0 -0
  49. data/lib/pay/billable/braintree.rb +0 -57
  50. data/lib/pay/billable/stripe.rb +0 -47
  51. data/lib/tasks/pay_tasks.rake +0 -4
@@ -1,3 +0,0 @@
1
- Pay.setup do |config|
2
- # billable_class = "User"
3
- end
@@ -1 +0,0 @@
1
- Stripe.api_key = Rails.application.secrets.stripe_api_key
File without changes
@@ -1,57 +0,0 @@
1
- module Pay
2
- module Billable
3
- module Braintree
4
- # def braintree_customer(token = nil)
5
- # if processor_id?
6
- # result = ::Braintree::PaymentMethod.create(
7
- # customer_id: processor_id,
8
- # payment_method_nonce: token,
9
- # options: { make_default: true }
10
- # )
11
-
12
- # raise StandardError, result.inspect unless result.success?
13
- # ::Braintree::Customer.find(processor_id)
14
- # else
15
- # result = ::Braintree::Customer.create(
16
- # email: email,
17
- # payment_method_nonce: token
18
- # )
19
-
20
- # raise StandardError, result.inspect unless result.success?
21
- # update(processor: 'braintree', processor_id: result.customer.id)
22
-
23
- # result.customer
24
- # end
25
- # end
26
-
27
- # def create_braintree_subscription(name = 'default')
28
- # token = braintree_customer.payment_methods.find(&:default?).token
29
-
30
- # result = ::Braintree::Subscription.create(
31
- # payment_method_token: token,
32
- # plan_id: plan
33
- # )
34
-
35
- # if result.success?
36
- # subscription = subscriptions.create(
37
- # name: name || 'default',
38
- # processor: processor,
39
- # processor_id: result.subscription.id,
40
- # processor_plan: plan,
41
- # trial_ends_at: ,
42
- # quantity: quantity || 1,
43
- # ends_at: nil
44
- # )
45
- # else
46
- # raise StandardError, result.inspect
47
- # end
48
-
49
- # subscription
50
- # end
51
-
52
- # def update_braintree_card(token)
53
- # # Placeholder
54
- # end
55
- end
56
- end
57
- end
@@ -1,47 +0,0 @@
1
- module Pay
2
- module Billable
3
- module Stripe
4
- def stripe_customer
5
- if processor_id?
6
- customer = ::Stripe::Customer.retrieve(processor_id)
7
- else
8
- customer = ::Stripe::Customer.create(email: email, source: card_token)
9
- update(processor: 'stripe', processor_id: customer.id)
10
- end
11
-
12
- customer
13
- end
14
-
15
- def create_stripe_subscription(name, plan)
16
- stripe_sub = stripe_customer.subscriptions.create(plan: plan)
17
- subscription = create_subscription(stripe_sub, 'stripe', name, plan)
18
- subscription
19
- end
20
-
21
- def update_stripe_card(token)
22
- customer = stripe_customer
23
- token = ::Stripe::Token.retrieve(token)
24
-
25
- return if token.card.id == customer.default_source
26
- save_stripe_card(token, customer)
27
- end
28
-
29
- def stripe_subscription(subscription_id)
30
- ::Stripe::Subscription.retrieve(subscription_id)
31
- end
32
-
33
- private
34
-
35
- def save_stripe_card(token, customer)
36
- card = customer.sources.create(source: token.id)
37
- customer.default_source = card.id
38
- customer.save
39
- update_card_on_file(card)
40
- end
41
-
42
- def trial_end_date(stripe_sub)
43
- stripe_sub.trial_end.present? ? Time.at(stripe_sub.trial_end) : nil
44
- end
45
- end
46
- end
47
- end
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :pay do
3
- # # Task goes here
4
- # end