GithubHelp home page GithubHelp logo

filabreu / unlock_gateway Goto Github PK

View Code? Open in Web Editor NEW

This project forked from danielweinmann/unlock_gateway

0.0 2.0 0.0 22 KB

Base gateway for Unlock's payment gateway integrations

License: MIT License

Ruby 100.00%

unlock_gateway's Introduction

UnlockGateway Code Climate

Base gateway for Unlock's payment gateway integrations

Installation

Create a Rails full Engine with:

rails plugin new unlock_my_gateway_name --full

Add this line to your gateway's .gemspec file:

s.add_dependency "unlock_gateway"

Require unlock_gateway before anything else:

# On lib/unlock_my_gateway_name.rb
require "unlock_gateway"

Usage

Gateway module

Every gateway should implement a module UnlockMyGatewayName::Models::Gateway that follows the pattern described here. You should add the following to this module:

include UnlockGateway::Models::Gateway

Contribution module

Every gateway should implement a module UnlockMyGatewayName::Models::Contribution that follows the pattern described here. You should add the following to this module:

include UnlockGateway::Models::Contribution

Setting class

To 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. Here is an example:

# In your lib/unlock_my_gateway_name/models/gateway.rb
module UnlockMyGatewayName
  module Models
    module Gateway

      include UnlockGateway::Models::Gateway

      def available_settings
        settings = []
        settings << UnlockGateway::Setting.new(:token, "Your API token", "Instructions")
        settings << UnlockGateway::Setting.new(:key, "Your API key", "Instructions")
      end

    end
  end
end

Controller

You should define a ContributionsController in your gateway, such as

class UnlockMyGatewayName::ContributionsController < ::ApplicationController
  is_unlock_gateway
end

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

Views

The 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 and base_form partials to avoid duplicating code. Here is an example:

# In your views/unlock_my_gateway_name/contributions/_form.html.slim
= form_for @contribution, url: my_gateway_name_contributions_path, method: :post do |form|
  = render partial: 'initiatives/contributions/sandbox_warning', locals: { gateway: gateway }
  = render partial: 'initiatives/contributions/base_form', locals: { form: form, gateway: gateway }
  = form.submit "Proceed to checkout"

Routes

You 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:

# In your config/routes.rb
Rails.application.routes.draw do

  resources :my_gateway_name_contributions, controller: 'unlock_my_gateway_name/contributions', only: [:create, :edit, :update], path: '/my_gateway_name' do
    member do
      put :activate
      put :suspend
    end
  end

end

Registering the gateway with Unlock's Gateway model

You should add an initializer to register the gateway, otherwise it won't show as an option for Unlock's users.

# In your config/initializers/register.rb
UnlockGateway.register 'UnlockMyGatewayName'

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

This project rocks and uses MIT-LICENSE.

unlock_gateway's People

Contributors

danielweinmann avatar filabreu avatar

Watchers

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