-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature/ability to apply coupon for price #2
Open
AndriyAndriyovuch
wants to merge
15
commits into
master
Choose a base branch
from
feature/ability_to_apply_coupon_for_price
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
bf9bc3b
add min_value to config, use BigDecimal to send amount to Monobank, r…
AndriyAndriyovuch 84494c2
added validation to amount type with raise TypeError, added min_value…
AndriyAndriyovuch d0c4a16
add check for minimum value if discount is unavailable
AndriyAndriyovuch 256273a
add ability to make discount by fixed sum or percents
AndriyAndriyovuch fe5c1a8
add ability to use default value as an Bigdecimal, update Readme
AndriyAndriyovuch f47258d
update Readme
AndriyAndriyovuch 91e2a66
move discount, covertaion and validation to services
AndriyAndriyovuch 23c59c3
add empty lines
AndriyAndriyovuch c9cf3ba
merged from master
AndriyAndriyovuch e272515
used named params in create payment method, fix README with Grammarly
AndriyAndriyovuch b26feb0
added named attributes
AndriyAndriyovuch 8f92a53
added named params to tests
AndriyAndriyovuch 4441334
added tests for invoice
AndriyAndriyovuch 1851952
Update README.md
AndriyAndriyovuch 9a02c77
Update README.md
AndriyAndriyovuch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,7 +1,8 @@ | ||
class MonopayRuby::Configuration | ||
attr_accessor :api_token | ||
attr_accessor :api_token, :min_price | ||
|
||
def initialize | ||
@api_token = ENV["MONOBANK_API_TOKEN"] # note ability to use ENV variable in docs | ||
@api_token = ENV["MONOBANK_API_TOKEN"] | ||
@min_price = ENV["MIN_PRICE"] || 1 | ||
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
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,9 @@ | ||
module MonopayRuby | ||
module Services | ||
class BaseService | ||
def self.call(*args) | ||
new(*args).call | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require "money" | ||
require "bigdecimal" | ||
|
||
module MonopayRuby | ||
module Services | ||
class ConvertAmount < BaseService | ||
attr_reader :amount, :currency | ||
|
||
def initialize(amount, currency) | ||
@amount = amount | ||
@currency = currency | ||
end | ||
|
||
def call | ||
if amount.is_a?(BigDecimal) | ||
Money.from_amount(amount, currency).cents | ||
elsif amount.is_a?(Integer) | ||
amount | ||
else | ||
raise TypeError, "allowed to use only a BigDecimal or Integer type" | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module MonopayRuby | ||
module Services | ||
class Discount < BaseService | ||
attr_reader :amount, :discount, :discount_is_fixed, :min_amount | ||
|
||
def initialize(amount, discount, discount_is_fixed, min_amount) | ||
@amount = amount | ||
@discount = discount | ||
@discount_is_fixed = discount_is_fixed | ||
@min_amount = min_amount | ||
end | ||
|
||
def call | ||
if discount_is_fixed | ||
sum = amount - discount | ||
else | ||
sum = amount * (1 - (discount.to_f / 100)) | ||
end | ||
|
||
[sum.to_i, min_amount].max | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require "bigdecimal" | ||
|
||
module MonopayRuby | ||
module Services | ||
class ValidateValue < BaseService | ||
attr_reader :amount, :currency, :type | ||
|
||
def initialize(amount, currency, type='Amount') | ||
@amount = amount | ||
@currency = currency | ||
@type = type | ||
end | ||
|
||
def call | ||
if amount.is_a?(Integer) || amount.is_a?(BigDecimal) | ||
if amount > 0 | ||
MonopayRuby::Services::ConvertAmount.call(amount, currency) | ||
else | ||
raise ValueError, "#{type} must be greater than 0" | ||
end | ||
else | ||
raise TypeError, "#{type} is allowed to be Integer or BigDecimal, got #{amount.class}" unless amount.is_a?(Integer) || amount.is_a?(BigDecimal) | ||
end | ||
end | ||
|
||
private | ||
|
||
def name(var) | ||
binding.local_variables.each do |name| | ||
value = binding.local_variable_get(name) | ||
return name.to_s if value == var | ||
end | ||
nil | ||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
щось трохи забагато аргументів, по конвеншинам так краще не робити, ну передавати можна, але от явно прописаних вже забагато, макс 3 гуд є, чи близько того