PaymentGatewayLibrary

Overview

Making Payment

Here's an example on how to use the payment gateway component to make payment.

	using Duis.Payment;
	using Duis.Payment.AuthorizeNet;
	
	AuthorizeNetRequest req = new AuthorizeNetRequest(SubmissionType.Standard);
	req.Login = "..."; // your merchant login id.
	req.TransactionKey = "..."; // the gateway generated transaction key.
	req.Method = PaymentMethod.CC; //
	req.Type = TransactionType.AUTH_CAPTURE;
	req.Amount = 49.95m;
	req.CardNumber = "4007000000027";
	req.ExpiryDate = "12/05";
	req.FirstName = "Charles D.";
	req.LastName = "Gaulle";
	req.Company = "ShoppingCartInc";
	req.Address = "342 N. Main Street #150";
	req.City = "Ft. Worth";
	req.State = "TX";
	req.Zip = "12345";
	req.Country = "USA";
	req.Phone = "(555)123-1234";
	req.Email = "charles@shoppingcartinc.org";

	AuthorizeNetGateway gateway = new AuthorizeNetGateway(@"https://www.gateway-url.net/gateway/transact.dll"); // the gateway url

	AuthorizeNetResponse res;
	try {
		res = gateway.SubmitTransaction(req);

	} catch(Exception ex) {
		// handle error
	}

	if(res.ResponseCode == ResponseCode.Approved) {
		// the transaction was approved!
	}
	

Protecting Data

You can protect data such as passwords, the transaction key and other sensitive data by using hashing or encryption.

Protecting Data with Hash

A hash is a one way algoritm. It would be impossible for you to determine the original string from the hash. Typically, you would use hashing to store passwords. To validate the password, you hash the provided password and compare it with the stored hashed password.

Here's an example of how to hash a string.

	using Duis.Cryptography;

	Hash hash = new Hash(HashType.SHA1); // use the SHA1 algorithm
	string result = hash.CreateHash(@"originalStringToHash");
	...
			

Protecting Data with Encryption

Encryption on the other hand is a two way algorithm. In symmetrical encryption, you use a key and an initialization vector to encrypt and decrypt data.

Here's an example of how to use the symmetrical encryption to encrypt and decrypt a string.

	using Duis.Cryptography;
	
	// encrypt

	// when the encryption object is created, the key and iv are randomly generated for it. however, you can also use
	// your own key and initialization vector if you so choose.
	SymmetricEncryption enc = new SymmetricEncryption(SymmetricEncryptionType.Rijndael); // use the Rijndael algorithm
	string originalString = @"Original string";
	
	encryptedString = enc.Encrypt(originalString);
	
	key = enc.KeyString; // keep the key in a safe place
	iv = enc.IVString; // keep the initialization vector in a safe place
	
	...
	
	// decrypt
	SymmetricEncryption enc = new SymmetricEncryption(SymmetricEncryptionType.Rijndael); // use the Rijndael algorithm
	enc.KeyString = key;
	enc.IVString = iv;
	
	string decryptedString = enc.Decrypt(encryptedString);