Skip to content

Add support for the Payout Reverse API #1129

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

Merged
merged 2 commits into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ before_install:
env:
global:
# If changing this number, please also change it in `BaseStripeTest.java`.
- STRIPE_MOCK_VERSION=0.99.0
- STRIPE_MOCK_VERSION=0.101.0

matrix:
include:
Expand Down
137 changes: 137 additions & 0 deletions src/main/java/com/stripe/model/Payout.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.stripe.param.PayoutCreateParams;
import com.stripe.param.PayoutListParams;
import com.stripe.param.PayoutRetrieveParams;
import com.stripe.param.PayoutReverseParams;
import com.stripe.param.PayoutUpdateParams;
import java.util.Map;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -129,6 +130,18 @@ public class Payout extends ApiResource implements MetadataStore<Payout>, Balanc
@SerializedName("object")
String object;

/** If the payout reverses another, this is the ID of the original payout. */
@SerializedName("original_payout")
@Getter(lombok.AccessLevel.NONE)
@Setter(lombok.AccessLevel.NONE)
ExpandableField<Payout> originalPayout;

/** If the payout was reversed, this is the ID of the payout that reverses this payout. */
@SerializedName("reversed_by")
@Getter(lombok.AccessLevel.NONE)
@Setter(lombok.AccessLevel.NONE)
ExpandableField<Payout> reversedBy;

/**
* The source balance this payout came from. One of {@code card}, {@code fpx}, or {@code
* bank_account}.
Expand Down Expand Up @@ -214,6 +227,42 @@ public void setFailureBalanceTransactionObject(BalanceTransaction expandableObje
new ExpandableField<BalanceTransaction>(expandableObject.getId(), expandableObject);
}

/** Get ID of expandable {@code originalPayout} object. */
public String getOriginalPayout() {
return (this.originalPayout != null) ? this.originalPayout.getId() : null;
}

public void setOriginalPayout(String id) {
this.originalPayout = ApiResource.setExpandableFieldId(id, this.originalPayout);
}

/** Get expanded {@code originalPayout}. */
public Payout getOriginalPayoutObject() {
return (this.originalPayout != null) ? this.originalPayout.getExpanded() : null;
}

public void setOriginalPayoutObject(Payout expandableObject) {
this.originalPayout = new ExpandableField<Payout>(expandableObject.getId(), expandableObject);
}

/** Get ID of expandable {@code reversedBy} object. */
public String getReversedBy() {
return (this.reversedBy != null) ? this.reversedBy.getId() : null;
}

public void setReversedBy(String id) {
this.reversedBy = ApiResource.setExpandableFieldId(id, this.reversedBy);
}

/** Get expanded {@code reversedBy}. */
public Payout getReversedByObject() {
return (this.reversedBy != null) ? this.reversedBy.getExpanded() : null;
}

public void setReversedByObject(Payout expandableObject) {
this.reversedBy = new ExpandableField<Payout>(expandableObject.getId(), expandableObject);
}

/**
* Retrieves the details of an existing payout. Supply the unique payout ID from either a payout
* creation request or the payout list, and Stripe will return the corresponding payout
Expand Down Expand Up @@ -473,4 +522,92 @@ public Payout cancel(PayoutCancelParams params, RequestOptions options) throws S
String.format("/v1/payouts/%s/cancel", ApiResource.urlEncodeId(this.getId())));
return ApiResource.request(ApiResource.RequestMethod.POST, url, params, Payout.class, options);
}

/**
* Reverses a payout by debiting the destination bank account. Only payouts for connected accounts
* to US bank accounts may be reversed at this time. If the payout is in the <code>pending</code>
* status, <code>/v1/payouts/:id/cancel</code> should be used instead.
*
* <p>By requesting a reversal via <code>/v1/payouts/:id/reverse</code>, you confirm that the
* authorized signatory of the selected bank account has authorized the debit on the bank account
* and that no other authorization is required.
*/
public Payout reverse() throws StripeException {
return reverse((Map<String, Object>) null, (RequestOptions) null);
}

