-
Notifications
You must be signed in to change notification settings - Fork 21
add PaymentRequest#total_payed and PaymentRequest#status #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
c4cbc9f
c4971be
fccd19c
fe8d76c
8c42e5c
2876db9
5d34a62
0c79c5d
5545861
a4bad6b
80e6503
0341af6
34ea2d9
cced22f
cca4657
997bd83
cbf0bda
054b6a1
9639fa7
db1f187
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,3 +13,5 @@ pkg | |
|
|
||
| # Bundler | ||
| Gemfile.lock | ||
|
|
||
| .ruby-version | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| source 'https://rubygems.org' | ||
|
|
||
| # Specify your gem's dependencies in new_gem.gemspec | ||
| gemspec | ||
| gemspec |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| module MyMoip | ||
| class JsResponse | ||
| PARAMS_MAPPER = { | ||
| 'Codigo' => 'code', | ||
| 'CodigoMoIP' => 'moip_code', | ||
| 'Mensagem' => 'message', | ||
| 'StatusPagamento' => 'payment_status', | ||
| 'Status' => 'status', | ||
| 'TaxaMoIP' => 'moip_tax_value', | ||
| 'TotalPago' => 'total_paid_value', | ||
| 'CodigoRetorno' => 'return_code', | ||
| 'url' => 'url', | ||
| 'Classificacao' => { | ||
| 'classification' => { 'Codigo' => 'code', 'Descricao' => 'description' } | ||
| } | ||
| } | ||
|
|
||
| include MyMoip::ParamsMapper | ||
|
|
||
| def success? | ||
| payment_status.eql?('Sucesso') | ||
| end | ||
|
|
||
| def failed? | ||
| payment_status.eql?('Falha') | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| module MyMoip | ||
| class Nasp | ||
| PARAMS_MAPPER = { | ||
| 'id_transacao' => 'transaction_id', | ||
| 'valor' => 'paid_value', | ||
| 'status_pagamento' => 'status', | ||
| 'cod_moip' => 'moip_code', | ||
| 'forma_pagamento' => 'payment_method_code', # 1 | ||
| 'tipo_pagamento' => 'payment_method', # BoletoBancario | ||
| 'parcelas' => 'installments', | ||
| 'email_consumidor' => 'payer_mail', | ||
| 'recebedor_login' => 'seller_mail', | ||
| 'cartao_bin' => 'card_first_numbers', | ||
| 'cartao_final' => 'card_last_numbers', | ||
| 'cartao_bandeira' => 'credit_card_logo', | ||
| 'cofre' => 'moip_lock_number', | ||
| 'classificacao' => 'classification' | ||
| } | ||
|
|
||
| include MyMoip::ParamsMapper | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| module MyMoip | ||
| module ParamsMapper | ||
| def initialize(params) | ||
| self.class::PARAMS_MAPPER.values.each_with_index do |attribute, index| | ||
| value = params[self.class::PARAMS_MAPPER.key(attribute)] | ||
|
|
||
| if attribute.is_a?(Hash) | ||
| define_multiple_attributes(attribute, value); next | ||
| end | ||
|
|
||
| define_singleton_method attribute do value end | ||
| end | ||
| end | ||
|
|
||
| def define_multiple_attributes(hash, value) | ||
| method_name = hash.keys.first | ||
| mapped_methods = hash[method_name] | ||
|
|
||
| if value | ||
| value = OpenStruct.new(Hash[ value.map { |k, v| [mapped_methods[k], v] } ]) | ||
| end | ||
|
|
||
| define_singleton_method method_name do value end | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,14 +36,10 @@ def to_xml(root = nil) | |
| root.DataVencimento(expiration_date.strftime('%Y-%m-%dT%H:%M:%S.%L%:z')) unless expiration_date.blank? | ||
|
|
||
| if expiration_days | ||
| type = nil | ||
| if expiration_days_type | ||
| if expiration_days_type == :business_day | ||
| type = {'Tipo' => 'Uteis'} | ||
| elsif expiration_days_type == :calendar_day | ||
| type = {'Tipo' => 'Corridos'} | ||
| end | ||
| end | ||
| type = { | ||
| business_day: {'Tipo' => 'Uteis'}, | ||
| calendar_day: {'Tipo' => 'Corridos'} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Space inside { missing. |
||
| }[expiration_days_type] | ||
|
|
||
| root.DiasExpiracao(expiration_days, type) | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| require 'active_support/core_ext/hash' | ||
|
|
||
| module MyMoip | ||
| class ConsultationRequest < Request | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra empty line detected at body beginning. |
||
| HTTP_METHOD = :get | ||
| PATH = '/ws/alpha/ConsultarInstrucao' | ||
| REQUIRES_AUTH = true | ||
|
|
||
| def api_call(opts = {}) | ||
| params = { | ||
| http_method: HTTP_METHOD, | ||
| requires_auth: REQUIRES_AUTH, | ||
| path: [PATH, id].join('/') | ||
| } | ||
|
|
||
| super(params, opts) | ||
| end | ||
|
|
||
| def response_hash | ||
| Hash.from_xml(@response.body) | ||
| end | ||
|
|
||
| def transactions | ||
| @transactions ||= get_transaction_params.map do |transaction_params| | ||
| MyMoip::Transaction.new(transaction_params) | ||
| end | ||
| end | ||
|
|
||
| def transaction(moip_code) | ||
| transaction_params = get_transaction_params.select { | ||
| |i| i.key(format_moip_code(moip_code)) | ||
| }.first | ||
| MyMoip::Transaction.new(transaction_params) | ||
| end | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra empty line detected at body end. |
||
| private | ||
|
|
||
| def format_moip_code(moip_code) | ||
| moip_code.to_s.rjust(12, '0').scan(/\d{4}/).join('.') | ||
| end | ||
|
|
||
| def get_transaction_params | ||
| payments = response_hash['ConsultarTokenResponse']\ | ||
| ['RespostaConsultar']\ | ||
| ['Autorizacao']\ | ||
| ['Pagamento'] | ||
|
|
||
| payments.is_a?(Hash) ? [payments] : payments | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
|
|
@@ -45,7 +55,19 @@ def url | |
|
|
||
| def code | ||
| @response["CodigoMoIP"] | ||
| rescue NoMethodError => e | ||
| rescue NoMethodError | ||
| nil | ||
| end | ||
|
|
||
| def status | ||
| STATUSES[@response["Status"]] | ||
| rescue NoMethodError | ||
| nil | ||
| end | ||
|
|
||
| def total_payed | ||
| @response["TotalPago"] | ||
| rescue NoMethodError | ||
| nil | ||
| end | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra empty line detected at body end. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| module MyMoip | ||
| class Transaction | ||
| PARAMS_MAPPER = { | ||
| 'Data' => 'date', # 2012-04-02T10:45:44.000-03:00 | ||
| 'DataCredito' => 'credit_date', # 2012-04-16T00:00:00.000-03:00 | ||
| 'TotalPago' => 'total_paid_value', # 1.00 | ||
| 'TaxaParaPagador' => 'payer_tax_value', # 0.00 | ||
| 'TaxaMoIP' => 'moip_tax_value', # 0.46 | ||
| 'ValorLiquido' => 'equity_value', # 0.54 | ||
| 'FormaPagamento' => 'payment_method', # CartaoDeCredito | ||
| 'InstituicaoPagamento' => 'payment_method_institution', # AmericanExpress | ||
| 'Status' => 'status', # Autorizado | ||
| 'CodigoMoIP' => 'moip_code', # 0000.2524.0547 | ||
| 'Parcela' => { | ||
| 'installment' => { 'TotalParcelas' => 'number' } | ||
| } | ||
| } | ||
|
|
||
| include MyMoip::ParamsMapper | ||
| end | ||
| end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space inside { missing.
Space inside } missing.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.