HEX
Server: Microsoft-IIS/10.0
System: Windows NT ITPWINWEBSVR22 10.0 build 20348 (Windows Server 2022) AMD64
User: www.conferencesearch.co.uk (0)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: D:/web/secure/itpplates/from bam/jsonrequest.asp
<%Option Explicit%>
<!--#include file="jsonObject.class.asp" -->
<!--#include file="dbfunctions.asp"-->
<!--#include file="commonutils.asp"-->
<%

Dim oJSONRequest

DoTest

Sub DoTest
  Dim ApiKey, url, str
  ApiKey = "n4bw55hdbVIuMYzFUR1ylZBxojnirI5j"
   'key = "testing123"

  url = "https://secure.itpartnership.com/bam4/jsonapi.asp"
  'str = "{ TotalAmount: 1, CurrencyCode: 1, TransactionId: 36985223, Business: { ApiKey: '" & key & "',Description: '' }, CreditTypes: [ {CreditTypeCode: 1, MaxNumberOfPayments: 1}] }"

  'str = "{ ""ApiKey"": """ & key & """, ""TotalAmount"": 1, ""CurrencyCode"": 1, ""TransactionId"": 36985223, ""Business"": {""ApiKey"": """ & key & """, ""Description"": """"}, ""CreditTypes"": [{""CreditTypeCode"": 1, ""MaxNumberOfPayments"": 1}]}"



  Set oJSONRequest = New JSONobject

  oJSONRequest.Add "apikey", ApiKey
  'oJSONRequest.Add "command", "GetHotelList"
  'oJSONRequest.Add "command", "GetRoomTypes"
  'oJSONRequest.Add "command", "GetArrivalDates"
  'oJSONRequest.Add "command", "GetNumberOfNights"
  'oJSONRequest.Add "command", "GetAllLookups"
  
  'oJSONRequest.Add "command", "CancelBooking"
  'oJSONRequest.Add "BookingNo", 3
  

  'oJSONRequest.Add "command", "GetTestData"
  
  oJSONRequest.Add "command", "GetAvailability"
  
  'oJSONRequest.Add "command", "GetHotelGuestList"
  'oJSONRequest.Add "HotelID", 1
  
  'oJSONRequest.Add "command", "GetBooking"
  'oJSONRequest.Add "BookingNo", 3

  
  'oJSONRequest.Add "command", "CreateBooking"
  Dim LAddBookingData
  LAddBookingData = False
  
  If LAddBookingData Then
    oJSONRequest.Add "Title", "Mr"
    oJSONRequest.Add "FirstName", "Test"
    oJSONRequest.Add "Surname", "Singh"
    oJSONRequest.Add "MembershipNo", "ABC123"
    oJSONRequest.Add "Telephone", "017891234567"
    oJSONRequest.Add "Mobile", "077771234567"
    oJSONRequest.Add "Email", "test@test.com"
    oJSONRequest.Add "HotelID", 1
    API_GetTestData
  End If

  str = oJSONRequest.Serialize

  Set oJSONRequest = Nothing  

  Dim oXMLHttp
  Set oXMLHttp=Server.Createobject("MSXML2.ServerXMLHTTP.6.0")
  oXMLHttp.open "POST", url, false
  oXMLHttp.setRequestHeader "Content-Type", "application/json"
  oXMLHttp.send str
  response.write oXMLHttp.responseText
  Set oXMLHttp = Nothing
End Sub
  
  
Sub API_GetTestData
  ' API_LoadRecordsetFromSQL False, "bookingrooms", "SELECT * FROM bookingrooms WHERE BookingNo = 6"
  API_LoadRecordsetFromSQL False, "bookingrooms", "SELECT Title, FirstName, Surname, ArrivalDate, NoOfNights, RoomTypeID, SharingWith, SpecialRequirements FROM bookingrooms WHERE BookingNo = 6"
End Sub

' loads the recordset from SQL into JSON response
Sub API_LoadRecordsetFromSQL(AMultiple, AName, ASQL)
  If AMultiple And AName <> "" Then
    'oJSONResponse.defaultPropertyName = AName
    
    ' following used to prevent error "A property already exists with the name: [[JSONroot]]."
    ' due to limitation of aspJSON
    ' see https://github.com/rcdmk/aspJSON/issues/36 for workaround
    
    Dim LJSON2
    Set LJSON2 = New JSONobject
    
  End If

  Dim oRS
  ' oConn is a global held in dbfunctions.asp and refers to the database which should already be opened by Initialise in commonutils.asp 
  ' nRecs is also another global in dbfunctions.asp  
  Set oRS = oConn.Execute(ASQL, nRecs, adCmdText)
    
  If AMultiple And AName <> "" Then
    LJSON2.LoadRecordset oRS
    oJSONRequest.Add AName, LJSON2.Parse(LJSON2.Serialize())
    Set LJSON2 = Nothing
  Else
    oJSONRequest.LoadRecordset oRS
  End If
  
  Set oRS = Nothing
End Sub

%>