Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,19 @@ params = Cryptopay::CoinWithdrawalParams.new(
force_commit: true
)

result = client.coin_withdrawals.create(params)
p result # => <CoinWithdrawalResult data=...>
# New amounts example
params = Cryptopay::CoinWithdrawalParams.new(
address: '2Mz3bcjSVHG8uQJpNjmCxp24VdTjwaqmFcJ',
amount: '100.0',
amount_currency: 'EUR',
received_currency: 'BTC',
amount_includes_processing_fee: true,
amount_includes_network_fee: true,
force_commit: true
)

result = client.coin_withdrawals.create(params)
p result # => <CoinWithdrawalResult data=...>
```
Expand Down Expand Up @@ -402,9 +415,8 @@ p result # => <InvoiceRecalculationResult data=...>

```ruby
invoice_id = '7e274430-e20f-4321-8748-20824287ae44'
invoice_refund_params = Cryptopay::InvoiceRefundParams.new(address: '0xf3532c1fd002665ec54d46a50787e0c69c76cd44')

result = client.invoices.create_refund(invoice_id, invoice_refund_params)
result = client.invoices.create_refund(invoice_id)
p result # => <InvoiceRefundResult data=...>
```

Expand Down
2 changes: 1 addition & 1 deletion lib/cryptopay/api/coin_withdrawals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def commit(coin_withdrawal_id, _opts = {})
end

# Create a withdrawal
# To create a withdrawal you need to use either &#x60;charged_amount&#x60;, &#x60;charged_amount_to_send&#x60; or &#x60;received_amount&#x60; parameters in your request body.
# To create a withdrawal you must provide either the legacy amount fields (&#x60;charged_amount&#x60;, &#x60;charged_amount_to_send&#x60;, &#x60;received_amount&#x60;) or the new amount fields (&#x60;amount&#x60;, &#x60;amount_currency&#x60;, &#x60;amount_includes_processing_fee&#x60;, &#x60;amount_includes_network_fee&#x60;). Mixing legacy and new amount fields in one request is not allowed.
# @param coin_withdrawal_params [CoinWithdrawalParams]
# @param [Hash] opts the optional parameters
# @return [CoinWithdrawalResult]
Expand Down
8 changes: 4 additions & 4 deletions lib/cryptopay/api/invoices.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ def create_recalculation(invoice_id, invoice_recalculation_params, _opts = {})
end

# Create invoice refund
# This endpoint allows you to create invoice refunds.
# This endpoint allows you to create invoice refunds to your cryptocurrency account.
# @param invoice_id [String] Invoice ID
# @param invoice_refund_params [InvoiceRefundParams]
# @param [Hash] opts the optional parameters
# @option opts [Object] :body
# @return [InvoiceRefundResult]
def create_refund(invoice_id, invoice_refund_params, _opts = {})
def create_refund(invoice_id, opts = {})
path = '/api/invoices/{invoice_id}/refunds'
path = path.sub('{invoice_id}', CGI.escape(invoice_id.to_s))

req = Request.new(
method: :post,
path: path,
body_params: invoice_refund_params
body_params: opts[:body] || {}
)

connection.call(req, return_type: InvoiceRefundResult)
Expand Down
7 changes: 1 addition & 6 deletions lib/cryptopay/models/beneficiary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def type
@attributes[:type]
end

# The registered name of the company for a `legal_person` or the full name for a `natural_person`.
# The registered name of the company for a `legal_person` or the full name for a `natural_person`. Note that only following symbols will be stored, regardless of the input value: letters of any language, digits `0-9`, symbols `&` `!` `,` `.` `-` and single spaces. Symbols `\\`, `/`, newlines and tabs will be replaced with spaces. Everything else will be removed, including double spaces and spaces in the end.
def name
@attributes[:name]
end
Expand All @@ -66,11 +66,6 @@ def invalid_properties
properties.push('invalid value for "name", the character length must be smaller than or equal to 100.')
end

pattern = Regexp.new(/^[a-zA-Z0-9\s-]+$/)
properties.push("invalid value for \"name\", must conform to the pattern #{pattern}.") if name !~ pattern

properties.push('invalid value for "address", address cannot be nil.') if address.nil?

address&.invalid_properties&.each do |prop|
properties.push("invalid value for \"address\": #{prop}")
end
Expand Down
4 changes: 1 addition & 3 deletions lib/cryptopay/models/beneficiary_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ def post_code
def invalid_properties
properties = []

properties.push('invalid value for "country", country cannot be nil.') if country.nil?

if country.to_s.length > 2
if !country.nil? && country.to_s.length > 2
properties.push('invalid value for "country", the character length must be smaller than or equal to 2.')
end

Expand Down
32 changes: 30 additions & 2 deletions lib/cryptopay/models/coin_withdrawal_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ class CoinWithdrawalParams
'network_fee_level': :network_fee_level,
'force_commit': :force_commit,
'travel_rule_compliant': :travel_rule_compliant,
'beneficiary': :beneficiary
'beneficiary': :beneficiary,
'amount': :amount,
'amount_currency': :amount_currency,
'amount_includes_processing_fee': :amount_includes_processing_fee,
'amount_includes_network_fee': :amount_includes_network_fee
},
types: {
'address': :String,
Expand All @@ -35,7 +39,11 @@ class CoinWithdrawalParams
'network_fee_level': :NetworkFeeLevel,
'force_commit': :Boolean,
'travel_rule_compliant': :Boolean,
'beneficiary': :Beneficiary
'beneficiary': :Beneficiary,
'amount': :Decimal,
'amount_currency': :String,
'amount_includes_processing_fee': :Boolean,
'amount_includes_network_fee': :Boolean
},
nullables: %i[
charged_amount
Expand Down Expand Up @@ -122,6 +130,26 @@ def beneficiary
@attributes[:beneficiary]
end

# Transaction amount for new calculation
def amount
@attributes[:amount]
end

# An currency of the transaction amount
def amount_currency
@attributes[:amount_currency]
end

# Whether the amount includes processing fee
def amount_includes_processing_fee
@attributes[:amount_includes_processing_fee]
end

# Whether the amount includes network fee
def amount_includes_network_fee
@attributes[:amount_includes_network_fee]
end

# Show invalid properties with the reasons. Usually used together with valid?
# @return Array for valid properties with the reasons
def invalid_properties
Expand Down
1 change: 0 additions & 1 deletion lib/cryptopay/require.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
require 'cryptopay/models/invoice_recalculation_result'
require 'cryptopay/models/invoice_refund'
require 'cryptopay/models/invoice_refund_list_result'
require 'cryptopay/models/invoice_refund_params'
require 'cryptopay/models/invoice_refund_result'
require 'cryptopay/models/invoice_result'
require 'cryptopay/models/invoice_status'
Expand Down
2 changes: 1 addition & 1 deletion lib/cryptopay/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Cryptopay
VERSION = '2.2.0'
VERSION = '3.0.0'
end
13 changes: 13 additions & 0 deletions spec/cryptopay/api/coin_withdrawals_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@
force_commit: true
)

result = client.coin_withdrawals.create(params)
p result # => <CoinWithdrawalResult data=...>
# New amounts example
params = Cryptopay::CoinWithdrawalParams.new(
address: '2Mz3bcjSVHG8uQJpNjmCxp24VdTjwaqmFcJ',
amount: '100.0',
amount_currency: 'EUR',
received_currency: 'BTC',
amount_includes_processing_fee: true,
amount_includes_network_fee: true,
force_commit: true
)

result = client.coin_withdrawals.create(params)
p result # => <CoinWithdrawalResult data=...>

Expand Down
3 changes: 1 addition & 2 deletions spec/cryptopay/api/invoices_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@
describe '#create_refund' do
it 'returns InvoiceRefundResult', :aggregate_failures, vcr: 'api/invoices/create_refund' do
invoice_id = '7e274430-e20f-4321-8748-20824287ae44'
invoice_refund_params = Cryptopay::InvoiceRefundParams.new(address: '0xf3532c1fd002665ec54d46a50787e0c69c76cd44')

result = client.invoices.create_refund(invoice_id, invoice_refund_params)
result = client.invoices.create_refund(invoice_id)
p result # => <InvoiceRefundResult data=...>

expect(result).to be_a(Cryptopay::InvoiceRefundResult)
Expand Down
63 changes: 63 additions & 0 deletions spec/support/cassettes/api/coin_withdrawals/create.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.