-
Notifications
You must be signed in to change notification settings - Fork 44.7k
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
feat(platform): Implement top-up flow for PAYG System #9050
base: dev
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for auto-gpt-docs-dev canceled.
|
✅ Deploy Preview for auto-gpt-docs canceled.
|
await User.prisma().update( | ||
where={"id": user_id}, data={"stripeCustomerId": customer.id} | ||
) | ||
user.stripeCustomerId = customer.id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await User.prisma().update( | |
where={"id": user_id}, data={"stripeCustomerId": customer.id} | |
) | |
user.stripeCustomerId = customer.id | |
user = await User.prisma().update( | |
where={"id": user_id}, data={"stripeCustomerId": customer.id} | |
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or even better: avoid calling Prisma here and add set_stripe_customer_id in model class on user.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left the original code - trying to change it or move to the function cascades into multiple errors and requires additional checks.
} | ||
], | ||
mode="payment", | ||
success_url="",# TODO kcze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So these will be webhook URLs ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are redirect urls after checkout
|
||
if (!stripe) { | ||
console.error("Stripe failed to load"); | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we throw an error instead ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed console.error
altogether, this should never happen; stripePromise
should never be null
and loadStripe
throws when we don't provide API key.
This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request. |
|
||
# Check the Checkout Session's payment_status property | ||
# to determine if fulfillment should be peformed | ||
if checkout_session.payment_status != "unpaid": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this riskier than just match 'paid' & 'no_payment_required' ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not now, there are only three options and this is from Stripe example but just to be sure I updated it anyway!
return {"checkout_url": checkout_url} | ||
|
||
|
||
@v1_router.post(path="/credits/stripe_webhook", tags=["credits"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious, Is this a non-authenticated request ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess no but it requires HTTPS on live data and API key to read correctly.
# Invalid signature | ||
raise HTTPException(status_code=400) | ||
|
||
print(event) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: make this logging ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
event['type'] == 'checkout.session.completed' | ||
or event['type'] == 'checkout.session.async_payment_succeeded' | ||
): | ||
await _user_credit_model.fulfill_checkout(event['data']['object']['id']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the nested check: uses get()
with fallback for safety?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also can we log/warn the non matching events ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the nested check: uses get() with fallback for safety?
What do you mean? I don't think using event.get(..)
would change anything.
Also can we log/warn the non matching events ?
Do you think this is necessary on our side? Stripe logs everything and each event has tons of data and only 4 out of hundreds are enabled for this webhook. I could disabled 2, so only the 2 matching will be sent.
# Check the Checkout Session's payment_status property | ||
# to determine if fulfillment should be peformed | ||
if checkout_session.payment_status != "unpaid": | ||
print("Payment status is not unpaid!") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: make this and the one above logging with more information ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed, that was only for testing.
const response = await api.requestTopUp(amount); | ||
|
||
router.push(response.checkout_url); | ||
}, [api]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won' this warn about router not part of the deplist ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added router
@@ -442,7 +446,7 @@ export default class BackendAPI { | |||
await new Promise((resolve) => setTimeout(resolve, 100 * retryCount)); | |||
} | |||
} | |||
console.log("Request: ", method, path, "from: ", page); | |||
console.log("Request: ", method, this.baseUrl, path, "from: ", page); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: console.debug ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed but this needs a refactor imo
Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly. |
WIP
Changes 🏗️
Checklist 📋
For code changes:
Example test plan
For configuration changes:
.env.example
is updated or already compatible with my changesdocker-compose.yml
is updated or already compatible with my changesExamples of configuration changes