RTP|One Guide: Validated Prompt Setup
Aspenware Commerce supports validating against a stored procedure in RTP|One when checking out in Aspenware Commerce. When configured, a customer validates they are eligible for a purchase of a particular fenced product either through entering data in a prompt field on the personalize step of checkout, or by only allowing only certain eligible guests to be assigned to a gated product on the PDP or on the Assign step of checkout. This document outlines the setup needed in RTP|One to make this work. Aspenware Commerce configuration can be completed after this is done in RTP|One by following this guide: Configuration: Validated Prompts.
Many varieties of validations are in use on customer sites which validate various pieces of data in RTP|One. These include Access Rules, Voucher Templates, Pass Media Prefixes, etc.
Almost anything in RTP|One can be validated against, but the key to the validation stored procedure is that a 0 needs to be returned to pass validation and a 1 needs to be returned to fail validation. Aspenware will always send the parameters, IPCode, ProductHeaderCode, PromptData, PromptCode, and ProductStartDate but these can either be used or not for the validation stored procedure.
The setup includes deploying the validated stored procedure to the RTPOne/RTPOneTest database, a new Rule and Prompt in RTP|One Admin, and a Product Prompt in Aspenware.
Detailed Setup Guide
Create a new Rule in RTP|One Administration like below.
General Tab
Name and Keyword – set to the same upper case description
Description – this description shows in when adding the Rule to the Prompt
Rule Type: Stored Procedure
XML Map: None
Data Type: String
Compare Type: None
Stored Proc. Name: description of stored procedure
Entities Tab
Add: RTP.Enterprise.Framework.BLL.Prompt
Rule Parameters Tab (*the Parameter descriptions must match exactly) - Add appropriate Object XML Map entry
Add Line Item IPCode and enter: IPCode
Add Line Item Product Header Code and enter: ProductHeaderCode
Add Prompt Data and enter: PromptData
Add Prompt Code and enter: PromptCode
Add Line Item Product Date and enter: ProductStartDate
Create a new Prompt in RTP Admin
General Tab:
Enter any Code, Display Order, Description, Display Caption and Security Level (recommend 0)
Validate Stored Procedure: enter KEYWORD from Rule
Rules tab: Add new Rule
Create a customer stored procedure. Below is an example where the assigned customer in check-out is being validated along with whether the VoucherID entered was created in RTP with VoucherTypeCode 123. The validation portion of the stored procedure (in red below) can be customized to validate anything in RTP. As long as a 0 is returned in the stored procedure results, the validation will succeed online. If a 1 is returned, it will fail validation. After deploying the stored procedure, you must GRANT EXECUTE privileges to the RTPOneRole or Unity role.
CREATE PROCEDURE [dbo].[AW_EcommValidatedPromptVoucherType123]--GRANT EXECUTE ON [dbo].[AW_EcommValidatedPromptVoucherType123] TO [RTPOneRole](@SessionToken nvarchar(32)='', -- Required@PromptData nvarchar(255)='', -- Required@PromptCode nvarchar(32)=-1, --Required@ProductHeaderCode nvarchar(32) = '',@IPCode nvarchar(32)=-1, --Required,@ProductStartDate DATE = '')ASBEGINset nocount onDECLARE @i_OperatorID nvarchar(255)DECLARE @i_ReturnMessage nvarchar(255)DECLARE @i_ReturnValue intDECLARE @i_SeedValue intDECLARE @i_ReturnCode intDECLARE @i_EligibilityInd char(1)SET @SessionToken = LTRIM(RTRIM(@SessionToken))SET @PromptData = LTRIM(RTRIM(@PromptData))SET @PromptCode = LTRIM(RTRIM(@PromptCode))SET @IPCode = LTRIM(RTRIM(@IPCode))SET @ProductHeaderCode = LTRIM(RTRIM(@ProductHeaderCode))-- Verify SessionSELECT @i_OperatorID = AuthenticationIDFROM dbo.UserSession WITH (NOLOCK)WHERE SessionToken = @SessionTokenIF @@ROWCOUNT = 0BEGINSET @i_ReturnMessage = 'Error: The User Session is not valid.'RAISERROR (@i_ReturnMessage, 16, 1)RETURN @@ERROREND--Validate VoucherType 123IF EXISTS( SELECT 0FROM dbo.Voucher vJOIN VoucherRecipient vrON v.VoucherID = vr.VoucherIDAND vr.RecipientIPCode = @IPCodeJOIN VoucherType vtON v.VoucherTypeCode = vt.VoucherTypeCodeAND v.VoucherStatusCode = 1and vt.VoucherTypeCode = 123AND v.VoucherID = @PromptData)BEGINSELECT 0 AS Code,'Valid' AS TextRETURNEND--Catch-allBEGINSELECT 1 AS Code,'Invalid' AS TextRETURNENDRETURN @@ERROREND
CREATE PROCEDURE [dbo].[AW_EcommValidatedPromptVoucherType123]
--GRANT EXECUTE ON [dbo].[AW_EcommValidatedPromptVoucherType123] TO [RTPOneRole]
(
@SessionToken nvarchar(32)='', -- Required
@PromptData nvarchar(255)='', -- Required
@PromptCode nvarchar(32)=-1, --Required
@ProductHeaderCode nvarchar(32) = '',
@IPCode nvarchar(32)=-1, --Required,
@ProductStartDate DATE = ''
)
AS
BEGIN
set nocount on
DECLARE @i_OperatorID nvarchar(255)
DECLARE @i_ReturnMessage nvarchar(255)
DECLARE @i_ReturnValue int
DECLARE @i_SeedValue int
DECLARE @i_ReturnCode int
DECLARE @i_EligibilityInd char(1)
SET @SessionToken = LTRIM(RTRIM(@SessionToken))
SET @PromptData = LTRIM(RTRIM(@PromptData))
SET @PromptCode = LTRIM(RTRIM(@PromptCode))
SET @IPCode = LTRIM(RTRIM(@IPCode))
SET @ProductHeaderCode = LTRIM(RTRIM(@ProductHeaderCode))
-- Verify Session
SELECT @i_OperatorID = AuthenticationID
FROM dbo.UserSession WITH (NOLOCK)
WHERE SessionToken = @SessionToken
IF @@ROWCOUNT = 0
BEGIN
SET @i_ReturnMessage = 'Error: The User Session is not valid.'
RAISERROR (@i_ReturnMessage, 16, 1)
RETURN @@ERROR
END
--Validate VoucherType 123
IF EXISTS
( SELECT 0
FROM dbo.Voucher v
JOIN VoucherRecipient vr
ON v.VoucherID = vr.VoucherID
AND vr.RecipientIPCode = @IPCode
JOIN VoucherType vt
ON v.VoucherTypeCode = vt.VoucherTypeCode
AND v.VoucherStatusCode = 1
and vt.VoucherTypeCode = 123
AND v.VoucherID = @PromptData
)
BEGIN
SELECT 0 AS Code,
'Valid' AS Text
RETURN
END
--Catch-all
BEGIN
SELECT 1 AS Code,
'Invalid' AS Text
RETURN
END
RETURN @@ERROR
END