-
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 3 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
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_value | ||
|
||
def initialize | ||
@api_token = ENV["MONOBANK_API_TOKEN"] # note ability to use ENV variable in docs | ||
@min_value = ENV["MIN_VALUE"] || 1 # 0.01 - minimun valid amount in Monobank | ||
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 |
---|---|---|
|
@@ -30,12 +30,14 @@ def initialize(redirect_url = nil, webhook_url = nil) | |
# @param [String] destination - additional info about payment | ||
# @param [String] reference - bill number or other reference | ||
# @return [Boolean] true if invoice was created successfully, false otherwise | ||
def create(amount, destination: nil, reference: nil) | ||
def create(amount, discount=1, destination: nil, reference: nil) | ||
begin | ||
@amount = convert_to_cents(amount) | ||
@amount = [convert_to_cents(amount), MonopayRuby.configuration.min_value].max | ||
@destination = destination | ||
@reference = reference | ||
|
||
make_discount(discount) if discount < 1 | ||
|
||
response = RestClient.post(API_CREATE_INVOICE_URL, request_body, headers) | ||
response_body = JSON.parse(response.body) | ||
|
||
|
@@ -75,10 +77,18 @@ def request_body | |
def convert_to_cents(amount) | ||
if amount.is_a?(BigDecimal) | ||
Money.from_amount(amount, DEFAULT_CURRENCY).cents | ||
else | ||
elsif amount.is_a?(Integer) | ||
amount | ||
else | ||
raise TypeError, "expected amount will be an Integer or BigDecimal, got #{amount.class}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. must be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. або |
||
end | ||
end | ||
|
||
def make_discount(discount) | ||
sum = (@amount * (1 - discount)).to_i | ||
|
||
@amount = [sum, MonopayRuby.configuration.min_value].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
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.
можеш цей комент забрати і буду просити створити розділ
Configuration
в рідмі, також вкажи там, що можна передати такий параметер і яке значення по дефолту та яке мінімальне, також дай рейз, якщо задане значення меньше мінімального, щось типуConfiguration value error: minimal allowed value is 0.01, your is "0"