-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef2a8d3
commit 8df8d13
Showing
14 changed files
with
247 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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,6 +1,7 @@ | ||
from postfinancecheckout import Configuration | ||
|
||
from postfinancecheckout.models import ( | ||
AddressCreate, | ||
LineItem, | ||
LineItemType, | ||
TransactionCreate, | ||
|
@@ -17,7 +18,22 @@ | |
|
||
|
||
def get_transaction_create(): | ||
address = AddressCreate( | ||
city = "Winterthur", | ||
country = "CH", | ||
email_address = "[email protected]", | ||
family_name = "Customer", | ||
given_name = "Good", | ||
postcode = "8400", | ||
postal_state = "ZH", | ||
organization_name = "Test GmbH", | ||
mobile_phone_number = "+41791234567", | ||
salutation = "Ms" | ||
) | ||
|
||
return TransactionCreate( | ||
currency="CHF", | ||
auto_confirmation_enabled=True, | ||
line_items=[ | ||
LineItem( | ||
name="Blue T-Shirt", | ||
|
@@ -28,8 +44,9 @@ def get_transaction_create(): | |
type=LineItemType.PRODUCT, | ||
) | ||
], | ||
auto_confirmation_enabled=True, | ||
currency="CHF", | ||
billing_address=address, | ||
shipping_address=address, | ||
language="en-GB", | ||
) | ||
|
||
|
||
|
@@ -38,4 +55,5 @@ def get_transaction_create(): | |
) | ||
|
||
TEST_CARD_PAYMENT_METHOD_CONFIGURATION_ID = 1352 | ||
TEST_ISR_INVOICE_PAYMENT_METHOD_CONFIGURATION_ID = 8656 | ||
TEST_CUSTOMER_ID = 7311742 |
This file contains 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,81 @@ | ||
import unittest | ||
|
||
from constants import ( | ||
API_CONFIG, | ||
SPACE_ID, | ||
get_transaction_create, | ||
FAKE_CARD_DATA, | ||
TEST_CARD_PAYMENT_METHOD_CONFIGURATION_ID, | ||
TEST_CUSTOMER_ID, | ||
) | ||
|
||
from postfinancecheckout.api import ( | ||
TransactionServiceApi, | ||
CardProcessingServiceApi, | ||
ChargeAttemptServiceApi | ||
) | ||
from postfinancecheckout.models import ( | ||
TransactionState, | ||
EntityQuery, | ||
EntityQueryFilter, | ||
EntityQueryFilterType, | ||
CriteriaOperator, | ||
TokenizationMode, | ||
TransactionCompletionBehavior, | ||
CustomersPresence, | ||
) | ||
|
||
class ChargeAttemptServiceTest(unittest.TestCase): | ||
"""ChargeAttemptServiceApi tests""" | ||
|
||
def setUp(self): | ||
self.transaction_service = TransactionServiceApi(API_CONFIG) | ||
self.card_processing_service = CardProcessingServiceApi(API_CONFIG) | ||
self.charge_attempt_service = ChargeAttemptServiceApi(API_CONFIG) | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def test_search(self): | ||
"""search() should find charge attempts by given criteria""" | ||
|
||
transaction_create = get_transaction_create() | ||
transaction_create.tokenization_mode = TokenizationMode.FORCE_CREATION | ||
transaction_create.customers_presence = CustomersPresence.NOT_PRESENT | ||
transaction_create.completion_behavior = TransactionCompletionBehavior.COMPLETE_DEFERRED | ||
|
||
transaction = self.transaction_service.create( | ||
space_id=SPACE_ID, transaction=transaction_create) | ||
transaction_processed = self.card_processing_service.process( | ||
space_id=SPACE_ID, | ||
transaction_id=transaction.id, | ||
payment_method_configuration_id=TEST_CARD_PAYMENT_METHOD_CONFIGURATION_ID, | ||
card_data=FAKE_CARD_DATA, | ||
) | ||
|
||
self.assertEqual( | ||
TransactionState.AUTHORIZED, | ||
transaction_processed.state, | ||
"State must be AUTHORIZED", | ||
) | ||
|
||
entity_query_filter = EntityQueryFilter( | ||
field_name="charge.transaction.id", | ||
value=transaction.id, | ||
type=EntityQueryFilterType.LEAF, | ||
operator=CriteriaOperator.EQUALS, | ||
) | ||
entity_query = EntityQuery(filter=entity_query_filter) | ||
|
||
attempts_found = self.charge_attempt_service.search( | ||
space_id=SPACE_ID, query=entity_query) | ||
|
||
self.assertTrue(len(attempts_found) > 0) | ||
for attempt in attempts_found: | ||
self.assertEqual(transaction.id, attempt.linked_transaction) | ||
|
||
# TODO write more API tests | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main(failfast=True) |
This file contains 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,132 @@ | ||
import unittest | ||
|
||
from constants import ( | ||
API_CONFIG, | ||
SPACE_ID, | ||
get_transaction_create, | ||
FAKE_CARD_DATA, | ||
TEST_CARD_PAYMENT_METHOD_CONFIGURATION_ID, | ||
TEST_ISR_INVOICE_PAYMENT_METHOD_CONFIGURATION_ID, | ||
) | ||
|
||
from postfinancecheckout.api import ( | ||
TransactionServiceApi, | ||
CardProcessingServiceApi, | ||
TransactionInvoiceServiceApi, | ||
TransactionCompletionServiceApi, | ||
) | ||
from postfinancecheckout.models import ( | ||
TransactionState, | ||
TransactionInvoiceState, | ||
EntityQuery, | ||
EntityQueryFilter, | ||
EntityQueryFilterType, | ||
CriteriaOperator, | ||
TokenizationMode, | ||
TransactionCompletionBehavior, | ||
CustomersPresence, | ||
) | ||
|
||
|
||
class TransactionInvoiceServiceTest(unittest.TestCase): | ||
"""TransactionInvoiceServiceApi tests""" | ||
|
||
def setUp(self): | ||
self.transaction_service = TransactionServiceApi(API_CONFIG) | ||
self.transaction_invoice_service = TransactionInvoiceServiceApi(API_CONFIG) | ||
self.transaction_completion_service = TransactionCompletionServiceApi( | ||
API_CONFIG) | ||
self.card_processing_service = CardProcessingServiceApi(API_CONFIG) | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def test_search(self): | ||
"""search() should find transaction invoice by a given criteria""" | ||
|
||
transaction_create = get_transaction_create() | ||
transaction_create.tokenization_mode = TokenizationMode.FORCE_CREATION | ||
transaction_create.customers_presence = CustomersPresence.NOT_PRESENT | ||
transaction_create.completion_behavior = TransactionCompletionBehavior.COMPLETE_IMMEDIATELY | ||
transaction = self.transaction_service.create(space_id=SPACE_ID, transaction=transaction_create) | ||
|
||
transaction_processed = self.card_processing_service.process( | ||
space_id=SPACE_ID, | ||
transaction_id=transaction.id, | ||
payment_method_configuration_id=TEST_CARD_PAYMENT_METHOD_CONFIGURATION_ID, | ||
card_data=FAKE_CARD_DATA, | ||
) | ||
|
||
self.assertEqual( | ||
TransactionState.FULFILL, | ||
transaction_processed.state, | ||
"State must be FULFILL", | ||
) | ||
|
||
entity_query_filter = EntityQueryFilter( | ||
# linkedTransaction does not work here as criteria | ||
field_name="completion.lineItemVersion.transaction.id", | ||
value=transaction_processed.id, | ||
type=EntityQueryFilterType.LEAF, | ||
operator=CriteriaOperator.EQUALS, | ||
) | ||
entity_query = EntityQuery(filter=entity_query_filter) | ||
|
||
invoices_found = self.transaction_invoice_service.search( | ||
space_id=SPACE_ID, query=entity_query) | ||
|
||
self.assertTrue(len(invoices_found) > 0, | ||
"Should find invoice", ) | ||
|
||
for invoice in invoices_found: | ||
self.assertEqual(TransactionInvoiceState.NOT_APPLICABLE, invoice.state, | ||
"Invoice paid by card is expected to be of NOT_APPLICABLE state") | ||
|
||
|
||
|
||
def test_derecognize_transaction_invoice(self): | ||
"""mark_as_derecognized() should derecognize open invoice""" | ||
|
||
transaction_create = get_transaction_create() | ||
transaction_create.tokenization_mode = TokenizationMode.FORCE_CREATION | ||
transaction_create.customers_presence = CustomersPresence.NOT_PRESENT | ||
transaction_create.completion_behavior = TransactionCompletionBehavior.COMPLETE_DEFERRED | ||
|
||
# we want invoice in OPEN state (OPEN invoices can be derecognized), so we force payment by invoice | ||
transaction_create.allowed_payment_method_configurations = [TEST_ISR_INVOICE_PAYMENT_METHOD_CONFIGURATION_ID] | ||
transaction = self.transaction_service.create(space_id=SPACE_ID, transaction=transaction_create) | ||
|
||
transaction_processed = self.transaction_service.process_without_user_interaction( | ||
space_id=SPACE_ID, id=transaction.id) | ||
|
||
transaction_completion = self.transaction_completion_service.complete_online( | ||
space_id=SPACE_ID, id=transaction_processed.id) | ||
|
||
entity_query_filter = EntityQueryFilter( | ||
field_name="completion.lineItemVersion.transaction.id", | ||
value=transaction_processed.id, | ||
type=EntityQueryFilterType.LEAF, | ||
operator=CriteriaOperator.EQUALS, | ||
) | ||
entity_query = EntityQuery(filter=entity_query_filter) | ||
|
||
invoices_found = self.transaction_invoice_service.search( | ||
space_id=SPACE_ID, query=entity_query) | ||
|
||
self.assertTrue(len(invoices_found) > 0, | ||
"Should find invoice", ) | ||
|
||
found_invoice = invoices_found[0] | ||
|
||
self.assertEqual(TransactionInvoiceState.OPEN, found_invoice.state, | ||
"Transaction paid by invoice should create invoice in OPEN state" ) | ||
|
||
derecognized_invoice = self.transaction_invoice_service.mark_as_derecognized( | ||
space_id=SPACE_ID, id=found_invoice.id); | ||
|
||
self.assertEqual(TransactionInvoiceState.DERECOGNIZED, derecognized_invoice.state, | ||
"Expected DERECOGNIZED invoice state") | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main(failfast=True) |
This file contains 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