pay 0.0.2 → 1.0.0.beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pay might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/MIT-LICENSE +1 -1
- data/README.md +256 -29
- data/Rakefile +1 -6
- data/app/controllers/pay/webhooks/braintree_controller.rb +56 -0
- data/app/jobs/pay/email_sync_job.rb +12 -0
- data/app/mailers/pay/user_mailer.rb +42 -0
- data/app/models/pay/charge.rb +31 -0
- data/app/models/pay/subscription.rb +77 -0
- data/app/views/pay/user_mailer/receipt.html.erb +20 -0
- data/app/views/pay/user_mailer/refund.html.erb +21 -0
- data/app/views/pay/user_mailer/subscription_renewing.html.erb +6 -0
- data/config/routes.rb +3 -1
- data/db/migrate/20170205020145_create_subscriptions.rb +1 -1
- data/db/migrate/20170503131610_add_fields_to_users.rb +3 -2
- data/db/migrate/20170727235816_create_charges.rb +17 -0
- data/lib/generators/pay/email_views_generator.rb +13 -0
- data/lib/pay.rb +65 -1
- data/lib/pay/billable.rb +54 -24
- data/lib/pay/billable/sync_email.rb +41 -0
- data/lib/pay/braintree.rb +16 -0
- data/lib/pay/braintree/api.rb +30 -0
- data/lib/pay/braintree/billable.rb +219 -0
- data/lib/pay/braintree/charge.rb +27 -0
- data/lib/pay/braintree/subscription.rb +173 -0
- data/lib/pay/engine.rb +14 -1
- data/lib/pay/receipts.rb +37 -0
- data/lib/pay/stripe.rb +17 -0
- data/lib/pay/stripe/api.rb +13 -0
- data/lib/pay/stripe/billable.rb +143 -0
- data/lib/pay/stripe/charge.rb +30 -0
- data/lib/pay/stripe/subscription.rb +48 -0
- data/lib/pay/stripe/webhooks.rb +39 -0
- data/lib/pay/stripe/webhooks/charge_refunded.rb +25 -0
- data/lib/pay/stripe/webhooks/charge_succeeded.rb +47 -0
- data/lib/pay/stripe/webhooks/customer_deleted.rb +31 -0
- data/lib/pay/stripe/webhooks/customer_updated.rb +19 -0
- data/lib/pay/stripe/webhooks/source_deleted.rb +19 -0
- data/lib/pay/stripe/webhooks/subscription_created.rb +46 -0
- data/lib/pay/stripe/webhooks/subscription_deleted.rb +21 -0
- data/lib/pay/stripe/webhooks/subscription_renewing.rb +25 -0
- data/lib/pay/stripe/webhooks/subscription_updated.rb +35 -0
- data/lib/pay/version.rb +1 -1
- metadata +124 -30
- data/app/models/subscription.rb +0 -59
- data/config/initializers/pay.rb +0 -3
- data/config/initializers/stripe.rb +0 -1
- data/db/development.sqlite3 +0 -0
- data/lib/pay/billable/braintree.rb +0 -57
- data/lib/pay/billable/stripe.rb +0 -47
- data/lib/tasks/pay_tasks.rake +0 -4
data/config/initializers/pay.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Stripe.api_key = Rails.application.secrets.stripe_api_key
|
data/db/development.sqlite3
DELETED
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
|
data/lib/pay/billable/stripe.rb
DELETED
@@ -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
|
data/lib/tasks/pay_tasks.rake
DELETED