Ask a Dev
Extension > Creating Custom Coupons on the Fly
From Russell:
**Q**: Do we need to call `SaveCoupon` from `couponService` or not while creating a custom coupon and applying it on the order on the fly? Also, does adding a newly created coupon mean that only its couponCode should be added to the `string[]` of the `orderCoupons` object?
**A**: When using the **ProcessCouponHook**. You have two options:
1. Add an existing coupon code to the `string[] CouponCodes`, then call the base functionality `func(request)`. If you use this method, the coupon code has already been set up in the system and will determine its discount amount. You are just adding to the order automatically.
2. Build your own Discount. Sometimes you want to build a discount that is different for everyone. In this case, you will run the base functionality and develop your `OrderCoupon` object. Using this method, you can create the discount amount very custom per person and order. This object asks for a `couponID`, which is looking at coupons that already exist, but you do not have to give a valid `couponID` if you don't want to. If you give it a valid `couponID,` the only thing that it will do is show that a coupon was used on this order in the UI.
Posted by Learning Experience Team over 3 years ago
Retail/WebOffice > Creating a Customer through the API
From Russell:
I had a question from a client about problems creating a customer through the Retail Shop. Retail and Back Office use the same authenticated call via the Angular v3Post call. In this case, the client struggled to figure out which fields were missing from the call and was running into problems with the Validation hook in Disco. Here's my response to them:
On the Customer Create issue, I'm seeing missing elements on the call in, and the ValidateApplicationHook is not managing them well when they're missing. The payload you sent in that failed is missing the following two elements:
1. PrimaryPhone
2. PostalCode must be passed in on the addresses, but as "Zip". (because the Azure Gateway does the mapping from PostalCode to Zip when you have used the public API in the past. You're calling through the Retail pathway now. Here is the swagger page for API2 (retail), focused on the CreateCustomer call: https://api2.directscale.com/swagger/ui/index#!/Customers/Customers_CreateCustomer) (see payload below)
**FYI**: On a CreateCustomer call from Retail, it looks like you only need to pass in "PrimaryAddress". The Retail API code creates a Disco "ShippingAddress" and "DefaultAddress" based on the Primary Address. If you want to set a shipping address differently, you'll need to call UpdateCustomer or the like, but I haven't looked into that. This is at least what I'm interpreting as I look through the code.
I also recommend you do some different null checking on validation elements in the WriteApplication hook (which is called in Create Customer, too). Something about the way it's done is blowing up if something is missing (this may be an artifact because I had to decompile the code, but I think you need to check for null or missing elements before using the reflection you've set up). But, if you get those two fields added from above, it'll work fine.
**Note**: this prompted the actual inclusion of the API payload. This is a little different than the public API because we do some mapping to fields you see here slightly differently. That said, it makes the same Disco call.
Payload of /api/Customers/CreateCustomer (I removed the DefaultAddress and ShippingAddress because they're stripped out on their way into Corpadmin)
{
"BackOfficeId": "string",
"BirthDate": "2021-01-18T23:14:02.081Z",
"CompanyName": "string",
"CustomerStatus": 0,
"CustomerType": 0,
"EmailAddress": "string",
"ExternalReferenceId": "string",
"FirstName": "string",
"LanguageCode": "string",
"LastName": "string",
"Password": "string",
"PrimaryPhone": "string",
"SecondaryPhone": "string",
"SendEmails": true,
"SignUpDate": "2021-01-18T23:14:02.081Z",
"SponsorId": 0,
"TaxExemptId": "string",
"TaxId": "string",
"TermsAccepted": "string",
"TextPhone": "string",
"Username": "string",
"WebAlias": "string",
"RomanizedFirstName": "string",
"RomanizedLastName": "string",
"LegalFirstName": "string",
"LegalLastName": "string"
"PrimaryAddress": {
"ID": 0,
"Line1": "string",
"Line2": "string",
"Line3": "string",
"City": "string",
"State": "string",
"Zip": "string",
"CountryCode": "string"
}
}
Posted by Learning Experience Team over 3 years ago
Extension > Getting Client ID and Environment on Running Application
From Russell:
Sometimes, it's essential to know whether you're running in a Sandbox or the Live environment and to verify the Client ID of the instance you're running on. This can be done in the extension using the following:
ExtensionContext is part of the SettingsService (ISettingsService), which can be injected.
Once you've got the handle to SettingsService, do this:
```
string clientId = _settingsService.ExtensionContext().ClientId; // IE, "demo"
DirectScale.Disco.Extension.EnvironmentType envType = _settingsService.ExtensionContext().EnvironmentType;
// EnvironmentType is an enum, and can be either Sandbox or Live
```
Read more: [Verifying Extension Environment and Client ID](https://developers.directscale.com/docs/verifying-extension-environment-and-client-id)
Posted by Learning Experience Team over 3 years ago