Skip to content

Commit

Permalink
Add support for charge capture. Update to version 1.1.18.
Browse files Browse the repository at this point in the history
  • Loading branch information
boucher committed Mar 18, 2013
1 parent 74c3504 commit e013661
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
=== 1.1.18 2013-03-19
* Add support for charge capture.

=== 1.1.17 2013-02-18
* Add ability to deserialize account-related events.
* Add user ID to Event object.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Add this dependency to your project's POM:
<dependency>
<groupId>com.stripe</groupId>
<artifactId>stripe-java</artifactId>
<version>1.1.17</version>
<version>1.1.18</version>
</dependency>

### Others
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.17
1.1.18
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.stripe</groupId>
<artifactId>stripe-java</artifactId>
<packaging>jar</packaging>
<version>1.1.17</version>
<version>1.1.18</version>
<name>stripe-java</name>
<url>https://github.com/stripe/stripe-java</url>
<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/stripe/Stripe.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public abstract class Stripe
{
public static final String API_BASE = "https://api.stripe.com";
public static final String VERSION = "1.1.17";
public static final String VERSION = "1.1.18";
public static String apiKey;
public static String apiVersion;
}
37 changes: 37 additions & 0 deletions src/main/java/com/stripe/model/Charge.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class Charge extends APIResource {
Boolean paid;
Boolean refunded;
Boolean disputed;
Boolean captured;
Integer fee;
String description;
String failureMessage;
Expand Down Expand Up @@ -85,6 +86,14 @@ public void setRefunded(Boolean refunded) {
this.refunded = refunded;
}

public Boolean getCaptured() {
return captured;
}

public void setCaptured(Boolean captured) {
this.captured = captured;
}

public Boolean getDisputed() {
return disputed;
}
Expand Down Expand Up @@ -189,12 +198,24 @@ public Charge refund() throws AuthenticationException,
return this.refund(null, null);
}

public Charge capture() throws AuthenticationException,
InvalidRequestException, APIConnectionException, CardException,
APIException {
return this.capture(null, null);
}

public Charge refund(Map<String, Object> params)
throws AuthenticationException, InvalidRequestException,
APIConnectionException, CardException, APIException {
return this.refund(params, null);
}

public Charge capture(Map<String, Object> params)
throws AuthenticationException, InvalidRequestException,
APIConnectionException, CardException, APIException {
return this.capture(params, null);
}

public static Charge create(Map<String, Object> params, String apiKey)
throws AuthenticationException, InvalidRequestException,
APIConnectionException, CardException, APIException {
Expand Down Expand Up @@ -222,6 +243,12 @@ public Charge refund(String apiKey) throws AuthenticationException,
return this.refund((Map<String, Object>) null, apiKey); // full refund
}

public Charge capture(String apiKey) throws AuthenticationException,
InvalidRequestException, APIConnectionException, CardException,
APIException {
return this.capture((Map<String, Object>) null, apiKey);
}

public Charge refund(Map<String, Object> params, String apiKey)
throws AuthenticationException, InvalidRequestException,
APIConnectionException, CardException, APIException {
Expand All @@ -232,6 +259,16 @@ public Charge refund(Map<String, Object> params, String apiKey)
Charge.class, apiKey);
}

public Charge capture(Map<String, Object> params, String apiKey)
throws AuthenticationException, InvalidRequestException,
APIConnectionException, CardException, APIException {
return request(
RequestMethod.POST,
String.format("%s/capture",
instanceURL(Charge.class, this.getId())), params,
Charge.class, apiKey);
}

public Dispute updateDispute(Map<String, Object> params, String apiKey)
throws AuthenticationException, InvalidRequestException,
APIConnectionException, CardException, APIException {
Expand Down
26 changes: 19 additions & 7 deletions src/test/java/com/stripe/StripeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
import com.stripe.model.Token;

public class StripeTest {
static Map<String, Object> defaultCardParams = new HashMap<String, Object>();
static Map<String, Object> defaultChargeParams = new HashMap<String, Object>();
static Map<String, Object> defaultCustomerParams = new HashMap<String, Object>();
static Map<String, Object> defaultPlanParams = new HashMap<String, Object>();
static Map<String, Object> defaultCouponParams = new HashMap<String, Object>();
static Map<String, Object> defaultTokenParams = new HashMap<String, Object>();
static HashMap<String, Object> defaultCardParams = new HashMap<String, Object>();
static HashMap<String, Object> defaultChargeParams = new HashMap<String, Object>();
static HashMap<String, Object> defaultCustomerParams = new HashMap<String, Object>();
static HashMap<String, Object> defaultPlanParams = new HashMap<String, Object>();
static HashMap<String, Object> defaultCouponParams = new HashMap<String, Object>();
static HashMap<String, Object> defaultTokenParams = new HashMap<String, Object>();

static String getUniquePlanId() {
return String.format("JAVA-PLAN-%s", UUID.randomUUID());
Expand Down Expand Up @@ -159,6 +159,18 @@ public void testChargeRefund() throws StripeException {
assertTrue(refundedCharge.getRefunded());
}

@Test
public void testChargeCapture() throws StripeException {
HashMap<String, Object> options = (HashMap<String, Object>)defaultChargeParams.clone();
options.put("capture", false);

Charge created = Charge.create(options);
assertFalse(created.getCaptured());

Charge captured = created.capture();
assertTrue(captured.getCaptured());
}

@Test
public void testChargePartialRefund() throws StripeException {
Charge createdCharge = Charge.create(defaultChargeParams);
Expand Down Expand Up @@ -480,7 +492,7 @@ public void testEventList() throws StripeException {
/**
* Ensure the provided parameter for API key is actually being used. All
* other PerCallAPIKey methods assume this part works.
*
*
* @throws StripeException
*/
@Test
Expand Down

0 comments on commit e013661

Please sign in to comment.