-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4f8106
commit af65ddd
Showing
38 changed files
with
1,502 additions
and
43 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
97 changes: 97 additions & 0 deletions
97
checkout-base/src/main/java/com/adyen/checkout/base/internal/Base64Coder.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,97 @@ | ||
/* | ||
* Copyright (c) 2017 Adyen N.V. | ||
* | ||
* This file is open source and available under the MIT license. See the LICENSE file for more info. | ||
* | ||
* Created by Ran Haveshush on 22/11/2018. | ||
*/ | ||
|
||
package com.adyen.checkout.base.internal; | ||
|
||
import android.support.annotation.NonNull; | ||
import android.util.Base64; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.nio.charset.Charset; | ||
|
||
public final class Base64Coder { | ||
|
||
private static final Charset DEFAULT_CHARSET = Api.CHARSET; | ||
|
||
public static final int DEFAULT_FLAGS = Base64.DEFAULT; | ||
|
||
@NonNull | ||
public static <D extends JsonDecodable> D decode(@NonNull String encodedData, @NonNull Class<D> decodableClass) throws JSONException { | ||
return decode(encodedData, decodableClass, DEFAULT_FLAGS); | ||
} | ||
|
||
@NonNull | ||
public static <D extends JsonDecodable> D decode(@NonNull String encodedData, @NonNull Class<D> decodableClass, int flags) throws JSONException { | ||
D decodeable = JsonDecodable.decodeFrom(encodedData, decodableClass, flags); | ||
|
||
return decodeable; | ||
} | ||
|
||
@NonNull | ||
public static <E extends JsonEncodable> String encode(@NonNull E encodable) throws JSONException { | ||
return encode(encodable, DEFAULT_FLAGS); | ||
} | ||
|
||
@NonNull | ||
public static <E extends JsonEncodable> String encode(@NonNull E encodable, int flags) throws JSONException { | ||
return JsonEncodable.encodeFrom(encodable, flags); | ||
} | ||
|
||
@NonNull | ||
public static String encodeToString(@NonNull JSONObject jsonObject) { | ||
return encodeToString(jsonObject, DEFAULT_FLAGS); | ||
} | ||
|
||
@NonNull | ||
public static String encodeToString(@NonNull JSONObject jsonObject, int flags) { | ||
return encodeToString(jsonObject.toString(), flags); | ||
} | ||
|
||
@NonNull | ||
public static String encodeToString(@NonNull String decodedData) { | ||
return encodeToString(decodedData, DEFAULT_FLAGS); | ||
} | ||
|
||
@NonNull | ||
public static String encodeToString(@NonNull String decodedData, int flags) { | ||
byte[] decodedBytes = decodedData.getBytes(DEFAULT_CHARSET); | ||
|
||
return Base64.encodeToString(decodedBytes, flags); | ||
} | ||
|
||
@NonNull | ||
public static JSONObject decodeToJSONObject(@NonNull String encodedData) throws JSONException { | ||
return decodeToJSONObject(encodedData, DEFAULT_FLAGS); | ||
} | ||
|
||
@NonNull | ||
public static JSONObject decodeToJSONObject(@NonNull String encodedData, int flags) throws JSONException { | ||
String decodedData = decodeToString(encodedData, flags); | ||
|
||
return new JSONObject(decodedData); | ||
} | ||
|
||
@NonNull | ||
public static String decodeToString(@NonNull String encodedData) { | ||
return decodeToString(encodedData, DEFAULT_FLAGS); | ||
} | ||
|
||
@NonNull | ||
public static String decodeToString(@NonNull String encodedData, int flags) { | ||
byte[] decodedBytes = Base64.decode(encodedData, flags); | ||
String decodedData = new String(decodedBytes, DEFAULT_CHARSET); | ||
|
||
return decodedData; | ||
} | ||
|
||
private Base64Coder() { | ||
throw new IllegalStateException("No instances."); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
checkout-base/src/main/java/com/adyen/checkout/base/internal/JsonDecodable.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,33 @@ | ||
/* | ||
* Copyright (c) 2017 Adyen N.V. | ||
* | ||
* This file is open source and available under the MIT license. See the LICENSE file for more info. | ||
* | ||
* Created by Ran Haveshush on 21/11/2018. | ||
*/ | ||
|
||
package com.adyen.checkout.base.internal; | ||
|
||
import android.support.annotation.NonNull; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
public abstract class JsonDecodable extends JsonObject { | ||
|
||
@NonNull | ||
public static <T extends JsonDecodable> T decodeFrom(@NonNull String encodedData, @NonNull Class<T> clazz) throws JSONException { | ||
return decodeFrom(encodedData, clazz, Base64Coder.DEFAULT_FLAGS); | ||
} | ||
|
||
@NonNull | ||
public static <T extends JsonDecodable> T decodeFrom(@NonNull String encodedData, @NonNull Class<T> clazz, int flags) throws JSONException { | ||
JSONObject jsonObject = Base64Coder.decodeToJSONObject(encodedData, flags); | ||
|
||
return parseFrom(jsonObject, clazz); | ||
} | ||
|
||
protected JsonDecodable(@NonNull JSONObject jsonObject) throws JSONException { | ||
super(jsonObject); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
checkout-base/src/main/java/com/adyen/checkout/base/internal/JsonEncodable.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,31 @@ | ||
/* | ||
* Copyright (c) 2017 Adyen N.V. | ||
* | ||
* This file is open source and available under the MIT license. See the LICENSE file for more info. | ||
* | ||
* Created by Ran Haveshush on 21/11/2018. | ||
*/ | ||
|
||
package com.adyen.checkout.base.internal; | ||
|
||
import android.support.annotation.NonNull; | ||
|
||
import org.json.JSONException; | ||
|
||
public abstract class JsonEncodable implements JsonSerializable { | ||
|
||
@NonNull | ||
static <E extends JsonEncodable> String encodeFrom(@NonNull E encodable) throws JSONException { | ||
return encodeFrom(encodable, Base64Coder.DEFAULT_FLAGS); | ||
} | ||
|
||
@NonNull | ||
static <E extends JsonEncodable> String encodeFrom(@NonNull E encodable, int flags) throws JSONException { | ||
return encodable.encode(flags); | ||
} | ||
|
||
@NonNull | ||
String encode(int flags) throws JSONException { | ||
return Base64Coder.encodeToString(serialize(), flags); | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
checkout-core/src/main/java/com/adyen/checkout/core/AuthenticationDetails.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,52 @@ | ||
/* | ||
* Copyright (c) 2018 Adyen N.V. | ||
* | ||
* This file is open source and available under the MIT license. See the LICENSE file for more info. | ||
* | ||
* Created by Ran Haveshush on 09/05/2018. | ||
*/ | ||
|
||
package com.adyen.checkout.core; | ||
|
||
import android.os.Parcelable; | ||
import android.support.annotation.NonNull; | ||
|
||
import com.adyen.checkout.core.model.Authentication; | ||
import com.adyen.checkout.core.model.InputDetail; | ||
import com.adyen.checkout.core.model.PaymentResultCode; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* The {@link AuthenticationDetails} class describes all required parameters for an authentication. | ||
*/ | ||
public interface AuthenticationDetails extends Parcelable { | ||
/** | ||
* @return The type of payment method for which authentication details are needed. | ||
*/ | ||
@NonNull | ||
String getPaymentMethodType(); | ||
|
||
/** | ||
* Get authentication data that might be needed for the shopper authentication. | ||
* | ||
* @param authenticationClass The {@link Authentication} {@link Class}. | ||
* @param <T> The {@link Authentication} type. | ||
* @return The parsed {@link Authentication}. | ||
* @throws CheckoutException If the data does not match the provided {@link Authentication} {@link Class}. | ||
*/ | ||
@NonNull | ||
<T extends Authentication> T getAuthentication(@NonNull Class<T> authenticationClass) throws CheckoutException; | ||
|
||
/** | ||
* @return The {@link List} of authentication {@link InputDetail InputDetails}. | ||
*/ | ||
@NonNull | ||
List<InputDetail> getInputDetails(); | ||
|
||
/** | ||
* @return The payment result code {@link PaymentResultCode}. | ||
*/ | ||
@NonNull | ||
PaymentResultCode getResultCode(); | ||
} |
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
22 changes: 22 additions & 0 deletions
22
checkout-core/src/main/java/com/adyen/checkout/core/handler/AuthenticationHandler.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,22 @@ | ||
/* | ||
* Copyright (c) 2018 Adyen N.V. | ||
* | ||
* This file is open source and available under the MIT license. See the LICENSE file for more info. | ||
* | ||
* Created by Ran Haveshush on 16/11/2018. | ||
*/ | ||
|
||
package com.adyen.checkout.core.handler; | ||
|
||
import android.support.annotation.NonNull; | ||
|
||
import com.adyen.checkout.core.AuthenticationDetails; | ||
|
||
public interface AuthenticationHandler { | ||
/** | ||
* Called when authentication details are required to continue with the payment. | ||
* | ||
* @param authenticationDetails The required authentication details. | ||
*/ | ||
void onAuthenticationDetailsRequired(@NonNull AuthenticationDetails authenticationDetails); | ||
} |
26 changes: 26 additions & 0 deletions
26
checkout-core/src/main/java/com/adyen/checkout/core/internal/AuthenticationManager.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,26 @@ | ||
/* | ||
* Copyright (c) 2018 Adyen N.V. | ||
* | ||
* This file is open source and available under the MIT license. See the LICENSE file for more info. | ||
* | ||
* Created by Ran Haveshush on 16/11/2018. | ||
*/ | ||
|
||
package com.adyen.checkout.core.internal; | ||
|
||
import android.support.annotation.NonNull; | ||
|
||
import com.adyen.checkout.core.AuthenticationDetails; | ||
import com.adyen.checkout.core.handler.AuthenticationHandler; | ||
|
||
final class AuthenticationManager extends BaseManager<AuthenticationHandler, AuthenticationDetails> { | ||
|
||
AuthenticationManager(@NonNull Listener listener) { | ||
super(listener); | ||
} | ||
|
||
@Override | ||
void dispatch(@NonNull AuthenticationHandler handler, @NonNull AuthenticationDetails data) { | ||
handler.onAuthenticationDetailsRequired(data); | ||
} | ||
} |
Oops, something went wrong.