Skip to content

Conversation

@mickjermsurawong-stripe
Copy link
Contributor

@mickjermsurawong-stripe mickjermsurawong-stripe commented Feb 1, 2019

This is a working branch for autogen-8.0 beta.
cc @stripe/api-libraries

@mickjermsurawong-stripe mickjermsurawong-stripe changed the title Autogen-8.0 beta [wip] Autogen-8.0 beta Feb 1, 2019
@mickjermsurawong-stripe
Copy link
Contributor Author

@remi-stripe the commit started with test:... should correspond to a group of resources affected by breaking changes. Happy to go through them with you to find out any issues I might miss!

@mickjermsurawong-stripe
Copy link
Contributor Author

This is failing now because I rebased on the latest master 7.20 which contain tests for classes that hasn't been generated.. The PR #672 will resolve this and make a parity with 7.20

@mickjermsurawong-stripe mickjermsurawong-stripe force-pushed the autogen/8.0-beta branch 2 times, most recently from c40db5e to 5340c29 Compare February 26, 2019 06:48
@mickjermsurawong-stripe mickjermsurawong-stripe force-pushed the autogen/8.0-beta branch 2 times, most recently from ec2a54d to fa53301 Compare March 15, 2019 21:07
Copy link
Contributor Author

@mickjermsurawong-stripe mickjermsurawong-stripe left a comment

Choose a reason for hiding this comment

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

ptal @brandur-stripe @ob-stripe
I enumerated 18 patterns of API methods encountered in stripe-java generated from sanity check here [0]
I put them in spreadsheet here and randomly manually check the implementations by myself here [1]
I made another random checks (under column in beta-8.0 PR) and annotate them on PR here for ease of review. Please feel free to spotcheck the endpoints in the spreadsheet. There are a few endpoints still to be merged.

[0] https://git.corp.stripe.com/stripe-internal/sdk-autogen-java/pull/46
[1] https://docs.google.com/spreadsheets/d/1Rv-ybR2vXbM9UC26UBOPcnTtqyopic9KTjkrunjjk-w/edit#gid=0

* complete.
*/
public PersonCollection persons(Map<String, Object> params)
public static Account create(Map<String, Object> params, RequestOptions options)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Create (standard): Static method to create a resource

Copy link
Contributor Author

Choose a reason for hiding this comment

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

public static Account create(Map<String, Object> params, RequestOptions options)
throws StripeException {
String url = String.format("%s%s", Stripe.getApiBase(), "/v1/accounts");
return request(ApiResource.RequestMethod.POST, url, params, Account.class, options);
}

* href="#balance_object">balance object</a> details available and pending amounts by source type.
*/
public static PayoutCollection list(Map<String, Object> params, RequestOptions options)
public static Payout create(Map<String, Object> params, RequestOptions options)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Create (standard): Static method to create a resource

Copy link
Contributor Author

Choose a reason for hiding this comment

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

public static Payout create(Map<String, Object> params, RequestOptions options)
throws StripeException {
String url = String.format("%s%s", Stripe.getApiBase(), "/v1/payouts");
return request(ApiResource.RequestMethod.POST, url, params, Payout.class, options);
}

Stripe.getApiBase(), this.getUrl()), params, FeeRefund.class, options);
String url = String.format("%s%s", Stripe.getApiBase(), this.getUrl());
return ApiResource.request(
ApiResource.RequestMethod.POST, url, params, FeeRefund.class, options);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Create (standard): Instance method to create sub-resource on collection already containing ID of the parent resource.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

public FeeRefund create(Map<String, Object> params, RequestOptions options)
throws StripeException {
String url = String.format("%s%s", Stripe.getApiBase(), this.getUrl());
return ApiResource.request(
ApiResource.RequestMethod.POST, url, params, FeeRefund.class, options);
}

