ClubReady Api

<back to all web services

SellContractRequest

The following routes are available for this service:
POST/sales/contract/soldSell a package to an existing user Sell a package to an existing user. The PaymentMethods property is an array of objects describing how you want ClubReady to take payment while selling the PackageId/InstallmentPlanId. If omitted (or null), the preferred on-file profile will be used.
import Foundation
import ServiceStack

// @ApiResponse(Description="", ResponseType=typeof(SellContractResultDto), StatusCode=200)
public class SellContractRequest : SellContractRequestDto, IRestrictedApiRequest
{
    /**
    * Api Authentication Key
    */
    // @ApiMember(Description="Api Authentication Key", IsRequired=true, ParameterType="query")
    public var apiKey:String

    /**
    * Member Id of the user buying the Package
    */
    // @ApiMember(Description="Member Id of the user buying the Package", IsRequired=true, ParameterType="query")
    public var memberId:Int

    /**
    * Id for the chain of the Api Key
    */
    // @ApiMember(Description="Id for the chain of the Api Key")
    public var chainId:Int?

    /**
    * Id of the store for the user
    */
    // @ApiMember(Description="Id of the store for the user", IsRequired=true)
    public var storeId:Int?

    /**
    * Package Id number of the package being purchased
    */
    // @ApiMember(Description="Package Id number of the package being purchased", IsRequired=true)
    public var packageId:Int

    /**
    * Installment Plan Id being purchased. If empty, the default package will be selected.
    */
    // @ApiMember(Description="Installment Plan Id being purchased. If empty, the default package will be selected.")
    public var installmentId:Int?

    /**
    * Amount being paid down, including tax
    */
    // @ApiMember(Description="Amount being paid down, including tax", IsRequired=true)
    public var paymentAmount:Double?

    /**
    * Promo code to apply a discount.
    */
    // @ApiMember(Description="Promo code to apply a discount.")
    public var promoCode:String

    /**
    * Staff Id of salesperson who sold the agreement.
    */
    // @ApiMember(Description="Staff Id of salesperson who sold the agreement.")
    public var staffId:Int?

