POST | /sales/contract/sold | Sell 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.* When using Query String values (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. |
---|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using ServiceStack;
using ServiceStack.DataAnnotations;
using ClubReady.Web.Api.Sales;
using ClubReady.Core.Api.Models;
using ClubReady.Web.Api;
using ClubReady.Core.Api.Sales;
using ClubReady.Payments;
using ClubReadyGateway.Gateway;
namespace ClubReady.Core.Api.Models
{
[DataContract]
public partial class PaymentMethodDto
{
[DataMember]
public virtual string AcctToken { get; set; }
[DataMember]
public virtual string ProfileToken { get; set; }
[DataMember]
public virtual string PaymentProfileId { get; set; }
[DataMember]
public virtual decimal? PaymentAmount { get; set; }
[DataMember]
public virtual bool? UsePreferred { get; set; }
[DataMember]
public virtual bool? DoNotUpdatePaymentTypePreference { get; set; }
}
}
namespace ClubReady.Core.Api.Sales
{
public partial class ContractSoldResponse
{
public virtual string ContractSaleID { get; set; }
public virtual string description { get; set; }
public virtual bool Success { get; set; }
public virtual IReadOnlyList<PendingPaymentResponse> PaymentResponses { get; set; }
}
}
namespace ClubReady.Payments
{
public partial class PendingPaymentResponse
{
public virtual string ResponseTransactionId { get; set; }
public virtual string ResponseTxnId { get; set; }
public virtual ResponseStatus ResponseStatus { get; set; }
public virtual decimal ResponseAmount { get; set; }
public virtual string ResponseText { get; set; }
public virtual string Last4 { get; set; }
public virtual string AcctClass { get; set; }
public virtual string AcctType { get; set; }
public virtual string AcctToken { get; set; }
}
}
namespace ClubReady.Web.Api
{
public enum RestrictedResourceType
{
Store,
Chain,
User,
Undefined,
}
}
namespace ClubReady.Web.Api.Sales
{
[ApiResponse(Description="", ResponseType=typeof(ClubReady.Core.Api.Sales.ContractSoldResponse), StatusCode=200)]
public partial class ContractSoldEndpoint
: IContractSoldEndpoint, IRestrictedApiRequest
{
public ContractSoldEndpoint()
{
PaymentMethods = new List<PaymentMethodDto>{};
}
///<summary>
///IP address of the end user
///</summary>
[ApiMember(Description="IP address of the end user", Name="X-Forwarded-For", ParameterType="header")]
public virtual string XForwardedFor { get; set; }
///<summary>
///Api Authentication Key
///</summary>
[ApiMember(Description="Api Authentication Key", IsRequired=true, ParameterType="query")]
public virtual string ApiKey { get; set; }
///<summary>
///Member Id of the user buying the Package
///</summary>
[ApiMember(Description="Member Id of the user buying the Package", IsRequired=true, ParameterType="query")]
public virtual int MemberId { get; set; }
///<summary>
///Id for the chain of the Api Key
///</summary>
[ApiMember(Description="Id for the chain of the Api Key")]
public virtual int? ChainId { get; set; }
///<summary>
///Id of the store for the user
///</summary>
[ApiMember(Description="Id of the store for the user", IsRequired=true)]
public virtual int? StoreId { get; set; }
///<summary>
///Package Id number of the package being purchased
///</summary>
[ApiMember(Description="Package Id number of the package being purchased", IsRequired=true)]
public virtual int PackageId { get; set; }
///<summary>
///Installment Plan Id being purchased. If empty, the default package will be selected.
///</summary>
[ApiMember(Description="Installment Plan Id being purchased. If empty, the default package will be selected.")]
public virtual int? InstallmentId { get; set; }
///<summary>
///Date contract takes affect
///</summary>
[ApiMember(Description="Date contract takes affect")]
public virtual DateTime? StartDate { get; set; }
///<summary>
///Amount being paid down, including tax
///</summary>
[ApiMember(Description="Amount being paid down, including tax", IsRequired=true)]
public virtual decimal? PaymentAmount { get; set; }
///<summary>
///Promo code to apply a discount.
///</summary>
[ApiMember(Description="Promo code to apply a discount.")]
public virtual string PromoCode { get; set; }
///<summary>
///Staff Id of salesperson who sold the agreement.
///</summary>
[ApiMember(Description="Staff Id of salesperson who sold the agreement.")]
public virtual int? StaffId { get; set; }
///<summary>
///An array of PaymentMethod objects to be used for this purchase. A null array (or omitted property) will use thePreferred method for the total amount.Each object of the array may contain properties:| Property | Description || --- | --- || PaymentAmount | The maximum amount to be attempted for this PaymentMethod. When null or omitted, the remaining PaymentAmount will be attempted. || **Use only one of the following three** | **UsePreferred** or **AcctToken** or **ProfileToken [DoNotUpdatePaymentTypePreference]** || UsePreferred | Set to `true` to use the Preferred method, otherwise omit the value or set to `null` or `false` || AcctToken | The AcctToken to attempt payment || ProfileToken | When provided, a PaymentMethod will be created (this will prevent the requirement to call `/sales/paymentprofile/import`) || DoNotUpdatePaymentTypePreference | [Optional] When creating a PaymentMethod (ProfileToken), it is set as the preferred method. To not create as preferred, set `DoNotUpdatePaymentTypePreference` to `true`. (for more information, see `/sales/paymentprofile/import`) || | |Only one of `UsePreferred`, `AcctToken`, `ProfileToken` or is needed. `DoNotUpdatePaymentTypePreference` is optionaland only valid with `ProfileToken`.* Scenario #1: Sell $3 contract using an existing PaymentMethod (i.e. AcctToken) for $1 and the Preferred method for $2.JSON:```json{ ... "PaymentAmount": 3.00, "PaymentMethods": [ { "PaymentAmount": "1.00", "AcctToken": "eyJ..." }, { "PaymentAmount": "2.00", "UsePreferred": true } ]}```JSV:```...,PaymentAmount:3.00,PaymentMethods:[{PaymentAmount:1.00,AcctToken:eyJ...NdQ},{PaymentAmount:2.00,UsePreferred:true}]```* Scenario #2: Sell $3 contract using a new PaymentMethod (i.e. ProfileToken) for $1 and the Preferred method for the remaining.Note, the sum of the PaymentMethod's PaymentAmount ($4) is greater than the agreement amount ($3). PaymentAmount is the maximum amount.This allows the first PaymentMethod to decline or partially approve (common with gift cards). Therefore, if the first PaymentMethod approvesfor $0.75, the second will be attempted for $2.25.JSON:```json{ ... "PaymentAmount": 3.00, "PaymentMethods": [ { "PaymentAmount": "1.00", "ProfileToken": "eyJ..." }, { "PaymentAmount": "3.00", "UsePreferred": true } ]}```JSV:```jsv...,PaymentAmount:3.00,PaymentMethods:[{PaymentAmount:1.00,ProfileToken:eyj...NdQ},{PaymentAmount:3.00,UsePreferred:true}]```Notes: * AcctTokens should not be parsed or persisted in the client application. They are currently jsonbased, but can be updated without notice.* ProfileToken is used to create a PaymentMethod in the ClubReady system. For more information, see `/sales/paymentprofile/import`.* If `PaymentMethods` is missing or `null`, the Preferred method will be used.* If a `PaymentMethods` `PaymentAmount` is not specified, the remaining amount will be attempted.* If a PaymentMethod is partially approved (common for gift cards), the PaymentMethod with anunspecified PaymentAmount will be charged the remaining amount, including the unapproved amount not.* When testing with this website, the PaymentMethods textbox needs JSV and only the square brackets and contents(e.g. `[{PaymentAmount:1.00,UsePreferred:true}]`).
///</summary>
[ApiMember(Description="An array of PaymentMethod objects to be used for this purchase. A null array (or omitted property) will use the\r\nPreferred method for the total amount.\r\n\r\nEach object of the array may contain properties:\r\n\r\n| Property | Description |\r\n| --- | --- |\r\n| PaymentAmount | The maximum amount to be attempted for this PaymentMethod. When null or omitted, the remaining PaymentAmount will be attempted. |\r\n| **Use only one of the following three** | **UsePreferred** or **AcctToken** or **ProfileToken [DoNotUpdatePaymentTypePreference]** |\r\n| UsePreferred | Set to `true` to use the Preferred method, otherwise omit the value or set to `null` or `false` |\r\n| AcctToken | The AcctToken to attempt payment |\r\n| ProfileToken | When provided, a PaymentMethod will be created (this will prevent the requirement to call `/sales/paymentprofile/import`) |\r\n| DoNotUpdatePaymentTypePreference | [Optional] When creating a PaymentMethod (ProfileToken), it is set as the preferred method. To not create as preferred, set `DoNotUpdatePaymentTypePreference` to `true`. (for more information, see `/sales/paymentprofile/import`) |\r\n| | |\r\n\r\nOnly one of `UsePreferred`, `AcctToken`, `ProfileToken` or is needed. `DoNotUpdatePaymentTypePreference` is optional\r\nand only valid with `ProfileToken`.\r\n\r\n* Scenario #1: Sell $3 contract using an existing PaymentMethod (i.e. AcctToken) for $1 and the Preferred method for $2.\r\n\r\nJSON:\r\n```json\r\n{\r\n ...\r\n \"PaymentAmount\": 3.00,\r\n \"PaymentMethods\": [\r\n {\r\n \"PaymentAmount\": \"1.00\",\r\n \"AcctToken\": \"eyJ...\"\r\n },\r\n {\r\n \"PaymentAmount\": \"2.00\",\r\n \"UsePreferred\": true\r\n }\r\n ]\r\n}\r\n```\r\nJSV:\r\n```\r\n...,PaymentAmount:3.00,PaymentMethods:[{PaymentAmount:1.00,AcctToken:eyJ...NdQ},{PaymentAmount:2.00,UsePreferred:true}]\r\n```\r\n\r\n* Scenario #2: Sell $3 contract using a new PaymentMethod (i.e. ProfileToken) for $1 and the Preferred method for the remaining.\r\nNote, the sum of the PaymentMethod's PaymentAmount ($4) is greater than the agreement amount ($3). PaymentAmount is the maximum amount.\r\nThis allows the first PaymentMethod to decline or partially approve (common with gift cards). Therefore, if the first PaymentMethod approves\r\nfor $0.75, the second will be attempted for $2.25.\r\n\r\nJSON:\r\n```json\r\n{ \r\n ...\r\n \"PaymentAmount\": 3.00,\r\n \"PaymentMethods\": [\r\n {\r\n \"PaymentAmount\": \"1.00\",\r\n \"ProfileToken\": \"eyJ...\"\r\n },\r\n {\r\n \"PaymentAmount\": \"3.00\",\r\n \"UsePreferred\": true\r\n }\r\n ]\r\n}\r\n```\r\nJSV:\r\n```jsv\r\n...,PaymentAmount:3.00,PaymentMethods:[{PaymentAmount:1.00,ProfileToken:eyj...NdQ},{PaymentAmount:3.00,UsePreferred:true}]\r\n```\r\n\r\nNotes: \r\n\r\n* AcctTokens should not be parsed or persisted in the client application. They are currently json\r\nbased, but can be updated without notice.\r\n\r\n* ProfileToken is used to create a PaymentMethod in the ClubReady system. For more information, \r\nsee `/sales/paymentprofile/import`.\r\n\r\n* If `PaymentMethods` is missing or `null`, the Preferred method will be used.\r\n\r\n* If a `PaymentMethods` `PaymentAmount` is not specified, the remaining amount will be attempted.\r\n\r\n* If a PaymentMethod is partially approved (common for gift cards), the PaymentMethod with an\r\nunspecified PaymentAmount will be charged the remaining amount, including the unapproved amount not.\r\n\r\n* When testing with this website, the PaymentMethods textbox needs JSV and only the square brackets and contents\r\n(e.g. `[{PaymentAmount:1.00,UsePreferred:true}]`).")]
public virtual List<PaymentMethodDto> PaymentMethods { get; set; }
public virtual int? RestrictedId { get; set; }
public virtual RestrictedResourceType RestrictedResourceType { get; set; }
}
}
namespace ClubReadyGateway.Gateway
{
public enum ResponseStatus
{
stsUnknown = 0,
stsSuccess = 1,
stsDecline = 2,
stsError = 3,
HardDeclineAccount = 4,
HardDeclineExpiry = 5,
PartialApproval = 11,
PendingSuccess = 12,
}
}
To override the Content-type in your clients, use the HTTP Accept Header, append the .csv suffix or ?format=csv
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/csv
Content-Type: text/csv
Content-Length: length
{"XForwardedFor":"String","ApiKey":"String","MemberId":0,"ChainId":0,"StoreId":0,"PackageId":0,"InstallmentId":0,"StartDate":"0001-01-01T00:00:00.0000000","PaymentAmount":0,"PromoCode":"String","StaffId":0,"PaymentMethods":[{"AcctToken":"String","ProfileToken":"String","PaymentProfileId":"String","PaymentAmount":0,"UsePreferred":false,"DoNotUpdatePaymentTypePreference":false}],"RestrictedId":0,"RestrictedResourceType":"Chain"}
HTTP/1.1 200 OK Content-Type: text/csv Content-Length: length {"ContractSaleID":"String","description":"String","Success":false}