Skip to content
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

[SDKS-144] Update address verification API's with latest spec #87

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions src/main/java/com/plivo/api/models/address/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ public class Address extends BaseResource {
private String addressProofType;
private JsonNode documentDetails;


public static AddressCreator creator(
String countryIso, String salutation, String firstName, String lastName,
String addressLine1, String addressLine2, String city, String region, String postalCode) {
return new AddressCreator(countryIso, salutation, firstName, lastName, addressLine1, addressLine2, city, region, postalCode);
String phoneNumberCountry, NumberType numberType, SalutationType salutation, String firstName,
String lastName, String addressLine1, String addressLine2, String city, String region, String postalCode, String countryIso) {
return new AddressCreator(phoneNumberCountry, numberType, salutation, firstName, lastName, addressLine1, addressLine2, city, region, postalCode, countryIso);
}

public static AddressUpdater updater(String id){
Expand Down
298 changes: 175 additions & 123 deletions src/main/java/com/plivo/api/models/address/AddressCreator.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.plivo.api.models.address;

import java.io.File;

import com.plivo.api.models.base.Creator;
import com.plivo.api.util.Utils;
import retrofit2.Call;
Expand All @@ -16,145 +18,195 @@ public class AddressCreator extends Creator<AddressCreateResponse> {
private String city;
private String region;
private String postalCode;
private String file;
private File file;
private Boolean autoCorrectAddress;
private String addressProofType;

public String countryIso() {
return countryIso;
}

public String salutation() {
return salutation;
}

public String firstName() {
return firstName;
}

public String lastName() {
return lastName;
}

public String addressLine1() {
return addressLine1;
}

public String addressLine2() {
return addressLine2;
}

public String city() {
return city;
}

public String region() {
return region;
}

public String postalCode() {
return postalCode;
}

public String file() {
return file;
}

public Boolean autoCorrectAddress() {
return autoCorrectAddress;
}

public String addressProofType() {
return addressProofType;
}

public AddressCreator(String countryIso, String salutation, String firstName, String lastName,
String addressLine1, String addressLine2, String city, String region, String postalCode) {
if (!Utils.allNotNull(countryIso, salutation, firstName, lastName,
addressLine1, addressLine2, city, region, postalCode)) {
throw new IllegalArgumentException("countryIso, salutation, firstName, lastName," +
"addressLine1, addressLine2, city, region and postalCode must not be null");
}
this.countryIso = countryIso;
this.salutation = salutation;
this.firstName = firstName;
this.lastName = lastName;
this.addressLine1 = addressLine1;
this.addressLine2 = addressLine2;
this.city = city;
this.region = region;
this.postalCode = postalCode;
}

public AddressCreator countryIso(String countryIso) {
this.countryIso = countryIso;
return this;
}

private String phoneNumberCountry;
private String fiscalIdentificationCode;
private String streetCode;
private String municipalCode;
private String numberType;
private String idNumber;
private String callBackUrl;


public String getCountryIso() {
return countryIso;
}

public String getAlias() {
return alias;
}

public String getSalutation() {
return salutation;
}

public String getFirstName() {
return firstName;
}

public String getLastName() {
return lastName;
}

public String getAddressLine1() {
return addressLine1;
}

public String getAddressLine2() {
return addressLine2;
}

public String getCity() {
return city;
}

public String getRegion() {
return region;
}

public String getPostalCode() {
return postalCode;
}

public File getFile() {
return file;
}

public Boolean getAutoCorrectAddress() {
return autoCorrectAddress;
}

public String getAddressProofType() {
return addressProofType;
}

public String getPhoneNumberCountry() {
return phoneNumberCountry;
}

public String getFiscalIdentificationCode() {
return fiscalIdentificationCode;
}

public String getStreetCode() {
return streetCode;
}

public String getMunicipalCode() {
return municipalCode;
}

public String getNumberType() {
return numberType;
}

public String getIdNumber() {
return idNumber;
}

public String getCallBackUrl() {
return callBackUrl;
}

public AddressCreator(String phoneNumberCountry, NumberType numberType, SalutationType salutation, String firstName, String lastName,
String addressLine1, String addressLine2, String city, String region, String postalCode, String countryIso) {

if (!Utils.allNotNull(phoneNumberCountry, numberType, salutation, firstName, lastName,
addressLine1, addressLine2, city, region, postalCode, countryIso)) {
throw new IllegalArgumentException("phoneNumberCountry, numberType, salutation, firstName, lastName," +
"addressLine1, addressLine2, city, region, postalCode and countryIso must not be null");
}

this.phoneNumberCountry = phoneNumberCountry;
this.numberType = numberType.toString();
this.salutation = salutation.toString();
this.firstName = firstName;
this.lastName = lastName;
this.addressLine1 = addressLine1;
this.addressLine2 = addressLine2;
this.city = city;
this.region = region;
this.postalCode = postalCode;
this.countryIso = countryIso;

}

public AddressCreator callbackUrl(String callbackUrl) {
this.callBackUrl = callbackUrl;
return this;
}

public AddressCreator alias(String alias) {
this.alias = alias;
return this;
}

public AddressCreator salutation(String salutation) {
this.salutation = salutation;
return this;
}

public AddressCreator firstName(String firstName) {
this.firstName = firstName;
return this;
}

public AddressCreator lastName(String lastName) {
this.lastName = lastName;
return this;
}

public AddressCreator addressLine1(String addressLine1) {
this.addressLine1 = addressLine1;
return this;
}

public AddressCreator addressLine2(String addressLine2) {
this.addressLine2 = addressLine2;
return this;
}

public AddressCreator city(String city) {
this.city = city;
return this;
}

public AddressCreator region(String region) {
this.region = region;
return this;
}

public AddressCreator postalCode(String postalCode) {
this.postalCode = postalCode;
return this;
}

public AddressCreator file(String file) {
this.file = file;
return this;
public AddressCreator file(String fileName) {
File file = null;
if(!Utils.isValidExtension(fileName)) {
throw new IllegalArgumentException("File that are supported are png,jpg and pdf");
}
file = new File(fileName);
if(!file.exists()) {
throw new IllegalArgumentException("File not found in the specified path");
}
if(!Utils.isValidSize(file)) {
throw new IllegalArgumentException("File size exceeds 5 MB");
}

this.file = file;
return this;
}

public AddressCreator autoCorrectAddress(Boolean autoCorrectAddress) {
this.autoCorrectAddress = autoCorrectAddress;
return this;
}

public AddressCreator addressProofType(String addressProofType) {
this.addressProofType = addressProofType;
public AddressCreator addressProofType(AddressProofType addressProofType) {
this.addressProofType = addressProofType.toString();
return this;
}

@Override
protected Call<AddressCreateResponse> obtainCall() {
return client().getApiService().addressCreate(client().getAuthId(), this);
}

public AddressCreator fiscalIdentificationCode(String fiscalIdentificationCode) {
this.fiscalIdentificationCode = fiscalIdentificationCode;
return this;
}

public AddressCreator streetCode(String streetCode) {
this.streetCode = streetCode;
return this;
}

public AddressCreator municipalCode(String municipalCode) {
this.municipalCode = municipalCode;
return this;
}

public AddressCreator idNumber(String idNumber) {
this.idNumber = idNumber;
return this;
}

@Override
protected Call<AddressCreateResponse> obtainCall() {
if(this.countryIso != null && this.countryIso.equals("ES")) {
if(this.fiscalIdentificationCode == null) {
throw new IllegalArgumentException("The parameter fiscal_identification_code is required for Spain numbers");
}
}

if(this.countryIso != null && this.countryIso.equals("DK")) {
if(this.streetCode == null || this.municipalCode == null) {
throw new IllegalArgumentException("The parameters street_code and municipal_code are required for Denmark numbers");
}
}

return client().getApiService().addressCreate(client().getAuthId(), this);
}

}


24 changes: 24 additions & 0 deletions src/main/java/com/plivo/api/models/address/AddressProofType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.plivo.api.models.address;

public enum AddressProofType {

NATIONALID("national_id"),
PASSPORT("passport"),
BUISNESSID("business_id"),
NIF("NIF"),
NIE("NIE"),
DNI("DNI");

private final String addressProofType;

AddressProofType(final String proofType) {
this.addressProofType = proofType;
}

@Override
public String toString() {
return this.addressProofType;
}


}
Loading