    /**
    * An array of Payment Methods to be used for this purchase. Any entry with PreferredOnFile is assumed if omitted or null.  Each object of the array may contain properties:| Property | Description || --- | --- || PaymentMethodType | Usually "AcctToken" (Default or omitted/null) or "PreferredOnFile" || PaymentAmount | The amount to be attempted for this Payment Method. When omitted (or null), the Request's PaymentAmount will be attempted || AcctToken | The AcctToken to attempt payment (when using PaymentMethodType:AcctToken) || ProfileToken | When provided (with AcctToken), a Payment Profile will be created (this will prevent the requirement to call `/sales/paymentprofile/import` (when using PaymentMethodType:AcctToken) || DoNotUpdatePaymentTypePreference | When using ProfileToken, do not set the PaymentTypePreference (for more information, see `/sales/paymentprofile/import` (when using PaymentMethodType:AcctToken) || | |* Scenario #1: Use the on file profile only. PaymentMethods can be omitted/null, or :  JSON:```json{    PaymentMethods: [        {            "PaymentMethodType":"PreferredOnFile",            "PaymentAmount":"1.00"        }    ]}```JSV:```jsv[{PaymentMethodType:PreferredOnFile,PaymentAmount:1.00}]```* Scenario #2: Use a Gift Card with PreferredOnFile to cover the amount not approved by the Gift Card.  JSON:```json{    PaymentMethods: [        {            "PaymentMethodType":"AcctToken",            "PaymentAmount":"1.00",            "AcctToken":"eyJ...GiftCard AcctToken...",            "ProfileToken":"eyJ...Gift Card ProfileToken..."        },        {            "PaymentMethodType":"PreferredOnFile",            "PaymentAmount":"1.00"        }    ]}```JSV:```jsv[{PaymentMethodType:AcctToken,PaymentAmount:1.00,AcctToken:eyj...,ProfileToken:eyJ...},{PaymentMethodType:PreferredOnFile,PaymentAmount:1.00}]```  Notes:  * The example shows PaymentAmount of 1.00 for both "AcctToken" and "PreferredOnFile". This is for the examplewith a total of $1.00. The firstPaymentMethod (the Gift Card) will be attempted for $1.00. If it partially approvesfor less than 1.00 (example: $0.80), the second payment method (PreferredOnFile) will be attempted for the lesser ofit's PaymentAmount and the remaining amount (example: $0.20).* If ProfileToken has already been used (e.g. used with `/sales/paymentprofile/import`), it does not need to be included,but AcctToken is required. ProfileToken is only needed once to 'activate' the AcctToken.* When using Query String (or this web site), this value must be encoded with JSV [(JSON-like Separated Values)](https://docs.servicestack.net/jsv-format).Basic steps to convert JSON to JSV: 1) Remove properties that are null, 2) Remove white space including line feeds, 3) Remove quotes.
    */
    // @ApiMember(Description="\r\nAn array of Payment Methods to be used for this purchase. Any entry with PreferredOnFile is assumed if omitted or null.  \r\n\r\nEach object of the array may contain properties:\r\n\r\n| Property | Description |\r\n| --- | --- |\r\n| PaymentMethodType | Usually \"AcctToken\" (Default or omitted/null) or \"PreferredOnFile\" |\r\n| PaymentAmount | The amount to be attempted for this Payment Method. When omitted (or null), the Request's PaymentAmount will be attempted |\r\n| AcctToken | The AcctToken to attempt payment (when using PaymentMethodType:AcctToken) |\r\n| ProfileToken | When provided (with AcctToken), a Payment Profile will be created (this will prevent the requirement to call `/sales/paymentprofile/import` (when using PaymentMethodType:AcctToken) |\r\n| DoNotUpdatePaymentTypePreference | When using ProfileToken, do not set the PaymentTypePreference (for more information, see `/sales/paymentprofile/import` (when using PaymentMethodType:AcctToken) |\r\n| | |\r\n\r\n* Scenario #1: Use the on file profile only. PaymentMethods can be omitted/null, or :  \r\n\r\nJSON:\r\n```json\r\n{\r\n    PaymentMethods: [\r\n        {\r\n            \"PaymentMethodType\":\"PreferredOnFile\",\r\n            \"PaymentAmount\":\"1.00\"\r\n        }\r\n    ]\r\n}\r\n```\r\nJSV:\r\n```jsv\r\n[{PaymentMethodType:PreferredOnFile,PaymentAmount:1.00}]\r\n```\r\n\r\n\r\n* Scenario #2: Use a Gift Card with PreferredOnFile to cover the amount not approved by the Gift Card.  \r\n\r\nJSON:\r\n```json\r\n{\r\n    PaymentMethods: [\r\n        {\r\n            \"PaymentMethodType\":\"AcctToken\",\r\n            \"PaymentAmount\":\"1.00\",\r\n            \"AcctToken\":\"eyJ...GiftCard AcctToken...\",\r\n            \"ProfileToken\":\"eyJ...Gift Card ProfileToken...\"\r\n        },\r\n        {\r\n            \"PaymentMethodType\":\"PreferredOnFile\",\r\n            \"PaymentAmount\":\"1.00\"\r\n        }\r\n    ]\r\n}\r\n```\r\nJSV:\r\n```jsv\r\n[{PaymentMethodType:AcctToken,PaymentAmount:1.00,AcctToken:eyj...,ProfileToken:eyJ...},{PaymentMethodType:PreferredOnFile,PaymentAmount:1.00}]\r\n```  \r\n\r\nNotes:  \r\n\r\n* The example shows PaymentAmount of 1.00 for both \"AcctToken\" and \"PreferredOnFile\". This is for the example\r\nwith a total of $1.00. The firstPaymentMethod (the Gift Card) will be attempted for $1.00. If it partially approves\r\nfor less than 1.00 (example: $0.80), the second payment method (PreferredOnFile) will be attempted for the lesser of\r\nit's PaymentAmount and the remaining amount (example: $0.20).\r\n\r\n* If ProfileToken has already been used (e.g. used with `/sales/paymentprofile/import`), it does not need to be included,\r\nbut AcctToken is required. ProfileToken is only needed once to 'activate' the AcctToken.\r\n\r\n* When using Query String (or this web site), this value must be encoded with JSV [(JSON-like Separated Values)](https://docs.servicestack.net/jsv-format).\r\nBasic steps to convert JSON to JSV: 1) Remove properties that are null, 2) Remove white space including line feeds, 3) Remove quotes.\r\n")
    public var paymentMethods:[PaymentMethodDto] = []

