-
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
dd13d18
commit 916244c
Showing
74 changed files
with
2,686 additions
and
141 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
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<ul> | ||
<li>Bug fixes.</li> | ||
<li>Added support for "Google pay"</li> | ||
</ul> |
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
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
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
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
78 changes: 78 additions & 0 deletions
78
.../src/main/java/com/adyen/checkout/base/model/payments/request/GooglePayPaymentMethod.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,78 @@ | ||
/* | ||
* Copyright (c) 2019 Adyen N.V. | ||
* | ||
* This file is open source and available under the MIT license. See the LICENSE file for more info. | ||
* | ||
* Created by caiof on 4/7/2019. | ||
*/ | ||
|
||
package com.adyen.checkout.base.model.payments.request; | ||
|
||
import android.os.Parcel; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
|
||
import com.adyen.checkout.base.util.PaymentMethodTypes; | ||
import com.adyen.checkout.core.exeption.ModelSerializationException; | ||
import com.adyen.checkout.core.model.JsonUtils; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
@SuppressWarnings("MemberName") | ||
public class GooglePayPaymentMethod extends PaymentMethodDetails { | ||
|
||
@NonNull | ||
public static final Creator<GooglePayPaymentMethod> CREATOR = new Creator<>(GooglePayPaymentMethod.class); | ||
|
||
public static final String PAYMENT_METHOD_TYPE = PaymentMethodTypes.GOOGLE_PAY; | ||
|
||
private static final String PAY_WITH_GOOGLE_TOKEN = "paywithgoogle.token"; | ||
|
||
@NonNull | ||
public static final Serializer<GooglePayPaymentMethod> SERIALIZER = new Serializer<GooglePayPaymentMethod>() { | ||
@NonNull | ||
@Override | ||
public JSONObject serialize(@NonNull GooglePayPaymentMethod modelObject) { | ||
final JSONObject jsonObject = new JSONObject(); | ||
try { | ||
// getting parameters from parent class | ||
jsonObject.putOpt(PaymentMethodDetails.TYPE, modelObject.getType()); | ||
|
||
jsonObject.putOpt(PAY_WITH_GOOGLE_TOKEN, modelObject.getToken()); | ||
} catch (JSONException e) { | ||
throw new ModelSerializationException(GooglePayPaymentMethod.class, e); | ||
} | ||
return jsonObject; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public GooglePayPaymentMethod deserialize(@NonNull JSONObject jsonObject) { | ||
final GooglePayPaymentMethod googlePayPaymentMethod = new GooglePayPaymentMethod(); | ||
|
||
// getting parameters from parent class | ||
googlePayPaymentMethod.setType(jsonObject.optString(PaymentMethodDetails.TYPE, null)); | ||
|
||
googlePayPaymentMethod.setToken(jsonObject.optString(PAY_WITH_GOOGLE_TOKEN, null)); | ||
|
||
return googlePayPaymentMethod; | ||
} | ||
}; | ||
|
||
private String token; | ||
|
||
@Override | ||
public void writeToParcel(@NonNull Parcel dest, int flags) { | ||
JsonUtils.writeToParcel(dest, SERIALIZER.serialize(this)); | ||
} | ||
|
||
@Nullable | ||
public String getToken() { | ||
return token; | ||
} | ||
|
||
public void setToken(@Nullable String token) { | ||
this.token = token; | ||
} | ||
} |
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
72 changes: 72 additions & 0 deletions
72
base-v3/src/main/java/com/adyen/checkout/base/util/AmountFormat.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,72 @@ | ||
/* | ||
* Copyright (c) 2019 Adyen N.V. | ||
* | ||
* This file is open source and available under the MIT license. See the LICENSE file for more info. | ||
* | ||
* Created by caiof on 31/7/2019. | ||
*/ | ||
|
||
package com.adyen.checkout.base.util; | ||
|
||
import android.support.annotation.NonNull; | ||
|
||
import com.adyen.checkout.base.model.payments.Amount; | ||
import com.adyen.checkout.core.exeption.NoConstructorException; | ||
import com.adyen.checkout.core.log.LogUtil; | ||
import com.adyen.checkout.core.log.Logger; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Currency; | ||
import java.util.Locale; | ||
|
||
public final class AmountFormat { | ||
private static final String TAG = LogUtil.getTag(); | ||
|
||
/** | ||
* Convert an {@link Amount} to its corresponding {@link BigDecimal} value. | ||
* | ||
* @param amount The {@link Amount} to be converted. | ||
* @return A {@link BigDecimal} representation of the {@link Amount}. | ||
*/ | ||
@NonNull | ||
public static BigDecimal toBigDecimal(@NonNull Amount amount) { | ||
return toBigDecimal(amount.getValue(), amount.getCurrency()); | ||
} | ||
|
||
/** | ||
* Convert a value in minor units with the corresponding currency code to its {@link BigDecimal} representation. | ||
* | ||
* @param value The value in minor units. | ||
* @param currencyCode The currency code of the value. | ||
* @return A {@link BigDecimal} representation. | ||
*/ | ||
@NonNull | ||
public static BigDecimal toBigDecimal(long value, @NonNull String currencyCode) { | ||
final int fractionDigits = getFractionDigits(currencyCode); | ||
|
||
return BigDecimal.valueOf(value, fractionDigits); | ||
} | ||
|
||
private static int getFractionDigits(@NonNull String currencyCode) { | ||
final String normalizedCurrencyCode = currencyCode.replaceAll("[^A-Z]", "").toUpperCase(Locale.ROOT); | ||
|
||
try { | ||
final CheckoutCurrency checkoutCurrency = CheckoutCurrency.valueOf(normalizedCurrencyCode); | ||
return checkoutCurrency.getFractionDigits(); | ||
} catch (IllegalArgumentException e) { | ||
Logger.e(TAG, normalizedCurrencyCode + " is an unsupported currency. Falling back to information from java.util.Currency."); | ||
} | ||
|
||
try { | ||
final Currency currency = Currency.getInstance(normalizedCurrencyCode); | ||
return Math.max(currency.getDefaultFractionDigits(), 0); | ||
} catch (IllegalArgumentException e) { | ||
Logger.e(TAG, "Could not determine fraction digits for " + normalizedCurrencyCode, e); | ||
return 0; | ||
} | ||
} | ||
|
||
private AmountFormat() { | ||
throw new NoConstructorException(); | ||
} | ||
} |
Oops, something went wrong.