Code Monkey home page Code Monkey logo

transbank-webpay's Introduction

Transbank::Webpay

Ruby Implementation of Transbank Webpay API SOAP

Installation

Add this line to your application's Gemfile:

gem 'transbank-webpay'

And then execute:

$ bundle

Or install it yourself as:

$ gem install transbank-webpay

Run the generator:

$ rails generate transbank_webpay:install

Usage

Init Transaction

response = Transbank::Webpay.init_transaction({
  buy_order:  'A1234567',
  session_id: '123456',
  return_url: 'http://web.com/return',
  final_url:  'http://web.com/finalize',
  amount:     12_000
})
 => #<Transbank::Webpay::Response valid: true, #<Transbank::Webpay::Struct token="12333b5bcd772565db2cbf36e88eafcca93a95dad29dd8bd6f44d6d37345", url="https://tbk-web.com/initTransactioninitTransaction">>
response.token
=> "12333b5bcd772565db2cbf36e88eafcca93a95dad29dd8bd6f44d6d37345"
response.url
=> "https://tbk-web.com/initTransaction"
response.valid?
=> true

Get Transaction Result

response = Transbank::Webpay.get_transaction_result(token)
=> #<Transbank::Webpay::Response valid: true, #<Transbank::Webpay::Struct accounting_date="0234", buy_order="A1234567", card_detail=#<Transbank::Webpay::Struct card_number=3456>, detail_output=#<Transbank::Webpay::Struct shares_number=0, amount=12000, commerce_code=237020000556, buy_order="A1234567", authorization_code=1234, payment_type_code="VN", response_code=0>, session_id=123456, transaction_date=Mon, 10 Jul 2016 10:00:00 -0400, url_redirection="https://tbk-web.com/filtroUnificado/voucher.cgi", vci="TSY">>
response.accounting_date
=> "0234"
response.buy_order
=> "A1234567"
response.card_detail.card_number
=> 3456
response.detail_output.shares_number
=> 0
response.detail_output.amount
=> 12000
response.detail_output.commerce_code
=> 237020000556
response.detail_output.buy_order
=> "A1234567"
response.detail_output.authorization_code
=> 1234
response.detail_output.payment_type_code
=> "VN"
response.response_code
=> 0
response.session_id
=> 123456
response.transaction_date
=> Mon, 10 Jul 2016 10:00:00 -0400
response.url_redirection
=> "https://tbk-web.com/filtroUnificado/voucher.cgi"
response.vci
=> "TSY"
response.valid?
=> true

Acknowledge Transaction

response = Transbank::Webpay.acknowledge_transaction(token)
=> #< Transbank::Webpay::Response valid: true>
response.valid?
=> true

Nullify

Transbank::Webpay.nullify({
  authorization_code: 1234,
  authorized_amount: 12_000,
  buy_order: 'A1234567',
  nullify_amount: 12_000
})
=> #<Transbank::Webpay::Response valid: true, #<Transbank::Webpay::Struct authorization_code=1415234, authorization_date=Mon, 10 Jul 2016 10:00:00 -0400, balance=0, nullified_amount=12000, token="8743gr557f7037005a48487197b0539a021436dabaf485c4947c95347ba1dgdw78">>

response.authorization_code
=> 1415234
response.authorization_date
=> Mon, 10 Jul 2016 10:00:00 -0400
response.balance
=> 0
response.nullified_amount
=> 12000
response.token
=> "8743gr557f7037005a48487197b0539a021436dabaf485c4947c95347ba1dgdw78"
response.valid?
=> true

Available response methods:

response.valid? # true or false if any errors occurred (exceptions included)
response.errors # errors array
response.errors_display? # errors for human
response.exception? # true or false if an exception occurred
response.exception # exception object
response.attributes # hash attributes response (token, reverse_code . . .)

Configuration

First, you need to set up your configuration:

rails generate transbank_webpay:install

Then edit (config/initializers/transbank_webpay.rb):

Transbank::Webpay.configure do |config|
  config.wsdl_transaction_url = 'WEBPAY_SOAP_URL'
  config.wsdl_nullify_url     = 'NULLIFY_WEBPAY_SOAP_URL'
  config.cert_path            = 'ABSOLUTE_PATH_TO_CRT_FILE'
  config.key_path             = 'ABSOLUTE_PATH_TO_KEY_FILE'
  config.server_cert_path     = 'ABSOLUTE_PATH_TO_SERVER_CRT_OR_PEM_FILE'
  config.commerce_code        = 'COMMERCE_CODE'
end

Contributing

  1. Fork it ( https://github.com/[my-github-username]/transbank-webpay/fork )
  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 a new Pull Request

License

transbank-webpay is released under the MIT License.

transbank-webpay's People

Contributors

ramon-sg avatar

Watchers

 avatar  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.