Skip to main content

Python implementation of Transbank's Webpay protocol.

Project description

Attention: Beta not ready for production

Python implementation of Transbank’s Webpay protocol.

Latest Version Development Status Build Status Coverage Status Code Health Downloads

Installation

pip install tbk

Usage

Set environment variable for Commerce and initialize.

os.environ['TBK_COMMERCE_ID'] = "597026007976"
os.environ['TBK_COMMERCE_KEY'] = "-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEAn3HzPC1ZBzCO3edUCf/XJiwj3bzJpjjTi/zBO9O+DDzZCaMp...""

from tbk.webpay.commerce import Commerce

commerce = Commerce.create_commerce()
# for development purposes you can use
# commerce = Commerce(testing=True)

If you want to set the official webpay log (for certification issues):

from tbk.webpay.logging import configure_logger
from tbk.webpay.logging.official import WebpayOfficialHandler

configure_logger(WebpayOfficialHandler(LOG_BASE_PATH))

Create a new payment and redirect user.

from tbk.webpay.payment import Payment

payment = Payment(
    request_ip='123.123.123.123',
    commerce=commerce,
    success_url='http://localhost:8080/webpay/success/',
    confirmation_url='http://127.0.0.1:8080/webpay/confirmation/',
    failure_url='http://localhost:8080/webpay/failure/',
    session_id='SOME_SESSION_VALUE',
    amount=123456,
    order_id=1,
)
payment.redirect_url

Then to confirm payment, use an endpoint with:

from tbk.webpay.confirmation import Confirmation

def confirmation(request):
    conf = Confirmation(
        commerce=commerce,
        request_ip=request.ip_address,
        data=request.POST
    )

    # validate_confirmation validate if order_id and amount are valid.
    if conf.is_success() and validate_confirmation(conf) and not conf.is_timeout():
        return HttpResponse(commerce.acknowledge)

    return HttpResponse(commerce.reject)

About webpay communication protocol: http://sagmor.com/rants/technical/webpay-communication-protocol/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tbk-0.2.0.tar.gz (16.3 kB view details)

Uploaded Source

File details

Details for the file tbk-0.2.0.tar.gz.

File metadata

  • Download URL: tbk-0.2.0.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for tbk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 70fabaa6f5c31cc7caf94f5ee4f21b1d5ab374dfe80af88f9398b641c9672691
MD5 99f6e10ef9b6c46eb8092fd63492e3e3
BLAKE2b-256 7cc0ac32b0129d595af6b393fb40d8ec97614fcac9db83cb29c7dd525d9fd43f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page