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

CA_CERT = "D:\\_RCLSJOB\\_orcakey\\064158__JP_u00008979\\ca.crt"
CERT    = "D:\\_RCLSJOB\\_orcakey\\064158__JP_u00008979\\064158__JP_u00008979_client53513.crt"
CERTKEY = "D:\\_RCLSJOB\\_orcakey\\064158__JP_u00008979\\064158__JP_u00008979_client53513.pem"
KEYPASS = "8eut49nev1"
APIUSER = "u00008979"
#APIUSER = "ormaster"
APIKEY  = "4b21c3618eeea587d7f0dc8d4ad5f9dd0ed778ca5ca4e07ba7291ac671a257ab"


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">1234567</Karte_Uid>
		<Orca_Uid type="string"></Orca_Uid>
		<Perform_Date type="string">2024-04-30</Perform_Date>
		<Perform_Month type="string">2024-04</Perform_Month>
		<Ac_Date type="string">2024-04-30</Ac_Date>
		<Receipt_Mode type="string">02</Receipt_Mode>
		<InOut type="string">OI</InOut>
		<Create_Mode type="string"></Create_Mode>
		<Submission_Mode type="string">02</Submission_Mode>
		<Check_Mode type="string"></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
