-
Notifications
You must be signed in to change notification settings - Fork 0
Pthmint 108 #54
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
Open
zulquer
wants to merge
3
commits into
master
Choose a base branch
from
PTHMINT-108
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Pthmint 108 #54
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ source = | |
| tests | ||
| omit = | ||
| env/ | ||
| examples/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,17 @@ | ||
| API_KEY= | ||
| E2E_API_KEY= | ||
| E2E_BASE_URL=https://testapi.multisafepay.com/v1/ | ||
| # Temporary override for strict feature examples not yet supported on testapi | ||
| E2E_NO_SANDBOX_BASE_URL= | ||
| PARTNER_API_KEY= | ||
| CLOUD_POS_TERMINAL_GROUP_ID=<terminal_group_id> | ||
|
|
||
| # Dedicated env vars for strict feature-specific E2E tests (temporary split) | ||
| E2E_PARTNER_API_KEY= | ||
| E2E_CLOUD_POS_TERMINAL_ID=<terminal_id> | ||
| E2E_TERMINAL_GROUP_API_KEY_GROUP_DEFAULT= | ||
|
|
||
| # Terminal group API keys — one entry per group_id | ||
| TERMINAL_GROUP_API_KEY_GROUP_DEFAULT= | ||
| # TERMINAL_GROUP_API_KEY_GROUP_A= | ||
| # TERMINAL_GROUP_API_KEY_GROUP_B= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| """Create a Cloud POS order and subscribe to its event stream.""" | ||
|
|
||
| import os | ||
| import time | ||
|
|
||
| from dotenv import load_dotenv | ||
| from multisafepay import Sdk | ||
| from multisafepay.api.paths.orders.request import OrderRequest | ||
| from multisafepay.client import ScopedCredentialResolver | ||
|
|
||
| # Load environment variables from a .env file | ||
| load_dotenv() | ||
|
|
||
| DEFAULT_ACCOUNT_API_KEY = (os.getenv("API_KEY") or "").strip() | ||
| PARTNER_AFFILIATE_API_KEY = (os.getenv("PARTNER_API_KEY") or "").strip() | ||
| TERMINAL_GROUP_DEFAULT_API_KEY = ( | ||
| os.getenv("TERMINAL_GROUP_API_KEY_GROUP_DEFAULT") or "" | ||
| ).strip() | ||
| CLOUD_POS_TERMINAL_GROUP_ID = os.getenv( | ||
| "CLOUD_POS_TERMINAL_GROUP_ID", | ||
| "Default", | ||
| ) | ||
|
|
||
| if __name__ == "__main__": | ||
| # This example executes Cloud POS calls with terminal-group scope. | ||
| scoped_terminal_group_id = CLOUD_POS_TERMINAL_GROUP_ID | ||
| resolver_kwargs = { | ||
| "default_api_key": DEFAULT_ACCOUNT_API_KEY, | ||
| "partner_affiliate_api_key": PARTNER_AFFILIATE_API_KEY, | ||
| } | ||
| if scoped_terminal_group_id: | ||
| resolver_kwargs["terminal_group_api_keys"] = { | ||
| scoped_terminal_group_id: TERMINAL_GROUP_DEFAULT_API_KEY, | ||
| } | ||
|
|
||
| credential_resolver = ScopedCredentialResolver(**resolver_kwargs) | ||
|
|
||
| multisafepay_sdk = Sdk( | ||
| is_production=False, | ||
| credential_resolver=credential_resolver, | ||
| ) | ||
| order_manager = multisafepay_sdk.get_order_manager() | ||
| event_manager = multisafepay_sdk.get_event_manager() | ||
|
|
||
| terminal_id = "<terminal_id>" | ||
| # Temporary override for local runs via .env. | ||
| terminal_id = os.getenv("CLOUD_POS_TERMINAL_ID", terminal_id) | ||
|
|
||
| order_id = f"cloud-pos-{int(time.time())}" | ||
|
|
||
| order_request = ( | ||
| OrderRequest() | ||
| .add_type("redirect") | ||
| .add_order_id(order_id) | ||
| .add_description("Cloud POS order") | ||
| .add_amount(100) | ||
| .add_currency("EUR") | ||
| .add_gateway_info( | ||
| { | ||
| "terminal_id": terminal_id, | ||
| }, | ||
|
zulquer marked this conversation as resolved.
|
||
| ) | ||
|
zulquer marked this conversation as resolved.
|
||
| ) | ||
|
|
||
| create_response = order_manager.create( | ||
| order_request, | ||
| terminal_group_id=scoped_terminal_group_id, | ||
| ) | ||
| order = create_response.get_data() | ||
|
|
||
| if order is None: | ||
| raise RuntimeError("Order creation did not return order data") | ||
|
|
||
| print(f"Created Cloud POS order: {order.order_id}") | ||
| print("Listening for events. Press Ctrl+C to stop.") | ||
|
|
||
| try: | ||
| with event_manager.subscribe_order_events(order, timeout=45.0) as stream: | ||
| for event in stream: | ||
| print(event) | ||
| except KeyboardInterrupt: | ||
| print("Stream interrupted by user.") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| """Create a Cloud POS order, wait 5 seconds, and cancel it.""" | ||
|
|
||
| import os | ||
| import time | ||
|
|
||
| from dotenv import load_dotenv | ||
|
|
||
| from multisafepay import Sdk | ||
| from multisafepay.api.paths.orders.request import OrderRequest | ||
| from multisafepay.client import ScopedCredentialResolver | ||
|
zulquer marked this conversation as resolved.
|
||
|
|
||
| # Load environment variables from a .env file | ||
| load_dotenv() | ||
|
|
||
| DEFAULT_ACCOUNT_API_KEY = (os.getenv("API_KEY") or "").strip() | ||
| PARTNER_AFFILIATE_API_KEY = (os.getenv("PARTNER_API_KEY") or "").strip() | ||
| TERMINAL_GROUP_DEFAULT_API_KEY = ( | ||
| os.getenv("TERMINAL_GROUP_API_KEY_GROUP_DEFAULT") or "" | ||
| ).strip() | ||
| CLOUD_POS_TERMINAL_GROUP_ID = os.getenv( | ||
| "CLOUD_POS_TERMINAL_GROUP_ID", | ||
| "Default", | ||
| ) | ||
|
|
||
| if __name__ == "__main__": | ||
| # This example executes Cloud POS calls with terminal-group scope. | ||
| scoped_terminal_group_id = CLOUD_POS_TERMINAL_GROUP_ID | ||
| resolver_kwargs = { | ||
| "default_api_key": DEFAULT_ACCOUNT_API_KEY, | ||
| "partner_affiliate_api_key": PARTNER_AFFILIATE_API_KEY, | ||
| } | ||
| if scoped_terminal_group_id: | ||
| resolver_kwargs["terminal_group_api_keys"] = { | ||
| scoped_terminal_group_id: TERMINAL_GROUP_DEFAULT_API_KEY, | ||
| } | ||
|
|
||
| credential_resolver = ScopedCredentialResolver(**resolver_kwargs) | ||
|
|
||
| multisafepay_sdk = Sdk( | ||
| is_production=False, | ||
| credential_resolver=credential_resolver, | ||
| ) | ||
| order_manager = multisafepay_sdk.get_order_manager() | ||
|
|
||
| # Temporary override for local runs; comment this line to force literal placeholder. | ||
| terminal_id = os.getenv("CLOUD_POS_TERMINAL_ID", "<terminal_id>") | ||
|
|
||
| order_request = ( | ||
| OrderRequest() | ||
| .add_type("redirect") | ||
| .add_order_id(f"cloud-pos-cancel-{int(time.time())}") | ||
| .add_description("Cloud POS cancel order") | ||
| .add_amount(100) | ||
| .add_currency("EUR") | ||
| .add_gateway_info( | ||
| { | ||
| "terminal_id": terminal_id, | ||
| }, | ||
| ) | ||
| ) | ||
|
|
||
| create_response = order_manager.create( | ||
| order_request, | ||
| terminal_group_id=scoped_terminal_group_id, | ||
| ) | ||
| order = create_response.get_data() | ||
|
|
||
| if order is None or not order.order_id: | ||
| raise RuntimeError("Order creation did not return order_id") | ||
|
|
||
| order_id = order.order_id | ||
| print(f"Created Cloud POS order: {order_id}") | ||
| print("Waiting 5 seconds before cancel...") | ||
| time.sleep(5) | ||
|
|
||
| cancel_response = order_manager.cancel_transaction( | ||
| order_id, | ||
| terminal_group_id=scoped_terminal_group_id, | ||
| ) | ||
|
|
||
| print(f"Canceled Cloud POS order: {order_id}") | ||
| print(cancel_response.get_data()) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| """Create a Cloud POS order and print its event stream credentials.""" | ||
|
|
||
| import os | ||
| import time | ||
|
|
||
| from dotenv import load_dotenv | ||
| from multisafepay import Sdk | ||
| from multisafepay.api.paths.orders.request import OrderRequest | ||
| from multisafepay.client import ScopedCredentialResolver | ||
|
zulquer marked this conversation as resolved.
|
||
|
|
||
| # Load environment variables from a .env file | ||
| load_dotenv() | ||
|
|
||
| DEFAULT_ACCOUNT_API_KEY = (os.getenv("API_KEY") or "").strip() | ||
| PARTNER_AFFILIATE_API_KEY = (os.getenv("PARTNER_API_KEY") or "").strip() | ||
| TERMINAL_GROUP_DEFAULT_API_KEY = ( | ||
| os.getenv("TERMINAL_GROUP_API_KEY_GROUP_DEFAULT") or "" | ||
| ).strip() | ||
| CLOUD_POS_TERMINAL_GROUP_ID = os.getenv( | ||
| "CLOUD_POS_TERMINAL_GROUP_ID", | ||
| "Default", | ||
| ) | ||
|
|
||
| if __name__ == "__main__": | ||
| # This example executes Cloud POS calls with terminal-group scope. | ||
| scoped_terminal_group_id = CLOUD_POS_TERMINAL_GROUP_ID | ||
| # Reuse one SDK for mixed traffic. The resolver is the source of truth for | ||
| # which key is used per endpoint/scope. | ||
| resolver_kwargs = { | ||
| "default_api_key": DEFAULT_ACCOUNT_API_KEY, | ||
| "partner_affiliate_api_key": PARTNER_AFFILIATE_API_KEY, | ||
| } | ||
| if scoped_terminal_group_id: | ||
| resolver_kwargs["terminal_group_api_keys"] = { | ||
| scoped_terminal_group_id: TERMINAL_GROUP_DEFAULT_API_KEY, | ||
| } | ||
|
|
||
| credential_resolver = ScopedCredentialResolver(**resolver_kwargs) | ||
|
|
||
| multisafepay_sdk = Sdk( | ||
| is_production=False, | ||
| credential_resolver=credential_resolver, | ||
| ) | ||
| order_manager = multisafepay_sdk.get_order_manager() | ||
|
|
||
| terminal_id = "<terminal_id>" | ||
| # Uncomment this line to override with CLOUD_POS_TERMINAL_ID from .env. | ||
| # terminal_id = os.getenv("CLOUD_POS_TERMINAL_ID", terminal_id) | ||
|
|
||
| order_id = f"cloud-pos-{int(time.time())}" | ||
|
|
||
| order_request = ( | ||
| OrderRequest() | ||
| .add_type("redirect") | ||
| .add_order_id(order_id) | ||
| .add_description("Cloud POS order") | ||
| .add_amount(100) | ||
| .add_currency("EUR") | ||
| .add_gateway_info( | ||
| { | ||
| "terminal_id": terminal_id, | ||
| }, | ||
| ) | ||
| ) | ||
|
|
||
| create_response = order_manager.create( | ||
| order_request, | ||
| terminal_group_id=scoped_terminal_group_id, | ||
| ) | ||
| order = create_response.get_data() | ||
|
|
||
| if order is None: | ||
| raise RuntimeError("Order creation did not return order data") | ||
|
|
||
| print(f"Created Cloud POS order: {order.order_id}") | ||
|
|
||
| events_token = order.events_token or order.event_token | ||
| events_stream_url = order.events_stream_url or order.event_stream_url | ||
|
|
||
| if events_token and events_stream_url: | ||
| print("Event stream credentials:") | ||
| print(f"EVENTS_TOKEN={events_token}") | ||
| print(f"EVENTS_STREAM_URL={events_stream_url}") | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.