-
-
Notifications
You must be signed in to change notification settings - Fork 293
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
Paddle payment provider #165
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2935435
Add Paddle payment provider
nm 0efae77
Merge branch 'master' into paddle
nm 74ea6be
Add paddle public key to ci.yml
nm afe66d7
Merge branch 'master' into paddle
excid3 448cd8f
Merge branch 'master' into paddle
excid3 eba2b42
Fix subscription created webhook and add readme improvement
nm 8924772
Merge branch 'master' into paddle
nm 31bd669
Merge branch 'paddle' of https://github.com/nm/pay into paddle
nm 49debeb
Merge branch 'master' into paddle
excid3 767611b
Store paddle public key for tests in separate file
nm 00bfbd6
Use Signed GlobalID in paddle passthrough parameter
nm cd43cfe
Standardize
nm 7c31b55
Update readme
nm 44e37d5
Merge branch 'master' into paddle
excid3 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module Pay | ||
module Webhooks | ||
class PaddleController < Pay::ApplicationController | ||
if Rails.application.config.action_controller.default_protect_from_forgery | ||
skip_before_action :verify_authenticity_token | ||
end | ||
|
||
def create | ||
verifier = Pay::Paddle::Webhooks::SignatureVerifier.new(check_params.as_json) | ||
if verifier.verify | ||
case params["alert_name"] | ||
when "subscription_created" | ||
Pay::Paddle::Webhooks::SubscriptionCreated.new(check_params.as_json) | ||
when "subscription_updated" | ||
Pay::Paddle::Webhooks::SubscriptionUpdated.new(check_params.as_json) | ||
when "subscription_cancelled" | ||
Pay::Paddle::Webhooks::SubscriptionCancelled.new(check_params.as_json) | ||
when "subscription_payment_succeeded" | ||
Pay::Paddle::Webhooks::SubscriptionPaymentSucceeded.new(check_params.as_json) | ||
when "subscription_payment_refunded" | ||
Pay::Paddle::Webhooks::SubscriptionPaymentRefunded.new(check_params.as_json) | ||
end | ||
render json: {success: true}, status: :ok | ||
excid3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
else | ||
head :ok | ||
end | ||
end | ||
|
||
private | ||
|
||
def check_params | ||
params.except(:action, :controller).permit! | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Alternatively, if using the paddle button:
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.
Is this secure? I could change the model and ID to anything.
Seems like we should do a signed GlobalID or something instead that we could verify server-side.
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.
Yes, you're right. That would allow to pay for another owner id or owner type. I changed it and now a signed GlobalID is used. In addition, a purpose string ensures that GlobalIDs cannot be swapped between Paddle products.
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.
Since this is received by the webhook for the subscription, I think the
for:
is probably unnecessary?If so, we can remove it and simplify a little bit which is nice.
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.
It depends: If you can create subscriptions for multiple owner types in your app or signed global IDs are made public otherwise, the
for:
would be necessary to prevent swapping the SGID in the javascript code.How likely is such a scenario? Probably not very likely. To be honest: If I pay for a subscription I am not interesting in changing the owner. That is the reason I just used
owner_type
andowner_id
in the beginning. I don't know, maybe using SGIDs withoutfor:
is a good tradeoff between simplicity and security. What do you think?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.
At least with an SGID, they could only swap SGIDs they had access to since it'd have to be generated server side. That'd leave it only to accounts they have access to.
If it was clear text, it's easy to tamper with. To be fair, you wouldn't want to pay for something and get it assigned to someone else, so it seems illogical to tamper with.
Maybe I'll build a helper to generate the passthrough JSON.