Commit Graph

42 Commits

Author SHA1 Message Date
Blake Erickson f40d6f9cad
DEV: Add some more verbose logging for debugging groups (#242)
Sometimes users aren't added to groups so adding some more logging
statements to aid in debugging.
2024-10-18 14:29:42 -06:00
Blake Erickson 9c5ec86de7
DEV: Guest payments follow up (#236)
Just some minor follow up changes to PR #234
2024-08-29 14:49:03 -06:00
Blake Erickson fa5e95860b
DEV: Fetch related guest payments (#234) 2024-08-28 21:51:34 -06:00
Blake Erickson 700c5e7727
FIX: Payments not showing up for users (#233)
Pricing table payments for one off purchases need to be attached to the
customer or they don't show up on the user's billing payments page.
2024-08-28 15:03:22 -06:00
Blake Erickson a2c70deeff
FIX: Create customer for one off pricing table purchases (#232)
When using the Stripe Pricing Table for one-off purchases
(non-subscription) stripe doesn't automatically create a customer
record. This was causing the pricing table webhook
endpoint to end prematurely and not add users to their appropriate
group after purchase. Now if we detect that there is no customer record
we will make an api call to Stripe to create one.
2024-08-28 11:27:55 -06:00
Blake Erickson 71643a023d
DEV: Use warn instead of info for Rails logger (#231)
Follow up to: e92dd39928
2024-08-28 09:17:08 -06:00
Blake Erickson e92dd39928
DEV: Add verbose logging site setting (#230)
To aid in debugging I'm adding a verbose logging site setting. I'm
adding this because I'm currently getting some errors in production that
I'm unable to replicate locally.

See: https://meta.discourse.org/t/323450/4
2024-08-27 18:40:12 -06:00
Blake Erickson f0b4984cee
FIX: Pricing table for one-off purchases (#228)
When using the Stripe Pricing table for one-off purchases
(non-subscriptions) the webhook was encountering an error because it was
expecting subscription information which does not exist for one-off
purchases. This fix addresses that issue ensuring that no errors occur,
that users are added to the appropriate group, and that uses can see
their purchase on the billing page.
2024-08-20 13:32:32 -06:00
Blake Erickson c02193943b
FIX: Admins unable to cancel a subscription for a user (#220) 2024-07-12 14:33:04 -06:00
Blake Erickson 3cc113973f
FEATURE: Site Setting to enable automatic tax (#218)
FEATURE: Site Setting to enable automatic tax

There is now a new site setting called
`discourse_subscriptions_enable_automatic_tax` that can be enabled if
you would like to automatically compute tax rates on all new
subscriptions.
2024-07-08 13:22:02 -06:00
Blake Erickson d63c84eca5
FIX: One-time purchase pending invoice item (#210)
This change ensures we attach the invoice item to the invoice to avoid
any occurrences of an empty invoice being paid with pending invoice
items.
2024-05-07 08:57:37 -06:00
Blake Erickson e132913db4
FIX: Login required for Stripe Checkout (#209)
If an anonymous user tries to subscribe we need to show them a log in
message first. We currently don't have support for anonymous
subscriptions.
2024-05-03 17:01:51 -06:00
Blake Erickson 5eba613f8f
FIX: Prevent duplicate stripe subscription list requests (#208)
Users can have multiple customer records in our db, so we need to filter
out non-unique stripe customer ids before fetching subscriptions for each.
2024-05-03 12:38:26 -06:00
Blake Erickson 66e8857c20
DEV: Stop deleting customers on cancel (#207)
Instead of deleting customers on cancel we will now update the
subscription status to canceled. This way we can have some visibility on
which users have canceled.
2024-05-02 13:38:30 -06:00
Blake Erickson 6f54494a3b
FIX: Allow active status for updated webhook (#203)
Likely there was an API change at some point now that we are using the
latest version of the stripe API. When the
`customer.subscription.updated` webhook is called we should also accept
the status of "active".
2024-04-29 15:50:05 -06:00
Blake Erickson 45754baa00
FEATURE: Add new stripe based pricing table (#202)
This commit adds an optional new stripe based pricing table.
If the user is logged in, the email field will be prepopulated with the users email.

The pricing table can be configured in the stripe dashboard.

Once the discourse_subscriptions_pricing_table setting is filled with the pricing table embed code from the stripe dashboard,
the pricing table will be displayed on /s/subscriptions

For more details see https://stripe.com/docs/payments/checkout/pricing-table
---------

Co-authored-by: spirobel <spirobel@protonmail.com>
2024-04-29 12:47:58 -06:00
Loïc Guitaut 87659e237b DEV: Fix new Rubocop offenses 2024-03-06 15:23:55 +01:00
Mark Reeves 803bba7938
FEATURE: Capture cardholder address fields for Stripe customer (#161)
- Adds the following fields to the subscription payment form:
  - Cardholder Name
  - Country
  - Postal Code
  - Address Line 1
  - City
  - State or Province
- Stripe recommends Cardholder Name & Country for verification; Cardholder Name, Country, and State/Province for US/Canada selections are required fields
- All fields are passed to Stripe for verification on submit
- Fields are also captured on the customer record in Stripe, under Billing Details
2023-05-05 13:20:35 -04:00
David Taylor 4e1a17c40c
DEV: Introduce syntax_tree for ruby formatting (#144) 2022-12-29 13:35:06 +01:00
Bianca Nenciu a58743e376
FIX: Simplify Stripe webhook handler (#135)
The 'customer.subscription.created' webhooks were not handled at all and
the logic was overcomplicated.
2022-10-03 13:33:50 +03:00
Faizaan Gagan 945af4f140
FIX: Allow user to update card details for recurring subscriptions (#123)
* add new route for card update

* create backend route

* update label

* basic functionality working

* ran rubocop

* added rspec tests for functionality

* make payment_method param compulsory

* fixed js linting

* improve client side error handling

* improve server side error handling

* improved update card page UI

* improve button UI for user subscriptions page

* give feedback to user about save status

* remove heading from last column

* fix padding on edit/delete buttons for update table

Co-authored-by: Blake Erickson <o.blakeerickson@gmail.com>
2022-07-05 19:53:27 -06:00
Blake Erickson 46759c90cd
FIX: Duplicate payments showing up in discourse UI (#118)
Duplicate payments were showing up in the discourse ui for users. Actual
transactions in stripe were not being duplicated. This fix ensures that
when parsing the api response we don't append any duplicates. Added a
duplicate entry to the specs to test for this.

I do think there can be some improvements made to this controller
endpoint, but I'd like to save those for a different and larger PR and
just get this fix out first.
2022-05-17 09:22:42 -06:00
Blake Erickson 4f2af3b01a
FIX: 500 error when editing a pricing plan (#94)
`.dig` isn't valid for stripe objects. This commit fixes this 500 error
you get when trying to edit a pricing plan:

```
NoMethodError (undefined method `dig' for #<Stripe::Price:0x....)
```
2021-11-12 16:20:16 -07:00
Vinoth Kannan 33008b0b47
DEV: use existing customer id instead of creating. (#92)
Previosuly, new customer record is created in Stripe for each subscription in Discourse.
2021-10-08 09:40:16 +05:30
Vinoth Kannan 3ce422ffbe
FIX: set interval field correctly in object root for recurring plans. (#91)
The interval field was missing in the Ember object since it was only available inside the nested object.

Co-authored-by: Jarek Radosz <jradosz@gmail.com>
2021-09-21 18:12:17 +05:30
Justin DiRose 8ab7a63167
FEATURE: Validate coupon codes on form submit (#74) 2021-06-16 12:54:54 -05:00
Justin DiRose f596a0f78a
FEATURE: Campaigns (#67)
Co-authored-by: Jordan Vidrine <jordan@jordanvidrine.com>

See https://github.com/discourse/discourse-subscriptions/pull/67 for the full description.
2021-06-02 13:15:03 -05:00
Justin DiRose a282475da3
FEATURE: Admin > Subscriptions Pagination (#50)
Meta topic: https://meta.discourse.org/t/subscriptions-add-pagination-to-admin-subscriptions-view/172500

This adds support for pagination using our `{{load-more}}` component in core. Implementation on the backend was a bit tricky because we don't return all results from Stripe, only those that match local subscriptions stored in the `DiscourseSubscriptions::Subscription` model.
2021-02-05 11:57:53 -06:00
Justin DiRose 072b558d40
FEATURE: Give option to repurchase products multiple times (#46)
Feature requested here: https://meta.discourse.org/t/subscriptions-allow-users-to-purchase-one-time-products-multiple-times/173732/

There may be cases where a site admin wants to allow the repurchasing of a product. This implements the functionality by adding a repurchaseable toggle in the admin screen when creating a product. This saves an attribute to the Stripe product metadata.

When a user has already purchased an item with this toggle enabled, they will be able to purchase it again when browsing to `/s`.
2021-01-31 14:17:44 -06:00
Justin DiRose 400313cded
FEATURE: Allow creation of coupons in admin panel (#43)
Adds full support to create coupon/promo codes in the Admin > Plugins > Subscriptions section of the plugin. The Create Coupon button opens a form on the same page, and the active checkboxes toggle the active status of the coupon code.
2021-01-13 11:47:22 -06:00
Justin DiRose da9b58398b
FEATURE: Support for coupons in checkout (#41)
This adds support for Stripe Promo Codes in the user checkout process. 

Also adds a discounted field to User > Billing > Subscriptions to show the amount or percent discounted.

This does not currently add in support for creating promo codes in the Subscriptions interface (that will come at a later point in time). Instead a coupon can be created with a promo code right from the Stripe dashboard.
2021-01-07 15:25:44 -06:00
Justin DiRose 70b96cf3b8
FIX: Properly show one time payments in user billing (#40)
Encountered a bug where some one time payments were not showing under User > Billing > Payments. This was due to a simple error in the logic
2021-01-06 14:01:16 -06:00
Justin DiRose b92627677f
FEATURE: Implement refunds from dashboard (#27)
An implementation of refunds from the Admin dashboard. To refund, go to Plugins > Subscriptions > Subscriptions then click the `Cancel` button. You'll be presented with a modal. If you wish to refund only the most recent payment, check the box. 

This only implements refunds for Subscriptions, not One Time Payments. One Time Payments will still need to be handled manually at this time.
2020-10-29 10:31:12 -05:00
Justin DiRose 1ad5b17640
FEATURE: Better UX for anonymous users (#25)
Improves the subscription flow for anonymous users by making the routes available, and showing a login button. Clicking login from this page will save a `destination_url` cookie so that when logging in they're redirected back to the subscription page they were at.
2020-10-28 13:30:26 -05:00
Justin DiRose 3a5078ded6
REFACTOR: Simplify controller setup (#24)
The code in the plugin needed a dramatic cleanup. This refactor collapses the Plan/Product/Subscription controllers on the backend into one new controller: `SubscribeController`.

This reduces N+1 calls to the back end during the subscription process and simplifies use of the code. 

I've also removed a bunch of dead code and refactored some logic into methods for easier readability. No feature/functionality changes in this commit; only refactoring. However, refactoring will allow for implementation of better anonymous user handling, so this is largely a foundation to enable making that change.
2020-10-21 13:36:31 -05:00
Faizaan Gagan 55e6accb9c
FEATURE: Markdown support for product description (#21) 2020-10-12 10:01:33 -05:00
Justin DiRose 6ce6e85ef4
Make rubocop happy 2020-08-19 15:11:16 -05:00
Justin DiRose a868e6b838
FEATURE: Cancel payments at end of subscription vs immediately
Previously, when a user canceled a subscription, the access would revoke
immediately on Discourse vs. at the end of the billing period. This
commit changes the behavior to remove membership at the end of the
billing period using Stripe's `cancel_at_period_end` attribute on the
Subscription object.

This commit now requires the setup of webhooks for subscription
processing to occur correctly.
2020-08-19 14:37:47 -05:00
Justin DiRose 9491f558ea
FEATURE: Add support for 3D Secure payments (#19)
Adds an additional checkout flow to support authentication of payment methods.
2020-07-24 15:07:18 -05:00
Justin DiRose 587661fafb
FEATURE: Allow one-time purchases on products (#18)
Building off the foundation of using the Prices API, this PR adds the ability to create a one-time purchase plan for any product, which then can add a user to the specified plan group.

Some things to be aware of:

    One-time purchases cannot have trials.
    One-time purchases use the Invoice API instead of Subscriptions. Invoices are created then charged immediately.
    Users should receive emails for these invoices directly from Stripe just like subscriptions.
2020-07-22 11:06:34 -05:00
Justin DiRose c9ff55b46a
REFACTOR: Use the Prices API in place of Plans (#17)
Stripe has a newer API called Prices where you can create a price for any product and it can either be recurring or one-time. The easy part is existing Plans work with the Prices API by passing a Plan ID, but objects are returned in the slightly-different Prices API object format.

This commit is a refactor to the new API to handle the data in its new form, and lays the foundation for a one time payment plan to be added to any subscriptions product.
2020-07-15 08:44:40 -05:00
Justin DiRose fb4f50478d
REFACTOR: Use engine to load files, add constraint (#14) 2020-07-06 11:11:04 -05:00