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

Fix Plan and InputPlan fields #41

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

stewSquared
Copy link

This resolves #40

WIP: I still need to add unit and integration tests, but this implements the basic approach.

x.statementDescriptor,
x.trialPeriodDays))

sealed abstract class Product
Copy link
Author

Choose a reason for hiding this comment

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

From the documentation:

product: The product whose pricing the created plan will represent. This can either be the ID of an existing product, or a dictionary containing fields used to create a service product.

The names for the two sub classes, ProductId and ServiceProduct from the names of the two italicized phrases, but I'm happy to shorten them if that would be more consistent with the rest of the names.

* @param intervalCount The number of intervals (specified in the [[interval]]
* property) between each subscription billing. For example,
* \[[interval]]=[[Interval.Month]] and [[intervalCount]]=3
* bills every 3 months.
* @param livemode
* @param name Display name of the plan
Copy link
Author

Choose a reason for hiding this comment

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

There was no name parameter for plan, but it's child object had a name parameter for the service product.

@stewSquared stewSquared force-pushed the fix-plan-parameters branch from f2e4b60 to fea9039 Compare March 20, 2018 02:56
"statement_descriptor" -> service.statementDescriptor
)
)
mapToPostParams(Option(params ++ mapToPostParams(service.metadata, "metadata")), "product")
Copy link
Author

@stewSquared stewSquared Mar 20, 2018

Choose a reason for hiding this comment

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

This was a little bit tricky to work out.
Akka HTP already includes a FormData class that seems relevant here. Might that make handling all these nested maps a bit simpler?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, we used to use unfiltered and switch to akka http that's why we are not using it.

Personally, I'm not particularly taken with akka http so I would not want to increase our dependency on it.

@stewSquared
Copy link
Author

It seems like the integration tests were failing before this PR. Was someone else already investigating that? https://travis-ci.org/mdedetrich/stripe-scala/jobs/355675799

@stewSquared
Copy link
Author

Ugh. I just realized the fixes I'm making here are only necessary because of a very recent Major change in the stripe API: https://stripe.com/docs/upgrades#2018-02-05

I suspect I'm seeing the integration tests on master fail for a similar reason.

@mdedetrich What version is the Stripe test account in CI tied to? Is it configurable?

@leonardehrenfried
Copy link
Collaborator

Ok, so the integration tests don't work on pull requests because the secret API token is required.

If you want to run them, you need a set the env variable STRIPE_TOKEN. If you don't want create a project yourself, you can contact me and I will send you the token.

