Payment Service - PaySimple/PaySimpleSDK GitHub Wiki

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

Payment Service

The Payment Service is used to create, get, reverse and void payments. The SDK provides the following methods:

  • CreateNewAccountPaymentAsync
  • CreateNewCustomerPaymentAsync
  • CreatePaymentAsync
  • GetCheckoutAsync
  • GetPaymentAsync
  • GetPaymentsAsync
  • GetPaymentTokenAsync
  • ReversePaymentAsync
  • VoidPaymentAsync

Constructor

Parameters:

Parameter Name Type Description Notes
settings IPaySimpleSdkSettings SDK Settings

Example:

var settings = new PaySimpleSettings("AoOtRylA63570WmH3eqChyFRqwhTnA2g0dnsV7zzQko4s4yKWdBorA1WiT7dK2H2xz06P562Hqv0heYBdfNamfQyxX50drtpL8s7", "AUserName");
var paymentService = new PaymentService(settings);

Service Methods


CreateNewAccountPaymentAsync

CreateNewAccountPaymentAsync is a convenience method that creates a new account and a new payment linked to an existing customer

Parameters:

Parameter Name Type Description Notes
accountPayment NewAccountPayment Account and Payment to create T is either Ach or CreditCard

Returns:

NewAccountPayment

Example:

var accountPayment = new NewAccountPayment<CreditCard>
{
	Account = new CreditCard
	{
		CustomerId = 123456,
		CreditCardNumber = "4111111111111111",
		ExpirationDate = "12/2021",
		Issuer = Issuer.Visa
	},
	Payment = new Payment
	{
		Amount = 50.00M,
		Cvv = 996
	}
};

var newAccountPayment = await paymentService.CreateNewAccountPaymentAsync<CreditCard>(accountPayment);

CreateNewCustomerPaymentAsync

CreateNewCustomerPaymentAsync is a convenience method that creates a new customer, a new account and a new payment

Parameters:

Parameter Name Type Description Notes
customerPayment NewCustomerPayment Customer, Account and Payment to create T is either Ach or CreditCard

Returns:

NewCustomerPayment

Example:

var customerPayment = new NewCustomerPayment<CreditCard>
{
	Customer = new Customer
	{
		FirstName = "Jayne",
		LastName = "Cobb"
	},
	Account = new CreditCard
	{		
		CreditCardNumber = "371449635398456",
		ExpirationDate = "12/2021",
		Issuer = Issuer.Amex
	},
	Payment = new Payment
	{
		Amount = 5.00M,
		Cvv = 996
	}
};

var newCustomerPayment = await paymentService.CreateNewCustomerPaymentAsync<CreditCard>(customerPayment);

CreatePaymentAsync

CreatePaymentAsync creates a new payment

Parameters:

Parameter Name Type Description Notes
payment Payment Payment to create

Returns:

Payment

Example:

var payment = new Payment
{
	AccountId = 123456,
	Amount = 42.00M,
}

var result = await paymentService.CreatePaymentAsync(payment);

GetCheckoutTokenAsync

GetCheckoutTokenAsync gets a token that will identify you during the checkout process

Returns:

CheckoutToken

Example:

var checkoutToken = await paymentService.GetCheckoutTokenAsync();

GetPaymentAsync

GetPaymentAsync gets a specific payment

Parameters:

Parameter Name Type Description Notes
paymentId int Id of the Payment to get

Returns:

Payment

Example:

var result = await paymentService.GetPaymentAsync(123456);

GetPaymentsAsync

GetPaymentsAsync gets Payments

Parameters:

Parameter Name Type Description Notes
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>

Example:

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

// Get all payments 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(status, PaymentSort.Amount);

GetPaymentTokenAsync

GetPaymentTokenAsync gets a token that represents protected card data for a payment account

Parameters:

Parameter Name Type Description Notes
request PaymentTokenRequest Information about the protected card data to get a token for

Returns:

PaymentToken

Example:

var tokenRequest = new PaymentTokenRequest
{
	CustomerAccountId = 123456,
	CustomerId = 44444,
	Cvv = "999"
};
var paymentToken = await paymentService.GetPaymentTokenAsync(tokenRequest);

ReversePaymentAsync

ReversePaymentAsync refunds a specific payment that has a status of Authorized (Credit Card) or ReversePosted (Ach)

Parameters:

Parameter Name Type Description Notes
paymentId int Id of the Payment to refund

Returns:

Payment

Example:

var result = await paymentService.ReversePaymentAsync(123456);

VoidPaymentAsync

VoidPaymentAsync refunds a specific payment that has a status of Authorized (Credit Card), Posted (Ach) and ReversePosted (Ach)

Parameters:

Parameter Name Type Description Notes
paymentId int Id of the Payment to refund

Returns:

Payment

Example:

var result = await paymentService.VoidPaymentAsync(123456);
⚠️ **GitHub.com Fallback** ⚠️