    public var restrictedId:Int?
    public var restrictedResourceType:RestrictedResourceType

    required public init(){ super.init() }

    private enum CodingKeys : String, CodingKey {
        case apiKey
        case memberId
        case chainId
        case storeId
        case packageId
        case installmentId
        case paymentAmount
        case promoCode
        case staffId
        case paymentMethods
        case restrictedId
        case restrictedResourceType
    }

    required public init(from decoder: Decoder) throws {
        try super.init(from: decoder)
        let container = try decoder.container(keyedBy: CodingKeys.self)
        apiKey = try container.decodeIfPresent(String.self, forKey: .apiKey)
        memberId = try container.decodeIfPresent(Int.self, forKey: .memberId)
        chainId = try container.decodeIfPresent(Int.self, forKey: .chainId)
        storeId = try container.decodeIfPresent(Int.self, forKey: .storeId)
        packageId = try container.decodeIfPresent(Int.self, forKey: .packageId)
        installmentId = try container.decodeIfPresent(Int.self, forKey: .installmentId)
        paymentAmount = try container.decodeIfPresent(Double.self, forKey: .paymentAmount)
        promoCode = try container.decodeIfPresent(String.self, forKey: .promoCode)
        staffId = try container.decodeIfPresent(Int.self, forKey: .staffId)
        paymentMethods = try container.decodeIfPresent([PaymentMethodDto].self, forKey: .paymentMethods) ?? []
        restrictedId = try container.decodeIfPresent(Int.self, forKey: .restrictedId)
        restrictedResourceType = try container.decodeIfPresent(RestrictedResourceType.self, forKey: .restrictedResourceType)
    }

    public override func encode(to encoder: Encoder) throws {
        try super.encode(to: encoder)
        var container = encoder.container(keyedBy: CodingKeys.self)
        if apiKey != nil { try container.encode(apiKey, forKey: .apiKey) }
        if memberId != nil { try container.encode(memberId, forKey: .memberId) }
        if chainId != nil { try container.encode(chainId, forKey: .chainId) }
        if storeId != nil { try container.encode(storeId, forKey: .storeId) }
        if packageId != nil { try container.encode(packageId, forKey: .packageId) }
        if installmentId != nil { try container.encode(installmentId, forKey: .installmentId) }
        if paymentAmount != nil { try container.encode(paymentAmount, forKey: .paymentAmount) }
        if promoCode != nil { try container.encode(promoCode, forKey: .promoCode) }
        if staffId != nil { try container.encode(staffId, forKey: .staffId) }
        if paymentMethods.count > 0 { try container.encode(paymentMethods, forKey: .paymentMethods) }
        if restrictedId != nil { try container.encode(restrictedId, forKey: .restrictedId) }
        if restrictedResourceType != nil { try container.encode(restrictedResourceType, forKey: .restrictedResourceType) }
    }
}

public class SellContractRequestDto : ApiDtoBase
{
    public var memberId:Int
    public var packageId:Int
    public var installmentId:Int?
    public var startDate:Date?
    public var paymentAmount:Double?
    public var promoCode:String
    public var paymentMethods:[PaymentMethodDto] = []
    public var staffId:Int?

    required public init(){ super.init() }

    private enum CodingKeys : String, CodingKey {
        case memberId
        case packageId
        case installmentId
        case startDate
        case paymentAmount
        case promoCode
        case paymentMethods
        case staffId
    }

    required public init(from decoder: Decoder) throws {
        try super.init(from: decoder)
        let container = try decoder.container(keyedBy: CodingKeys.self)
        memberId = try container.decodeIfPresent(Int.self, forKey: .memberId)
        packageId = try container.decodeIfPresent(Int.self, forKey: .packageId)
        installmentId = try container.decodeIfPresent(Int.self, forKey: .installmentId)
        startDate = try container.decodeIfPresent(Date.self, forKey: .startDate)
        paymentAmount = try container.decodeIfPresent(Double.self, forKey: .paymentAmount)
        promoCode = try container.decodeIfPresent(String.self, forKey: .promoCode)
        paymentMethods = try container.decodeIfPresent([PaymentMethodDto].self, forKey: .paymentMethods) ?? []
        staffId = try container.decodeIfPresent(Int.self, forKey: .staffId)
    }

    public override func encode(to encoder: Encoder) throws {
        try super.encode(to: encoder)
        var container = encoder.container(keyedBy: CodingKeys.self)
        if memberId != nil { try container.encode(memberId, forKey: .memberId) }
        if packageId != nil { try container.encode(packageId, forKey: .packageId) }
        if installmentId != nil { try container.encode(installmentId, forKey: .installmentId) }
        if startDate != nil { try container.encode(startDate, forKey: .startDate) }
        if paymentAmount != nil { try container.encode(paymentAmount, forKey: .paymentAmount) }
        if promoCode != nil { try container.encode(promoCode, forKey: .promoCode) }
        if paymentMethods.count > 0 { try container.encode(paymentMethods, forKey: .paymentMethods) }
        if staffId != nil { try container.encode(staffId, forKey: .staffId) }
    }
}

public class ApiDtoBase : Codable
{
    public var apiKey:String
    public var storeId:Int?
    public var chainId:Int?

    required public init(){}
}

// @DataContract
public class PaymentMethodDto : Codable
{
    // @DataMember
    public var acctToken:String

    // @DataMember
    public var profileToken:String

    // @DataMember
    public var paymentProfileId:String

    // @DataMember
    public var paymentAmount:Double?

    // @DataMember
    public var paymentMethodType:PaymentMethodType?

    // @DataMember
    public var doNotUpdatePaymentTypePreference:Bool?

    required public init(){}
}

public enum PaymentMethodType : Int, Codable
{
    case Uninitialized = 0
    case PaymentProfileId = 1
    case PreferredOnFile = 2
    case AcctToken = 3
    case Error = -1
}

public enum RestrictedResourceType : String, Codable
{
    case Store
    case Chain
    case User
    case Undefined
}

public class SellContractResultDto : Codable
{
    public var contractSaleID:String
    public var Description:String
    public var success:Bool
    public var paymentResponses:IReadOnlyList<PendingPaymentResponse>

    required public init(){}
}

public class PendingPaymentResponse : Codable
{
    public var responseTransactionId:String
    public var responseTxnId:String
    public var responseStatus:ResponseStatus
    public var responseAmount:Double
    public var responseText:String
    public var last4:String
    public var acctClass:String
    public var acctType:String
    public var acctToken:String

    required public init(){}
}


Swift SellContractRequest DTOs

To override the Content-type in your clients, use the HTTP Accept Header, append the .jsv suffix or ?format=jsv

HTTP + JSV

The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.

POST /sales/contract/sold HTTP/1.1 
Host: www.clubready.com 
Accept: text/jsv
Content-Type: text/jsv
Content-Length: length

{
	ApiKey: String,
	MemberId: 0,
	ChainId: 0,
	StoreId: 0,
	PackageId: 0,
	InstallmentId: 0,
	PaymentAmount: 0,
	PromoCode: String,
	StaffId: 0,
	PaymentMethods: 
	[
		{
			AcctToken: String,
			ProfileToken: String,
			PaymentProfileId: String,
			PaymentAmount: 0,
			PaymentMethodType: Uninitialized,
			DoNotUpdatePaymentTypePreference: False
		}
	],
	RestrictedId: 0,
	RestrictedResourceType: Chain,
	StartDate: 0001-01-01
}
HTTP/1.1 200 OK
Content-Type: text/jsv
Content-Length: length

{
	ContractSaleID: String,
	description: String,
	Success: False
}