OloLabs.Promotions.SDK
3.0.3
Prefix Reserved
dotnet add package OloLabs.Promotions.SDK --version 3.0.3
NuGet\Install-Package OloLabs.Promotions.SDK -Version 3.0.3
<PackageReference Include="OloLabs.Promotions.SDK" Version="3.0.3" />
<PackageVersion Include="OloLabs.Promotions.SDK" Version="3.0.3" />
<PackageReference Include="OloLabs.Promotions.SDK" />
paket add OloLabs.Promotions.SDK --version 3.0.3
#r "nuget: OloLabs.Promotions.SDK, 3.0.3"
#:package OloLabs.Promotions.SDK@3.0.3
#addin nuget:?package=OloLabs.Promotions.SDK&version=3.0.3
#tool nuget:?package=OloLabs.Promotions.SDK&version=3.0.3
OloLabs.Promotions.SDK
OloLabs.Promotions.SDK is a NuGet package that provides models and tools for integrating with the Olo Promotions Specification.
View the Promotions Spec at https://developer.olo.com/docs.
Use of the SDK is subject to the terms of the Olo Promotions SDK License.
Table of Contents
Getting Started
Install from NuGet.org
This SDK is available on NuGet.org: OloLabs.Promotions.SDK
This can be installed via the NuGet command line:
nuget install OloLabs.Promotions.SDK
Or added to an existing project using the dotnet CLI:
dotnet add package OloLabs.Promotions.SDK
Or added via Visual Studio's NuGet Package Manager:
Install from .nupkg file
- Download the latest release of our NuGet package GitHub or NuGet.org.
- Create a local feed for NuGet.
- Add the OloLabs.Promotions.SDK package to the local feed.
- Install the package to your application.
nuget install OloLabs.Promotions.SDK
Structure
The SDK includes three primary directories/namespaces:
├───OloLabs.Promotions.SDK
│ ├───Authentication
│ ├───Requests
│ └───Responses
These areas include:
- Authentication helpers
- Models for Requests
- Models for Responses
How to Use
Authentication
bool ValidateSignature(string signatureFromRequest)
{
// Build the RequestAuthenticator.
var requestAuthenticator = new RequestAuthenticator();
// Generate a signature using the URL and body from the incoming request, along with the shared secret between you and Olo.
var expectedSignature = requestAuthenticator.CreateSignature(
url: "https://your-promotions-api.local/promotions/validate",
body: "{the-request-body}",
secret: "YOUR_SECRET");
// Compare the request's signature (provided in the header X-Promo-Signature) with your generated signature.
// If they match, then the signature is valid and the request is successfully authenticated.
// If they don't match, then the signature is invalid and the request fails authentication.
return signatureFromRequest == expectedSignature;
}
You can register the RequestAuthenticator for dependency injection using the IRequestAuthenticator interface.
builder.Services.AddSingleton<IRequestAuthenticator, RequestAuthenticator>();
Then you can inject it in your controllers/services/etc.
public class PromotionsRequestAuthenticatorMiddleware
{
private readonly IRequestAuthenticator _requestAuthenticator;
public PromotionsRequestAuthenticatorMiddleware(IRequestAuthenticator requestAuthenticator)
{
_requestAuthenticator = requestAuthenticator;
}
bool ValidateSignature(string signatureFromRequest)
{
var expectedSignature = _requestAuthenticator.CreateSignature(...);
...
}
}
Requests
The following request models are provided:
AccruePointsRequestCreateAccountRequestRedeemPromotionsRequestValidatePromotionsRequestVoidAccrualRequestVoidRedemptionRequest
You can use the relevant models in your API configuration to accept incoming Promotions requests that specify a request body.
public class ValidatePromotionsController
{
[HttpPost]
public IActionResult ValidatePromotions([FromBody] ValidatePromotionsRequest request)
{
Console.WriteLine(JsonSerializer.Serialize(request));
}
}
// Output:
// {
// "orderId": null,
// "accountId": "391528477",
// "source": "Web",
// "handoff": "delivery",
// "currency": "USD",
// "placed": "2023-02-01T18:00:00.000Z",
// "wanted": "2023-02-01T19:30:00.000Z",
// ...
// }
No request models are provided for the endpoints "Find Accounts" and "Get Account" since they only accept query and path parameters via the URL and do not accept request bodies.
To accept these parameters, specify them in your API route configuration.
[Route("/promotions/accounts/{accountId}")]
public class GetAccountController
{
...
}
Responses
Successful Responses
The following response models are provided:
AccruePointsResponseCreateAccountResponseFindAccountsResponseGetAccountResponseRedeemPromotionsResponseValidatePromotionsResponseVoidAccrualResponseVoidRedemptionResponse
You can use the relevant models to return successful responses from your API.
public class VoidAccrualController
{
[HttpDelete]
public IActionResult VoidAccrual(...)
{
...
return Ok(new VoidAccrualResponse
{
Transaction = new Transaction
{
...
}
});
}
}
Error Responses
Two error response models are provided:
ErrorCodeResponse- For
400 Bad Requesterror responses that require acode. - Use
ErrorCodeto specify the value forcodeErrorCode.InvalidAccount→INVALID_ACCOUNTErrorCode.InvalidPromotion→INVALID_PROMOTION- etc.
- For
ErrorResponse- For all other error responses.
Example for ErrorCodeResponse:
public class VoidAccrualController
{
[HttpDelete]
[Route("/promotions/accruals/{accrualId}")]
public IActionResult VoidAccrual(string accrualId, [FromBody] VoidAccrualRequest request)
{
...
return BadRequest(new ErrorCodeResponse
{
Id = Guid.NewGuid().ToString(),
Code = ErrorCode.InvalidAccount // "INVALID_ACCOUNT",
Details = $"Account ID '{request.AccountId}' could not be found.",
Message = "There was a problem with your loyalty account. Please try again later."
});
}
}
Example for ErrorResponse:
public class VoidAccrualController
{
[HttpDelete]
[Route("/promotions/accruals/{accrualId}")]
public IActionResult VoidAccrual(string accrualId, [FromBody] VoidAccrualRequest request)
{
...
return NotFound(new ErrorResponse
{
Id = Guid.NewGuid().ToString(),
Details = $"Transaction ID {accrualId} could not be found.",
Message = "There was a problem voiding the loyalty transaction. Please try again later."
});
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.