def test_products_create(client): custom_type = client.types.create( types.TypeDraft(name=types.LocalizedString(en="myType"), resource_type_ids=[types.ResourceTypeId.ASSET], field_definitions=[types.FieldDefinition(name="foo")])) assert custom_type.id draft = types.ProductDraft( key="test-product", publish=True, master_variant=types.ProductVariantDraft( assets=[ types.AssetDraft(custom=types.CustomFieldsDraft( type=types.TypeResourceIdentifier(id=custom_type.id), fields=types.FieldContainer(foo="bar"), )) ], prices=[ types.PriceDraft( value=types.CentPrecisionMoneyDraft(cent_amount=1000, currency_code="EUR"), country="NL", ) ], ), ) product = client.products.create(draft) assert product.id assert product.master_data.current.master_variant.assets assert product.master_data.current.master_variant.prices
def test_payments_get_by_id(client): custom_type = client.types.create( types.TypeDraft( name=types.LocalizedString(en="myType"), key="payment-info", resource_type_ids=[types.ResourceTypeId.PAYMENT_INTERFACE_INTERACTION], field_definitions=[ types.FieldDefinition( type=types.CustomFieldStringType(), name="operations", label=types.LocalizedString(en="Operation"), required=False, ) ], ) ) payment = client.payments.create( types.PaymentDraft( key="test-payment", amount_planned=types.Money(cent_amount=2000, currency_code="GBP"), payment_method_info=types.PaymentMethodInfo( payment_interface="ADYEN", method="mc" ), transactions=[ types.TransactionDraft( type=types.TransactionType.CHARGE, amount=types.Money(cent_amount=2000, currency_code="GBP"), interaction_id="8525483242578266", state=types.TransactionState.SUCCESS, ) ], interface_interactions=[ types.CustomFieldsDraft( type=types.TypeResourceIdentifier(id=custom_type.id), fields=types.FieldContainer( { "operations": "CANCEL,CAPTURE,REFUND", "success": True, "psp_reference": "8525483242578266", "merchant_reference": "some reference", "reason": "82132:0005:10/2020", "amount": 2000, "payment_method": "mc", "event_date": "2019-01-24T11:04:17.000000Z", "currency_code": "GBP", "event_code": "AUTHORISATION", "merchant_account_code": "TestMerchant", } ), ) ], ) ) assert payment.id assert payment.key == "test-payment"
def test_serialize_field_container(): draft = types.CustomFieldsDraft( type=types.ResourceIdentifier(type_id=types.ReferenceTypeId.CART, id="foobar"), fields=types.FieldContainer(foobar=10), ) result = schemas.CustomFieldsDraftSchema().dump(draft) expected = { "fields": {"foobar": 10}, "type": {"typeId": "cart", "id": "foobar", "key": None}, } assert expected == result roundtrip = schemas.CustomFieldsDraftSchema().load(expected) assert draft == roundtrip
def test_payments_get_by_id(client): payment = client.payments.create( types.PaymentDraft( key="test-payment", amount_planned=types.Money(cent_amount=2000, currency_code="GBP"), payment_method_info=types.PaymentMethodInfo( payment_interface="ADYEN", method="mc" ), transactions=[ types.TransactionDraft( type=types.TransactionType.CHARGE, amount=types.Money(cent_amount=2000, currency_code="GBP"), interaction_id="8525483242578266", state=types.TransactionState.SUCCESS, ) ], interface_interactions=[ types.CustomFieldsDraft( fields=types.FieldContainer( { "operations": "CANCEL,CAPTURE,REFUND", "success": True, "psp_reference": "8525483242578266", "merchant_reference": "some reference", "reason": "82132:0005:10/2020", "amount": 2000, "payment_method": "mc", "event_date": "2019-01-24T11:04:17.000000Z", "currency_code": "GBP", "event_code": "AUTHORISATION", "merchant_account_code": "TestMerchant", } ) ) ], ) ) assert payment.id assert payment.key == "test-payment"
def post_load(self, data, **kwargs): return types.CustomFieldsDraft(**data)