Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change API for setting the request environment #11

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

harrylewis
Copy link
Member

@harrylewis harrylewis commented Mar 9, 2024

Description

This PR changes the API for setting the request environment. It is now set through Payrix.environment= instead of Payrix.test_mode=.

# Use sandbox environment.
- Payrix.test_mode = true
+ Payrix.environment = :sandbox

# Use production environment.
- Payrix.test_mode = false
+ Payrix.environment = :production

Without explicit configuration, the default environment is sandbox now instead of production.

Additionally, support has been added for passing an :environment parameter into the options hash for all CRUD operations.

# `Payrix.environment` is used to determine environment used.
Payrix::Txn.retrieve('t1_txn_64026b07cc6a79dd5cfd0da')

# Use sandbox environment (https://test-api.payrix.com).
Payrix::Txn.retrieve('t1_txn_64026b07cc6a79dd5cfd0da', { environment: :sandbox })

# Use production environment (https://api.payrix.com).
Payrix::Txn.retrieve('t1_txn_64026b07cc6a79dd5cfd0da', { environment: :production })

@harrylewis harrylewis self-assigned this Mar 9, 2024
@harrylewis harrylewis force-pushed the support-test-mode-parameter branch from 44b5e35 to aad2853 Compare March 9, 2024 19:19
@harrylewis harrylewis marked this pull request as ready for review March 9, 2024 19:22
@harrylewis harrylewis requested a review from jazziining March 9, 2024 19:22
Clarify some the test descriptions, and add a test case for a missed
edge case, when the test mode setting is not explicitly set.
@harrylewis harrylewis force-pushed the support-test-mode-parameter branch from aad2853 to c855590 Compare August 29, 2024 19:39
@harrylewis harrylewis changed the title Support per-request :test_mode configuration Change API for setting the request environment Aug 29, 2024
@harrylewis harrylewis force-pushed the support-test-mode-parameter branch from c855590 to 6d9510c Compare August 29, 2024 19:42
This is done for a generally safer library that requires explicit
configuration to access the production environment.
@harrylewis harrylewis force-pushed the support-test-mode-parameter branch from 6d9510c to 2c8bb51 Compare August 29, 2024 19:58
This is an override argument, which will allow overriding the static
environment configuration.
@harrylewis harrylewis force-pushed the support-test-mode-parameter branch from 2c8bb51 to 17540bb Compare August 29, 2024 20:02
Comment on lines +22 to +25
ENVIRONMENTS = {
sandbox: :sandbox,
production: :production,
}.freeze
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are only two available environments, which correspond with two different URL's.

Comment on lines -34 to +40
def self.test_mode=(test_mode)
configuration.test_mode = test_mode
def self.environment=(environment)
configuration.environment = environment
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the configuration setter from .test_mode= to .environment=.

url = Payrix.configuration.url
url = Payrix.configuration.url(options[:environment])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Support passing in the :environment per-request.

Comment on lines +15 to +19
def environment=(environment)
validate_environment!(environment)

@environment = environment.to_sym
end
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I am defining an explicit setter so that we can raise an appropriate developer error when it is set incorrectly.

Comment on lines -11 to +12
@test_mode = false
@environment = Payrix::ENVIRONMENTS.fetch(:sandbox)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the default environment setting to sandbox. This is done to foster more safety when using the library, and prevent making accidental mutations in the production environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant