-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #283 from amihaiemil/280
#280 Stripe BillingInfo front-end form and validation (fe + be)
- Loading branch information
Showing
12 changed files
with
1,399 additions
and
277 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
181 changes: 181 additions & 0 deletions
181
src/main/java/com/selfxdsd/selfweb/api/input/StripeWalletInput.java
This file contains 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,181 @@ | ||
/** | ||
* Copyright (c) 2020, Self XDSD Contributors | ||
* All rights reserved. | ||
* <p> | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), | ||
* to read the Software only. Permission is hereby NOT GRANTED to use, copy, | ||
* modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software. | ||
* <p> | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | ||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT | ||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package com.selfxdsd.selfweb.api.input; | ||
|
||
import com.selfxdsd.api.BillingInfo; | ||
import com.selfxdsd.selfweb.api.input.validators.NoSpecialChars; | ||
import com.selfxdsd.selfweb.api.input.validators.ValidCountry; | ||
|
||
import javax.validation.constraints.Email; | ||
import javax.validation.constraints.NotBlank; | ||
|
||
/** | ||
* Input for a new Stripe wallet (project billing info). | ||
* @author Mihai Andronache ([email protected]) | ||
* @version $Id$ | ||
* @since 0.0.1 | ||
* @checkstyle HiddenField (200 lines) | ||
* @checkstyle JavadocVariable (200 lines) | ||
* @checkstyle JavadocMethod (200 lines) | ||
*/ | ||
public final class StripeWalletInput { | ||
|
||
@NotBlank(message = "Legal name is mandatory!") | ||
@NoSpecialChars | ||
private String legalName; | ||
|
||
@NotBlank(message = "Country is mandatory!") | ||
@NoSpecialChars | ||
@ValidCountry | ||
private String country; | ||
|
||
@NotBlank(message = "Address is mandatory!") | ||
@NoSpecialChars | ||
private String address; | ||
|
||
@NotBlank(message = "City is mandatory!") | ||
@NoSpecialChars | ||
private String city; | ||
|
||
@NotBlank(message = "Zipcode is mandatory!") | ||
@NoSpecialChars | ||
private String zipcode; | ||
|
||
@NotBlank(message = "E-Mail is mandatory!") | ||
@Email(message = "Please provide a valid e-mail address.") | ||
@NoSpecialChars | ||
private String email; | ||
|
||
@NoSpecialChars | ||
private String other; | ||
|
||
public String getLegalName() { | ||
return this.legalName; | ||
} | ||
|
||
public void setLegalName(final String legalName) { | ||
this.legalName = legalName; | ||
} | ||
|
||
public String getCountry() { | ||
return this.country; | ||
} | ||
|
||
public void setCountry(final String country) { | ||
this.country = country; | ||
} | ||
|
||
public String getAddress() { | ||
return this.address; | ||
} | ||
|
||
public void setAddress(final String address) { | ||
this.address = address; | ||
} | ||
|
||
public String getCity() { | ||
return this.city; | ||
} | ||
|
||
public void setCity(final String city) { | ||
this.city = city; | ||
} | ||
|
||
public String getZipcode() { | ||
return this.zipcode; | ||
} | ||
|
||
public void setZipcode(final String zipcode) { | ||
this.zipcode = zipcode; | ||
} | ||
|
||
public String getEmail() { | ||
return this.email; | ||
} | ||
|
||
public void setEmail(final String email) { | ||
this.email = email; | ||
} | ||
|
||
public String getOther() { | ||
return this.other; | ||
} | ||
|
||
public void setOther(final String other) { | ||
this.other = other; | ||
} | ||
|
||
/** | ||
* Billing info from Stripe input form. | ||
*/ | ||
public static final class StripeBillingInfo implements BillingInfo { | ||
|
||
/** | ||
* Input from the Stripe wallet formular. | ||
*/ | ||
private StripeWalletInput input; | ||
|
||
/** | ||
* Ctor. | ||
* @param input Input from the Stripe wallet form. | ||
*/ | ||
public StripeBillingInfo(final StripeWalletInput input) { | ||
this.input = input; | ||
} | ||
|
||
@Override | ||
public String legalName() { | ||
return this.input.getLegalName(); | ||
} | ||
|
||
@Override | ||
public String country() { | ||
return this.input.getCountry(); | ||
} | ||
|
||
@Override | ||
public String address() { | ||
return this.input.getAddress(); | ||
} | ||
|
||
@Override | ||
public String city() { | ||
return this.input.getCity(); | ||
} | ||
|
||
@Override | ||
public String zipcode() { | ||
return this.input.getZipcode(); | ||
} | ||
|
||
@Override | ||
public String email() { | ||
return this.input.getEmail(); | ||
} | ||
|
||
@Override | ||
public String other() { | ||
return this.input.getOther(); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/com/selfxdsd/selfweb/api/input/validators/NoSpecialChars.java
This file contains 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,58 @@ | ||
/** | ||
* Copyright (c) 2020, Self XDSD Contributors | ||
* All rights reserved. | ||
* <p> | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), | ||
* to read the Software only. Permission is hereby NOT GRANTED to use, copy, | ||
* modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software. | ||
* <p> | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | ||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT | ||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package com.selfxdsd.selfweb.api.input.validators; | ||
|
||
import javax.validation.Constraint; | ||
import javax.validation.Payload; | ||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
|
||
/** | ||
* Annotation for String inputs. Forbids the mentioned special chars. | ||
* @author Mihai Andronache ([email protected] | ||
* @version $Id$ | ||
* @since 0.0.1 | ||
* @checkstyle JavadocMethod (200 lines) | ||
*/ | ||
@Documented | ||
@Target({ FIELD }) | ||
@Constraint(validatedBy = NoSpecialCharsValidator.class) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface NoSpecialChars { | ||
|
||
String message() default "No special chars allowed."; | ||
|
||
/** | ||
* The forbidden chars. | ||
* By default, the forbidden chars are: "[](){};<>/\`!%^*$? | ||
* @return String containing the forbidden chars. | ||
*/ | ||
String forbidden() default "\"[](){};<>/\\`!%^*$?"; | ||
|
||
Class<?>[] groups() default {}; | ||
Class<? extends Payload>[] payload() default {}; | ||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/com/selfxdsd/selfweb/api/input/validators/NoSpecialCharsValidator.java
This file contains 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,61 @@ | ||
/** | ||
* Copyright (c) 2020, Self XDSD Contributors | ||
* All rights reserved. | ||
* <p> | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), | ||
* to read the Software only. Permission is hereby NOT GRANTED to use, copy, | ||
* modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software. | ||
* <p> | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | ||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT | ||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package com.selfxdsd.selfweb.api.input.validators; | ||
|
||
import javax.validation.ConstraintValidator; | ||
import javax.validation.ConstraintValidatorContext; | ||
|
||
/** | ||
* Validator for the annotation {@link NoSpecialChars}. | ||
* @author Mihai Andronache ([email protected]) | ||
* @version $Id$ | ||
* @since 0.0.1 | ||
*/ | ||
public final class NoSpecialCharsValidator | ||
implements ConstraintValidator<NoSpecialChars, String> { | ||
|
||
/** | ||
* The forbidden chars. | ||
*/ | ||
private String forbidden; | ||
|
||
@Override | ||
public void initialize(final NoSpecialChars constraintAnnotation) { | ||
this.forbidden = constraintAnnotation.forbidden(); | ||
} | ||
|
||
@Override | ||
public boolean isValid( | ||
final String value, | ||
final ConstraintValidatorContext context | ||
) { | ||
boolean isValid = true; | ||
for (int i = 0; i < this.forbidden.length(); i++) { | ||
if(value.contains(String.valueOf(this.forbidden.charAt(i)))) { | ||
isValid = false; | ||
break; | ||
} | ||
} | ||
return isValid; | ||
} | ||
} |
Oops, something went wrong.