trustpaylib¶
TrustPay payment solution constants and utils.
- class trustpaylib.TrustPay(environment)¶
- CURRENCIES¶
Supportted currencies (trustpaylib.CURRENCIES)
- LANGUAGES¶
Supportted languages (trustpaylib.LANGUAGES)
- COUNTRIES¶
Supportted countries (trustpaylib.COUNTRIES)
- RESULT_CODES¶
Known result codes of redirects and notifications (trustpaylib.RESULT_CODES)
- RESULT_CODES_DESC¶
Short and long description for result codes of redirects and notifications (trustpaylib.RESULT_CODES_DESC)
- build_link(pay_request, sign=True, validate=True, merge_env=True)¶
Finalizes raw payment request and generates redirect link.
- Args:
pay_request (trustpaylib.TrustPayRequest):
sign (bool): If False, don’t sign pay request.
validate (bool): If False, don’t validate pay request.
merge_env (bool): If False, don’t merge pay request with env.
- Returns:
- string: Redirect link.
- check_notification_signature(notification)¶
Check if notification is signed with environment’s secret key.
- Args:
- notification (trustpaylib.TrustPayNotification)
- Returns:
- bool
- classmethod create_signature_msg(pay_request)¶
Concatenate set of payment request attributes and creates message to be hashed.
- Args:
- pay_request (trustpaylib.TrustPayRequest):
- Returns:
- string: Signature message.
- finalize_request(pay_request, sign=True, validate=True, merge_env=True)¶
Raw payment request is merged with environment, signed and validated.
- Args:
pay_request (trustpaylib.TrustPayRequest):
sign (bool): If False, don’t sign pay request.
validate (bool): If False, don’t validate pay request.
merge_env (bool): If False, don’t merge pay request with env.
- Returns:
- New trustpaylib.TrustPayRequest prepared for building link or creating form.
- classmethod get_result_desc(rc)¶
Returns description of result code.
- Args:
- rc (int|string):
- Result code from redirect or notification.
- Returns:
- Named tuple with short and long attributes for short, long description. (trustpaylib.RESULT_CODES_DESC)
>>> TrustPay.get_result_desc(1001).short 'Invalid request' >>> TrustPay.get_result_desc(1001).long 'Data sent is not properly formatted.'
- merge_env_with_request(pay_request)¶
Merge specific attributes of environment with payment request.
- Args:
- pay_request (trustpaylib.TrustPayRequest):
- Payment request to merge.
- Returns:
- New trustpaylib.TrustPayRequest instance with attributes merged with those in environment if not already set on pay_request.
- pay_request_signature(pay_request)¶
Use environments secret key to generate hash to sign pay request.
- Args:
- pay_request (trustpaylib.TrustPayRequest):
- Payment request already prepared for signing.
- Returns:
- Hash.
- sign_request(pay_request)¶
Sign payment request.
- Args:
- pay_request (trustpaylib.TrustPayRequest):
- Payment request already prepared for signing.
- Returns:
- New trustpaylib.TrustPayRequest instance with SIG attribute set to generated signature.
- classmethod validate_request(pay_request)¶
Validate payment request.
Check if all attributes for signed/non-signed payment request are present. Check if amount has at max two decimal places.
On validation errors, raises ValueError.
- Args:
- pay_request (trustpaylib.TrustPayRequest):
- Returns:
- Given pay_request.
- Raises:
- ValueError
- class trustpaylib.TrustPayRequest¶
TrustPayRequest(AID, AMT, CUR, REF, URL, RURL, CURL, EURL, NURL, SIG, LNG, CNT, DSC, EMA)
- class trustpaylib.TrustPayRedirect¶
TrustPayRedirect(REF, RES, PID)
- class trustpaylib.TrustPayNotification¶
TrustPayNotification(AID, TYP, AMT, CUR, REF, RES, TID, OID, TSS, SIG)
Constants¶
- trustpaylib.TEST_API_URL = 'https://test.trustpay.eu/mapi/paymentservice.aspx'¶
str(object=’‘) -> string
Return a nice string representation of the object. If the argument is a string, the return value is the same object.
- trustpaylib.API_URL = 'https://ib.trustpay.eu/mapi/paymentservice.aspx'¶
str(object=’‘) -> string
Return a nice string representation of the object. If the argument is a string, the return value is the same object.
- trustpaylib.TRUSTCARD_API_URL = 'https://ib.trustpay.eu/mapi/cardpayments.aspx'¶
str(object=’‘) -> string
Return a nice string representation of the object. If the argument is a string, the return value is the same object.
- trustpaylib.CURRENCIES = TrustPayCurrencies(CZK='CZK', EUR='EUR', GBP='GBP', HUF='HUF', PLN='PLN', USD='USD', RON='RON', BGN='BGN', HRK='HRK', LTL='LTL', TRY='TRY')¶
TrustPayCurrencies(CZK, EUR, GBP, HUF, PLN, USD, RON, BGN, HRK, LTL, TRY)
- trustpaylib.LANGUAGES = TrustPayLanguages(bg='bg', bs='bs', cs='cs', de='de', en='en', es='es', et='et', hr='hr', hu='hu', it='it', lt='lt', lv='lv', pl='pl', ro='ro', ru='ru', sk='sk', sl='sl', sr='sr', uk='uk')¶
TrustPayLanguages(bg, bs, cs, de, en, es, et, hr, hu, it, lt, lv, pl, ro, ru, sk, sl, sr, uk)
- trustpaylib.COUNTRIES = TrustPayCountries(CZ='CZ', HU='HU', PL='PL', SK='SK', EE='EE', BG='BG', RO='RO', HR='HR', LV='LV', LT='LT', SI='SI', TR='TR', FI='FI')¶
TrustPayCountries(CZ, HU, PL, SK, EE, BG, RO, HR, LV, LT, SI, TR, FI)
- trustpaylib.COUNTRIES_VERBOSE = TrustPayCountriesVerbose(CZ='Czech Republic', HU='Hungary', PL='Poland', SK='Slovak Republic', EE='Estonia', BG='Bulgaria', RO='Romania', HR='Croatia', LV='Latvia', LT='Lithuania', SI='Slovenia', TR='Turkey', FI='Finland')¶
TrustPayCountriesVerbose(CZ, HU, PL, SK, EE, BG, RO, HR, LV, LT, SI, TR, FI)
- trustpaylib.RESULT_CODES = TrustPayResultCodes(SUCCESS='0', PENDING='1', ANNOUNCED='2', AUTHORIZED='3', PROCESSING='4', AUTHORIZED_ONLY='5', INVALID_REQUEST='1001', UNKNOWN_ACCOUNT='1002', MERCHANT_ACCOUNT_DISABLED='1003', INVALID_SIGN='1004', USER_CANCEL='1005', INVALID_AUTHENTICATION='1006', DISPOSABLE_BALANCE='1007', SERVICE_NOT_ALLOWED='1008', PAYSAFECARD_TIMEOUT='1009', GENERAL_ERROR='1100', UNSUPPORTED_CURRENCY_CONVERSION='1101')¶
TrustPayResultCodes(SUCCESS, PENDING, ANNOUNCED, AUTHORIZED, PROCESSING, AUTHORIZED_ONLY, INVALID_REQUEST, UNKNOWN_ACCOUNT, MERCHANT_ACCOUNT_DISABLED, INVALID_SIGN, USER_CANCEL, INVALID_AUTHENTICATION, DISPOSABLE_BALANCE, SERVICE_NOT_ALLOWED, PAYSAFECARD_TIMEOUT, GENERAL_ERROR, UNSUPPORTED_CURRENCY_CONVERSION)
- trustpaylib.RESULT_CODES_DESC = {'1100': TrustPayResultCodesDesc(short='General Error', long='Internal error has occurred.'), '1101': TrustPayResultCodesDesc(short='Unsupported currency conversion', long='Currency conversion for requested currencies is not supported.'), '1': TrustPayResultCodesDesc(short='Pending', long='Payment is pending (offline payment)'), '0': TrustPayResultCodesDesc(short='Success', long='Payment was successfully processed.'), '3': TrustPayResultCodesDesc(short='Authorized', long='Payment was successfully authorized. Another notification (with result code 0 - success) will be sent when TrustPay receives and processes payment from 3rd party.'), '2': TrustPayResultCodesDesc(short='Announced', long='TrustPay has been notified that the clientplaced a payment order or has made payment, but further confirmation from 3rd party is needed.'), '5': TrustPayResultCodesDesc(short='Authorized only', long='Card payment was successfully authorized, but not captured. Subsequent MAPI call(s) is (are) required to capture payment.'), '4': TrustPayResultCodesDesc(short='Processing', long='TrustPay has received the payment, but it must be internally processed before it is settled on the merchant\xe2\x80\x98s account.'), '1009': TrustPayResultCodesDesc(short='PaySafeCard timeout', long='Cards allocation will be cancelled.'), '1008': TrustPayResultCodesDesc(short='Service not allowed', long='Service cannot be used or permission to use given service has not been granted.'), '1007': TrustPayResultCodesDesc(short='Disposable balance', long='Requested transaction amount is greater than disposable balance.'), '1006': TrustPayResultCodesDesc(short='Invalid authentication', long='Request was not properly authenticated'), '1005': TrustPayResultCodesDesc(short='User cancel', long='Customer has cancelled the payment.'), '1004': TrustPayResultCodesDesc(short='Invalid sign', long='The message is not signed correctly.'), '1003': TrustPayResultCodesDesc(short="Merchant's account disabled", long="Merchant's account has been disabled."), '1002': TrustPayResultCodesDesc(short='Unknown account', long='Account with specified ID was not found.'), '1001': TrustPayResultCodesDesc(short='Invalid request', long='Data sent is not properly formatted.')}¶
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s
(key, value) pairs- dict(iterable) -> new dictionary initialized as if via:
d = {} for k, v in iterable:
d[k] = v- dict(**kwargs) -> new dictionary initialized with the name=value pairs
- in the keyword argument list. For example: dict(one=1, two=2)