Skip to content
This repository was archived by the owner on May 29, 2025. It is now read-only.

Commit 4563a8b

Browse files
author
Paul Daigle
committed
Minor modifications to v2.4 functionality.
1 parent 5ca3bd7 commit 4563a8b

9 files changed

Lines changed: 22 additions & 20 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ pkg
77
.ruby-gemset
88
*.swo
99
*.swp
10-
bitpaykey.pem
10+
bitpaykey.pem
11+
constants.txt

GUIDE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,10 @@ API Documentation is available on the [BitPay site](https://bitpay.com/api).
194194

195195
In order to run the tests, you must have phantomjs installed and on your PATH.
196196

197-
The tests require that environment variables be set for the bitpay server, user name, and password. First run:
197+
The tests require that environment variables be set for the bitpay server, user name, password, an invoice id for refunds and a valid testnet bitcoin address for refunds. First run:
198198

199199
```bash
200-
$ source ./spec/set_constants.sh https://test.bitpay.com <yourusername> <yourpassword>
200+
$ source ./spec/set_constants.sh https://test.bitpay.com <yourusername> <yourpassword> <a-confirmed-invoice-id> <a-valid-testnet-address>
201201
$ bundle install
202202
$ bundle exec rake
203203
```

config/constants.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
DASHBOARD_URL = "#{ROOT_ADDRESS}/dashboard/merchant/home"
1212

1313
# Specify a bitpay txid which has 6+ confirmations. Default belongs to 'bitpayrubyclient@gmail.com' test account
14-
REFUND_TRANSACTION = ENV['REFUND_TRANSACTION'] || 'TKKgh3LJuRXnq6hSR3hhNR'
15-
REFUND_ADDRESS = ENV['REFUND_ADDRESS'] || '2NCMQ8LRu71SfLMYTi8qotg6VRpBZynpFAh' # Hamish's Testnet Copay Wallet
14+
REFUND_TRANSACTION = ENV['REFUND_TRANSACTION']
15+
REFUND_ADDRESS = ENV['REFUND_ADDRESS']
1616

1717
unless
1818
ROOT_ADDRESS &&

features/step_definitions/refund_steps.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
Given(/^the user requests a specific refund$/) do
1212
client = new_client_from_stored_values
13-
@response = client.get_refund(id: REFUND_TRANSACTION, request_id: @refund_id)
13+
@response = client.get_refund(invoice_id: REFUND_TRANSACTION, request_id: @refund_id)
1414
end
1515

1616
Then(/^they will receive the refund$/) do
@@ -29,9 +29,9 @@
2929
Given(/^a properly formatted cancellation request$/) do
3030
client = new_client_from_stored_values
3131
@refund_id = client.get_all_refunds_for_invoice(id: REFUND_TRANSACTION).first["id"]
32-
@response = client.cancel_refund(id: REFUND_TRANSACTION, request_id: @refund_id)
32+
@response = client.cancel_refund(invoice_id: REFUND_TRANSACTION, request_id: @refund_id)
3333
end
3434

3535
Then(/^the refund will be cancelled$/) do
3636
expect(@response).to eq("Success")
37-
end
37+
end

features/step_definitions/step_helpers.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ def new_client_from_stored_values
6464
unless client.verify_tokens then
6565
raise "Locally stored tokens are invalid, please remove #{BitPay::TOKEN_FILE_PATH}" end
6666
else
67-
claim_code = get_claim_code_from_server
6867
pem = BitPay::KeyUtils.generate_pem
6968
client = BitPay::SDK::Client.new(api_uri: ROOT_ADDRESS, pem: pem, insecure: true)
7069
sleep 1 # rate limit compliance

lib/bitpay/client.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ def get_all_refunds_for_invoice(id:)
125125
# @example:
126126
# client.get_refund(id: 'JB49z2MsDH7FunczeyDS8j', request_id: '4evCrXq4EDXk4oqDXdWQhX')
127127
#
128-
def get_refund(id:, request_id:)
129-
urlpath = "invoices/#{id}/refunds/#{request_id}"
130-
invoice = get_invoice(id: id)
128+
def get_refund(invoice_id:, request_id:)
129+
urlpath = "invoices/#{invoice_id}/refunds/#{request_id}"
130+
invoice = get_invoice(id: invoice_id)
131131
get(path: urlpath, token: invoice["token"])
132132
end
133133

@@ -137,9 +137,9 @@ def get_refund(id:, request_id:)
137137
# @example:
138138
# client.cancel_refund(id: 'JB49z2MsDH7FunczeyDS8j', request_id: '4evCrXq4EDXk4oqDXdWQhX')
139139
#
140-
def cancel_refund(id:, request_id:)
141-
urlpath = "invoices/#{id}/refunds/#{request_id}"
142-
refund = get_refund(id: id, request_id: request_id)
140+
def cancel_refund(invoice_id:, request_id:)
141+
urlpath = "invoices/#{invoice_id}/refunds/#{request_id}"
142+
refund = get_refund(invoice_id: invoice_id, request_id: request_id)
143143
delete(path: urlpath, token: refund["token"])
144144
end
145145

lib/bitpay/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
# or https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
44

55
module BitPay
6-
VERSION = '2.3.1'
6+
VERSION = '2.4.0'
77
end

spec/client_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ def tokens
151151
before {stub_const('ENV', {'BITPAY_PEM' => PEM})}
152152
it { is_expected.to respond_to(:get_refund) }
153153
it 'should get the token for the invoice' do
154-
bitpay_client.get_refund(id: 'TEST_INVOICE_ID', request_id: 'TEST_REQUEST_ID')
154+
bitpay_client.get_refund(invoice_id: 'TEST_INVOICE_ID', request_id: 'TEST_REQUEST_ID')
155155
expect(WebMock).to have_requested :get, "#{BitPay::TEST_API_URI}/invoices/TEST_INVOICE_ID?token=MERCHANT_TOKEN"
156156
end
157157
it 'should GET a single refund' do
158-
bitpay_client.get_refund(id: 'TEST_INVOICE_ID', request_id: 'TEST_REQUEST_ID')
158+
bitpay_client.get_refund(invoice_id: 'TEST_INVOICE_ID', request_id: 'TEST_REQUEST_ID')
159159
expect(WebMock).to have_requested :get, "#{BitPay::TEST_API_URI}/invoices/TEST_INVOICE_ID/refunds/TEST_REQUEST_ID?token=MERCHANT_INVOICE_TOKEN"
160160
end
161161
end

spec/set_constants.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ export RCTESTUSER=$2
66
echo $RCTESTUSER
77
export RCTESTPASSWORD=$3
88
echo $RCTESTPASSWORD
9-
export PRIV_KEY=$4
10-
echo $PRIV_KEY
9+
export REFUND_TRANSACTION=$4
10+
echo $REFUND_TRANSACTION
11+
export REFUND_ADDRESS=$5
12+
echo $REFUND_ADDRESS

0 commit comments

Comments
 (0)