#!/usr/bin/ruby
# coding:utf-8
require 'uri'
require 'net/https'

CA_CERT = "root.crt"
CERT    = "004633__JP_u00000624_client2870.crt"
CERTKEY = "004633__JP_u00000624_client2870.pem"
KEYPASS = "zoUKB7+Fp3"
APIUSER = "ormaster"
APIKEY  = "dea21f1b3236bdfcc65bbc166362c5241269dce7599c69c7dc378484ae56e66a"


Net::HTTP.version_1_2
# 本番環境
#https = Net::HTTP.new("weborca.cloud.orcamo.jp","443")
# デモ環境
https = Net::HTTP.new("demo-weborca.cloud.orcamo.jp","443")
https.use_ssl = true
https.ca_file = CA_CERT
https.cert = OpenSSL::X509::Certificate.new(File.read(CERT))
https.key = OpenSSL::PKey::RSA.new(File.read(CERTKEY),KEYPASS)
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
https.verify_depth = 5

https.start do
  req = Net::HTTP::Post.new("/api/orca44/receiptdatamakev3")
  req.body = <<-EOF
<data>
        <receiptdata_makev3req type="record">
                <Request_Number type="string">01</Request_Number>
                <Karte_Uid type="string">94e16fd4-4664-49cf-9be0-0af44ac25d4a</Karte_Uid>
                <Orca_Uid type="string"></Orca_Uid>
                <Perform_Date type="string">2024-07-11</Perform_Date>
                <Perform_Month type="string">2024-07</Perform_Month>
                <Ac_Date type="string">2024-07-11</Ac_Date>
                <Receipt_Mode type="string">02</Receipt_Mode>
                <InOut type="string">O</InOut>
                <Create_Mode type="string">Check</Create_Mode>
                <Submission_Mode type="string">02</Submission_Mode>
                <Check_Mode type="string">Yes</Check_Mode>
        </receiptdata_makev3req>
</data>
  EOF

  req.content_type = "application/xml"
  req.content_length = req.body.size
  req.basic_auth(APIUSER,APIKEY)

  res = https.request(req)

  unless res.code == "200"
   raise "http error:#{res.code}"
  end

  puts res.body
end
