December 23, 2025

Transbank Integration in Your Online Store: Tuniforme Case Study

Transbank Integration in Your Online Store: Tuniforme Case Study

Transbank Integration in Your Online Store: Tuniforme Case Study

If you’re developing an online store in Chile, sooner or later you’ll need to integrate Transbank, the country’s main payment gateway. 💳

In this tutorial, I’ll show you how to integrate Transbank based on my experience with Tuniforme, a uniform store with inventory management and order system.


🏪 Project Context: Tuniforme

Tuniforme is a web application I developed for a development workshop, which includes:

✅ Product catalog (uniforms)
✅ Inventory management with low stock alerts
✅ Order and tracking system
✅ Purchase history by user
Payment gateway with Transbank
✅ Roles: Administrator, Employee, User

🔗 Live demo: tuniforme.onrender.com


💡 What is Transbank?

Transbank is Chile’s main electronic payment company. It processes payments with:

  • Credit and debit cards
  • Webpay Plus
  • Oneclick
  • Patpass

It’s the standard payment gateway for e-commerce in Chile, and integrating it is essential if you want to accept online payments in the Chilean market.


🔧 Prerequisites

Before starting, you need:

  1. Developer account at Transbank
  2. Transbank SDK (Python, PHP, Java, etc.)
  3. Test environment (sandbox)
  4. Security certificates

🚀 Step 1: Environment Configuration

First, you need to register as a developer at Transbank and get your API credentials. For development, you’ll use the sandbox environment with test credentials.

# Example configuration in Django/Flask
TRANSBANK_API_KEY = 'your-api-key'
TRANSBANK_SECRET = 'your-secret'
TRANSBANK_ENVIRONMENT = 'sandbox'  # or 'production'

💻 Step 2: Create the Transaction

When a user wants to make a payment, you need to create a transaction and redirect them to Transbank’s payment page.

# Simplified example
from transbank.webpay.webpay_plus.transaction import Transaction

def create_payment(amount, order_id):
    response = Transaction.create(
        buy_order=order_id,
        session_id=session_id,
        amount=amount,
        return_url='https://yoursite.com/payment/confirm'
    )
    return response['url'], response['token']

✅ Step 3: Confirm the Payment

After the user completes the payment on Transbank, they’re redirected back to your site. You need to confirm the transaction and update the order status.

def confirm_payment(token):
    response = Transaction.commit(token)

    if response['status'] == 'AUTHORIZED':
        # Payment successful
        update_order_status(response['buy_order'], 'paid')
        return True
    else:
        # Payment failed
        return False

🛡️ Security and Best Practices

  • Never store card data on your server
  • Always validate the transaction on the server side
  • Use HTTPS for all payment-related pages
  • Log all transactions for auditing
  • Handle errors gracefully and inform users clearly

🐛 Common Errors and Solutions

Error 1: Invalid token
Solution: Make sure you’re using the correct token and it hasn’t expired

Error 2: Transaction rejected
Solution: Check that the amount is correct and the user has sufficient funds

Error 3: Connection timeout
Solution: Implement retry logic and inform the user to check their order status


🎯 Conclusion

Integrating Transbank may seem complicated at first, but following these steps you’ll have your payment gateway working in no time.

Remember: Always test in the development environment before going to production.


📌 Complete code of the Tuniforme project available upon request

Share