saucy/app/lib/if_then_pay.rb

35 lines
1.0 KiB
Ruby
Raw Normal View History

2022-06-25 12:48:46 +00:00
require 'net/http'
module IfThenPay
def self.generate_gateway_link(id:, amount:, description:)
response = Net::HTTP.post(
URI("https://ifthenpay.com/api/gateway/paybylink/#{ENV['IFTHENPAY_KEY']}"),
JSON.generate({
id: id,
amount: amount.to_s,
description: description.to_s,
"lang": "pt",
"expiredate": "",
"accounts": ENV['IFTHENPAY_ACCOUNTS'],
})
)
JSON.parse(response.body)
end
2023-08-07 12:50:50 +00:00
def self.payments(date)
2024-03-21 14:52:59 +00:00
end_date = (Time.parse(date) + 1).strftime("%d-%m-%Y %H:%M:%S")
2024-02-01 09:16:02 +00:00
URI("https://ifthenpay.com/ifmbws/ifmbws.asmx/getPaymentsJson?chavebackoffice=#{ENV['IFTHENPAY_BO_KEY']}&entidade=&subentidade=&dtHrInicio=#{date}&dtHrFim=#{end_date}&referencia=&valor=&sandbox=0")
2023-08-07 12:50:50 +00:00
.then{|u| Net::HTTP.get(u)}
.then{|b| Nokogiri::XML(b).child.child.text}
.then{|x| JSON.parse(x)}
end
2024-03-21 14:52:59 +00:00
def self.multibanco_account
ENV['IFTHENPAY_ACCOUNTS']
.split(";")
.map { |acc| acc.split("|").first }
.find { |acc| acc.match?(/^\d+$/) }
end
2022-06-25 12:48:46 +00:00
end