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

Pantera plan and product updates #1099

Merged

Conversation

pantera-stripe
Copy link

@pantera-stripe pantera-stripe commented Feb 8, 2018

Summary
Replacement for @jhoon-stripe's PR: #1068
This PR adds support for an upcoming Stripe API version, released on 2018-02-05. Extends the original PR by adding nickname to StripePlan and type to StripeProduct. Also adds BillingCycleAnchor to StripeSubscription which was also released on 2018-02-05

r? @ob-stripe @brandur-stripe (brandur reviewed original PR)
cc @stripe/api-libraries

@pantera-stripe pantera-stripe changed the title Pantera plan and product updates WIP Pantera plan and product updates Feb 8, 2018
@pantera-stripe pantera-stripe force-pushed the pantera-plan-and-product-updates branch 2 times, most recently from 8ef0147 to 4ab177b Compare February 11, 2018 02:23
@remi-stripe
Copy link
Contributor

@pantera-stripe wanted to flag #1101 to make sure it could be done in the same PR. Let me know if you need help!

@pantera-stripe
Copy link
Author

pantera-stripe commented Feb 12, 2018

@remi-stripe You're right, we're missing that variable. I was about to cargo-cult the code from the create options, but I just realized... it's buggy. (If I'm reading this correctly)

        [JsonProperty("billing_cycle_anchor")]
        internal string BillingCycleAnchorInternal
        {
            get
            {
                if (BillingCycleAnchorNow)
                    return "now";

                if (BillingCycleAnchorUnchanged)
                    return "unchanged";

                return BillingCycleAnchor?.ConvertDateTimeToEpoch().ToString();
            }
        }

If BillingCycleAnchorNow is true it'll send now. If you set both BillingCycleAnchorNow and BillingCycleAnchorUnchanged to true it'll also send now! Yay!

Basically, setting BillingCycleAnchorNow will override either of the other values. I'm fine replicating this not-so-amazing behavior in this PR. But I'd like to push a larger fix off to another PR. I really want to get this reviewed and merged.

@remi-stripe
Copy link
Contributor

@pantera-stripe I'm fine with reproducing the current behaviour. It's not perfect but the alternative would be to either send both and rely on the API error or do an assert or similar to leave early. FWIW we have some logic like this in stripe-go where we make a decision on which one to send first and I think it's okay.

@pantera-stripe pantera-stripe changed the title WIP Pantera plan and product updates Pantera plan and product updates Feb 12, 2018
@pantera-stripe
Copy link
Author

r? @brandur-stripe @remi-stripe

PlanCreateOptions = new StripePlanCreateOptions() {
// Add a space at the end to ensure the ID is properly URL encoded
// when passed in the URL for other methods
Id = "test-plan-" + Guid.NewGuid().ToString() + " ",
Copy link
Contributor

Choose a reason for hiding this comment

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

We likely can skip enforcing the Id here since it's now optional

@@ -11,14 +11,13 @@ public class creating_and_updating_plans : IClassFixture<plans_fixture>

public creating_and_updating_plans(plans_fixture fixture)
{
this.fixture = fixture;
this.fixture = fixture;
Copy link
Contributor

Choose a reason for hiding this comment

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

remove extra space

}

[Fact]
public void created_has_the_right_details()
{
fixture.Plan.Id.Should().Be(fixture.PlanCreateOptions.Id);
fixture.Plan.Name.Should().Be(fixture.PlanCreateOptions.Name);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we test the Nickname property here?

@@ -28,7 +27,6 @@ public void created_has_the_right_details()
public void updated_has_the_right_details()
{
fixture.PlanUpdated.Id.Should().Be(fixture.Plan.Id);
fixture.PlanUpdated.Name.Should().BeEquivalentTo(fixture.PlanUpdateOptions.Name);
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above, we should look at Nickname

@@ -35,10 +35,16 @@ public class StripePlan : StripeEntityWithId
[JsonProperty("name")]
public string Name { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we remove Name completely?

Copy link
Author

Choose a reason for hiding this comment

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

Wouldn't that prevent existing API integrations from upgrading their bindings?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't entirely follow. Anyone who gets that new version of the code will already have to change their integration since it's a new API version and we've added/moved/removed multiple properties.

Name does not exist on the new API version, only Nickname does so Name should go.

This will all be behind a major version

Copy link
Author

Choose a reason for hiding this comment

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

Right, I'm talking the other way. Do merchants ever update their bindings independent of their API version? If not, then I can remove it. But if they do, then updating bindings to this version would eliminate their ability to access Name

Copy link
Contributor

Choose a reason for hiding this comment

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

@pantera-stripe stripe-dotnet enforces an API version for the entire library. There is no way to "choose" an API version. Every user of stripe-dotnet is locked to the API version that the version of the library they use has been built for.

In another part of your PR you are now enforcing 2018-02-06 so every developer who upgrades their integration to that new version of stripe-dotnet will use that version on every API request. So Name will never exist or be set.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah. Totally overlooked that. Will remove.


/// <summary>
/// A sublist of active SKUs associated with this product.
/// </summary>
[JsonProperty("skus")]
public StripeList<StripeSku> Skus { get; set; }

/// <summary>
/// What appears on a customers credit card statement. Max of 22 characters.
Copy link
Contributor

Choose a reason for hiding this comment

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

customer's
I'd also remove the 22 chars mention, better to keep this in the official docs.

public string StatementDescriptor { get; set; }

/// <summary>
/// The type of the Product. Either 'good' or 'service'
Copy link
Contributor

Choose a reason for hiding this comment

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

missing trailing .

[JsonProperty("metadata")]
public Dictionary<string, string> Metadata { get; set; }

[JsonProperty("nickname")]
public string Nickname { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

should be in alphabetical order if we can


namespace Stripe
{
public class StripeProductNestedCreateOptions : INestedOptions
Copy link
Contributor

Choose a reason for hiding this comment

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

Since it's nested under the plan options I think we might want to name it StripePlanProductCreatOptions to indicate the relation.

Not a huge deal though as naming is at best inconsistent in the library today already.

Copy link
Author

Choose a reason for hiding this comment

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

My thought was there is nothing specific about the nesting to plans -- though you're right, that's the only place it's used and probably the only place it'll ever be used.


[JsonProperty("product[statement_descriptor]")]
public string StatementDescriptor { get; set; }
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We should support all options here and not just name and statement_descriptor. The API docs indicate we support id and metadata too.

Copy link
Author

Choose a reason for hiding this comment

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

Good catch.

@pantera-stripe
Copy link
Author

Applied the feedback.

r? @remi-stripe

@remi-stripe
Copy link
Contributor

Looks good to me. I don't like giving the only +1 on PRs though.

r? @ob-stripe

Copy link
Contributor

@ob-stripe ob-stripe left a comment

Choose a reason for hiding this comment

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

LGTM overall, just one comment to address.

public string Nickname { get; set; }

[JsonProperty("product")]
public string ProductId { get; set; }

[JsonProperty("statement_descriptor")]
public string StatementDescriptor { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we remove this property?

Copy link
Author

Choose a reason for hiding this comment

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

Yup. Will remove.

@ob-stripe
Copy link
Contributor

@pantera-stripe LGTM. Mind squashing the commits before I merge?

@pantera-stripe
Copy link
Author

@ob-stripe squashed

@ob-stripe ob-stripe merged commit 8b35fa0 into stripe:master Feb 13, 2018
@pantera-stripe pantera-stripe deleted the pantera-plan-and-product-updates branch February 13, 2018 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants