Customer Service - PaySimple/PaySimpleSDK GitHub Wiki

Home | Account Service | Customer Service | Payment Service | Payment Schedule Service | PagedResult | Exceptions

Customer Service

The Customer Service is used to create, get, update and delete Customer records. The Customer Service also provides methods to get Accounts, Payments and Schedules associated with a specific Customer. The SDK provides the following methods:

  • CreateCustomerAsync
  • DeleteCustomerAsync
  • GetAchAccountsAsync
  • GetAllAccountsAsync
  • GetCreditCardAccountsAsync
  • GetCustomerAsync
  • GetCustomersAsync
  • GetDefaultAchAccountAsync
  • GetDefaultCreditCardAccountAsync
  • GetPaymentPlansAsync
  • GetPaymentsAsync
  • GetPaymentSchedulesAsync
  • GetRecurringPaymentSchedulesAsync
  • MatchOrCreateCustomerAndCreditCardAccountAsync
  • MatchOrCreateCustomerAndAchAccountAsync
  • SetDefaultAccountAsync
  • UpdateCustomerAsync

Constructor

Parameters:

Parameter Name Type Description Notes
settings IPaySimpleSdkSettings SDK Settings

Example:

var settings = new PaySimpleSettings("AoOtRylA63570WmH3eqChyFRqwhTnA2g0dnsV7zzQko4s4yKWdBorA1WiT7dK2H2xz06P562Hqv0heYBdfNamfQyxX50drtpL8s7", "AUserName");
var customerService = new CustomerService(settings);

Service Methods


CreateCustomerAsync

CreateCustomerAsync creates a new Customer

Parameters:

Parameter Name Type Description Notes
customer Customer Customer to create

Returns:

Customer

Example:

var customer = new Customer
{
	FirstName = "Mal",
	LastName = "Reynolds"
};

var customer = await customerService.CreateCustomerAsync(customer);

DeleteCustomerAsync

DeleteCustomerAsync deletes an existing Customer

Parameters:

Parameter Name Type Description Notes
customerId int Id of the Customer to delete

Example:

await customerService.DeleteCustomerAsync(123456);

GetAchAccountsAsync

GetAchAccountsAsync gets all Ach accounts associated with a Customer

Parameters:

Parameter Name Type Description Notes
customerId int CustomerId of the customer to get the accounts for

Returns:

IEnumerable<Ach>

Example:

var achAccounts = await customerService.GetAchAccountsAsync(123456);

GetAllAccountsAsync

GetAllAccountsAsync get all Ach & Credit Card accounts associated with a Customer

Parameters:

Parameter Name Type Description Notes
customerId int CustomerId of the customer to get the accounts for

Returns:

AccountList

Example:

var accounts = await customerService.GetAllAccountsAsync(123456);

GetCreditCardAccountsAsync

GetCreditCardAccountsAsync gets all Credit Card accounts associated with a Customer

Parameters:

Parameter Name Type Description Notes
customerId int CustomerId of the customer to get the accounts for

Returns:

IEnumerable<CreditCard>

Example:

var creditCardAccounts = await customerService.GetCreditCardAccountsAsync(123456);

GetCustomerAsync

GetCustomerAsync gets a specifc Customer

Parameters:

Parameter Name Type Description Notes
customerId int CustomerId of the customer to get

Returns:

Customer

Example:

var customer = await customerService.GetCustomerAsync(123456);

GetCustomersAsync

GetCustomersAsync gets a list of Customers

Parameters:

Parameter Name Type Description Notes
sortBy CustomerSort The field to sort the results by Default: CustomerSort.LastName
direction SortDirection The direction to sort the results by Default: SortDirection.ASC
page int The page to get Default: 1
pageSize int The page size Default: 200
lite bool Get a lite version of the returned object Default: false

Returns:

PagedResult<IEnumerable<Customer>>

Example:

// Get the first page of customers sorted by FirstName, in Descending order
var customers = await customerService.GetCustomersAsync(CustomerSort.FirstName, SortDirection.DESC, 1);

// Get the third page of customers sorted by BillingAddressCity, in Ascending order, with lite Customer object
var customers = await customerService.GetCustomersAsync(CustomerSort.BillingAddressCity, page: 3, lite: true);

GetDefaultAchAccountAsync

GetDefaultAchAccountAsync gets the default Ach Account associated with a Customer

Parameters:

Parameter Name Type Description Notes
customerId int CustomerId of the customer

Returns:

Ach

Example:

var achAccount = await customerService.GetDefaultAchAccountAsync(123456);

GetDefaultCreditCardAccountAsync

GetDefaultCreditCardAccountAsync gets the default CreditCard Account associated with a Customer

Parameters:

Parameter Name Type Description Notes
customerId int CustomerId of the customer

Returns:

CreditCard

Example:

var creditcardAccount = await customerService.GetDefaultCreditCardAccountAsync(123456);

GetPaymentPlansAsync

GetPaymentPlansAsync gets Customer Payment Plans

Parameters:

Parameter Name Type Description Notes
customerId int CustomerId of the customer
startDate DateTime? Start date of the payment plan Default: null
endDate DateTime? End date of the payment plan Default: null
status ScheduleStatus Status of the payment plan Default: ScheduleStatus.None
sortBy ScheduleSort Field to sort the resulting list by Default: ScheduleSort.Id
direction SortDirection The direction to sort the results by Default: SortDirection.ASC
page int The page to get Default: 1
pageSize int The page size Default: 200
lite bool Get a lite version of the returned object Default: false

Returns:

PagedResult<IEnumerable<PaymentPlan>>

Example:

// Get all payment plans for customer id 123456 sorted by Id, ascending
var paymentPlans = await customerService.GetPaymentPlansAsync(123456);

