bitpay / ruby-client

Powerful, flexible, lightweight SDK for the BitPay Bitcoin Payment Gateway API.
MIT License
79 stars 64 forks source link

add refunds and cucumber tests with documentation #38

Closed heisler3030 closed 9 years ago

heisler3030 commented 9 years ago

Re-adds refunds capability with associated feature specs. Also adds "cancel_refund" method and associated documentation.

As a side effect, the tests now request and store a merchant token, under the new_client_from_stored_values method

Testing refunds requires a pre-seeded transaction with 6+ transactions. This has been created under the bitpayrubyclient@gmail.com test account and specified in constants.rb. This can be overridden by setting the REFUND_TRANSACTION environment variable to a qualified transaction belonging to a different test user.

If you want to use the defaults, just use

source ./spec/set_constants.sh https://test.bitpay.com bitpayrubyclient@gmail.com Bc*#Qlz2JPK2

to pre-wire your test environment

ionux commented 9 years ago

Nice work on the commit! PhantomJS appears to have crashed the build, though:

State has changed to %c%s(%s) %cfrom %c%s(%s). color: blue menu.dashboard {"page":"home","params":null} color: auto color: blue  {}
PhantomJS has crashed. Please read the crash reporting guide at https://github.com/ariya/phantomjs/wiki/Crash-Reporting and file a bug report at https://github.com/ariya/phantomjs/issues/new with the crash dump file attached: /tmp/2082ed6c-65b4-ed8c-5da08245-60335f40.dmp
    Given the user pairs with BitPay with a valid pairing code # features/step_definitions/keygen_steps.rb:4
      PhantomJS client died while processing {"name":"visit","args":["https://test.bitpay.com/api-tokens"]} (Capybara::Poltergeist::DeadClient)
      ./features/step_definitions/step_helpers.rb:26:in `get_claim_code_from_server'
      ./features/step_definitions/keygen_steps.rb:5:in `/^the user pairs with BitPay(?: with a valid pairing code|)$/'
      features/pairing.feature:7:in `Given the user pairs with BitPay with a valid pairing code'
    Then the user is paired with BitPay                        # features/step_definitions/keygen_steps.rb:30
  Scenario: the client initiates pairing          # features/pairing.feature:10
FLASH Failed to load.
    Given the user performs a client-side pairing # features/step_definitions/keygen_steps.rb:55
      Timed out waiting for response to {"name":"visit","args":["https://test.bitpay.com"]}. It's possible that this happened because something took a very long time (for example a page load was slow). If so, setting the Poltergeist :timeout option to a higher value will help (see the docs for details). If increasing the timeout does not help, this is probably a bug in Poltergeist - please report it to the issue tracker. (Capybara::Poltergeist::TimeoutError)
      ./features/step_definitions/step_helpers.rb:34:in `approve_token_on_server'
      ./features/step_definitions/keygen_steps.rb:61:in `/^the user performs a client\-side pairing$/'
      features/pairing.feature:11:in `Given the user performs a client-side pairing'
    Then the user has a merchant token            # features/step_definitions/keygen_steps.rb:64
heisler3030 commented 9 years ago

yeah this has been a recurring problem. Will experiment with some sleeps and adjusting the timeout per Paul's suggestion.

philosodad commented 9 years ago

The last time that Phantom was crashing it was a gem version issue. After looking this over, I don't think this is a sleeps or timeout issue.

heisler3030 commented 9 years ago

Doubled the timeout to 10 seconds... unclear if it was this or just a lucky roll of the dice but the CI passed! I also removed the DELETE branch as discussed in the comments.

ionux commented 9 years ago

Excellent work, guys! This is really looking solid!

heisler3030 commented 9 years ago

So the good news is that the refunds endpoint actually does proper validation for us:

client.refund_invoice(id: 'TKKgh3LJuRXnq6hSR3hhNR', params: {amount: "thirdy", currency: 'USDAY'})
BitPay::BitPayError: 500: Currency USDAY does not match the currency with which this invoice was created (USD) or BTC.

client.refund_invoice(id: 'TKKgh3LJuRXnq6hSR3hhNR', params: {amount: "thirdy", currency: 'USD'})
BitPay::BitPayError: 500: Invalid amount specified

I have a small commit for the BTC fix that I will submit shortly, after giving time for the test.bitpay.com rate limiter to expire...