// idpapi.h: Saferpay C-API header file

#ifndef __IDPAPP_H__
#define __IDPAPP_H__

#ifdef WIN32
#define IDPEXPORT __declspec(dllexport)
#else
#define IDPEXPORT
#endif

typedef long HRESULT;

typedef void * IDP_HANDLE;

#define IDP_CHECKSUM 0xAFFEAFFEL

#define IDP_ASSERT_VALID(p, T) {\
	if(!p) return IDP_E_INVALID_HANDLE;\
	if(((T*)p)->m_CheckSum != IDP_CHECKSUM) return IDP_E_INVALID_HANDLE; }

#ifdef __cplusplus
extern "C" {
#endif

// factory functions
IDPEXPORT IDP_HANDLE CreateConfigurationSetup();
IDPEXPORT void DestroyConfigurationSetup(IDP_HANDLE hConfigurationSetup);

IDPEXPORT IDP_HANDLE CreateMessageFactory();
IDPEXPORT void DestroyMessageFactory(IDP_HANDLE hMessageFactory);

IDPEXPORT IDP_HANDLE CreateMessageObject();
IDPEXPORT void DestroyMessageObject(IDP_HANDLE hMessageObject);



// class ConfigurationSetup
IDPEXPORT HRESULT ConfigurationSetup_SetConfiguration(IDP_HANDLE hConfigurationSetup,
							 const char *pszPath);

IDPEXPORT HRESULT ConfigurationSetup_Reconfigure(IDP_HANDLE hConfigurationSetup,
												const char *pszServerURL,
												const char *pszUserName,
												const char *pszPassword);

IDPEXPORT HRESULT ConfigurationSetup_SetOption(IDP_HANDLE hConfigurationSetup,
											   const char *pszName,
											   const char *pszValue);

IDPEXPORT HRESULT ConfigurationSetup_GetAttribute(IDP_HANDLE hConfigurationSetup,
												  const char *pszFile,
												  const char *pszName,long *pcbSize,
												  char *pValue);

IDPEXPORT HRESULT ConfigurationSetup_SetAttribute(IDP_HANDLE hConfigurationSetup,
												  const char *pszFile,
												  const char *pszName,
												  const char *pszNewVal);


// class MessageFactory
IDPEXPORT HRESULT MessageFactory_VerifyPayConfirm(IDP_HANDLE hMessageFactory,
												  const char *pszData,
												  const char *pszSignature,
												  IDP_HANDLE *phMessageObject);

IDPEXPORT HRESULT MessageFactory_Open(IDP_HANDLE hMessageFactory, const char *pszPath);

IDPEXPORT HRESULT MessageFactory_CreateRequest(IDP_HANDLE hMessageFactory,
												   const char *pszMsgType,
												   IDP_HANDLE *phMessageObject);

IDPEXPORT HRESULT MessageFactory_CreatePayInit(IDP_HANDLE hMessageFactory,
											   IDP_HANDLE *phMessageObject);

IDPEXPORT HRESULT MessageFactory_CreatePayComplete(IDP_HANDLE hMessageFactory,
												   const char *pszId,
												   const char *pszToken,
												   IDP_HANDLE *phMessageObject);


// class MessageObject
IDPEXPORT HRESULT MessageObject_GetURL(IDP_HANDLE hMessageObject,
									   long *pcbSize,
									   char *pURL);

IDPEXPORT HRESULT MessageObject_SetAttribute(IDP_HANDLE hMessageObject,
											 const char *pszName,
											 const char *pszValue);

IDPEXPORT HRESULT MessageObject_GetAttribute(IDP_HANDLE hMessageObject,
											 const char *pszName,
											 long *pcbSize,
											 char *pValue);

IDPEXPORT HRESULT MessageObject_Capture(IDP_HANDLE hMessageObject);

IDPEXPORT HRESULT MessageObject_Execute(IDP_HANDLE hMessageObject,
										IDP_HANDLE *phResponse);

IDPEXPORT HRESULT MessageObject_Open(IDP_HANDLE hMessageObject,
									 const char *pszPath);

IDPEXPORT HRESULT MessageObject_FromString(IDP_HANDLE hMessageObject, const char * Message);

IDPEXPORT HRESULT MessageObject_ToString(IDP_HANDLE hMessageObject, long *pcbSize,
										 char *pValue);

// Error lookup
IDPEXPORT long IDP_GetErrorStringFromResult(long hr, long *pcbSize, char *pTxt);


#ifdef __cplusplus
}
#endif

#endif // defined(__IDPAPP_H__)