Regarding the test project version: it is set to a version from 2016. This could be changed but ideally we should be setting the Stripe-Version header with every request. I wanted to implement this (see #21) but never got around to it.

Why do we need this? You can set a project version in Stripe itself but can override that for every request. To me, hardcoding the version stripe-scala expects would be the only sane way forward.

See https://stripe.com/docs/upgrades

If you want to fix this problem too, @stewSquared, it would be most appreciated.

@stewSquared
Copy link
Author

@leonardehrenfried I do have a Stripe API key that I'm using locally. It fails for me on master, so I'm guessing my key is for a newer version of the API (I get Missing required param: type.). Would you mind sending the test key you use to my email? [email protected]

As for the Stripe-Version header, I totally agree. Setting the version explicitly is the sane way to go, especially for a library. How about I submit an implementation that sets it via an implicit StripeVersion the same way we handle ApiKey and EndPoint? We could put a default in Config that corresponds to whatever the library is written against.

On that note, should this library perhaps have branches for breaking changes like this? This is still a fairly recent change from Stripe.

@leonardehrenfried
Copy link
Collaborator

leonardehrenfried commented Mar 21, 2018

Creating an implicit version is a great idea although I don't think it needs to be too configurable since there isn't an easy way to switch between the version. The expected properties aren't so easily changed in the code.

If we had lots of people working on the different branches I would agree, but as it is it would make an already thinly-"staffed" project harder to maintain.

I believe it's more practical if we just add table to the readme that says that version X of stripe-scala is hardcoded to use version Z of the Stripe API. People can change the version config but it's likely that this will not work.

Or are you interested in maintaining and updating these branches?

@stewSquared
Copy link
Author

Right, a table in the README make much more sense. Someone could always fork off of an older version if they need to patch it.

@leonardehrenfried
Copy link
Collaborator

leonardehrenfried commented Mar 21, 2018

I've sent you the API key. I've also checked the default version of the test project and it's 2016-10-19.

I suggest you set the hardcoded version to something very recent. In that case a few integration tests will fail (I believe there have been some renamings in the area of transfers, which are now called payouts). But that shouldn't be very arduous to clean up as Stripe doesn't change stuff that often.

If you need a hand, I'm happy to help.

Maybe the solution to the failing integration tests would be to not run them for PRs. They can't work as they don't have an API key.

Another alternative would be to just publish the API key - it's a dummy project with no real data anyway, but I'm still a bit nervous about that option.

WDYT?

@stewSquared
Copy link
Author

Hmm. Publishing even the test key makes me nervous too. How about setting it in travis as an encryted environmental variable in travis? https://docs.travis-ci.com/user/environment-variables/#Defining-Variables-in-Repository-Settings

@leonardehrenfried
Copy link
Collaborator

It is an encrypted variable but that doesn't work for pull requests since that would make it essentially public. Anyone could trivially create a PR that reads and prints the secret value.

@stewSquared
Copy link
Author

Oh, right! Good point. I suppose we don't run integration tests for PRs then. It's not too much hassle to run the tests locally before merging, is it?

I just confirmed this PR passes (none of the tests touch plans/subscriptions)

@leonardehrenfried
Copy link
Collaborator

Are you planning on adding a few tests to this PR, unit or integration ones?

@leonardehrenfried
Copy link
Collaborator

We don't get that many contributions so running them before merging isn't going to be too annoying.

@mdedetrich
Copy link
Owner

Is everything good for the PR, or?

@stewSquared
Copy link
Author

stewSquared commented Mar 23, 2018 via email

@mdedetrich
Copy link
Owner

No worries, just ping us when you are done

@mdedetrich
Copy link
Owner

@stewSquared I would rebase against master as another pr was just merged there

@stewSquared
Copy link
Author

@mdedetrich Sure thing!
I have a bit more time now, so I'll dig back in to this PR tomorrow.

@stewSquared stewSquared force-pushed the fix-plan-parameters branch from fea9039 to b6334a3 Compare April 3, 2018 06:14
@stewSquared
Copy link
Author

stewSquared commented Apr 3, 2018

After rebasing on #43, I get sbt dependency resolution errors:

[error] (*:update) sbt.ResolveException: unresolved dependency: com.thoughtworks.sbt-api-mappings#sbt-api-mappings;2.0.0: not found

@leonardehrenfried
Copy link
Collaborator

leonardehrenfried commented Apr 3, 2018 via email

@stewSquared
Copy link
Author

@leonardehrenfried I did push my state after rebasing.
But, as it happens I must have just been seeing anything temporary. The build loads fine now.

@leonardehrenfried
Copy link
Collaborator

The scala 2.11 build fails because of some missing Either-related compatibility code.

Can you import cats.syntax.either._?

@stewSquared
Copy link
Author

Oh, I didn't notice the cross build. I'll fix it for 2.11 in a moment.

Thanks for being patient with this PR. I've blocked out a calendar slot so I can commit to finishing touches on this PR.

@stewSquared stewSquared force-pushed the fix-plan-parameters branch from b6334a3 to 29dd366 Compare April 4, 2018 09:26
@dwene
Copy link

dwene commented Apr 21, 2018

Any chance this will merge soon?

@leonardehrenfried
Copy link
Collaborator

This is currently wip, @stewSquared needs to give us the green light when he's ready.

@mdedetrich
Copy link
Owner

@stewSquared Any update on this?

@stewSquared
Copy link
Author

@mdedetrich Hi! I almost forgot about this. I'm using Stripe again, so I'll do some testing and update this ticket. It might need a rebase or a new PR

@mdedetrich
Copy link
Owner

@stewSquared No worries, it might need a big rebase though

@mdedetrich
Copy link
Owner

@stewSquared I have just updated master with some QoL fixes (i.e. applying new scalafmt, making case class final as well as using the Some constructor) so you will probably have to rebase your branch, I don't think the conflicts should be too bad (just remember to use scalafmt before committing)

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.

Plans.create has incorrect parameters
4 participants