/**
* Reverses a payout by debiting the destination bank account. Only payouts for connected accounts
* to US bank accounts may be reversed at this time. If the payout is in the <code>pending</code>
* status, <code>/v1/payouts/:id/cancel</code> should be used instead.
*
* <p>By requesting a reversal via <code>/v1/payouts/:id/reverse</code>, you confirm that the
* authorized signatory of the selected bank account has authorized the debit on the bank account
* and that no other authorization is required.
*/
public Payout reverse(RequestOptions options) throws StripeException {
return reverse((Map<String, Object>) null, options);
}

/**
* Reverses a payout by debiting the destination bank account. Only payouts for connected accounts
* to US bank accounts may be reversed at this time. If the payout is in the <code>pending</code>
* status, <code>/v1/payouts/:id/cancel</code> should be used instead.
*
* <p>By requesting a reversal via <code>/v1/payouts/:id/reverse</code>, you confirm that the
* authorized signatory of the selected bank account has authorized the debit on the bank account
* and that no other authorization is required.
*/
public Payout reverse(Map<String, Object> params) throws StripeException {
return reverse(params, (RequestOptions) null);
}

/**
* Reverses a payout by debiting the destination bank account. Only payouts for connected accounts
* to US bank accounts may be reversed at this time. If the payout is in the <code>pending</code>
* status, <code>/v1/payouts/:id/cancel</code> should be used instead.
*
* <p>By requesting a reversal via <code>/v1/payouts/:id/reverse</code>, you confirm that the
* authorized signatory of the selected bank account has authorized the debit on the bank account
* and that no other authorization is required.
*/
public Payout reverse(Map<String, Object> params, RequestOptions options) throws StripeException {
String url =
String.format(
"%s%s",
Stripe.getApiBase(),
String.format("/v1/payouts/%s/reverse", ApiResource.urlEncodeId(this.getId())));
return ApiResource.request(ApiResource.RequestMethod.POST, url, params, Payout.class, options);
}

/**
* Reverses a payout by debiting the destination bank account. Only payouts for connected accounts
* to US bank accounts may be reversed at this time. If the payout is in the <code>pending</code>
* status, <code>/v1/payouts/:id/cancel</code> should be used instead.
*
* <p>By requesting a reversal via <code>/v1/payouts/:id/reverse</code>, you confirm that the
* authorized signatory of the selected bank account has authorized the debit on the bank account
* and that no other authorization is required.
*/
public Payout reverse(PayoutReverseParams params) throws StripeException {
return reverse(params, (RequestOptions) null);
}

/**
* Reverses a payout by debiting the destination bank account. Only payouts for connected accounts
* to US bank accounts may be reversed at this time. If the payout is in the <code>pending</code>
* status, <code>/v1/payouts/:id/cancel</code> should be used instead.
*
* <p>By requesting a reversal via <code>/v1/payouts/:id/reverse</code>, you confirm that the
* authorized signatory of the selected bank account has authorized the debit on the bank account
* and that no other authorization is required.
*/
public Payout reverse(PayoutReverseParams params, RequestOptions options) throws StripeException {
String url =
String.format(
"%s%s",
Stripe.getApiBase(),
String.format("/v1/payouts/%s/reverse", ApiResource.urlEncodeId(this.getId())));
return ApiResource.request(ApiResource.RequestMethod.POST, url, params, Payout.class, options);
}
}
137 changes: 137 additions & 0 deletions src/main/java/com/stripe/param/PayoutReverseParams.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// File generated from our OpenAPI spec
package com.stripe.param;

import com.google.gson.annotations.SerializedName;
import com.stripe.net.ApiRequestParams;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.Getter;

