Compare commits

...

2 Commits

Author SHA1 Message Date
Paul Daigle
bcfeb8edb5 fix bug with BTC amounts of more than two decimals 2015-03-05 17:24:11 -05:00
Hamish Eisler
e6bc86bd4b correct BTC validation 2015-03-05 17:20:01 -05:00
3 changed files with 12 additions and 7 deletions

View File

@ -1,3 +1,4 @@
@invoices
Feature: creating an invoice
The user won't get any money
If they can't
@ -10,17 +11,18 @@ Feature: creating an invoice
When the user creates an invoice for <price> <currency>
Then they should recieve an invoice in response for <price> <currency>
Examples:
| price | currency |
| "5.23" | "USD" |
| price | currency |
| "5.23" | "USD" |
| "10.21" | "EUR" |
| "0.225" | "BTC" |
Scenario Outline: The invoice contains illegal characters
When the user creates an invoice for <price> <currency>
Then they will receive a BitPay::ArgumentError matching <message>
Examples:
| price | currency | message |
| "5,023" | "USD" | "Price must be formatted as a float" |
| "3.21" | "EaUR" | "Currency is invalid." |
| "5,023" | "USD" | "Price must be formatted as a float" |
| "3.21" | "EaUR" | "Currency is invalid." |
| "" | "USD" | "Price must be formatted as a float" |
| "Ten" | "USD" | "Price must be formatted as a float" |
| "10" | "" | "Currency is invalid." |
| "10" | "" | "Currency is invalid." |

View File

@ -61,7 +61,10 @@ module BitPay
# Defaults to pos facade, also works with merchant facade
#
def create_invoice(price:, currency:, facade: 'pos', params:{})
raise BitPay::ArgumentError, "Illegal Argument: Price must be formatted as a float" unless ( price.is_a?(Numeric) || /^[[:digit:]]+(\.[[:digit:]]{2})?$/.match(price) )
raise BitPay::ArgumentError, "Illegal Argument: Price must be formatted as a float" unless
price.is_a?(Numeric) ||
/^[[:digit:]]+(\.[[:digit:]]{2})?$/.match(price) ||
currency == 'BTC' && /^[[:digit:]]+(\.[[:digit:]]{1,6})?$/.match(price)
raise BitPay::ArgumentError, "Illegal Argument: Currency is invalid." unless /^[[:upper:]]{3}$/.match(currency)
params.merge!({price: price, currency: currency})
response = send_request("POST", "invoices", facade: facade, params: params)

View File

@ -3,5 +3,5 @@
# or https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
module BitPay
VERSION = '2.3.1'
VERSION = '2.3.2'
end