This repository has been archived by the owner on May 13, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ferblape/master
Mejora en el manejo de reportes
- Loading branch information
Showing
13 changed files
with
315 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
rvm use 1.9.2-p180@dm | ||
rvm use 1.9.2-p180@dm --create |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# coding: UTF-8 | ||
|
||
module DineroMailIpn | ||
class Report | ||
|
||
# Transaction status list | ||
PENDING_STATUS = 1 | ||
COMPLETED_STATUS = 2 | ||
CANCELLED_STATUS = 3 | ||
|
||
attr_reader :id, :amount | ||
|
||
def initialize(attributes) | ||
@id = attributes[:id] | ||
@amount = attributes[:amount] | ||
@state = attributes[:state] | ||
end | ||
|
||
def transaction_completed? | ||
@state == COMPLETED_STATUS | ||
end | ||
|
||
def transaction_pending? | ||
@state == PENDING_STATUS | ||
end | ||
|
||
def transaction_cancelled? | ||
@state == CANCELLED_STATUS | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# coding: UTF-8 | ||
|
||
module DineroMailIpn | ||
class Reporter | ||
|
||
# Report status list | ||
VALID_REPORT_STATUS = 1 | ||
MALFORMED_REPORT_STATUS = 2 | ||
INVALID_ACCOUNT_NUMBER_REPORT_STATUS = 3 | ||
INVALID_PASSWORD_REPORT_STATUS = 4 | ||
INVALID_REQUEST_TYPE_STATUS = 5 | ||
INVALID_TRANSACTION_ID_REQUEST_STATUS = 6 | ||
INVALID_PASSWORD_OR_ACCOUNT_NUMBER_REQUEST_STATUS = 7 | ||
TRANSACTION_NOT_FOUND_REQUEST_STATUS = 8 | ||
|
||
attr_reader :reports | ||
|
||
def initialize(xml_response) | ||
@doc = Nokogiri::XML(xml_response.downcase) | ||
@reports = build_reports | ||
end | ||
|
||
def valid? | ||
@doc.xpath("//estadoreporte").first.content.to_i == VALID_REPORT_STATUS | ||
end | ||
|
||
private | ||
|
||
def build_reports | ||
return [] if @doc.xpath("//operacion").empty? | ||
@doc.xpath("//operacion").map do |report_xml| | ||
DineroMailIpn::Report.new :id => report_xml.xpath("//id").first.content.to_i, | ||
:amount => report_xml.xpath("//monto").first.content.to_i, | ||
:state => report_xml.xpath("//estado").first.content.to_i | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?xml version="1.0" encoding="ISO-8859-1"?> | ||
<REPORTE> | ||
<ESTADOREPORTE>1</ESTADOREPORTE> | ||
<DETALLE> | ||
<OPERACIONES> | ||
<OPERACION> | ||
<ID>1</ID> | ||
<FECHA>12/29/2011 7:38:00 PM</FECHA> | ||
<ESTADO>2</ESTADO> | ||
<COMPRADOR> | ||
<EMAIL>email@customer.com</EMAIL> | ||
<DIRECCION/> | ||
<COMENTARIO/> | ||
</COMPRADOR> | ||
<MONTO>1010</MONTO> | ||
<MONTONETO>510</MONTONETO> | ||
<METODOPAGO>3</METODOPAGO> | ||
<ITEMS> | ||
<ITEM> | ||
<DESCRIPCION>Camiseta amarilla</DESCRIPCION> | ||
<MONEDA>1</MONEDA> | ||
<PRECIOUNITARIO>1010</PRECIOUNITARIO> | ||
<CANTIDAD>1</CANTIDAD> | ||
</ITEM> | ||
</ITEMS> | ||
</OPERACION> | ||
<OPERACION> | ||
<ID>2</ID> | ||
<FECHA>12/30/2011 17:38:00 PM</FECHA> | ||
<ESTADO>2</ESTADO> | ||
<COMPRADOR> | ||
<EMAIL>other-email@other-customer.com</EMAIL> | ||
<DIRECCION/> | ||
<COMENTARIO/> | ||
</COMPRADOR> | ||
<MONTO>2000</MONTO> | ||
<MONTONETO>710</MONTONETO> | ||
<METODOPAGO>3</METODOPAGO> | ||
<ITEMS> | ||
<ITEM> | ||
<DESCRIPCION>Sombrero rojo</DESCRIPCION> | ||
<MONEDA>1</MONEDA> | ||
<PRECIOUNITARIO>1000</PRECIOUNITARIO> | ||
<CANTIDAD>2</CANTIDAD> | ||
</ITEM> | ||
</ITEMS> | ||
</OPERACION> | ||
</OPERACIONES> | ||
</DETALLE> | ||
</REPORTE> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="ISO-8859-1"?> | ||
<REPORTE> | ||
<ESTADOREPORTE>1</ESTADOREPORTE> | ||
<DETALLE> | ||
<OPERACIONES> | ||
<OPERACION> | ||
<ID>1</ID> | ||
<FECHA>12/29/2011 7:38:00 PM</FECHA> | ||
<ESTADO>2</ESTADO> | ||
<COMPRADOR> | ||
<EMAIL>email@customer.com</EMAIL> | ||
<DIRECCION/> | ||
<COMENTARIO/> | ||
</COMPRADOR> | ||
<MONTO>1010</MONTO> | ||
<MONTONETO>510</MONTONETO> | ||
<METODOPAGO>3</METODOPAGO> | ||
<ITEMS> | ||
<ITEM> | ||
<DESCRIPCION>Camiseta amarilla</DESCRIPCION> | ||
<MONEDA>1</MONEDA> | ||
<PRECIOUNITARIO>1010</PRECIOUNITARIO> | ||
<CANTIDAD>1</CANTIDAD> | ||
</ITEM> | ||
</ITEMS> | ||
</OPERACION> | ||
</OPERACIONES> | ||
</DETALLE> | ||
</REPORTE> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,56 @@ | ||
# encoding: utf-8 | ||
|
||
require 'helper' | ||
require 'dinero_mail_ipn' | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
class TestDineroMailIpn < Test::Unit::TestCase | ||
|
||
context "when I query the Dinero Mail API via GET" do | ||
|
||
should "return OK for the query with valid Pin and Account parameters" do | ||
stub_get("/vender/ConsultaPago.asp?XML=1&Acount=17128254&Pin=AYCN7IXDTM&Email=ernesto%40ombushop.com&StartDate=20110702&EndDate=20110703", | ||
stub_get("/vender/ConsultaPago.asp?XML=1&Acount=17128254&Pin=AYCN7IXDTM&Email=ernesto%40ombushop.com&StartDate=20110702&EndDate=20110703", | ||
"ConsultaPagoOkWithoutCollections.xml") | ||
client = DineroMailIpn::Client.new(:email => 'ernesto@ombushop.com', :account => '17128254', :pin => 'AYCN7IXDTM') | ||
response = client.consulta_pago(Date.new(2011,7,2), Date.new(2011,7,3)) | ||
assert_equal response.state, "1" | ||
assert_equal response.state_description, "La consulta se realizó correctamente" | ||
end | ||
should "return Error for the query" do | ||
stub_get("/vender/ConsultaPago.asp?XML=1&Acount=123&Pin=UasdM&Email=ernesto%40ombushop.com&StartDate=20110702&EndDate=20110703", | ||
"ConsultaPagoErrorBadCredentials.xml") | ||
|
||
should "return Error for the query" do | ||
stub_get("/vender/ConsultaPago.asp?XML=1&Acount=123&Pin=UasdM&Email=ernesto%40ombushop.com&StartDate=20110702&EndDate=20110703", | ||
"ConsultaPagoErrorBadCredentials.xml") | ||
client = DineroMailIpn::Client.new(:email => 'ernesto@ombushop.com', :account => '123', :pin => 'UasdM') | ||
response = client.consulta_pago(Date.new(2011,7,2), Date.new(2011,7,3)) | ||
assert_equal response.state, "2" | ||
assert_equal response.state_description, "Los valores son incorrectos para realizar la consulta" | ||
end | ||
|
||
end | ||
|
||
context "when I query for some transactions" do | ||
|
||
should "return a new report object" do | ||
stub_post("/Vender/Consulta_IPN.asp", "ConsultaTransacciones1-2Success.xml", | ||
{:url => {:https => false}}) | ||
|
||
client = DineroMailIpn::Client.new(:password => 'fuckingipnpasswordinplaintext', :account => '17128254') | ||
reporter = client.consulta_transacciones(1,2) | ||
assert reporter.kind_of?(DineroMailIpn::Reporter) | ||
assert_equal 2, reporter.reports.size | ||
end | ||
|
||
end | ||
|
||
context "when I query for a transactions" do | ||
|
||
should "return a new report object" do | ||
stub_post("/Vender/Consulta_IPN.asp", "ConsultaTransacciones1Success.xml", | ||
{:url => {:https => false}}) | ||
|
||
client = DineroMailIpn::Client.new(:password => 'fuckingipnpasswordinplaintext', :account => '17128254') | ||
reporter = client.consulta_transacciones(1) | ||
assert reporter.kind_of?(DineroMailIpn::Reporter) | ||
assert_equal 1, reporter.reports.size | ||
end | ||
|
||
end | ||
end |
Oops, something went wrong.