# Adding new controllers and routes to Discourse-subscriptions plugin

**URL:** <https://meta.discourse.org/t/adding-new-controllers-and-routes-to-discourse-subscriptions-plugin/233704>\
**Category:** Development\
**Tags:** subscriptions\
**Created:** [July 22, 2022, 10:44pm UTC](https://meta.discourse.org/t/adding-new-controllers-and-routes-to-discourse-subscriptions-plugin/233704 "2022-07-22T22:44:19Z")\
**Posts on this page:** 6\
**Page:** 1

## AI-generated summary

The discussion revolves around adding a new payment method (bank transfer) to the Discourse-subscriptions plugin. [martin_junior_tchoup](/t/-/233704/1) seeks help integrating a new Ruby controller (`PaymentIntentsController`) and Ember route for handling bank transfer payments via Stripe. Despite creating the controller and route, they encounter a 404 error, indicating the route isn't recognized. [merefield](/t/-/233704/2) advises breaking the task into smaller parts, using existing plugin code as a reference, and ensuring proper Ember route and controller setup. [martin_junior_tchoup](/t/-/233704/4) confirms they’ve removed prior work and are starting fresh, showing their current implementation, including a form in `subscribe/show.hbs`, a `PaymentIntentsController`, and a route in `routes.rb`. They ask about the best way to handle form submission—whether to use a new Ember controller, modify `subscribe-show.js`, or use a script tag. [merefield](/t/-/233704/5) recommends creating an Ember route and controller, referencing Ember guides and existing user preference screens for guidance.

<div class="post-metadata">

**Author:** ![martin\_junior\_tchoup](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/martin_junior_tchoup/32/253858_2.png) [@martin\_junior\_tchoup](https://meta.discourse.org/u/martin_junior_tchoup)\
**Post date:** [July 22, 2022, 10:44pm UTC](https://meta.discourse.org/t/adding-new-controllers-and-routes-to-discourse-subscriptions-plugin/233704/1 "2022-07-22T22:44:19Z")

</div>

Hello,  
I need help, I’m used to create fullstack applications but regarding ember and rails I’m still a beginner.

I want to add another payment method (bank transfer) to the discourse-subscriptions plugin. I already managed to create some new routes and add some features to it, but I’m struggling to add a new controller to the /discourse\_subscriptions/ controllers directory and make it work properly.

I want to set up a ruby controller that will act as a server and an ember template as my client the structure is as follows:

 ![structure](https://global.discourse-cdn.com/meta/original/4X/e/0/a/e0a70bf72faa18e84daa16da03d795512e73f225.png)

after creating the payment intent, the payment\_intent controller must return the necessary payment instructions to the client.  
more details: [Stripe - accept bank transfers](https://stripe.com/docs/payments/bank-transfers/accept-a-payment)

I have already created new pages by adding methods in the subscribe\_controller.rb file in the discourse\_subscriptions/ controller folder but when I try to create another controller (the server) it doesn’t work, it displays a 404 error, however in the ember inspector I see that the route actually exists (yes it is really confusing).

NB I created all the corresponding routes and their method types in the route.rb and subscriptions-route-map.js files.

I created a ruby **payment\_intent controller** and a corresponding route, **the controller should receive a post request from the client and generate a Stripe payment intent based on the data received with the post request, after the payment intent is created it should return the necessary payment instructions to the client**.  
On the client side, I have a small form with a submit button.

**I can’t establish the communication between this controller and the client page (server-client), the fact that there are two controllers( rails and ember) is a bit confusing**.

---

<div class="post-metadata">

**Author:** ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)\
**Post date:** [July 23, 2022, 10:31am UTC](https://meta.discourse.org/t/adding-new-controllers-and-routes-to-discourse-subscriptions-plugin/233704/2 "2022-07-23T10:31:30Z")

</div>

Great progress. As your first foray into Discourse plugin dev, this is definitely ambitious. The upside of that is the sense of achievement and utility you will get once you get this working. The risk you run here is you are biting so much off in one go it might put you off continuing to work on the platform. The Ember/Rails combo is quite a lot to take on, especially initially, keep going!

Some tips for the time being:

- Tackle things in chunks.
- Pushing the fork to GitHub, then permalinking sections of code here might help the community see what you are doing more clearly.
- First worry about the down data from your Rails controller, check that by addressing the rails route with `.json` on the end of the http address to see the raw data that is being passed down to the client. That will prove out the Rails side of the GET.
- Think of the Ember Controller as the module to handle “in interface actions” and stuff that might have to be pushed back up to the back-end (You can handle actions on Routes too, but I digress! :D)
- The Ember Router connects the back-end to the rest of the front end, setting up the model for the Template, it’s Components and/or Controller to consume.
- **Use prior art** , go through all the official and Pavilion plugins on GitHub to see how things are done for similar actions/purposes. It’s all open source, leverage it, copy it, follow the conventions (especially those on Discourse core!)! 🙂

---

<div class="post-metadata">

**Author:** ![martin\_junior\_tchoup](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/martin_junior_tchoup/32/253858_2.png) [@martin\_junior\_tchoup](https://meta.discourse.org/u/martin_junior_tchoup)\
**Post date:** [July 23, 2022, 12:45pm UTC](https://meta.discourse.org/t/adding-new-controllers-and-routes-to-discourse-subscriptions-plugin/233704/3 "2022-07-23T12:45:56Z")

</div>

Thank you, I will follow your advice and keep you informed 🙂

---

<div class="post-metadata">

**Author:** ![martin\_junior\_tchoup](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/martin_junior_tchoup/32/253858_2.png) [@martin\_junior\_tchoup](https://meta.discourse.org/u/martin_junior_tchoup)\
**Post date:** [July 23, 2022, 3:31pm UTC](https://meta.discourse.org/t/adding-new-controllers-and-routes-to-discourse-subscriptions-plugin/233704/4 "2022-07-23T15:31:50Z")

</div>

I have deleted all wath i did yesterday and i have started back from zero. Let me show you what i have already done up till now and the problem(s) i am currently facing. For the moment i don’t really care about editing the /locales .yml files i have hard-coded all the text, and i also decided to use classic html rather than handlebar (I’ll come back to it once I have something that works)

1. **I have added the bank transfer option**  
 ![bktransfer-option](https://global.discourse-cdn.com/meta/original/4X/8/1/a/81a9433d4406289da65b061e8959cc3f15d03245.png)

```plaintext
../discourse-subscriptions/assets/javascripts/discourse/templates/subscribe/show.hbs
<hr>
      <h3>Bank Transfer</h3>
      <form action="/payment_intent" method="post">
       <!-- some data-->
        <input type="submit" value="Next" class="btn btn-primary ">
      </form>
      <hr>

```

1. **I have created a payment\_intent controller**  
../discourse-subscriptions/app/controllers/discourse\_subscriptions/payment\_intents\_controller.rb

```plaintext
module DiscourseSubscriptions
    class PaymentIntentsController < ::ApplicationController
      include DiscourseSubscriptions::Stripe
      include DiscourseSubscriptions::Group
      before_action :set_api_key
      requires_login except: [:index, :contributors, :show]

      def create
        params.require([:source, :plan])
        begin
          #customer = find_or_create_customer(params[:source])
          # create a test payment intent
          bk_payment_intent = Stripe::PaymentIntent.create({
            amount: 1099,
            currency: 'eur'  
          })

          render json: payment_intent
        end
    end
end

```

1. **It’s route**  
../discourse-subscriptions/config/routes.rb

```plaintext
 resources :payment_intents, only: %i[create]

```

**But when i run the project and go to the ember inspector it tells me the route doesn’t exist**

 ![intent error](https://global.discourse-cdn.com/meta/original/4X/8/5/3/8538bb3e3d6f91b45a08cec151c9b64c24f44667.png)

**And after that what would be the best way to handle the form submission ? should i create another ember controller,use the subscribe-show.js controller or add a script tag within the subscribe/show.hbs?**

---

<div class="post-metadata">

**Author:** ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)\
**Post date:** [July 23, 2022, 4:24pm UTC](https://meta.discourse.org/t/adding-new-controllers-and-routes-to-discourse-subscriptions-plugin/233704/5 "2022-07-23T16:24:21Z")

</div>

> [@martin\_junior\_tchoup](#):
>
> should i create another ember controller

You need an Ember route for this screen and an Ember controller. I don’t see one here, so “another”?

Be sure to look at:

[Ember.js Guides - Guides and Tutorials - Ember Guides (emberjs.com)](https://guides.emberjs.com/v3.28.0/)

And take a look at the code for the user preferences screens, which is a basic set of forms.

---

<div class="post-metadata">

**Author:** ![martin\_junior\_tchoup](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/martin_junior_tchoup/32/253858_2.png) [@martin\_junior\_tchoup](https://meta.discourse.org/u/martin_junior_tchoup)\
**Post date:** [July 23, 2022, 8:38pm UTC](https://meta.discourse.org/t/adding-new-controllers-and-routes-to-discourse-subscriptions-plugin/233704/6 "2022-07-23T20:38:12Z")

</div>

Ok. thank you for your reply
