-
Notifications
You must be signed in to change notification settings - Fork 0
Support Payrix Canada API through region configuration #13
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
Changes from all commits
ab27ff6
a16189e
d55353f
a71a8ac
b96a5f5
e22f657
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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(options[:environment]) | ||
| url = Payrix.configuration.url(options[:region], options[:environment]) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we are supporting a new |
||
|
|
||
| page_number = Payrix::RequestOptions::Page::Number.construct(options[:page]) | ||
| page_limit = Payrix::RequestOptions::Page::Limit.construct(options[:limit]) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,35 +4,35 @@ module Payrix | |
| # Use this class to configure API parameters such as API URL, API key, etc. | ||
| class Configuration | ||
| attr_accessor :api_key, :session_key | ||
| attr_reader :environment | ||
| attr_reader :region, :environment | ||
|
|
||
| def initialize | ||
| @api_key = '' | ||
| @session_key = '' | ||
| @region = nil | ||
| @environment = Payrix::ENVIRONMENTS.fetch(:sandbox) | ||
| end | ||
|
|
||
| def region=(region) | ||
| validate_region!(region) | ||
|
|
||
| @region = region.to_sym | ||
| end | ||
|
Comment on lines
+16
to
+20
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is used for setting the region configuration globally. |
||
|
|
||
| def environment=(environment) | ||
| validate_environment!(environment) | ||
|
|
||
| @environment = environment.to_sym | ||
| end | ||
|
|
||
| def url(environment_override = nil) | ||
| environment = @environment | ||
|
|
||
| unless environment_override.nil? | ||
| validate_environment!(environment_override) | ||
| def url(region_override = nil, environment_override = nil) | ||
| region = region_override || @region | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This supports a region override, which always take precedent over the global configuration. |
||
| environment = environment_override || @environment | ||
|
|
||
| environment = environment_override.to_sym | ||
| end | ||
| validate_region!(region) | ||
| validate_environment!(environment) | ||
|
|
||
| case environment | ||
| when Payrix::ENVIRONMENTS.fetch(:sandbox) | ||
| 'https://test-api.payrix.com' | ||
| when Payrix::ENVIRONMENTS.fetch(:production) | ||
| 'https://api.payrix.com' | ||
| end | ||
| Payrix::ENDPOINTS[region.to_sym][environment.to_sym] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The set of API endpoints has been extracted to a "look up table", where additional regions can be added easily in the future. |
||
| end | ||
|
|
||
| private | ||
|
|
@@ -41,5 +41,10 @@ def validate_environment!(environment) | |
| raise InvalidEnvironmentError unless environment.respond_to?(:to_sym) | ||
| raise InvalidEnvironmentError unless Payrix::ENVIRONMENTS.values.include?(environment.to_sym) | ||
| end | ||
|
|
||
| def validate_region!(region) | ||
| raise InvalidRegionError unless region.respond_to?(:to_sym) | ||
| raise InvalidRegionError unless Payrix::REGIONS.values.include?(region.to_sym) | ||
| end | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This library aims to be as developer friendly as possible. This means surfacing developer errors as soon as possible. We ensure the region setting is within the supported list, or raise an error before we even send the request to the Payrix API. This way, a developer doesn't need to wait long to get this feedback. |
||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We support the Payrix Canada API by routing to these endpoints, when configured with
:caabove.