Creating Transactions

Examples on this page are for creating transactions using the server-to-server API. Transactions can also be created using Transparent Redirect. The server-to-server API is easier to understand, so even if you’re planning to use TR, you may want to read this page first.

Minimal Example

The only required attributes to create a transaction are the amount, credit card number, and credit card expiration date.

var request = new TransactionRequest
{
    Amount = 100.00M,
    CreditCard = new CreditCardRequest
    {
        Number = "5105105105105100",
        ExpirationDate = "05/2012",
    }
};

Result<Transaction> result = gateway.Transaction.Sale(request);

Note: Before you actually receive funds for authorization transactions, you have to submit them for settlement.

For other transaction details that can be provided, see the full example.

Result Handling

See the page on transaction result handling for information on how to check for validation errors and examine processor responses.

Full Example

Here is an example of passing in everything possible. Some parameters are mutually exclusive, so we’ll show those in separate examples. If you’re creating transactions using Transparent Redirect, all of these attributes can be included in the TR data, or you can create html input fields for them. If there is anything you want to store with the transaction details that we don’t have a field for, you can always use custom fields.

TransactionRequest request = new TransactionRequest
{
    Amount = 10.00M,
    OrderId = "order id",
    MerchantAccountId = "a_merchant_account_id",
    CreditCard = new CreditCardRequest
    {
        Number = "5105105105105100",
        ExpirationDate = "05/2012",
        CardholderName = "The Cardholder",
        CVV = "cvv"
    },
    Customer = new CustomerRequest
    {
        FirstName = "Drew",
        LastName = "Smith",
        Company = "Braintree",
        Phone = "312-555-1234",
        Fax = "312-555-1235",
        Website = "http://www.example.com",
        Email = "drew@example.com"
    },
    BillingAddress = new AddressRequest
    {
        FirstName = "Paul",
        LastName = "Smith",
        Company = "Braintree",
        StreetAddress = "1 E Main St",
        ExtendedAddress = "Suite 403",
        Locality = "Chicago",
        Region = "Illinois",
        PostalCode = "60622",
        CountryCodeAlpha2 = "US"
    },
    ShippingAddress = new AddressRequest
    {
        FirstName = "Jen",
        LastName = "Smith",
        Company = "Braintree",
        StreetAddress = "1 E 1st St",
        ExtendedAddress = "Suite 403",
        Locality = "Bartlett",
        Region = "Illinois",
        PostalCode = "60103",
        CountryCodeAlpha2 = "US"
    },
    Options = new TransactionOptionsRequest
    {
        SubmitForSettlement = true
    }
};

Result<Transaction> result = gateway.Transaction.Sale(request);

Expiration Date

Expiration month and year can be passed as separate fields rather than as a single field.

TransactionRequest request = new TransactionRequest
{
    Amount = 10.00M,
    CreditCard = new CreditCardRequest
    {
        Number = "5105105105105100",
        ExpirationMonth = "05",
        ExpirationYear = "2012"
    }
};

Result<Transaction> result = gateway.Transaction.Sale(request);

Country

You can provide country using any of the ISO 3166-1 country codes.

In version 2.5.0 you can specify the country using the name, alpha-2 code, alpha-3 code, or numeric code. In earlier verions, you can only use the country name.

TransactionRequest request = new TransactionRequest
{
    Amount = 10.00M,
    CreditCard = new CreditCardRequest
    {
        Number = "5105105105105100",
        ExpirationDate = "05/2012",
    },
    BillingAddress = new AddressRequest
    {
        CountryCodeAlpha2 = "US"
    }
};

Result<Transaction> result = gateway.Transaction.Sale(request);
TransactionRequest request = new TransactionRequest
{
    Amount = 10.00M,
    CreditCard = new CreditCardRequest
    {
        Number = "5105105105105100",
        ExpirationDate = "05/2012",
    },
    BillingAddress = new AddressRequest
    {
        CountryCodeAlpha3 = "USA"
    }
};

Result<Transaction> result = gateway.Transaction.Sale(request);
TransactionRequest request = new TransactionRequest
{
    Amount = 10.00M,
    CreditCard = new CreditCardRequest
    {
        Number = "5105105105105100",
        ExpirationDate = "05/2012",
    },
    BillingAddress = new AddressRequest
    {
        CountryCodeNumeric = "840"
    }
};

Result<Transaction> result = gateway.Transaction.Sale(request);
TransactionRequest request = new TransactionRequest
{
    Amount = 10.00M,
    CreditCard = new CreditCardRequest
    {
        Number = "5105105105105100",
        ExpirationDate = "05/2012",
    },
    BillingAddress = new AddressRequest
    {
        CountryName = "United States of America"
    }
};

Result<Transaction> result = gateway.Transaction.Sale(request);

Storing in Vault

When storing in the vault can you specify customer ID and credit card token.

TransactionRequest request = new TransactionRequest
{
    Amount = 10.00M,
    CreditCard = new CreditCardRequest
    {
        Token = "a_token",
        Number = "5105105105105100",
        ExpirationDate = "05/2012",
    },
    Customer = new CustomerRequest
    {
        Id = "a_customer_id"
    },
    BillingAddress = new AddressRequest
    {
        PostalCode = "60622",
    },
    ShippingAddress = new AddressRequest
    {
        StreetAddress = "1 E 1st St",
        Locality = "Bartlett",
        Region = "Illinois",
        PostalCode = "60103",
    },
    Options = new TransactionOptionsRequest
    {
        StoreInVault = true,
        AddBillingAddressToPaymentMethod = true,
        StoreShippingInVault = true
    }
};

Result<Transaction> result = gateway.Transaction.Sale(request);

Creating from Vault

When creating transactions from the vault you can provide the customer ID and/or payment method token instead of credit card details.

TransactionRequest request = new TransactionRequest
{
    Amount = 10.00M,
    CustomerId = "the_customer_id",
    PaymentMethodToken = "the_payment_method_token"
};

Result<Transaction> result = gateway.Transaction.Sale(request);

See Also

Options that are available when creating a transaction: