|
The SCMP API clients are supported on 32-bit operating systems only. |
The following example shows the C code required to send a request for credit card authorization and to process the results. See Using the SDK for details on writing the code.
Example 1Example of Credit Card Authorization Request in C
#include <stdlib.h>
#include <string.h>
#include "ics.h"
main()
{
/* Allocate request and result space */
ics_msg *request;
ics_msg *result;
char *s = NULL;
int rcode;
/* Initialize the request, which holds all the information */
/* sent to CyberSource */
request = ics_init(0);
if (request == NULL) {
/* Initialization failed, do something appropriate */
}
/* Add your company's information to the request */
ics_fadd(request, "merchant_id", "infodev");
/* Add the services you want to the request */
ics_fadd(request, "ics_applications", "ics_auth");
ics_fadd(request, "server_host", "ics2testa.ic3.com");
/* Add the customer information to the request */
ics_fadd(request, "customer_firstname", "John");
ics_fadd(request, "customer_lastname", "Doe");
ics_fadd(request, "customer_email", "nobody@cybersource.com");
ics_fadd(request, "customer_phone", "6509656000");
/* set more fields as necessary */
/* (not all required fields shown here) */
/* Add the offer information to the request */
ics_fadd(request, "offer0", "amount:10.99^quantity:1");
/* send the request to CyberSource server */
result = ics_send(request);
/* Handle the reply codes and error messages. */
if (result == NULL) {
printf("ics error: got a NULL reply.\n");
}
s = ics_fgetbyname(result, "ics_rcode");
if (s == NULL) {
rcode = -1;
} else {
rcode = atoi(s);
}
if (rcode < 0) {
printf ("ics error: %s\n", ics_fgetbyname(result, "ics_rmsg"));
/* Error occurred */
/* Notify customer that error occurred; */
/* ask customer to try again. */
}
else if (rcode == 0) {
/* Request declined */
/* Evaluate rflag for reason why declined */
s = ics_fgetbyname(result, "ics_rflag");
if (strcmp(s, "DINVALIDDATA") == 0) {
/* Notify customer that request included invalid data. */
}
else if (strcmp(s, "DCARDREFUSED") == 0) {
/* Card declined by the bank; */
/* notify customer that unable to process order. */
}
else {
/* Handle remaining possible declined reply flags here. */
/* Write error handler to process */
/* new reply flags created by CyberSource. */
}
}
else {
/* Successful transaction; */
/* perform any local processing, and */
/* notify customer of success. */
}
ics_destroy (request);
ics_destroy (result);
}