Skip to content

Commit

Permalink
Merge pull request #266 from stripe/remi-countryspec-support
Browse files Browse the repository at this point in the history
Added support for CountrySpec
  • Loading branch information
brandur committed Feb 12, 2016
2 parents 67cb5e2 + a7f6a0d commit 984911b
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 0 deletions.
89 changes: 89 additions & 0 deletions src/main/java/com/stripe/model/CountrySpec.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
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;

public class CountrySpec extends APIResource implements HasId {
String id;
Map<String, List<String>> supportedBankAccountCurrencies;
List<String> supportedPaymentCurrencies;
List<String> supportedPaymentMethods;
VerificationFields verificationFields;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public Map<String, List<String>> getSupportedBankAccountCurrencies() {
return supportedBankAccountCurrencies;
}

public void setSupportedBankAccountCurrencies(Map<String, List<String>> supportedBankAccountCurrencies) {
this.supportedBankAccountCurrencies = supportedBankAccountCurrencies;
}

public List<String> getSupportedPaymentCurrencies() {
return supportedPaymentCurrencies;
}

public void setSupportedPaymentCurrencies(List<String> supportedPaymentCurrencies) {
this.supportedPaymentCurrencies = supportedPaymentCurrencies;
}

public List<String> getSupportedPaymentMethods() {
return supportedPaymentMethods;
}

public void setSupportedPaymentMethods(List<String> supportedPaymentMethods) {
this.supportedPaymentMethods = supportedPaymentMethods;
}

public VerificationFields getVerificationFields() {
return verificationFields;
}

public void setVerificationFields(VerificationFields verificationFields) {
this.verificationFields = verificationFields;
}

public static CountrySpec retrieve(String country) throws AuthenticationException,
InvalidRequestException, APIConnectionException, CardException,
APIException {
return retrieve(country, (RequestOptions) null);
}

public static CountrySpec retrieve(String country, RequestOptions options)
throws AuthenticationException, InvalidRequestException,
APIConnectionException, CardException, APIException {
return request(
RequestMethod.GET,
instanceURL(CountrySpec.class, country),
null,
CountrySpec.class,
options);
}

public static CountrySpecCollection list(Map<String, Object> params)
throws AuthenticationException, InvalidRequestException,
APIConnectionException, CardException, APIException {
return list(params, (RequestOptions) null);
}

public static CountrySpecCollection list(Map<String, Object> params, RequestOptions options)
throws AuthenticationException, InvalidRequestException,
APIConnectionException, CardException, APIException {
return requestCollection(classURL(CountrySpec.class), params, CountrySpecCollection.class, options);
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/stripe/model/CountrySpecCollection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.stripe.model;

public class CountrySpecCollection extends StripeCollection<CountrySpec> {
}
48 changes: 48 additions & 0 deletions src/main/java/com/stripe/model/VerificationFields.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.stripe.model;

import com.google.gson.annotations.SerializedName;
import java.util.List;

public final class VerificationFields extends StripeObject {
protected VerificationFieldsDetails individual;
protected VerificationFieldsDetails company;

public VerificationFieldsDetails getIndividual() {
return individual;
}

public VerificationFields setIndividual(VerificationFieldsDetails individual) {
this.individual = individual;
return this;
}

public VerificationFieldsDetails getCompany() {
return company;
}

public VerificationFields setCompany(VerificationFieldsDetails company) {
this.company = company;
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

VerificationFields verificationFields = (VerificationFields) o;

if (individual != null ? !individual.equals(verificationFields.individual) : verificationFields.individual != null) {
return false;
}
if (company != null ? !company.equals(verificationFields.company) : verificationFields.company != null) {
return false;
}

return true;
}
}
48 changes: 48 additions & 0 deletions src/main/java/com/stripe/model/VerificationFieldsDetails.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.stripe.model;

import com.google.gson.annotations.SerializedName;
import java.util.List;

public final class VerificationFieldsDetails extends StripeObject {
protected List<String> additional;
protected List<String> minimum;

public List<String> getAdditional() {
return additional;
}

public VerificationFieldsDetails setAdditional(List<String> additional) {
this.additional = additional;
return this;
}

public List<String> getMinimum() {
return minimum;
}

public VerificationFieldsDetails setMinimum(List<String> minimum) {
this.additional = minimum;
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

VerificationFieldsDetails verificationFieldsDetails = (VerificationFieldsDetails) o;

if (additional != null ? !additional.equals(verificationFieldsDetails.additional) : verificationFieldsDetails.additional != null) {
return false;
}
if (minimum != null ? !minimum.equals(verificationFieldsDetails.minimum) : verificationFieldsDetails.minimum != null) {
return false;
}

return true;
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/stripe/net/APIResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ private static String className(Class<?> clazz) {
return "file";
} else if (className.equals("bitcoinreceiver")) {
return "bitcoin_receiver";
} else if (className.equals("countryspec")) {
return "country_spec";
} else {
return className;
}
Expand Down
40 changes: 40 additions & 0 deletions src/test/java/com/stripe/StripeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import com.stripe.model.Card;
import com.stripe.model.Charge;
import com.stripe.model.ChargeRefundCollection;
import com.stripe.model.CountrySpec;
import com.stripe.model.CountrySpecCollection;
import com.stripe.model.Coupon;
import com.stripe.model.Customer;
import com.stripe.model.CustomerSubscriptionCollection;
Expand Down Expand Up @@ -56,6 +58,9 @@
import com.stripe.model.Token;
import com.stripe.model.Transfer;
import com.stripe.model.TransferReversalCollection;
import com.stripe.model.VerificationFields;
import com.stripe.model.VerificationFieldsDetails;

import com.stripe.net.RequestOptions;

import junit.framework.Assert;
Expand Down Expand Up @@ -2366,4 +2371,39 @@ public void getAllExternalAccounts() throws StripeException {

Assert.assertNotNull(accountCollection);
}

@Test
public void testCountrySpecRetrieve() throws StripeException {
String country = "US";
CountrySpec retrievedCountrySpec = CountrySpec.retrieve(country);

assertEquals(country, retrievedCountrySpec.getId());
assertNotSame(retrievedCountrySpec.getSupportedPaymentCurrencies().size(), 0);
assertNotSame(retrievedCountrySpec.getSupportedBankAccountCurrencies().size(), 0);
assertNotSame(retrievedCountrySpec.getSupportedPaymentMethods().size(), 0);

List<String> countryForBankAccountInUsd = retrievedCountrySpec.getSupportedBankAccountCurrencies().get("usd");
assertNotSame(countryForBankAccountInUsd.size(), 0);

VerificationFields verificationFields = retrievedCountrySpec.getVerificationFields();
assertNotSame(verificationFields.getIndividual().getMinimum().size(), 0);

CountrySpec retrievedCountrySpec2 = CountrySpec.retrieve(country);
VerificationFields verificationFields2 = retrievedCountrySpec2.getVerificationFields();
assert(verificationFields2.equals(verificationFields));

CountrySpec retrievedCountrySpecFR = CountrySpec.retrieve("FR");
VerificationFields verificationFieldsFR = retrievedCountrySpecFR.getVerificationFields();
assert(!verificationFieldsFR.equals(verificationFields));
}

@Test
public void testCountrySpecAll() throws StripeException {
Integer limit = 3;
Map<String, Object> listParams = new HashMap<String, Object>();
listParams.put("count", limit);
CountrySpecCollection retrievedCountrySpecCollection = CountrySpec.list(listParams);

assertEquals((Integer)retrievedCountrySpecCollection.getData().size(), limit);
}
}

0 comments on commit 984911b

Please sign in to comment.