Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion lib/mymoip/requests/payment_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ class PaymentRequest < Request
REQUIRES_AUTH = false
FORMAT = :json
PAYMENT_SLIP_PATH = "/Instrucao.do?token="
STATUSES = {
"Autorizado" => 1,
"Iniciado" => 2,
"BoletoImpresso" => 3,
"Concluido" => 4,
"Cancelado" => 5,
"EmAnalise" => 6,
"Estornado" => 7,
"Reembolsado" => 9
}

attr_reader :token

Expand Down Expand Up @@ -49,5 +59,17 @@ def code
nil
end

def status
STATUSES[@response["Status"]]
rescue NoMethodError => e
nil
end

def total_payed
@response["TotalPago"]
rescue NoMethodError => e
nil
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at body end.

end
end
end
63 changes: 36 additions & 27 deletions test/lib/test_payment_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,51 +70,60 @@ def test_success_method_returns_false_in_payments_already_made
end

def test_method_to_get_moip_code
instruction = Fixture.instruction(payer: Fixture.payer)
transparent_request = MyMoip::TransparentRequest.new("your_own_id")
VCR.use_cassette('transparent_request') do
transparent_request.api_call(instruction)
end
credit_card_payment = MyMoip::CreditCardPayment.new(Fixture.credit_card, installments: 1)
payment_request = MyMoip::PaymentRequest.new("your_own_id")
VCR.use_cassette('payment_request') do
payment_request.api_call(credit_card_payment, token: transparent_request.token)
end
assert_equal 102596, payment_request.code
make_a_successfully_payment
assert_equal 102596, @payment_request.code
end

def test_method_to_get_status
make_a_successfully_payment
assert_equal 6, @payment_request.status
end

def test_method_to_get_total_payed
make_a_successfully_payment
assert_equal '200.00', @payment_request.total_payed
end

def test_code_method_should_return_nil_with_blank_response
instruction = Fixture.instruction(payer: Fixture.payer)
transparent_request = MyMoip::TransparentRequest.new("your_own_id")
VCR.use_cassette('transparent_request') do
transparent_request.api_call(instruction)
end
credit_card_payment = MyMoip::CreditCardPayment.new(Fixture.credit_card, installments: 1)
payment_request = MyMoip::PaymentRequest.new("your_own_id")
assert_nil payment_request.code
end

def test_status_method_should_return_nil_with_blank_response
payment_request = MyMoip::PaymentRequest.new("your_own_id")
assert_nil payment_request.status
end

def test_total_payed_method_should_return_nil_with_blank_response
payment_request = MyMoip::PaymentRequest.new("your_own_id")
assert_nil payment_request.total_payed
end

def test_method_to_get_response_url
make_a_successfully_payment
assert_equal "https://desenvolvedor.moip.com.br/sandbox/Instrucao.do?token=#{@transparent_request.token}", @payment_request.url
end

def test_url_method_should_return_nil_with_blank_response
instruction = Fixture.instruction(payer: Fixture.payer)
transparent_request = MyMoip::TransparentRequest.new("your_own_id")
VCR.use_cassette('transparent_request') do
transparent_request.api_call(instruction)
end
payment_slip_payment = MyMoip::PaymentSlipPayment.new
payment_request = MyMoip::PaymentRequest.new("your_own_id")
VCR.use_cassette('payment_request_with_payment_slip') do
payment_request.api_call(payment_slip_payment, token: transparent_request.token)
end
assert_equal "https://desenvolvedor.moip.com.br/sandbox/Instrucao.do?token=#{transparent_request.token}", payment_request.url
assert_nil payment_request.url
end

def test_url_method_should_return_nil_with_blank_response
def make_a_successfully_payment
instruction = Fixture.instruction(payer: Fixture.payer)
transparent_request = MyMoip::TransparentRequest.new("your_own_id")
@transparent_request = MyMoip::TransparentRequest.new("your_own_id")
VCR.use_cassette('transparent_request') do
transparent_request.api_call(instruction)
@transparent_request.api_call(instruction)
end
credit_card_payment = MyMoip::CreditCardPayment.new(Fixture.credit_card, installments: 1)
@payment_request = MyMoip::PaymentRequest.new("your_own_id")
VCR.use_cassette('payment_request') do
@payment_request.api_call(credit_card_payment, token: @transparent_request.token)
end
payment_request = MyMoip::PaymentRequest.new("your_own_id")
assert_nil payment_request.url
end
end