API documentation

class tbk.webpay.commerce.Commerce(id=None, key=None, testing=False)

Initialize a Commerce with given commerce_id and the private PEM key.

If testing flag is True then TEST_COMMERCE_KEY and TEST_COMMERCE_ID are used.

Parameters:
  • commerce_id – Commerce ID
  • key – Commerce private RSA key
  • testing – If True will use certification URLs and keys.
acknowledge

The ACK string encrypted for succes response on confirmation to Transbank.

static create_commerce()

Creates commerce from environment variables TBK_COMMERCE_ID, TBK_COMMERCE_KEY or for testing purposes TBK_COMMERCE_TESTING.

get_config_tbk(confirmation_url)

Returns a string with the TBK_CONFIG.dat.

Parameters:confirmation_url – URL where callback is made.
get_public_key()

Returns Commerce public key from PEM private key.

reject

The ERR string encrypted for reject response on confirmation to Transbank.

class tbk.webpay.payment.Payment(request_ip, amount, order_id, success_url, confirmation_url, session_id=None, failure_url=None, commerce=None)

Initialize a Payment object with params required to create the redirection url.

redirect_url

Redirect user to this URL and will begin the payment process.

token

Token given by Transbank for payment initialization url.

transaction_id

Transaction ID for Transbank, a secure random int between 0 and 999999999.

class tbk.webpay.confirmation.Confirmation(commerce, request_ip, data, timeout=25)

Create a confirmation instance which handle callback data from transbank.

Given that Webpay accept acknowledge response only in less than 30 seconds, there is a timeout of 25 seconds (by default) for suceed the answer.

Parameters:
  • commerce – Commerce instance corresponding to data['TBK_ID_COMERCIO'].
  • request_ip – String representing request ip.
  • data – dict like instance with TBK_PARAM.
  • timeout – seconds between initialization and is_success to don’t suceed.
amount

Amount sent by Webpay.

Return type:decimal.Decimal
is_success(check_timeout=True)

Check if Webpay response TBK_RESPUESTA is equal to 0 and if the lapse between initialization and this call is less than self.timeout when check_timeout is True (default).

Parameters:check_timeout – When True, check time between initialization and call.
is_timeout()

Check if the lapse between initialization and now is more than self.timeout.

order_id

Order id sent by Webpay.

class tbk.webpay.confirmation.ConfirmationPayload(data)

A convenient class to handle Webpay Transaction Payload.

accountable_date

Accountable date of transaction, localized as America/Santiago

amount

Amount sent in TBK_MONTO as a Decimal.

authorization_code

Transaction authorization code.

credit_card_last_digits

Last 4 digits of the card used by customer.

credit_card_number

12 digits credit card string, only showing last digits.

installments

Quantity of installments

message

Message corresponding to response code TBK_RESPUESTA.

order_id

Order ID from TBK_ORDEN_COMPRA as string.

paid_at

Localized at America/Santiago datetime of TBK_FECHA_TRANSACCION.

payment_type

Payment Type according to TBK_TIPO_PAGO.

payment_type_code

Payment type code according to TBK_TIPO_PAGO.

response

Response code as int (TBK_RESPUESTA)

session_id

Session id, if ‘null’ then None

transaction_id

Transaction ID as int.