shop.payment_providers.unzer_abstract

Attributes

Classes

UnzerClientViURShop

UnzerAbstract

Abstract base class for Unzer payment methods in the ViUR Shop.

Functions

log_unzer_error(func)

Decorator to log unzer errors

Module Contents

shop.payment_providers.unzer_abstract.logger
shop.payment_providers.unzer_abstract.P
shop.payment_providers.unzer_abstract.R
shop.payment_providers.unzer_abstract.log_unzer_error(func)

Decorator to log unzer errors

Decorator that logs details of an unzer.model.ErrorResponse if raised, then re-raises the error.

Parameters:

func (viur.shop.types.t.Callable[P, R])

Return type:

viur.shop.types.t.Callable[P, R]

class shop.payment_providers.unzer_abstract.UnzerClientViURShop(private_key, public_key, sandbox=False, language='en')

Bases: unzer.UnzerClient

Parameters:
  • private_key (str | viur.shop.types.t.Callable[[], str])

  • public_key (str | viur.shop.types.t.Callable[[], str])

  • sandbox (bool | viur.shop.types.t.Callable[[], bool])

  • language (str)

language = 'en'
property private_key: str
Return type:

str

property public_key: str
Return type:

str

property sandbox: bool
Return type:

bool

_request(url, method, headers, payload, auth)
class shop.payment_providers.unzer_abstract.UnzerAbstract(*, private_key, public_key, sandbox=False, language=None, **kwargs)

Bases: shop.payment_providers.PaymentProviderAbstract

Abstract base class for Unzer payment methods in the ViUR Shop.

Provides common functionality for Unzer-based payment providers, including API communication and payment type handling.

Create a new Unzer payment provider.

Parameters:
  • private_key (str | viur.shop.types.t.Callable[[], str]) – The private key to use for authentication.

  • public_key (str | viur.shop.types.t.Callable[[], str]) – The public key to use for authentication.

  • sandbox (bool | viur.shop.types.t.Callable[[], bool]) – Use sandbox mode (development mode).

  • language (str | None) – Enforce this language. If None, the language of the current request is used.

  • kwargs (viur.shop.types.t.Any)

language = None
client
property private_key: str
Return type:

str

property public_key: str
Return type:

str

property sandbox: bool
Return type:

bool

can_checkout(order_skel)

Check if a checkout process can be started

An empty list means not error, a list with errors rejects the checkout start.

Parameters:

order_skel (viur.core.skeleton.SkeletonInstance)

Return type:

list[viur.shop.types.ClientError]

checkout(order_skel)
Parameters:

order_skel (viur.core.skeleton.SkeletonInstance)

Return type:

viur.shop.types.t.Any

abstract get_payment_type(order_skel)
Parameters:

order_skel (viur.core.skeleton.SkeletonInstance)

Return type:

unzer.model.PaymentType

get_checkout_start_data(order_skel)
Parameters:

order_skel (viur.core.skeleton.SkeletonInstance)

Return type:

dict[str, viur.shop.types.t.Any]

can_order(order_skel)
Parameters:

order_skel (viur.core.skeleton.SkeletonInstance)

Return type:

list[viur.shop.types.ClientError]

charge(order_skel, payment=None)
Parameters:
  • order_skel (viur.shop.types.SkeletonInstance_T[viur.shop.skeletons.OrderSkel])

  • payment (viur.shop.types.t.Any | None)

Return type:

tuple[viur.shop.types.SkeletonInstance_T[viur.shop.skeletons.OrderSkel], viur.shop.types.t.Any]

get_order_by_pay_id(payment_id, public_key, *args, **kwargs)

Helper method to get the order skel for a payment-id.

Parameters:
  • payment_id (str) – The payment id. (ex: s-pay-1).

  • public_key (str) – Public key of the key pair.

Returns:

The order-skel if the key seems valid. None otherwise.

Return type:

viur.shop.types.SkeletonInstance_T[viur.shop.skeletons.OrderSkel] | None

check_payment_state(order_skel)

Get the payment state for a order.

Checks all payments stored in order_skel[“payment”][“payments”] for a completed and full charge.

In case of a completed charge, only the payment data of the charged payment is returned. Otherwise (failed or missing payment), data of all payments is returned.

Parameters:

order_skel (viur.core.skeleton.SkeletonInstance) – OrderSkel SkeletonInstance to check

Returns:

A tuple: [is_paid-boolean, payment-data]

Return type:

tuple[bool, unzer.PaymentGetResponse | list[unzer.PaymentGetResponse]]

return_handler(order_key)

Return Endpoint

Endpoint to which customers are redirected once they have processed a payment on the payment server.

Parameters:

order_key (viur.core.db.Key)

Return type:

viur.shop.types.t.Any

webhook(*args, **kwargs)

Webhook for unzer.

Listens to all events, but handle payment-complete as backup currently only.

get_debug_information(*, order_key=None, payment_id=None)

Get information about a payment / order.

Parameters:
  • order_key (viur.core.db.Key | str | None) – Key of the order skeleton.

  • payment_id (str | None) – Unzer ID of the order / payment.

Return type:

viur.shop.types.JsonResponse[list[dict[str, viur.shop.types.t.Any]]]

save_type(order_key, type_id)
Parameters:
  • order_key (str | viur.core.db.Key)

  • type_id (str)

customer_from_order_skel(order_skel)
Parameters:

order_skel (viur.core.skeleton.SkeletonInstance)

Return type:

unzer.Customer

customer_id_from_order_skel(order_skel)
Parameters:

order_skel (viur.core.skeleton.SkeletonInstance)

Return type:

str

address_from_address_skel(address_skel)
Parameters:

address_skel (viur.core.skeleton.SkeletonInstance)

Return type:

unzer.Address

static shop_salutation_to_unzer_salutation(salutation)
Parameters:

salutation (viur.shop.types.Salutation)

Return type:

unzer.model.customer.Salutation

classmethod model_to_dict(obj)

Convert any nested unzer model to dict representation

Parameters:

obj (viur.shop.types.t.Any)

Return type:

viur.shop.types.t.Any