braspag-sdk


Namebraspag-sdk JSON
Version 0.0.7 PyPI version JSON
download
home_pagehttps://github.com/romatallinn/braspagSdk-python
SummaryAn unofficial Python SDK for Braspag
upload_time2024-03-13 15:31:44
maintainer
docs_urlNone
authorRoman Sirokov
requires_python>=3.7,<4.0
license
keywords braspag sdk python cielo api ecommerce brazil payments
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Braspag SDK for Python
[![PyPi page link -- version](https://img.shields.io/pypi/v/braspag-sdk.svg)](https://pypi.python.org/pypi/braspag-sdk)
[![License](https://img.shields.io/github/license/romatallinn/braspagSdk-python)](LICENSE)


An unofficial Python SDK for [Braspag](https://braspag.github.io/).

## Disclaimer
This SDK is created for personal use and the functionality is limited to the needs of my projects.
You are more than welcome to contribute the code you need as soon as it follows the same code style.
Fortunately, this is a very simple SDK, so it should be easy to understand and extend.

# Getting Started

## Installation
```bash
pip install --upgrade braspag-sdk
```

## Configuration
```python
import os

from braspag_sdk import Braspag, MerchantCredentials, SplitCredentials, EMV3DSCredentials, SilentOrderPostCredentials

merchant_creds = MerchantCredentials(
    merchant_id=os.environ.get('BRASPAG_MERCHANT_ID'),
    merchant_key=os.environ.get('BRASPAG_MERCHANT_KEY'),
)

split_creds = SplitCredentials(
    client_secret=os.environ.get('BRASPAG_SPLIT_CLIENT_SECRET'),
)

emv3ds_creds = EMV3DSCredentials(
    client_id=os.environ.get('BRASPAG_EMV3DS_CLIENT_ID'),
    client_secret=os.environ.get('BRASPAG_EMV3DS_CLIENT_SECRET'),
)

sop_creds = SilentOrderPostCredentials(
    client_id=os.environ.get('BRASPAG_SOP_CLIENT_ID'),
    client_secret=os.environ.get('BRASPAG_SOP_CLIENT_SECRET'),
)

braspagSdk = Braspag(merchant_creds, is_sandbox=True)
braspagSdk.add_split(split_creds)
braspagSdk.add_emv3ds(emv3ds_creds)
braspagSdk.add_sop(sop_creds)
```

## Usage

### Creating a payment
[Official Documentation](https://braspag.github.io//manual/braspag-pagador)

```python
from braspag_sdk import Braspag, Sale, Customer, Address, CreditCard, Payment, SplitPayment

# Configuration
braspagSdk: Braspag = ...

print(f'Creating payment transaction in Braspag...')

# Prepare the basic sale info.
sale = Sale(merchant_order_id=...)

# Prepare the customer info.
sale.customer = Customer(name=...)
sale.customer.email = ...
sale.customer.identity = ...
sale.customer.identity_type = ...   # 'cpf' or 'cnpj'

# Prepare the customer's address.
sale_address = Address()
sale_address.street = ...
sale_address.number = ...
sale_address.complement = ...
sale_address.zip_code = ...
sale_address.city = ...
sale_address.state = ...
sale_address.country = ...
sale.customer.address = sale_address

# Prepare the payment info and credit card for it.
# Most likely, you are not PCI compliant, so you will need to use Braspag's card tokenization.
credit_card = CreditCard(security_code=None, brand=None)
credit_card.card_token = ''

sale.payment = Payment(amount=..., installments=...)
sale.payment.soft_descriptor = ...,
sale.payment.credit_card = credit_card

# Split payment with subourdintate merchants.
subordinate_merchant_id = ...
amount = ...
sale.payment.do_split = True
sale.payment.split_payments = [
    SplitPayment(subordinate_merchant_id, amount, mdr=..., fee=...)
]

# Create the payment in Cielo.
sale_response = braspagSdk.payments.create_sale(sale)
payment_response = sale_response['Payment']

# Save the payment reference in Dizconto's database.
payment_id = payment_response['PaymentId']
payment_method = payment_response['Type']
payment_status = payment_response['Status']
payment_reason = payment_response['ReturnCode']
payment_amount = payment_response['Amount']
print(f'Created Braspag Payment: {payment_id}')
```

### Creating a subordinate merchant
[Official Documentation](https://braspag.github.io//manual/split-de-pagamentos-pagador)

```python
from braspag_sdk import Braspag, SplitMerchant, SplitMerchantAddress, SplitMerchantBank, SplitMerchantAgreement

# Configuration.
braspagSdk: Braspag = ...
braspagSdk.add_split(...)

print(f'Creating Braspag Split Subordinate Merchant...')

address = SplitMerchantAddress(
    street=...,
    number=...,
    complement=...,
    neighborhood=...,
    zip_code=...,
    city=...,
    state=...,
)

bank_account = SplitMerchantBank(
    bank=...,
    bank_account_type=...,
    number=...,
    verifier_digit=...,
    agency_number=...,
    agency_digit=...,
    operation=...,
)

agreements = [
    SplitMerchantAgreement(
        percent=...,
        fee=...,
    )
]

split_merchant = SplitMerchant(master_merchant_id=...)
split_merchant.fancy_name = ...
split_merchant.website = ...
split_merchant.mail_address = ...
split_merchant.contact_name = ...
split_merchant.contact_phone = ...
split_merchant.corporate_name = ...
split_merchant.document_number = ...
split_merchant.document_type = ...
split_merchant.address = address
split_merchant.bank_account = bank_account
split_merchant.agreements = agreements

result = braspagSdk.split.create_split_merchant(split_merchant)
merchant_id = result['id']
print(f'Created Braspag Split Subordinate Merchant: {merchant_id}')
```

### Other

```python
from braspag_sdk import Braspag

# Configuration.
braspagSdk: Braspag = ...

# Payments
payment_id = ...
braspagSdk.payments.get_sale(payment_id)
braspagSdk.payments.capture_sale(payment_id, amount=...)
braspagSdk.payments.cancel_sale(payment_id, amount=...)

# Generate access token for EMV 3DS.
# Learn more: https://braspag.github.io//manual/emv3ds#1.-criando-o-token-de-acesso
establishment_code = ...
merchant_name = ...
mcc = ...
braspagSdk.emv3ds.get_access_token(establishment_code, merchant_name, mcc)

# Generate access token for Silent Order Post.
# Learn more: https://braspag.github.io//manualp/braspag-silent-order-post#2.-obtendo-accesstoken-sop
braspagSdk.sop.get_access_token()
```

# License
Licensed under the MIT license, see [`LICENSE`](LICENSE).
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/romatallinn/braspagSdk-python",
    "name": "braspag-sdk",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "",
    "keywords": "braspag,sdk,python,cielo,api,ecommerce,brazil,payments",
    "author": "Roman Sirokov",
    "author_email": "sirokov@dizconto.com",
    "download_url": "https://files.pythonhosted.org/packages/90/e6/bd693d19044e18cac85221a1de2e3985203a26f304159304b9855ccf4d2d/braspag_sdk-0.0.7.tar.gz",
    "platform": null,
    "description": "# Braspag SDK for Python\n[![PyPi page link -- version](https://img.shields.io/pypi/v/braspag-sdk.svg)](https://pypi.python.org/pypi/braspag-sdk)\n[![License](https://img.shields.io/github/license/romatallinn/braspagSdk-python)](LICENSE)\n\n\nAn unofficial Python SDK for [Braspag](https://braspag.github.io/).\n\n## Disclaimer\nThis SDK is created for personal use and the functionality is limited to the needs of my projects.\nYou are more than welcome to contribute the code you need as soon as it follows the same code style.\nFortunately, this is a very simple SDK, so it should be easy to understand and extend.\n\n# Getting Started\n\n## Installation\n```bash\npip install --upgrade braspag-sdk\n```\n\n## Configuration\n```python\nimport os\n\nfrom braspag_sdk import Braspag, MerchantCredentials, SplitCredentials, EMV3DSCredentials, SilentOrderPostCredentials\n\nmerchant_creds = MerchantCredentials(\n    merchant_id=os.environ.get('BRASPAG_MERCHANT_ID'),\n    merchant_key=os.environ.get('BRASPAG_MERCHANT_KEY'),\n)\n\nsplit_creds = SplitCredentials(\n    client_secret=os.environ.get('BRASPAG_SPLIT_CLIENT_SECRET'),\n)\n\nemv3ds_creds = EMV3DSCredentials(\n    client_id=os.environ.get('BRASPAG_EMV3DS_CLIENT_ID'),\n    client_secret=os.environ.get('BRASPAG_EMV3DS_CLIENT_SECRET'),\n)\n\nsop_creds = SilentOrderPostCredentials(\n    client_id=os.environ.get('BRASPAG_SOP_CLIENT_ID'),\n    client_secret=os.environ.get('BRASPAG_SOP_CLIENT_SECRET'),\n)\n\nbraspagSdk = Braspag(merchant_creds, is_sandbox=True)\nbraspagSdk.add_split(split_creds)\nbraspagSdk.add_emv3ds(emv3ds_creds)\nbraspagSdk.add_sop(sop_creds)\n```\n\n## Usage\n\n### Creating a payment\n[Official Documentation](https://braspag.github.io//manual/braspag-pagador)\n\n```python\nfrom braspag_sdk import Braspag, Sale, Customer, Address, CreditCard, Payment, SplitPayment\n\n# Configuration\nbraspagSdk: Braspag = ...\n\nprint(f'Creating payment transaction in Braspag...')\n\n# Prepare the basic sale info.\nsale = Sale(merchant_order_id=...)\n\n# Prepare the customer info.\nsale.customer = Customer(name=...)\nsale.customer.email = ...\nsale.customer.identity = ...\nsale.customer.identity_type = ...   # 'cpf' or 'cnpj'\n\n# Prepare the customer's address.\nsale_address = Address()\nsale_address.street = ...\nsale_address.number = ...\nsale_address.complement = ...\nsale_address.zip_code = ...\nsale_address.city = ...\nsale_address.state = ...\nsale_address.country = ...\nsale.customer.address = sale_address\n\n# Prepare the payment info and credit card for it.\n# Most likely, you are not PCI compliant, so you will need to use Braspag's card tokenization.\ncredit_card = CreditCard(security_code=None, brand=None)\ncredit_card.card_token = ''\n\nsale.payment = Payment(amount=..., installments=...)\nsale.payment.soft_descriptor = ...,\nsale.payment.credit_card = credit_card\n\n# Split payment with subourdintate merchants.\nsubordinate_merchant_id = ...\namount = ...\nsale.payment.do_split = True\nsale.payment.split_payments = [\n    SplitPayment(subordinate_merchant_id, amount, mdr=..., fee=...)\n]\n\n# Create the payment in Cielo.\nsale_response = braspagSdk.payments.create_sale(sale)\npayment_response = sale_response['Payment']\n\n# Save the payment reference in Dizconto's database.\npayment_id = payment_response['PaymentId']\npayment_method = payment_response['Type']\npayment_status = payment_response['Status']\npayment_reason = payment_response['ReturnCode']\npayment_amount = payment_response['Amount']\nprint(f'Created Braspag Payment: {payment_id}')\n```\n\n### Creating a subordinate merchant\n[Official Documentation](https://braspag.github.io//manual/split-de-pagamentos-pagador)\n\n```python\nfrom braspag_sdk import Braspag, SplitMerchant, SplitMerchantAddress, SplitMerchantBank, SplitMerchantAgreement\n\n# Configuration.\nbraspagSdk: Braspag = ...\nbraspagSdk.add_split(...)\n\nprint(f'Creating Braspag Split Subordinate Merchant...')\n\naddress = SplitMerchantAddress(\n    street=...,\n    number=...,\n    complement=...,\n    neighborhood=...,\n    zip_code=...,\n    city=...,\n    state=...,\n)\n\nbank_account = SplitMerchantBank(\n    bank=...,\n    bank_account_type=...,\n    number=...,\n    verifier_digit=...,\n    agency_number=...,\n    agency_digit=...,\n    operation=...,\n)\n\nagreements = [\n    SplitMerchantAgreement(\n        percent=...,\n        fee=...,\n    )\n]\n\nsplit_merchant = SplitMerchant(master_merchant_id=...)\nsplit_merchant.fancy_name = ...\nsplit_merchant.website = ...\nsplit_merchant.mail_address = ...\nsplit_merchant.contact_name = ...\nsplit_merchant.contact_phone = ...\nsplit_merchant.corporate_name = ...\nsplit_merchant.document_number = ...\nsplit_merchant.document_type = ...\nsplit_merchant.address = address\nsplit_merchant.bank_account = bank_account\nsplit_merchant.agreements = agreements\n\nresult = braspagSdk.split.create_split_merchant(split_merchant)\nmerchant_id = result['id']\nprint(f'Created Braspag Split Subordinate Merchant: {merchant_id}')\n```\n\n### Other\n\n```python\nfrom braspag_sdk import Braspag\n\n# Configuration.\nbraspagSdk: Braspag = ...\n\n# Payments\npayment_id = ...\nbraspagSdk.payments.get_sale(payment_id)\nbraspagSdk.payments.capture_sale(payment_id, amount=...)\nbraspagSdk.payments.cancel_sale(payment_id, amount=...)\n\n# Generate access token for EMV 3DS.\n# Learn more: https://braspag.github.io//manual/emv3ds#1.-criando-o-token-de-acesso\nestablishment_code = ...\nmerchant_name = ...\nmcc = ...\nbraspagSdk.emv3ds.get_access_token(establishment_code, merchant_name, mcc)\n\n# Generate access token for Silent Order Post.\n# Learn more: https://braspag.github.io//manualp/braspag-silent-order-post#2.-obtendo-accesstoken-sop\nbraspagSdk.sop.get_access_token()\n```\n\n# License\nLicensed under the MIT license, see [`LICENSE`](LICENSE).",
    "bugtrack_url": null,
    "license": "",
    "summary": "An unofficial Python SDK for Braspag",
    "version": "0.0.7",
    "project_urls": {
        "Homepage": "https://github.com/romatallinn/braspagSdk-python",
        "Repository": "https://github.com/romatallinn/braspagSdk-python"
    },
    "split_keywords": [
        "braspag",
        "sdk",
        "python",
        "cielo",
        "api",
        "ecommerce",
        "brazil",
        "payments"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "223c9e3e5d243cd6e620434651cec58ccd16a9b1f0a148db45bb84678d9d0bf2",
                "md5": "58a2c964f5c113ca0b7281e69127e53b",
                "sha256": "577302a43f1ca5383bddb27dd2151b588879d7c5c9b879fd79593d00ddb2418b"
            },
            "downloads": -1,
            "filename": "braspag_sdk-0.0.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "58a2c964f5c113ca0b7281e69127e53b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 22998,
            "upload_time": "2024-03-13T15:31:41",
            "upload_time_iso_8601": "2024-03-13T15:31:41.452997Z",
            "url": "https://files.pythonhosted.org/packages/22/3c/9e3e5d243cd6e620434651cec58ccd16a9b1f0a148db45bb84678d9d0bf2/braspag_sdk-0.0.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "90e6bd693d19044e18cac85221a1de2e3985203a26f304159304b9855ccf4d2d",
                "md5": "6e9d12c8a18782fbfc951653c10edbec",
                "sha256": "0aa4799a226658dfb9dccbe6cea9c5a4c19847b80a70c3330dc9e4d1fa12bd94"
            },
            "downloads": -1,
            "filename": "braspag_sdk-0.0.7.tar.gz",
            "has_sig": false,
            "md5_digest": "6e9d12c8a18782fbfc951653c10edbec",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 12680,
            "upload_time": "2024-03-13T15:31:44",
            "upload_time_iso_8601": "2024-03-13T15:31:44.009690Z",
            "url": "https://files.pythonhosted.org/packages/90/e6/bd693d19044e18cac85221a1de2e3985203a26f304159304b9855ccf4d2d/braspag_sdk-0.0.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-13 15:31:44",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "romatallinn",
    "github_project": "braspagSdk-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "braspag-sdk"
}
        
Elapsed time: 0.22899s