@Getter
public class PayoutReverseParams extends ApiRequestParams {
/** Specifies which fields in the response should be expanded. */
@SerializedName("expand")
List<String> expand;

/**
* Map of extra parameters for custom features not available in this client library. The content
* in this map is not serialized under this field's {@code @SerializedName} value. Instead, each
* key/value pair is serialized as if the key is a root-level field (serialized) name in this
* param object. Effectively, this map is flattened to its parent instance.
*/
@SerializedName(ApiRequestParams.EXTRA_PARAMS_KEY)
Map<String, Object> extraParams;

/**
* Set of <a href="https://stripe.com/docs/api/metadata">key-value pairs</a> that you can attach
* to an object. This can be useful for storing additional information about the object in a
* structured format. Individual keys can be unset by posting an empty value to them. All keys can
* be unset by posting an empty value to {@code metadata}.
*/
@SerializedName("metadata")
Map<String, String> metadata;

private PayoutReverseParams(
List<String> expand, Map<String, Object> extraParams, Map<String, String> metadata) {
this.expand = expand;
this.extraParams = extraParams;
this.metadata = metadata;
}

public static Builder builder() {
return new Builder();
}

public static class Builder {
private List<String> expand;

private Map<String, Object> extraParams;

private Map<String, String> metadata;

/** Finalize and obtain parameter instance from this builder. */
public PayoutReverseParams build() {
return new PayoutReverseParams(this.expand, this.extraParams, this.metadata);
}

/**
* Add an element to `expand` list. A list is initialized for the first `add/addAll` call, and
* subsequent calls adds additional elements to the original list. See {@link
* PayoutReverseParams#expand} for the field documentation.
*/
public Builder addExpand(String element) {
if (this.expand == null) {
this.expand = new ArrayList<>();
}
this.expand.add(element);
return this;
}

/**
* Add all elements to `expand` list. A list is initialized for the first `add/addAll` call, and
* subsequent calls adds additional elements to the original list. See {@link
* PayoutReverseParams#expand} for the field documentation.
*/
public Builder addAllExpand(List<String> elements) {
if (this.expand == null) {
this.expand = new ArrayList<>();
}
this.expand.addAll(elements);
return this;
}

/**
* Add a key/value pair to `extraParams` map. A map is initialized for the first `put/putAll`
* call, and subsequent calls add additional key/value pairs to the original map. See {@link
* PayoutReverseParams#extraParams} for the field documentation.
*/
public Builder putExtraParam(String key, Object value) {
if (this.extraParams == null) {
this.extraParams = new HashMap<>();
}
this.extraParams.put(key, value);
return this;
}

/**
* Add all map key/value pairs to `extraParams` map. A map is initialized for the first
* `put/putAll` call, and subsequent calls add additional key/value pairs to the original map.
* See {@link PayoutReverseParams#extraParams} for the field documentation.
*/
public Builder putAllExtraParam(Map<String, Object> map) {
if (this.extraParams == null) {
this.extraParams = new HashMap<>();
}
this.extraParams.putAll(map);
return this;
}

/**
* Add a key/value pair to `metadata` map. A map is initialized for the first `put/putAll` call,
* and subsequent calls add additional key/value pairs to the original map. See {@link
* PayoutReverseParams#metadata} for the field documentation.
*/
public Builder putMetadata(String key, String value) {
if (this.metadata == null) {
this.metadata = new HashMap<>();
}
this.metadata.put(key, value);
return this;
}

/**
* Add all map key/value pairs to `metadata` map. A map is initialized for the first
* `put/putAll` call, and subsequent calls add additional key/value pairs to the original map.
* See {@link PayoutReverseParams#metadata} for the field documentation.
*/
public Builder putAllMetadata(Map<String, String> map) {
if (this.metadata == null) {
this.metadata = new HashMap<>();
}
this.metadata.putAll(map);
return this;
}
}
}
2 changes: 1 addition & 1 deletion src/test/java/com/stripe/BaseStripeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

public class BaseStripeTest {
// If changing this number, please also change it in `.travis.yml`.
private static final String MOCK_MINIMUM_VERSION = "0.99.0";
private static final String MOCK_MINIMUM_VERSION = "0.101.0";

private static String port;

Expand Down
11 changes: 11 additions & 0 deletions src/test/java/com/stripe/functional/PayoutTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,15 @@ public void testCancel() throws StripeException {
verifyRequest(
ApiResource.RequestMethod.POST, String.format("/v1/payouts/%s/cancel", resource.getId()));
}

@Test
public void testReverse() throws StripeException {
final Payout resource = getPayoutFixture();

final Payout reversedPayout = resource.reverse();

assertNotNull(reversedPayout);
verifyRequest(
ApiResource.RequestMethod.POST, String.format("/v1/payouts/%s/reverse", resource.getId()));
}
}