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

Stripe promote on checkout #228

Merged
merged 11 commits into from
Jul 25, 2022
Merged

Stripe promote on checkout #228

merged 11 commits into from
Jul 25, 2022

Conversation

ro-tex
Copy link
Contributor

@ro-tex ro-tex commented Jul 5, 2022

PULL REQUEST

Overview

Our typical payment flow starts with us creating a checkout session and redirecting the user to a Stripe-controlled page where they make the actual payment. After the payment is done, we wait for a push notification on our webhook endpoint. We process that notification and promote/demote the user accordingly.
This works well and is reliable because Stripe will keep sending the webhook event until they get a successful response.
The problem with it is that it might take a while and the user will be left without any notification what is going on.

This PR solves that problem by introducing a new endpoint which we can proactively call in order to check the status of a given checkout session and promote the user, if required. Note that we won't demote the user by calling this endpoint - that will be handled by the webhook endpoint. This new endpoint will only be used in order to speed up the user promotion process, so we get happy users.

Example for Visual Changes

Response JSON example:

{
    "created": 1658417273,
    "currentPeriodStart": 1658417273,
    "discount": {
        "amountOff": 0,
        "currency": "",
        "duration": "repeating",
        "durationInMonths": 3,
        "name": "test50%",
        "percentOff": 50
    },
    "id": "sub_1LO1I5IzjULiPWN6zatWjjxl",
    "plan": {
        "amount": 2000,
        "currency": "usd",
        "interval": "month",
        "intervalCount": 1,
        "product": {
            "description": "Pin up to 4TB",
            "name": "Skynet Pro"
        }
    },
    "startDate": 1658417273,
    "status": "active"
}

Checklist

  • All git commits are signed. (REQUIRED)
  • All new methods or updated methods have clear docstrings.
  • Testing added or updated for new methods.
  • Verified if any changes impact the WebPortal Health Checks.
  • Appropriate documentation updated.
  • Changelog file created.

Issues Closed

Closes SKY-1056

@ro-tex ro-tex self-assigned this Jul 5, 2022
@ro-tex ro-tex force-pushed the ivo/stripe_promote_on_checkout branch from cac7e7e to add777d Compare July 5, 2022 08:37
@linear
Copy link

linear bot commented Jul 6, 2022

SKY-1056 Implement an API endpoint to query the status of a payment

This endpoint should synchronously check the payment status with Stripe and update the user record if it was successful (so that we don't need to wait for the webhook call to arrive).

api/stripe.go Outdated Show resolved Hide resolved
api/stripe.go Show resolved Hide resolved
@ro-tex ro-tex marked this pull request as ready for review July 7, 2022 08:36
@ro-tex ro-tex enabled auto-merge July 7, 2022 08:41
Copy link

@peterjan peterjan left a comment

Choose a reason for hiding this comment

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

looks good, would clean it up a bit but definitely close to done

api/stripe.go Outdated Show resolved Hide resolved
test/api/stripe_test.go Outdated Show resolved Hide resolved
test/api/stripe_test.go Outdated Show resolved Hide resolved
test/api/stripe_test.go Outdated Show resolved Hide resolved
api/stripe.go Outdated Show resolved Hide resolved
@ro-tex ro-tex marked this pull request as draft July 21, 2022 14:45
auto-merge was automatically disabled July 21, 2022 14:45

Pull request was converted to draft

…e parts we need and use the proper naming convention.

Fix some error messages.
Set the client's email and description in Stripe when creating it.
@ro-tex ro-tex marked this pull request as ready for review July 22, 2022 12:52
@ro-tex ro-tex enabled auto-merge July 22, 2022 12:52
peterjan
peterjan previously approved these changes Jul 25, 2022
@ro-tex ro-tex requested a review from peterjan July 25, 2022 10:37
@ro-tex ro-tex merged commit 74d6623 into main Jul 25, 2022
@ro-tex ro-tex deleted the ivo/stripe_promote_on_checkout branch July 25, 2022 14:30
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.

3 participants