Activity
Posted in JWT with Devise (App and API)
Hey Stephen, did you see the series on how to build an OAuth Provider in Rails? It integrates with Devise, it will generate JWTs for access tokens if you want, and you can use it with iOS and Android to provide a "Login with My App" process just like Twitter or Facebook which is cool.
Posted in rails generate devise:install hangs
Try running "spring stop" in the new app folder, delete the folder, and then try again. Spring will cache files like that and do weird things.
Sebastian, you can always build custom buttons for Trix to add those features.
Posted in Paypal & Stripe
Hey Brian,
Where's your confusion?
A webhook is sending you some JSON data, so you have to poke around through it to get what you want out (the amount in this case).
Your error says you called amount on a Stripe Subscription which doesn't have an amount, a plan does.
NoMethodError (undefined method `amount' for #Stripe::Subscription:0x00005630b03da5b8)
Print out your event in the terminal or byebug / pry it so you can see what data you've got.
Posted in Paypal & Stripe
You're calling charge.amount on the stripe object you set just before with:
charge = event.data.object
Since that's a Subscription object, you can call methods on it for the attributes it has. This is not your model.
https://stripe.com/docs/api#subscription_object
As you can see, you can ask that object for the plan, and then the plan for the amount.
Posted in Paypal & Stripe
Looks like it doesn't support it directly, it must be nested inside an html key. You can see under the "form_with options" header here: https://api.rubyonrails.org/v5.1/classes/ActionView/Helpers/FormHelper.html#method-i-form_with
Either way, that works fine though. 👍
Posted in Exporting Records To CSV Discussion
Yep, that's pretty normal for very large files. Generate it, store it somewhere that you can link to, and then either send them an email or display it on the website with a link to download. That's pretty standard to what you'd see in other apps.
Posted in Paypal & Stripe
Hey Brian,
So the existing card form shows up but it doesn't hide the new card form? Is that correct?
For some debugging, just print out the results of things like <%= current_user.card_last4? %> to make sure it is true. Then try just adding a simple like style: "background: blue" to your form and make sure you've got that working. Then go swap it out with the conditional version, since you'll probably have discovered what's wrong then.
I love when that happens!
- If you want a fully managed affiliates, then they're going to have to do that. They've got to monitor every new user and charge that comes in to verify they were referrals.
- They're manual at the moment via PayPal (or however you want to pay), but will be automated in the future.
I will be, but I have to split out the products into separate Stripe accounts before I can do that it looks like.
Posted in Paypal & Stripe
Hey Brian,
So for PayPal, I actually use Braintree. I've got it setup so I don't use their form, but rather trigger the PayPal checkout from a link. You can check out the Braintree episode I did on GoRails for that. I am using the Braintree JS v2 still, as it looks like they came out with v3 that doesn't support the same feature.
https://gorails.com/episodes/braintree
It's just a lot easier to integrate with Braintree than it is to use PayPal directly, and PayPal purchased Braintree a few years ago.
The acts_as_list gem has some methods for inserting and moving items in a list. It updates all the values afterward if you were to insert an item at position 2 like you mentioned. You'd need to make those updates in a transaction so it would undo all of them if any one failed.
In fact, you might just want to use that gem. It comes in handy so you don't have to reinvent the wheel on any of that.
Posted in Using Webhooks with Stripe Discussion
It should automatically load that file as long as you named it correctly. class WebhookHandlers::StripeWebhookHandler; end
Posted in Rails Application Templates Discussion
Hmmm, it sounds like Administrate didn't generate a dashboard file for the Announcement model. That's weird.
Posted in Stripe integration on Ruby On Rails
You need to save the new subscription to a variable.
subscription = customer.subscriptions.create(plan: params[:plan])
Posted in Stripe integration on Ruby On Rails
Hey Raphael,
Basically like they said, you'd just create the source rather than passing it in to the subscription
customer = Stripe::Customer.create
customer.sources.create(source: params[:stripeToken])
customer.subscriptions.create(plan: params[:plan])
Posted in Multi tenancy for one type of user
Honestly, the thing that scales best and is easiest to do for just about all "multitenancy" is to just build it at an application level. Use pundit to verify that someone trying to access the vendor section has permissions.
Multitenency is really more for when you absolutely can't have two customer's data in the same database. Think situations like you are dealing HIPAA or something like that where you are collecting very private data.
In most cases, you just want to scope queries and add permissions to separate out parts of your app to specific users. For example, the vendor section you're talking about. If a user is marked as a vendor, then when they visit the vendor area, they only see their products. And if you want to scope it by domain, lookup the domain and verify if the user has permission, if not redirect them to theirs.
Posted in How do I handle this race condition?
Just your standard ActiveJob features: MyJob.set(wait: 30.seconds).perform_later
And in the job, try to find if the file exists, if not, schedule the job again with the same args.
Roughly:
class MyJob < ApplicationJob
def perform(file_id, retry_count=0)
file = lookup_file(file_id)
if file.present?
# process
elsif retry_count < 10 # maximum number of retries
MyJob.set(wait: 30.seconds).perform_later(file_id, retry_count + 1)
end
end
end
Posted in How do I handle this race condition?
Sounds like a terrible webhook lol.
You can always have the webhook schedule a job for 30 seconds in the future or something. If it still can't find it, schedule another job 30 seconds in the future, until it finds it or hits a maximum number of retries.