Skip to content

Commit

Permalink
Add partial refunds; version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
anurag committed Nov 29, 2011
1 parent 716300f commit f0a89b3
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 19 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ Add this dependency to your project's POM:
<dependency>
<groupId>com.stripe</groupId>
<artifactId>stripe-java</artifactId>
<version>1.0.6</version>
<version>1.0.7</version>
</dependency>

### Others

You'll need to manually install the following JARs:

* The Stripe JAR from https://code.stripe.com/stripe-java-1.0.6.jar
* The Stripe JAR from https://code.stripe.com/stripe-java-1.0.7.jar
* [Google Gson](http://code.google.com/p/google-gson/) from <http://google-gson.googlecode.com/files/google-gson-1.7.1-release.zip>.

Usage
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.6
1.0.7
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.0.6</version>
<version>1.0.7</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,6 +3,6 @@
public abstract class Stripe
{
public static final String API_BASE = "https://api.stripe.com/v1";
public static final String VERSION = "1.0.6";
public static final String VERSION = "1.0.7";
public static String apiKey;
}
22 changes: 17 additions & 5 deletions src/main/java/com/stripe/model/Charge.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class Charge extends APIResource {
Boolean refunded;
Integer fee;
String description;
Integer amountRefunded;
Card card;

public String getId() {
Expand Down Expand Up @@ -88,7 +89,15 @@ public String getDescription() {
public void setDescription(String description) {
this.description = description;
}

public Integer getAmountRefunded() {
return amountRefunded;
}

public void setAmountRefunded(Integer amountRefunded) {
this.amountRefunded = amountRefunded;
}

public Card getCard() {
return card;
}
Expand All @@ -104,15 +113,18 @@ public static Charge create(Map<String, Object> params) throws StripeException {
public static Charge retrieve(String id) throws StripeException {
return request(RequestMethod.GET, instanceURL(Charge.class, id), null, Charge.class);
}

public static ChargeCollection all(Map<String, Object> params) throws StripeException {
return request(RequestMethod.GET, classURL(Charge.class), params, ChargeCollection.class);
}

public Charge refund() throws StripeException {
return this.refund(null); // full refund
}

public Charge refund(Map<String, Object> params) throws StripeException {
return request(RequestMethod.POST,
String.format("%s/refund", instanceURL(Charge.class, this.getId())),
null, Charge.class);
params, Charge.class);
}

}
}
28 changes: 19 additions & 9 deletions src/test/java/com/stripe/StripeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,48 +81,58 @@ static Customer createDefaultCustomerWithPlan(Plan plan) throws StripeException
defaultCardParams.put("address_zip", "94301");
defaultCardParams.put("address_state", "CA");
defaultCardParams.put("address_country", "USA");

defaultChargeParams.put("amount", 100);
defaultChargeParams.put("currency", "usd");
defaultChargeParams.put("card", defaultCardParams);

defaultCustomerParams.put("card", defaultCardParams);
defaultCustomerParams.put("description", "Java Bindings Customer");

defaultPlanParams.put("amount", 100);
defaultPlanParams.put("currency", "usd");
defaultPlanParams.put("interval", "month");
defaultPlanParams.put("name", "Java Bindings Plan");

defaultCouponParams.put("duration", "once");
defaultCouponParams.put("percent_off", 10);
}

@Test public void testChargeCreate() throws StripeException {
Charge createdCharge = Charge.create(defaultChargeParams);
assertFalse(createdCharge.getRefunded());
}

@Test public void testChargeRetrieve() throws StripeException {
Charge createdCharge = Charge.create(defaultChargeParams);
Charge retrievedCharge = Charge.retrieve(createdCharge.getId());
assertEquals(createdCharge.getCreated(), retrievedCharge.getCreated());
assertEquals(createdCharge.getId(), retrievedCharge.getId());
}

@Test public void testChargeRefund() throws StripeException {
Charge createdCharge = Charge.create(defaultChargeParams);
Charge refundedCharge = createdCharge.refund();
assertTrue(refundedCharge.getRefunded());
}


@Test public void testChargePartialRefund() throws StripeException {
Charge createdCharge = Charge.create(defaultChargeParams);
Map<String, Object> refundParams = new HashMap<String, Object>();
final Integer REFUND_AMOUNT = 50;
refundParams.put("amount", REFUND_AMOUNT);
Charge refundedCharge = createdCharge.refund(refundParams);
assertFalse(refundedCharge.getRefunded());
assertEquals(refundedCharge.getAmountRefunded(), REFUND_AMOUNT);
}

@Test public void testChargeList() throws StripeException {
Map<String, Object> listParams = new HashMap<String, Object>();
listParams.put("count", 1);
List<Charge> charges = Charge.all(listParams).getData();
assertEquals(charges.size(), 1);
}

@Test(expected=CardException.class)
public void testInvalidCard() throws StripeException {
Map<String, Object> invalidChargeParams = new HashMap<String, Object>();
Expand Down

0 comments on commit f0a89b3

Please sign in to comment.