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

adding stripe modular example #29

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

tylernix
Copy link

@tylernix tylernix commented May 30, 2024

Description

This example models a few of Stripe's core functionality, but not everything.
It introduces another modular models example splitting the model into 3 modules:

  • accounts.fga - core Stripe account functionality
  • payments.fga - (yet to be implemented)
  • issuing.fga - credit card issuing and transactions

It also introduces modeling concepts such as "self-defining" relationships, "dual-write" relationships, and "intermediate" relationships. It also uses exclusions and conditions.

It includes tests for two scenarios:

  1. SCENARIO 1: An account manages 2 cards, assigned to users Raghd and Jon. Raghd's card is active and makes two purchases. Jon's card is inactive and makes one purchase
  2. SCENARIO 2: A Stripe account (in test mode) manages one active card that tries to make a purchase.
  • Working on writing a README.md for the sample store.

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

@tylernix tylernix requested a review from a team as a code owner May 30, 2024 22:06
@aaguiarz
Copy link
Member

Let's also add a readme file as in the rest of the examples

Copy link
Member

@aaguiarz aaguiarz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a few comments

@@ -0,0 +1,34 @@
module issuing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like an odd module name. What would be the app component handling this called? "card-management""

define view_only: [user] or admin
define transfer_analyst_in_test_mode: transfer_analyst but not transfer_analyst from test_mode # intermediate relations, just used for evaluating other relations

define test_mode: [account] # self-defining relationship, used to set a type into a true/false state
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should explain in the comments what is test mode used for in Stripe


extend type account
relations
define card: [card] # dual-writes relationships between card & account, when you need to traverse relations on two types checking both ways (starting at card then going up or account then going down)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify why we need to traverse it both ways?

## default spending limit is 500 USD a day
## could be 100 USD per transaction
## could be 3000 USD per month
condition spending_limit(transaction_amount: double, transaction_limit: double, daily_amount: double, daily_limit: double, monthly_amount: double, monthly_limit: double) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have tuples/tests that use the condition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants