Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #7 from lucasruroken/master
Browse files Browse the repository at this point in the history
Up-to-date with lucasruroken repo
  • Loading branch information
Lucas Juarez authored Feb 24, 2017
2 parents 6645e22 + d1ec337 commit a7677dc
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 56 deletions.
24 changes: 7 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,16 @@ Spree Mercado Pago Payment Method
This project is compatible with spree 3.2.0 and Rails 5

```
gem 'spree_mercado_pago', '~> 3.2.0.rc2', git: "[email protected]:lucasruroken/spree_mercado_pago.git"
gem 'spree_mercado_pago', '~> 3.2.0.rc2', git: "[email protected]:manuca/spree_mercado_pago.git"
```

If you want to use this gem with spree 2.3 or 2.4, you should use the original repo:
```
gem 'spree_mercado_pago', git: "[email protected]:manuca/spree_mercado_pago.git"
```

inside your project run
You should run inside your project

```
bundle exec rails g spree_mercado_pago:install
```

to import assets and migrations.
This will import assets and migrations

Usage
-----
Expand All @@ -32,15 +27,10 @@ IPN
For IPN you need to configure the notification URL in Mercado Pago's site. The notification URL will be `http[s]://[your_domain]/mercado_pago/ipn`. Please review Mercado Pago's documentation at http://developers.mercadopago.com/ for the correct place where to configure IPN notification URLs.


Pending Work
------------

- Configurable currency

Testing
-------

- clone this repo
- execute `bundle`
- execute `rake test_app` to build a dummy app directory inside specs
- execute `bundle exec rspec spec`
- Clone this repo
- Execute `bundle`
- Execute `rake test_app` to build a dummy app directory inside specs
- Execute `bundle exec rspec spec`
2 changes: 1 addition & 1 deletion app/models/mercado_pago/client/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def preferences_url(token)
end

def sandbox
@api_options[:sandbox]
Rails.application.try(:secrets).try(:[], :mercadopago).try(:[], "sandbox")
end

def get(url, request_options={}, options={})
Expand Down
4 changes: 2 additions & 2 deletions app/models/mercado_pago/client/authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ def send_authentication_request
end

def client_id
@payment_method.preferred_client_id
Rails.application.try(:secrets).try(:[], :mercadopago).try(:[], "client_id")
end

def client_secret
@payment_method.preferred_client_secret
Rails.application.try(:secrets).try(:[], :mercadopago).try(:[], "client_secret")
end

def access_token
Expand Down
7 changes: 4 additions & 3 deletions app/models/spree/payment_method/mercado_pago.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
module Spree
class PaymentMethod::MercadoPago < PaymentMethod
preference :client_id, :integer
preference :client_secret, :string
preference :sandbox, :boolean, default: true

def payment_profiles_supported?
false
Expand All @@ -29,6 +26,10 @@ def auto_capture?
false
end

def preferred_sandbox
Rails.application.try(:secrets).try(:[], :mercadopago).try(:[], "sandbox")
end

## Admin options

def can_void?(payment)
Expand Down
38 changes: 18 additions & 20 deletions spec/controllers/spree/mercado_pago_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
require 'spec_helper'

module Spree
describe MercadoPagoController do
describe "#ipn" do
let(:operation_id) { "op123" }
RSpec.describe Spree::MercadoPagoController, type: :controller do
describe "#ipn" do
let(:operation_id) { "op123" }

describe "for valid notifications" do
let(:use_case) { double("use_case") }
context "for valid notifications" do
let(:use_case) { double("use_case") }

it "handles notification and returns success" do
allow(MercadoPago::HandleReceivedNotification).to receive(:new).and_return(use_case)
expect(use_case).to receive(:process!)
it "handles notification and returns success" do
allow(MercadoPago::HandleReceivedNotification).to receive(:new).and_return(use_case)
expect(use_case).to receive(:process!)

spree_post :ipn, { id: operation_id, topic: "payment" }
expect(response).to be_success
spree_post :ipn, { id: operation_id, topic: "payment" }
expect(response).to be_success

notification = ::MercadoPago::Notification.order(:created_at).last
expect(notification.topic).to eq("payment")
expect(notification.operation_id).to eq(operation_id)
end
notification = MercadoPago::Notification.order(:created_at).last
expect(notification.topic).to eq("payment")
expect(notification.operation_id).to eq(operation_id)
end
end

describe "for invalid notification" do
it "responds with invalid request" do
spree_post :ipn, { id: operation_id, topic: "nonexistent_topic" }
expect(response).to be_bad_request
end
context "for invalid notification" do
it "responds with invalid request" do
spree_post :ipn, { id: operation_id, topic: "nonexistent_topic" }
expect(response).to be_bad_request
end
end
end
Expand Down
16 changes: 4 additions & 12 deletions spec/models/mercado_pago/client_spec.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
require 'spec_helper'
require 'json'

describe MercadoPago::Client do
RSpec.describe MercadoPago::Client, type: :model do
SPEC_ROOT = File.expand_path('../', File.dirname(__FILE__))

let(:payment_method) do
double('payment_method', preferred_client_id: 1, preferred_client_secret: 1)
end
let(:payment_method){ double('payment_method', preferred_client_id: 1, preferred_client_secret: 1) }

let(:order) { double('order', payment_method: payment_method, number: 'testorder', line_items: [], ship_total: 1000) }
let(:url_callbacks) { {success: 'url', failure: 'url', pending: 'url'} }
let(:payment_method) { double :payment_method, id: 1, preferred_client_id: 'app id', preferred_client_secret: 'app secret' }
let(:payment) {double :payment, payment_method:payment_method, id:1, identifier:"fruta" }

let(:login_json_response) do
File.open("#{SPEC_ROOT}/../fixtures/authenticated.json").read
end

let(:preferences_json_response) do
File.open("#{SPEC_ROOT}/../fixtures/preferences_created.json").read
end

let(:login_json_response){ File.open("#{SPEC_ROOT}/../fixtures/authenticated.json").read }
let(:preferences_json_response){ File.open("#{SPEC_ROOT}/../fixtures/preferences_created.json").read }
let(:client) { MercadoPago::Client.new(payment_method) }

describe '#initialize' do
Expand Down
1 change: 0 additions & 1 deletion spec/models/mercado_pago/order_preferences_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
let(:subject) { MercadoPago::OrderPreferencesBuilder.new(order, payment, callback_urls, payer_data).preferences_hash }

it "should return external reference" do
expect(subject).to include(external_reference:payment.number)
end

it "should set callback urls" do
Expand Down

0 comments on commit a7677dc

Please sign in to comment.