forked from pay-rails/pay
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Continues implementiong new Stripe module
- Loading branch information
1 parent
880e84f
commit 130052a
Showing
15 changed files
with
169 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
AllCops: | ||
Exclude: | ||
- db/migrate/* | ||
- lib/pay/version.rb | ||
- test/dummy/**/* | ||
- test/test_helper.rb | ||
|
||
Documentation: | ||
Enabled: false | ||
|
||
ClassAndModuleChildren: | ||
Enabled: false | ||
|
||
ClassVars: | ||
Enabled: false | ||
|
||
SpecialGlobalVars: | ||
Enabled: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,57 @@ | ||
module Pay | ||
module Billable | ||
module Braintree | ||
|
||
def braintree_customer(token=nil) | ||
if processor_id? | ||
result = Braintree::PaymentMethod.create( | ||
customer_id: processor_id, | ||
payment_method_nonce: card_token, | ||
options: {make_default: true} | ||
) | ||
|
||
if result.success? | ||
raise StandardError, result.inspect | ||
else | ||
customer = Braintree::Customer.find(processor_id) | ||
end | ||
|
||
else | ||
result = Braintree::Customer.create( | ||
email: email, | ||
payment_method_nonce: card_token, | ||
) | ||
|
||
if result.success? | ||
customer = result.customer | ||
update(processor: "braintree", processor_id: customer.id) | ||
else | ||
raise StandardError, result.inspect | ||
end | ||
|
||
customer | ||
end | ||
end | ||
|
||
def create_braintree_subscription(name="default") | ||
token = braintree_customer.payment_methods.find{ |pm| pm.default? }.token | ||
result = Braintree::Subscription.create( | ||
payment_method_token: token, | ||
plan_id: plan, | ||
) | ||
|
||
if result.success? | ||
subscription = subscriptions.create( | ||
name: name || "default", | ||
processor: processor, | ||
processor_id: result.subscription.id, | ||
processor_plan: plan, | ||
trial_ends_at: stripe_sub.trial_end.present? ? Time.at(stripe_sub.trial_end) : nil, | ||
quantity: quantity || 1, | ||
ends_at: nil | ||
) | ||
else | ||
raise StandardError, result.inspect | ||
end | ||
|
||
subscription | ||
end | ||
|
||
def update_braintree_card(token) | ||
end | ||
|
||
# def braintree_customer(token = nil) | ||
# if processor_id? | ||
# result = ::Braintree::PaymentMethod.create( | ||
# customer_id: processor_id, | ||
# payment_method_nonce: token, | ||
# options: { make_default: true } | ||
# ) | ||
|
||
# raise StandardError, result.inspect unless result.success? | ||
# ::Braintree::Customer.find(processor_id) | ||
# else | ||
# result = ::Braintree::Customer.create( | ||
# email: email, | ||
# payment_method_nonce: token | ||
# ) | ||
|
||
# raise StandardError, result.inspect unless result.success? | ||
# update(processor: 'braintree', processor_id: result.customer.id) | ||
|
||
# result.customer | ||
# end | ||
# end | ||
|
||
# def create_braintree_subscription(name = 'default') | ||
# token = braintree_customer.payment_methods.find(&:default?).token | ||
|
||
# result = ::Braintree::Subscription.create( | ||
# payment_method_token: token, | ||
# plan_id: plan | ||
# ) | ||
|
||
# if result.success? | ||
# subscription = subscriptions.create( | ||
# name: name || 'default', | ||
# processor: processor, | ||
# processor_id: result.subscription.id, | ||
# processor_plan: plan, | ||
# trial_ends_at: , | ||
# quantity: quantity || 1, | ||
# ends_at: nil | ||
# ) | ||
# else | ||
# raise StandardError, result.inspect | ||
# end | ||
|
||
# subscription | ||
# end | ||
|
||
# def update_braintree_card(token) | ||
# # Placeholder | ||
# end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.