Implement multibanco detection
This commit is contained in:
parent
c7a5f2a8e0
commit
931310657a
@ -16,12 +16,12 @@ class PaymentsController < ApplicationController
|
||||
if payment.nil?
|
||||
render status: 400, json: { error: "couldn't find payment" }
|
||||
else
|
||||
# TODO: handle double payments
|
||||
# TODO: handle double payments (impossible)
|
||||
contribution_params = {
|
||||
eurocents: payment["Valor"],
|
||||
payment_method: {
|
||||
"MB" => "multibanco",
|
||||
"MBWAY" => "mbway"
|
||||
IfThenPay.multibanco_account => "multibanco",
|
||||
"MBWAY" => "mbway",
|
||||
}.fetch(params["payment_method"]),
|
||||
payment_on: params["payment_datetime"],
|
||||
payment_reference: payment["Terminal"],
|
||||
|
@ -18,10 +18,17 @@ module IfThenPay
|
||||
end
|
||||
|
||||
def self.payments(date)
|
||||
end_date = (Time.parse(date) + 1).strftime("%Y-%m-%d %H:%M:%S")
|
||||
end_date = (Time.parse(date) + 1).strftime("%d-%m-%Y %H:%M:%S")
|
||||
URI("https://ifthenpay.com/ifmbws/ifmbws.asmx/getPaymentsJson?chavebackoffice=#{ENV['IFTHENPAY_BO_KEY']}&entidade=&subentidade=&dtHrInicio=#{date}&dtHrFim=#{end_date}&referencia=&valor=&sandbox=0")
|
||||
.then{|u| Net::HTTP.get(u)}
|
||||
.then{|b| Nokogiri::XML(b).child.child.text}
|
||||
.then{|x| JSON.parse(x)}
|
||||
end
|
||||
|
||||
def self.multibanco_account
|
||||
ENV['IFTHENPAY_ACCOUNTS']
|
||||
.split(";")
|
||||
.map { |acc| acc.split("|").first }
|
||||
.find { |acc| acc.match?(/^\d+$/) }
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user