Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for free trials #51

Merged
merged 1 commit into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/grant-revoke-access-to-product.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ exports.dynamodbStreamHandler = async (event) => {
// eslint-disable-next-line no-console
console.log(`DynamoDb record updated! OldImage: ${JSON.stringify(oldImage)} | NewImage: ${JSON.stringify(newImage)}`);


/*
successfully_subscribed is set true:
- for SaaS Contracts: after reciving the entitlement in entitlement-sqs.js for the first time
- for SaaS Contracts: no email is sent but after receiving the message in the subscription topic
- for SaaS Subscriptions: after reciving the subscribe-success message in subscription-sqs.js

subscription_expired is set to true:
- for SaaS Contracts: after detecting expired entitlement in entitlement-sqs.js
- for SaaS Subscriptions: after reciving the unsubscribe-success message in subscription-sqs.js
*/
const grantAccess = newImage.successfully_subscribed === true
&& oldImage.successfully_subscribed !== true;
const grantAccess = newImage.successfully_subscribed === true &&
typeof newImage.is_free_trial_term_present !== "undefined" &&
( oldImage.successfully_subscribed !== true || typeof oldImage.is_free_trial_term_present === "undefined" )


const revokeAccess = newImage.subscription_expired === true
&& !oldImage.subscription_expired;
Expand Down
8 changes: 7 additions & 1 deletion src/subscription-sqs.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,21 @@ exports.SQSHandler = async (event) => {
throw new Error(`Unhandled action - msg: ${JSON.stringify(record)}`);
}

let isFreeTrialTermPresent = false;
if (typeof message.isFreeTrialTermPresent === "string") {
isFreeTrialTermPresent = message.isFreeTrialTermPresent.toLowerCase() === "true";
}

const dynamoDbParams = {
TableName: newSubscribersTableName,
Key: {
customerIdentifier: { S: message['customer-identifier'] },
},
UpdateExpression: 'set successfully_subscribed = :ss, subscription_expired = :se',
UpdateExpression: 'set successfully_subscribed = :ss, subscription_expired = :se, is_free_trial_term_present = :ft',
ExpressionAttributeValues: {
':ss': { BOOL: successfullySubscribed },
':se': { BOOL: subscriptionExpired },
':ft': { BOOL: isFreeTrialTermPresent}
},
ReturnValues: 'UPDATED_NEW',
};
Expand Down
1 change: 0 additions & 1 deletion template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ Resources:

SubscriptionSQSHandler:
Type: AWS::Serverless::Function
Condition: CreateSubscriptionLogic
Properties:
CodeUri: src
Handler: subscription-sqs.SQSHandler
Expand Down