GithubHelp home page GithubHelp logo

javierpoo / tbk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sagmor/tbk

0.0 1.0 0.0 641 KB

Ruby implementation of Transbank's Webpay protocol

Home Page: http://sagmor.com/tbk

License: MIT License

tbk's Introduction

About

Gem Version Build Status Code Climate

This is a pure ruby replacement of Transbank's Binary Integration Kit (aka. KCC) developed to simplify the integration with it's payment gateway Webpay.

Disclaimer

This library is not developed, supported nor endorsed in any way by Transbank S.A. and is the result of reverse engineering Transbank's Integration Kit (aka. KCC) for interoperability purposes as allowed by Chilean Law 20.435 Article 71 ร‘ Section b

Usage

Add this line to your application's Gemfile:

gem 'tbk'

Configure your commerce

TBK.configure do |config|
  config.commerce_id YOUR_COMMERCE_ID
  config.commerce_key YOUR_RSA_KEY

  # When certifying with Transbank you'll need to use the official logger
  config.webpay_logger :official do |logger|
    # On this path will be the config file and logs in the KCC format.
    logger.directory Rails.root.join('log/webpay')
  end
end

To start a payment from your application

class WebpayController < ApplicationController

  # ...

  # Start a payment
  def pay
    # Setup the payment
    @payment = TBK::Webpay::Payment.new({
      request_ip: request.ip,
      amount: ORDER_AMOUNT,
      order_id: ORDER_ID,
      success_url: webpay_success_url,
      # Webpay can only access the HTTP protocol to a direct IP address (keep that in mind)
      confirmation_url: webpay_confirmation_url(host: SERVER_IP_ADDRESS, protocol: 'http'),

      # Optionaly supply:
      session_id: SOME_SESSION_VALUE,
      failure_url: webpay_failure_url # success_url is used by default
    })

    # Redirect the user to Webpay
    redirect_to @payment.redirect_url
  end

  # ...
end

And to process a payment

class WebpayController < ApplicationController

  # ...

  # Confirmation callback executed from Webpay servers
  def confirmation
    # Read the confirmation data from the request
    @confirmation = TBK::Webpay::Confirmation.new({
      request_ip: request.ip,
      body: request.raw_post
    })

    if # confirmation is invalid for some reason (wrong order_id or amount, double payment, etc...)
      render text: @confirmation.reject
      return # reject and stop execution
    end

    if @confirmation.success?
      # EXITO!
      # perform everything you have to do here.
    end

    # Acknowledge payment
    render text: @confirmation.acknowledge
  end

  # ...

end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Bitdeli Badge

tbk's People

Contributors

sagmor avatar bitdeli-chef avatar xaro avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.