{"id":21714474,"url":"https://github.com/frizbee/kasikornbank","last_synced_at":"2025-07-10T15:41:14.909Z","repository":{"id":56879906,"uuid":"78923983","full_name":"frizbee/kasikornbank","owner":"frizbee","description":"This gem provides support for the accepting a credit cards payments with K-Payment Gateway (Kasikorn bank)","archived":false,"fork":false,"pushed_at":"2019-09-09T15:57:52.000Z","size":4205,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-19T04:05:02.415Z","etag":null,"topics":["ecommerce","gem","payment-gateway","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/frizbee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-14T07:19:00.000Z","updated_at":"2025-06-03T12:57:06.000Z","dependencies_parsed_at":"2022-08-20T11:40:45.355Z","dependency_job_id":null,"html_url":"https://github.com/frizbee/kasikornbank","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/frizbee/kasikornbank","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frizbee%2Fkasikornbank","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frizbee%2Fkasikornbank/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frizbee%2Fkasikornbank/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frizbee%2Fkasikornbank/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/frizbee","download_url":"https://codeload.github.com/frizbee/kasikornbank/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frizbee%2Fkasikornbank/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264599659,"owners_count":23635311,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ecommerce","gem","payment-gateway","ruby"],"created_at":"2024-11-26T00:35:31.838Z","updated_at":"2025-07-10T15:41:14.877Z","avatar_url":"https://github.com/frizbee.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/frizbee/kasikornbank.svg?branch=master)](https://travis-ci.org/frizbee/kasikornbank)\n[![Gem Version](https://badge.fury.io/rb/kasikornbank.svg)](https://badge.fury.io/rb/kasikornbank)\n[![Code Climate](https://codeclimate.com/github/frizbee/kasikornbank/badges/gpa.svg)](https://codeclimate.com/github/frizbee/kasikornbank)\n[![Issue Count](https://codeclimate.com/github/frizbee/kasikornbank/badges/issue_count.svg)](https://codeclimate.com/github/frizbee/kasikornbank)\n\n# Kasikorn Bank Payment Gateway (Thailand)\n\nThis gem provides support for the accepting a credit cards payments with\nK-Payment Gateway (Kasikorn Bank Payment Gateway)\n\nPlease check official documentation from KasikornBank [docs/kasikornbank.md](docs/kasikornbank.md) document last time updated at Aug 30, 2016\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'kasikornbank', '~\u003e 0.1.8'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install kasikornbank\n\n## Usage\n\n### 1 - Configuration\n\nGenerate initializer\n\n```ruby\nrails g kasikornbank:install\n```\nSet credentials and other options in `config/initializers/kasikornbank.rb`\n```ruby\nKasikornbank.configure do |config|\n  config.merchant2 = ENV[\"KBANK_MERCHANT2\"]\n  config.term2 = ENV[\"KBANK_TERM2\"]\n  config.kbank_secret = ENV[\"KBANK_SECRET\"]\n  config.url2 = \"https://www.example.com/kbank_back_url\"\n  config.respurl = \"https://www.example.com/kbank_notify_url\"\nend\n```\n\n`config.merchant2` = Merchant ID Your merchant number issued by KBank. Numeric 15 digits e.g. 401001234567001.\n`config.term2` = Terminal ID Your terminal ID issued by KBank. Numeric 8 digits e.g. 70123456.\n`config.kbank_secret` = Secret key (salt) to make md5 hash. Issued by KBank.\n`config.url2` = URL where cardholder will be redirected back to merchant website.\n`config.respurl` = Notify url. Must be SSL/TLS URL where KBank will send a variable PMGWRESP2.\n\n### 2 - Render Form\n\nIn your `checkout#create` method call\n```ruby\nkbank = Kasikornbank::Render.new({\n\tinvmerchant: \"987\",\n\tdetails2: \"Electric Fan = Model XYZ103\",\n\tip_address: \"111.111.111.205\",\n\tamount: 10.99,\n\tshop_id: \"00\",\n\tpayterm2: \"10\"\n})\n```\n\n`invmerchant` = Invoice number, should be a unique number.\n`details2` = Product description.\n`ip_address` = IP address of merchant's server.\n`amount` = Total amount of purchased order.\n`shop_id` = \u003c**Optional**\u003e Shop ID, for payment template, see documentation.\n`payterm2` = \u003c**Optional**\u003e Number of month for installment.\n\n\u003e :exclamation: Unfortunately, Kasikorn Bank doesn't have a proper way to handle payment API. In this case `Kasikornbank::Render.new()` will generage auto submit form and return it with `post` method. This form should be placed in `checkout#create` view file.\n\n#### Example\n\n_\\# app/controllers/checkout_controller.rb_\n\n```ruby\nrequire 'kasikornbank'\n\n....\n\ndef create\n\tkbank = Kasikornbank::Render.new({\n\t\tinvmerchant: \"987\",\n\t\tdetails2: \"Electric Fan = Model XYZ103\",\n\t\tip_address: \"111.111.111.205\",\n\t\tamount: 10.99\n\t})\n\t@form = kbank.form\nend\n```\n_\\# app/views/checkout/create.html.erb_\n```ruby\n\u003c%= @form.html_safe if @form.present? %\u003e\n```\n\n### 3 - Response\n\nTo be able to receive response from KBank you have to create another action in your checkout controller with post request as it is mandatory by KBank.\n\nIn your `routes.rb` file add `post 'checkout/kbank_response', to: 'checkout#kbank_response'` make sure that this line is out of scope of your locale.\n\nNext step is to avoid blocking request by CSRF rule. This post request will come directly from KBank server, you need to make sure that `checkout#kbank_response` action is not blocked by CSRF. To do that, go to `checkout_controller.rb` and add this line:  `skip_before_action :verify_authenticity_token, :only =\u003e [:kbank_response]` this will give access to post anything to your action. Scary huh?\n\nKBank will send response to your `checkout#kbank_response` action to\ncatch that respose use `Kasikornbank::Response.new(request.POST)` method\nin your controller. You will be provided with hash of data `{:response=\u003e\"success\", :invoice=\u003e\"17\", :amount=\u003e874.0, :auth_code=\u003enil}` use it to update your database.\n\n#### Example\n\n_\\# config/routes.rb_\n```ruby\nscope \"/:locale\", locale: /en|th|zh/ do\n  ...\n  resources :checkout, only: [:new, :create]\n  ...\nend\npost \"checkout/kbank_response\", to: \"checkout#kbank_response\"\n```\n\n_\\# app/controllers/checkout_controller.rb_\n```ruby\nrequire 'kasikornbank'\nskip_before_action :verify_authenticity_token, :only =\u003e [:kbank_response, :kbank_notification]\n\n...\n# This is where cardholder will be re-directed back to merchant's website (POST request)\ndef kbank_response\n  response = Kasikornbank::Response.new(request.POST)\n  kbank = response.kbank_response\n  checkout = Checkout.find(kbank[:invoice])\n  ...\n  # Here update your DB\n  # and send confirmation emails\n  ...\nend\n\n# This URI where kbank will send a variable 'PMGWRESP2' to merchant's server (POST requrest)\ndef kbank_notification\n  response = Kasikornbank::Response.new(request.POST)\n  kbank = response.kbank_response\n  checkout = Checkout.find(kbank[:invoice])\n  ...\n  # Here update your DB\n  # and send confirmation emails\n  ...\nend\n```\n_\\# Response will be `{:respcode=\u003e\"00\", :response=\u003e\"success\", :invoice=\u003e\"21\", :amount=\u003e211.0, :auth_code=\u003e\"140580\", :card=\u003e\"4751XXXXXXXX1452\", :card_type=\u003e\"VISA\"}`_\n\u003e Controller name, routes, response url can be replaced with name you like.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nI would love if you find some time and contribute to this gem to improve open source for other developers.\n\nBug reports and pull requests are welcome on GitHub at https://github.com/frizbee/kasikornbank. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrizbee%2Fkasikornbank","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrizbee%2Fkasikornbank","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrizbee%2Fkasikornbank/lists"}