-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
342e477
commit 8c09772
Showing
10 changed files
with
913 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import java.math.BigInteger; | ||
import java.net.MalformedURLException; | ||
import java.rmi.RemoteException; | ||
import java.net.URL; | ||
import javax.xml.rpc.ServiceException; | ||
import org.apache.axis.AxisFault; | ||
import org.apache.ws.security.WSConstants; | ||
import org.apache.ws.security.handler.WSHandlerConstants; | ||
import com.cybersource.stub.*; | ||
|
||
public class Sample | ||
{ | ||
// Before using this example, replace the generic value with your merchant ID. | ||
private static final String MERCHANT_ID = "your_merchant_id"; | ||
private static final String LIB_VERSION = "1.4/1.5.1"; // Axis Version / WSS4J Version | ||
// Remember to also change the TRANSACTION_KEY in SamplePWCallback.java | ||
|
||
private static final String SERVER_URL = "https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor"; | ||
|
||
public static void main( String[] args ) | ||
{ | ||
RequestMessage request = new RequestMessage(); | ||
|
||
request.setMerchantID( MERCHANT_ID ); | ||
|
||
// Before using this example, replace the generic value with | ||
// your reference number for the current transaction. | ||
request.setMerchantReferenceCode( "your_merchant_reference_code" ); | ||
|
||
// To help us troubleshoot any problems that you may encounter, | ||
// please include the following information about your application. | ||
request.setClientLibrary( "Java Axis WSS4J" ); | ||
request.setClientLibraryVersion( LIB_VERSION ); | ||
request.setClientEnvironment( | ||
System.getProperty( "os.name" ) + "/" + | ||
System.getProperty( "os.version" ) + "/" + | ||
System.getProperty( "java.vendor" ) + "/" + | ||
System.getProperty( "java.version" ) ); | ||
|
||
// This section contains a sample transaction request for the authorization | ||
// service with complete billing, payment card, and purchase (two items) information. | ||
request.setCcAuthService( new CCAuthService() ); | ||
request.getCcAuthService().setRun( "true" ); | ||
|
||
BillTo billTo = new BillTo(); | ||
billTo.setFirstName( "John" ); | ||
billTo.setLastName( "Doe" ); | ||
billTo.setStreet1( "1295 Charleston Road" ); | ||
billTo.setCity( "Mountain View" ); | ||
billTo.setState( "CA" ); | ||
billTo.setPostalCode( "94043" ); | ||
billTo.setCountry( "US" ); | ||
billTo.setEmail( "[email protected]" ); | ||
billTo.setIpAddress( "10.7.111.111" ); | ||
request.setBillTo( billTo ); | ||
|
||
Card card = new Card(); | ||
card.setAccountNumber( "4111111111111111" ); | ||
card.setExpirationMonth( new BigInteger("12") ); | ||
card.setExpirationYear( new BigInteger("2020") ); | ||
request.setCard( card ); | ||
|
||
PurchaseTotals purchaseTotals = new PurchaseTotals(); | ||
purchaseTotals.setCurrency( "USD" ); | ||
request.setPurchaseTotals( purchaseTotals ); | ||
|
||
Item[] items = new Item[2]; | ||
|
||
Item item = new Item(); | ||
item.setId( new BigInteger( "0" ) ); | ||
item.setUnitPrice( "12.34" ); | ||
item.setQuantity( new BigInteger( "2" ) ); | ||
items[0] = item; | ||
|
||
item = new Item(); | ||
item.setId( new BigInteger( "1" ) ); | ||
item.setUnitPrice( "56.78" ); | ||
items[1] = item; | ||
|
||
request.setItem( items ); | ||
|
||
try { | ||
TransactionProcessorLocator service | ||
= new TransactionProcessorLocator(); | ||
|
||
URL endpoint = new URL( SERVER_URL ); | ||
|
||
ITransactionProcessorStub stub | ||
= (ITransactionProcessorStub) service.getportXML( endpoint ); | ||
|
||
stub._setProperty( WSHandlerConstants.USER, request.getMerchantID() ); | ||
|
||
ReplyMessage reply = stub.runTransaction( request ); | ||
|
||
// To retrieve individual reply fields, follow these examples. | ||
System.out.println("decision = " + reply.getDecision()); | ||
System.out.println("reasonCode = " + reply.getReasonCode()); | ||
System.out.println("requestID = " + reply.getRequestID()); | ||
System.out.println("requestToken = " + reply.getRequestToken()); | ||
System.out.println("ccAuthReply.reasonCode = " + reply.getCcAuthReply().getReasonCode()); | ||
|
||
} catch(AxisFault e) { | ||
System.out.println( "AxisFault: " + e ); | ||
} catch (MalformedURLException e) { | ||
System.out.println( "MalformedURLException: " + e ); | ||
} catch (RemoteException e) { | ||
System.out.println( "RemoteException: " + e ); | ||
} catch (ServiceException e) { | ||
System.out.println( "ServiceException: " + e ); | ||
} | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> | ||
<transport name="http" pivot="java:org.apache.axis.transport.http.HTTPSender"/> | ||
<globalConfiguration > | ||
<requestFlow > | ||
<handler type="java:org.apache.ws.axis.security.WSDoAllSender" > | ||
<parameter name="action" value="UsernameToken"/> | ||
<parameter name="passwordType" value="PasswordText"/> | ||
<parameter name="passwordCallbackClass" value="SamplePWCallback"/> | ||
</handler> | ||
</requestFlow > | ||
</globalConfiguration > | ||
</deployment> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import java.io.IOException; | ||
import javax.security.auth.callback.Callback; | ||
import javax.security.auth.callback.CallbackHandler; | ||
import javax.security.auth.callback.UnsupportedCallbackException; | ||
import org.apache.ws.security.WSPasswordCallback; | ||
|
||
/** | ||
* Sample password callback for the client | ||
*/ | ||
public class SamplePWCallback implements CallbackHandler { | ||
|
||
// Before using this sample, change the generic value with your reference number for the current transaction. | ||
private static final String TRANSACTION_KEY = "your_transaction_key"; | ||
|
||
/** | ||
* @see javax.security.auth.callback.CallbackHandler#handle(javax.security.auth.callback.Callback[]) | ||
*/ | ||
public void handle(Callback[] callbacks) | ||
throws IOException, UnsupportedCallbackException | ||
{ | ||
for (int i = 0; i < callbacks.length; i++) { | ||
if (callbacks[i] instanceof WSPasswordCallback) { | ||
WSPasswordCallback pc = (WSPasswordCallback)callbacks[i]; | ||
|
||
// This sample returns one password for all merchants. | ||
// To support multiple passwords, return the password | ||
// corresponding to pc.getIdentifier(). | ||
pc.setPassword( TRANSACTION_KEY ); | ||
} else { | ||
throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback"); | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
GSOAP=../gsoap/bin/soapcpp2 | ||
GWSDL=../gsoap/bin/wsdl2h | ||
SOAPH=../gsoap/stdsoap2.h | ||
SOAPCPP=../gsoap/stdsoap2.cpp | ||
CC=gcc | ||
CPP=g++ | ||
LIBS=-lcrypto -lssl | ||
COFLAGS=-O2 | ||
CWFLAGS=-Wall | ||
CIFLAGS=-I. -I../gsoap -I../gsoap/plugin | ||
CMFLAGS=-DWITH_DOM -DWITH_OPENSSL | ||
CFLAGS= $(CWFLAGS) $(COFLAGS) $(CIFLAGS) $(CMFLAGS) | ||
cybsdemo: sample.cpp $(SOAPH) $(SOAPCPP) ../gsoap/dom.cpp wsseapi.o smdevp.o | ||
$(CPP) $(CFLAGS) -o cybsdemo sample.cpp soapC.cpp soapClient.cpp ../gsoap/dom.cpp $(SOAPCPP) wsseapi.o smdevp.o $(LIBS) | ||
header: CyberSourceTransaction.wsdl | ||
$(GWSDL) -t ../gsoap/WS/WS-typemap.dat -s -o cybersource.h CyberSourceTransaction.wsdl | ||
source: | ||
$(GSOAP) -C -I../gsoap/import cybersource.h | ||
wsseapi.o: ../gsoap/plugin/wsseapi.h ../gsoap/plugin/wsseapi.c | ||
$(CPP) $(CFLAGS) -c ../gsoap/plugin/wsseapi.c | ||
smdevp.o: ../gsoap/plugin/smdevp.h ../gsoap/plugin/smdevp.c | ||
$(CPP) $(CFLAGS) -c ../gsoap/plugin/smdevp.c | ||
clean: | ||
rm -f *.o soapH.h soapStub.h soapC.cpp soapClient.cpp soap*Proxy.h soap*Object.h soapClientLib.cpp | ||
distclean: | ||
rm -f *.o *.xml *.nsmap *.log soapH.h soapStub.h soapC.cpp soapClient.cpp soapClientLib.cpp soap*Proxy.h soap*Object.h cybsdemo cybersource.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
#include "soapITransactionProcessorProxy.h" | ||
#include "ITransactionProcessor.nsmap" | ||
#ifdef WIN32 | ||
#include "gsoapWinInet.h" | ||
#endif | ||
#include "wsseapi.h" | ||
|
||
#ifndef WIN32 | ||
#include <signal.h> | ||
void sigpipe_handle(int x) {} | ||
#endif | ||
|
||
// Before using this example, replace the generic values with your merchant ID and password. | ||
const char *MERCHANT_ID = "your_merchant_id"; | ||
const char *TRANSACTION_KEY = "your_transaction_key"; | ||
const char *SERVER_URL = "https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor"; | ||
const char *LIB_VERSION = "2.7.9d"; // gSOAP version | ||
const char *ENVIRONMENT = "your_platform_info_e.g._Linux 2.6"; | ||
#ifndef WIN32 | ||
const char *CACERTS_FILE = "../gsoap/samples/ssl/cacerts.pem"; | ||
#endif | ||
|
||
|
||
void handleFault(struct soap *soap) | ||
{ | ||
// This section dumps information to stdout. | ||
soap_print_fault( soap, stdout ); | ||
SOAP_ENV__Fault *fault = soap->fault; | ||
printf("faultcode = %s\n", fault->faultcode); | ||
printf("faultstring = %s\n", fault->faultstring); | ||
SOAP_ENV__Detail *detail = fault->detail; | ||
if (detail != NULL) { | ||
printf("detail = %s\n", detail->__any); | ||
} | ||
} | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
|
||
#ifndef WIN32 | ||
// one-time initializations | ||
signal(SIGPIPE, sigpipe_handle); | ||
soap_ssl_init(); | ||
#endif | ||
|
||
ITransactionProcessor service; | ||
service.endpoint = SERVER_URL; | ||
|
||
#ifdef WIN32 | ||
soap_register_plugin( service.soap, wininet_plugin ); | ||
#else | ||
if (soap_ssl_client_context( | ||
service.soap, SOAP_SSL_DEFAULT, NULL, NULL, CACERTS_FILE, NULL, NULL )) | ||
{ | ||
handleFault(service.soap); | ||
exit(1); | ||
} | ||
#endif | ||
|
||
ns3__RequestMessage request; | ||
|
||
request.merchantID = (char *) MERCHANT_ID; | ||
|
||
// Before using this example, replace the generic values with your | ||
// reference number for the current transaction. | ||
request.merchantReferenceCode = "your_merchant_reference_code"; | ||
|
||
// To help us troubleshoot any problems that you may encounter, | ||
// please include the following information about your application. | ||
request.clientLibrary = "gSOAP"; | ||
request.clientLibraryVersion = (char *) LIB_VERSION; | ||
request.clientEnvironment = (char *) ENVIRONMENT; | ||
|
||
|
||
// This section contains a sample transaction request for the authorization service | ||
// with complete billing, payment card, and purchase (two items) information. | ||
ns3__CCAuthService ccAuthService; | ||
ccAuthService.run = "true"; | ||
request.ccAuthService = &ccAuthService; | ||
|
||
ns3__BillTo billTo; | ||
billTo.firstName = "John"; | ||
billTo.lastName = "Doe"; | ||
billTo.street1 = "1295 Charleston Road"; | ||
billTo.city = "Mountain View"; | ||
billTo.state = "CA"; | ||
billTo.postalCode = "94043"; | ||
billTo.country = "US"; | ||
billTo.email = "[email protected]"; | ||
billTo.ipAddress = "10.7.111.111"; | ||
request.billTo = &billTo; | ||
|
||
ns3__Card card; | ||
card.accountNumber = "4111111111111111"; | ||
int expmo = 12; | ||
int expyr = 2020; | ||
card.expirationMonth = &expmo; | ||
card.expirationYear = &expyr; | ||
request.card = &card; | ||
|
||
ns3__PurchaseTotals purchaseTotals; | ||
purchaseTotals.currency = "USD"; | ||
request.purchaseTotals = &purchaseTotals; | ||
|
||
ns3__Item item0; | ||
int id0 = 0; | ||
item0.id = &id0; | ||
item0.unitPrice = "12.34"; | ||
int quantity = 2; | ||
item0.quantity = &quantity; | ||
|
||
ns3__Item item1; | ||
int id1 = 1; | ||
item1.id = &id1; | ||
item1.unitPrice = "12.34"; | ||
|
||
// Note that request.item expects an array of ns3__Item pointers, | ||
// which is different from an array of contiguous ns3__Item's. | ||
// Also, this sample uses a static array. In your code, you are more likely | ||
// to need a dynamic heap-allocated array as the number of line items may vary. | ||
// In any case, you must set request.__sizeitem to the size of the array. | ||
|
||
ns3__Item *items[2] = { &item0, &item1 }; | ||
request.__sizeitem = 2; | ||
request.item = items; | ||
|
||
ns3__ReplyMessage reply; | ||
|
||
soap_wsse_add_UsernameTokenText( | ||
service.soap, NULL, request.merchantID, TRANSACTION_KEY ); | ||
|
||
int ret = service.__ns1__runTransaction( &request, &reply ); | ||
switch (ret) | ||
{ | ||
case SOAP_OK: | ||
// display selected reply fields | ||
printf("decision = %s\n", reply.decision); | ||
printf("reasonCode = %d\n", reply.reasonCode); | ||
printf("requestID = %s\n", reply.requestID); | ||
printf("requestToken = %s\n", reply.requestToken); | ||
printf("ccAuthReply.reasonCode = %d\n", | ||
reply.ccAuthReply->reasonCode); | ||
break; | ||
|
||
case SOAP_FAULT: | ||
handleFault(service.soap); | ||
break; | ||
|
||
default: | ||
// soap_print_fault works even with non-fault error codes. | ||
soap_print_fault(service.soap, stdout); | ||
printf( "Error code: %d\nPlease consult the gSOAP documentation.\n", ret ); | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.