-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathNVPTest.cpp
288 lines (245 loc) · 7.57 KB
/
NVPTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
// NVPTest.cpp : Defines the entry po int for the console application.
//
#ifdef WIN32
#include "stdafx.h"
#else
#include "ctype.h"
#endif
#include "NVPCybersource.h"
#include "util.h"
//#include <thread>
#include <map>
#pragma comment(lib, "NVPClient.lib")
#pragma comment(lib, "BASECLIENT.lib")
const char CYBS_INI_FILE[] = "../cybs.ini";
void printContent(CybsMap *map);
std::wstring runAuth(CybsMap *cfgMap);
void runCapture( CybsMap* config, std::wstring authRequestID );
void handleFault(INVPTransactionProcessorProxy proxy);
void printMap (std::map <std::wstring, std::wstring> m);
void handleError( int status, CybsMap *store )
{
wprintf( L"RunTransaction Status: %d\n", status );
switch( status ) {
case CYBS_S_PRE_SEND_ERROR:
wprintf( L"The following error occurred before the request could be sent:\n" );
wprintf( L"%s\n", cybs_get(store, CYBS_SK_ERROR_INFO));
break;
case CYBS_S_SEND_ERROR:
wprintf( L"The following error occurred:\n" );
wprintf( L"%s\n", cybs_get(store, CYBS_SK_ERROR_INFO));
break;
default:
wprintf( L"The following error occurred:\n" );
wprintf( L"%s\n", cybs_get(store, CYBS_SK_ERROR_INFO));
break;
}
}
int main(void)
{
//Sleep(10000);
CybsMap *cfgMap = cybs_create_map();
//char *requestID;
std::wstring requestID;
cybs_load_config(CYBS_INI_FILE, cfgMap);
#ifdef WIN32
printf( "\nCONFIGURATION (%s): \n", CYBS_INI_FILE);
#else
wprintf( L"\nCONFIGURATION (%s): \n", CYBS_INI_FILE);
#endif
if ( !cfgMap ) {
printf( "Error: could not find the config file [%s]\n", CYBS_INI_FILE );
return(1);
}
printContent(cfgMap);
//int i = 0;
//while (i<2) {
requestID = runAuth(cfgMap);
//i++;
if ( !requestID.empty() ) {
runCapture( cfgMap, requestID );
//free( requestID );
}
//}
cybs_destroy_map(cfgMap);
return (0);
}
std::wstring runAuth(CybsMap *cfgMap) {
//const char *decision, *requestID;
std::wstring decision, requestID;
char *ret = NULL;
INVPTransactionProcessorProxy proxy = INVPTransactionProcessorProxy ();
soap_mode(proxy.soap, (soap_mode)SOAP_XML_CANONICAL);
soap_set_omode(proxy.soap, SOAP_C_UTFSTRING);
soap_set_imode(proxy.soap, SOAP_C_UTFSTRING);
soap_set_omode(proxy.soap, SOAP_C_MBSTRING);
soap_set_imode(proxy.soap, SOAP_C_MBSTRING);
std::map <std::wstring, std::wstring> request;
request[L"merchantReferenceCode"] = L"your_merchant_reference_code";
request[L"billTo_firstName"] = L"AJŠAß";
request[L"billTo_lastName"] = L"Doe";
request[L"billTo_street1"] = L"1295 Charleston Road";
request[L"billTo_city"] = L"Mountain View";
request[L"billTo_state"] = L"CA";
request[L"billTo_postalCode"] = L"94043";
request[L"billTo_country"] = L"US";
request[L"billTo_email"] = L"[email protected]";
request[L"billTo_ipAddress"] = L"10.7.7.7";
request[L"billTo_phoneNumber"] = L"650-965-6000";
request[L"shipTo_firstName"] = L"Jane";
request[L"shipTo_lastName"] = L"Jane";
request[L"shipTo_street1"] = L"123 toile délavée noir";
request[L"shipTo_state"] = L"CA";
request[L"shipTo_city"] = L"CA";
request[L"shipTo_postalCode"] = L"94401";
request[L"shipTo_country"] = L"US";
request[L"card_accountNumber"] = L"xxxxxxxxxxxxxxxx";
request[L"card_expirationMonth"] = L"12";
request[L"card_expirationYear"] = L"2021";
request[L"purchaseTotals_currency"] = L"USD";
request[L"item_0_unitPrice"] = L"12.34";
request[L"ccAuthService_run"] = L"true";
wprintf( L"CREDIT CARD AUTHORIZATION REQUEST: \n" );
printMap (request);
std::map <std::wstring, std::wstring> resMap;
int status = runTransaction(&proxy, cfgMap, request, resMap);
switch (status)
{
case SOAP_OK:
wprintf( L"\nCREDIT CARD AUTHORIZATION REPLY: \n" );
printMap(resMap);
decision = resMap.find(L"decision")->second;
if( wcscmp (decision.c_str(), L"ACCEPT") == 0 ) {
requestID = resMap.find(L"requestID")->second;
}
break;
case SOAP_FAULT:
handleFault(proxy);
break;
case CYBS_S_PRE_SEND_ERROR:
if (cybs_get(cfgMap, CYBS_SK_ERROR_INFO)) {
#ifdef WIN32
printf( "%s\n", cybs_get(cfgMap, CYBS_SK_ERROR_INFO));
#else
wprintf( L"%s\n", cybs_get(cfgMap, CYBS_SK_ERROR_INFO));
#endif
}
break;
default:
if (cybs_get(cfgMap, CYBS_SK_ERROR_INFO)) {
#ifdef WIN32
printf( "%s\n", cybs_get(cfgMap, CYBS_SK_ERROR_INFO));
#else
wprintf( L"%s\n", cybs_get(cfgMap, CYBS_SK_ERROR_INFO));
#endif
}
#ifdef WIN32
printf("\nfaultstring = %s\n", proxy.soap_fault_string());
#else
wprintf(L"\nfaultstring = %s\n", proxy.soap_fault_string());
#endif
}
proxy.destroy();
soap_delete(proxy.soap, NULL);
soap_dealloc(proxy.soap, NULL);
soap_destroy(proxy.soap);
soap_end(proxy.soap);
soap_done(proxy.soap);
return( requestID );
}
void runCapture( CybsMap* cfgMap, std::wstring authRequestID ) {
INVPTransactionProcessorProxy proxy = INVPTransactionProcessorProxy ();
soap_mode(proxy.soap, (soap_mode)SOAP_XML_CANONICAL);
std::map <std::wstring, std::wstring> requestMap;
std::map <std::wstring, std::wstring> resMap;
requestMap[L"ccCaptureService_run"] = L"true";
requestMap[L"merchantReferenceCode"] = L"your_merchant_reference_code";
requestMap[L"ccCaptureService_authRequestID"] = authRequestID;
requestMap[L"purchaseTotals_currency"] = L"USD";
requestMap[L"item_0_unitPrice"] = L"12.34";
wprintf( L"\nFOLLOW-ON CAPTURE REQUEST: \n" );
printMap(requestMap);
int status = runTransaction(&proxy, cfgMap, requestMap, resMap);
switch (status)
{
case SOAP_OK:
wprintf( L"\nFOLLOW-ON CAPTURE REPLY: \n" );
//printContent(responseMap);
printMap(resMap);
break;
case SOAP_FAULT:
handleFault(proxy);
break;
case CYBS_S_PRE_SEND_ERROR:
if (cybs_get(cfgMap, CYBS_SK_ERROR_INFO)) {
#ifdef WIN32
printf( "%s\n", cybs_get(cfgMap, CYBS_SK_ERROR_INFO));
#else
wprintf( L"%s\n", cybs_get(cfgMap, CYBS_SK_ERROR_INFO));
#endif
}
break;
default:
if (cybs_get(cfgMap, CYBS_SK_ERROR_INFO)) {
#ifdef WIN32
printf( "%s\n", cybs_get(cfgMap, CYBS_SK_ERROR_INFO));
#else
wprintf( L"%s\n", cybs_get(cfgMap, CYBS_SK_ERROR_INFO));
#endif
}
printf("faultstring = %s\n", proxy.soap_fault_string());
}
proxy.destroy();
soap_delete(proxy.soap, NULL);
soap_dealloc(proxy.soap, NULL);
soap_destroy(proxy.soap);
soap_end(proxy.soap);
soap_done(proxy.soap);
}
void handleFault(INVPTransactionProcessorProxy proxy)
{
#ifdef WIN32
printf("faultcode = %s\n", proxy.soap->fault->faultcode);
printf("faultstring = %s\n", proxy.soap_fault_string());
#else
wprintf(L"faultcode = %s\n", proxy.soap->fault->faultcode);
wprintf(L"faultstring = %s\n", proxy.soap_fault_string());
#endif
SOAP_ENV__Detail *detail = proxy.soap->fault->detail;
if (detail != NULL) {
#ifdef WIN32
printf("detail = %s\n", detail->__any);
#else
wprintf(L"detail = %s\n", detail->__any);
#endif
}
}
void printMap (std::map <std::wstring, std::wstring> m) {
typedef std::map <std::wstring, std::wstring>::const_iterator it_type;
for(it_type iterator = m.begin(); iterator != m.end(); iterator++) {
#ifdef WIN32
wprintf (L"%s", iterator->first.c_str());
wprintf (L"==>");
wprintf (L"%s",iterator->second.c_str());
wprintf (L"\n");
#else
wprintf (L"%S", iterator->first.c_str());
wprintf (L"==>");
wprintf (L"%S",iterator->second.c_str());
wprintf (L"\n");
#endif
}
}
void printContent(CybsMap *map) {
int i = 0;
while (i < map->length) {
CybsTable table = map->pairs[i];
#ifdef WIN32
printf(" %s ==> %s\n", table.key, table.value);
#else
wprintf(L" %s ==> %s\n", table.key, table.value);
#endif
i = i +1;
}
wprintf(L"\n");
}