*/
public static UsageRecord create(Map<String, Object> params, RequestOptions options)
public static UsageRecord createOnSubscriptionItem(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Create (custom): Static method to create sub-resource on parent resource, taking of parent resource explicitly.
    Contrast this to creating on sub-resource collection relying on the implicit parent resource.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

public static UsageRecord createOnSubscriptionItem(
String subscriptionItem, Map<String, Object> params, RequestOptions options)
throws StripeException {
String url =
String.format(
"%s%s",
Stripe.getApiBase(),
String.format("/v1/subscription_items/%s/usage_records", subscriptionItem));
return request(ApiResource.RequestMethod.POST, url, params, UsageRecord.class, options);
}
}

return request(RequestMethod.GET, singleClassUrl(Balance.class), params, Balance.class,
options);
String url = String.format("%s%s", Stripe.getApiBase(), "/v1/balance");
return request(ApiResource.RequestMethod.GET, url, params, Balance.class, options);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Retrieve (standard): Static method to retrieve a singleton-like resource, taking no ID.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

public static Balance retrieve(Map<String, Object> params, RequestOptions options)
throws StripeException {
String url = String.format("%s%s", Stripe.getApiBase(), "/v1/balance");
return request(ApiResource.RequestMethod.GET, url, params, Balance.class, options);
}

0,
null);
}
return request(ApiResource.RequestMethod.POST, url, params, BankAccount.class, options);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Update (custom): Instance method to update sub-resource having business-logic impact besides mutating the data. Same behavior of relying on instance ID attributes of instance and its parent resource just just like the standard update method on sub-resource.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/** Verify a specified bank account for a given customer. */
public BankAccount verify(Map<String, Object> params, RequestOptions options)
throws StripeException {
String url;
if (this.getCustomer() != null) {
url =
String.format(
"%s%s",
Stripe.getApiBase(),
String.format(
"/v1/customers/%s/sources/%s/verify", this.getCustomer(), this.getId()));
} else {
throw new InvalidRequestException(
"Unable to construct url because [customer] field(s) are all null",
null,
null,
null,
0,
null);
}
return request(ApiResource.RequestMethod.POST, url, params, BankAccount.class, options);
}

String url =
String.format(
"%s%s", Stripe.getApiBase(), String.format("/v1/webhook_endpoints/%s", this.getId()));
return request(ApiResource.RequestMethod.DELETE, url, params, WebhookEndpoint.class, options);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Delete (standard): Instance method to delete a resource on itself, relying on ID attribute of the instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/**
* You can also delete webhook endpoints via the <a
* href="https://dashboard.stripe.com/account/webhooks">webhook endpoint management</a> page of
* the Stripe dashboard.
*/
public WebhookEndpoint delete(Map<String, Object> params, RequestOptions options)
throws StripeException {
String url =
String.format(
"%s%s", Stripe.getApiBase(), String.format("/v1/webhook_endpoints/%s", this.getId()));
return request(ApiResource.RequestMethod.DELETE, url, params, WebhookEndpoint.class, options);
}

0,
null);
}
return request(ApiResource.RequestMethod.DELETE, url, params, Card.class, options);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Delete (standard): Instance method to delete a sub-resource on itself, relying on ID attributes of the instance, and of its parent resource. There is validation on parent resource ID.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/**
* Delete a specified external account for a given account.
*
* <p>Delete a specified source for a given customer.
*/
public Card delete(Map<String, Object> params, RequestOptions options) throws StripeException {
String url;
if (this.getAccount() != null) {
url =
String.format(
"%s%s",
Stripe.getApiBase(),
String.format(
"/v1/accounts/%s/external_accounts/%s", this.getAccount(), this.getId()));
} else if (this.getCustomer() != null) {
url =
String.format(
"%s%s",
Stripe.getApiBase(),
String.format("/v1/customers/%s/sources/%s", this.getCustomer(), this.getId()));
} else {
throw new InvalidRequestException(
"Unable to construct url because [account, customer] field(s) are all null",
null,
null,
null,
0,
null);
}
return request(ApiResource.RequestMethod.DELETE, url, params, Card.class, options);
}

