moiper 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +20 -1
- data/lib/moiper/notification.rb +80 -0
- data/lib/moiper/notification_controller_helper.rb +9 -0
- data/lib/moiper/railtie.rb +34 -0
- data/lib/moiper/version.rb +1 -1
- data/lib/moiper.rb +2 -0
- data/spec/moiper/notification_controller_helper_spec.rb +29 -0
- data/spec/moiper/notification_spec.rb +30 -0
- metadata +15 -8
    
        data/README.md
    CHANGED
    
    | @@ -48,7 +48,26 @@ payment = Moiper::Payment.new( | |
| 48 48 |  | 
| 49 49 | 
             
            response = payment.checkout
         | 
| 50 50 |  | 
| 51 | 
            -
            redirect_to response.checkout_url if  | 
| 51 | 
            +
            redirect_to response.checkout_url if response.success?
         | 
| 52 | 
            +
            ```
         | 
| 53 | 
            +
             | 
| 54 | 
            +
            ### Notifications
         | 
| 55 | 
            +
             | 
| 56 | 
            +
            Moip will notify your application with a POST, you can see more information at this url: http://labs.moip.com.br/referencia/nasp/
         | 
| 57 | 
            +
             | 
| 58 | 
            +
            ```ruby
         | 
| 59 | 
            +
            class OrdersController < ApplicationController
         | 
| 60 | 
            +
              include Moiper::NotificationControllerHelper
         | 
| 61 | 
            +
             | 
| 62 | 
            +
              def confirm
         | 
| 63 | 
            +
                moip_notification do |notification|
         | 
| 64 | 
            +
                  # Here you can update your database with updated information from Moip
         | 
| 65 | 
            +
                  @order = Order.find_by_unique_identifier(notification.id)
         | 
| 66 | 
            +
                  @order.update_attribute :status, notification.payment_status
         | 
| 67 | 
            +
                  @order.save
         | 
| 68 | 
            +
                end
         | 
| 69 | 
            +
              end
         | 
| 70 | 
            +
            end
         | 
| 52 71 | 
             
            ```
         | 
| 53 72 |  | 
| 54 73 | 
             
            ## Disclaimer
         | 
| @@ -0,0 +1,80 @@ | |
| 1 | 
            +
            module Moiper
         | 
| 2 | 
            +
              class Notification
         | 
| 3 | 
            +
                PAYMENT_STATUSES = {
         | 
| 4 | 
            +
                  1 => :authorized,
         | 
| 5 | 
            +
                  2 => :started,
         | 
| 6 | 
            +
                  3 => :payment_form_printed,
         | 
| 7 | 
            +
                  4 => :finished,
         | 
| 8 | 
            +
                  5 => :canceled,
         | 
| 9 | 
            +
                  6 => :under_analysis,
         | 
| 10 | 
            +
                  7 => :returned,
         | 
| 11 | 
            +
                  9 => :reimbursed
         | 
| 12 | 
            +
                }
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                FINANCIAL_INSTITUTIONS = {
         | 
| 15 | 
            +
                  1 => "MoIP",
         | 
| 16 | 
            +
                  3 => "Visa",
         | 
| 17 | 
            +
                  7 => "AmericanExpress",
         | 
| 18 | 
            +
                  5 => "Mastercard",
         | 
| 19 | 
            +
                  6 => "Diners",
         | 
| 20 | 
            +
                  8 => "BancoDoBrasil",
         | 
| 21 | 
            +
                  22 => "Bradesco",
         | 
| 22 | 
            +
                  13 => "Itau",
         | 
| 23 | 
            +
                  75 => "Hipercard",
         | 
| 24 | 
            +
                  76 => "Paggo",
         | 
| 25 | 
            +
                  88 => "Banrisul"
         | 
| 26 | 
            +
                }
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                PAYMENT_METHODS = {
         | 
| 29 | 
            +
                  "BoletoBancario" => :payment_form,
         | 
| 30 | 
            +
                  "CartaoDeCredito" => :credit_card,
         | 
| 31 | 
            +
                  "DebitoBancario" => :debit,
         | 
| 32 | 
            +
                  "CartaoDeDebito" => :debit_card,
         | 
| 33 | 
            +
                  "FinanciamentoBancario" => :financing,
         | 
| 34 | 
            +
                  "CarteiraMoIP" => :moip_account
         | 
| 35 | 
            +
                }
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                attr_reader :params
         | 
| 38 | 
            +
                private :params
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                def initialize(params)
         | 
| 41 | 
            +
                  @params = params
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                def id
         | 
| 45 | 
            +
                  params["id_transacao"]
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                def price
         | 
| 49 | 
            +
                  params["valor"].to_i / 100.0
         | 
| 50 | 
            +
                end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                def payment_status
         | 
| 53 | 
            +
                  PAYMENT_STATUSES[params["status_pagamento"].to_i]
         | 
| 54 | 
            +
                end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                def moip_id
         | 
| 57 | 
            +
                  params["cod_moip"].to_i
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                def financial_institution
         | 
| 61 | 
            +
                  FINANCIAL_INSTITUTIONS[params["forma_pagamento"].to_i]
         | 
| 62 | 
            +
                end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                def payment_method
         | 
| 65 | 
            +
                  PAYMENT_METHODS[params["tipo_pagamento"]]
         | 
| 66 | 
            +
                end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                def quotas
         | 
| 69 | 
            +
                  params["parcelas"].to_i
         | 
| 70 | 
            +
                end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                def user_email
         | 
| 73 | 
            +
                  params["email_consumidor"]
         | 
| 74 | 
            +
                end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                def additional_info
         | 
| 77 | 
            +
                  params["classificacao"]
         | 
| 78 | 
            +
                end
         | 
| 79 | 
            +
              end
         | 
| 80 | 
            +
            end
         | 
| @@ -0,0 +1,34 @@ | |
| 1 | 
            +
            module Moiper
         | 
| 2 | 
            +
              class Railtie < Rails::Railtie
         | 
| 3 | 
            +
                # Expose Moiper's configuration to the Rails application configuration.
         | 
| 4 | 
            +
                #
         | 
| 5 | 
            +
                #   module MyApplication
         | 
| 6 | 
            +
                #     class Application < Rails::Application
         | 
| 7 | 
            +
                #       config.moiper.sandbox = true
         | 
| 8 | 
            +
                #       config.moiper.token = "teste"
         | 
| 9 | 
            +
                #       config.moiper.key = "secret"
         | 
| 10 | 
            +
                #     end
         | 
| 11 | 
            +
                #   end
         | 
| 12 | 
            +
                config.moiper = Moiper
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                initializer "load notification controller helper" do
         | 
| 15 | 
            +
                  require "moiper/notification_controller_helper"
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                initializer "load moiper.yml file" do
         | 
| 19 | 
            +
                  config_file = Rails.root.join("config", "moiper.yml")
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                  if config_file.file?
         | 
| 22 | 
            +
                    yaml = YAML.load(File.read(config_file))[Rails.env]
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                    if yaml
         | 
| 25 | 
            +
                      Moiper.configure do |config|
         | 
| 26 | 
            +
                        config.sandbox = yaml["sandbox"]
         | 
| 27 | 
            +
                        config.token = yaml["token"]
         | 
| 28 | 
            +
                        config.key = yaml["key"]
         | 
| 29 | 
            +
                      end
         | 
| 30 | 
            +
                    end
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
            end
         | 
    
        data/lib/moiper/version.rb
    CHANGED
    
    
    
        data/lib/moiper.rb
    CHANGED
    
    
| @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            require "spec_helper"
         | 
| 2 | 
            +
            require "moiper/notification_controller_helper"
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            describe Moiper::NotificationControllerHelper do
         | 
| 5 | 
            +
              class DummyController
         | 
| 6 | 
            +
                include Moiper::NotificationControllerHelper
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def params
         | 
| 9 | 
            +
                  {}
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              describe "#moip_notification" do
         | 
| 14 | 
            +
                it "yields a Moip::Notification object" do
         | 
| 15 | 
            +
                  controller = DummyController.new
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  controller.moip_notification do |notification|
         | 
| 18 | 
            +
                    notification.should be_kind_of Moiper::Notification
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                it "allows custom params option" do
         | 
| 23 | 
            +
                  controller = DummyController.new
         | 
| 24 | 
            +
                  params = {}
         | 
| 25 | 
            +
                  Moiper::Notification.should_receive(:new).with(params)
         | 
| 26 | 
            +
                  controller.moip_notification(params)
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
            end
         | 
| @@ -0,0 +1,30 @@ | |
| 1 | 
            +
            require "spec_helper"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Moiper::Notification do
         | 
| 4 | 
            +
              let(:params) {
         | 
| 5 | 
            +
                {
         | 
| 6 | 
            +
                  "id_transacao" => "abc.1234",
         | 
| 7 | 
            +
                  "valor" => "50034",
         | 
| 8 | 
            +
                  "status_pagamento" => "5",
         | 
| 9 | 
            +
                  "cod_moip" => "12345678",
         | 
| 10 | 
            +
                  "forma_pagamento" => "3",
         | 
| 11 | 
            +
                  "tipo_pagamento" => "CartaoDeCredito",
         | 
| 12 | 
            +
                  "parcelas" => "1",
         | 
| 13 | 
            +
                  "email_consumidor" => "pagador@email.com.br",
         | 
| 14 | 
            +
                  "classificacao" => "Solicitado pelo vendedor"
         | 
| 15 | 
            +
                }
         | 
| 16 | 
            +
              }
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              # subject { Moiper::Notification.new(params) }
         | 
| 19 | 
            +
              subject { described_class.new(params) }
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              its(:id) { should eq "abc.1234" }
         | 
| 22 | 
            +
              its(:price) { should eq 500.34 }
         | 
| 23 | 
            +
              its(:payment_status) { should eq :canceled }
         | 
| 24 | 
            +
              its(:moip_id) { should eq 12345678 }
         | 
| 25 | 
            +
              its(:financial_institution) { should eq "Visa" }
         | 
| 26 | 
            +
              its(:payment_method) { should eq :credit_card }
         | 
| 27 | 
            +
              its(:quotas) { should eq 1 }
         | 
| 28 | 
            +
              its(:user_email) { should eq "pagador@email.com.br" }
         | 
| 29 | 
            +
              its(:additional_info) { should eq "Solicitado pelo vendedor" }
         | 
| 30 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: moiper
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0 | 
| 4 | 
            +
              version: 0.1.0
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,11 +9,11 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2013-01- | 
| 12 | 
            +
            date: 2013-01-23 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: nokogiri
         | 
| 16 | 
            -
              requirement: & | 
| 16 | 
            +
              requirement: &2160905440 !ruby/object:Gem::Requirement
         | 
| 17 17 | 
             
                none: false
         | 
| 18 18 | 
             
                requirements:
         | 
| 19 19 | 
             
                - - ! '>='
         | 
| @@ -21,10 +21,10 @@ dependencies: | |
| 21 21 | 
             
                    version: '0'
         | 
| 22 22 | 
             
              type: :runtime
         | 
| 23 23 | 
             
              prerelease: false
         | 
| 24 | 
            -
              version_requirements: * | 
| 24 | 
            +
              version_requirements: *2160905440
         | 
| 25 25 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 26 26 | 
             
              name: rspec
         | 
| 27 | 
            -
              requirement: & | 
| 27 | 
            +
              requirement: &2160904920 !ruby/object:Gem::Requirement
         | 
| 28 28 | 
             
                none: false
         | 
| 29 29 | 
             
                requirements:
         | 
| 30 30 | 
             
                - - ! '>='
         | 
| @@ -32,7 +32,7 @@ dependencies: | |
| 32 32 | 
             
                    version: '0'
         | 
| 33 33 | 
             
              type: :development
         | 
| 34 34 | 
             
              prerelease: false
         | 
| 35 | 
            -
              version_requirements: * | 
| 35 | 
            +
              version_requirements: *2160904920
         | 
| 36 36 | 
             
            description: Moip payment service integration library.
         | 
| 37 37 | 
             
            email:
         | 
| 38 38 | 
             
            - rnavarro1@gmail.com
         | 
| @@ -47,11 +47,16 @@ files: | |
| 47 47 | 
             
            - Rakefile
         | 
| 48 48 | 
             
            - lib/moiper.rb
         | 
| 49 49 | 
             
            - lib/moiper/cacert.pem
         | 
| 50 | 
            +
            - lib/moiper/notification.rb
         | 
| 51 | 
            +
            - lib/moiper/notification_controller_helper.rb
         | 
| 50 52 | 
             
            - lib/moiper/payment.rb
         | 
| 53 | 
            +
            - lib/moiper/railtie.rb
         | 
| 51 54 | 
             
            - lib/moiper/request.rb
         | 
| 52 55 | 
             
            - lib/moiper/response.rb
         | 
| 53 56 | 
             
            - lib/moiper/version.rb
         | 
| 54 57 | 
             
            - moiper.gemspec
         | 
| 58 | 
            +
            - spec/moiper/notification_controller_helper_spec.rb
         | 
| 59 | 
            +
            - spec/moiper/notification_spec.rb
         | 
| 55 60 | 
             
            - spec/moiper/payment_spec.rb
         | 
| 56 61 | 
             
            - spec/moiper/request_spec.rb
         | 
| 57 62 | 
             
            - spec/moiper/response_spec.rb
         | 
| @@ -71,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 71 76 | 
             
                  version: '0'
         | 
| 72 77 | 
             
                  segments:
         | 
| 73 78 | 
             
                  - 0
         | 
| 74 | 
            -
                  hash:  | 
| 79 | 
            +
                  hash: 3233836298932843302
         | 
| 75 80 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 76 81 | 
             
              none: false
         | 
| 77 82 | 
             
              requirements:
         | 
| @@ -80,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 80 85 | 
             
                  version: '0'
         | 
| 81 86 | 
             
                  segments:
         | 
| 82 87 | 
             
                  - 0
         | 
| 83 | 
            -
                  hash:  | 
| 88 | 
            +
                  hash: 3233836298932843302
         | 
| 84 89 | 
             
            requirements: []
         | 
| 85 90 | 
             
            rubyforge_project: 
         | 
| 86 91 | 
             
            rubygems_version: 1.8.11
         | 
| @@ -88,6 +93,8 @@ signing_key: | |
| 88 93 | 
             
            specification_version: 3
         | 
| 89 94 | 
             
            summary: Moip payment service integration library.
         | 
| 90 95 | 
             
            test_files:
         | 
| 96 | 
            +
            - spec/moiper/notification_controller_helper_spec.rb
         | 
| 97 | 
            +
            - spec/moiper/notification_spec.rb
         | 
| 91 98 | 
             
            - spec/moiper/payment_spec.rb
         | 
| 92 99 | 
             
            - spec/moiper/request_spec.rb
         | 
| 93 100 | 
             
            - spec/moiper/response_spec.rb
         |