Skip to content

Commit

Permalink
Support :test_mode parameter in options hash
Browse files Browse the repository at this point in the history
  • Loading branch information
harrylewis committed Mar 9, 2024
1 parent 9ba96a0 commit 44b5e35
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased

- Support passing `:test_mode` parameter into `options` hash for all operations.

## 1.0.0 (2023-11-27)

- Interact with the Payrix API!
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@ merchant.members # => [...}

#### Per Request Configuration

Pass in `:api_key` to set the API key used per request.
Set the following configuration parameters per request.

- `:api_key` - Set the API key used.
- `:test_mode` - Set `true` to use the Sandvox environment, and `false` to use the Production environment.

```ruby
Payrix::Merchant.retrieve('t1_mer_620acd189522582b3fb7849', { api_key: 'b442...' })
Expand Down
2 changes: 1 addition & 1 deletion lib/payrix/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Payrix
# The Payrix::Client is used both internally and externally to initiate API requests to the Payrix API.
class Client
def request(method:, resource:, data: {}, filters: {}, options: {})
url = Payrix.configuration.url
url = Payrix.configuration.url(options[:test_mode])

page_number = Payrix::RequestOptions::Page::Number.construct(options[:page])
page_limit = Payrix::RequestOptions::Page::Limit.construct(options[:limit])
Expand Down
12 changes: 8 additions & 4 deletions spec/lib/payrix/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
WebMock
.stub_request(
:get,
'https://api.payrix.com/txns?page[number]=1&page[limit]=10&expand[merchant][]=',
'https://test-api.payrix.com/txns?page[number]=1&page[limit]=10&expand[merchant][]=',
)
.with(
headers: {
Expand Down Expand Up @@ -68,6 +68,7 @@
limit: 10,
expand: ['merchant'],
api_key: 'custom-key',
test_mode: true,
},
)

Expand Down Expand Up @@ -110,7 +111,7 @@
it 'supports advanced requests' do
stub =
WebMock
.stub_request(:post, 'https://api.payrix.com/txns?expand[merchant][]=')
.stub_request(:post, 'https://test-api.payrix.com/txns?expand[merchant][]=')
.with(
headers: {
'Content-Type' => 'application/json',
Expand Down Expand Up @@ -142,6 +143,7 @@
options: {
expand: ['merchant'],
api_key: 'custom-key',
test_mode: true,
},
)

Expand Down Expand Up @@ -192,7 +194,7 @@
it 'supports advanced requests' do
stub =
WebMock
.stub_request(:put, 'https://api.payrix.com/txns/t1_txn_64026b07cc6a79dd5cfd0da')
.stub_request(:put, 'https://test-api.payrix.com/txns/t1_txn_64026b07cc6a79dd5cfd0da')
.with(
headers: {
'Content-Type' => 'application/json',
Expand Down Expand Up @@ -223,6 +225,7 @@
},
options: {
api_key: 'custom-key',
test_mode: true,
},
)

Expand Down Expand Up @@ -261,7 +264,7 @@
it 'supports advanced requests' do
stub =
WebMock
.stub_request(:delete, 'https://api.payrix.com/txns/t1_txn_64026b07cc6a79dd5cfd0da')
.stub_request(:delete, 'https://test-api.payrix.com/txns/t1_txn_64026b07cc6a79dd5cfd0da')
.with(
headers: {
'Content-Type' => 'application/json',
Expand All @@ -286,6 +289,7 @@
resource: 'txns/t1_txn_64026b07cc6a79dd5cfd0da',
options: {
api_key: 'custom-key',
test_mode: true,
},
)

Expand Down

0 comments on commit 44b5e35

Please sign in to comment.