String url =
String.format(
"%s%s", Stripe.getApiBase(), String.format("/v1/customers/%s/discount", this.getId()));
return request(ApiResource.RequestMethod.DELETE, url, params, Discount.class, options);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Delete (custom): Instance method to delete an arbitrary resource relying ID attribute of the instance.
    Method name makes it distinct from standard delete method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/** Removes the currently applied discount on a customer. */
public Discount deleteDiscount(Map<String, Object> params, RequestOptions options)
throws StripeException {
String url =
String.format(
"%s%s", Stripe.getApiBase(), String.format("/v1/customers/%s/discount", this.getId()));
return request(ApiResource.RequestMethod.DELETE, url, params, Discount.class, options);
}

0,
null);
}
return request(ApiResource.RequestMethod.DELETE, url, params, Source.class, options);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Delete (custom): Instance method to delete-like a sub-resource on itself, relying on ID attributes of the instance, and its reference to parent resource. POST should be used instead. Currently one method has this behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/** Delete a specified source for a given customer. */
public Source detach(Map<String, Object> params, RequestOptions options) throws StripeException {
String url;
if (this.getCustomer() != null) {
url =
String.format(
"%s%s",
Stripe.getApiBase(),
String.format("/v1/customers/%s/sources/%s", this.getCustomer(), this.getId()));
} else {
throw new InvalidRequestException(
"Unable to construct url because [customer] field(s) are all null",
null,
null,
null,
0,
null);
}
return request(ApiResource.RequestMethod.DELETE, url, params, Source.class, options);
}

@mickjermsurawong-stripe
Copy link
Contributor Author

Added permalinks there for convenience of review without clicking to view the file

@mickjermsurawong-stripe mickjermsurawong-stripe changed the title [wip] Autogen-8.0 beta Autogen-8.0 beta Mar 18, 2019
@mickjermsurawong-stripe mickjermsurawong-stripe changed the title Autogen-8.0 beta Autogen-8.0 Mar 18, 2019
@tmaxwell-stripe
Copy link

I looked over the snippets of code that you pulled out into comments; they look correct to me.

@ob-stripe
Copy link
Contributor

I've spot-checked a few other random methods, particularly some non-CRUDL methods (charge capture, etc.) and nothing stood out to me either. This looks pretty great!

mickjermsurawong-stripe and others added 23 commits March 19, 2019 12:25
…on mismatch (#664)

* make event data backward compat

* implement versioned data

* rename work

* rename exception

* improve deserializeUnsafeWith

* add comments using static pinned version
test: CardTest ambiguous call with typed param
* extract common deserializer method

extract common logic

* implement ApiParamRequest

add api param request

* Add to base test lenient request params comparison for list/array int/long comparison

* use List<Object> instead of Object[] in untyped deserializer

* provide documentation to deserializer and api request param

* reorder import statments

* fix other imports in new files
* [generated] source: spec3.sdk.yaml@non-master-spec-e27a05e in mickjermsurawong/no-v-change

* [generated] source: spec3.sdk.yaml@spec-82bb471 in master

* [generated] source: spec3.sdk.yaml@spec-3869a7f in master

* [generated] source: spec3.sdk.yaml@non-master-spec-02ef86a in mickjermsurawong/undoc-sensitive-enum
@mickjermsurawong-stripe
Copy link
Contributor Author

mickjermsurawong-stripe commented Mar 19, 2019

thank you @remi-stripe @ob-stripe @tmaxwell-stripe @brandur-stripe !
I'm self-approving here because I suspect it'll be hard for anyone to say this is good overall without looking at all the code, and it's impossible so..

  • I've done manual review and spot-check and surfaced the different patterns.
  • I made sure that no tests are unnecessarily removed, and all of them are passing now
  • There's breaking changes diff have been reviewed..
  • Updated the lib to have pin api version

@rattrayalex-stripe
Copy link
Contributor

LGTM

I trust you, Mick 😄

@mickjermsurawong-stripe mickjermsurawong-stripe merged commit 80e8487 into master Mar 19, 2019
@mickjermsurawong-stripe mickjermsurawong-stripe deleted the autogen/8.0-beta branch March 29, 2019 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants