{"id":18063284,"url":"https://github.com/danielweinmann/unlock_gateway","last_synced_at":"2025-04-11T15:36:53.152Z","repository":{"id":23010651,"uuid":"26361438","full_name":"danielweinmann/unlock_gateway","owner":"danielweinmann","description":"Base gateway for Unlock's payment gateway integrations","archived":false,"fork":false,"pushed_at":"2016-12-20T18:30:02.000Z","size":22,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T23:38:50.972Z","etag":null,"topics":[],"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/danielweinmann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-08T13:32:28.000Z","updated_at":"2016-12-20T18:30:03.000Z","dependencies_parsed_at":"2022-08-21T09:10:10.441Z","dependency_job_id":null,"html_url":"https://github.com/danielweinmann/unlock_gateway","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielweinmann%2Funlock_gateway","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielweinmann%2Funlock_gateway/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielweinmann%2Funlock_gateway/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielweinmann%2Funlock_gateway/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielweinmann","download_url":"https://codeload.github.com/danielweinmann/unlock_gateway/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248432244,"owners_count":21102338,"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":[],"created_at":"2024-10-31T05:10:29.868Z","updated_at":"2025-04-11T15:36:53.133Z","avatar_url":"https://github.com/danielweinmann.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# UnlockGateway [![Code Climate](https://codeclimate.com/github/danielweinmann/unlock_gateway.png)](https://codeclimate.com/github/danielweinmann/unlock_gateway)\n\nBase gateway for [Unlock](http://github.com/danielweinmann/unlock)'s payment gateway integrations\n\n## Installation\n\nCreate a Rails full Engine with:\n\n``` terminal\nrails plugin new unlock_my_gateway_name --full\n```\n\nAdd this line to your gateway's .gemspec file:\n\n``` ruby\ns.add_dependency \"unlock_gateway\"\n```\n\nRequire `unlock_gateway` before anything else:\n\n``` ruby\n# On lib/unlock_my_gateway_name.rb\nrequire \"unlock_gateway\"\n```\n\n## Usage\n\n### Gateway module\n\nEvery gateway should implement a module UnlockMyGatewayName::Models::Gateway that follows the pattern described [here](https://github.com/danielweinmann/unlock_gateway/blob/master/lib/unlock_gateway/models/gateway.rb). You should add the following to this module:\n\n``` ruby\ninclude UnlockGateway::Models::Gateway\n```\n\n### Contribution module\n\nEvery gateway should implement a module UnlockMyGatewayName::Models::Contribution that follows the pattern described [here](https://github.com/danielweinmann/unlock_gateway/blob/master/lib/unlock_gateway/models/contribution.rb). You should add the following to this module:\n\n``` ruby\ninclude UnlockGateway::Models::Contribution\n```\n\n### Setting class\n\nTo let Unlock know what are the settings for this gateway, you should implement a method called _available_settings_ in your UnlockMyGatewayName::Models::Gateway that returns an array of [UnlockGateway::Setting](https://github.com/danielweinmann/unlock_gateway/blob/master/lib/unlock_gateway/setting.rb). Here is an example:\n\n``` ruby\n# In your lib/unlock_my_gateway_name/models/gateway.rb\nmodule UnlockMyGatewayName\n  module Models\n    module Gateway\n\n      include UnlockGateway::Models::Gateway\n\n      def available_settings\n        settings = []\n        settings \u003c\u003c UnlockGateway::Setting.new(:token, \"Your API token\", \"Instructions\")\n        settings \u003c\u003c UnlockGateway::Setting.new(:key, \"Your API key\", \"Instructions\")\n      end\n\n    end\n  end\nend\n```\n\n### Controller\n\nYou should define a ContributionsController in your gateway, such as\n\n``` ruby\nclass UnlockMyGatewayName::ContributionsController \u003c ::ApplicationController\n  is_unlock_gateway\nend\n```\n\nCalling `is_unlock_gateway` inside you controller will extend UnlockGateway::Controller::ClassMethods and include UnlockGateway::Controller, preparing your controller to be an unlock gateway controller. You can check out what is added to your controller [here](https://github.com/danielweinmann/unlock_gateway/blob/master/lib/unlock_gateway/controller.rb).\n\n### Views\n\nThe only view you _need_ to create is a partial called `unlock_my_gateway_name/contributions/_form`, that will receive a local variable `gateway`. In this partial you can render the [sandbox_warning](https://github.com/danielweinmann/unlock/blob/master/app/views/initiatives/contributions/_sandbox_warning.html.slim) and [base_form](https://github.com/danielweinmann/unlock/blob/master/app/views/initiatives/contributions/_base_form.html.slim) partials to avoid duplicating code. Here is an example:\n\n``` ruby\n# In your views/unlock_my_gateway_name/contributions/_form.html.slim\n= form_for @contribution, url: my_gateway_name_contributions_path, method: :post do |form|\n  = render partial: 'initiatives/contributions/sandbox_warning', locals: { gateway: gateway }\n  = render partial: 'initiatives/contributions/base_form', locals: { form: form, gateway: gateway }\n  = form.submit \"Proceed to checkout\"\n```\n\n### Routes\n\nYou should add a `:my_gateway_name_contributions` resource in your `config/routes.rb` that uses `UnlockMyGatewayName::ContributionsController` and has the same path as you've defined in `UnlockMyGatewayName::Models::Gateway#path`. You should also always add member actions `activate` and `suspend`. Here is an example:\n\n``` ruby\n# In your config/routes.rb\nRails.application.routes.draw do\n\n  resources :my_gateway_name_contributions, controller: 'unlock_my_gateway_name/contributions', only: [:create, :edit, :update], path: '/my_gateway_name' do\n    member do\n      put :activate\n      put :suspend\n    end\n  end\n\nend\n```\n\n### Registering the gateway with Unlock's Gateway model\n\nYou should add an initializer to register the gateway, otherwise it won't show as an option for Unlock's users.\n\n``` ruby\n# In your config/initializers/register.rb\nUnlockGateway.register 'UnlockMyGatewayName'\n```\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n\n\nThis project rocks and uses MIT-LICENSE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielweinmann%2Funlock_gateway","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielweinmann%2Funlock_gateway","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielweinmann%2Funlock_gateway/lists"}