POST | /v1/order | Creates an order for a selected vehicle via the Agency API | This endpoint is called from Online Showroom to create a vehicle order. It builds the order request object for the Agency API before calling it to create the order. The information it retrieves and builds for the Agency API request include 1.) The customer. 2.) The vehicle. 3.) Ourright purchase. 4.) Motability. 5.) Offers applicable to the vehicle Validation is performed on the input data which includes checking for mandatory items: 1.} Customer details 2.) Vehicle Vin 3.) Agent 4.) GSSN Outlet Id 5.) Source 6.) Order Type 7.) Customer Location Id 8.) Estimated Handover Date |
---|
import Foundation
import ServiceStack
public class CreateOrderRequest : CreateOrderBase, IGet
{
required public init(){ super.init() }
required public init(from decoder: Decoder) throws {
try super.init(from: decoder)
}
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
}
}
public class CreateOrderBase : Codable
{
public var source:Source
public var gssnId:String
public var additionalInformation:String
public var cash:Bool
public var finance:Bool
public var customer:Customer
public var vehicle:Vehicle
public var financeCriteria:FinanceCriteria
public var backOrderGuid:String?
public var tagUrl:String
public var outrightPurchase:OutrightPurchase
public var motability:Bool
public var motabilityPricingId:Int?
public var financeApplicationReference:String
public var specialist:Bool
public var gasId:String
public var personalisedItemOfferIds:[Int]
public var suggestedVin:String
public var nonOptimumReason:String
public var motabilityType:MotabilityType
public var estimatedHandoverDate:String
required public init(){}
}
public enum Source : Int, Codable
{
case OnlineShowroom = 1
case OneAdmin = 2
}
public class Customer : SalesforceCustomer
{
public var profileId:String?
public var preferences:Preferences
required public init(){ super.init() }
private enum CodingKeys : String, CodingKey {
case profileId
case preferences
}
required public init(from decoder: Decoder) throws {
try super.init(from: decoder)
let container = try decoder.container(keyedBy: CodingKeys.self)
profileId = try container.decodeIfPresent(String.self, forKey: .profileId)
preferences = try container.decodeIfPresent(Preferences.self, forKey: .preferences)
}
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
if profileId != nil { try container.encode(profileId, forKey: .profileId) }
if preferences != nil { try container.encode(preferences, forKey: .preferences) }
}
}
public class SalesforceCustomer : ICustomer, Codable
{
public var customerId:String
public var isCiam:Bool
public var companyName:String
public var title:String
public var firstname:String
public var surname:String
public var emailAddress:String
public var telephone:String
public var address:Address
public var mode:CustomerMode
required public init(){}
}
public class Address : Codable
{
public var property:String
public var street:String
public var town:String
public var county:String
public var locality:String
public var postcode:String
required public init(){}
}
public enum CustomerMode : Int, Codable
{
case Private = 1
case Business = 2
case Motability = 3
}
public class Preferences : Codable
{
public var optinEmail:Bool
public var optinPost:Bool
public var optinSMS:Bool
public var optinTelephone:Bool
required public init(){}
}
public class Vehicle : Codable
{
public var vin:String
required public init(){}
}
public class FinanceCriteria : Codable
{
public var key:String
public var name:String
public var type:String
public var isDefault:Bool
public var term:Term
public var deposit:Deposit
public var mileage:Mileage
public var advanceRentals:AdvanceRentals
public var isPersonalised:Bool
public var regularPayment:String
public var partExchange:String
public var settlement:String
public var customerType:String
public var vehicleType:VehicleType
required public init(){}
}
public class Term : Codable
{
public var options:[Option] = []
required public init(){}
}
public class Option : Codable
{
public var isDefault:Bool
public var value:Int
required public init(){}
}
public class Deposit : Codable
{
public var `default`:String
required public init(){}
}
public class Mileage : Codable
{
public var options:[Option] = []
required public init(){}
}
public class AdvanceRentals : Codable
{
public var options:[Option] = []
required public init(){}
}
public enum VehicleType : String, Codable
{
case UNASSIGNED
case NEW
case USED
}
public class OutrightPurchase : Codable
{
public var isOutrightPurchase:Bool
public var reference:String
public var discountRate:Double
public var bm7NST:String
public var isBackOrder:Bool
public var isCOPConverter:Bool
required public init(){}
}
public enum MotabilityType : Int, Codable
{
case PIP = 1
case WPMS = 2
case UNASSIGNED = 3
}
public class CreateOrderResponse : Codable
{
public var guid:String
public var reference:String
public var responseStatus:ResponseStatus
public var backOrderReference:String
required public init(){}
}
To override the Content-type in your clients, use the HTTP Accept Header, append the .jsv suffix or ?format=jsv
The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.
POST /v1/order HTTP/1.1
Host: prod-api-agency-orch-mb-dhc.rapp-customers.co.uk
Accept: text/jsv
Content-Type: text/jsv
Content-Length: length
{
Source: OnlineShowroom,
GssnId: String,
AdditionalInformation: String,
Cash: False,
Finance: False,
Customer:
{
ProfileId: 00000000000000000000000000000000,
Preferences:
{
OptinEmail: False,
OptinPost: False,
OptinSMS: False,
OptinTelephone: False
},
CustomerId: String,
IsCiam: False,
CompanyName: String,
Title: String,
Firstname: String,
Surname: String,
EmailAddress: String,
Telephone: String,
Address:
{
Property: String,
Street: String,
Town: String,
County: String,
Locality: String,
Postcode: String
},
Mode: Private
},
Vehicle:
{
Vin: String
},
FinanceCriteria:
{
Key: String,
Name: String,
Type: String,
IsDefault: False,
Term:
{
Options:
[
{
IsDefault: False,
Value: 0
}
]
},
Deposit:
{
Default: String
},
Mileage:
{
Options:
[
{
IsDefault: False,
Value: 0
}
]
},
AdvanceRentals:
{
Options:
[
{
IsDefault: False,
Value: 0
}
]
},
IsPersonalised: False,
RegularPayment: String,
PartExchange: String,
Settlement: String,
CustomerType: String,
VehicleType: UNASSIGNED
},
BackOrderGuid: 00000000000000000000000000000000,
TagUrl: String,
OutrightPurchase:
{
IsOutrightPurchase: False,
Reference: String,
DiscountRate: 0,
Bm7NST: String,
IsBackOrder: False,
IsCOPConverter: False
},
Motability: False,
MotabilityPricingId: 0,
FinanceApplicationReference: String,
Specialist: False,
GasId: String,
PersonalisedItemOfferIds:
[
0
],
SuggestedVin: String,
NonOptimumReason: String,
MotabilityType: PIP,
EstimatedHandoverDate: String
}
HTTP/1.1 200 OK Content-Type: text/jsv Content-Length: length { Guid: String, Reference: String, ResponseStatus: { ErrorCode: String, Message: String, StackTrace: String, Errors: [ { ErrorCode: String, FieldName: String, Message: String, Meta: { String: String } } ], Meta: { String: String } }, BackOrderReference: String }