Skip to content
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
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/monopay-ruby/configuration.rb
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
Copy link
Owner

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"

@min_value = ENV["MIN_VALUE"] || 1 # 0.01 - minimun valid amount in Monobank
end
end
16 changes: 13 additions & 3 deletions lib/monopay-ruby/invoices/simple_invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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}"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must be

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

або allowed to use only a BigDecimal or Integer price

end
end

def make_discount(discount)
sum = (@amount * (1 - discount)).to_i

@amount = [sum, MonopayRuby.configuration.min_value].max
end
end
end
end
1 change: 0 additions & 1 deletion lib/monopay-ruby/webhooks/public_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
require "base64"
require "json"

require "pry"
module MonopayRuby
module Webhooks
class PublicKey < MonopayRuby::Base
Expand Down
Loading