Creating Customers

You can create a customer by itself, with a credit card, or with a credit card with a billing address.

This page describes creating customers using the server-to-server API. Customers 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.

Just a Customer

Here is an example of creating a customer without credit card information. If all customer validations pass, success will be true.

var request = new CustomerRequest
{
    FirstName = "Mark",
    LastName = "Jones",
    Company = "Jones Co.",
    Email = "mark.jones@example.com",
    Fax = "419-555-1234",
    Phone = "614-555-1234",
    Website = "http://example.com"
};
Result<Customer> result = gateway.Customer.Create(request);

bool success = result.IsSuccess();
// true

string customerId = result.Target.Id;
// e.g. 594019

Specify Your Own Customer ID

If you do not specify the customer ID, as in the example above, the gateway will generate one. You can also choose what you would like the ID to be.

var request = new CustomerRequest
{
    Id = "customer_123",
    FirstName = "Mark"
};

Result<Customer> result = gateway.Customer.Create(request);

Blank Customer

None of the parameters are required, so if you’re only interested in storing credit card details without any customer information, you can create a blank customer.

Result<Customer> result = gateway.Customer.Create(new CustomerRequest());

Customer with Credit Card

You can also create a credit card along with a customer. If all customer validations and credit card validations pass, and the card is verified (if requested), success will return true.

var request = new CustomerRequest
{
    FirstName = "Fred",
    LastName = "Jones",
    CreditCard = new CreditCardRequest
    {
        CardholderName = "Fred Jones",
        Number = "5105105105105100",
        ExpirationDate = "05/2012"
    }
};
Result<Customer> result = gateway.Customer.Create(request);

bool success = result.IsSuccess();
// true

Customer customer = result.Target;
string customerId = customer.Id;
// e.g. 160923

string cardToken = customer.CreditCards[0].Token;
// e.g. f28w

If you do not specify a token for the credit card, as in the example above, the gateway will generate one. You can also choose what you want the token to be.

var request = new CustomerRequest
{
    CreditCard = new CreditCardRequest
    {
        Token = "credit_card_123",
        Number = "5105105105105100",
        ExpirationDate = "05/2012"
    }
};

Result<Customer> result = gateway.Customer.Create(request);

By default, the credit card number is not verified to be a valid, open account. If you want to check for that, use the card verification API.

Customer with Credit Card with Billing Address

You can also create a credit card with billing address along with a customer.

var request = new CustomerRequest
{
    FirstName = "Fred",
    LastName = "Jones",
    CreditCard = new CreditCardRequest
    {
        Number = "5105105105105100",
        ExpirationDate = "05/2012",
        BillingAddress = new CreditCardAddressRequest
        {
            StreetAddress = "1 E Main St",
            ExtendedAddress = "Unit 2",
            Locality = "Chicago",
            Region = "Illinois",
            PostalCode = "60607",
            CountryCodeAlpha2 = "US"
        }
    }
};

Result<Customer> result = gateway.Customer.Create(request);

Customer customer = result.Target;
string streetAddress = customer.CreditCards[0].BillingAddress.StreetAddress;
// e.g. "1 E Main St"

See Also