00001
00002
00003
00004 #include "tclink.h"
00005
00006 #include <stdio.h>
00007 #include <stdlib.h>
00008 #include <string.h>
00009 #include <ctype.h>
00010
00011
00012
00013
00014 #define CUSTID "XXXX"
00015 #define PASSWORD "PPPP"
00016
00017
00018
00019
00020
00021 enum { VISA = 0, MC, DISC, AMEX, ACH, BID, NUM_CARDS };
00022
00023
00024
00025 struct { char *cc, *exp; } cards[NUM_CARDS] =
00026 { { "4111111111111111", "0404" },
00027 { "5411111111111115", "0404" },
00028 { "6011111111111117", "0404" },
00029 { "341111111111111", "0404" },
00030 { "123456789", "55554444333222" },
00031 { NULL, NULL }
00032 };
00033
00034 int main(int argc, char *argv[])
00035 {
00036 TCLinkHandle handle;
00037 int arg = 1, card = -1, demo = 0, verify = 0, wallet = 0;
00038 char *action, *amount = 0, *transid = 0, *bid = 0;
00039 char buf[256], buf2[256];
00040 char *ptr;
00041
00042 printf("TCTest (using TCLink version %s)\n", TCLinkGetVersion(buf));
00043
00044 if (argc < 2) {
00045 printf("usage: %s <action> [<<card> | <transid>> <amount>] [bug] [demo] [verify] [wallet]\n",argv[0]);
00046 printf(" action = sale | preauth | postauth | credit | store | unstore | walletsale\n");
00047 printf(" card = visa | mc | disc | amex | bid | ach\n");
00048 printf(" transid = (14 character transid)\n");
00049 printf(" amount = dollar amount in cents\n");
00050 printf(" demo = (transaction is demo only)\n");
00051 return 4;
00052 }
00053
00054 action = argv[arg++];
00055 if (!strcasecmp(action, "unstore"))
00056 bid = argv[arg++];
00057 else if (arg < argc)
00058 {
00059 if (isdigit(argv[arg][0])) transid = argv[arg++];
00060 else if (!strcasecmp(argv[arg], "visa")) card = VISA;
00061 else if (!strcasecmp(argv[arg], "mc")) card = MC;
00062 else if (!strcasecmp(argv[arg], "disc")) card = DISC;
00063 else if (!strcasecmp(argv[arg], "amex")) card = AMEX;
00064 else if (!strcasecmp(argv[arg], "bid")) card = BID;
00065 else if (!strcasecmp(argv[arg], "ach")) card = ACH;
00066 if (card >= 0)
00067 arg++;
00068 }
00069
00070 if (card == BID && arg < argc)
00071 bid = argv[arg++];
00072
00073 if (arg < argc && isdigit(argv[arg][0]))
00074 amount = argv[arg++];
00075
00076 while (arg < argc)
00077 {
00078 if (!strcmp(argv[arg], "demo"))
00079 demo = 1;
00080 else if (!strcmp(argv[arg], "verify"))
00081 verify = 1;
00082 else if (!strcmp(argv[arg], "wallet"))
00083 wallet = 1;
00084 arg++;
00085 }
00086
00087 handle = TCLinkCreate();
00088
00089 TCLinkPushParam(handle, "custid", CUSTID);
00090 TCLinkPushParam(handle, "password", PASSWORD);
00091 TCLinkPushParam(handle, "action", action);
00092 if (amount)
00093 TCLinkPushParam(handle, "amount", amount);
00094 if (demo)
00095 TCLinkPushParam(handle, "demo", "y");
00096 if (verify)
00097 TCLinkPushParam(handle, "verify", "y");
00098 if (wallet)
00099 TCLinkPushParam(handle, "wallet", "y");
00100
00101 if (!strcmp(action, "sale") || !strcmp(action, "walletsale") ||
00102 !strcmp(action, "preauth") || !strcmp(action, "store"))
00103 {
00104 if (card == BID) {
00105 TCLinkPushParam(handle, "billingid", bid);
00106 }
00107 else {
00108 TCLinkPushParam(handle, "address1", "123 Test St.");
00109 TCLinkPushParam(handle, "zip", "90001");
00110 TCLinkPushParam(handle, "name", "Joe Test");
00111
00112 if (card == ACH) {
00113 TCLinkPushParam(handle, "media", "ach");
00114 TCLinkPushParam(handle, "routing", cards[card].cc);
00115 TCLinkPushParam(handle, "account", cards[card].exp);
00116 TCLinkPushParam(handle, "checknum", "1001");
00117 }
00118 else {
00119 TCLinkPushParam(handle, "media", "cc");
00120 TCLinkPushParam(handle, "cc", cards[card].cc);
00121 TCLinkPushParam(handle, "exp", cards[card].exp);
00122 }
00123 }
00124
00125 if (!strcmp(action, "sale") || !strcmp(action, "preauth"))
00126 TCLinkPushParam(handle, "avs", "n");
00127 }
00128 else if (!strcmp(action, "credit"))
00129 {
00130 TCLinkPushParam(handle, "transid", transid);
00131 }
00132 else if (!strcmp(action, "postauth"))
00133 {
00134 TCLinkPushParam(handle, "transid", transid);
00135 }
00136 else if (!strcmp(action, "unstore"))
00137 {
00138 TCLinkPushParam(handle, "billingid", bid);
00139 }
00140
00141 TCLinkSend(handle);
00142
00143 ptr = TCLinkGetResponse(handle, "status", buf);
00144 if (ptr)
00145 {
00146 if (TCLinkGetResponse(handle, "transid", buf2))
00147 printf("transid is: %s\n", buf2);
00148 printf("status is: %s\n", ptr);
00149 if (!strcmp(ptr, "accepted") || !strcmp(ptr, "approved"))
00150 return 0;
00151 if (!strcmp(ptr, "decline") || !strcmp(ptr, "rejected")) {
00152 printf("declinetype is: %s\n", TCLinkGetResponse(handle, "declinetype", buf));
00153 return 1;
00154 }
00155 if (!strcmp(ptr, "error")) {
00156 printf("errortype is: %s\n", TCLinkGetResponse(handle, "errortype", buf));
00157 return 2;
00158 }
00159 if (!strcmp(ptr, "baddata")) {
00160 printf("offenders are: %s\n", TCLinkGetResponse(handle, "offenders", buf));
00161 return 3;
00162 }
00163 }
00164
00165 return 3;
00166 }
00167