-
Notifications
You must be signed in to change notification settings - Fork 0
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 #21 from hopper/allow-tokenisation-by-the-partner
Allow card tokenization from the partner
- Loading branch information
Showing
6 changed files
with
272 additions
and
35 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
69 changes: 69 additions & 0 deletions
69
src/main/java/com/hopper/cloud/airlines/HopperPaymentClient.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,69 @@ | ||
package com.hopper.cloud.airlines; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.hopper.cloud.airlines.model.*; | ||
import com.hopper.cloud.airlines.model.tokenization.TokenizationRequest; | ||
import com.hopper.cloud.airlines.model.tokenization.TokenizationResponse; | ||
import kong.unirest.HttpResponse; | ||
import kong.unirest.ObjectMapper; | ||
import kong.unirest.Unirest; | ||
|
||
public class HopperPaymentClient { | ||
private String paymentUrl; | ||
private String paymentUsername; | ||
private String paymentPassword; | ||
|
||
public HopperPaymentClient(String paymentUrl, String paymentUsername, String paymentPassword) { | ||
this.initHopperPaymentClient(paymentUrl, paymentUsername, paymentPassword); | ||
} | ||
|
||
|
||
private void initHopperPaymentClient(String paymentUrl, String paymentUsername, String paymentPassword) { | ||
this.paymentUrl = paymentUrl; | ||
this.paymentUsername = paymentUsername; | ||
this.paymentPassword = paymentPassword; | ||
|
||
Unirest.config().setObjectMapper(new ObjectMapper() { | ||
final com.fasterxml.jackson.databind.ObjectMapper mapper | ||
= new com.fasterxml.jackson.databind.ObjectMapper(); | ||
|
||
public String writeValue(Object value) { | ||
try { | ||
return mapper.writeValueAsString(value); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public <T> T readValue(String value, Class<T> valueType) { | ||
try { | ||
return mapper.readValue(value, valueType); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
}).connectTimeout(60000); | ||
|
||
} | ||
|
||
|
||
public HttpResponse<TokenizationResponse> getTokenizedPaymentHttpResponse(TokenizationRequest tokenizationRequest) throws ApiException { | ||
if (StringUtil.isEmpty(paymentUrl) || StringUtil.isEmpty(paymentUsername) || StringUtil.isEmpty(paymentPassword)) { | ||
throw new ApiException("Missing credentials for payment"); | ||
} | ||
return Unirest.post(paymentUrl) | ||
.basicAuth(paymentUsername, paymentPassword) | ||
.header("Content-Type", "application/json") | ||
.body(tokenizationRequest) | ||
.asObject(TokenizationResponse.class); | ||
} | ||
|
||
public String tokenizePaymentCard(PaymentCardDetail paymentCardDetail) throws ApiException { | ||
HttpResponse<TokenizationResponse> response = getTokenizedPaymentHttpResponse(new TokenizationRequest(paymentCardDetail)); | ||
if (response.getStatus() == 201) { | ||
return response.getBody().getTransaction().getPaymentMethod().getToken(); | ||
} else { | ||
throw new ApiException("Unable to create this specific token, response : " + response.getStatus()); | ||
} | ||
} | ||
} |
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
157 changes: 157 additions & 0 deletions
157
src/main/java/com/hopper/cloud/airlines/model/PaymentCardDetail.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,157 @@ | ||
package com.hopper.cloud.airlines.model; | ||
|
||
import java.util.Objects; | ||
|
||
public class PaymentCardDetail { | ||
private String number; | ||
private String verificationValue; | ||
private String month; | ||
private String year; | ||
private String firstName; | ||
private String lastName; | ||
private String addressLine1; | ||
private String addressLine2; | ||
private String city; | ||
private String postalCode; | ||
private String stateOrProvince; | ||
private String country; | ||
private String emailAddress; | ||
|
||
public PaymentCardDetail() { | ||
} | ||
|
||
public String getNumber() { | ||
return number; | ||
} | ||
|
||
public void setNumber(String number) { | ||
this.number = number; | ||
} | ||
|
||
public String getVerificationValue() { | ||
return verificationValue; | ||
} | ||
|
||
public void setVerificationValue(String verificationValue) { | ||
this.verificationValue = verificationValue; | ||
} | ||
|
||
public String getMonth() { | ||
return month; | ||
} | ||
|
||
public void setMonth(String month) { | ||
this.month = month; | ||
} | ||
|
||
public String getYear() { | ||
return year; | ||
} | ||
|
||
public void setYear(String year) { | ||
this.year = year; | ||
} | ||
|
||
public String getFirstName() { | ||
return firstName; | ||
} | ||
|
||
public void setFirstName(String firstName) { | ||
this.firstName = firstName; | ||
} | ||
|
||
public String getLastName() { | ||
return lastName; | ||
} | ||
|
||
public void setLastName(String lastName) { | ||
this.lastName = lastName; | ||
} | ||
|
||
public String getAddressLine1() { | ||
return addressLine1; | ||
} | ||
|
||
public void setAddressLine1(String addressLine1) { | ||
this.addressLine1 = addressLine1; | ||
} | ||
|
||
public String getAddressLine2() { | ||
return addressLine2; | ||
} | ||
|
||
public void setAddressLine2(String addressLine2) { | ||
this.addressLine2 = addressLine2; | ||
} | ||
|
||
public String getCity() { | ||
return city; | ||
} | ||
|
||
public void setCity(String city) { | ||
this.city = city; | ||
} | ||
|
||
public String getPostalCode() { | ||
return postalCode; | ||
} | ||
|
||
public void setPostalCode(String postalCode) { | ||
this.postalCode = postalCode; | ||
} | ||
|
||
public String getStateOrProvince() { | ||
return stateOrProvince; | ||
} | ||
|
||
public void setStateOrProvince(String stateOrProvince) { | ||
this.stateOrProvince = stateOrProvince; | ||
} | ||
|
||
public String getCountry() { | ||
return country; | ||
} | ||
|
||
public void setCountry(String country) { | ||
this.country = country; | ||
} | ||
|
||
public String getEmailAddress() { | ||
return emailAddress; | ||
} | ||
|
||
public void setEmailAddress(String emailAddress) { | ||
this.emailAddress = emailAddress; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
PaymentCardDetail processCfarPayment = (PaymentCardDetail) o; | ||
return Objects.equals(this.number, processCfarPayment.number) && | ||
Objects.equals(this.verificationValue, processCfarPayment.verificationValue) && | ||
Objects.equals(this.month, processCfarPayment.month) && | ||
Objects.equals(this.year, processCfarPayment.year) && | ||
Objects.equals(this.firstName, processCfarPayment.firstName) && | ||
Objects.equals(this.lastName, processCfarPayment.lastName) && | ||
Objects.equals(this.addressLine1, processCfarPayment.addressLine1) && | ||
Objects.equals(this.addressLine2, processCfarPayment.addressLine2) && | ||
Objects.equals(this.postalCode, processCfarPayment.postalCode) && | ||
Objects.equals(this.city, processCfarPayment.city) && | ||
Objects.equals(this.stateOrProvince, processCfarPayment.stateOrProvince) && | ||
Objects.equals(this.country, processCfarPayment.country) && | ||
Objects.equals(this.emailAddress, processCfarPayment.emailAddress); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(number, verificationValue, month, year, firstName, lastName, addressLine1, addressLine2, postalCode, city, stateOrProvince, country, emailAddress); | ||
} | ||
|
||
} | ||
|
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