-
Notifications
You must be signed in to change notification settings - Fork 368
Add support for the payment_intent resource #543
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,311 @@ | ||
package com.stripe.model; | ||
|
||
import com.stripe.exception.APIConnectionException; | ||
import com.stripe.exception.APIException; | ||
import com.stripe.exception.AuthenticationException; | ||
import com.stripe.exception.CardException; | ||
import com.stripe.exception.InvalidRequestException; | ||
import com.stripe.net.APIResource; | ||
import com.stripe.net.RequestOptions; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@EqualsAndHashCode(callSuper = false) | ||
public class PaymentIntent extends APIResource implements MetadataStore<PaymentIntent>, HasId { | ||
@Getter(onMethod = @__({@Override})) String id; | ||
String object; | ||
List<String> allowedSourceTypes; | ||
Long amount; | ||
Long amountCapturable; | ||
Long amountReceived; | ||
@Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE) ExpandableField<Application> application; | ||
Long applicationFee; | ||
Long canceledAt; | ||
String captureMethod; | ||
ChargeCollection charges; | ||
String clientSecret; | ||
String confirmationMethod; | ||
Long created; | ||
String currency; | ||
@Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE) ExpandableField<Customer> customer; | ||
Boolean livemode; | ||
@Getter(onMethod = @__({@Override})) Map<String, String> metadata; | ||
PaymentIntentSourceAction nextSourceAction; | ||
@Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE) ExpandableField<Account> onBehalfOf; | ||
String receiptEmail; | ||
String returnUrl; | ||
ShippingDetails shipping; | ||
@Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE) ExpandableField<ExternalAccount> source; | ||
String statementDescriptor; | ||
PaymentIntentTransferData transferData; | ||
String status; | ||
|
||
// <editor-fold desc="application"> | ||
public String getApplication() { | ||
return (this.application != null) ? this.application.getId() : null; | ||
} | ||
|
||
public void setApplication(String applicationId) { | ||
this.application = setExpandableFieldID(applicationId, this.application); | ||
} | ||
|
||
public Application getApplicationObject() { | ||
return (this.application != null) ? this.application.getExpanded() : null; | ||
} | ||
|
||
public void setApplicationObject(Application c) { | ||
this.application = new ExpandableField<Application>(c.getId(), c); | ||
} | ||
// </editor-fold> | ||
|
||
// <editor-fold desc="customer"> | ||
public String getCustomer() { | ||
return (this.customer != null) ? this.customer.getId() : null; | ||
} | ||
|
||
public void setCustomer(String customerId) { | ||
this.customer = setExpandableFieldID(customerId, this.customer); | ||
|
||
} | ||
|
||
public Customer getCustomerObject() { | ||
return (this.customer != null) ? this.customer.getExpanded() : null; | ||
} | ||
|
||
public void setCustomerObject(Customer c) { | ||
this.customer = new ExpandableField<Customer>(c.getId(), c); | ||
} | ||
// </editor-fold> | ||
|
||
// <editor-fold desc="onBehalfOf"> | ||
public String getOnBehalfOf() { | ||
return (this.onBehalfOf != null) ? this.onBehalfOf.getId() : null; | ||
} | ||
|
||
public void setOnBehalfOf(String onBehalfOfId) { | ||
this.onBehalfOf = APIResource.setExpandableFieldID(onBehalfOfId, this.onBehalfOf); | ||
} | ||
|
||
public Account getOnBehalfOfObject() { | ||
return (this.onBehalfOf != null) ? this.onBehalfOf.getExpanded() : null; | ||
} | ||
|
||
public void setOnBehalfOfObject(Account c) { | ||
this.onBehalfOf = new ExpandableField<Account>(c.getId(), c); | ||
} | ||
// </editor-fold> | ||
|
||
// <editor-fold desc="source"> | ||
public String getSource() { | ||
return (this.source != null) ? this.source.getId() : null; | ||
} | ||
|
||
public void setSource(String sourceId) { | ||
this.source = APIResource.setExpandableFieldID(sourceId, this.source); | ||
} | ||
|
||
public ExternalAccount getSourceObject() { | ||
return (this.source != null) ? this.source.getExpanded() : null; | ||
} | ||
|
||
public void setSourceObject(ExternalAccount c) { | ||
this.source = new ExpandableField<ExternalAccount>(c.getId(), c); | ||
} | ||
// </editor-fold> | ||
|
||
// <editor-fold desc="cancel"> | ||
/** | ||
* Cancel a payment intent. | ||
*/ | ||
public PaymentIntent cancel() | ||
throws AuthenticationException, InvalidRequestException, | ||
APIConnectionException, CardException, APIException { | ||
return cancel(null, null); | ||
} | ||
|
||
/** | ||
* Cancel a payment intent. | ||
*/ | ||
public PaymentIntent cancel(Map<String, Object> params) | ||
throws AuthenticationException, InvalidRequestException, | ||
APIConnectionException, CardException, APIException { | ||
return cancel(params, null); | ||
} | ||
|
||
/** | ||
* Cancel a payment intent. | ||
*/ | ||
public PaymentIntent cancel(Map<String, Object> params, RequestOptions options) | ||
throws AuthenticationException, InvalidRequestException, | ||
APIConnectionException, CardException, APIException { | ||
return request(RequestMethod.POST, instanceURL(PaymentIntent.class, this.id) + "/cancel", | ||
params, PaymentIntent.class, options); | ||
} | ||
// </editor-fold> | ||
|
||
// <editor-fold desc="capture"> | ||
/** | ||
* Capture a payment intent. | ||
*/ | ||
public PaymentIntent capture() | ||
throws AuthenticationException, InvalidRequestException, | ||
APIConnectionException, CardException, APIException { | ||
return capture(null, null); | ||
} | ||
|
||
/** | ||
* Capture a payment intent. | ||
*/ | ||
public PaymentIntent capture(Map<String, Object> params) | ||
throws AuthenticationException, InvalidRequestException, | ||
APIConnectionException, CardException, APIException { | ||
return capture(params, null); | ||
} | ||
|
||
/** | ||
* Capture a payment intent. | ||
*/ | ||
public PaymentIntent capture(Map<String, Object> params, RequestOptions options) | ||
throws AuthenticationException, InvalidRequestException, | ||
APIConnectionException, CardException, APIException { | ||
return request(RequestMethod.POST, instanceURL(PaymentIntent.class, this.id) + "/capture", | ||
params, PaymentIntent.class, options); | ||
} | ||
// </editor-fold> | ||
|
||
// <editor-fold desc="confirm"> | ||
/** | ||
* Confirm a payment intent. | ||
*/ | ||
public PaymentIntent confirm() | ||
throws AuthenticationException, InvalidRequestException, | ||
APIConnectionException, CardException, APIException { | ||
return confirm(null, null); | ||
} | ||
|
||
/** | ||
* Confirm a payment intent. | ||
*/ | ||
public PaymentIntent confirm(Map<String, Object> params) | ||
throws AuthenticationException, InvalidRequestException, | ||
APIConnectionException, CardException, APIException { | ||
return confirm(params, null); | ||
} | ||
|
||
/** | ||
* Confirm a payment intent. | ||
*/ | ||
public PaymentIntent confirm(Map<String, Object> params, RequestOptions options) | ||
throws AuthenticationException, InvalidRequestException, | ||
APIConnectionException, CardException, APIException { | ||
return request(RequestMethod.POST, instanceURL(PaymentIntent.class, this.id) + "/confirm", | ||
params, PaymentIntent.class, options); | ||
} | ||
// </editor-fold> | ||
|
||
// <editor-fold desc="create"> | ||
/** | ||
* Create a payment intent. | ||
*/ | ||
public static PaymentIntent create(Map<String, Object> params) | ||
throws AuthenticationException, InvalidRequestException, | ||
APIConnectionException, CardException, APIException { | ||
return create(params, null); | ||
} | ||
|
||
/** | ||
* Create a payment intent. | ||
*/ | ||
public static PaymentIntent create(Map<String, Object> params, RequestOptions options) | ||
throws AuthenticationException, InvalidRequestException, | ||
APIConnectionException, CardException, APIException { | ||
return request(RequestMethod.POST, classURL(PaymentIntent.class), params, | ||
PaymentIntent.class, options); | ||
} | ||
// </editor-fold> | ||
|
||
// <editor-fold desc="list"> | ||
/** | ||
* List all payment intents. | ||
*/ | ||
public static PaymentIntentCollection list(Map<String, Object> params) | ||
throws AuthenticationException, InvalidRequestException, | ||
APIConnectionException, CardException, APIException { | ||
return list(params, null); | ||
} | ||
|
||
/** | ||
* List all payment intents. | ||
*/ | ||
public static PaymentIntentCollection list(Map<String, Object> params, RequestOptions options) | ||
throws AuthenticationException, InvalidRequestException, APIConnectionException, | ||
CardException, APIException { | ||
return requestCollection(classURL(PaymentIntent.class), params, | ||
PaymentIntentCollection.class, options); | ||
} | ||
// </editor-fold> | ||
|
||
// <editor-fold desc="retrieve"> | ||
/** | ||
* Retrieve a payment intent. | ||
*/ | ||
public static PaymentIntent retrieve(String id) throws AuthenticationException, | ||
InvalidRequestException, APIConnectionException, CardException, | ||
APIException { | ||
return retrieve(id, null); | ||
} | ||
|
||
/** | ||
* Retrieve a payment intent. | ||
*/ | ||
public static PaymentIntent retrieve(String id, RequestOptions options) | ||
throws AuthenticationException, InvalidRequestException, | ||
APIConnectionException, CardException, APIException { | ||
return request(RequestMethod.GET, instanceURL(PaymentIntent.class, id), null, | ||
PaymentIntent.class, options); | ||
} | ||
|
||
/** | ||
* Retrieve a payment intent. | ||
*/ | ||
public static PaymentIntent retrieve(String id, Map<String, Object> params, | ||
RequestOptions options) | ||
throws AuthenticationException, InvalidRequestException, | ||
APIConnectionException, CardException, APIException { | ||
return request(RequestMethod.GET, instanceURL(PaymentIntent.class, id), params, | ||
PaymentIntent.class, options); | ||
} | ||
// </editor-fold> | ||
|
||
// <editor-fold desc="update"> | ||
/** | ||
* Update a payment intent. | ||
*/ | ||
@Override | ||
public PaymentIntent update(Map<String, Object> params) | ||
throws AuthenticationException, InvalidRequestException, | ||
APIConnectionException, CardException, APIException { | ||
return update(params, null); | ||
} | ||
|
||
/** | ||
* Update a payment intent. | ||
*/ | ||
@Override | ||
public PaymentIntent update(Map<String, Object> params, RequestOptions options) | ||
throws AuthenticationException, InvalidRequestException, | ||
APIConnectionException, CardException, APIException { | ||
return request(RequestMethod.POST, instanceURL(PaymentIntent.class, this.id), params, | ||
PaymentIntent.class, | ||
options); | ||
} | ||
// </editor-fold> | ||
} |
This file contains hidden or 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,4 @@ | ||
package com.stripe.model; | ||
|
||
public class PaymentIntentCollection extends StripeCollection<PaymentIntent> { | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/stripe/model/PaymentIntentSourceAction.java
This file contains hidden or 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,13 @@ | ||
package com.stripe.model; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@EqualsAndHashCode(callSuper = false) | ||
public final class PaymentIntentSourceAction extends StripeObject { | ||
protected String type; | ||
protected PaymentIntentSourceActionValue value; | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/stripe/model/PaymentIntentSourceActionDeserializer.java
This file contains hidden or 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,46 @@ | ||
package com.stripe.model; | ||
|
||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonDeserializationContext; | ||
import com.google.gson.JsonDeserializer; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParseException; | ||
import com.google.gson.JsonPrimitive; | ||
import com.stripe.net.APIResource; | ||
|
||
import java.lang.reflect.Type; | ||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
|
||
public class PaymentIntentSourceActionDeserializer implements | ||
JsonDeserializer<PaymentIntentSourceAction> { | ||
|
||
static final Map<String, Class<? extends PaymentIntentSourceActionValue>> objectMap = | ||
new HashMap<String, Class<? extends PaymentIntentSourceActionValue>>(); | ||
|
||
static { | ||
objectMap.put("authorize_with_url", PaymentIntentSourceActionValueAuthorizeWithUrl.class); | ||
} | ||
|
||
/** | ||
* Deserializes the JSON payload contained in a next_source_action attribute into a | ||
* {@link PaymentIntentSourceAction} instance. | ||
*/ | ||
@Override | ||
public PaymentIntentSourceAction deserialize(JsonElement json, Type typeOfT, | ||
JsonDeserializationContext context) | ||
throws JsonParseException { | ||
PaymentIntentSourceAction sourceAction = new PaymentIntentSourceAction(); | ||
JsonObject jsonObject = json.getAsJsonObject(); | ||
String type = jsonObject.get("type").getAsString(); | ||
sourceAction.setType(type); | ||
Class<? extends PaymentIntentSourceActionValue> cl = objectMap.get(type); | ||
if (cl != null) { | ||
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
Sorry, something went wrong. |
||
PaymentIntentSourceActionValue value = APIResource.GSON.fromJson(jsonObject.get("value"), cl); | ||
sourceAction.setValue(value); | ||
} | ||
return sourceAction; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/stripe/model/PaymentIntentSourceActionValue.java
This file contains hidden or 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,4 @@ | ||
package com.stripe.model; | ||
|
||
public abstract class PaymentIntentSourceActionValue extends StripeObject { | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/stripe/model/PaymentIntentSourceActionValueAuthorizeWithUrl.java
This file contains hidden or 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,13 @@ | ||
package com.stripe.model; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@EqualsAndHashCode(callSuper = false) | ||
public final class PaymentIntentSourceActionValueAuthorizeWithUrl | ||
extends PaymentIntentSourceActionValue { | ||
protected String url; | ||
} |
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.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
Sorry, something went wrong.