Implement multibanco detection
This commit is contained in:
parent
c7a5f2a8e0
commit
931310657a
@ -16,12 +16,12 @@ class PaymentsController < ApplicationController
|
|||||||
if payment.nil?
|
if payment.nil?
|
||||||
render status: 400, json: { error: "couldn't find payment" }
|
render status: 400, json: { error: "couldn't find payment" }
|
||||||
else
|
else
|
||||||
# TODO: handle double payments
|
# TODO: handle double payments (impossible)
|
||||||
contribution_params = {
|
contribution_params = {
|
||||||
eurocents: payment["Valor"],
|
eurocents: payment["Valor"],
|
||||||
payment_method: {
|
payment_method: {
|
||||||
"MB" => "multibanco",
|
IfThenPay.multibanco_account => "multibanco",
|
||||||
"MBWAY" => "mbway"
|
"MBWAY" => "mbway",
|
||||||
}.fetch(params["payment_method"]),
|
}.fetch(params["payment_method"]),
|
||||||
payment_on: params["payment_datetime"],
|
payment_on: params["payment_datetime"],
|
||||||
payment_reference: payment["Terminal"],
|
payment_reference: payment["Terminal"],
|
||||||
|
@ -18,10 +18,17 @@ module IfThenPay
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.payments(date)
|
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")
|
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{|u| Net::HTTP.get(u)}
|
||||||
.then{|b| Nokogiri::XML(b).child.child.text}
|
.then{|b| Nokogiri::XML(b).child.child.text}
|
||||||
.then{|x| JSON.parse(x)}
|
.then{|x| JSON.parse(x)}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.multibanco_account
|
||||||
|
ENV['IFTHENPAY_ACCOUNTS']
|
||||||
|
.split(";")
|
||||||
|
.map { |acc| acc.split("|").first }
|
||||||
|
.find { |acc| acc.match?(/^\d+$/) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user