Python Braspag Lib

Request object

class braspag.BraspagRequest(merchant_id=None, homologation=False)

Implements Braspag Pagador API (manual version 1.9).

Boleto generation is not yet implemented.

authorize(order_id, customer_id, customer_name, customer_email, amount, card_holder, card_number, card_security_code, card_exp_date, save_card, card_token, number_of_payments, payment_method, payment_plan, transaction_type=2, currency='BRL', country='BRA')[source]

All arguments supplied to this method must be keyword arguments.

Parameters:
  • order_id – Order id. It will be used to indentify the order later in Braspag.
  • customer_id – Must be user’s CPF/CNPJ.
  • customer_name – User’s full name.
  • customer_email – User’s email address.
  • amount – Amount to charge.
  • card_holder – Name printed on card.
  • card_number – Card number.
  • card_security_code – Card security code.
  • card_exp_date – Card expiration date.
  • save_card – Flag that tell to Braspag to store card number. If set to True Reponse will return a card token. Default: False.
  • card_token – Card token returned by Braspag. When used it should replace card_holder, card_exp_date, card_number and card_security_code.
  • number_of_payments – Number of payments that the amount will be devided (number of months). Default: 1.
  • currency – Currency of the given amount. Default: BRL.
  • country – User’s country. Default: BRA.
  • transaction_type – An integer representing one of the Transaction Types. Default: 2.
  • payment_plan – An integer representing how multiple payments should be handled. Default: 0. See Payment Plans.
  • payment_method – Integer representing one of the available Payment Methods.
Returns:

BraspagResponse

capture(transaction_id, amount=0)

Capture the given amount from the given transaction_id.

This method should only be called after pre-authorizing the transaction by calling authorize() with transaction_types 1 or 3.

Returns:BraspagResponse
refund(transaction_id, amount=0)

Refund the given amount for the given transaction_id.

This method should be used to return funds to customers for transactions that happened at least 24 hours ago. For transactions that happended within 24 hours use void().

If the amount is 0 (zero) the full transaction will be refunded.

Returns:BraspagResponse
void(transaction_id, amount=0)

Void the given amount for the given transaction_id.

This method should be used to return funds to customers for transactions that happened within less than 23h and 59 minutes ago. For other transactions use refund().

If the amount is 0 (zero) the full transaction will be voided.

Returns:BraspagResponse

Examples

Creditcard example

The example bellow shows how to authorize a credit card transation:

from braspag import BraspagRequest

ORDER_ID = u'84765421-5435-85C2-3F41-85A72BE2433E'
MERCHANT_ID = u'12345678-1234-1234-1234-1234567890AB'

request = BraspagRequest(merchant_id=MERCHANT_ID, homologation=True)
response = request.authorize(
    order_id=ORDER_ID,
    customer_id=u'12345678900',
    customer_name=u'José da Silva',
    customer_email='jose123@dasilva.com.br',
    payment_method=997, #simulated BRL
    amount=10000,
    card_holder=u'Jose da Silva',
    card_number=u'0000000000000001',
    card_security_code='123',
    card_exp_date='05/2018',
)

The argument order_id should be an GUID valid string which indentifies this transaction on your system. The argument customer_id must be a valid CPF or CNPJ for the user.

The amount given should be an integer where the 2 last digits will represent the decimal places.

Response object

class braspag.BraspagResponse(http_reponse)

TODO:

correlation_id
errors
success
order_id
braspag_order_id
transaction_id
payment_method
amount
acquirer_transaction_id
authorization_code
return_code
return_message
card_token
status

Exceptions

exception braspag.exceptions.BraspagException[source]

Bases: exceptions.Exception

Custom exception

exception braspag.exceptions.BraspagHttpResponseException(code, msg)[source]

Bases: braspag.exceptions.BraspagException

Status code Exception

Utils

braspag.utils.is_valid_guid(guid)[source]
braspag.utils.spaceless(xml_str)[source]

Project Versions

Table Of Contents

Previous topic

Installation

Next topic

Constants

This Page