// Get all active payment plans for customer id 123456 sorted by next payment date descending
var paymentPlans = await customerService.GetPaymentPlansAsync(123456, status: ScheduleStatus.Active, sortBy: ScheduleSort.NextPaymentDate, direction: SortDirection.DESC);

GetPaymentsAsync

GetPaymentsAsync gets Customer Payments

Parameters:

Parameter Name Type Description Notes
customerId int CustomerId of the customer
startDate DateTime? Start date of the payment plan Default: null
endDate DateTime? End date of the payment plan Default: null
status IEnumerable Stati of the payment plan Default: null
sortBy PaymentSort Field to sort the resulting list by Default: PaymentSort.Id
direction SortDirection The direction to sort the results by Default: SortDirection.ASC
page int The page to get Default: 1
pageSize int The page size Default: 200
lite bool Get a lite version of the returned object Default: false

Returns:

PagedResult<IEnumerable<Payment>>

Example:

// Get all payments for customer id 123456 sorted by payment Id, ascending
var payments = await customerService.GetPaymentsAsync(123456);

// Get all payments between 3 days ago and today with a payment status of Authorized, Voided or Returned, sorted by Amount
var status = new List<PaymentStatus>
{
	PaymentStatus.Authorized,
	PaymentStatus.Voided,
	PaymentStatus.Returned
};
var payments = await customerService.GetPaymentsAsync(123456, DateTime.Now.AddDays(-3), DateTime.Now, status, PaymentSort.Amount);

GetPaymentSchedulesAsync

GetPaymentSchedulesAsync gets Customer Payment Schedules (PaymentPlans and RecurringPayments)

Parameters:

Parameter Name Type Description Notes
customerId int CustomerId of the customer
startDate DateTime? Start date of the payment plan Default: null
endDate DateTime? End date of the payment plan Default: null
status ScheduleStatus Status of the payment plan Default: ScheduleStatus.None
sortBy ScheduleSort Field to sort the resulting list by Default: ScheduleSort.Id
direction SortDirection The direction to sort the results by Default: SortDirection.ASC
page int The page to get Default: 1
pageSize int The page size Default: 200
lite bool Get a lite version of the returned object Default: false

Returns:

PagedResult<IEnumerable<PaymentScheduleList>>

Example:

// Get all payment schedules for customer id 123456 sorted by Id, ascending
var paymentSchedules = await customerService.GetPaymentSchedulesAsync(123456);

GetRecurringPaymentSchedulesAsync

GetRecurringPaymentSchedulesAsync gets Customer Recurring Payment Schedules

Parameters:

Parameter Name Type Description Notes
customerId int CustomerId of the customer
startDate DateTime? Start date of the payment plan Default: null
endDate DateTime? End date of the payment plan Default: null
status ScheduleStatus Status of the payment plan Default: ScheduleStatus.None
sortBy ScheduleSort Field to sort the resulting list by Default: ScheduleSort.Id
direction SortDirection The direction to sort the results by Default: SortDirection.ASC
page int The page to get Default: 1
pageSize int The page size Default: 200
lite bool Get a lite version of the returned object Default: false

Returns:

PagedResult<IEnumerable<RecurringPayment>>

Example:

// Get all recurring payment schedules for customer id 123456 sorted by Id, ascending
var recurringSchedules = await customerService.GetRecurringPaymentSchedulesAsync(123456);

// Get all expired recurring payment schedules for customer id 123456 sorted by next payment amount ascending with a page size of 50 using lite records
var recurringSchedules = await customerService.GetRecurringPaymentSchedulesAsync(123456, status: ScheduleStatus.Expired, sortBy: ScheduleSort.PaymentAmount, pageSize: 50, lite = true);

MatchOrCreateCustomerAndCreditCardAccountAsync

MatchOrCreateCustomerAndCreditCardAccountAsync will match or create a customer and credit card with each other

Parameters:

Parameter Name Type Description Notes
request CustomerAndAccountRequest Customer and credit card account information

Example:

var customerAndCreditCard = new CustomerAndAccountRequest
{
	Customer = new Customer
	{
		Email = "[email protected]"
	},
	CreditCardAccount = new CreditCard
	{
		CreditCardNumber = "4111111111111111",
		BillingZipCode = "55555",
		Issuer = Issuer.Visa
	}
};
await customerService.MatchOrCreateCustomerAndCreditCardAccountAsync(customerAndCreditCard);

MatchOrCreateCustomerAndAchAccountAsync

MatchOrCreateCustomerAndAchAccountAsync sets a Customer Account to be the default account for Ach and CreditCard

Parameters:

Parameter Name Type Description Notes
request CustomerAndAccountRequest Customer and ach account information

Example:

var customerAndAch = new CustomerAndAccountRequest
{
	Customer = new Customer
	{
		Email = "[email protected]"
	},
	AchAccount = new Ach
	{
		RoutingNumber = "131111114",
		AccountNumber = "751111111"
	}
};
await customerService.MatchOrCreateCustomerAndAchAccountAsync(customerAndAch);

SetDefaultAccountAsync

SetDefaultAccountAsync sets a Customer Account to be the default account for Ach and CreditCard

Parameters:

Parameter Name Type Description Notes
customerId int CustomerId of the customer
accountId int Id of the account to set as the default account

Example:

await customerService.SetDefaultAccountAsync(123456, 654321);

UpdateCustomerAsync

UpdateCustomerAsync updates an existing Customer

Parameters:

Parameter Name Type Description Notes
customer Customer Customer to update

Returns:

Customer

Example:

var customer = new Customer
{
	Id = 123456,
	FirstName = "Mal",
	LastName = "Reynolds",
	ShippingSameAsBilling = false
};

var customer = await customerService.UpdateCustomerAsync(customer);
⚠️ **GitHub.com Fallback** ⚠️