diff --git a/CHANGELOG.md b/CHANGELOG.md index 62615bc..470cf0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Unreleased + +- Support passing `:test_mode` parameter into `options` hash for all CRUD operations. + ## 1.0.0 (2023-11-27) - Interact with the Payrix API! diff --git a/README.md b/README.md index 066c05c..f11c787 100644 --- a/README.md +++ b/README.md @@ -240,10 +240,13 @@ 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...' }) +Payrix::Merchant.retrieve('t1_mer_620acd189522582b3fb7849', { api_key: 'b442...', test_mode: true }) ``` This is useful if you need to set the API key in a thread-safe way, which is not possible through diff --git a/lib/payrix/client.rb b/lib/payrix/client.rb index 526d031..3110c5d 100644 --- a/lib/payrix/client.rb +++ b/lib/payrix/client.rb @@ -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]) diff --git a/spec/lib/payrix/client_spec.rb b/spec/lib/payrix/client_spec.rb index b8875be..835f1c1 100644 --- a/spec/lib/payrix/client_spec.rb +++ b/spec/lib/payrix/client_spec.rb @@ -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: { @@ -68,6 +68,7 @@ limit: 10, expand: ['merchant'], api_key: 'custom-key', + test_mode: true, }, ) @@ -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', @@ -142,6 +143,7 @@ options: { expand: ['merchant'], api_key: 'custom-key', + test_mode: true, }, ) @@ -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', @@ -223,6 +225,7 @@ }, options: { api_key: 'custom-key', + test_mode: true, }, ) @@ -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', @@ -286,6 +289,7 @@ resource: 'txns/t1_txn_64026b07cc6a79dd5cfd0da', options: { api_key: 'custom-key', + test_mode: true, }, )