Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

828 lines
30 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1994 **
  4. //*********************************************************************
  5. //
  6. // PAYMENT.CPP - Functions for
  7. //
  8. // HISTORY:
  9. //
  10. // 05/13/98 donaldm Created.
  11. // 08/19/98 donaldm BUGBUG: The code to collect and save the user
  12. // entered data is not optimal in terms of size
  13. // and can/should be cleaned up at some future time
  14. //
  15. //*********************************************************************
  16. #include "pre.h"
  17. // Dialog handles for the different payment methods, which will be nested into our mail dialog
  18. HWND hDlgCreditCard = NULL;
  19. HWND hDlgInvoice = NULL;
  20. HWND hDlgPhoneBill = NULL;
  21. HWND hDlgCustom = NULL;
  22. HWND hDlgCurrentPaymentType = NULL;
  23. BOOL g_bCustomPaymentActive = FALSE;
  24. WORD wCurrentPaymentType = PAYMENT_TYPE_INVALID; // NOTE: this must be initialize to a value
  25. HACCEL hAccelCreditCard = NULL;
  26. HACCEL hAccelInvoice = NULL;
  27. HACCEL hAccelPhoneBill = NULL;
  28. #define NUM_EXPIRE_YEARS 38
  29. #define BASE_YEAR 1998
  30. #define MAX_YEAR_LEN 5
  31. #define NUM_EXPIRE_MONTHS 12
  32. const TCHAR cszCustomPayment[] = TEXT("CUSTOMPAYMENT");
  33. INT_PTR CALLBACK CreditCardPaymentDlgProc
  34. (
  35. HWND hDlg,
  36. UINT uMsg,
  37. WPARAM wParam,
  38. LPARAM lParam
  39. )
  40. {
  41. // Create a local reference for the ISPData object
  42. IICWISPData *pISPData = gpWizardState->pISPData;
  43. // in order not to corrupt mem this guy must be big enough to hold
  44. // fmax_firstname + "" + max last name
  45. TCHAR szTemp[MAX_RES_LEN*2 + 4] = TEXT("\0");
  46. switch (uMsg)
  47. {
  48. case WM_CTLCOLORDLG:
  49. case WM_CTLCOLORSTATIC:
  50. if(gpWizardState->cmnStateData.bOEMCustom)
  51. {
  52. SetTextColor((HDC)wParam, gpWizardState->cmnStateData.clrText);
  53. SetBkMode((HDC)wParam, TRANSPARENT);
  54. return (INT_PTR) GetStockObject(NULL_BRUSH);
  55. }
  56. break;
  57. case WM_INITDIALOG:
  58. {
  59. int i;
  60. // Initialize the fields we know about
  61. SYSTEMTIME SystemTime; // system time structure
  62. GetLocalTime(&SystemTime);
  63. // Populate the Expires year listbox
  64. ComboBox_ResetContent(GetDlgItem(hDlg, IDC_PAYMENT_EXPIREYEAR));
  65. TCHAR szYear[MAX_YEAR_LEN];
  66. for (i = 0; i < NUM_EXPIRE_YEARS; i++)
  67. {
  68. wsprintf (szYear, TEXT("%4d"), i + BASE_YEAR);
  69. ComboBox_AddString(GetDlgItem(hDlg, IDC_PAYMENT_EXPIREYEAR), szYear);
  70. }
  71. // Select the first year in the list if unselected
  72. if (ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_PAYMENT_EXPIREYEAR)) == -1)
  73. {
  74. ComboBox_SetCurSel( GetDlgItem(hDlg, IDC_PAYMENT_EXPIREYEAR),
  75. SystemTime.wYear - BASE_YEAR);
  76. }
  77. // Populate the Expires Month listbox
  78. ComboBox_ResetContent(GetDlgItem(hDlg, IDC_PAYMENT_EXPIREMONTH));
  79. for (i = 0; i < NUM_EXPIRE_MONTHS; i++)
  80. {
  81. LoadString(ghInstanceResDll, IDS_JANUARY + i, szTemp, ARRAYSIZE(szTemp));
  82. ComboBox_AddString(GetDlgItem(hDlg, IDC_PAYMENT_EXPIREMONTH), szTemp);
  83. }
  84. // Select the first Month in the list if unselected
  85. if (ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_PAYMENT_EXPIREMONTH)) == -1)
  86. {
  87. ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_PAYMENT_EXPIREMONTH), SystemTime.wMonth - 1);
  88. }
  89. if (pISPData->GetDataElement(ISPDATA_USER_FE_NAME))
  90. {
  91. lstrcpy(szTemp, pISPData->GetDataElement(ISPDATA_USER_FE_NAME));
  92. SetDlgItemText(hDlg, IDC_PAYMENT_CCNAME, szTemp);
  93. }
  94. else
  95. {
  96. lstrcpy(szTemp, pISPData->GetDataElement(ISPDATA_USER_FIRSTNAME));
  97. lstrcat(szTemp, TEXT(" "));
  98. lstrcat(szTemp, pISPData->GetDataElement(ISPDATA_USER_LASTNAME));
  99. SetDlgItemText(hDlg, IDC_PAYMENT_CCNAME, szTemp);
  100. }
  101. lstrcpy(szTemp, pISPData->GetDataElement(ISPDATA_USER_ADDRESS));
  102. if (LCID_JPN != GetUserDefaultLCID())
  103. {
  104. lstrcat(szTemp, TEXT(" "));
  105. lstrcat(szTemp, pISPData->GetDataElement(ISPDATA_USER_MOREADDRESS));
  106. }
  107. SetDlgItemText(hDlg, IDC_PAYMENT_CCADDRESS, szTemp);
  108. SetDlgItemText(hDlg, IDC_PAYMENT_CCZIP, pISPData->GetDataElement(ISPDATA_USER_ZIP));
  109. break;
  110. }
  111. // User clicked next, so we need to collect and validate dat
  112. case WM_USER_NEXT:
  113. {
  114. CPAYCSV far *pcPAYCSV = (CPAYCSV far *)lParam;
  115. UINT uCtrlID;
  116. // If the ISP support LUHN, validate the content
  117. if (pcPAYCSV->get_bLUHNCheck())
  118. {
  119. uCtrlID = IDC_PAYMENT_CCNUMBER;
  120. GetDlgItemText(hDlg, uCtrlID, szTemp, ARRAYSIZE(szTemp));
  121. if (!pISPData->PutDataElement(ISPDATA_PAYMENT_CARDNUMBER, szTemp, ISPDATA_Validate_Content))
  122. goto CreditCardPaymentOKError;
  123. }
  124. else
  125. {
  126. // no content validate, so just do data present validation
  127. uCtrlID = IDC_PAYMENT_CCNUMBER;
  128. GetDlgItemText(hDlg, uCtrlID, szTemp, ARRAYSIZE(szTemp));
  129. if (!pISPData->PutDataElement(ISPDATA_PAYMENT_CARDNUMBER, szTemp, ISPDATA_Validate_DataPresent))
  130. goto CreditCardPaymentOKError;
  131. }
  132. uCtrlID = IDC_PAYMENT_CCNAME;
  133. GetDlgItemText(hDlg, uCtrlID, szTemp, ARRAYSIZE(szTemp));
  134. if (!pISPData->PutDataElement(ISPDATA_PAYMENT_CARDHOLDER, szTemp, ISPDATA_Validate_DataPresent))
  135. goto CreditCardPaymentOKError;
  136. uCtrlID = IDC_PAYMENT_CCADDRESS;
  137. GetDlgItemText(hDlg, IDC_PAYMENT_CCADDRESS, szTemp, ARRAYSIZE(szTemp));
  138. if (!pISPData->PutDataElement(ISPDATA_PAYMENT_BILLADDRESS, szTemp, ISPDATA_Validate_DataPresent))
  139. goto CreditCardPaymentOKError;
  140. uCtrlID = IDC_PAYMENT_CCZIP;
  141. GetDlgItemText(hDlg, IDC_PAYMENT_CCZIP, szTemp, ARRAYSIZE(szTemp));
  142. if (!pISPData->PutDataElement(ISPDATA_PAYMENT_BILLZIP, szTemp , ISPDATA_Validate_DataPresent))
  143. goto CreditCardPaymentOKError;
  144. // Month must be converted into numeric equivalent
  145. _itot(ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_PAYMENT_EXPIREMONTH)) + 1, szTemp, 10);
  146. pISPData->PutDataElement(ISPDATA_PAYMENT_EXMONTH, szTemp , ISPDATA_Validate_None);
  147. uCtrlID = IDC_PAYMENT_EXPIREYEAR;
  148. GetDlgItemText(hDlg, uCtrlID, szTemp, ARRAYSIZE(szTemp));
  149. if (!pISPData->PutDataElement(ISPDATA_PAYMENT_EXYEAR, szTemp , ISPDATA_Validate_Content))
  150. goto CreditCardPaymentOKError;
  151. // OK to move on
  152. SetPropSheetResult(hDlg,TRUE);
  153. return TRUE;
  154. CreditCardPaymentOKError:
  155. SetFocus(GetDlgItem(hDlg, uCtrlID));
  156. SetPropSheetResult(hDlg, FALSE);
  157. return TRUE;
  158. }
  159. }
  160. // Default return value if message is not handled
  161. return FALSE;
  162. }
  163. INT_PTR CALLBACK InvoicePaymentDlgProc
  164. (
  165. HWND hDlg,
  166. UINT uMsg,
  167. WPARAM wParam,
  168. LPARAM lParam
  169. )
  170. {
  171. // Create a local reference for the ISPData object
  172. IICWISPData *pISPData = gpWizardState->pISPData;
  173. TCHAR szTemp[MAX_RES_LEN] = TEXT("\0");
  174. switch (uMsg)
  175. {
  176. case WM_CTLCOLORDLG:
  177. case WM_CTLCOLORSTATIC:
  178. if(gpWizardState->cmnStateData.bOEMCustom)
  179. {
  180. SetTextColor((HDC)wParam, gpWizardState->cmnStateData.clrText);
  181. SetBkMode((HDC)wParam, TRANSPARENT);
  182. return (INT_PTR) GetStockObject(NULL_BRUSH);
  183. }
  184. break;
  185. case WM_INITDIALOG:
  186. {
  187. SetDlgItemText(hDlg, IDC_PAYMENT_IVADDRESS1, pISPData->GetDataElement(ISPDATA_USER_ADDRESS));
  188. SetDlgItemText(hDlg, IDC_PAYMENT_IVADDRESS2, pISPData->GetDataElement(ISPDATA_USER_MOREADDRESS));
  189. SetDlgItemText(hDlg, IDC_PAYMENT_IVCITY, pISPData->GetDataElement(ISPDATA_USER_CITY));
  190. SetDlgItemText(hDlg, IDC_PAYMENT_IVSTATE, pISPData->GetDataElement(ISPDATA_USER_STATE));
  191. SetDlgItemText(hDlg, IDC_PAYMENT_IVZIP, pISPData->GetDataElement(ISPDATA_USER_ZIP));
  192. break;
  193. }
  194. // User clicked next, so we need to collect entered data
  195. case WM_USER_NEXT:
  196. {
  197. UINT uCtrlID;
  198. uCtrlID = IDC_PAYMENT_IVADDRESS1;
  199. GetDlgItemText(hDlg, uCtrlID, szTemp, ARRAYSIZE(szTemp));
  200. if (!pISPData->PutDataElement(ISPDATA_PAYMENT_BILLADDRESS, szTemp, ISPDATA_Validate_DataPresent))
  201. goto InvoicePaymentOKError;
  202. uCtrlID = IDC_PAYMENT_IVADDRESS2;
  203. GetDlgItemText(hDlg, uCtrlID, szTemp, ARRAYSIZE(szTemp));
  204. if (!pISPData->PutDataElement(ISPDATA_PAYMENT_BILLEXADDRESS, szTemp, ISPDATA_Validate_DataPresent))
  205. goto InvoicePaymentOKError;
  206. uCtrlID = IDC_PAYMENT_IVCITY;
  207. GetDlgItemText(hDlg, uCtrlID, szTemp, ARRAYSIZE(szTemp));
  208. if (!pISPData->PutDataElement(ISPDATA_PAYMENT_BILLCITY, szTemp, ISPDATA_Validate_DataPresent))
  209. goto InvoicePaymentOKError;
  210. uCtrlID = IDC_PAYMENT_IVSTATE;
  211. GetDlgItemText(hDlg, uCtrlID, szTemp, ARRAYSIZE(szTemp));
  212. if (!pISPData->PutDataElement(ISPDATA_PAYMENT_BILLSTATE, szTemp, ISPDATA_Validate_DataPresent))
  213. goto InvoicePaymentOKError;
  214. uCtrlID = IDC_PAYMENT_IVZIP;
  215. GetDlgItemText(hDlg, uCtrlID, szTemp, ARRAYSIZE(szTemp));
  216. if (!pISPData->PutDataElement(ISPDATA_PAYMENT_BILLZIP, szTemp, ISPDATA_Validate_DataPresent))
  217. goto InvoicePaymentOKError;
  218. SetPropSheetResult(hDlg,TRUE);
  219. return TRUE;
  220. InvoicePaymentOKError:
  221. SetFocus(GetDlgItem(hDlg, uCtrlID));
  222. SetPropSheetResult(hDlg, FALSE);
  223. return TRUE;
  224. }
  225. }
  226. // Default return value if message is not handled
  227. return FALSE;
  228. }
  229. INT_PTR CALLBACK PhoneBillPaymentDlgProc
  230. (
  231. HWND hDlg,
  232. UINT uMsg,
  233. WPARAM wParam,
  234. LPARAM lParam
  235. )
  236. {
  237. // Create a local reference for the ISPData object
  238. IICWISPData *pISPData = gpWizardState->pISPData;
  239. TCHAR szTemp[MAX_RES_LEN] = TEXT("\0");
  240. switch (uMsg)
  241. {
  242. case WM_CTLCOLORDLG:
  243. case WM_CTLCOLORSTATIC:
  244. if(gpWizardState->cmnStateData.bOEMCustom)
  245. {
  246. SetTextColor((HDC)wParam, gpWizardState->cmnStateData.clrText);
  247. SetBkMode((HDC)wParam, TRANSPARENT);
  248. return (INT_PTR) GetStockObject(NULL_BRUSH);
  249. }
  250. break;
  251. case WM_INITDIALOG:
  252. {
  253. TCHAR szTemp[MAX_RES_LEN];
  254. lstrcpy(szTemp, pISPData->GetDataElement(ISPDATA_USER_FIRSTNAME));
  255. lstrcat(szTemp, TEXT(" "));
  256. lstrcat(szTemp, pISPData->GetDataElement(ISPDATA_USER_LASTNAME));
  257. SetDlgItemText(hDlg, IDC_PAYMENT_PHONEIV_BILLNAME, szTemp);
  258. SetDlgItemText(hDlg, IDC_PAYMENT_PHONEIV_ACCNUM, pISPData->GetDataElement(ISPDATA_USER_PHONE));
  259. break;
  260. }
  261. // User clicked next, so we need to collect and validate dat
  262. case WM_USER_NEXT:
  263. {
  264. UINT uCtrlID;
  265. uCtrlID = IDC_PAYMENT_PHONEIV_BILLNAME;
  266. GetDlgItemText(hDlg, uCtrlID, szTemp, ARRAYSIZE(szTemp));
  267. if (!pISPData->PutDataElement(ISPDATA_PAYMENT_BILLNAME, szTemp, ISPDATA_Validate_DataPresent))
  268. goto PhoneBillPaymentOKError;
  269. uCtrlID = IDC_PAYMENT_PHONEIV_ACCNUM;
  270. GetDlgItemText(hDlg, uCtrlID, szTemp, ARRAYSIZE(szTemp));
  271. if (!pISPData->PutDataElement(ISPDATA_PAYMENT_BILLPHONE, szTemp, ISPDATA_Validate_DataPresent))
  272. goto PhoneBillPaymentOKError;
  273. SetPropSheetResult(hDlg,TRUE);
  274. return TRUE;
  275. PhoneBillPaymentOKError:
  276. SetFocus(GetDlgItem(hDlg, uCtrlID));
  277. SetPropSheetResult(hDlg, FALSE);
  278. return TRUE;
  279. }
  280. }
  281. // Default return value if message is not handled
  282. return FALSE;
  283. }
  284. INT_PTR CALLBACK CustomPaymentDlgProc
  285. (
  286. HWND hDlg,
  287. UINT uMsg,
  288. WPARAM wParam,
  289. LPARAM lParam
  290. )
  291. {
  292. switch (uMsg)
  293. {
  294. // This is custom, because for the custom page, we must connect to the window
  295. // and browse everytime the custom pay page is activated, since an intervening
  296. // step may have connected the browser to a different window
  297. case WM_USER_CUSTOMINIT:
  298. {
  299. CPAYCSV far *pcPAYCSV = (CPAYCSV far *)lParam;
  300. gpWizardState->pICWWebView->ConnectToWindow(GetDlgItem(hDlg, IDC_PAYMENT_CUSTOM_INV), PAGETYPE_CUSTOMPAY);
  301. // Navigate to the Custom Payment HTML
  302. gpWizardState->lpSelectedISPInfo->DisplayHTML(pcPAYCSV->get_szCustomPayURLPath());
  303. // Load any persisted data
  304. gpWizardState->lpSelectedISPInfo->LoadHistory((BSTR)A2W(cszCustomPayment));
  305. return TRUE;
  306. }
  307. // User clicked next, so we need to collect and validate dat
  308. case WM_USER_NEXT:
  309. {
  310. TCHAR szQuery[INTERNET_MAX_URL_LENGTH];
  311. memset(szQuery, 0, sizeof(szQuery));
  312. // Attach the walker to the curent page
  313. // Use the Walker to get the query string
  314. IWebBrowser2 *lpWebBrowser;
  315. gpWizardState->pICWWebView->get_BrowserObject(&lpWebBrowser);
  316. gpWizardState->pHTMLWalker->AttachToDocument(lpWebBrowser);
  317. gpWizardState->pHTMLWalker->get_FirstFormQueryString(szQuery);
  318. gpWizardState->pISPData->PutDataElement(ISPDATA_PAYMENT_CUSTOMDATA, szQuery, ISPDATA_Validate_None);
  319. // detach the walker
  320. gpWizardState->pHTMLWalker->Detach();
  321. SetPropSheetResult(hDlg,TRUE);
  322. return TRUE;
  323. }
  324. }
  325. // Default return value if message is not handled
  326. return FALSE;
  327. }
  328. /*******************************************************************
  329. NAME: SwitchPaymentType
  330. ********************************************************************/
  331. void SwitchPaymentType
  332. (
  333. HWND hDlg,
  334. WORD wPaymentType
  335. )
  336. {
  337. TCHAR szTemp[MAX_RES_LEN];
  338. PAGEINFO *pPageInfo = (PAGEINFO *) GetWindowLongPtr(hDlg,DWLP_USER);
  339. // nothing to do if the payment type has not changed
  340. if (wPaymentType == wCurrentPaymentType)
  341. return;
  342. // set the current payment type
  343. wCurrentPaymentType = wPaymentType;
  344. // If the custom payment DLG is currently active, then we
  345. // need to persist any data the user may have entered.
  346. if (g_bCustomPaymentActive && IsWindowVisible(hDlgCurrentPaymentType))
  347. {
  348. gpWizardState->lpSelectedISPInfo->SaveHistory((BSTR)A2W(cszCustomPayment));
  349. }
  350. // Hide the current payment type window if there is one
  351. if (hDlgCurrentPaymentType)
  352. {
  353. ShowWindow(hDlgCurrentPaymentType, SW_HIDE);
  354. }
  355. //assume false for the weboc event handling
  356. g_bCustomPaymentActive = FALSE;
  357. gpWizardState->pISPData->PutDataElement(ISPDATA_PAYMENT_CUSTOMDATA, NULL, ISPDATA_Validate_None);
  358. // Create a new payment type DLG if necessary
  359. switch (wPaymentType)
  360. {
  361. case PAYMENT_TYPE_CREDITCARD:
  362. {
  363. if (NULL == hDlgCreditCard)
  364. {
  365. hDlgCreditCard = CreateDialog(ghInstanceResDll,
  366. MAKEINTRESOURCE(IDD_PAYMENTTYPE_CREDITCARD),
  367. hDlg,
  368. CreditCardPaymentDlgProc);
  369. // Also load the accelerator
  370. hAccelCreditCard = LoadAccelerators(ghInstanceResDll,
  371. MAKEINTRESOURCE(IDA_PAYMENTTYPE_CREDITCARD));
  372. }
  373. hDlgCurrentPaymentType = hDlgCreditCard;
  374. // Set the acclerator table to the nested dialog
  375. pPageInfo->hAccelNested = hAccelCreditCard;
  376. LoadString(ghInstanceResDll, IDS_PAYMENT_CREDITCARD, szTemp, ARRAYSIZE(szTemp));
  377. break;
  378. }
  379. case PAYMENT_TYPE_INVOICE:
  380. {
  381. if (NULL == hDlgInvoice)
  382. {
  383. hDlgInvoice = CreateDialog(ghInstanceResDll,
  384. MAKEINTRESOURCE(IDD_PAYMENTTYPE_INVOICE),
  385. hDlg,
  386. InvoicePaymentDlgProc);
  387. // Also load the accelerator
  388. hAccelInvoice = LoadAccelerators(ghInstanceResDll,
  389. MAKEINTRESOURCE(IDA_PAYMENTTYPE_INVOICE));
  390. }
  391. hDlgCurrentPaymentType = hDlgInvoice;
  392. // Set the acclerator table to the nested dialog
  393. pPageInfo->hAccelNested = hAccelInvoice;
  394. LoadString(ghInstanceResDll, IDS_PAYMENT_INVOICE, szTemp, ARRAYSIZE(szTemp));
  395. break;
  396. }
  397. case PAYMENT_TYPE_PHONEBILL:
  398. {
  399. if (NULL == hDlgPhoneBill)
  400. {
  401. hDlgPhoneBill = CreateDialog(ghInstanceResDll,
  402. MAKEINTRESOURCE(IDD_PAYMENTTYPE_PHONEBILL),
  403. hDlg,
  404. PhoneBillPaymentDlgProc);
  405. // Also load the accelerator
  406. hAccelPhoneBill = LoadAccelerators(ghInstanceResDll,
  407. MAKEINTRESOURCE(IDA_PAYMENTTYPE_PHONEBILL));
  408. }
  409. hDlgCurrentPaymentType = hDlgPhoneBill;
  410. // Set the acclerator table to the nested dialog
  411. pPageInfo->hAccelNested = hAccelPhoneBill;
  412. LoadString(ghInstanceResDll, IDS_PAYMENT_PHONE, szTemp, ARRAYSIZE(szTemp));
  413. break;
  414. }
  415. case PAYMENT_TYPE_CUSTOM:
  416. {
  417. g_bCustomPaymentActive = TRUE;
  418. if (NULL == hDlgCustom)
  419. {
  420. hDlgCustom = CreateDialog(ghInstanceResDll,
  421. MAKEINTRESOURCE(IDD_PAYMENTTYPE_CUSTOM),
  422. hDlg,
  423. CustomPaymentDlgProc);
  424. }
  425. hDlgCurrentPaymentType = hDlgCustom;
  426. // Set the acclerator table to the nested dialog. There is not one
  427. // in this case
  428. pPageInfo->hAccelNested = NULL;
  429. // We must force the custom payment type dialog to connect and browse
  430. CPAYCSV far *pcPAYCSV;
  431. HWND hWndPayment = GetDlgItem(hDlg, IDC_PAYMENTTYPE);
  432. // Get the currently selected item's PAYCSV obhect
  433. pcPAYCSV = (CPAYCSV *)ComboBox_GetItemData(hWndPayment, ComboBox_GetCurSel( hWndPayment ));
  434. ASSERT(pcPAYCSV);
  435. SendMessage(hDlgCustom, WM_USER_CUSTOMINIT, 0, (LPARAM)pcPAYCSV);
  436. LoadString(ghInstanceResDll, IDS_PAYMENT_CUSTOM, szTemp, ARRAYSIZE(szTemp));
  437. break;
  438. }
  439. }
  440. // Set the combo box string
  441. SetDlgItemText(hDlg, IDC_PAYMENT_GROUP, szTemp);
  442. // Show the new payment type window
  443. ShowWindowWithParentControl(hDlgCurrentPaymentType);
  444. }
  445. /*******************************************************************
  446. NAME: PaymentInitProc
  447. SYNOPSIS: Called when page is displayed
  448. ENTRY: hDlg - dialog window
  449. fFirstInit - TRUE if this is the first time the dialog
  450. is initialized, FALSE if this InitProc has been called
  451. before (e.g. went past this page and backed up)
  452. ********************************************************************/
  453. BOOL CALLBACK PaymentInitProc
  454. (
  455. HWND hDlg,
  456. BOOL fFirstInit,
  457. UINT *puNextPage
  458. )
  459. {
  460. BOOL bRet = TRUE;
  461. BOOL bLUHN = FALSE;
  462. HWND hWndPayment = GetDlgItem(hDlg, IDC_PAYMENTTYPE);
  463. CPAYCSV far *pcPAYCSV;
  464. // if we've travelled through external apprentice pages,
  465. // it's easy for our current page pointer to get munged,
  466. // so reset it here for sanity's sake.
  467. gpWizardState->uCurrentPage = ORD_PAGE_PAYMENT;
  468. ASSERT(gpWizardState->lpSelectedISPInfo);
  469. // invalidate the current payment type, so that we refresh everthing
  470. // in the event that we are reloading this page
  471. wCurrentPaymentType = PAYMENT_TYPE_INVALID;
  472. if (fFirstInit || !(gpWizardState->pStorage->Compare(ICW_PAYMENT,
  473. gpWizardState->lpSelectedISPInfo->get_szPayCSVPath(),
  474. MAX_PATH)))
  475. {
  476. CCSVFile far *pcCSVFile;
  477. HRESULT hr;
  478. int iIndex;
  479. // Read the payment .CSV file.
  480. pcCSVFile = new CCSVFile;
  481. if (!pcCSVFile)
  482. {
  483. MsgBox(hDlg, IDS_ERR_OUTOFMEMORY, MB_ICONEXCLAMATION,MB_OK);
  484. return (FALSE);
  485. }
  486. gpWizardState->pStorage->Set(ICW_PAYMENT, gpWizardState->lpSelectedISPInfo->get_szPayCSVPath(), MAX_PATH);
  487. if (!pcCSVFile->Open(gpWizardState->lpSelectedISPInfo->get_szPayCSVPath()))
  488. {
  489. AssertMsg(0, "Cannot open payment .CSV file");
  490. delete pcCSVFile;
  491. pcCSVFile = NULL;
  492. return (FALSE);
  493. }
  494. // Read the first line, since it contains field headers
  495. pcPAYCSV = new CPAYCSV;
  496. if (!pcPAYCSV)
  497. {
  498. // BUGBUG Show error message
  499. return (FALSE);
  500. }
  501. // Reading the first line also determines whether the csv file is contains
  502. // the LUHN format. If it does, we need to keep a record of bLUHN so that the
  503. // subsequent line can be read correctly.
  504. if (ERROR_SUCCESS != (hr = pcPAYCSV->ReadFirstLine(pcCSVFile, &bLUHN)))
  505. {
  506. // Handle the error case
  507. delete pcCSVFile;
  508. pcCSVFile = NULL;
  509. return (FALSE);
  510. }
  511. delete pcPAYCSV; // Don't need this one any more
  512. ComboBox_ResetContent(hWndPayment);
  513. // Read the Payment CSV file
  514. do {
  515. // Allocate a new Payment record
  516. pcPAYCSV = new CPAYCSV;
  517. if (!pcPAYCSV)
  518. {
  519. // BUGBUG Show error message
  520. bRet = FALSE;
  521. break;
  522. }
  523. // Read a line from the ISPINFO file
  524. hr = pcPAYCSV->ReadOneLine(pcCSVFile, bLUHN);
  525. if (hr == ERROR_NO_MORE_ITEMS)
  526. {
  527. delete pcPAYCSV; // We don't need this one
  528. break;
  529. }
  530. else if (hr == ERROR_FILE_NOT_FOUND)
  531. {
  532. // BUGBUG Show error message
  533. delete pcPAYCSV;
  534. pcPAYCSV = NULL;
  535. }
  536. else if (hr != ERROR_SUCCESS)
  537. {
  538. // BUGBUG Show error message
  539. delete pcPAYCSV;
  540. bRet = FALSE;
  541. break;
  542. }
  543. // Add the entry to the comboBox
  544. if (pcPAYCSV)
  545. {
  546. iIndex = ComboBox_AddString(hWndPayment, pcPAYCSV->get_szDisplayName());
  547. ComboBox_SetItemData(hWndPayment, iIndex, pcPAYCSV);
  548. }
  549. } while (TRUE);
  550. // Select the first payment type in the list
  551. ComboBox_SetCurSel(hWndPayment, 0);
  552. pcPAYCSV = (CPAYCSV *)ComboBox_GetItemData(hWndPayment, 0);
  553. ASSERT(pcPAYCSV);
  554. SwitchPaymentType(hDlg, pcPAYCSV->get_wPaymentType());
  555. pcCSVFile->Close();
  556. delete pcCSVFile;
  557. pcCSVFile = NULL;
  558. }
  559. else
  560. {
  561. // Get the currently selected item
  562. int iIndex = ComboBox_GetCurSel( hWndPayment );
  563. // Get the payment type, and update the payment area
  564. pcPAYCSV = (CPAYCSV *)ComboBox_GetItemData(hWndPayment, iIndex);
  565. ASSERT(pcPAYCSV);
  566. SwitchPaymentType(hDlg, pcPAYCSV->get_wPaymentType());
  567. // Setup the ISPData object so that is can apply proper validation based on the selected ISP
  568. // this is necessary here, because the user info page might have been skiped
  569. gpWizardState->pISPData->PutValidationFlags(gpWizardState->lpSelectedISPInfo->get_dwRequiredUserInputFlags());
  570. }
  571. if (!fFirstInit)
  572. {
  573. TCHAR szTemp[MAX_RES_LEN];
  574. if (LoadString(ghInstanceResDll,
  575. ((gpWizardState->lpSelectedISPInfo->get_dwCFGFlag() & ICW_CFGFLAG_SECURE) ? IDS_PAYMENT_SECURE : IDS_PAYMENT_UNSECURE),
  576. szTemp,
  577. MAX_RES_LEN))
  578. {
  579. SetWindowText (GetDlgItem(hDlg,IDC_PAYMENT_SECURE), szTemp);
  580. }
  581. }
  582. return bRet;
  583. }
  584. /*******************************************************************
  585. NAME: PaymentOKProc
  586. SYNOPSIS: Called when Next or Back btns pressed from page
  587. ENTRY: hDlg - dialog window
  588. fForward - TRUE if 'Next' was pressed, FALSE if 'Back'
  589. puNextPage - if 'Next' was pressed,
  590. proc can fill this in with next page to go to. This
  591. parameter is ingored if 'Back' was pressed.
  592. pfKeepHistory - page will not be kept in history if
  593. proc fills this in with FALSE.
  594. EXIT: returns TRUE to allow page to be turned, FALSE
  595. to keep the same page.
  596. ********************************************************************/
  597. BOOL CALLBACK PaymentOKProc
  598. (
  599. HWND hDlg,
  600. BOOL fForward,
  601. UINT *puNextPage,
  602. BOOL *pfKeepHistory
  603. )
  604. {
  605. // If the custom payment DLG has been shown, then we
  606. // need to persist any data the user may have entered.
  607. // We have shown the custom payment DLG, it hDlgCustom is not NULL
  608. if (NULL != hDlgCustom && IsWindowVisible(hDlgCustom))
  609. {
  610. gpWizardState->lpSelectedISPInfo->SaveHistory((BSTR)A2W(cszCustomPayment));
  611. }
  612. // NOTE that we are leaving the payment page, so the custom payment
  613. // WEBOC is no longer active
  614. g_bCustomPaymentActive = FALSE;
  615. if (fForward)
  616. {
  617. TCHAR szTemp[MAX_RES_LEN];
  618. HWND hWndPayment = GetDlgItem(hDlg, IDC_PAYMENTTYPE);
  619. CPAYCSV far *pcPAYCSV;
  620. int iIndex;
  621. // Create a local reference for the ISPData object
  622. IICWISPData *pISPData = gpWizardState->pISPData;
  623. // Get the payment type
  624. iIndex = ComboBox_GetCurSel(hWndPayment);
  625. pcPAYCSV = (CPAYCSV *)ComboBox_GetItemData(hWndPayment, iIndex);
  626. wsprintf (szTemp, TEXT("%d"), pcPAYCSV->get_wPaymentType());
  627. pISPData->PutDataElement(ISPDATA_PAYMENT_TYPE, szTemp, ISPDATA_Validate_None);
  628. // Set the display name
  629. pISPData->PutDataElement(ISPDATA_PAYMENT_DISPLAYNAME, pcPAYCSV->get_szDisplayName(), ISPDATA_Validate_None);
  630. switch(pcPAYCSV->get_wPaymentType())
  631. {
  632. case PAYMENT_TYPE_CREDITCARD:
  633. if (!SendMessage(hDlgCreditCard, WM_USER_NEXT, 0, (LPARAM)pcPAYCSV))
  634. return FALSE;
  635. break;
  636. case PAYMENT_TYPE_INVOICE:
  637. if (!SendMessage(hDlgInvoice, WM_USER_NEXT, 0, (LPARAM)pcPAYCSV))
  638. return FALSE;
  639. break;
  640. case PAYMENT_TYPE_PHONEBILL:
  641. if (!SendMessage(hDlgPhoneBill, WM_USER_NEXT, 0, (LPARAM)pcPAYCSV))
  642. return FALSE;
  643. break;
  644. case PAYMENT_TYPE_CUSTOM:
  645. if (!SendMessage(hDlgCustom, WM_USER_NEXT, 0, (LPARAM)pcPAYCSV))
  646. return FALSE;
  647. break;
  648. }
  649. }
  650. return TRUE;
  651. }
  652. /*******************************************************************
  653. NAME: PaymentCmdProc
  654. ********************************************************************/
  655. BOOL CALLBACK PaymentCmdProc
  656. (
  657. HWND hDlg,
  658. WPARAM wParam,
  659. LPARAM lParam
  660. )
  661. {
  662. WORD wNotifyCode = HIWORD (wParam);
  663. switch(LOWORD(wParam))
  664. {
  665. case IDC_PAYMENTTYPE:
  666. {
  667. if (wNotifyCode == CBN_SELENDOK || wNotifyCode == CBN_CLOSEUP)
  668. {
  669. // Get the currently selected item
  670. CPAYCSV far *pcPAYCSV;
  671. HWND hWndPayment = GetDlgItem(hDlg, IDC_PAYMENTTYPE);
  672. int iIndex = ComboBox_GetCurSel( hWndPayment );
  673. // Get the payment type, and update the payment are
  674. pcPAYCSV = (CPAYCSV *)ComboBox_GetItemData(hWndPayment, iIndex);
  675. ASSERT(pcPAYCSV);
  676. SwitchPaymentType(hDlg, pcPAYCSV->get_wPaymentType());
  677. }
  678. break;
  679. }
  680. default:
  681. break;
  682. }
  683. return 1;
  684. }